From 31f670aff328924c1e6b57a9f3416b667ef4c21d Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Mon, 12 Nov 2012 23:22:18 +0100 Subject: [PATCH] v1.4.0a: - Fix: Block breaking of hanging entities (Paintings/ItemFrames) in/out of gamemode-areas - German Translation (As bad as English one, even its my primary lang.) - Removed Permission-Configuration * It is now always enabled to prevent confusion. * ATTION for PEX-Admins: # You have to add a Permission "-limitedcreative.keepinventory" if # you like to keep separated Inventories even with an # '*'-Admin-Permission - Now blocking interaction with item-frames in creative when nolimit.drop is enabled (default). So people neither can drop items, nor put it in a frame to pass it to survival. - Added Command Blocker * ATTENTION: You have to update the configuration by hand to add the commands to the block-list. --- config.yml | 43 ++++++------ lang/de_DE.yml | 68 +++++++++++++++++++ lang/en_US.yml | 2 + plugin.yml | 7 +- pom.xml | 10 ++- .../limitedcreative/Configuration.java | 33 ++++++--- .../minecraft/limitedcreative/Core.java | 8 +++ .../minecraft/limitedcreative/LCPlayer.java | 30 ++++---- .../minecraft/limitedcreative/Perms.java | 10 +++ .../cmdblock/CommandBlocker.java | 42 ++++++++++++ .../cmdblock/ICmdBlockEntry.java | 5 ++ .../cmdblock/RegexpBlockEntry.java | 19 ++++++ .../cmdblock/StringBlockEntry.java | 17 +++++ .../listeners/LimitListener.java | 62 ++++++++++++----- .../regions/RegionListener.java | 30 +++++--- 15 files changed, 311 insertions(+), 75 deletions(-) create mode 100644 lang/de_DE.yml create mode 100644 src/de/jaschastarke/minecraft/limitedcreative/cmdblock/CommandBlocker.java create mode 100644 src/de/jaschastarke/minecraft/limitedcreative/cmdblock/ICmdBlockEntry.java create mode 100644 src/de/jaschastarke/minecraft/limitedcreative/cmdblock/RegexpBlockEntry.java create mode 100644 src/de/jaschastarke/minecraft/limitedcreative/cmdblock/StringBlockEntry.java diff --git a/config.yml b/config.yml index 2f501d5..8e230d1 100644 --- a/config.yml +++ b/config.yml @@ -101,7 +101,7 @@ limit: # 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) + # You can use the technical name (see http://jd.bukkit.org/doxygen/d6/d0e/enumorg_1_1bukkit_1_1Material.html) # 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". @@ -117,7 +117,7 @@ limit: # BreakBlackList # Prevents destroying 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) + # You can use the technical name (see http://jd.bukkit.org/doxygen/d6/d0e/enumorg_1_1bukkit_1_1Material.html) # or the id of the block/item (better use the id, if you're not sure). # 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! Named data values aren't supported yet. If you don't add a data-value, all blocks @@ -130,7 +130,7 @@ limit: region: # RegionsEnabled - # Enables the Feature for "creative-regions". This Feature is automatically disabled, if the required plugin + # Enables the feature for "creative-regions". This Feature is automatically disabled, if the required plugin # "WorldGuard" (http://dev.bukkit.org/server-mods/worldguard/) isn't found. # default: true enabled: true @@ -148,24 +148,27 @@ region: # default: true remember: true -permissions: - # PermissionsEnabled - # When enabled, the Permissions will allow selected users to ignore limitations like PvP, Chest-Block, etc. - # When not enabled, all users are treated equally. - # Note: Not all Permission, are affected by this option. So you still need the defined permissions or op, to use - # commands, even if this options is disabled! - # default: false - enabled: false - - # PermissionKeepInventory - # Disables the limitedcreative.keepinventory-Permission, so you can use the separated-inventories-feature, even - # if you have a permission plugin that grants ALL permission to you. - # If Enabled, only players WITHOUT the limitedcreative.keepinventory-Permission, have separated inventories; - # Players with the permission will have the inventory, like this plugin were not installed. - # When "PermissionsEnabled" is false, the KeepInventory-Option will act like disabled, even if you set it to true. - # default: false - keepinventory: false +cmdblock: + # CommandBlockerEnabled + # Enables the feature for blocking certain commands in creative mode. + # default: true + enabled: true + + # CommandBlockerList + # Defines the list of commands that are blocked while in creative mode. The leading / isn't included. By default + # the list-item is treated as simple string as typed in by the user after the /. All commands starting with + # this string are blocked, even if more parameteres are entered by the user. + # If the first Char is ^ the entry is interpreted as a regular expression (including the ^ for begin of the string). + # Only use regular expressions if you know them. + # default: [] + commands: + # - logout + # - home + # - home second + # - ^chest (one|two|three) + # - ^(lc|limitedcreative) s(urvival)? + # Locale (Language) # Uncomment the "locale: en_US"-Line, to override the locale which be used for localized messages. By default the diff --git a/lang/de_DE.yml b/lang/de_DE.yml new file mode 100644 index 0000000..3b03faa --- /dev/null +++ b/lang/de_DE.yml @@ -0,0 +1,68 @@ +basic: + loaded: + worldguard: Erfolgreich mit WorldGuard-Integration geladen + no_worldguard: Erfolgreich geladen (ohne WorldGuard) + feature: + store: Getrennte Inventare + limit: Kreativ-Einschränkungen + region: Kreativ-Regionen + conflict: Wegen eines Konfliktes mit {0} ist die Funktion {1} deaktiviert + warning: + worldguard_not_found: WorldGuard wurd enicht gefunde, dahier ist die Funktion {0} deaktiviert + # double single-quote '' because of MessageFormater to insert {0} +command: + player: Spieler + switch: + survival: Ändert den Spiel-Modus des Charakters zu Überleben + creative: Ändert den Spiel-Modus des Charakters zu Kreativ + adventure: Ändert den Spiel-Modus des Charakters zu Abenteuer + config: + overview: "[Einstellung] - liste durch weglassen" + settings: "Verfügbare Einstellungen: " + reload: Lädt das Plugin neu (funktioniert nur teilweise) + gamemode: + changed: "{0}'s Spiel-Modus wurde geändert" + no_change: Bereits in diesem Spiel-Modus + option: + done: Option geändert. + worldguard: + alias: Alias für den //region-Befehl + unknown_flag: Unbekanntes Attribut + available_flags: Verfügbare Attribute + region_not_found: Keine Region mit dieser ID gefunden + world_not_found: Es konnte keine Welt mit diesem Namen gefunden werden + no_flag_given: Es muss ein Attribut angegeben werden, dass gesetzt werden soll + no_integration: Der worldguard-Befehl ist nicht verfügbar, da WorldGuard nicht gefunden wurde + flag_set: "Das Attribut {0} wurde gesetzt" + additional_flags: Zusätzliche Attribute +cmdblock: + blocked: Dieser Befehl ist im Kreativ-Modus blockiert. +exception: + command: + lackingpermission: Kein Zugriff auf diesen Befehl + toomuchparameter: Zuviele Argumente angegeben + missingparameter: Nicht genügen Argumente angegeben + playernotfound: Spieler nicht gefunden + invalidoption: Unbkeannte Option + config: + savefail: Die Konfiguration konnte nicht gespeichert werden + material_not_found: (Konfiguration) Material mit Name/ID "{0}" wurde nicht gefunden. + storage: + load: Fehler beim Laden des Inventars. Bitte einen Admin die Option "UnsafeStorege" in LimitedCreative zu aktivieren um ungültig verzauberte Gegenstände zu erlauben + region: + not_optional: "In dieser Region kannst du nicht im folgenden Modus sein: {0}" +blocked: + chest: Zugriff auf Truhen ist im Kreativ-Modus nicht erlaubt + sign: Im Kreativ-Modus kann nicht mit Schildern interagiert werden + button: Im Kreativ-Modus kann nicht mit Buttons interagiert werden + lever: Im Kreativ-Modus kann nicht mit Schaltern interagiert werden + survival_flying: Du solltest auf dem Boden stehen wenn du Kreativ-Regionen verlässt + outside_place: Du kannst keine Blöcke außerhalb von Spiel-Modus-Regionen setzen + outside_break: Du kannst keine Blöcke außerhalb von Spiel-Modus-Regionen zerstören + inside_place: Du kannst keine Blöcke innerhalb von Spiel-Modus-Regionen setzen + inside_break: Du kannst keine Blöcke innerhalb von Spiel-Modus-Regionen zerstören + use: Du darfst diese Art von Gegenständen im Kreativ-Modus verwenden + place: Du darfst diese Art von Blöcken im Kreativ-Modus nicht setzen + break: Du darfst diese Art von Blöcken im Kreativ-Modus nicht zerstören + piston: Verschieben von Block {0} aus einer Spiel-Modus-Region bei {1} wurde blockiert + piston_in: Verschieben von Block {0} in eine Spiel-Modus-Region bei {1} wurde blockiert \ No newline at end of file diff --git a/lang/en_US.yml b/lang/en_US.yml index 24723dc..ad4779a 100644 --- a/lang/en_US.yml +++ b/lang/en_US.yml @@ -35,6 +35,8 @@ command: no_integration: The worldguard-commands are not available, because worldguard wasn't found flag_set: "The flag {0} was set" additional_flags: Additional flags +cmdblock: + blocked: This command is blocked while in creative mode. exception: command: lackingpermission: You do not have access to this command diff --git a/plugin.yml b/plugin.yml index 909bb25..a8b6bc2 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: LimitedCreative main: de.jaschastarke.minecraft.limitedcreative.Core -version: 1.3.0c +version: 1.4.0a softdepend: [WorldGuard, WorldEdit, MultiInv] dev-url: http://dev.bukkit.org/server-mods/limited-creative/ commands: @@ -72,4 +72,7 @@ permissions: default: false limitedcreative.nolimit.break: description: Allows bypassing the "block break"-limitation - default: false \ No newline at end of file + default: false + limitedcreative.cmdblock.all: + description: Allowy bypassting the "command block"-limitation + default: op diff --git a/pom.xml b/pom.xml index 846ea2b..a1c06d0 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.jaschastarke LimitedCreative LimitedCreative - 1.3.0c + 1.4.0a https://github.com/possi/LimitedCreative scm:git:git://github.com/possi/LimitedCreative.git @@ -31,6 +31,10 @@ onarandombox http://repo.onarandombox.com/content/groups/public + + vault-repo + http://ci.herocraftonline.com/plugin/repository/everything + ${basedir}/src @@ -68,12 +72,12 @@ org.bukkit bukkit - 1.3.1-R1.0 + 1.4.2-R0.2 com.sk89q worldguard - 5.5.4-SNAPSHOT + 5.6.3 uk.org.whoami diff --git a/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java b/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java index b7fb4e6..9dfebb1 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java @@ -32,6 +32,9 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.material.MaterialData; +import de.jaschastarke.minecraft.limitedcreative.cmdblock.ICmdBlockEntry; +import de.jaschastarke.minecraft.limitedcreative.cmdblock.RegexpBlockEntry; +import de.jaschastarke.minecraft.limitedcreative.cmdblock.StringBlockEntry; import de.jaschastarke.minecraft.limitedcreative.store.InvYamlStorage; import de.jaschastarke.minecraft.limitedcreative.store.PlayerInventoryStorage; @@ -53,9 +56,8 @@ public class Configuration { BLOCKBENCHES("limit.workbench", false), REMOVEDROP("limit.remove_drops", true), REMOVEPICKUP("limit.remove_pickup", false), - PERMISSIONS("permissions.enabled", false), - PERM_KEEPINVENTORY("permissions.keepinventory", false), PERM_WEPIF("permissions.wepif", true), + CMDBLOCKER("cmdblocker.enabled", true), DEBUG("debug", false); private String key; @@ -93,8 +95,6 @@ public class Configuration { throw new IllegalArgumentException("Setting this option is not allowed");*/ this.reload(); c.set(opt.getKey(), value); - if (value && opt == Option.PERM_KEEPINVENTORY && !this.getPermissionsEnabled()) - c.set(Option.PERMISSIONS.getKey(), true); this.save(); } @@ -153,12 +153,6 @@ public class Configuration { return this.getBoolean(Option.BLOCKDAMAGEMOB); } - public boolean getPermissionsEnabled() { - return this.getBoolean(Option.PERMISSIONS); - } - public boolean getPermissionToKeepInventory() { - return this.getPermissionsEnabled() && this.getBoolean(Option.PERM_KEEPINVENTORY); - } public boolean getWEPIFEnabled() { return this.getBoolean(Option.PERM_WEPIF); } @@ -291,4 +285,23 @@ public class Configuration { } return null; } + + public boolean getCommandBlockerEnabled() { + return this.getBoolean(Option.CMDBLOCKER); + } + + private List _blocklist = null; + public List getCommandBlockList() { + if (_blocklist == null) { + _blocklist = new ArrayList(); + for (String cmd : c.getStringList("cmdblock.commands")) { + if (cmd.startsWith("^")) { + _blocklist.add(new RegexpBlockEntry(cmd)); + } else { + _blocklist.add(new StringBlockEntry(cmd)); + } + } + } + return _blocklist; + } } diff --git a/src/de/jaschastarke/minecraft/limitedcreative/Core.java b/src/de/jaschastarke/minecraft/limitedcreative/Core.java index 9dcc317..f221a4e 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/Core.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/Core.java @@ -25,6 +25,7 @@ import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; import de.jaschastarke.minecraft.integration.Communicator; +import de.jaschastarke.minecraft.limitedcreative.cmdblock.CommandBlocker; import de.jaschastarke.minecraft.limitedcreative.listeners.LimitListener; import de.jaschastarke.minecraft.limitedcreative.listeners.MainListener; import de.jaschastarke.minecraft.limitedcreative.regions.WorldGuardIntegration; @@ -40,6 +41,7 @@ public class Core extends JavaPlugin { public Communicator com; public static Core plugin; public NoBlockItemSpawn spawnblock; + public CommandBlocker cmdblock; @Override public void onDisable() { @@ -55,6 +57,7 @@ public class Core extends JavaPlugin { config = null; spawnblock = null; com = null; + cmdblock = null; } @Override @@ -86,9 +89,14 @@ public class Core extends JavaPlugin { warn(L("basic.warning.worldguard_not_found", L("basic.feature.region"))); } + // 4th Feature: Command Blocker + if (config.getCommandBlockerEnabled()) + cmdblock = new CommandBlocker(this); + debug("Store: " + config.getStoreEnabled()); debug("Limit: " + config.getLimitEnabled()); debug("Region: " + (worldguard != null)); + debug("CmdBlock: " + config.getCommandBlockerEnabled()); Commands.register(this); diff --git a/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java b/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java index f9b8ab4..8b45d9e 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java @@ -172,7 +172,7 @@ public class LCPlayer { Core.debug(getName() + " going into " + gm); if (isActiveRegionGameMode()) { // change to the other gamemode as the area defines if (!isActiveRegionGameMode(gm)) { // only when we are not switching to the mode the region allows - if (!plugin.config.getRegionOptional() && (!plugin.config.getPermissionsEnabled() || !hasPermission(Perms.REGIONS_BYPASS))) { + if (!plugin.config.getRegionOptional() && !hasPermission(Perms.REGIONS_BYPASS)) { getPlayer().sendMessage(ChatColor.RED + L("exception.region.not_optional", gm.toString().toLowerCase())); Core.debug("... denied"); return false; @@ -192,7 +192,7 @@ public class LCPlayer { * Feature 1: Separated Inventories / Storage */ if (plugin.config.getStoreEnabled()) { - if (plugin.config.getPermissionToKeepInventory() && hasPermission(Perms.KEEPINVENTORY)) + if (hasPermission(Perms.KEEPINVENTORY)) return true; getPlayer().closeInventory(); @@ -252,7 +252,7 @@ public class LCPlayer { public void onDropItem(PlayerDropItemEvent event) { Core.debug(getName() + " ("+getPlayer().getGameMode()+") drops items " + event.getItemDrop().getItemStack().getType()); if (getPlayer().getGameMode() == GameMode.CREATIVE) { - if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.DROP)) + if (hasPermission(Perms.NoLimit.DROP)) return; Core.debug("removed"); if (plugin.config.getRemoveDrop()) @@ -263,7 +263,7 @@ public class LCPlayer { } public void onPickupItem(PlayerPickupItemEvent event) { if (getPlayer().getGameMode() == GameMode.CREATIVE) { - if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.PICKUP)) + if (hasPermission(Perms.NoLimit.PICKUP)) return; if (plugin.config.getBlockPickupInCreative()) { event.setCancelled(true); @@ -276,7 +276,7 @@ public class LCPlayer { public void onDie(EntityDeathEvent event) { if (getPlayer().getGameMode() == GameMode.CREATIVE) { - if (!plugin.config.getPermissionsEnabled() || !hasPermission(Perms.NoLimit.DROP)) { + if (!hasPermission(Perms.NoLimit.DROP)) { event.getDrops().clear(); //getInv().storeTemp(); } @@ -297,13 +297,13 @@ public class LCPlayer { // its PVP Player attacker = (Player) from; if (attacker.getGameMode() == GameMode.CREATIVE) { - if (!plugin.config.getPermissionsEnabled() || !Players.get(attacker).hasPermission(Perms.NoLimit.PVP)) { + if (!Players.get(attacker).hasPermission(Perms.NoLimit.PVP)) { event.setCancelled(true); return; // skip next check } } if (getPlayer().getGameMode() == GameMode.CREATIVE) { - if (!plugin.config.getPermissionsEnabled() || !hasPermission(Perms.NoLimit.PVP)) { + if (!hasPermission(Perms.NoLimit.PVP)) { event.setCancelled(true); } } @@ -312,7 +312,7 @@ public class LCPlayer { public void onDealDamage(EntityDamageByEntityEvent event) { // deals damage if (event.getEntity() instanceof Creature) { if (getPlayer().getGameMode() == GameMode.CREATIVE && plugin.config.getMobDamageBlock()) { - if (!plugin.config.getPermissionsEnabled() || !hasPermission(Perms.NoLimit.MOB_DAMAGE)) { + if (!hasPermission(Perms.NoLimit.MOB_DAMAGE)) { event.setCancelled(true); } } @@ -325,7 +325,7 @@ public class LCPlayer { public void onTarget(EntityTargetEvent event) { if (event.getEntity() instanceof Creature) { if (((Player) event.getTarget()).getGameMode() == GameMode.CREATIVE && plugin.config.getMobDamageBlock()) { - if (!plugin.config.getPermissionsEnabled() || !hasPermission(Perms.NoLimit.MOB_DAMAGE)) { + if (!hasPermission(Perms.NoLimit.MOB_DAMAGE)) { event.setCancelled(true); } } @@ -335,7 +335,7 @@ public class LCPlayer { public void onChestAccess(PlayerInteractEvent event) { if (event.getPlayer().getGameMode() != GameMode.CREATIVE) return; - if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.CHEST)) + if (hasPermission(Perms.NoLimit.CHEST)) return; event.getPlayer().sendMessage(L("blocked.chest")); event.setCancelled(true); @@ -343,7 +343,7 @@ public class LCPlayer { public void onChestAccess(PlayerInteractEntityEvent event) { // chest-minecarts are different events if (getPlayer().getGameMode() != GameMode.CREATIVE) return; - if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.CHEST)) + if (hasPermission(Perms.NoLimit.CHEST)) return; event.getPlayer().sendMessage(L("blocked.chest")); event.setCancelled(true); @@ -351,7 +351,7 @@ public class LCPlayer { public void onBenchAccess(PlayerInteractEvent event) { if (!plugin.config.getBenchBlock() || event.getPlayer().getGameMode() != GameMode.CREATIVE) return; - if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.CHEST)) + if (hasPermission(Perms.NoLimit.CHEST)) return; event.getPlayer().sendMessage(L("blocked.chest")); event.setCancelled(true); @@ -359,7 +359,7 @@ public class LCPlayer { public void onSignAccess(PlayerInteractEvent event) { if (!plugin.config.getSignBlock() || event.getPlayer().getGameMode() != GameMode.CREATIVE) return; - if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.SIGN)) + if (hasPermission(Perms.NoLimit.SIGN)) return; event.getPlayer().sendMessage(L("blocked.sign")); event.setCancelled(true); @@ -368,12 +368,12 @@ public class LCPlayer { if (!plugin.config.getButtonBlock() || event.getPlayer().getGameMode() != GameMode.CREATIVE) return; if (event.getClickedBlock().getState() instanceof Lever) { - if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.LEVER)) + if (hasPermission(Perms.NoLimit.LEVER)) return; event.getPlayer().sendMessage(L("blocked.lever")); event.setCancelled(true); } else { - if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.BUTTON)) + if (hasPermission(Perms.NoLimit.BUTTON)) return; event.getPlayer().sendMessage(L("blocked.button")); event.setCancelled(true); diff --git a/src/de/jaschastarke/minecraft/limitedcreative/Perms.java b/src/de/jaschastarke/minecraft/limitedcreative/Perms.java index f5be286..892200c 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/Perms.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/Perms.java @@ -65,4 +65,14 @@ public enum Perms implements IPermission { return Perms.NS + SEP + NoLimit.NS + SEP + perm; } } + + public static final class CmdBlock { // not the best way, but this matches to everything in this plugin ;) + public static final String NS = "cmdblock"; + + public static IPermission ALL = new IPermission() { + public String toString() { + return Perms.NS + SEP + CmdBlock.NS + SEP + "all"; + } + }; + } } diff --git a/src/de/jaschastarke/minecraft/limitedcreative/cmdblock/CommandBlocker.java b/src/de/jaschastarke/minecraft/limitedcreative/cmdblock/CommandBlocker.java new file mode 100644 index 0000000..3c90e3b --- /dev/null +++ b/src/de/jaschastarke/minecraft/limitedcreative/cmdblock/CommandBlocker.java @@ -0,0 +1,42 @@ +package de.jaschastarke.minecraft.limitedcreative.cmdblock; + +import static de.jaschastarke.minecraft.utils.Locale.L; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +import de.jaschastarke.minecraft.limitedcreative.Core; +import de.jaschastarke.minecraft.limitedcreative.LCPlayer; +import de.jaschastarke.minecraft.limitedcreative.Perms; +import de.jaschastarke.minecraft.limitedcreative.Players; + +public class CommandBlocker { + private Core plugin; + public CommandBlocker(Core plugin) { + this.plugin = plugin; + + plugin.getServer().getPluginManager().registerEvents(new Listener(), plugin); + } + + + class Listener implements org.bukkit.event.Listener { + @EventHandler + public void onPreCommand(PlayerCommandPreprocessEvent event) { + String cmd = event.getMessage(); + if (cmd.startsWith("/")) { // just to be sure ;) + cmd = cmd.substring(1); + for (ICmdBlockEntry blockentry : plugin.config.getCommandBlockList()) { + if (blockentry.test(cmd)) { + LCPlayer player = Players.get(event.getPlayer()); + if (!player.hasPermission(Perms.CmdBlock.ALL)) { + Core.debug("CmdBlock: "+event.getPlayer().getName()+": '/"+cmd+"' blocked by rule '"+blockentry.toString()+"'"); + event.setCancelled(true); + event.getPlayer().sendMessage(L("cmdblock.blocked")); + return; + } + } + } + } + } + } +} diff --git a/src/de/jaschastarke/minecraft/limitedcreative/cmdblock/ICmdBlockEntry.java b/src/de/jaschastarke/minecraft/limitedcreative/cmdblock/ICmdBlockEntry.java new file mode 100644 index 0000000..8036483 --- /dev/null +++ b/src/de/jaschastarke/minecraft/limitedcreative/cmdblock/ICmdBlockEntry.java @@ -0,0 +1,5 @@ +package de.jaschastarke.minecraft.limitedcreative.cmdblock; + +public interface ICmdBlockEntry { + public boolean test(String cmd); +} diff --git a/src/de/jaschastarke/minecraft/limitedcreative/cmdblock/RegexpBlockEntry.java b/src/de/jaschastarke/minecraft/limitedcreative/cmdblock/RegexpBlockEntry.java new file mode 100644 index 0000000..9650e5f --- /dev/null +++ b/src/de/jaschastarke/minecraft/limitedcreative/cmdblock/RegexpBlockEntry.java @@ -0,0 +1,19 @@ +package de.jaschastarke.minecraft.limitedcreative.cmdblock; + +import java.util.regex.Pattern; + +public class RegexpBlockEntry implements ICmdBlockEntry { + private Pattern rx; + public RegexpBlockEntry(String regex) { + rx = Pattern.compile(regex); + } + + @Override + public boolean test(String cmd) { + return rx.matcher(cmd).matches(); + } + + public String toString() { + return rx.pattern(); + } +} diff --git a/src/de/jaschastarke/minecraft/limitedcreative/cmdblock/StringBlockEntry.java b/src/de/jaschastarke/minecraft/limitedcreative/cmdblock/StringBlockEntry.java new file mode 100644 index 0000000..0e4bd12 --- /dev/null +++ b/src/de/jaschastarke/minecraft/limitedcreative/cmdblock/StringBlockEntry.java @@ -0,0 +1,17 @@ +package de.jaschastarke.minecraft.limitedcreative.cmdblock; + +public class StringBlockEntry implements ICmdBlockEntry { + private String str; + public StringBlockEntry(String cmd) { + str = cmd; + } + + @Override + public boolean test(String cmd) { + return cmd.startsWith(this.str); + } + + public String toString() { + return str; + } +} diff --git a/src/de/jaschastarke/minecraft/limitedcreative/listeners/LimitListener.java b/src/de/jaschastarke/minecraft/limitedcreative/listeners/LimitListener.java index d158731..8b0a2ec 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/listeners/LimitListener.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/listeners/LimitListener.java @@ -25,9 +25,11 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; import org.bukkit.entity.Entity; +import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.entity.StorageMinecart; +import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -39,6 +41,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; @@ -76,7 +79,7 @@ public class LimitListener implements Listener { return; LCPlayer player = Players.get(event.getPlayer()); - if (!plugin.config.getPermissionsEnabled() || !player.hasPermission(Perms.NoLimit.USE)) { + if (!player.hasPermission(Perms.NoLimit.USE)) { if (event.getItem() != null && BlackList.isBlackListed(plugin.config.getBlockedUse(), event.getItem())) { event.setCancelled(true); event.setUseItemInHand(Event.Result.DENY); @@ -107,16 +110,25 @@ public class LimitListener implements Listener { return; LCPlayer player = Players.get(event.getPlayer()); - if (!plugin.config.getPermissionsEnabled() || !player.hasPermission(Perms.NoLimit.USE)) { + if (!player.hasPermission(Perms.NoLimit.USE)) { if (event.getPlayer().getItemInHand() != null && BlackList.isBlackListed(plugin.config.getBlockedUse(), event.getPlayer().getItemInHand())) { event.setCancelled(true); event.getPlayer().sendMessage(L("blocked.use")); return; } } - Entity entity = event.getRightClicked(); + // Temporary Solution: While dropping of Items is prevented we don't allow Interaction with ItemFrames, so no + // Items can be "placed" anywhere. + if (!player.hasPermission(Perms.NoLimit.DROP)) { + if (entity instanceof ItemFrame && plugin.config.getRemoveDrop()) { + event.setCancelled(true); + event.getPlayer().sendMessage(L("blocked.use")); + return; + } + } + if (entity instanceof StorageMinecart) { player.onChestAccess(event); } @@ -168,25 +180,24 @@ public class LimitListener implements Listener { Players.get(event.getPlayer()).onRespawn(event); }*/ - @EventHandler - public void onBlockBreak(BlockBreakEvent event) { - if (event.isCancelled()) - return; - if (event.getPlayer().getGameMode() == GameMode.CREATIVE) { - LCPlayer player = Players.get(event.getPlayer()); - if (!plugin.config.getPermissionsEnabled() || !player.hasPermission(Perms.NoLimit.BREAK)) { - if (BlackList.isBlackListed(plugin.config.getBlockedBreaks(), event.getBlock())) { + + private void whenBlockBreak(Cancellable event, Block block, Player eventPlayer) { + if (eventPlayer.getGameMode() == GameMode.CREATIVE) { + LCPlayer player = Players.get(eventPlayer); + if (!player.hasPermission(Perms.NoLimit.BREAK)) { + if (BlackList.isBlackListed(plugin.config.getBlockedBreaks(), block)) { event.setCancelled(true); - event.getPlayer().sendMessage(L("blocked.break")); + eventPlayer.sendMessage(L("blocked.break")); } } - if (plugin.config.getPermissionsEnabled() && player.hasPermission(Perms.NoLimit.DROP)) + if (player.hasPermission(Perms.NoLimit.DROP)) return; // Prevent dropping of doors and beds when destroying the wrong part - Block block = event.getBlock(); + + // TODO: Fix, Remove, or make it god like, but this little thing is crap ;) Material mat = block.getType(); - switch (event.getBlock().getType()) { + switch (block.getType()) { case WOODEN_DOOR: mat = Material.WOOD_DOOR; plugin.spawnblock.block(block.getRelative(BlockFace.DOWN).getLocation(), mat); @@ -203,17 +214,34 @@ public class LimitListener implements Listener { plugin.spawnblock.block(block.getRelative(BlockFace.WEST).getLocation(), mat); break; default: - plugin.spawnblock.block(event.getBlock().getLocation(), mat); + plugin.spawnblock.block(block.getLocation(), mat); } } } + + /* Doesn't make sense yet, as the block always will be Air. whenBlockBreak should be changed to use Material + * instead. Maybe in the Feature. + @EventHandler + public void onHangingBreak(HangingBreakByEntityEvent event) { + if (event.getRemover() instanceof Player) { + Player eventPlayer = (Player) event.getRemover(); + whenBlockBreak(event, event.getEntity().getLocation().getBlock(), eventPlayer); + } + }*/ + + @EventHandler + public void onBlockBreak(BlockBreakEvent event) { + if (event.isCancelled()) + return; + whenBlockBreak(event, event.getBlock(), event.getPlayer()); + } @EventHandler public void onBlockPlace(BlockPlaceEvent event) { if (event.isCancelled()) return; if (event.getPlayer().getGameMode() == GameMode.CREATIVE) { LCPlayer player = Players.get(event.getPlayer()); - if (!plugin.config.getPermissionsEnabled() || !player.hasPermission(Perms.NoLimit.USE)) { + if (!player.hasPermission(Perms.NoLimit.USE)) { if (BlackList.isBlackListed(plugin.config.getBlockedUse(), event.getBlock())) { event.setCancelled(true); event.getPlayer().sendMessage(L("blocked.place")); diff --git a/src/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java b/src/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java index 7862940..6144a66 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java @@ -7,6 +7,8 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Item; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; @@ -14,6 +16,7 @@ import org.bukkit.event.block.BlockPistonExtendEvent; 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 de.jaschastarke.minecraft.limitedcreative.Core; import de.jaschastarke.minecraft.limitedcreative.LCPlayer; @@ -43,27 +46,38 @@ public class RegionListener implements Listener { public void onBlockBreak(BlockBreakEvent event) { if (event.isCancelled()) return; + whenBlockBreak(event, event.getBlock(), event.getPlayer()); + } + + @EventHandler + public void onHangingBreak(HangingBreakByEntityEvent event) { + if (event.getRemover() instanceof Player) { + Player eventPlayer = (Player) event.getRemover(); + whenBlockBreak(event, event.getEntity().getLocation().getBlock(), eventPlayer); + } + } - LCPlayer player = Players.get(event.getPlayer()); - boolean diffrent_region = rm.isDiffrentRegion(event.getPlayer(), event.getBlock().getLocation()); + private void whenBlockBreak(Cancellable event, Block block, Player eventPlayer) { + LCPlayer player = Players.get(eventPlayer); + boolean diffrent_region = rm.isDiffrentRegion(eventPlayer, block.getLocation()); if (player.isActiveRegionGameMode() && diffrent_region) { // do not break outside of "gamemod-change-region" when in the region - if (rm.getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE, event.getPlayer()) != player.getActiveRegionGameMode()) { - event.getPlayer().sendMessage(L("blocked.outside_break")); + if (rm.getRegionSet(block).getFlag(Flags.GAMEMODE, eventPlayer) != player.getActiveRegionGameMode()) { + eventPlayer.sendMessage(L("blocked.outside_break")); event.setCancelled(true); } } else if (diffrent_region) { // do not break inside of "survial-region in creative world" when outside - if (rm.getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE) != null) { - event.getPlayer().sendMessage(L("blocked.inside_break")); + if (rm.getRegionSet(block).getFlag(Flags.GAMEMODE) != null) { + eventPlayer.sendMessage(L("blocked.inside_break")); event.setCancelled(true); } } if (!event.isCancelled()) { // prevent any drops for survival players in creative regions - if (event.getPlayer().getGameMode() != GameMode.CREATIVE && rm.getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE) == GameMode.CREATIVE) { - plugin.spawnblock.block(event.getBlock(), player); + if (eventPlayer.getGameMode() != GameMode.CREATIVE && rm.getRegionSet(block).getFlag(Flags.GAMEMODE) == GameMode.CREATIVE) { + plugin.spawnblock.block(block, player); } } }