From 6770398c144500e8b7eb5d916ee6633678cfc208 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Tue, 7 Feb 2023 18:07:47 -0500 Subject: [PATCH] block solidifying beeps, stop right click attacks --- .../hideAndSeek/game/EntityHider.java | 3 +- .../hideAndSeek/game/PlayerLoader.java | 1 - .../game/listener/DisguiseHandler.java | 26 ++++++++----- .../hideAndSeek/game/util/Disguise.java | 37 ++++++++++++++++++- 4 files changed, 53 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EntityHider.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EntityHider.java index 3892f6f..fb98008 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EntityHider.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EntityHider.java @@ -2,7 +2,6 @@ package net.tylermurphy.hideAndSeek.game; import static com.comphenix.protocol.PacketType.Play.Server.*; -import java.lang.reflect.InvocationTargetException; import java.util.Collections; import java.util.Map; @@ -31,7 +30,7 @@ public class EntityHider implements Listener { private static final PacketType[] ENTITY_PACKETS = { ENTITY_EQUIPMENT, ANIMATION, NAMED_ENTITY_SPAWN, - COLLECT, SPAWN_ENTITY, SPAWN_ENTITY_LIVING, SPAWN_ENTITY_PAINTING, SPAWN_ENTITY_EXPERIENCE_ORB, + COLLECT, SPAWN_ENTITY, SPAWN_ENTITY_EXPERIENCE_ORB, ENTITY_VELOCITY, REL_ENTITY_MOVE, ENTITY_LOOK, ENTITY_TELEPORT, ENTITY_HEAD_ROTATION, ENTITY_STATUS, ATTACH_ENTITY, ENTITY_METADATA, ENTITY_EFFECT, REMOVE_ENTITY_EFFECT, BLOCK_BREAK_ANIMATION diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/PlayerLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/game/PlayerLoader.java index 10157cd..4ee1f5c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/PlayerLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/PlayerLoader.java @@ -128,7 +128,6 @@ public class PlayerLoader { player.setGameMode(GameMode.ADVENTURE); player.getInventory().clear(); for(PotionEffect effect : player.getActivePotionEffects()) { - Main.getInstance().getLogger().severe(player.getName() + " " + effect.getType()); if(effect.getType().getName().equals("INVISIBILITY") && Main.getInstance().getDisguiser().disguised(player)) continue; player.removePotionEffect(effect.getType()); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DisguiseHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DisguiseHandler.java index c80e83f..68eb26b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DisguiseHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DisguiseHandler.java @@ -7,6 +7,10 @@ import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; +import com.comphenix.protocol.wrappers.EnumWrappers; +import com.comphenix.protocol.wrappers.WrappedEnumEntityUseAction; +import com.cryptomorin.xseries.XSound; +import com.cryptomorin.xseries.messages.ActionBar; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.game.util.Disguise; import org.bukkit.Bukkit; @@ -33,17 +37,13 @@ public class DisguiseHandler implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void onMove(PlayerMoveEvent event) { - final Disguise disguise = Main.getInstance().getDisguiser().getDisguise(event.getPlayer()); - if(disguise == null) return; - final Location lastLocation = event.getPlayer().getLocation(); - Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> { - final Location currentLocation = event.getPlayer().getLocation(); - if(lastLocation.getWorld() != currentLocation.getWorld()) return; - double distance = lastLocation.distance(currentLocation); - disguise.setSolidify(distance < .1); - }, 20 * 3); - if(event.getFrom().distance(event.getTo()) > .1) + final Player player = event.getPlayer(); + final Disguise disguise = Main.getInstance().getDisguiser().getDisguise(player); + if(disguise == null) return;; + if(event.getFrom().distance(event.getTo()) > .1) { disguise.setSolidify(false); + } + disguise.startSolidifying(); } private PacketAdapter createProtocol(){ @@ -52,6 +52,12 @@ public class DisguiseHandler implements Listener { @Override public void onPacketReceiving(PacketEvent event){ PacketContainer packet = event.getPacket(); + + // only left click attacks + WrappedEnumEntityUseAction action = packet.getEnumEntityUseActions().getValues().stream().findFirst().orElse(null); + if (action == null) return; + if (action.getAction() != EnumWrappers.EntityUseAction.ATTACK) return; + Player player = event.getPlayer(); int id = packet.getIntegers().read(0); Disguise disguise = Main.getInstance().getDisguiser().getByEntityID(id); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/util/Disguise.java b/src/main/java/net/tylermurphy/hideAndSeek/game/util/Disguise.java index b9ea09b..b3460d0 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/util/Disguise.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/util/Disguise.java @@ -1,5 +1,7 @@ package net.tylermurphy.hideAndSeek.game.util; +import com.cryptomorin.xseries.XSound; +import com.cryptomorin.xseries.messages.ActionBar; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.util.packet.BlockChangePacket; import net.tylermurphy.hideAndSeek.util.packet.EntityTeleportPacket; @@ -20,7 +22,7 @@ public class Disguise { FallingBlock block; Horse hitBox; Location blockLocation; - boolean solid, solidify; + boolean solid, solidify, solidifying; static Team hidden; static { @@ -172,4 +174,37 @@ public class Disguise { } } + public void startSolidifying() { + if (solidifying) return; + if (solid) return; + solidifying = true; + final Location lastLocation = hider.getLocation(); + Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> solidifyUpdate(lastLocation, 3), 10); + } + + private void solidifyUpdate(Location lastLocation, int time) { + Location currentLocation = hider.getLocation(); + if(lastLocation.getWorld() != currentLocation.getWorld()) { + solidifying = false; + return; + } + if(lastLocation.distance(currentLocation) > .1) { + solidifying = false; + return; + } + if(time == 0) { + ActionBar.clearActionBar(hider); + setSolidify(true); + solidifying = false; + } else { + StringBuilder s = new StringBuilder(); + for (int i = 0; i < time; i++) { + s.append("▪"); + } + ActionBar.sendActionBar(hider, s.toString()); + XSound.BLOCK_NOTE_BLOCK_PLING.play(hider, 1, 1); + Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> solidifyUpdate(lastLocation, time - 1), 20); + } + } + } \ No newline at end of file