forked from GeyserMC/Geyser
Fix NullPointerException with invalid scoreboard teams
This commit is contained in:
parent
2dc9a7186e
commit
60abdbac3c
1 changed files with 24 additions and 11 deletions
|
@ -33,6 +33,7 @@ import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
import org.geysermc.connector.network.translators.Translator;
|
import org.geysermc.connector.network.translators.Translator;
|
||||||
import org.geysermc.connector.scoreboard.Scoreboard;
|
import org.geysermc.connector.scoreboard.Scoreboard;
|
||||||
|
import org.geysermc.connector.scoreboard.Team;
|
||||||
import org.geysermc.connector.scoreboard.UpdateType;
|
import org.geysermc.connector.scoreboard.UpdateType;
|
||||||
import org.geysermc.connector.utils.MessageUtils;
|
import org.geysermc.connector.utils.MessageUtils;
|
||||||
|
|
||||||
|
@ -48,6 +49,7 @@ public class JavaTeamTranslator extends PacketTranslator<ServerTeamPacket> {
|
||||||
GeyserConnector.getInstance().getLogger().debug("Team packet " + packet.getTeamName() + " " + packet.getAction() + " " + Arrays.toString(packet.getPlayers()));
|
GeyserConnector.getInstance().getLogger().debug("Team packet " + packet.getTeamName() + " " + packet.getAction() + " " + Arrays.toString(packet.getPlayers()));
|
||||||
|
|
||||||
Scoreboard scoreboard = session.getScoreboardCache().getScoreboard();
|
Scoreboard scoreboard = session.getScoreboardCache().getScoreboard();
|
||||||
|
Team team = scoreboard.getTeam(packet.getTeamName());
|
||||||
switch (packet.getAction()) {
|
switch (packet.getAction()) {
|
||||||
case CREATE:
|
case CREATE:
|
||||||
scoreboard.registerNewTeam(packet.getTeamName(), toPlayerSet(packet.getPlayers()))
|
scoreboard.registerNewTeam(packet.getTeamName(), toPlayerSet(packet.getPlayers()))
|
||||||
|
@ -57,18 +59,29 @@ public class JavaTeamTranslator extends PacketTranslator<ServerTeamPacket> {
|
||||||
.setSuffix(MessageUtils.getBedrockMessage(packet.getSuffix()));
|
.setSuffix(MessageUtils.getBedrockMessage(packet.getSuffix()));
|
||||||
break;
|
break;
|
||||||
case UPDATE:
|
case UPDATE:
|
||||||
scoreboard.getTeam(packet.getTeamName())
|
if (team != null) {
|
||||||
.setName(MessageUtils.getBedrockMessage(packet.getDisplayName()))
|
team.setName(MessageUtils.getBedrockMessage(packet.getDisplayName()))
|
||||||
.setColor(packet.getColor())
|
.setColor(packet.getColor())
|
||||||
.setPrefix(MessageUtils.getBedrockMessage(packet.getPrefix()))
|
.setPrefix(MessageUtils.getBedrockMessage(packet.getPrefix()))
|
||||||
.setSuffix(MessageUtils.getBedrockMessage(packet.getSuffix()))
|
.setSuffix(MessageUtils.getBedrockMessage(packet.getSuffix()))
|
||||||
.setUpdateType(UpdateType.UPDATE);
|
.setUpdateType(UpdateType.UPDATE);
|
||||||
|
} else {
|
||||||
|
GeyserConnector.getInstance().getLogger().error("Error while translating Team Packet " + packet.getAction() + "! Scoreboard Team " + packet.getTeamName() + " is not registered.");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ADD_PLAYER:
|
case ADD_PLAYER:
|
||||||
scoreboard.getTeam(packet.getTeamName()).addEntities(packet.getPlayers());
|
if(team != null){
|
||||||
|
team.addEntities(packet.getPlayers());
|
||||||
|
} else {
|
||||||
|
GeyserConnector.getInstance().getLogger().error("Error while translating Team Packet " + packet.getAction() + "! Scoreboard Team " + packet.getTeamName() + " is not registered.");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case REMOVE_PLAYER:
|
case REMOVE_PLAYER:
|
||||||
scoreboard.getTeam(packet.getTeamName()).removeEntities(packet.getPlayers());
|
if(team != null){
|
||||||
|
team.removeEntities(packet.getPlayers());
|
||||||
|
} else {
|
||||||
|
GeyserConnector.getInstance().getLogger().error("Error while translating Team Packet " + packet.getAction() + "! Scoreboard Team " + packet.getTeamName() + " is not registered.");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case REMOVE:
|
case REMOVE:
|
||||||
scoreboard.removeTeam(packet.getTeamName());
|
scoreboard.removeTeam(packet.getTeamName());
|
||||||
|
|
Loading…
Reference in a new issue