From 147e453299b6e17e603184f70b9ff760f9083ab0 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Fri, 3 Feb 2012 22:47:56 +0100 Subject: [PATCH] v0.9: - blocking pistons region bypass - reworked config/blacklist and configuration commands - added optional feature: prevent dealing damage to creatures - added optional feautre: prevent usage of buttons/levers - added possibility to blacklist items with spec. data - * supporting monster_eggs --- config.yml | 16 ++ lang/default.yml | 13 +- plugin.yml | 11 +- .../minecraft/limitedcreative/BlackList.java | 55 +++++++ .../minecraft/limitedcreative/Commands.java | 59 +++----- .../limitedcreative/Configuration.java | 143 ++++++++++-------- .../minecraft/limitedcreative/LCPlayer.java | 45 +++++- .../listeners/LimitListener.java | 30 +++- .../regions/RegionListener.java | 56 +++++++ src/de/jaschastarke/minecraft/utils/Util.java | 5 + 10 files changed, 316 insertions(+), 117 deletions(-) create mode 100644 src/de/jaschastarke/minecraft/limitedcreative/BlackList.java diff --git a/config.yml b/config.yml index 91d24b8..ccedaa5 100644 --- a/config.yml +++ b/config.yml @@ -62,12 +62,25 @@ limit: # default: true sign: true + # BlockButtons + # When enabled also blocks usage of Buttons & Levers while in creative mode. + # default: false + button: false + + # BlockDamageToMobs + # Prevents dealing damage to all creatures in creative (friendly sheeps as well as hostile creepers). + # default: false + damagemob: false + # UseBlackList # Prevents using or placing of the given blocks in creative mode (and only in creative). # You can use the technical name (see http://jd.bukkit.org/doxygen/d7/dd9/namespaceorg_1_1bukkit.html#ab7fa290bb19b9a830362aa88028ec80a) # or the id of the block/item (better use the id, if you're not sure). # To prevent Lava you need to add "LAVA_BUCKET", because lava-blocks aren't "placed", therefore Lava-Buckets are # "used". + # You may add the data separated with a colon e.g.: "35:11" blocks blue wool. But be sure to put it in quotes, to + # not break yml-configuration! Also supporting Eggs (e.g: "MONSTER_EGG:56" blocks Ghasts-Eggs). Named data values aren't + # supported yet. # This option can only changed by reloading the plugin (not via ingame commands). # default: [] use: [] @@ -77,6 +90,9 @@ limit: # You can use the technical name (see http://jd.bukkit.org/doxygen/d7/dd9/namespaceorg_1_1bukkit.html#ab7fa290bb19b9a830362aa88028ec80a) # or the id of the block/item (better use the id, if you're not sure). # This option can only changed by reloading the plugin (not via ingame commands). + # You may add the data separated with a colon e.g.: "WOOL:11" blocks blue wool. But be sure to put it in quotes, to + # not break yml-configuration! + # supported yet. # default: [bedrock] break: - bedrock diff --git a/lang/default.yml b/lang/default.yml index fee4b94..236d6a4 100644 --- a/lang/default.yml +++ b/lang/default.yml @@ -9,7 +9,7 @@ basic: conflict: Due to conflict with the plugin {0}, the feature {1} is disabled warning: worldguard_not_found: WorldGuard isn''t found, the feature {0} is disabled - # double single-quote '' because of MessageFormater to insert {0} + # double single-quote '' because of MessageFormater to insert {0} command: player: player switch: @@ -17,10 +17,7 @@ command: creative: Changes the game mode of a player to creative config: overview: "[setting] - empty for list of settings" - settings: - - "Available Settings: storecreative," - - "removedrop, removepickup, blockpickup, blocksign," - - "permissions, perm_keepinventory" + settings: "Available Settings: " reload: Reloads plugin (doesn't work on update!) gamemode: changed: "{0}'s game mode has been changed" @@ -54,9 +51,13 @@ exception: blocked: chest: Access to chests is not allowed in creative mode sign: To interact with signs is not allowed in creative mode + button: To interact with buttons is not allowed in creative mode + lever: To interact with levers is not allowed in creative mode survival_flying: You should stay on ground, when leaving a creative-area outside_creative: You can not place blocks outside of the creative-area outside_creative_break: You can not destroy blocks outside of the creative-area use: You are not allowed to use this type of item place: You are not allowed to place this type of block - break: You are not allowed to break this type of block \ No newline at end of file + break: You are not allowed to break this type of block + piston: Moving {0} block out of creative area was blocked at {1} + piston_in: Moving {0} block into creative area was blocked at {1} \ No newline at end of file diff --git a/plugin.yml b/plugin.yml index 3a90499..5c03bf0 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: LimitedCreative main: de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore -version: 0.8.2-beta +version: 0.9-beta softdepend: [WorldGuard, WorldEdit, MultiInv] dev-url: http://dev.bukkit.org/server-mods/limited-creative/ commands: @@ -43,9 +43,18 @@ permissions: limitedcreative.nolimit.sign: description: Allows bypassing the "do not interact with signs"-limitation default: false + limitedcreative.nolimit.button: + description: Allows bypassing the "do not interact with buttons"-limitation + default: false + limitedcreative.nolimit.lever: + description: Allows bypassing the "do not interact with levers"-limitation + default: false limitedcreative.nolimit.pvp: description: Allows bypassing the "no pvp"-limitation default: false + limitedcreative.nolimit.mob_damage: + description: Allows bypassing the "no dealing damage to creatures"-limitation + default: false limitedcreative.nolimit.use: description: Allows bypassing the "block place/item use"-limitation default: false diff --git a/src/de/jaschastarke/minecraft/limitedcreative/BlackList.java b/src/de/jaschastarke/minecraft/limitedcreative/BlackList.java new file mode 100644 index 0000000..31fe8b9 --- /dev/null +++ b/src/de/jaschastarke/minecraft/limitedcreative/BlackList.java @@ -0,0 +1,55 @@ +package de.jaschastarke.minecraft.limitedcreative; + +import java.util.List; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.inventory.ItemStack; + +public class BlackList { + private Material mat; + private int data = -1; + public BlackList(Material material, int data) { + mat = material; + this.data = data; + } + public BlackList(Material material) { + mat = material; + } + public boolean matches(Block block) { + if (this.mat != block.getType()) + return false; + if (this.data != -1 && this.data != block.getData()) + return false; + return true; + } + public boolean matches(ItemStack item) { + if (this.mat != item.getType()) + return false; + if (this.data != -1) { + if (this.mat == Material.MONSTER_EGG) { + if (this.data != item.getDurability()) + return false; + } else { + if (this.data != item.getData().getData()) + return false; + } + } + return true; + } + + public static boolean isBlackListed(List list, Block block) { + for (BlackList bl : list) { + if (bl.matches(block)) + return true; + } + return false; + } + public static boolean isBlackListed(List list, ItemStack item) { + for (BlackList bl : list) { + if (bl.matches(item)) + return true; + } + return false; + } +} diff --git a/src/de/jaschastarke/minecraft/limitedcreative/Commands.java b/src/de/jaschastarke/minecraft/limitedcreative/Commands.java index c522726..1fae2f7 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/Commands.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/Commands.java @@ -18,6 +18,7 @@ package de.jaschastarke.minecraft.limitedcreative; import java.util.Arrays; +import java.util.List; import org.bukkit.ChatColor; import org.bukkit.GameMode; @@ -108,18 +109,6 @@ public class Commands { } return false; } - - - public enum Option { - STORECREATIVE, - BLOCKPICKUP, - BLOCKSIGN, - PERMISSIONS, - PERM_KEEPINVENTORY, - REMOVEDROP, - REMOVEPICKUP, - DEBUG, - }; private void setOption(CommandSender sender, String[] args, boolean b) throws CommandException { if (sender instanceof Player && !plugin.perm.hasPermission(sender, "limitedcreative.config")) { @@ -128,44 +117,30 @@ public class Commands { if (args.length > 2) throw new InvalidCommandException("exception.command.tomuchparameter"); if (args.length < 2) { - for (String l : L("command.config.settings").split("\n")) - sender.sendMessage(l); + StringBuilder str = new StringBuilder(L("command.config.settings")); + List options = Configuration.Option.getAvailableOptions(); + for (int i = 0; i < options.size(); i++) { + str.append(options.get(i).name().toLowerCase()); + if (i < options.size() - 1) + str.append(", "); + if ((i - 1) % 5 == 0) { + sender.sendMessage(str.toString()); + str = new StringBuilder(); + } + } + if (str.length() > 0) + sender.sendMessage(str.toString()); return; } - Option opt = null; + Configuration.Option opt = null; try { - opt = Option.valueOf(args[1].toUpperCase()); + opt = Configuration.Option.valueOf(args[1].toUpperCase()); } catch (IllegalArgumentException e) { throw new InvalidCommandException("exception.command.invalidoption"); } - switch (opt) { - case STORECREATIVE: - plugin.config.setStoreCreative(b); - break; - case BLOCKPICKUP: - plugin.config.setBlockPickupInCreative(b); - break; - case BLOCKSIGN: - plugin.config.setSignBlock(b); - break; - case PERMISSIONS: - plugin.config.setPermissionsEnabled(b); - break; - case PERM_KEEPINVENTORY: - plugin.config.setPermissionToKeepInventory(b); - break; - case REMOVEDROP: - plugin.config.setRemoveDrop(b); - break; - case REMOVEPICKUP: - plugin.config.setRemovePickup(b); - break; - case DEBUG: - plugin.config.setDebug(b); - break; - } + plugin.config.set(opt, b); sender.sendMessage(L("command.option.done")); } diff --git a/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java b/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java index b920422..0df985b 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java @@ -19,6 +19,7 @@ package de.jaschastarke.minecraft.limitedcreative; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.bukkit.Material; @@ -32,6 +33,38 @@ public class Configuration { private File file; public static LimitedCreativeCore plugin; + public enum Option { + STORECREATIVE("store.creative", true), + REGION_OPTIONAL("region.optional", true), + BLOCKPICKUP("limit.pickup", true), + BLOCKSIGN("limit.sign", true), + BLOCKBUTTON("limit.button", false), + BLOCKDAMAGEMOB("limit.damagemob", false), + REMOVEDROP("limit.remove_drops", true), + REMOVEPICKUP("limit.remove_pickup", false), + PERMISSIONS("permissions.enabled", false), + PERM_KEEPINVENTORY("permissions.keepinventory", false), + DEBUG("debug", false); + + private String key; + private boolean _default; + private Option(String key, boolean def) { + this.key = key; + this._default = def; + } + public String getKey() { + return key; + } + public boolean getDefault() { + return _default; + } + public static List