block solidifying beeps, stop right click attacks

This commit is contained in:
Tyler Murphy 2023-02-07 18:07:47 -05:00
parent 2139a8d5d3
commit 6770398c14
4 changed files with 53 additions and 14 deletions

View file

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

View file

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

View file

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

View file

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