From b63b044085a4c4d698b19a4fcb51e957436b82bd Mon Sep 17 00:00:00 2001 From: tobyp Date: Sun, 9 Jun 2013 17:08:45 +0200 Subject: [PATCH] Added sheep-eat BlockChangeEntry for sheep eating grass, so it can be rolled back/rebuilt. --- config.yml | 1 + plugin.yml | 1 + src/uk/co/oliwali/HawkEye/DataType.java | 5 +++-- src/uk/co/oliwali/HawkEye/SearchParser.java | 2 +- .../listeners/MonitorEntityListener.java | 20 +++++++++++++++++-- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/config.yml b/config.yml index 9866f37..e4a6cac 100644 --- a/config.yml +++ b/config.yml @@ -45,6 +45,7 @@ log: worldedit-break: false crop-trample: true block-ignite: false + sheep-eat: true general: max-lines: 0 log-item-drops-on-death: false diff --git a/plugin.yml b/plugin.yml index 8c036e3..85debd7 100644 --- a/plugin.yml +++ b/plugin.yml @@ -73,3 +73,4 @@ permissions: hawkeye.search.tree-grow: true hawkeye.search.mushroom-grow: true hawkeye.search.entity-kill: true + hawkeye.search.sheep-eat: true diff --git a/src/uk/co/oliwali/HawkEye/DataType.java b/src/uk/co/oliwali/HawkEye/DataType.java index 219f687..2f272c4 100644 --- a/src/uk/co/oliwali/HawkEye/DataType.java +++ b/src/uk/co/oliwali/HawkEye/DataType.java @@ -18,7 +18,7 @@ * @author oliverw92 */ public enum DataType { - + BLOCK_BREAK(0, BlockEntry.class, "block-break", true, true), BLOCK_PLACE(1, BlockChangeEntry.class, "block-place", true, true), SIGN_PLACE(2, SignEntry.class, "sign-place", true, true), @@ -64,7 +64,8 @@ public enum DataType { WORLDEDIT_BREAK(42, BlockEntry.class, "worldedit-break", true, true), WORLDEDIT_PLACE(43, BlockChangeEntry.class, "worldedit-place", true, true), CROP_TRAMPLE(44, BlockEntry.class, "crop-trample", true, true), - BLOCK_IGNITE(45, SimpleRollbackEntry.class, "block-ignite", true, true); + BLOCK_IGNITE(45, SimpleRollbackEntry.class, "block-ignite", true, true), + SHEEP_EAT(46, BlockChangeEntry.class, "sheep-eat", true, true); private int id; private boolean canHere; diff --git a/src/uk/co/oliwali/HawkEye/SearchParser.java b/src/uk/co/oliwali/HawkEye/SearchParser.java index ab072ca..6e5469a 100644 --- a/src/uk/co/oliwali/HawkEye/SearchParser.java +++ b/src/uk/co/oliwali/HawkEye/SearchParser.java @@ -262,4 +262,4 @@ public void parseLocations() { } -} +} diff --git a/src/uk/co/oliwali/HawkEye/listeners/MonitorEntityListener.java b/src/uk/co/oliwali/HawkEye/listeners/MonitorEntityListener.java index 592e8ee..56c1d83 100644 --- a/src/uk/co/oliwali/HawkEye/listeners/MonitorEntityListener.java +++ b/src/uk/co/oliwali/HawkEye/listeners/MonitorEntityListener.java @@ -11,6 +11,7 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Painting; import org.bukkit.entity.Player; +import org.bukkit.entity.Sheep; import org.bukkit.entity.Silverfish; import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -194,11 +195,11 @@ public void onHangingPlace(HangingPlaceEvent event) { @HawkEvent(dataType = {DataType.ENDERMAN_PICKUP, DataType.ENDERMAN_PLACE}) public void onEntityChangeBlock(EntityChangeBlockEvent event) { - + if (!(event.getEntity() instanceof Enderman)) return; Block block = event.getBlock(); - + // Enderman picking up block if (event.getTo() == Material.AIR && Config.isLogged(DataType.ENDERMAN_PICKUP)) { if (block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) @@ -218,4 +219,19 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) { DataManager.addEntry(new BlockChangeEntry("Environment", DataType.ENDERMAN_PLACE, block.getLocation(), block.getState(), newState)); } } + + @HawkEvent(dataType = {DataType.SHEEP_EAT}) + public void onEntityEatBlock(EntityChangeBlockEvent event) { + + if (!(event.getEntity() instanceof Sheep)) return; + + Block block = event.getBlock(); + + // Enderman picking up block + if (Config.isLogged(DataType.SHEEP_EAT) && event.getTo() == Material.DIRT && block.getType() == Material.GRASS) { + BlockState newState =block.getState(); + newState.setType(Material.DIRT); + DataManager.addEntry(new BlockChangeEntry("Environment", DataType.SHEEP_EAT, block.getLocation(), block.getState(), newState)); + } + } }