Add command restrict while sitting

This commit is contained in:
Shevchik 2013-12-15 20:10:22 +04:00
parent 6e8132ee0f
commit 4567af8d83
4 changed files with 67 additions and 9 deletions

View File

@ -34,14 +34,16 @@ public class Chairs extends JavaPlugin {
public boolean invertedStairCheck, invertedStepCheck, ignoreIfBlockInHand;
public boolean sitEffectsEnabled;
public double distance;
public HashSet<String> disabledRegions = new HashSet<String>();
public int maxChairWidth;
public int sitMaxHealth;
public int sitHealthPerInterval;
public int sitEffectInterval;
public HashSet<String> disabledRegions = new HashSet<String>();
public boolean sitDisableAllCommands = false;
public HashSet<String> sitDisabledCommands = new HashSet<String>();
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<String>(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<ChairBlock>();
for (String s : config.getStringList("sit-blocks")) {

View File

@ -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);
}
}
}
}
}
}

View File

@ -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;

View File

@ -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'