From ea1921935ecd3e014bad0234d137c1a6ba4bb724 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Wed, 25 Sep 2013 19:25:24 +0200 Subject: [PATCH] Per world disable of BlockState module --- .../blockstate/BlockListener.java | 12 +++++++++ .../blockstate/BlockStateCommand.java | 4 +++ .../blockstate/BlockStateConfig.java | 25 ++++++++++++++++--- .../blockstate/HangingListener.java | 6 +++++ .../blockstate/PlayerListener.java | 12 +++++++-- .../blockstate/ThreadedModel.java | 10 +++++--- src/main/resources/lang/messages.properties | 1 + .../resources/lang/messages_de.properties | 1 + 8 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockListener.java index 7d0635f..7d4e5c0 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockListener.java @@ -30,6 +30,8 @@ public class BlockListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { + if (mod.getConfig().getIgnoredWorlds().contains(event.getBlock().getWorld().getName())) + return; if (mod.getModel().isRestricted(event.getBlock())) { if (mod.isDebug()) mod.getLog().debug("Breaking bad, err.. block: " + event.getBlock().getLocation().toString()); @@ -46,6 +48,8 @@ public class BlockListener implements Listener { @EventHandler public void onOtherBlockDestroy(BlockDestroyedEvent event) { + if (mod.getConfig().getIgnoredWorlds().contains(event.getBlock().getWorld().getName())) + return; if (mod.getModel().isRestricted(event.getBlock())) { if (mod.isDebug()) mod.getLog().debug("Breaking attached block: " + event.getBlock().getLocation().toString()); @@ -59,6 +63,8 @@ public class BlockListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlocksBreakByExplosion(EntityExplodeEvent event) { + if (mod.getConfig().getIgnoredWorlds().contains(event.getLocation().getWorld().getName())) + return; Map states = mod.getModel().getRestrictedStates(event.blockList()); DBTransaction update = mod.getModel().groupUpdate(); for (Block block : event.blockList()) { @@ -78,6 +84,8 @@ public class BlockListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPlace(BlockPlaceEvent event) { + if (mod.getConfig().getIgnoredWorlds().contains(event.getBlock().getWorld().getName())) + return; BlockState s = new BlockState(); s.setLocation(event.getBlock().getLocation()); s.setPlayer(event.getPlayer()); @@ -90,6 +98,8 @@ public class BlockListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPistionExtend(BlockPistonExtendEvent event) { + if (mod.getConfig().getIgnoredWorlds().contains(event.getBlock().getWorld().getName())) + return; if (event.getBlock().getMetadata("LCBS_pistonIsAlreadyExtended").size() > 0) // Fixes long known Bukkit issue return; event.getBlock().setMetadata("LCBS_pistonIsAlreadyExtended", new FixedMetadataValue(mod.getPlugin(), new Boolean(true))); @@ -119,6 +129,8 @@ public class BlockListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPistionRetract(BlockPistonRetractEvent event) { + if (mod.getConfig().getIgnoredWorlds().contains(event.getBlock().getWorld().getName())) + return; event.getBlock().removeMetadata("LCBS_pistonIsAlreadyExtended", mod.getPlugin()); Block dest = event.getBlock().getRelative(event.getDirection()); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateCommand.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateCommand.java index bdd3632..7a2bd5a 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateCommand.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateCommand.java @@ -102,6 +102,10 @@ public class BlockStateCommand extends BukkitCommand implements IHelpDescribed { if (args.length < 1) {// doesn't count parameters return false; } + if (mod.getConfig().getIgnoredWorlds().contains(context.getPlayer().getWorld().getName())) { + context.response(L("command.blockstate.world_ignored", context.getPlayer().getWorld().getName())); + return true; + } String gm = args[0].toLowerCase(); final GameMode tgm; if (gm.equals("0") || gm.equals("s") || gm.equals("survival")) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java index 947e2b5..bf78547 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java @@ -4,6 +4,7 @@ import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import de.jaschastarke.bukkit.lib.configuration.Configuration; +import de.jaschastarke.bukkit.lib.configuration.StringList; import de.jaschastarke.configuration.IConfigurationNode; import de.jaschastarke.configuration.IConfigurationSubGroup; import de.jaschastarke.configuration.InvalidValueException; @@ -86,7 +87,7 @@ public class BlockStateConfig extends Configuration implements IConfigurationSub * BlockStateThreading * * This experimental variant of the experimental Feature uses Threading to minimize lag. This fully relies on - * Bukkit metadata implementation. You only should need this, if there are often plays more then 10 players at once + * Bukkit metadata implementation. You only should need this, if there are often plays more then 10 players at once * on your server. Be aware that this requires more memory. * * default: false @@ -126,16 +127,34 @@ public class BlockStateConfig extends Configuration implements IConfigurationSub /** * BlockStateLogSurvival * - * Log all Block-Places to the database. Disable to make the database more slim by not adding blocks placed in + * Log all Block-Places to the database. Disable to make the database more slim by not adding blocks placed in * survival-mode. * * default: true */ - @IsConfigurationNode(order = 100) + @IsConfigurationNode(order = 400) public boolean getLogSurvival() { return config.getBoolean("logSurvival", true); } + private StringList ignoredWorlds = null; + + /** + * BlockStateIgnoredWorlds + * + * While you may use per world permissions to configure limitations fine graded, you may want to disable the + * BlockState-Feature for certain worlds (like complete creative worlds) to save cpu and memory. + * + * default: [] + */ + @IsConfigurationNode(order = 500) + public StringList getIgnoredWorlds() { + if (ignoredWorlds == null) { + ignoredWorlds = new StringList(config.getStringList("ignoredWorlds")); + } + return ignoredWorlds; + } + protected void setTool(Object val) throws InvalidValueException { String v = (String) val; Material m = null; 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 5ca97ec..f3fad65 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingListener.java @@ -22,6 +22,8 @@ public class HangingListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { + if (mod.getConfig().getIgnoredWorlds().contains(event.getRightClicked().getWorld().getName())) + return; if (event.getRightClicked() instanceof ItemFrame) { if (mod.getModel().isRestricted(event.getRightClicked().getLocation().getBlock())) { if (mod.isDebug()) @@ -49,6 +51,8 @@ public class HangingListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onHangingBreak(HangingBreakEvent event) { + if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName())) + return; if (event.getEntity() instanceof ItemFrame) { if (mod.isDebug()) mod.getLog().debug("Breaking hanging: " + event.getEntity().getLocation().toString()); @@ -67,6 +71,8 @@ public class HangingListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onHangingPlace(HangingPlaceEvent event) { + if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName())) + return; if (event.getEntity() instanceof ItemFrame) { BlockState s = new BlockState(); s.setLocation(event.getEntity().getLocation().getBlock().getLocation()); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/PlayerListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/PlayerListener.java index 1eadfc2..b00bca5 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/PlayerListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/PlayerListener.java @@ -30,7 +30,11 @@ public class PlayerListener implements Listener { if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { Block b = event.getClickedBlock(); if (b != null && event.getPlayer().getItemInHand().getType().equals(mod.getConfig().getTool()) && mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), BlockStatePermissions.TOOL)) { - showInfo(event.getPlayer(), b.getLocation(), b.getType()); + if (mod.getConfig().getIgnoredWorlds().contains(event.getClickedBlock().getWorld().getName())) { + event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("command.blockstate.world_ignored", event.getClickedBlock().getWorld().getName())); + } else { + showInfo(event.getPlayer(), b.getLocation(), b.getType()); + } } } } @@ -38,7 +42,11 @@ public class PlayerListener implements Listener { public void onInteractEntity(PlayerInteractEntityEvent event) { Entity e = event.getRightClicked(); if (e != null && e instanceof ItemFrame && event.getPlayer().getItemInHand().getType().equals(mod.getConfig().getTool()) && mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), BlockStatePermissions.TOOL)) { - showInfo(event.getPlayer(), e.getLocation(), Material.ITEM_FRAME); + if (mod.getConfig().getIgnoredWorlds().contains(e.getWorld().getName())) { + event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("command.blockstate.world_ignored", e.getWorld().getName())); + } else { + showInfo(event.getPlayer(), e.getLocation(), Material.ITEM_FRAME); + } event.setCancelled(true); } } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/ThreadedModel.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/ThreadedModel.java index c9c20e3..8cf2766 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/ThreadedModel.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/ThreadedModel.java @@ -42,8 +42,10 @@ public class ThreadedModel extends AbstractModel implements DBModel, Listener { // We don't keep any reference to queries, because it contains the DB-Connection, which should be only used // from the thread from now on (as SQLite may not threadsafe) for (World w : mod.getPlugin().getServer().getWorlds()) { - for (Chunk chunk : w.getLoadedChunks()) { - threads.queueChunkLoad(chunk); + if (!mod.getConfig().getIgnoredWorlds().containsIgnoreCase(w.getName())) { + for (Chunk chunk : w.getLoadedChunks()) { + threads.queueChunkLoad(chunk); + } } } threads.start(); @@ -61,7 +63,9 @@ public class ThreadedModel extends AbstractModel implements DBModel, Listener { @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onChunkLoad(ChunkLoadEvent event) { - threads.queueChunkLoad(event.getChunk()); + if (!mod.getConfig().getIgnoredWorlds().containsIgnoreCase(event.getWorld().getName())) { + threads.queueChunkLoad(event.getChunk()); + } } @Override diff --git a/src/main/resources/lang/messages.properties b/src/main/resources/lang/messages.properties index dc3c5a0..5b87b84 100644 --- a/src/main/resources/lang/messages.properties +++ b/src/main/resources/lang/messages.properties @@ -25,6 +25,7 @@ command.worldguard.flag_set: "The flag {0} was set" command.worldguard.additional_flags: Additional flags: command.blockstate: LimitedCreative-BlockState-Command: modify blockstate database to prevent drops of selected blocks (requires WorldEdit) +command.blockstate.world_ignored: The BlockState-Feature is disabled for this World ({0}) command.blockstate.requires_worldedit: This command requires WorldEdit-Plugin command.blockstate.worledit_selection_empty: Select a region with WorldEdit first command.blockstate.command_updated: Successfully updated {0} blocks. diff --git a/src/main/resources/lang/messages_de.properties b/src/main/resources/lang/messages_de.properties index 3117183..d1a38c6 100644 --- a/src/main/resources/lang/messages_de.properties +++ b/src/main/resources/lang/messages_de.properties @@ -25,6 +25,7 @@ command.worldguard.flag_set: Das Attribut {0} wurde gesetzt command.worldguard.additional_flags: Zusätzliche Attribute: command.blockstate: LimitedCreative-BlockStatus-Kommando: Ändern der BlockStatus Datenbank um Beute aus den ausgewählten Blöcken zu verhindern (benötigt WorldEdit) +command.blockstate.world_ignored: Das BlockStatus-Modul ist für diese Welt deaktiviert ({0}) command.blockstate.requires_worldedit: Dieser Befehl benötigt WorldEdit command.blockstate.worledit_selection_empty: Zuerst eine Region mit WorldEdit auswählen command.blockstate.command_updated: Erfolgreich {0} Blöcke aktuallisiert