From ead8daca4e75137ba87d2ad1af3dce8bbe4a5271 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 26 Jan 2021 00:53:55 +1300 Subject: [PATCH] Fix libsdisguises.seethrough --- .../disguise/disguisetypes/Disguise.java | 9 +++ .../utilities/listeners/DisguiseListener.java | 80 +++++++++---------- .../packethandlers/PacketHandlerSpawn.java | 1 - 3 files changed, 48 insertions(+), 42 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java index df0ab387..7dd0375e 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -1081,6 +1081,15 @@ public abstract class Disguise { multiName = new String[0]; } + for (Player player : Bukkit.getOnlinePlayers()) { + if (player.hasPermission("libsdisguises.seethrough") || + ((TargetedDisguise) this).getDisguiseTarget() != TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) { + continue; + } + + ((TargetedDisguise) this).addPlayer(player); + } + if (LibsPremium.getUserID().equals("123" + "45") || !LibsMsg.OWNED_BY.getRaw().contains("'")) { ((TargetedDisguise) this).setDisguiseTarget(TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/listeners/DisguiseListener.java b/src/main/java/me/libraryaddict/disguise/utilities/listeners/DisguiseListener.java index 5f86a64f..5db0ced7 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/listeners/DisguiseListener.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/listeners/DisguiseListener.java @@ -16,7 +16,6 @@ import me.libraryaddict.disguise.utilities.LibsEntityInteract; import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.modded.ModdedEntity; import me.libraryaddict.disguise.utilities.modded.ModdedManager; -import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; import me.libraryaddict.disguise.utilities.translations.LibsMsg; import org.apache.commons.lang.math.RandomUtils; import org.bukkit.Bukkit; @@ -59,8 +58,7 @@ public class DisguiseListener implements Listener { runUpdateScheduler(); - if (!LibsPremium.getPluginInformation().isPremium() || - LibsPremium.getPluginInformation().getUserID().matches("[0-9]+")) { + if (!LibsPremium.getPluginInformation().isPremium() || LibsPremium.getPluginInformation().getUserID().matches("[0-9]+")) { Bukkit.getPluginManager().registerEvents(this, plugin); } @@ -109,8 +107,7 @@ public class DisguiseListener implements Listener { } if (autoUpdate && !isCheckReleases()) { - DisguiseUtilities.getLogger() - .info("Plugin will attempt to auto update when new builds are ready! Check config to disable."); + DisguiseUtilities.getLogger().info("Plugin will attempt to auto update when new builds are ready! Check config to disable."); } } @@ -132,8 +129,7 @@ public class DisguiseListener implements Listener { } } - @EventHandler(priority = EventPriority.MONITOR, - ignoreCancelled = true) + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onVelocity(PlayerVelocityEvent event) { DisguiseUtilities.setPlayerVelocity(event.getPlayer()); @@ -142,8 +138,7 @@ public class DisguiseListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGH, - ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onAttack(EntityDamageByEntityEvent event) { Entity attacker = event.getDamager(); @@ -177,14 +172,12 @@ public class DisguiseListener implements Listener { private boolean canRetaliate(Entity entity) { return entity.hasMetadata("LD-LastAttacked") && - entity.getMetadata("LD-LastAttacked").get(0).asLong() + (DisguiseConfig.getPvPTimer() * 1000) > - System.currentTimeMillis(); + entity.getMetadata("LD-LastAttacked").get(0).asLong() + (DisguiseConfig.getPvPTimer() * 1000) > System.currentTimeMillis(); } private void setRetaliation(Entity entity) { entity.removeMetadata("LD-LastAttacked", LibsDisguises.getInstance()); - entity.setMetadata("LD-LastAttacked", - new FixedMetadataValue(LibsDisguises.getInstance(), System.currentTimeMillis())); + entity.setMetadata("LD-LastAttacked", new FixedMetadataValue(LibsDisguises.getInstance(), System.currentTimeMillis())); } private void checkPlayerCanFight(EntityDamageByEntityEvent event, Entity attacker) { @@ -195,8 +188,7 @@ public class DisguiseListener implements Listener { return; } - if (!attacker.hasPermission("libsdisguises." + (pvp ? "pvp" : "pve")) && - !attacker.hasPermission("libsdisguises." + (pvp ? "pvp" : "pve"))) { + if (!attacker.hasPermission("libsdisguises." + (pvp ? "pvp" : "pve")) && !attacker.hasPermission("libsdisguises." + (pvp ? "pvp" : "pve"))) { if (!DisguiseConfig.isRetaliationCombat() || !canRetaliate(attacker)) { Disguise[] disguises = DisguiseAPI.getDisguises(attacker); @@ -371,6 +363,11 @@ public class DisguiseListener implements Listener { continue; } + if (p.hasPermission("libsdisguises.seethrough") && + targetedDisguise.getDisguiseTarget() == TargetedDisguise.TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) { + targetedDisguise.addPlayer(p); + } + if (!targetedDisguise.canSee(p)) { continue; } @@ -383,8 +380,7 @@ public class DisguiseListener implements Listener { if (disguise.isDisplayedInTab()) { try { - ProtocolLibrary.getProtocolManager().sendServerPacket(p, - DisguiseUtilities.getTabPacket(disguise, PlayerInfoAction.ADD_PLAYER)); + ProtocolLibrary.getProtocolManager().sendServerPacket(p, DisguiseUtilities.getTabPacket(disguise, PlayerInfoAction.ADD_PLAYER)); } catch (InvocationTargetException e) { e.printStackTrace(); } @@ -406,14 +402,13 @@ public class DisguiseListener implements Listener { } if (!p.hasMetadata("forge_mods")) { - Optional required = ModdedManager.getEntities().values().stream() - .filter(c -> c.getMod() != null && c.getRequired() != null).findAny(); + Optional required = + ModdedManager.getEntities().values().stream().filter(c -> c.getMod() != null && c.getRequired() != null).findAny(); required.ifPresent(customEntity -> p.kickPlayer(customEntity.getRequired())); } - if (DisguiseConfig.isSaveGameProfiles() && DisguiseConfig.isUpdateGameProfiles() && - DisguiseUtilities.hasGameProfile(p.getName())) { + if (DisguiseConfig.isSaveGameProfiles() && DisguiseConfig.isUpdateGameProfiles() && DisguiseUtilities.hasGameProfile(p.getName())) { WrappedGameProfile profile = WrappedGameProfile.fromPlayer(p); if (!profile.getProperties().isEmpty()) { @@ -431,8 +426,8 @@ public class DisguiseListener implements Listener { } if (!p.hasMetadata("forge_mods")) { - Optional required = ModdedManager.getEntities().values().stream() - .filter(c -> c.getMod() != null && c.getRequired() != null).findAny(); + Optional required = + ModdedManager.getEntities().values().stream().filter(c -> c.getMod() != null && c.getRequired() != null).findAny(); required.ifPresent(customEntity -> p.kickPlayer(customEntity.getRequired())); } @@ -443,12 +438,10 @@ public class DisguiseListener implements Listener { /** * Most likely faster if we don't bother doing checks if he sees a player disguise */ - @EventHandler(priority = EventPriority.MONITOR, - ignoreCancelled = true) + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onMove(PlayerMoveEvent event) { // If yer a pirate with a pirated jar, sometimes you can't move - if (("%%__USER__%%".isEmpty() || DisguiseUtilities.isInvalidFile()) && !event.getPlayer().isOp() && - RandomUtils.nextDouble() < 0.01) { + if (("%%__USER__%%".isEmpty() || DisguiseUtilities.isInvalidFile()) && !event.getPlayer().isOp() && RandomUtils.nextDouble() < 0.01) { event.setCancelled(true); } @@ -471,8 +464,7 @@ public class DisguiseListener implements Listener { Disguise disguise; if ((disguise = DisguiseAPI.getDisguise(event.getPlayer())) != null) { - if (disguise.getType() == - DisguiseType.SHULKER) { // Stop Shulker disguises from moving their coordinates + if (disguise.getType() == DisguiseType.SHULKER) { // Stop Shulker disguises from moving their coordinates Location from = event.getFrom(); Location to = event.getTo(); @@ -491,6 +483,18 @@ public class DisguiseListener implements Listener { DisguiseUtilities.removeSelfDisguiseScoreboard(player); + if (player.hasPermission("libsdisguises.seethrough")) { + for (Set disguises : DisguiseUtilities.getDisguises().values()) { + for (TargetedDisguise disguise : disguises) { + if (disguise.getDisguiseTarget() != TargetedDisguise.TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) { + continue; + } + + disguise.silentlyRemovePlayer(player.getName()); + } + } + } + if (!DisguiseConfig.isSavePlayerDisguises()) { return; } @@ -563,15 +567,13 @@ public class DisguiseListener implements Listener { } } - @EventHandler(priority = EventPriority.MONITOR, - ignoreCancelled = true) + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onTeleport(PlayerTeleportEvent event) { final Player player = event.getPlayer(); Location to = event.getTo(); Location from = event.getFrom(); - if (!player.isOp() && !player.hasPermission("minecraft.command.teleport") && - LibsPremium.getPaidInformation() != null && + if (!player.isOp() && !player.hasPermission("minecraft.command.teleport") && LibsPremium.getPaidInformation() != null && LibsPremium.getPaidInformation().getUserID().equals("1592")) { player.sendMessage(ChatColor.GOLD + "Your teleport was a success!"); } @@ -580,8 +582,7 @@ public class DisguiseListener implements Listener { return; } - if (DisguiseConfig.isUndisguiseOnWorldChange() && to.getWorld() != null && from.getWorld() != null && - to.getWorld() != from.getWorld()) { + if (DisguiseConfig.isUndisguiseOnWorldChange() && to.getWorld() != null && from.getWorld() != null && to.getWorld() != from.getWorld()) { Disguise[] disguises = DisguiseAPI.getDisguises(event.getPlayer()); if (disguises.length > 0) { @@ -634,8 +635,7 @@ public class DisguiseListener implements Listener { } } - @EventHandler(priority = EventPriority.MONITOR, - ignoreCancelled = true) + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onVehicleEnter(VehicleEnterEvent event) { if (!(event.getEntered() instanceof Player)) { return; @@ -652,8 +652,7 @@ public class DisguiseListener implements Listener { ((Player) event.getEntered()).updateInventory(); } - @EventHandler(priority = EventPriority.MONITOR, - ignoreCancelled = true) + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onVehicleLeave(VehicleExitEvent event) { if (event.getExited() instanceof Player) { final Disguise disguise = DisguiseAPI.getDisguise((Player) event.getExited(), event.getExited()); @@ -671,8 +670,7 @@ public class DisguiseListener implements Listener { } } - @EventHandler(priority = EventPriority.MONITOR, - ignoreCancelled = true) + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onWorldSwitch(final PlayerChangedWorldEvent event) { if (!DisguiseAPI.isDisguised(event.getPlayer())) { return; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java index e23babe5..a1a7800b 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java @@ -57,7 +57,6 @@ public class PacketHandlerSpawn implements IPacketHandler { @Override public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer, Entity entity) { - packets.clear(); if (disguise.getType() == DisguiseType.UNKNOWN) {