This commit is contained in:
samczsun 2017-02-11 21:56:40 -05:00 committed by cnr
parent e7dbe48937
commit ecb42d91fe
4 changed files with 48 additions and 6 deletions

View File

@ -50,6 +50,7 @@ import org.bukkit.util.Vector;
public class UtilEnt public class UtilEnt
{ {
public static final String FLAG_NO_REMOVE = "noremove";
//Custom Entity Names //Custom Entity Names
private static HashMap<Entity, String> _nameMap = new HashMap<Entity, String>(); private static HashMap<Entity, String> _nameMap = new HashMap<Entity, String>();
@ -77,6 +78,27 @@ public class UtilEnt
//((CraftEntity)entity).getHandle().setSilent(silence); //((CraftEntity)entity).getHandle().setSilent(silence);
} }
public static void addFlag(Entity entity, String flag)
{
if (entity == null)
return;
entity.setMetadata("flag:" + flag, new FixedMetadataValue(UtilServer.getPlugin(), true));
}
public static void removeFlag(Entity entity, String flag)
{
if (entity == null)
return;
entity.removeMetadata("flag:" + flag, UtilServer.getPlugin());
}
public static boolean hasFlag(Entity entity, String flag)
{
return entity.hasMetadata("flag:" + flag);
}
public static void ghost(Entity entity, boolean ghost, boolean invisible) public static void ghost(Entity entity, boolean ghost, boolean invisible)
{ {
if (entity instanceof LivingEntity) if (entity instanceof LivingEntity)

View File

@ -18,7 +18,6 @@ import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; 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.CraftPlayer; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftSlime;
import org.bukkit.craftbukkit.v1_8_R3.util.CraftMagicNumbers; import org.bukkit.craftbukkit.v1_8_R3.util.CraftMagicNumbers;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -84,6 +83,11 @@ public class BlockForm
this._fallingBlockBase.setRemoveWhenFarAway(false); this._fallingBlockBase.setRemoveWhenFarAway(false);
this._fallingBlockBase.setPassenger(this._fallingBlock); this._fallingBlockBase.setPassenger(this._fallingBlock);
UtilEnt.addFlag(this._fallingBlock, UtilEnt.FLAG_NO_REMOVE);
UtilEnt.addFlag(this._fallingBlock, MorphBlock.FLAG_BLOCK_MORPH_COMPONENT);
UtilEnt.addFlag(this._fallingBlockBase, UtilEnt.FLAG_NO_REMOVE);
UtilEnt.addFlag(this._fallingBlockBase, MorphBlock.FLAG_BLOCK_MORPH_COMPONENT);
_nmsFallingBlockBase = ((CraftEntity) _fallingBlockBase).getHandle(); _nmsFallingBlockBase = ((CraftEntity) _fallingBlockBase).getHandle();
_disguiseBlockBase = new DisguiseSlime(_fallingBlockBase); _disguiseBlockBase = new DisguiseSlime(_fallingBlockBase);
_disguiseBlockBase.SetSize(0); _disguiseBlockBase.SetSize(0);
@ -209,18 +213,18 @@ public class BlockForm
_block = block; _block = block;
// Effect // Effect
_player.playEffect(_player.getLocation(), Effect.STEP_SOUND, _blockMat); _player.playEffect(_block.getLocation(), Effect.STEP_SOUND, _blockMat);
removeFallingBlock(); removeFallingBlock();
// Display // Display
for (Player other : UtilServer.getPlayers()) for (Player other : UtilServer.getPlayers())
{ {
other.sendBlockChange(_player.getLocation(), _blockMat, (byte) _blockData); other.sendBlockChange(_block.getLocation(), _blockMat, (byte) _blockData);
} }
// Sound // Sound
_player.playSound(_player.getLocation(), Sound.NOTE_PLING, 1f, 2f); _player.playSound(_block.getLocation(), Sound.NOTE_PLING, 1f, 2f);
} }
} }
} }

View File

@ -14,10 +14,12 @@ import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; 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.EntityDamageEvent;
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.UtilEnt;
import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
@ -32,6 +34,8 @@ import mineplex.core.utils.UtilScheduler;
public class MorphBlock extends MorphGadget implements IPacketHandler public class MorphBlock extends MorphGadget implements IPacketHandler
{ {
public static final String FLAG_BLOCK_MORPH_COMPONENT = "block-morph-component";
private Map<Player, BlockForm> _active = new HashMap<>(); private Map<Player, BlockForm> _active = new HashMap<>();
public MorphBlock(GadgetManager manager) public MorphBlock(GadgetManager manager)
@ -91,6 +95,15 @@ public class MorphBlock extends MorphGadget implements IPacketHandler
form.reset(event.getClickedBlock()); form.reset(event.getClickedBlock());
} }
@EventHandler
public void onDamage(EntityDamageEvent event)
{
if (UtilEnt.hasFlag(event.getEntity(), FLAG_BLOCK_MORPH_COMPONENT))
{
event.setCancelled(true);
}
}
@Override @Override
public void handle(PacketInfo packetInfo) public void handle(PacketInfo packetInfo)
{ {

View File

@ -60,6 +60,7 @@ import mineplex.core.common.Rank;
import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.currency.GlobalCurrency;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
@ -710,9 +711,11 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
event.getEntity().leaveVehicle(); event.getEntity().leaveVehicle();
event.getEntity().teleport(GetSpawn()); event.getEntity().teleport(GetSpawn());
} }
else else
{
if (!UtilEnt.hasFlag(event.getEntity(), UtilEnt.FLAG_NO_REMOVE))
event.getEntity().remove(); event.getEntity().remove();
}
event.setCancelled(true); event.setCancelled(true);
} }