idk some "cool" stuff
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
package hdvtdev.blockAndSeek.managers;
|
||||
|
||||
import hdvtdev.blockAndSeek.BlockAndSeekContainer;
|
||||
import hdvtdev.blockAndSeek.Keys;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import org.bukkit.Bukkit;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
|
||||
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.persistence.PersistentDataType;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -18,26 +19,58 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public class FreezeManager {
|
||||
|
||||
private static final Map<Player, FreezeData> frozenPlayers = new ConcurrentHashMap<>();
|
||||
private static final Map<Player, BlockData> playerDisguise = new ConcurrentHashMap<>();
|
||||
private static final Map<BlockData, Player> disguisePlayer = new ConcurrentHashMap<>();
|
||||
|
||||
private static final Vector velocity = new Vector(0, 0, 0);
|
||||
private static final Disguise hideDisguise = new MiscDisguise(DisguiseType.LLAMA_SPIT);
|
||||
private static final Vector zeroVelocity = new Vector(0, 0, 0);
|
||||
|
||||
public static boolean freeze(Player player, Material material) {
|
||||
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) {
|
||||
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);
|
||||
FreezeData data = frozenPlayers.remove(player);
|
||||
if (data != null) {
|
||||
unfreeze(player, location, data);
|
||||
}
|
||||
}
|
||||
|
||||
BlockAndSeekContainer.NO_COLLIDE_TEAM.removeEntry(player.getName());
|
||||
public static boolean unfreeze(BlockData blockData) {
|
||||
Player player = disguisePlayer.get(blockData);
|
||||
if (player != null) {
|
||||
freeze(player);
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
if (data.disguise() != null) DisguiseAPI.disguiseToAll(player, data.disguise);
|
||||
private static void unfreeze(Player player, Location location, FreezeData data) {
|
||||
|
||||
Location blockLocation = location.getBlock().getLocation();
|
||||
location.getWorld().setBlockData(blockLocation, data.blockData);
|
||||
player.getPersistentDataContainer().remove(Keys.FROZEN_PLAYER);
|
||||
|
||||
|
||||
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);
|
||||
} else {
|
||||
|
||||
Block block = location.getBlock();
|
||||
@@ -45,35 +78,37 @@ public class FreezeManager {
|
||||
Location blockLocation = block.getLocation();
|
||||
Location centerLocation = blockLocation.toCenterLocation();
|
||||
Location upperBlockLocation = centerLocation.clone();
|
||||
upperBlockLocation.setY(upperBlockLocation.getY() + 1);
|
||||
upperBlockLocation.setY(upperBlockLocation.getY() + 0.25);
|
||||
|
||||
if (!upperBlockLocation.getBlock().isSolid() && !blockLocation.getBlock().isSolid()) {
|
||||
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
p.sendBlockChange(blockLocation, material.createBlockData());
|
||||
}
|
||||
|
||||
location.getWorld().setBlockData(blockLocation, playerDisguise.get(player));
|
||||
|
||||
centerLocation.setY(centerLocation.getY() - 0.5);
|
||||
centerLocation.setY(centerLocation.getY() - 0.85);
|
||||
|
||||
player.setVelocity(velocity);
|
||||
player.setVelocity(zeroVelocity);
|
||||
player.setInvulnerable(true);
|
||||
BlockAndSeekContainer.NO_COLLIDE_TEAM.addEntry(player.getName());
|
||||
player.getPersistentDataContainer().set(Keys.FROZEN_PLAYER, PersistentDataType.BOOLEAN, true);
|
||||
Keys.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);
|
||||
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);
|
||||
});
|
||||
|
||||
|
||||
Disguise disguise = DisguiseAPI.getDisguise(player);
|
||||
|
||||
DisguiseAPI.undisguiseToAll(player);
|
||||
DisguiseAPI.disguiseToAll(player, hideDisguise);
|
||||
|
||||
|
||||
frozenPlayers.put(player, new FreezeData(armorStand, blockData, disguise));
|
||||
|
||||
Reference in New Issue
Block a user