From f545debb9738444efd0aa418ef51013061b8b347 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Sat, 26 Oct 2013 18:19:35 +0200 Subject: [PATCH] ItemFrame (Hanging) Handling --- .../limitedcreative/LimitedCreative.java | 2 ++ .../limitedcreative/ModBlockStates.java | 2 ++ .../limitedcreative/ModCreativeLimits.java | 2 ++ .../limitedcreative/limits/BlockListener.java | 9 ++++++++ .../regions/BlockListener.java | 21 +++++++++++++++++++ 5 files changed, 36 insertions(+) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/LimitedCreative.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/LimitedCreative.java index 3854d27..b7d3843 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/LimitedCreative.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/LimitedCreative.java @@ -5,6 +5,7 @@ import de.jaschastarke.bukkit.lib.Core; import de.jaschastarke.bukkit.lib.PluginLang; import de.jaschastarke.bukkit.lib.configuration.command.ConfigCommand; import de.jaschastarke.bukkit.lib.modules.AdditionalBlockBreaks; +import de.jaschastarke.bukkit.lib.modules.InstantHangingBreak; import de.jaschastarke.utils.ClassDescriptorStorage; public class LimitedCreative extends Core { @@ -27,6 +28,7 @@ public class LimitedCreative extends Core { Hooks.inizializeHooks(this); modules.addSharedModule(new AdditionalBlockBreaks(this)); + modules.addSharedModule(new InstantHangingBreak(this)); modules.addSharedModule(new FeatureBlockItemSpawn(this)); addModule(new FeatureSwitchGameMode(this)); addModule(new ModInventories(this)); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java index 105c5fe..0360a42 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java @@ -6,6 +6,7 @@ import de.jaschastarke.bukkit.lib.CoreModule; import de.jaschastarke.bukkit.lib.commands.AliasHelpedCommand; import de.jaschastarke.bukkit.lib.modules.AdditionalBlockBreaks; import de.jaschastarke.bukkit.lib.modules.BlockFall; +import de.jaschastarke.bukkit.lib.modules.InstantHangingBreak; import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockListener; import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateCommand; import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateConfig; @@ -42,6 +43,7 @@ public class ModBlockStates extends CoreModule { blockDrops = modules.linkSharedModule(FeatureBlockItemSpawn.class, plugin.getModules()); modules.linkSharedModule(AdditionalBlockBreaks.class, plugin.getModules()); + modules.linkSharedModule(InstantHangingBreak.class, plugin.getModules()); this.addModule(new BlockFall(plugin)); listeners.addListener(new BlockListener(this)); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModCreativeLimits.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModCreativeLimits.java index 48669e3..352fbe1 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModCreativeLimits.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModCreativeLimits.java @@ -2,6 +2,7 @@ package de.jaschastarke.minecraft.limitedcreative; import de.jaschastarke.bukkit.lib.CoreModule; import de.jaschastarke.bukkit.lib.modules.AdditionalBlockBreaks; +import de.jaschastarke.bukkit.lib.modules.InstantHangingBreak; import de.jaschastarke.minecraft.limitedcreative.limits.BlockListener; import de.jaschastarke.minecraft.limitedcreative.limits.EntityListener; import de.jaschastarke.minecraft.limitedcreative.limits.EntityNoDrop; @@ -37,6 +38,7 @@ public class ModCreativeLimits extends CoreModule { blockDrops = modules.linkSharedModule(FeatureBlockItemSpawn.class, plugin.getModules()); modules.linkSharedModule(AdditionalBlockBreaks.class, plugin.getModules()); + modules.linkSharedModule(InstantHangingBreak.class, plugin.getModules()); } public FeatureBlockItemSpawn getBlockSpawn() { diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlockListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlockListener.java index 0e44571..4a2e0f2 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlockListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlockListener.java @@ -25,6 +25,7 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import de.jaschastarke.bukkit.lib.events.AttachedBlockDestroyedByPlayerEvent; +import de.jaschastarke.bukkit.lib.events.HangingBreakByPlayerBlockEvent; import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission; import de.jaschastarke.minecraft.lib.permissions.IDynamicPermission; import de.jaschastarke.minecraft.limitedcreative.ModCreativeLimits; @@ -67,6 +68,14 @@ public class BlockListener implements Listener { } } } + @EventHandler(ignoreCancelled = true) + public void onHangingBreakByPlayer(HangingBreakByPlayerBlockEvent event) { + if (mod.isDebug()) + mod.getLog().debug("Attached Hanging " + event.getEntity().getType() + " destroyed by player block place/break: " + event.getPlayer().getName() + " in GM " + event.getPlayer().getGameMode().toString()); + if (event.getPlayer().getGameMode() == GameMode.CREATIVE) { + event.getDrops().clear(); + } + } private boolean checkPermission(Player player, IDynamicPermission perm) { return mod.getPlugin().getPermManager().hasPermission(player, perm); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/BlockListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/BlockListener.java index 5a71ccc..743e1ea 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/BlockListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/BlockListener.java @@ -13,6 +13,7 @@ import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; +import org.bukkit.event.hanging.HangingPlaceEvent; import de.jaschastarke.bukkit.lib.Utils; import de.jaschastarke.minecraft.limitedcreative.ModRegions; @@ -87,6 +88,26 @@ public class BlockListener extends Listener { } } } + + @EventHandler(ignoreCancelled = true) + public void onHangingPlace(HangingPlaceEvent event) { + PlayerMeta pdata = new PlayerMeta(event.getPlayer()); + boolean diffrent_region = getRM().isDiffrentRegion(event.getPlayer(), event.getEntity().getLocation()); + + if (pdata.isActiveRegionGameMode() && diffrent_region) { + // do not build outside of "gamemod-change-region" when in the region + if (getRM().getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE, event.getPlayer()) != pdata.getActiveRegionGameMode()) { + event.getPlayer().sendMessage(L("blocked.outside_place")); + event.setCancelled(true); + } + } else if (diffrent_region) { + // do not build inside of "survial-region in creative world" when outside + if (getRM().getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE) != null && getRM().getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) { + event.getPlayer().sendMessage(L("blocked.inside_place")); + event.setCancelled(true); + } + } + } @EventHandler public void onPistonExtend(BlockPistonExtendEvent event) {