mirror of
https://github.com/PEXPlugins/Modifyworld.git
synced 2025-01-06 18:47:53 +01:00
Added player sprint and sneak handlers. issue #78
This commit is contained in:
parent
578e491263
commit
5e24747edf
@ -39,50 +39,65 @@ import ru.tehkode.permissions.PermissionUser;
|
||||
* @author t3hk0d3
|
||||
*/
|
||||
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);
|
||||
|
||||
|
||||
this.whitelistKickMessage = config.getString("messages.whitelist", this.whitelistKickMessage);
|
||||
this.prohibitedItemMessage = config.getString("messages.prohibitedItem", this.prohibitedItemMessage);
|
||||
this.checkInventory = config.getBoolean("itemRestrictions", this.checkInventory);
|
||||
this.dropRestrictedItem = config.getBoolean("drop-restricted-item", this.dropRestrictedItem);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@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) {
|
||||
PermissionUser user = this.permissionsManager.getUser(event.getName());
|
||||
|
||||
|
||||
if (user != null && !user.has("modifyworld.login", Bukkit.getServer().getWorlds().get(0).getName())) {
|
||||
event.disallow(PlayerPreLoginEvent.Result.KICK_WHITELIST, whitelistKickMessage);
|
||||
Logger.getLogger("Minecraft").info("Player \"" + user.getName() + "\" were kicked by Modifyworld - lack of modifyworld.login permission");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(Type.PLAYER_LOGIN)
|
||||
@Toggleable("whitelist")
|
||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||
PermissionUser user = this.permissionsManager.getUser(event.getPlayer());
|
||||
|
||||
|
||||
if (user != null && !user.has("modifyworld.login", Bukkit.getServer().getWorlds().get(0).getName())) {
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, whitelistKickMessage);
|
||||
//event.getPlayer().kickPlayer(whitelistKickMessage);
|
||||
Logger.getLogger("Minecraft").info("Player \"" + user.getName() + "\" were kicked by Modifyworld - lack of modifyworld.login permission");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(Type.PLAYER_BED_ENTER)
|
||||
public void onPlayerBedEnter(PlayerBedEnterEvent event) {
|
||||
if (!permissionsManager.has(event.getPlayer(), "modifyworld.usebeds")) {
|
||||
@ -90,7 +105,7 @@ public class PlayerListener extends ModifyworldListener {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(Type.PLAYER_BUCKET_EMPTY)
|
||||
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
|
||||
String bucketName = event.getBucket().toString().toLowerCase().replace("_bucket", ""); // WATER_BUCKET -> water
|
||||
@ -99,7 +114,7 @@ public class PlayerListener extends ModifyworldListener {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(Type.PLAYER_BUCKET_FILL)
|
||||
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
|
||||
String materialName = event.getBlockClicked().getType().toString().toLowerCase().replace("stationary_", ""); // STATIONARY_WATER -> water
|
||||
@ -108,7 +123,7 @@ public class PlayerListener extends ModifyworldListener {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(Type.PLAYER_COMMAND_PREPROCESS)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
if (event.getMessage().startsWith("/tell") && !permissionsManager.has(event.getPlayer(), "modifyworld.chat.private")) {
|
||||
@ -116,7 +131,7 @@ public class PlayerListener extends ModifyworldListener {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(Type.PLAYER_CHAT)
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
if (!permissionsManager.has(event.getPlayer(), "modifyworld.chat")) {
|
||||
@ -124,36 +139,36 @@ public class PlayerListener extends ModifyworldListener {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(Type.PLAYER_PICKUP_ITEM)
|
||||
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||
if (!canInteractWithMaterial(event.getPlayer(), "modifyworld.items.pickup.", event.getItem().getItemStack().getType())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
|
||||
this.checkPlayerInventory(event.getPlayer());
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(Type.PLAYER_DROP_ITEM)
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
if (!canInteractWithMaterial(event.getPlayer(), "modifyworld.items.drop.", event.getItemDrop().getItemStack().getType())) {
|
||||
informPlayerAboutDenial(event.getPlayer());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
|
||||
this.checkPlayerInventory(event.getPlayer());
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(Type.PLAYER_INVENTORY)
|
||||
public void onInventoryOpen(PlayerInventoryEvent event) {
|
||||
this.checkPlayerInventory(event.getPlayer());
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(Type.PLAYER_ITEM_HELD)
|
||||
public void onItemHeldChange(PlayerItemHeldEvent event) {
|
||||
this.checkPlayerInventory(event.getPlayer());
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(Type.PLAYER_INTERACT_ENTITY)
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
if (!permissionsManager.has(event.getPlayer(), "modifyworld.interact." + getEntityName(event.getRightClicked()))) {
|
||||
@ -161,31 +176,34 @@ public class PlayerListener extends ModifyworldListener {
|
||||
informPlayerAboutDenial(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
|
||||
if (!canInteractWithMaterial(event.getPlayer(), "modifyworld.blocks.interact.", event.getClickedBlock().getType())) {
|
||||
informPlayerAboutDenial(event.getPlayer());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void checkPlayerInventory(Player player) {
|
||||
if (!checkInventory) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Inventory inventory = player.getInventory();
|
||||
for (ItemStack stack : inventory.getContents()) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user