Added player sprint and sneak handlers. issue #78

This commit is contained in:
t3hk0d3 2011-10-07 00:14:21 +04:00
parent 578e491263
commit 5e24747edf

View File

@ -42,14 +42,11 @@ public class PlayerListener extends ModifyworldListener {
public final static String WHITELIST_MESSAGE = "You are not allowed to join this server. Goodbye!";
public final static String PROHIBITED_ITEM = "You have prohibited item \"%s\".";
protected boolean checkInventory = false;
protected boolean dropRestrictedItem = false;
protected String whitelistKickMessage = WHITELIST_MESSAGE;
protected String prohibitedItemMessage = PROHIBITED_ITEM;
public PlayerListener(Plugin plugin, ConfigurationNode config) {
super(plugin, config);
@ -60,6 +57,24 @@ public class PlayerListener extends ModifyworldListener {
}
@EventHandler(Type.PLAYER_TOGGLE_SNEAK)
public void onPlayerSneak(PlayerToggleSneakEvent event) {
if (event.isSneaking() && !permissionsManager.has(event.getPlayer(), "modifyworld.sneak")) {
informPlayer(event.getPlayer(), ChatColor.RED + "Sorry, you don't have enough permissions");
event.setCancelled(true);
event.getPlayer().setSneaking(false);
}
}
@EventHandler(Type.PLAYER_TOGGLE_SPRINT)
public void onPlayerSprint(PlayerToggleSprintEvent event) {
if (event.isSprinting() && !permissionsManager.has(event.getPlayer(), "modifyworld.sprint")) {
informPlayer(event.getPlayer(), ChatColor.RED + "Sorry, you don't have enough permissions");
event.setCancelled(true);
event.getPlayer().setSprinting(false);
}
}
@EventHandler(Type.PLAYER_PRELOGIN)
@Toggleable("whitelist")
public void onPlayerPreLogin(PlayerPreLoginEvent event) {
@ -164,6 +179,9 @@ public class PlayerListener extends ModifyworldListener {
@EventHandler(Type.PLAYER_INTERACT)
public void onPlayerInteract(PlayerInteractEvent event) {
// Checking item restriction
this.checkPlayerInventory(event.getPlayer());
Action action = event.getAction();
if (action != Action.LEFT_CLICK_BLOCK && action != Action.RIGHT_CLICK_BLOCK && action != Action.PHYSICAL) {
return;
@ -185,7 +203,7 @@ public class PlayerListener extends ModifyworldListener {
if (stack != null && !permissionsManager.has(player, "modifyworld.items.have." + stack.getTypeId())) {
inventory.remove(stack);
if(this.dropRestrictedItem){
if (this.dropRestrictedItem) {
player.getWorld().dropItemNaturally(player.getLocation(), stack);
}