Fix libsdisguises.seethrough

This commit is contained in:
libraryaddict 2021-01-26 00:53:55 +13:00
parent 11785d1842
commit ead8daca4e
3 changed files with 48 additions and 42 deletions

View File

@ -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);

View File

@ -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<ModdedEntity> required = ModdedManager.getEntities().values().stream()
.filter(c -> c.getMod() != null && c.getRequired() != null).findAny();
Optional<ModdedEntity> 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<ModdedEntity> required = ModdedManager.getEntities().values().stream()
.filter(c -> c.getMod() != null && c.getRequired() != null).findAny();
Optional<ModdedEntity> 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<TargetedDisguise> 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;

View File

@ -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) {