block solidifying beeps, stop right click attacks
This commit is contained in:
parent
2139a8d5d3
commit
6770398c14
4 changed files with 53 additions and 14 deletions
|
@ -2,7 +2,6 @@ package net.tylermurphy.hideAndSeek.game;
|
||||||
|
|
||||||
import static com.comphenix.protocol.PacketType.Play.Server.*;
|
import static com.comphenix.protocol.PacketType.Play.Server.*;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -31,7 +30,7 @@ public class EntityHider implements Listener {
|
||||||
|
|
||||||
private static final PacketType[] ENTITY_PACKETS = {
|
private static final PacketType[] ENTITY_PACKETS = {
|
||||||
ENTITY_EQUIPMENT, ANIMATION, NAMED_ENTITY_SPAWN,
|
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_VELOCITY, REL_ENTITY_MOVE, ENTITY_LOOK,
|
||||||
ENTITY_TELEPORT, ENTITY_HEAD_ROTATION, ENTITY_STATUS, ATTACH_ENTITY, ENTITY_METADATA,
|
ENTITY_TELEPORT, ENTITY_HEAD_ROTATION, ENTITY_STATUS, ATTACH_ENTITY, ENTITY_METADATA,
|
||||||
ENTITY_EFFECT, REMOVE_ENTITY_EFFECT, BLOCK_BREAK_ANIMATION
|
ENTITY_EFFECT, REMOVE_ENTITY_EFFECT, BLOCK_BREAK_ANIMATION
|
||||||
|
|
|
@ -128,7 +128,6 @@ public class PlayerLoader {
|
||||||
player.setGameMode(GameMode.ADVENTURE);
|
player.setGameMode(GameMode.ADVENTURE);
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
for(PotionEffect effect : player.getActivePotionEffects()) {
|
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;
|
if(effect.getType().getName().equals("INVISIBILITY") && Main.getInstance().getDisguiser().disguised(player)) continue;
|
||||||
player.removePotionEffect(effect.getType());
|
player.removePotionEffect(effect.getType());
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,10 @@ import com.comphenix.protocol.ProtocolManager;
|
||||||
import com.comphenix.protocol.events.PacketAdapter;
|
import com.comphenix.protocol.events.PacketAdapter;
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
import com.comphenix.protocol.events.PacketEvent;
|
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.Main;
|
||||||
import net.tylermurphy.hideAndSeek.game.util.Disguise;
|
import net.tylermurphy.hideAndSeek.game.util.Disguise;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -33,18 +37,14 @@ public class DisguiseHandler implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onMove(PlayerMoveEvent event) {
|
public void onMove(PlayerMoveEvent event) {
|
||||||
final Disguise disguise = Main.getInstance().getDisguiser().getDisguise(event.getPlayer());
|
final Player player = event.getPlayer();
|
||||||
if(disguise == null) return;
|
final Disguise disguise = Main.getInstance().getDisguiser().getDisguise(player);
|
||||||
final Location lastLocation = event.getPlayer().getLocation();
|
if(disguise == null) return;;
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> {
|
if(event.getFrom().distance(event.getTo()) > .1) {
|
||||||
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)
|
|
||||||
disguise.setSolidify(false);
|
disguise.setSolidify(false);
|
||||||
}
|
}
|
||||||
|
disguise.startSolidifying();
|
||||||
|
}
|
||||||
|
|
||||||
private PacketAdapter createProtocol(){
|
private PacketAdapter createProtocol(){
|
||||||
return new PacketAdapter(Main.getInstance(), USE_ENTITY) {
|
return new PacketAdapter(Main.getInstance(), USE_ENTITY) {
|
||||||
|
@ -52,6 +52,12 @@ public class DisguiseHandler implements Listener {
|
||||||
@Override
|
@Override
|
||||||
public void onPacketReceiving(PacketEvent event){
|
public void onPacketReceiving(PacketEvent event){
|
||||||
PacketContainer packet = event.getPacket();
|
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();
|
Player player = event.getPlayer();
|
||||||
int id = packet.getIntegers().read(0);
|
int id = packet.getIntegers().read(0);
|
||||||
Disguise disguise = Main.getInstance().getDisguiser().getByEntityID(id);
|
Disguise disguise = Main.getInstance().getDisguiser().getByEntityID(id);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package net.tylermurphy.hideAndSeek.game.util;
|
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.Main;
|
||||||
import net.tylermurphy.hideAndSeek.util.packet.BlockChangePacket;
|
import net.tylermurphy.hideAndSeek.util.packet.BlockChangePacket;
|
||||||
import net.tylermurphy.hideAndSeek.util.packet.EntityTeleportPacket;
|
import net.tylermurphy.hideAndSeek.util.packet.EntityTeleportPacket;
|
||||||
|
@ -20,7 +22,7 @@ public class Disguise {
|
||||||
FallingBlock block;
|
FallingBlock block;
|
||||||
Horse hitBox;
|
Horse hitBox;
|
||||||
Location blockLocation;
|
Location blockLocation;
|
||||||
boolean solid, solidify;
|
boolean solid, solidify, solidifying;
|
||||||
static Team hidden;
|
static Team hidden;
|
||||||
|
|
||||||
static {
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue