From db96bf5395f59dc0ca8588ad910aa9b09091569d Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 18 Sep 2013 08:03:19 +0300 Subject: [PATCH] Add "block spreads", "block forms" and "entity forms block" world events. --- .../containers/core/WorldScriptHelper.java | 137 ++++++++++++++++-- 1 file changed, 127 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/aufdemrand/denizen/scripts/containers/core/WorldScriptHelper.java b/src/main/java/net/aufdemrand/denizen/scripts/containers/core/WorldScriptHelper.java index a9523f3162..7ed8c99338 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/containers/core/WorldScriptHelper.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/containers/core/WorldScriptHelper.java @@ -56,6 +56,7 @@ import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockDispenseEvent; import org.bukkit.event.block.BlockFadeEvent; +import org.bukkit.event.block.BlockFormEvent; import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.block.BlockGrowEvent; import org.bukkit.event.block.BlockIgniteEvent; @@ -64,6 +65,8 @@ import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockRedstoneEvent; +import org.bukkit.event.block.BlockSpreadEvent; +import org.bukkit.event.block.EntityBlockFormEvent; import org.bukkit.event.block.LeavesDecayEvent; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.enchantment.EnchantItemEvent; @@ -499,14 +502,48 @@ public void blockFade(BlockFadeEvent event) { // <--[event] // @Events - // block spreads - // spreads + // block forms + // forms + // + // @Triggers when a block is formed based on world conditions, + // e.g. when snow forms in a snow storm or ice forms + // in a snowy biome + // @Context + // returns the dLocation the block. + // returns the dMaterial of the block. + // + // @Determine + // "CANCELLED" to stop the block from forming. + // + // --> + @EventHandler + public void blockForm(BlockFormEvent event) { + + Map context = new HashMap(); + dMaterial material = new dMaterial(event.getBlock().getType()); + + context.put("location", new dLocation(event.getBlock().getLocation())); + context.put("material", material); + + String determination = doEvents(Arrays.asList + ("block forms", + material.identify() + " forms"), + null, null, context); + + if (determination.toUpperCase().startsWith("CANCELLED")) + event.setCancelled(true); + } + + // <--[event] + // @Events + // liquid spreads + // spreads // // @Triggers when a liquid block spreads. // @Context // returns the dLocation the block spread to. // returns the dLocation the block spread from. - // returns the dMaterial of the block that spread. + // returns the dMaterial of the block that spread. // // @Determine // "CANCELLED" to stop the block from spreading. @@ -523,7 +560,7 @@ public void blockFromTo(BlockFromToEvent event) { context.put("material", material); String determination = doEvents(Arrays.asList - ("block spreads", + ("liquid spreads", material.identify() + " spreads"), null, null, context); @@ -536,7 +573,9 @@ public void blockFromTo(BlockFromToEvent event) { // block grows // grows // - // @Triggers when a block grows naturally in the world. + // @Triggers when a block grows naturally in the world, + // e.g. when wheat, sugar canes, cactuses, + // watermelons or pumpkins grow // @Context // returns the dLocation the block. // returns the dMaterial of the block. @@ -730,15 +769,15 @@ public void blockPlace(BlockPlaceEvent event) { // <--[event] // @Events - // block powered - // powered - // block unpowered - // unpowered + // block powers + // powers + // block unpowers + // unpowers // // @Triggers when a block is (un)powered. // @Context // returns the dLocation of the block that was (un)powered. - // returns the dMaterial of the block that was (un)powered. + // returns the dMaterial of the block that was (un)powered. // // @Determine // "CANCELLED" to stop the block from being (un)powered. @@ -756,10 +795,14 @@ public void blockRedstone(BlockRedstoneEvent event) { List events = new ArrayList(); if (event.getNewCurrent() > 0) { + events.add("block powers"); + events.add(material.identify() + " powers"); events.add("block powered"); events.add(material.identify() + " powered"); } else { + events.add("block unpowers"); + events.add(material.identify() + " unpowers"); events.add("block unpowered"); events.add(material.identify() + " unpowered"); } @@ -770,6 +813,39 @@ public void blockRedstone(BlockRedstoneEvent event) { event.setNewCurrent(event.getOldCurrent()); } + // <--[event] + // @Events + // block grows + // grows + // + // @Triggers when a block spreads based on world conditions, + // e.g. when fire spreads, when mushrooms spread + // @Context + // returns the dLocation the block. + // returns the dMaterial of the block. + // + // @Determine + // "CANCELLED" to stop the block from growing. + // + // --> + @EventHandler + public void blockSpread(BlockSpreadEvent event) { + + Map context = new HashMap(); + dMaterial material = new dMaterial(event.getBlock().getType()); + + context.put("location", new dLocation(event.getBlock().getLocation())); + context.put("material", material); + + String determination = doEvents(Arrays.asList + ("block spreads", + material.identify() + " spreads"), + null, null, context); + + if (determination.toUpperCase().startsWith("CANCELLED")) + event.setCancelled(true); + } + // <--[event] // @Events // brewing stand brews @@ -799,6 +875,47 @@ public void brew(BrewEvent event) { event.setCancelled(true); } + // <--[event] + // @Events + // entity forms block + // entity forms + // forms block + // forms + // + // @Triggers when a block is formed by an entity, + // e.g. when a snowman forms snow + // @Context + // returns the dLocation the block. + // returns the dMaterial of the block. + // returns the dEntity that formed the block. + // + // @Determine + // "CANCELLED" to stop the block from forming. + // + // --> + @EventHandler + public void entityBlockForm(EntityBlockFormEvent event) { + + Map context = new HashMap(); + dMaterial material = new dMaterial(event.getBlock().getType()); + dEntity entity = new dEntity(event.getEntity()); + String entityType = entity.getEntityType().name(); + + context.put("location", new dLocation(event.getBlock().getLocation())); + context.put("material", material); + context.put("entity", entity.getDenizenObject()); + + String determination = doEvents(Arrays.asList + ("entity forms block", + "entity forms " + material.identify(), + entityType + " forms block", + entityType + " forms " + material.identify()), + null, null, context); + + if (determination.toUpperCase().startsWith("CANCELLED")) + event.setCancelled(true); + } + // <--[event] // @Events // furnace burns item