Block morph rewrite
This commit is contained in:
parent
0befc7d967
commit
e7dbe48937
@ -3,18 +3,10 @@ package mineplex.core.gadget.gadgets.morph;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import mineplex.core.common.util.F;
|
|
||||||
import mineplex.core.common.util.MapUtil;
|
|
||||||
import mineplex.core.common.util.UtilBlock;
|
|
||||||
import mineplex.core.common.util.UtilPlayer;
|
|
||||||
import mineplex.core.common.util.UtilServer;
|
|
||||||
import mineplex.core.disguise.disguises.DisguiseCat;
|
|
||||||
import mineplex.core.disguise.disguises.DisguiseChicken;
|
|
||||||
import mineplex.core.gadget.event.GadgetBlockEvent;
|
|
||||||
import mineplex.core.gadget.gadgets.morph.managers.UtilMorph;
|
|
||||||
import mineplex.core.itemstack.ItemStackFactory;
|
|
||||||
import mineplex.core.recharge.Recharge;
|
|
||||||
import net.minecraft.server.v1_8_R3.Entity;
|
import net.minecraft.server.v1_8_R3.Entity;
|
||||||
|
import net.minecraft.server.v1_8_R3.EntityArmorStand;
|
||||||
|
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
||||||
|
import net.minecraft.server.v1_8_R3.IBlockData;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Effect;
|
import org.bukkit.Effect;
|
||||||
@ -23,67 +15,122 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
|
||||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftFallingSand;
|
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.FallingBlock;
|
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftSlime;
|
||||||
|
import org.bukkit.craftbukkit.v1_8_R3.util.CraftMagicNumbers;
|
||||||
|
import org.bukkit.entity.ArmorStand;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.Slime;
|
||||||
|
|
||||||
|
import mineplex.core.common.util.F;
|
||||||
|
import mineplex.core.common.util.UtilBlock;
|
||||||
|
import mineplex.core.common.util.UtilEnt;
|
||||||
|
import mineplex.core.common.util.UtilPlayer;
|
||||||
|
import mineplex.core.common.util.UtilServer;
|
||||||
|
import mineplex.core.disguise.disguises.DisguiseBlock;
|
||||||
|
import mineplex.core.disguise.disguises.DisguiseSlime;
|
||||||
|
import mineplex.core.gadget.event.GadgetBlockEvent;
|
||||||
|
import mineplex.core.itemstack.ItemStackFactory;
|
||||||
|
|
||||||
public class BlockForm
|
public class BlockForm
|
||||||
{
|
{
|
||||||
private MorphBlock _host;
|
private MorphBlock _host;
|
||||||
private Player _player;
|
private Player _player;
|
||||||
|
|
||||||
private Material _mat;
|
private Material _blockMat;
|
||||||
|
private int _blockData;
|
||||||
|
|
||||||
private Block _block;
|
private Block _block;
|
||||||
private Location _loc;
|
private Location _loc;
|
||||||
|
|
||||||
public BlockForm(MorphBlock host, Player player, Material mat)
|
private Slime _fallingBlock;
|
||||||
|
private ArmorStand _fallingBlockBase;
|
||||||
|
|
||||||
|
private DisguiseBlock _disguiseBlock;
|
||||||
|
private DisguiseSlime _disguiseBlockBase;
|
||||||
|
private DisguiseSlime _hiddenDisguise;
|
||||||
|
|
||||||
|
private EntityPlayer _entityPlayer;
|
||||||
|
private Entity _nmsFallingBlockBase;
|
||||||
|
|
||||||
|
public BlockForm(MorphBlock host, Player player, Material blockMat, int blockData)
|
||||||
{
|
{
|
||||||
_host = host;
|
_host = host;
|
||||||
_player = player;
|
_player = player;
|
||||||
|
|
||||||
_mat = mat;
|
_blockMat = blockMat;
|
||||||
|
_blockData = blockData;
|
||||||
|
|
||||||
_loc = player.getLocation();
|
_loc = player.getLocation();
|
||||||
|
|
||||||
|
_entityPlayer = ((CraftPlayer) player).getHandle();
|
||||||
|
|
||||||
|
_hiddenDisguise = new DisguiseSlime(player);
|
||||||
|
_hiddenDisguise.setInvisible(true);
|
||||||
|
|
||||||
|
_host.Manager.getDisguiseManager().disguise(_hiddenDisguise);
|
||||||
|
|
||||||
|
this._fallingBlock = _loc.getWorld().spawn(_loc, Slime.class);
|
||||||
|
this._fallingBlock.setSize(0);
|
||||||
|
this._fallingBlock.setRemoveWhenFarAway(false);
|
||||||
|
UtilEnt.vegetate(this._fallingBlock, true);
|
||||||
|
UtilEnt.ghost(this._fallingBlock, true, true);
|
||||||
|
|
||||||
|
this._fallingBlockBase = (ArmorStand) new EntityArmorStand(((CraftWorld) this._loc.getWorld()).getHandle(), this._loc.getX(), this._loc.getY(), this._loc.getZ()).getBukkitEntity();
|
||||||
|
this._fallingBlockBase.setGravity(false);
|
||||||
|
this._fallingBlockBase.setVisible(false);
|
||||||
|
this._fallingBlockBase.setRemoveWhenFarAway(false);
|
||||||
|
this._fallingBlockBase.setPassenger(this._fallingBlock);
|
||||||
|
|
||||||
|
_nmsFallingBlockBase = ((CraftEntity) _fallingBlockBase).getHandle();
|
||||||
|
_disguiseBlockBase = new DisguiseSlime(_fallingBlockBase);
|
||||||
|
_disguiseBlockBase.SetSize(0);
|
||||||
|
_disguiseBlockBase.setInvisible(true);
|
||||||
|
_host.Manager.getDisguiseManager().disguise(_disguiseBlockBase);
|
||||||
|
|
||||||
Apply();
|
Apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Apply()
|
private void createFallingBlock()
|
||||||
{
|
{
|
||||||
// Remove Old
|
removeFallingBlock();
|
||||||
if (_player.getPassenger() != null)
|
|
||||||
{
|
|
||||||
Recharge.Instance.useForce(_player, "PassengerChange", 100);
|
|
||||||
|
|
||||||
_player.getPassenger().remove();
|
_disguiseBlock = new DisguiseBlock(_fallingBlock, _blockMat.getId(), _blockData);
|
||||||
_player.eject();
|
_disguiseBlock.setHideIfNotDisguised(true);
|
||||||
|
_host.Manager.getDisguiseManager().disguise(_disguiseBlock);
|
||||||
|
|
||||||
|
_fallingBlockBase.setPassenger(_fallingBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
((CraftEntity) _player).getHandle().getDataWatcher().watch(0, Byte.valueOf((byte) 32), Entity.META_ENTITYDATA, (byte) 32);
|
private void removeFallingBlock()
|
||||||
|
{
|
||||||
// Player > Chicken
|
if (_disguiseBlock != null)
|
||||||
DisguiseChicken disguise = new DisguiseChicken(_player);
|
{
|
||||||
disguise.setBaby();
|
_host.Manager.getDisguiseManager().undisguise(_disguiseBlock);
|
||||||
disguise.setSoundDisguise(new DisguiseCat(_player));
|
_disguiseBlock = null;
|
||||||
disguise.setInvisible(true);
|
_fallingBlockBase.setPassenger(null);
|
||||||
//_host.Manager.getDisguiseManager().disguise(disguise);
|
}
|
||||||
UtilMorph.disguise(_player, disguise, _host.Manager.getDisguiseManager());
|
}
|
||||||
|
|
||||||
// Apply Falling Block
|
|
||||||
FallingBlockCheck();
|
|
||||||
|
|
||||||
|
private void Apply()
|
||||||
|
{
|
||||||
|
if (_block != null)
|
||||||
|
{
|
||||||
|
SolidifyRemove(false);
|
||||||
|
}
|
||||||
|
createFallingBlock();
|
||||||
// Inform
|
// Inform
|
||||||
String blockName = F.elem(ItemStackFactory.Instance.GetName(_mat, (byte) 0, false));
|
|
||||||
if (!blockName.contains("Block"))
|
String name = ItemStackFactory.Instance.GetName(_blockMat, (byte) _blockData, false);
|
||||||
UtilPlayer
|
|
||||||
.message(
|
if (!name.contains("Block"))
|
||||||
_player,
|
{
|
||||||
F.main("Morph",
|
name = name + " Block";
|
||||||
"You are now a "
|
}
|
||||||
+ F.elem(ItemStackFactory.Instance.GetName(_mat, (byte) 0, false) + " Block") + "!"));
|
|
||||||
else
|
UtilPlayer.message(_player, F.main("Morph", "You are now " + F.vowelAN(name) + " " + F.elem(name) + "!"));
|
||||||
UtilPlayer.message(_player,
|
|
||||||
F.main("Morph", "You are now a " + F.elem(ItemStackFactory.Instance.GetName(_mat, (byte) 0, false)) + "!"));
|
|
||||||
|
|
||||||
// Sound
|
// Sound
|
||||||
_player.playSound(_player.getLocation(), Sound.ZOMBIE_UNFECT, 2f, 2f);
|
_player.playSound(_player.getLocation(), Sound.ZOMBIE_UNFECT, 2f, 2f);
|
||||||
@ -91,32 +138,39 @@ public class BlockForm
|
|||||||
|
|
||||||
public void Remove()
|
public void Remove()
|
||||||
{
|
{
|
||||||
SolidifyRemove();
|
SolidifyRemove(false);
|
||||||
|
removeFallingBlock();
|
||||||
|
|
||||||
//_host.Manager.getDisguiseManager().undisguise(_player);
|
_host.Manager.getDisguiseManager().undisguise(_hiddenDisguise);
|
||||||
UtilMorph.undisguise(_player, _host.Manager.getDisguiseManager());
|
_host.Manager.getDisguiseManager().undisguise(_disguiseBlockBase);
|
||||||
|
_fallingBlockBase.remove();
|
||||||
// Remove FB
|
_fallingBlockBase = null;
|
||||||
if (_player.getPassenger() != null)
|
_fallingBlock.remove();
|
||||||
{
|
_fallingBlock = null;
|
||||||
Recharge.Instance.useForce(_player, "PassengerChange", 100);
|
_nmsFallingBlockBase = null;
|
||||||
|
|
||||||
_player.getPassenger().remove();
|
|
||||||
_player.eject();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
((CraftEntity) _player).getHandle().getDataWatcher().watch(0, Byte.valueOf((byte) 0), Entity.META_ENTITYDATA, (byte) 0);
|
public void update()
|
||||||
}
|
|
||||||
|
|
||||||
public void SolidifyUpdate()
|
|
||||||
{
|
{
|
||||||
if (!_player.isSprinting())
|
|
||||||
((CraftEntity) _player).getHandle().getDataWatcher()
|
|
||||||
.watch(0, Byte.valueOf((byte) 32), Entity.META_ENTITYDATA, (byte) 32);
|
|
||||||
|
|
||||||
// Not a Block
|
// Not a Block
|
||||||
if (_block == null)
|
if (_block == null)
|
||||||
{
|
{
|
||||||
|
if (_fallingBlockBase.getPassenger() != _fallingBlock)
|
||||||
|
_fallingBlockBase.setPassenger(_fallingBlock);
|
||||||
|
|
||||||
|
if (!_nmsFallingBlockBase.getBukkitEntity().getWorld().equals(_player.getWorld()))
|
||||||
|
_nmsFallingBlockBase.getBukkitEntity().teleport(_player);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_nmsFallingBlockBase.locX = _entityPlayer.locX;
|
||||||
|
_nmsFallingBlockBase.locY = _entityPlayer.locY;
|
||||||
|
_nmsFallingBlockBase.locZ = _entityPlayer.locZ;
|
||||||
|
_nmsFallingBlockBase.motX = _entityPlayer.motX;
|
||||||
|
_nmsFallingBlockBase.motY = _entityPlayer.motY;
|
||||||
|
_nmsFallingBlockBase.motZ = _entityPlayer.motZ;
|
||||||
|
_nmsFallingBlockBase.velocityChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Moved
|
// Moved
|
||||||
if (!_loc.getBlock().equals(_player.getLocation().getBlock()))
|
if (!_loc.getBlock().equals(_player.getLocation().getBlock()))
|
||||||
{
|
{
|
||||||
@ -135,7 +189,7 @@ public class BlockForm
|
|||||||
{
|
{
|
||||||
Block block = _player.getLocation().getBlock();
|
Block block = _player.getLocation().getBlock();
|
||||||
|
|
||||||
List<Block> blockList = new ArrayList<Block>();
|
List<Block> blockList = new ArrayList<>();
|
||||||
blockList.add(block);
|
blockList.add(block);
|
||||||
|
|
||||||
GadgetBlockEvent event = new GadgetBlockEvent(_host, blockList);
|
GadgetBlockEvent event = new GadgetBlockEvent(_host, blockList);
|
||||||
@ -155,14 +209,15 @@ public class BlockForm
|
|||||||
_block = block;
|
_block = block;
|
||||||
|
|
||||||
// Effect
|
// Effect
|
||||||
_player.playEffect(_player.getLocation(), Effect.STEP_SOUND, _mat);
|
_player.playEffect(_player.getLocation(), Effect.STEP_SOUND, _blockMat);
|
||||||
// block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, _mat);
|
|
||||||
|
removeFallingBlock();
|
||||||
|
|
||||||
// Display
|
// Display
|
||||||
SolidifyVisual();
|
for (Player other : UtilServer.getPlayers())
|
||||||
|
{
|
||||||
// Invisible
|
other.sendBlockChange(_player.getLocation(), _blockMat, (byte) _blockData);
|
||||||
// Host.Manager.GetCondition().Factory().Cloak("Disguised as Block", Player, Player, 60000, false, false);
|
}
|
||||||
|
|
||||||
// Sound
|
// Sound
|
||||||
_player.playSound(_player.getLocation(), Sound.NOTE_PLING, 1f, 2f);
|
_player.playSound(_player.getLocation(), Sound.NOTE_PLING, 1f, 2f);
|
||||||
@ -175,93 +230,62 @@ public class BlockForm
|
|||||||
// Moved
|
// Moved
|
||||||
if (!_loc.getBlock().equals(_player.getLocation().getBlock()))
|
if (!_loc.getBlock().equals(_player.getLocation().getBlock()))
|
||||||
{
|
{
|
||||||
SolidifyRemove();
|
SolidifyRemove(true);
|
||||||
}
|
|
||||||
// Send Packets
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SolidifyVisual();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SolidifyRemove()
|
private void SolidifyRemove(boolean create)
|
||||||
{
|
{
|
||||||
if (_block != null)
|
if (_block != null)
|
||||||
{
|
{
|
||||||
MapUtil.QuickChangeBlockAt(_block.getLocation(), 0, (byte) 0);
|
Location location = _block.getLocation();
|
||||||
_block = null;
|
_block = null;
|
||||||
|
|
||||||
|
for (Player other : UtilServer.getPlayers())
|
||||||
|
{
|
||||||
|
other.sendBlockChange(location, 0, (byte) 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
_player.setExp(0f);
|
_player.setExp(0f);
|
||||||
|
|
||||||
// Host.Manager.GetCondition().EndCondition(Player, null, "Disguised as Block");
|
|
||||||
|
|
||||||
// Inform
|
// Inform
|
||||||
_player.playSound(_player.getLocation(), Sound.NOTE_PLING, 1f, 0.5f);
|
_player.playSound(_player.getLocation(), Sound.NOTE_PLING, 1f, 0.5f);
|
||||||
|
|
||||||
FallingBlockCheck();
|
if (create)
|
||||||
|
createFallingBlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
public void reset(Block block)
|
||||||
public void SolidifyVisual()
|
|
||||||
{
|
{
|
||||||
if (_block == null)
|
if (block == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Remove Old
|
if (block.getType() == Material.AIR)
|
||||||
if (_player.getPassenger() != null)
|
|
||||||
{
|
|
||||||
Recharge.Instance.useForce(_player, "PassengerChange", 100);
|
|
||||||
|
|
||||||
_player.getPassenger().remove();
|
|
||||||
_player.eject();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Others
|
|
||||||
for (Player other : UtilServer.getPlayers())
|
|
||||||
other.sendBlockChange(_player.getLocation(), _mat, (byte) 0);
|
|
||||||
|
|
||||||
// Self
|
|
||||||
_player.sendBlockChange(_player.getLocation(), 36, (byte) 0);
|
|
||||||
|
|
||||||
FallingBlockCheck();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void FallingBlockCheck()
|
|
||||||
{
|
|
||||||
// Block Form (Hide Falling)
|
|
||||||
if (_block != null)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Recreate Falling
|
if (_blockMat == block.getType() && _blockData == block.getData())
|
||||||
if (_player.getPassenger() == null || !_player.getPassenger().isValid())
|
|
||||||
{
|
|
||||||
if (!Recharge.Instance.use(_player, "PassengerChange", 100, false, false))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Falling Block
|
_blockMat = block.getType();
|
||||||
FallingBlock block = _player.getWorld().spawnFallingBlock(_player.getEyeLocation(), _mat, (byte) 0);
|
_blockData = block.getData();
|
||||||
|
|
||||||
// No Arrow Collision
|
Apply();
|
||||||
((CraftFallingSand) block).getHandle().spectating = true;
|
|
||||||
|
|
||||||
_player.setPassenger(block);
|
|
||||||
|
|
||||||
_host.fallingBlockRegister(block);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure Falling doesnt Despawn
|
public Block getBlock()
|
||||||
else
|
|
||||||
{
|
|
||||||
((CraftFallingSand) _player.getPassenger()).getHandle().ticksLived = 1;
|
|
||||||
_player.getPassenger().setTicksLived(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Block GetBlock()
|
|
||||||
{
|
{
|
||||||
return _block;
|
return _block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IBlockData getBlockData()
|
||||||
|
{
|
||||||
|
return CraftMagicNumbers.getBlock(_blockMat).fromLegacyData(_blockData);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer()
|
||||||
|
{
|
||||||
|
return this._player;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,36 +1,38 @@
|
|||||||
package mineplex.core.gadget.gadgets.morph;
|
package mineplex.core.gadget.gadgets.morph;
|
||||||
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.Map;
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_8_R3.Blocks;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayInBlockDig;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayOutBlockChange;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityVelocity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.FallingBlock;
|
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
|
||||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
import mineplex.core.common.util.C;
|
import mineplex.core.common.util.C;
|
||||||
import mineplex.core.common.util.LineFormat;
|
import mineplex.core.common.util.LineFormat;
|
||||||
import mineplex.core.common.util.UtilBlock;
|
|
||||||
import mineplex.core.common.util.UtilEvent;
|
import mineplex.core.common.util.UtilEvent;
|
||||||
import mineplex.core.common.util.UtilMath;
|
|
||||||
import mineplex.core.common.util.UtilText;
|
|
||||||
import mineplex.core.common.util.UtilEvent.ActionType;
|
import mineplex.core.common.util.UtilEvent.ActionType;
|
||||||
import mineplex.core.event.StackerEvent;
|
import mineplex.core.common.util.UtilPlayer;
|
||||||
|
import mineplex.core.common.util.UtilText;
|
||||||
import mineplex.core.gadget.GadgetManager;
|
import mineplex.core.gadget.GadgetManager;
|
||||||
import mineplex.core.gadget.types.MorphGadget;
|
import mineplex.core.gadget.types.MorphGadget;
|
||||||
|
import mineplex.core.packethandler.IPacketHandler;
|
||||||
|
import mineplex.core.packethandler.PacketInfo;
|
||||||
import mineplex.core.recharge.Recharge;
|
import mineplex.core.recharge.Recharge;
|
||||||
import mineplex.core.updater.UpdateType;
|
import mineplex.core.updater.UpdateType;
|
||||||
import mineplex.core.updater.event.UpdateEvent;
|
import mineplex.core.utils.UtilScheduler;
|
||||||
|
|
||||||
public class MorphBlock extends MorphGadget
|
public class MorphBlock extends MorphGadget implements IPacketHandler
|
||||||
{
|
{
|
||||||
private HashMap<Player, BlockForm> _active = new HashMap<Player, BlockForm>();
|
private Map<Player, BlockForm> _active = new HashMap<>();
|
||||||
private HashSet<FallingBlock> _blocks = new HashSet<FallingBlock>();
|
|
||||||
|
|
||||||
public MorphBlock(GadgetManager manager)
|
public MorphBlock(GadgetManager manager)
|
||||||
{
|
{
|
||||||
@ -42,7 +44,11 @@ public class MorphBlock extends MorphGadget
|
|||||||
"#" + C.cWhite + "Stay Still to use Solidify",
|
"#" + C.cWhite + "Stay Still to use Solidify",
|
||||||
}, LineFormat.LORE),
|
}, LineFormat.LORE),
|
||||||
30000,
|
30000,
|
||||||
Material.EMERALD_BLOCK, (byte)0);
|
Material.EMERALD_BLOCK, (byte) 0);
|
||||||
|
|
||||||
|
UtilScheduler.runEvery(UpdateType.TICK, () -> _active.values().forEach(BlockForm::update));
|
||||||
|
|
||||||
|
manager.getPacketManager().addPacketHandler(this, PacketPlayOutBlockChange.class, PacketPlayInBlockDig.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -50,7 +56,7 @@ public class MorphBlock extends MorphGadget
|
|||||||
{
|
{
|
||||||
this.applyArmor(player, message);
|
this.applyArmor(player, message);
|
||||||
|
|
||||||
_active.put(player, new BlockForm(this, player, Material.EMERALD_BLOCK));
|
_active.put(player, new BlockForm(this, player, Material.EMERALD_BLOCK, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -58,7 +64,6 @@ public class MorphBlock extends MorphGadget
|
|||||||
{
|
{
|
||||||
this.removeArmor(player);
|
this.removeArmor(player);
|
||||||
|
|
||||||
|
|
||||||
BlockForm form = _active.remove(player);
|
BlockForm form = _active.remove(player);
|
||||||
if (form != null)
|
if (form != null)
|
||||||
{
|
{
|
||||||
@ -66,19 +71,6 @@ public class MorphBlock extends MorphGadget
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void formUpdate(UpdateEvent event)
|
|
||||||
{
|
|
||||||
if (event.getType() != UpdateType.TICK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (BlockForm form : _active.values())
|
|
||||||
{
|
|
||||||
form.SolidifyUpdate();
|
|
||||||
form.FallingBlockCheck();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void formChange(PlayerInteractEvent event)
|
public void formChange(PlayerInteractEvent event)
|
||||||
{
|
{
|
||||||
@ -88,9 +80,6 @@ public class MorphBlock extends MorphGadget
|
|||||||
if (!UtilEvent.isAction(event, ActionType.L_BLOCK) && !UtilEvent.isAction(event, ActionType.R_BLOCK))
|
if (!UtilEvent.isAction(event, ActionType.L_BLOCK) && !UtilEvent.isAction(event, ActionType.R_BLOCK))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!UtilBlock.solid(event.getClickedBlock()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!Recharge.Instance.use(event.getPlayer(), getName(), 500, false, false))
|
if (!Recharge.Instance.use(event.getPlayer(), getName(), 500, false, false))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -99,67 +88,50 @@ public class MorphBlock extends MorphGadget
|
|||||||
if (form == null)
|
if (form == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
form.Remove();
|
form.reset(event.getClickedBlock());
|
||||||
|
|
||||||
_active.put(event.getPlayer(), new BlockForm(this, event.getPlayer(), event.getClickedBlock().getType()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@Override
|
||||||
public void stacker(StackerEvent event)
|
public void handle(PacketInfo packetInfo)
|
||||||
{
|
{
|
||||||
if (_active.containsKey(event.getEntity()))
|
if (packetInfo.getPacket() instanceof PacketPlayOutBlockChange)
|
||||||
event.setCancelled(true);
|
{
|
||||||
|
PacketPlayOutBlockChange packet = (PacketPlayOutBlockChange) packetInfo.getPacket();
|
||||||
|
|
||||||
|
for (BlockForm form : _active.values())
|
||||||
|
{
|
||||||
|
if (form.getBlock() == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Location location = form.getBlock().getLocation();
|
||||||
|
if (packetInfo.getPlayer().getWorld() == location.getWorld() && packet.a.getX() == location.getX() && packet.a.getY() == location.getY() && packet.a.getZ() == location.getZ())
|
||||||
|
{
|
||||||
|
if (packetInfo.getPlayer() == form.getPlayer())
|
||||||
|
{
|
||||||
|
packet.block = Blocks.AIR.getBlockData();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
public void fallingBlockRegister(FallingBlock block)
|
|
||||||
{
|
{
|
||||||
_blocks.add(block);
|
packet.block = form.getBlockData();
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void fallingBlockForm(EntityChangeBlockEvent event)
|
|
||||||
{
|
|
||||||
if (_blocks.remove(event.getEntity()))
|
|
||||||
{
|
|
||||||
event.getEntity().remove();
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void fallingBlockClean(UpdateEvent event)
|
|
||||||
{
|
|
||||||
if (event.getType() != UpdateType.SEC)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Iterator<FallingBlock> blockIterator = _blocks.iterator();
|
|
||||||
|
|
||||||
while (blockIterator.hasNext())
|
|
||||||
{
|
|
||||||
FallingBlock block = blockIterator.next();
|
|
||||||
|
|
||||||
if (!block.isValid() || block.getVehicle() == null)
|
|
||||||
{
|
|
||||||
block.remove();
|
|
||||||
blockIterator.remove();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@EventHandler
|
else if (packetInfo.getPacket() instanceof PacketPlayInBlockDig)
|
||||||
public void itemSpawnCancel(ItemSpawnEvent event)
|
|
||||||
{
|
{
|
||||||
Iterator<FallingBlock> blockIterator = _blocks.iterator();
|
PacketPlayInBlockDig packet = (PacketPlayInBlockDig) packetInfo.getPacket();
|
||||||
|
|
||||||
while (blockIterator.hasNext())
|
for (BlockForm form : _active.values())
|
||||||
{
|
{
|
||||||
FallingBlock block = blockIterator.next();
|
if (form.getBlock() == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (UtilMath.offset(block, event.getEntity()) < 0.1)
|
Location location = form.getBlock().getLocation();
|
||||||
|
if (packetInfo.getPlayer().getWorld() == location.getWorld() && packet.a.getX() == location.getX() && packet.a.getY() == location.getY() && packet.a.getZ() == location.getZ())
|
||||||
{
|
{
|
||||||
block.remove();
|
packetInfo.setCancelled(true);
|
||||||
blockIterator.remove();
|
packetInfo.getPlayer().sendBlockChange(location, 0, (byte) 0);
|
||||||
event.setCancelled(true);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user