Skip to content

Commit

Permalink
add null checks in player ban tags
Browse files Browse the repository at this point in the history
that debug line is a mess but it's debug so who cares
  • Loading branch information
mcmonkey4eva committed Sep 2, 2022
1 parent cffb1a2 commit f261a8a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
Expand Up @@ -39,6 +39,9 @@ public void setPlayerSkin(Player player, String name) {
NetworkInterceptHelper.enable();
PlayerProfile profile = getFakeProfile(player, true);
PlayerProfile skinProfile = NMSHandler.instance.fillPlayerProfile(new PlayerProfile(name, null));
if (skinProfile == null) {
return;
}
if (skinProfile.getTexture() != null) {
profile.setTexture(skinProfile.getTexture());
profile.setTextureSignature(skinProfile.getTextureSignature());
Expand Down
Expand Up @@ -961,6 +961,9 @@ public static void registerTags() {
// Returns whether the player is banned.
// -->
tagProcessor.registerTag(ElementTag.class, "is_banned", (attribute, object) -> {
if (object.getName() == null) {
return new ElementTag(false);
}
BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(object.getName());
if (ban == null) {
return new ElementTag(false);
Expand Down Expand Up @@ -1067,13 +1070,19 @@ else if (ban.getExpiration() == null) {
// Potentially can be null.
// -->
tagProcessor.registerTag(TimeTag.class, "ban_expiration_time", (attribute, object) -> {
if (object.getName() == null) {
return null;
}
BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(object.getName());
if (ban == null || ban.getExpiration() == null || (ban.getExpiration() != null && ban.getExpiration().before(new Date()))) {
return null;
}
return new TimeTag(ban.getExpiration().getTime());
});
tagProcessor.registerTag(DurationTag.class, "ban_expiration", (attribute, object) -> {
if (object.getName() == null) {
return null;
}
BukkitImplDeprecations.playerTimePlayedTags.warn(attribute.context);
BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(object.getName());
if (ban == null || ban.getExpiration() == null || (ban.getExpiration() != null && ban.getExpiration().before(new Date()))) {
Expand All @@ -1089,6 +1098,9 @@ else if (ban.getExpiration() == null) {
// Returns the reason for the player's ban, if they are banned.
// -->
tagProcessor.registerTag(ElementTag.class, "ban_reason", (attribute, object) -> {
if (object.getName() == null) {
return null;
}
BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(object.getName());
if (ban == null || (ban.getExpiration() != null && ban.getExpiration().before(new Date()))) {
return null;
Expand All @@ -1103,13 +1115,19 @@ else if (ban.getExpiration() == null) {
// Returns when the player's ban was created, if they are banned.
// -->
tagProcessor.registerTag(TimeTag.class, "ban_created_time", (attribute, object) -> {
if (object.getName() == null) {
return null;
}
BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(object.getName());
if (ban == null || (ban.getExpiration() != null && ban.getExpiration().before(new Date()))) {
return null;
}
return new TimeTag(ban.getCreated().getTime());
});
tagProcessor.registerTag(DurationTag.class, "ban_created", (attribute, object) -> {
if (object.getName() == null) {
return null;
}
Deprecations.timeTagRewrite.warn(attribute.context);
BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(object.getName());
if (ban == null || (ban.getExpiration() != null && ban.getExpiration().before(new Date()))) {
Expand All @@ -1125,6 +1143,9 @@ else if (ban.getExpiration() == null) {
// Returns the source of the player's ban, if they are banned.
// -->
tagProcessor.registerTag(ElementTag.class, "ban_source", (attribute, object) -> {
if (object.getName() == null) {
return null;
}
BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(object.getName());
if (ban == null || (ban.getExpiration() != null && ban.getExpiration().before(new Date()))) {
return null;
Expand All @@ -1133,6 +1154,9 @@ else if (ban.getExpiration() == null) {
});

tagProcessor.registerTag(ObjectTag.class, "ban_info", (attribute, object) -> {
if (object.getName() == null) {
return null;
}
BukkitImplDeprecations.playerBanInfoTags.warn(attribute.context);
BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(object.getName());
if (ban == null || (ban.getExpiration() != null && ban.getExpiration().before(new Date()))) {
Expand Down Expand Up @@ -3743,7 +3767,7 @@ else if (getPlayerEntity().getGameMode() == GameMode.SPECTATOR) {
// @tags
// <PlayerTag.name>
// -->
if (mechanism.matches("name")) {
if (mechanism.matches("name") && mechanism.hasValue()) {
String name = mechanism.getValue().asString();
if (name.length() > 16) {
Debug.echoError("Must specify a name with no more than 16 characters.");
Expand All @@ -3761,7 +3785,7 @@ else if (getPlayerEntity().getGameMode() == GameMode.SPECTATOR) {
// Changes the skin of the player to the skin of the given player name.
// See also <@link language Player Entity Skins (Skin Blobs)>.
// -->
if (mechanism.matches("skin")) {
if (mechanism.matches("skin") && mechanism.hasValue()) {
String name = mechanism.getValue().asString();
if (name.length() > 16) {
Debug.echoError("Must specify a name with no more than 16 characters.");
Expand All @@ -3782,7 +3806,7 @@ else if (getPlayerEntity().getGameMode() == GameMode.SPECTATOR) {
// @tags
// <PlayerTag.skin_blob>
// -->
if (mechanism.matches("skin_blob")) {
if (mechanism.matches("skin_blob") && mechanism.hasValue()) {
NMSHandler.instance.getProfileEditor().setPlayerSkinBlob(getPlayerEntity(), mechanism.getValue().asString());
}

Expand Down
Expand Up @@ -260,6 +260,12 @@ else if (packet instanceof ClientboundRemoveEntitiesPacket) {
ClientboundRemoveEntitiesPacket removePacket = (ClientboundRemoveEntitiesPacket) packet;
doPacketOutput("Packet: ClientboundRemoveEntitiesPacket sent to " + player.getScoreboardName() + " for entities: " + removePacket.getEntityIds().stream().map(Object::toString).collect(Collectors.joining(", ")));
}
else if (packet instanceof ClientboundPlayerInfoPacket) {
ClientboundPlayerInfoPacket playerInfoPacket = (ClientboundPlayerInfoPacket) packet;
doPacketOutput("Packet: ClientboundPlayerInfoPacket sent to " + player.getScoreboardName() + " of type " + playerInfoPacket.getAction() + " for player profiles: " +
playerInfoPacket.getEntries().stream().map(p -> "mode=" + p.getGameMode() + "/latency=" + p.getLatency() + "/display=" + p.getDisplayName() + "/name=" + p.getProfile().getName() + "/id=" + p.getProfile().getId() + "/"
+ p.getProfile().getProperties().asMap().entrySet().stream().map(e -> e.getKey() + "=" + e.getValue().stream().map(v -> v.getValue() + ";" + v.getSignature()).collect(Collectors.joining(";;;"))).collect(Collectors.joining("/"))).collect(Collectors.joining(", ")));
}
else {
doPacketOutput("Packet: " + packet.getClass().getCanonicalName() + " sent to " + player.getScoreboardName());
}
Expand Down

0 comments on commit f261a8a

Please sign in to comment.