93 lines
3.1 KiB
Java
93 lines
3.1 KiB
Java
|
|
package hdvtdev.blockAndSeek.managers;
|
||
|
|
|
||
|
|
import hdvtdev.blockAndSeek.BlockAndSeekContainer;
|
||
|
|
import me.libraryaddict.disguise.DisguiseAPI;
|
||
|
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||
|
|
import org.bukkit.Bukkit;
|
||
|
|
import org.bukkit.Location;
|
||
|
|
import org.bukkit.Material;
|
||
|
|
import org.bukkit.block.Block;
|
||
|
|
import org.bukkit.block.data.BlockData;
|
||
|
|
import org.bukkit.entity.ArmorStand;
|
||
|
|
import org.bukkit.entity.Player;
|
||
|
|
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<>();
|
||
|
|
|
||
|
|
private static final Vector velocity = new Vector(0, 0, 0);
|
||
|
|
|
||
|
|
public static boolean freeze(Player player, Material material) {
|
||
|
|
Location location = player.getLocation();
|
||
|
|
if (frozenPlayers.containsKey(player)) {
|
||
|
|
FreezeData data = frozenPlayers.remove(player);
|
||
|
|
Location blockLocation = location.getBlock().getLocation();
|
||
|
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||
|
|
p.sendBlockChange(blockLocation, data.blockData);
|
||
|
|
}
|
||
|
|
ArmorStand armorStand = data.armorStand;
|
||
|
|
armorStand.removePassenger(player);
|
||
|
|
armorStand.remove();
|
||
|
|
player.setInvulnerable(false);
|
||
|
|
|
||
|
|
BlockAndSeekContainer.NO_COLLIDE_TEAM.removeEntry(player.getName());
|
||
|
|
|
||
|
|
if (data.disguise() != null) DisguiseAPI.disguiseToAll(player, data.disguise);
|
||
|
|
|
||
|
|
} else {
|
||
|
|
|
||
|
|
Block block = location.getBlock();
|
||
|
|
BlockData blockData = block.getBlockData();
|
||
|
|
Location blockLocation = block.getLocation();
|
||
|
|
Location centerLocation = blockLocation.toCenterLocation();
|
||
|
|
Location upperBlockLocation = centerLocation.clone();
|
||
|
|
upperBlockLocation.setY(upperBlockLocation.getY() + 1);
|
||
|
|
|
||
|
|
if (!upperBlockLocation.getBlock().isSolid() && !blockLocation.getBlock().isSolid()) {
|
||
|
|
|
||
|
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||
|
|
p.sendBlockChange(blockLocation, material.createBlockData());
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
centerLocation.setY(centerLocation.getY() - 0.5);
|
||
|
|
|
||
|
|
player.setVelocity(velocity);
|
||
|
|
player.setInvulnerable(true);
|
||
|
|
BlockAndSeekContainer.NO_COLLIDE_TEAM.addEntry(player.getName());
|
||
|
|
|
||
|
|
|
||
|
|
ArmorStand armorStand = location.getWorld().spawn(centerLocation, ArmorStand.class);
|
||
|
|
armorStand.setInvulnerable(true);
|
||
|
|
armorStand.setSmall(true);
|
||
|
|
armorStand.setGravity(true);
|
||
|
|
armorStand.setCanMove(false);
|
||
|
|
armorStand.setInvisible(true);
|
||
|
|
armorStand.setCollidable(false);
|
||
|
|
armorStand.addPassenger(player);
|
||
|
|
|
||
|
|
|
||
|
|
Disguise disguise = DisguiseAPI.getDisguise(player);
|
||
|
|
|
||
|
|
DisguiseAPI.undisguiseToAll(player);
|
||
|
|
|
||
|
|
|
||
|
|
frozenPlayers.put(player, new FreezeData(armorStand, blockData, disguise));
|
||
|
|
} else return false;
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
private record FreezeData(ArmorStand armorStand, BlockData blockData, Disguise disguise) {
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|