From d9238a01c661831aac880bab5643114104315819 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 24 Feb 2017 01:42:13 +1300 Subject: [PATCH] Fix scoreboards --- .../disguise/DisguiseConfig.java | 2 +- .../disguise/utilities/DisguiseUtilities.java | 68 +++++++++++-------- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/me/libraryaddict/disguise/DisguiseConfig.java b/src/me/libraryaddict/disguise/DisguiseConfig.java index fd898e89..67a4ad65 100644 --- a/src/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/me/libraryaddict/disguise/DisguiseConfig.java @@ -15,7 +15,7 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException import me.libraryaddict.disguise.utilities.PacketsManager; public class DisguiseConfig { - public static enum DisguisePushing { + public static enum DisguisePushing { // This enum has a really bad name.. MODIFY_SCOREBOARD, IGNORE_SCOREBOARD, CREATE_SCOREBOARD; } diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index d0f083e4..2e46bee3 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -86,7 +86,7 @@ public class DisguiseUtilities { private static HashSet selfDisguised = new HashSet<>(); private static Thread mainThread; private static PacketContainer spawnChunk; - private static HashMap previousTeam = new HashMap(); + private static HashMap preDisguiseTeam = new HashMap(); static { try { @@ -1031,17 +1031,19 @@ public class DisguiseUtilities { ex.printStackTrace(); } - String prevTeam = previousTeam.remove(player.getUniqueId()); + String originalTeam = preDisguiseTeam.remove(player.getUniqueId()); if (DisguiseConfig.getPushingOption() != DisguisePushing.IGNORE_SCOREBOARD) { - // Code to stop player pushing in 1.9 + // Code to stop player pushing Scoreboard scoreboard = player.getScoreboard(); - Team team = prevTeam == null ? null : scoreboard.getTeam(prevTeam); + Team team = originalTeam == null ? null : scoreboard.getTeam(originalTeam); Team ldTeam = scoreboard.getEntryTeam(player.getName()); if (ldTeam != null) { - if (!ldTeam.getName().equals("LDPushing") && !ldTeam.getName().endsWith("_LDP")) + if (!ldTeam.getName().equals("LDPushing") && !ldTeam.getName().endsWith("_LDP")) { + // Its not a team assigned by me ldTeam = null; + } } if (team != null) { @@ -1137,47 +1139,59 @@ public class DisguiseUtilities { // Code to stop player pushing Scoreboard scoreboard = player.getScoreboard(); Team prevTeam = scoreboard.getEntryTeam(player.getName()); + Team ldTeam = null; - if (prevTeam != null && pOption == DisguisePushing.CREATE_SCOREBOARD) { - previousTeam.put(player.getUniqueId(), prevTeam.getName()); + // If the player is in a team already + if (prevTeam != null) { + // If we're creating a scoreboard + if (pOption == DisguisePushing.CREATE_SCOREBOARD) { + // Remember his old team so we can give him it back later + preDisguiseTeam.put(player.getUniqueId(), prevTeam.getName()); + } + else { + // We're modifying the scoreboard + ldTeam = prevTeam; + } } - Team t; - String createName = null; + String ldTeamName = null; + // If we are creating a new scoreboard because the current one must not be modified if (pOption == DisguisePushing.CREATE_SCOREBOARD) { - createName = (prevTeam == null ? "No Team" : prevTeam.getName()); + // If they have a team, we'll reuse that name. Otherwise go for another name + ldTeamName = (prevTeam == null ? "No Team" : prevTeam.getName()); - createName = createName.substring(0, Math.min(12, createName.length())); + // Give the teamname a custom name + ldTeamName = ldTeamName.substring(0, Math.min(12, ldTeamName.length())) + "_LDP"; } - else { - createName = "LDPushing"; + else if (ldTeam == null) { + ldTeamName = "LDPushing"; } - if ((t = scoreboard.getTeam(createName)) == null) { - t = scoreboard.registerNewTeam(createName); + if (ldTeamName != null && (ldTeam = scoreboard.getTeam(ldTeamName)) == null) { + ldTeam = scoreboard.registerNewTeam(ldTeamName); } - if (t.getOption(Option.COLLISION_RULE) != OptionStatus.NEVER) { - t.setOption(Option.COLLISION_RULE, OptionStatus.NEVER); + if (ldTeam.getOption(Option.COLLISION_RULE) != OptionStatus.NEVER) { + ldTeam.setOption(Option.COLLISION_RULE, OptionStatus.NEVER); } - if (t.canSeeFriendlyInvisibles()) { - t.setCanSeeFriendlyInvisibles(false); + if (ldTeam.canSeeFriendlyInvisibles()) { + ldTeam.setCanSeeFriendlyInvisibles(false); } - if (!t.hasEntry(player.getName())) - t.addEntry(player.getName()); + if (!ldTeam.hasEntry(player.getName())) + ldTeam.addEntry(player.getName()); if (pOption == DisguisePushing.CREATE_SCOREBOARD && prevTeam != null) { - t.setAllowFriendlyFire(prevTeam.allowFriendlyFire()); - t.setCanSeeFriendlyInvisibles(prevTeam.canSeeFriendlyInvisibles()); - t.setDisplayName(prevTeam.getDisplayName()); - t.setPrefix(prevTeam.getPrefix()); - t.setSuffix(prevTeam.getSuffix()); + ldTeam.setAllowFriendlyFire(prevTeam.allowFriendlyFire()); + ldTeam.setCanSeeFriendlyInvisibles(prevTeam.canSeeFriendlyInvisibles()); + ldTeam.setDisplayName(prevTeam.getDisplayName()); + ldTeam.setPrefix(prevTeam.getPrefix()); + ldTeam.setSuffix(prevTeam.getSuffix()); for (Option option : Team.Option.values()) { - t.setOption(option, prevTeam.getOption(option)); + ldTeam.setOption(option, prevTeam.getOption(option)); } } }