From 06e08c630e6336ce0aa85f60b5198a4cc26494ae Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Mon, 9 Dec 2013 23:07:44 +0100 Subject: [PATCH] BlockState Hanging Punch in 1.7.2 --- pom.xml | 4 +-- .../blockstate/HangingListener.java | 30 +++++++++++++++++++ .../limitedcreative/gmperm/GMPermConfig.java | 4 ++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index a9920da..e361688 100644 --- a/pom.xml +++ b/pom.xml @@ -3,13 +3,13 @@ de.jaschastarke LimitedCreative LimitedCreative - 2.2-SNAPSHOT + 2.3-SNAPSHOT https://github.com/possi/LimitedCreative UTF-8 1.4-SNAPSHOT - 1.6.4-R1.0 + 1.7.2-R0.1-SNAPSHOT diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingListener.java index f3fad65..0977897 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingListener.java @@ -5,9 +5,11 @@ import java.util.Date; import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.entity.ItemFrame; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; @@ -48,6 +50,34 @@ public class HangingListener implements Listener { } } } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPlayerLeftInteractEntity(EntityDamageByEntityEvent event) { + if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName())) + return; + if (event.getDamager() instanceof Player && event.getEntity() instanceof ItemFrame) { + if (mod.getModel().isRestricted(event.getEntity().getLocation().getBlock())) { + if (mod.isDebug()) + mod.getLog().debug("Modifying hanging: " + event.getEntity().getLocation().toString()); + + if (((Player) event.getDamager()).getGameMode() != GameMode.CREATIVE) { + if (mod.isDebug()) + mod.getLog().debug("... was placed by creative. Modify prevented"); + event.setCancelled(true); + return; + } + } else { + BlockState s = new BlockState(); + s.setLocation(event.getEntity().getLocation().getBlock().getLocation()); + s.setPlayer((Player) event.getDamager()); + s.setDate(new Date()); + + if (mod.isDebug()) + mod.getLog().debug("Saving BlockState: " + s.toString()); + + mod.getModel().setState(s); + } + } + } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onHangingBreak(HangingBreakEvent event) { diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/GMPermConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/GMPermConfig.java index f54788e..a318aa8 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/GMPermConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/GMPermConfig.java @@ -92,7 +92,9 @@ public class GMPermConfig extends Configuration implements IConfigurationSubGrou */ @IsConfigurationNode(order = 300) public String getAdventureGroup() { - return config.getString("adventureGroup"); + if (config.isBoolean("adventureGroup")) + return null; + return config.getString("adventureGroup", null); } @Override