use of com.elmakers.mine.bukkit.api.block.BlockData in project MagicPlugin by elBukkit.
the class EntityController method onItemSpawn.
@EventHandler(priority = EventPriority.LOWEST)
public void onItemSpawn(ItemSpawnEvent event) {
if (disableItemSpawn || com.elmakers.mine.bukkit.block.BlockData.undoing) {
event.setCancelled(true);
return;
}
Item itemEntity = event.getEntity();
ItemStack spawnedItem = itemEntity.getItemStack();
Block block = itemEntity.getLocation().getBlock();
BlockData undoData = com.elmakers.mine.bukkit.block.UndoList.getBlockData(block.getLocation());
boolean isBreaking = block.getType() != Material.AIR;
if (!isBreaking) {
MaterialSet doubleAttachables = controller.getMaterialSetManager().getMaterialSetEmpty("attachable_double");
isBreaking = doubleAttachables.testItem(spawnedItem);
}
if (undoData != null && isBreaking) {
// So we can catch this as a one-time event, for blocks we have recorded.
if (undoData.getMaterial() != Material.AIR) {
UndoList undoList = undoData.getUndoList();
if (undoList != null) {
undoList.add(block);
} else {
controller.getLogger().warning("Block broken into item under undo at " + block + ", but no undo list was assigned");
}
event.setCancelled(true);
return;
}
// If this was a block we built magically, don't drop items if the item being dropped
// matches the block type. This is messy, but avoid players losing all their items
// when suffocating inside a Blob
Collection<ItemStack> drops = block.getDrops();
if (drops != null) {
for (ItemStack drop : drops) {
if (drop.getType() == spawnedItem.getType()) {
com.elmakers.mine.bukkit.block.UndoList.commit(undoData);
event.setCancelled(true);
return;
}
}
}
}
if (Wand.isSkill(spawnedItem)) {
event.setCancelled(true);
return;
}
if (Wand.isWand(spawnedItem)) {
boolean invulnerable = controller.getWandProperty(spawnedItem, "invulnerable", false);
if (invulnerable) {
CompatibilityUtils.setInvulnerable(event.getEntity());
}
boolean trackWand = controller.getWandProperty(spawnedItem, "track", false);
if (trackWand) {
Wand wand = controller.getWand(spawnedItem);
controller.addLostWand(wand, event.getEntity().getLocation());
}
} else {
// registerEntityForUndo(event.getEntity());
if (ageDroppedItems > 0) {
int ticks = ageDroppedItems * 20 / 1000;
Item item = event.getEntity();
CompatibilityUtils.ageItem(item, ticks);
}
}
}
use of com.elmakers.mine.bukkit.api.block.BlockData in project MagicPlugin by elBukkit.
the class PhysicsHandler method allowPhysics.
protected boolean allowPhysics(Block block) {
if (timeout == 0) {
controller.unregisterPhysicsHandler(this);
return true;
}
long now = System.currentTimeMillis();
if (now > timeout) {
controller.unregisterPhysicsHandler(this);
timeout = 0;
return true;
}
BlockData registered = UndoList.getBlockData(block.getLocation());
if (registered == null) {
return true;
}
com.elmakers.mine.bukkit.api.block.UndoList registeredList = registered.getUndoList();
if (registeredList != null && !registeredList.getApplyPhysics()) {
timeout = Math.min(now + timeoutBuffer, timeout);
return false;
}
return true;
}
use of com.elmakers.mine.bukkit.api.block.BlockData in project MagicPlugin by elBukkit.
the class UndoList method add.
@Override
public boolean add(BlockData blockData) {
if (bypass)
return true;
if (!super.add(blockData)) {
return false;
}
modifiedTime = System.currentTimeMillis();
if (watching != null) {
BlockData attachedBlock = watching.remove(blockData.getId());
if (attachedBlock != null) {
removeFromWatched(attachedBlock);
}
}
register(blockData);
blockData.setUndoList(this);
if (loading)
return true;
addAttachable(blockData, BlockFace.NORTH, attachablesWall);
addAttachable(blockData, BlockFace.SOUTH, attachablesWall);
addAttachable(blockData, BlockFace.EAST, attachablesWall);
addAttachable(blockData, BlockFace.WEST, attachablesWall);
addAttachable(blockData, BlockFace.UP, attachables);
addAttachable(blockData, BlockFace.DOWN, attachables);
return true;
}
use of com.elmakers.mine.bukkit.api.block.BlockData in project MagicPlugin by elBukkit.
the class UndoList method remove.
@Override
public boolean remove(Object o) {
if (o instanceof BlockData) {
BlockData block = (BlockData) o;
removeFromModified(block);
}
return super.remove(o);
}
use of com.elmakers.mine.bukkit.api.block.BlockData in project MagicPlugin by elBukkit.
the class UndoList method register.
public static BlockData register(Block block) {
BlockData blockData = new com.elmakers.mine.bukkit.block.BlockData(block);
registry.registerModified(blockData);
return blockData;
}
Aggregations