diff --git a/src/com/cnaude/chairs/Chairs.java b/src/com/cnaude/chairs/Chairs.java index 87ee854..a09c8f5 100644 --- a/src/com/cnaude/chairs/Chairs.java +++ b/src/com/cnaude/chairs/Chairs.java @@ -34,14 +34,16 @@ public class Chairs extends JavaPlugin { public boolean invertedStairCheck, invertedStepCheck, ignoreIfBlockInHand; public boolean sitEffectsEnabled; public double distance; + public HashSet disabledRegions = new HashSet(); public int maxChairWidth; public int sitMaxHealth; public int sitHealthPerInterval; public int sitEffectInterval; - public HashSet disabledRegions = new HashSet(); + public boolean sitDisableAllCommands = false; + public HashSet sitDisabledCommands = new HashSet(); private Logger log; public ChairsIgnoreList ignoreList; - public String msgSitting, msgStanding, msgOccupied, msgNoPerm, msgReloaded, msgDisabled, msgEnabled; + public String msgSitting, msgStanding, msgOccupied, msgNoPerm, msgReloaded, msgDisabled, msgEnabled, msgCommandRestricted; private Class vehiclearrowclass; @@ -71,12 +73,8 @@ public class Chairs extends JavaPlugin { loadConfig(); getServer().getPluginManager().registerEvents(new TrySitEventListener(this, ignoreList), this); getServer().getPluginManager().registerEvents(new TryUnsitEventListener(this), this); + getServer().getPluginManager().registerEvents(new CommandRestrict(this), this); getCommand("chairs").setExecutor(new ChairsCommand(this, ignoreList)); - if (sitEffectsEnabled) { - logInfo("Enabling sitting effects."); - chairEffects = new ChairEffects(this); - } - } @Override @@ -243,6 +241,16 @@ public class Chairs extends JavaPlugin { sitEffectInterval = config.getInt("sit-effects.interval",20); sitMaxHealth = config.getInt("sit-effects.healing.max-percent",100); sitHealthPerInterval = config.getInt("sit-effects.healing.amount",1); + if (sitEffectsEnabled) { + if (chairEffects != null) { + chairEffects.cancel(); + } + logInfo("Enabling sitting effects."); + chairEffects = new ChairEffects(this); + } + + sitDisableAllCommands = config.getBoolean("sit-restrictions.commands.all"); + sitDisabledCommands = new HashSet(config.getStringList("sit-restrictions.commands.list")); msgSitting = ChatColor.translateAlternateColorCodes('&',config.getString("messages.sitting")); msgStanding = ChatColor.translateAlternateColorCodes('&',config.getString("messages.standing")); @@ -251,6 +259,7 @@ public class Chairs extends JavaPlugin { msgEnabled = ChatColor.translateAlternateColorCodes('&',config.getString("messages.enabled")); msgDisabled = ChatColor.translateAlternateColorCodes('&',config.getString("messages.disabled")); msgReloaded = ChatColor.translateAlternateColorCodes('&',config.getString("messages.reloaded")); + msgCommandRestricted = ChatColor.translateAlternateColorCodes('&',config.getString("messages.command-restricted")); allowedBlocks = new ArrayList(); for (String s : config.getStringList("sit-blocks")) { diff --git a/src/com/cnaude/chairs/CommandRestrict.java b/src/com/cnaude/chairs/CommandRestrict.java new file mode 100644 index 0000000..49ae2c5 --- /dev/null +++ b/src/com/cnaude/chairs/CommandRestrict.java @@ -0,0 +1,43 @@ +package com.cnaude.chairs; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +public class CommandRestrict implements Listener { + + private Chairs plugin; + public CommandRestrict(Chairs plugin) { + this.plugin = plugin; + } + + @EventHandler(priority=EventPriority.LOWEST) + public void onPlayerCommand(PlayerCommandPreprocessEvent event) + { + Player player = event.getPlayer(); + String playercommand = event.getMessage().toLowerCase(); + if (plugin.sit.containsKey(player.getName())) + { + for (String disabledCommand : plugin.sitDisabledCommands) + { + if (plugin.sitDisableAllCommands) + { + event.setCancelled(true); + player.sendMessage(plugin.msgCommandRestricted); + } else + if (disabledCommand.startsWith(playercommand)) + { + String therest = disabledCommand.replace(playercommand, ""); + if (therest.startsWith(" ")) + { + event.setCancelled(true); + player.sendMessage(plugin.msgCommandRestricted); + } + } + } + } + } + +} diff --git a/src/com/cnaude/chairs/TryUnsitEventListener.java b/src/com/cnaude/chairs/TryUnsitEventListener.java index 1491a49..016d3eb 100644 --- a/src/com/cnaude/chairs/TryUnsitEventListener.java +++ b/src/com/cnaude/chairs/TryUnsitEventListener.java @@ -3,7 +3,6 @@ package com.cnaude.chairs; import java.util.HashSet; import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; diff --git a/src/config.yml b/src/config.yml index fb354a4..a8a22ee 100644 --- a/src/config.yml +++ b/src/config.yml @@ -38,13 +38,19 @@ distance: 2 upside-down-check: true upper-step-check: true ignore-if-item-in-hand: false -disabledWGRegions: [] +disabledWGRegions: +- exampleregionname sit-effects: enabled: false interval: 20 healing: amount: 1 max-percent: 100 +sit-restrictions: + commands: + all: false + list: + - /examplecommand notify-player: true messages: sitting: '&7You are now sitting.' @@ -54,3 +60,4 @@ messages: no-permission: '&cYou do not have permission to do this!' enabled: '&7You have enabled chairs for yourself!' disabled: '&7You have disabled chairs for yourself!' + command-restricted: '&7You can't issue this command while sitting'