Add command restrict while sitting
This commit is contained in:
parent
6e8132ee0f
commit
4567af8d83
@ -34,14 +34,16 @@ public class Chairs extends JavaPlugin {
|
|||||||
public boolean invertedStairCheck, invertedStepCheck, ignoreIfBlockInHand;
|
public boolean invertedStairCheck, invertedStepCheck, ignoreIfBlockInHand;
|
||||||
public boolean sitEffectsEnabled;
|
public boolean sitEffectsEnabled;
|
||||||
public double distance;
|
public double distance;
|
||||||
|
public HashSet<String> disabledRegions = new HashSet<String>();
|
||||||
public int maxChairWidth;
|
public int maxChairWidth;
|
||||||
public int sitMaxHealth;
|
public int sitMaxHealth;
|
||||||
public int sitHealthPerInterval;
|
public int sitHealthPerInterval;
|
||||||
public int sitEffectInterval;
|
public int sitEffectInterval;
|
||||||
public HashSet<String> disabledRegions = new HashSet<String>();
|
public boolean sitDisableAllCommands = false;
|
||||||
|
public HashSet<String> sitDisabledCommands = new HashSet<String>();
|
||||||
private Logger log;
|
private Logger log;
|
||||||
public ChairsIgnoreList ignoreList;
|
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;
|
private Class<?> vehiclearrowclass;
|
||||||
|
|
||||||
@ -71,12 +73,8 @@ public class Chairs extends JavaPlugin {
|
|||||||
loadConfig();
|
loadConfig();
|
||||||
getServer().getPluginManager().registerEvents(new TrySitEventListener(this, ignoreList), this);
|
getServer().getPluginManager().registerEvents(new TrySitEventListener(this, ignoreList), this);
|
||||||
getServer().getPluginManager().registerEvents(new TryUnsitEventListener(this), this);
|
getServer().getPluginManager().registerEvents(new TryUnsitEventListener(this), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new CommandRestrict(this), this);
|
||||||
getCommand("chairs").setExecutor(new ChairsCommand(this, ignoreList));
|
getCommand("chairs").setExecutor(new ChairsCommand(this, ignoreList));
|
||||||
if (sitEffectsEnabled) {
|
|
||||||
logInfo("Enabling sitting effects.");
|
|
||||||
chairEffects = new ChairEffects(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -243,6 +241,16 @@ public class Chairs extends JavaPlugin {
|
|||||||
sitEffectInterval = config.getInt("sit-effects.interval",20);
|
sitEffectInterval = config.getInt("sit-effects.interval",20);
|
||||||
sitMaxHealth = config.getInt("sit-effects.healing.max-percent",100);
|
sitMaxHealth = config.getInt("sit-effects.healing.max-percent",100);
|
||||||
sitHealthPerInterval = config.getInt("sit-effects.healing.amount",1);
|
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"));
|
msgSitting = ChatColor.translateAlternateColorCodes('&',config.getString("messages.sitting"));
|
||||||
msgStanding = ChatColor.translateAlternateColorCodes('&',config.getString("messages.standing"));
|
msgStanding = ChatColor.translateAlternateColorCodes('&',config.getString("messages.standing"));
|
||||||
@ -251,6 +259,7 @@ public class Chairs extends JavaPlugin {
|
|||||||
msgEnabled = ChatColor.translateAlternateColorCodes('&',config.getString("messages.enabled"));
|
msgEnabled = ChatColor.translateAlternateColorCodes('&',config.getString("messages.enabled"));
|
||||||
msgDisabled = ChatColor.translateAlternateColorCodes('&',config.getString("messages.disabled"));
|
msgDisabled = ChatColor.translateAlternateColorCodes('&',config.getString("messages.disabled"));
|
||||||
msgReloaded = ChatColor.translateAlternateColorCodes('&',config.getString("messages.reloaded"));
|
msgReloaded = ChatColor.translateAlternateColorCodes('&',config.getString("messages.reloaded"));
|
||||||
|
msgCommandRestricted = ChatColor.translateAlternateColorCodes('&',config.getString("messages.command-restricted"));
|
||||||
|
|
||||||
allowedBlocks = new ArrayList<ChairBlock>();
|
allowedBlocks = new ArrayList<ChairBlock>();
|
||||||
for (String s : config.getStringList("sit-blocks")) {
|
for (String s : config.getStringList("sit-blocks")) {
|
||||||
|
43
src/com/cnaude/chairs/CommandRestrict.java
Normal file
43
src/com/cnaude/chairs/CommandRestrict.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,7 +3,6 @@ package com.cnaude.chairs;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
@ -38,13 +38,19 @@ distance: 2
|
|||||||
upside-down-check: true
|
upside-down-check: true
|
||||||
upper-step-check: true
|
upper-step-check: true
|
||||||
ignore-if-item-in-hand: false
|
ignore-if-item-in-hand: false
|
||||||
disabledWGRegions: []
|
disabledWGRegions:
|
||||||
|
- exampleregionname
|
||||||
sit-effects:
|
sit-effects:
|
||||||
enabled: false
|
enabled: false
|
||||||
interval: 20
|
interval: 20
|
||||||
healing:
|
healing:
|
||||||
amount: 1
|
amount: 1
|
||||||
max-percent: 100
|
max-percent: 100
|
||||||
|
sit-restrictions:
|
||||||
|
commands:
|
||||||
|
all: false
|
||||||
|
list:
|
||||||
|
- /examplecommand
|
||||||
notify-player: true
|
notify-player: true
|
||||||
messages:
|
messages:
|
||||||
sitting: '&7You are now sitting.'
|
sitting: '&7You are now sitting.'
|
||||||
@ -54,3 +60,4 @@ messages:
|
|||||||
no-permission: '&cYou do not have permission to do this!'
|
no-permission: '&cYou do not have permission to do this!'
|
||||||
enabled: '&7You have enabled chairs for yourself!'
|
enabled: '&7You have enabled chairs for yourself!'
|
||||||
disabled: '&7You have disabled chairs for yourself!'
|
disabled: '&7You have disabled chairs for yourself!'
|
||||||
|
command-restricted: '&7You can't issue this command while sitting'
|
||||||
|
Loading…
Reference in New Issue
Block a user