2025-06-28 00:36:06 +03:00
|
|
|
package hdvtdev.blockAndSeek.managers;
|
|
|
|
|
|
2025-07-01 03:25:09 +03:00
|
|
|
import hdvtdev.blockAndSeek.Keys;
|
2025-06-28 00:36:06 +03:00
|
|
|
import me.libraryaddict.disguise.DisguiseAPI;
|
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
2025-07-01 03:25:09 +03:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
|
2025-06-28 00:36:06 +03:00
|
|
|
import org.bukkit.Location;
|
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
|
import org.bukkit.block.data.BlockData;
|
|
|
|
|
import org.bukkit.entity.ArmorStand;
|
|
|
|
|
import org.bukkit.entity.Player;
|
2025-07-01 03:25:09 +03:00
|
|
|
import org.bukkit.persistence.PersistentDataType;
|
2025-06-28 00:36:06 +03:00
|
|
|
import org.bukkit.util.Vector;
|
|
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
|
|
public class FreezeManager {
|
|
|
|
|
|
|
|
|
|
private static final Map<Player, FreezeData> frozenPlayers = new ConcurrentHashMap<>();
|
2025-07-01 03:25:09 +03:00
|
|
|
private static final Map<Player, BlockData> playerDisguise = new ConcurrentHashMap<>();
|
|
|
|
|
private static final Map<BlockData, Player> disguisePlayer = new ConcurrentHashMap<>();
|
2025-06-28 00:36:06 +03:00
|
|
|
|
2025-07-01 03:25:09 +03:00
|
|
|
private static final Disguise hideDisguise = new MiscDisguise(DisguiseType.LLAMA_SPIT);
|
|
|
|
|
private static final Vector zeroVelocity = new Vector(0, 0, 0);
|
2025-06-28 00:36:06 +03:00
|
|
|
|
2025-07-01 03:25:09 +03:00
|
|
|
public static void addPlayerDisguise(Player player, BlockData blockData) {
|
|
|
|
|
disguisePlayer.put(blockData, player);
|
|
|
|
|
playerDisguise.put(player, blockData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void removePlayerDisguise(Player player) {
|
|
|
|
|
disguisePlayer.remove(playerDisguise.remove(player));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void unfreezeIfFrozen(Player player) {
|
2025-06-28 00:36:06 +03:00
|
|
|
Location location = player.getLocation();
|
2025-07-01 03:25:09 +03:00
|
|
|
FreezeData data = frozenPlayers.remove(player);
|
|
|
|
|
if (data != null) {
|
|
|
|
|
unfreeze(player, location, data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean unfreeze(BlockData blockData) {
|
|
|
|
|
Player player = disguisePlayer.get(blockData);
|
|
|
|
|
if (player != null) {
|
|
|
|
|
freeze(player);
|
|
|
|
|
return true;
|
|
|
|
|
} else return false;
|
|
|
|
|
}
|
2025-06-28 00:36:06 +03:00
|
|
|
|
2025-07-01 03:25:09 +03:00
|
|
|
private static void unfreeze(Player player, Location location, FreezeData data) {
|
2025-06-28 00:36:06 +03:00
|
|
|
|
2025-07-01 03:25:09 +03:00
|
|
|
Location blockLocation = location.getBlock().getLocation();
|
|
|
|
|
location.getWorld().setBlockData(blockLocation, data.blockData);
|
|
|
|
|
player.getPersistentDataContainer().remove(Keys.FROZEN_PLAYER);
|
2025-06-28 00:36:06 +03:00
|
|
|
|
2025-07-03 02:40:14 +03:00
|
|
|
player.setFreezeTicks(0);
|
2025-07-01 03:25:09 +03:00
|
|
|
data.armorStand.remove();
|
|
|
|
|
player.setInvulnerable(false);
|
|
|
|
|
|
|
|
|
|
Keys.NO_COLLIDE_TEAM.removeEntry(player.getName());
|
|
|
|
|
|
|
|
|
|
if (data.disguise != null) DisguiseAPI.disguiseToAll(player, data.disguise);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean freeze(Player player) {
|
|
|
|
|
Location location = player.getLocation();
|
|
|
|
|
FreezeData data = frozenPlayers.remove(player);
|
|
|
|
|
if (data != null) {
|
|
|
|
|
unfreeze(player, location, data);
|
2025-06-28 00:36:06 +03:00
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
Block block = location.getBlock();
|
|
|
|
|
BlockData blockData = block.getBlockData();
|
|
|
|
|
Location blockLocation = block.getLocation();
|
|
|
|
|
Location centerLocation = blockLocation.toCenterLocation();
|
|
|
|
|
Location upperBlockLocation = centerLocation.clone();
|
2025-07-01 03:25:09 +03:00
|
|
|
upperBlockLocation.setY(upperBlockLocation.getY() + 0.25);
|
2025-06-28 00:36:06 +03:00
|
|
|
|
|
|
|
|
if (!upperBlockLocation.getBlock().isSolid() && !blockLocation.getBlock().isSolid()) {
|
|
|
|
|
|
|
|
|
|
|
2025-07-01 03:25:09 +03:00
|
|
|
location.getWorld().setBlockData(blockLocation, playerDisguise.get(player));
|
2025-06-28 00:36:06 +03:00
|
|
|
|
2025-07-01 03:25:09 +03:00
|
|
|
centerLocation.setY(centerLocation.getY() - 0.85);
|
2025-06-28 00:36:06 +03:00
|
|
|
|
2025-07-01 03:25:09 +03:00
|
|
|
player.setVelocity(zeroVelocity);
|
2025-06-28 00:36:06 +03:00
|
|
|
player.setInvulnerable(true);
|
2025-07-01 03:25:09 +03:00
|
|
|
player.getPersistentDataContainer().set(Keys.FROZEN_PLAYER, PersistentDataType.BOOLEAN, true);
|
|
|
|
|
Keys.NO_COLLIDE_TEAM.addEntry(player.getName());
|
2025-06-28 00:36:06 +03:00
|
|
|
|
|
|
|
|
|
2025-07-01 03:25:09 +03:00
|
|
|
ArmorStand armorStand = location.getWorld().spawn(centerLocation, ArmorStand.class, stand -> {
|
|
|
|
|
stand.setVisible(false);
|
|
|
|
|
stand.setVisible(false);
|
|
|
|
|
stand.setCollidable(false);
|
|
|
|
|
stand.setGravity(true);
|
|
|
|
|
stand.setSmall(true);
|
|
|
|
|
stand.setCanMove(false);
|
|
|
|
|
stand.addPassenger(player);
|
|
|
|
|
stand.getPersistentDataContainer().set(Keys.FROZEN_PLAYER, PersistentDataType.BOOLEAN, true);
|
|
|
|
|
stand.setInvulnerable(true);
|
|
|
|
|
});
|
2025-06-28 00:36:06 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
Disguise disguise = DisguiseAPI.getDisguise(player);
|
|
|
|
|
|
2025-07-01 03:25:09 +03:00
|
|
|
DisguiseAPI.disguiseToAll(player, hideDisguise);
|
2025-06-28 00:36:06 +03:00
|
|
|
|
2025-07-03 02:40:14 +03:00
|
|
|
player.setFreezeTicks(40);
|
|
|
|
|
|
2025-06-28 00:36:06 +03:00
|
|
|
|
|
|
|
|
frozenPlayers.put(player, new FreezeData(armorStand, blockData, disguise));
|
|
|
|
|
} else return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private record FreezeData(ArmorStand armorStand, BlockData blockData, Disguise disguise) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|