Skip to content

Commit

Permalink
Fix CB Names MCP->MOJ
Browse files Browse the repository at this point in the history
in scoreboard
  • Loading branch information
C0D3-M4513R committed Nov 17, 2023
1 parent db9fecc commit 337f437
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@
if (compoundtag1.hasUUID("Attach")) {
uuid = compoundtag1.getUUID("Attach");
} else {
@@ -239,6 +_,9 @@
@@ -239,9 +_,12 @@
}

p_11263_.initInventoryMenu();
Expand All @@ -280,7 +280,11 @@
+ LOGGER.info("{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", p_11263_.getName().getString(), s1, p_11263_.getId(), serverlevel1.serverLevelData.getLevelName(), p_11263_.getX(), p_11263_.getY(), p_11263_.getZ());
}

protected void updateEntireScoreboard(ServerScoreboard p_11274_, ServerPlayer p_11275_) {
- protected void updateEntireScoreboard(ServerScoreboard p_11274_, ServerPlayer p_11275_) {
+ public void updateEntireScoreboard(ServerScoreboard p_11274_, ServerPlayer p_11275_) {
Set<Objective> set = Sets.newHashSet();

for(PlayerTeam playerteam : p_11274_.getPlayerTeams()) {
@@ -262,25 +_,26 @@
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.google.common.collect.ImmutableMap;
import java.util.Map;
import net.minecraft.world.scores.ScoreboardObjective;
import net.minecraft.world.scores.criteria.IScoreboardCriteria;
import net.minecraft.world.scores.Objective;
import net.minecraft.world.scores.criteria.ObjectiveCriteria;
import org.bukkit.scoreboard.Criteria;
import org.bukkit.scoreboard.RenderType;

Expand All @@ -14,9 +14,9 @@ public final class CraftCriteria implements Criteria {
static {
ImmutableMap.Builder<String, CraftCriteria> defaults = ImmutableMap.builder();

for (Map.Entry<String, IScoreboardCriteria> entry : IScoreboardCriteria.CRITERIA_CACHE.entrySet()) {
for (Map.Entry<String, ObjectiveCriteria> entry : ObjectiveCriteria.CRITERIA_CACHE.entrySet()) {
String name = entry.getKey();
IScoreboardCriteria criteria = entry.getValue();
ObjectiveCriteria criteria = entry.getValue();

defaults.put(name, new CraftCriteria(criteria));
}
Expand All @@ -25,15 +25,15 @@ public final class CraftCriteria implements Criteria {
DUMMY = DEFAULTS.get("dummy");
}

final IScoreboardCriteria criteria;
final ObjectiveCriteria criteria;
final String bukkitName;

private CraftCriteria(String bukkitName) {
this.bukkitName = bukkitName;
this.criteria = DUMMY.criteria;
}

private CraftCriteria(IScoreboardCriteria criteria) {
private CraftCriteria(ObjectiveCriteria criteria) {
this.criteria = criteria;
this.bukkitName = criteria.getName();
}
Expand All @@ -53,7 +53,7 @@ public RenderType getDefaultRenderType() {
return RenderType.values()[criteria.getDefaultRenderType().ordinal()];
}

static CraftCriteria getFromNMS(ScoreboardObjective objective) {
static CraftCriteria getFromNMS(Objective objective) {
return DEFAULTS.get(objective.getCriteria().getName());
}

Expand All @@ -63,7 +63,7 @@ public static CraftCriteria getFromBukkit(String name) {
return criteria;
}

return IScoreboardCriteria.byName(name).map(CraftCriteria::new).orElseGet(() -> new CraftCriteria(name));
return ObjectiveCriteria.byName(name).map(CraftCriteria::new).orElseGet(() -> new CraftCriteria(name));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.common.base.Preconditions;
import net.minecraft.world.scores.Scoreboard;
import net.minecraft.world.scores.ScoreboardObjective;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_20_R2.util.CraftChatMessage;
import org.bukkit.scoreboard.Criteria;
Expand All @@ -12,16 +11,16 @@
import org.bukkit.scoreboard.Score;

final class CraftObjective extends CraftScoreboardComponent implements Objective {
private final ScoreboardObjective objective;
private final net.minecraft.world.scores.Objective objective;
private final CraftCriteria criteria;

CraftObjective(CraftScoreboard scoreboard, ScoreboardObjective objective) {
CraftObjective(CraftScoreboard scoreboard, net.minecraft.world.scores.Objective objective) {
super(scoreboard);
this.objective = objective;
this.criteria = CraftCriteria.getFromNMS(objective);
}

ScoreboardObjective getHandle() {
net.minecraft.world.scores.Objective getHandle() {
return objective;
}

Expand Down Expand Up @@ -72,7 +71,7 @@ public boolean isModifiable() {
public void setDisplaySlot(DisplaySlot slot) {
CraftScoreboard scoreboard = checkState();
Scoreboard board = scoreboard.board;
ScoreboardObjective objective = this.objective;
net.minecraft.world.scores.Objective objective = this.objective;

for (net.minecraft.world.scores.DisplaySlot i : net.minecraft.world.scores.DisplaySlot.values()) {
if (board.getDisplayObjective(i) == objective) {
Expand All @@ -89,7 +88,7 @@ public void setDisplaySlot(DisplaySlot slot) {
public DisplaySlot getDisplaySlot() {
CraftScoreboard scoreboard = checkState();
Scoreboard board = scoreboard.board;
ScoreboardObjective objective = this.objective;
net.minecraft.world.scores.Objective objective = this.objective;

for (net.minecraft.world.scores.DisplaySlot i : net.minecraft.world.scores.DisplaySlot.values()) {
if (board.getDisplayObjective(i) == objective) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import java.util.Map;
import net.minecraft.world.scores.Scoreboard;
import net.minecraft.world.scores.ScoreboardObjective;
import net.minecraft.world.scores.ScoreboardScore;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.scoreboard.Objective;
Expand Down Expand Up @@ -44,8 +42,8 @@ public int getScore() {
Scoreboard board = objective.checkState().board;

if (board.getTrackedPlayers().contains(entry)) { // Lazy
Map<ScoreboardObjective, ScoreboardScore> scores = board.getPlayerScores(entry);
ScoreboardScore score = scores.get(objective.getHandle());
Map<net.minecraft.world.scores.Objective, net.minecraft.world.scores.Score> scores = board.getPlayerScores(entry);
net.minecraft.world.scores.Score score = scores.get(objective.getHandle());
if (score != null) { // Lazy
return score.getScore();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import net.minecraft.world.scores.Scoreboard;
import net.minecraft.world.scores.ScoreboardObjective;
import net.minecraft.world.scores.ScoreboardTeam;
import net.minecraft.world.scores.PlayerTeam;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_20_R2.util.CraftChatMessage;
Expand Down Expand Up @@ -53,14 +52,14 @@ public CraftObjective registerNewObjective(String name, Criteria criteria, Strin
Preconditions.checkArgument(name.length() <= Short.MAX_VALUE, "The name '%s' is longer than the limit of 32767 characters (%s)", name, name.length());
Preconditions.checkArgument(board.getObjective(name) == null, "An objective of name '%s' already exists", name);

ScoreboardObjective objective = board.addObjective(name, ((CraftCriteria) criteria).criteria, CraftChatMessage.fromStringOrNull(displayName), CraftScoreboardTranslations.fromBukkitRender(renderType));
net.minecraft.world.scores.Objective objective = board.addObjective(name, ((CraftCriteria) criteria).criteria, CraftChatMessage.fromStringOrNull(displayName), CraftScoreboardTranslations.fromBukkitRender(renderType));
return new CraftObjective(this, objective);
}

@Override
public Objective getObjective(String name) {
Preconditions.checkArgument(name != null, "Objective name cannot be null");
ScoreboardObjective nms = board.getObjective(name);
net.minecraft.world.scores.Objective nms = board.getObjective(name);
return nms == null ? null : new CraftObjective(this, nms);
}

Expand All @@ -69,7 +68,7 @@ public ImmutableSet<Objective> getObjectivesByCriteria(String criteria) {
Preconditions.checkArgument(criteria != null, "Criteria name cannot be null");

ImmutableSet.Builder<Objective> objectives = ImmutableSet.builder();
for (ScoreboardObjective netObjective : this.board.getObjectives()) {
for (net.minecraft.world.scores.Objective netObjective : this.board.getObjectives()) {
CraftObjective objective = new CraftObjective(this, netObjective);
if (objective.getCriteria().equals(criteria)) {
objectives.add(objective);
Expand All @@ -83,7 +82,7 @@ public ImmutableSet<Objective> getObjectivesByCriteria(Criteria criteria) {
Preconditions.checkArgument(criteria != null, "Criteria cannot be null");

ImmutableSet.Builder<Objective> objectives = ImmutableSet.builder();
for (ScoreboardObjective netObjective : board.getObjectives()) {
for (net.minecraft.world.scores.Objective netObjective : board.getObjectives()) {
CraftObjective objective = new CraftObjective(this, netObjective);
if (objective.getTrackedCriteria().equals(criteria)) {
objectives.add(objective);
Expand All @@ -95,13 +94,13 @@ public ImmutableSet<Objective> getObjectivesByCriteria(Criteria criteria) {

@Override
public ImmutableSet<Objective> getObjectives() {
return ImmutableSet.copyOf(Iterables.transform(this.board.getObjectives(), (Function<ScoreboardObjective, Objective>) input -> new CraftObjective(CraftScoreboard.this, input)));
return ImmutableSet.copyOf(Iterables.transform(this.board.getObjectives(), (Function<net.minecraft.world.scores.Objective, Objective>) input -> new CraftObjective(CraftScoreboard.this, input)));
}

@Override
public Objective getObjective(DisplaySlot slot) {
Preconditions.checkArgument(slot != null, "Display slot cannot be null");
ScoreboardObjective objective = board.getDisplayObjective(CraftScoreboardTranslations.fromBukkitSlot(slot));
net.minecraft.world.scores.Objective objective = board.getDisplayObjective(CraftScoreboardTranslations.fromBukkitSlot(slot));
if (objective == null) {
return null;
}
Expand All @@ -120,7 +119,7 @@ public ImmutableSet<Score> getScores(String entry) {
Preconditions.checkArgument(entry != null, "Entry cannot be null");

ImmutableSet.Builder<Score> scores = ImmutableSet.builder();
for (ScoreboardObjective objective : this.board.getObjectives()) {
for (net.minecraft.world.scores.Objective objective : this.board.getObjectives()) {
scores.add(new CraftScore(new CraftObjective(this, objective), entry));
}
return scores.build();
Expand All @@ -137,7 +136,7 @@ public void resetScores(OfflinePlayer player) {
public void resetScores(String entry) {
Preconditions.checkArgument(entry != null, "Entry cannot be null");

for (ScoreboardObjective objective : this.board.getObjectives()) {
for (net.minecraft.world.scores.Objective objective : this.board.getObjectives()) {
board.resetPlayerScore(entry, objective);
}
}
Expand All @@ -146,29 +145,29 @@ public void resetScores(String entry) {
public Team getPlayerTeam(OfflinePlayer player) {
Preconditions.checkArgument(player != null, "OfflinePlayer cannot be null");

ScoreboardTeam team = board.getPlayersTeam(player.getName());
PlayerTeam team = board.getPlayersTeam(player.getName());
return team == null ? null : new CraftTeam(this, team);
}

@Override
public Team getEntryTeam(String entry) {
Preconditions.checkArgument(entry != null, "Entry cannot be null");

ScoreboardTeam team = board.getPlayersTeam(entry);
PlayerTeam team = board.getPlayersTeam(entry);
return team == null ? null : new CraftTeam(this, team);
}

@Override
public Team getTeam(String teamName) {
Preconditions.checkArgument(teamName != null, "Team name cannot be null");

ScoreboardTeam team = board.getPlayerTeam(teamName);
PlayerTeam team = board.getPlayerTeam(teamName);
return team == null ? null : new CraftTeam(this, team);
}

@Override
public ImmutableSet<Team> getTeams() {
return ImmutableSet.copyOf(Iterables.transform(this.board.getPlayerTeams(), (Function<ScoreboardTeam, Team>) input -> new CraftTeam(CraftScoreboard.this, input)));
return ImmutableSet.copyOf(Iterables.transform(this.board.getPlayerTeams(), (Function<PlayerTeam, Team>) input -> new CraftTeam(CraftScoreboard.this, input)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
import java.util.Iterator;
import java.util.Map;
import java.util.function.Consumer;
import net.minecraft.network.protocol.game.PacketPlayOutScoreboardObjective;
import net.minecraft.network.protocol.game.PacketPlayOutScoreboardTeam;
import net.minecraft.network.protocol.game.ClientboundSetObjectivePacket;
import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ScoreboardServer;
import net.minecraft.server.level.EntityPlayer;
import net.minecraft.server.ServerScoreboard;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.scores.Scoreboard;
import net.minecraft.world.scores.ScoreboardObjective;
import net.minecraft.world.scores.ScoreboardScore;
import net.minecraft.world.scores.ScoreboardTeam;
import net.minecraft.world.scores.criteria.IScoreboardCriteria;
import net.minecraft.world.scores.Objective;
import net.minecraft.world.scores.Score;
import net.minecraft.world.scores.PlayerTeam;
import net.minecraft.world.scores.criteria.ObjectiveCriteria;
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_20_R2.util.WeakCollection;
import org.bukkit.entity.Player;
Expand All @@ -41,7 +41,7 @@ public CraftScoreboard getMainScoreboard() {

@Override
public CraftScoreboard getNewScoreboard() {
CraftScoreboard scoreboard = new CraftScoreboard(new ScoreboardServer(server));
CraftScoreboard scoreboard = new CraftScoreboard(new ServerScoreboard(server));
scoreboards.add(scoreboard);
return scoreboard;
}
Expand All @@ -59,7 +59,7 @@ public void setPlayerBoard(CraftPlayer player, org.bukkit.scoreboard.Scoreboard
CraftScoreboard scoreboard = (CraftScoreboard) bukkitScoreboard;
net.minecraft.world.scores.Scoreboard oldboard = getPlayerBoard(player).getHandle();
net.minecraft.world.scores.Scoreboard newboard = scoreboard.getHandle();
EntityPlayer entityplayer = player.getHandle();
ServerPlayer entityplayer = player.getHandle();

if (oldboard == newboard) {
return;
Expand All @@ -72,24 +72,24 @@ public void setPlayerBoard(CraftPlayer player, org.bukkit.scoreboard.Scoreboard
}

// Old objective tracking
HashSet<ScoreboardObjective> removed = new HashSet<>();
HashSet<Objective> removed = new HashSet<>();
for (int i = 0; i < 3; ++i) {
ScoreboardObjective scoreboardobjective = oldboard.getDisplayObjective(net.minecraft.world.scores.DisplaySlot.BY_ID.apply(i));
Objective scoreboardobjective = oldboard.getDisplayObjective(net.minecraft.world.scores.DisplaySlot.BY_ID.apply(i));
if (scoreboardobjective != null && !removed.contains(scoreboardobjective)) {
entityplayer.connection.send(new PacketPlayOutScoreboardObjective(scoreboardobjective, 1));
entityplayer.connection.send(new ClientboundSetObjectivePacket(scoreboardobjective, 1));
removed.add(scoreboardobjective);
}
}

// Old team tracking
Iterator<?> iterator = oldboard.getPlayerTeams().iterator();
Iterator<PlayerTeam> iterator = oldboard.getPlayerTeams().iterator();
while (iterator.hasNext()) {
ScoreboardTeam scoreboardteam = (ScoreboardTeam) iterator.next();
entityplayer.connection.send(PacketPlayOutScoreboardTeam.createRemovePacket(scoreboardteam));
PlayerTeam scoreboardteam = iterator.next();
entityplayer.connection.send(ClientboundSetPlayerTeamPacket.createRemovePacket(scoreboardteam));
}

// The above is the reverse of the below method.
server.getPlayerList().updateEntireScoreboard((ScoreboardServer) newboard, player.getHandle());
server.getPlayerList().updateEntireScoreboard((ServerScoreboard) newboard, player.getHandle());
}

// CraftBukkit method
Expand All @@ -98,7 +98,7 @@ public void removePlayer(Player player) {
}

// CraftBukkit method
public void getScoreboardScores(IScoreboardCriteria criteria, String name, Consumer<ScoreboardScore> consumer) {
public void getScoreboardScores(ObjectiveCriteria criteria, String name, Consumer<Score> consumer) {
for (CraftScoreboard scoreboard : scoreboards) {
Scoreboard board = scoreboard.board;
board.forAllObjectives(criteria, name, (score) -> consumer.accept(score));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.bukkit.craftbukkit.v1_20_R2.scoreboard;

import com.google.common.collect.ImmutableBiMap;
import net.minecraft.world.scores.criteria.IScoreboardCriteria;
import net.minecraft.world.scores.criteria.ObjectiveCriteria;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.RenderType;

Expand Down Expand Up @@ -39,11 +39,11 @@ static net.minecraft.world.scores.DisplaySlot fromBukkitSlot(DisplaySlot slot) {
return net.minecraft.world.scores.DisplaySlot.CODEC.byName(SLOTS.get(slot));
}

static RenderType toBukkitRender(IScoreboardCriteria.EnumScoreboardHealthDisplay display) {
static RenderType toBukkitRender(ObjectiveCriteria.RenderType display) {
return RenderType.valueOf(display.name());
}

static IScoreboardCriteria.EnumScoreboardHealthDisplay fromBukkitRender(RenderType render) {
return IScoreboardCriteria.EnumScoreboardHealthDisplay.valueOf(render.name());
static ObjectiveCriteria.RenderType fromBukkitRender(RenderType render) {
return ObjectiveCriteria.RenderType.valueOf(render.name());
}
}
Loading

0 comments on commit 337f437

Please sign in to comment.