use of com.elmakers.mine.bukkit.api.block.UndoList 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.UndoList in project MagicPlugin by elBukkit.
the class ExplosionController method onEntityFinalizeExplode.
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityFinalizeExplode(EntityExplodeEvent event) {
Entity explodingEntity = event.getEntity();
if (explodingEntity == null)
return;
UndoList blockList = getExplosionUndo(explodingEntity);
if (blockList == null)
return;
if (event.isCancelled()) {
blockList.cancelExplosion(explodingEntity);
} else {
controller.disableItemSpawn();
try {
blockList.finalizeExplosion(explodingEntity, event.blockList());
} catch (Exception ex) {
controller.getLogger().log(Level.WARNING, "Error finalizing explosion", ex);
}
controller.enableItemSpawn();
}
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class HangingController method onHangingBreak.
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onHangingBreak(HangingBreakEvent event) {
final Hanging entity = event.getEntity();
if (!entity.isValid())
return;
try {
final BlockFace attachedFace = entity.getAttachedFace();
Location location = entity.getLocation();
UndoList undoList = controller.getPendingUndo(location);
if (undoList != null) {
event.setCancelled(true);
undoList.damage(entity);
} else {
location = location.getBlock().getRelative(attachedFace).getLocation();
undoList = controller.getPendingUndo(location);
if (undoList != null) {
event.setCancelled(true);
undoList.damage(entity);
}
}
} catch (Exception ex) {
controller.getLogger().log(Level.WARNING, "Failed to handle HangingBreakEvent", ex);
}
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class PlayerController method onPlayerPrePickupItem.
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerPrePickupItem(PlayerPickupItemEvent event) {
Item item = event.getItem();
ItemStack pickup = item.getItemStack();
if (NMSUtils.isTemporary(pickup) || item.hasMetadata("temporary")) {
item.remove();
event.setCancelled(true);
return;
}
boolean isWand = Wand.isWand(pickup);
// Creative mode inventory hacky work-around :\
if (event.getPlayer().getGameMode() == GameMode.CREATIVE && isWand && enableCreativeModeEjecting) {
event.setCancelled(true);
return;
}
// Check to see if this is an item we might undo, and remove it from undo
UndoList undoList = controller.getEntityUndo(item);
if (undoList != null) {
undoList.remove(item);
}
Player player = event.getPlayer();
Mage mage = controller.getMage(player);
// Remove lost wands from records
Messages messages = controller.getMessages();
if (isWand) {
Wand wand = controller.getWand(pickup);
if (!wand.canUse(player)) {
if (lastDropWarn == 0 || System.currentTimeMillis() - lastDropWarn > 10000) {
mage.sendMessage(messages.get("wand.bound").replace("$name", wand.getOwner()));
}
lastDropWarn = System.currentTimeMillis();
event.setCancelled(true);
return;
}
controller.removeLostWand(wand.getId());
}
// Wands will absorb spells and upgrade items
Wand activeWand = mage.getActiveWand();
if (activeWand != null && activeWand.isModifiable() && (Wand.isSpell(pickup) || Wand.isBrush(pickup) || Wand.isUpgrade(pickup) || Wand.isSP(pickup)) && activeWand.addItem(pickup)) {
event.getItem().remove();
event.setCancelled(true);
return;
}
if (!mage.hasStoredInventory() && isWand) {
mage.checkWandNextTick();
}
}
use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.
the class MagicController method undoRecent.
@Nullable
@Override
public UndoList undoRecent(Block target, int timeout) {
for (Mage mage : mages.values()) {
com.elmakers.mine.bukkit.api.block.UndoQueue queue = mage.getUndoQueue();
UndoList undid = queue.undoRecent(target, timeout);
if (undid != null) {
return undid;
}
}
return null;
}
Aggregations