diff --git a/src/main/java/com/graywolf336/jail/enums/LangString.java b/src/main/java/com/graywolf336/jail/enums/LangString.java index b0b26c4..6d99d16 100644 --- a/src/main/java/com/graywolf336/jail/enums/LangString.java +++ b/src/main/java/com/graywolf336/jail/enums/LangString.java @@ -11,6 +11,10 @@ public enum LangString { COMMAND ("actions"), /** Section for when a player tramples a crop and protection is enabled. */ CROPTRAMPLING ("actions"), + /** Section for when a player interacts with a block that is blacklisted. */ + INTERACTIONBLOCKS ("actions"), + /** Section for when a player interacts with an item that is blacklisted. */ + INTERACTIONITEMS ("actions"), //Jailing section diff --git a/src/main/java/com/graywolf336/jail/enums/Settings.java b/src/main/java/com/graywolf336/jail/enums/Settings.java index bb8c422..eedf0fd 100644 --- a/src/main/java/com/graywolf336/jail/enums/Settings.java +++ b/src/main/java/com/graywolf336/jail/enums/Settings.java @@ -32,6 +32,10 @@ public enum Settings { LOGJAILING("jailing.jail.logToConsole"), MAXAFKTIME("jailing.during.maxAFKTime"), OPENCHEST("jailing.during.openChest"), + PREVENTINTERACTIONBLOCKS("jailing.during.preventInteractionBlocks"), + PREVENTINTERACTIONBLOCKSPENALTY("jailing.during.preventInteractionBlocksPenalty"), + PREVENTINTERACTIONITEMS("jailing.during.preventInteractionItems"), + PREVENTINTERACTIONITEMSPENALTY("jailing.during.preventInteractionItemsPenalty"), RECIEVEMESSAGES("jailing.during.recieveMessages"), RELEASETOPREVIOUSPOSITION("jailing.release.backToPreviousPosition"), RESTOREPREVIOUSGAMEMODE("jailing.release.restorePreviousGameMode"), diff --git a/src/main/java/com/graywolf336/jail/listeners/ProtectionListener.java b/src/main/java/com/graywolf336/jail/listeners/ProtectionListener.java index 769b485..be1e426 100644 --- a/src/main/java/com/graywolf336/jail/listeners/ProtectionListener.java +++ b/src/main/java/com/graywolf336/jail/listeners/ProtectionListener.java @@ -34,7 +34,6 @@ public class ProtectionListener implements Listener { //of the jails. if(pl.getJailManager().isPlayerJailed(event.getPlayer().getName())) { //Get the breaking whitelist, check if the current item is in there - //the list must be lowercase, need to stress that if(!Util.isStringInsideList(pl.getConfig().getStringList(Settings.BLOCKBREAKWHITELIST.getPath()), event.getBlock().getType().toString().toLowerCase())) { //As our Util.getTime throws an exception when the time is in an @@ -80,7 +79,6 @@ public class ProtectionListener implements Listener { //of the jails. if(pl.getJailManager().isPlayerJailed(event.getPlayer().getName())) { //Get the placing whitelist, check if the current item is in there - //the list must be lowercase, need to stress that if(!Util.isStringInsideList(pl.getConfig().getStringList(Settings.BLOCKPLACEWHITELIST.getPath()), event.getBlock().getType().toString().toLowerCase())) { //As our Util.getTime throws an exception when the time is in an @@ -244,4 +242,78 @@ public class ProtectionListener implements Listener { } } } + + @EventHandler(ignoreCancelled=true) + public void interactionProtection(PlayerInteractEvent event) { + //As the old version didn't do anything with Physical interactions, we won't either + if (event.getAction() != Action.PHYSICAL) { + //First thing is first, let's be sure the player we're dealing with is in jail + if(pl.getJailManager().isPlayerJailed(event.getPlayer().getName())) { + + //Let's check if they've interacted with a block + if (event.getClickedBlock() != null) { + //Get the interaction blacklist, check if the current block is in there + //if it is, then let's take action + if(Util.isStringInsideList(pl.getConfig().getStringList(Settings.PREVENTINTERACTIONBLOCKS.getPath()), + event.getClickedBlock().getType().toString().toLowerCase())) { + try { + long add = Util.getTime(pl.getConfig().getString(Settings.PREVENTINTERACTIONBLOCKSPENALTY.getPath())); + pl.getJailManager().getPrisoner(event.getPlayer().getName()).addTime(add); + + String msg = ""; + if(add == 0L) { + //Generate the protection message, provide the method with one argument + //which is the thing we are protecting against + msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGENOPENALTY, pl.getJailIO().getLanguageString(LangString.INTERACTIONBLOCKS)); + }else { + //Generate the protection message, provide the method with two arguments + //First is the time in minutes and second is the thing we are protecting against + msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGE, + new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)), + pl.getJailIO().getLanguageString(LangString.INTERACTIONBLOCKS) }); + } + + //Send the message + event.getPlayer().sendMessage(msg); + }catch(Exception e) { + pl.getLogger().severe("Prevent Interaction with Blocks penalty's time is in the wrong format, please fix."); + } + + event.setCancelled(true); + } + }else if (event.getPlayer().getItemInHand() != null) { + //Otherwise let's check if they have something in hand + //Get the interaction blacklist, check if the current item is in there + //if it is, then let's take action + if(Util.isStringInsideList(pl.getConfig().getStringList(Settings.PREVENTINTERACTIONITEMS.getPath()), + event.getClickedBlock().getType().toString().toLowerCase())) { + try { + long add = Util.getTime(pl.getConfig().getString(Settings.PREVENTINTERACTIONITEMSPENALTY.getPath())); + pl.getJailManager().getPrisoner(event.getPlayer().getName()).addTime(add); + + String msg = ""; + if(add == 0L) { + //Generate the protection message, provide the method with one argument + //which is the thing we are protecting against + msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGENOPENALTY, pl.getJailIO().getLanguageString(LangString.INTERACTIONITEMS)); + }else { + //Generate the protection message, provide the method with two arguments + //First is the time in minutes and second is the thing we are protecting against + msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGE, + new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)), + pl.getJailIO().getLanguageString(LangString.INTERACTIONITEMS) }); + } + + //Send the message + event.getPlayer().sendMessage(msg); + }catch(Exception e) { + pl.getLogger().severe("Prevent Interaction with Items penalty's time is in the wrong format, please fix."); + } + + event.setCancelled(true); + } + } + } + } + } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index d430edf..b04fec0 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -34,6 +34,10 @@ jailing: ignoreSleeping: true maxAFKTime: 10m #in minutes openChest: true + preventInteractionBlocks: ['wooden_door', 'iron_door_block'] + preventInteractionBlocksPenalty: 5m + preventInteractionItems: [] + preventInteractionItemsPenalty: 5m recieveMessages: true jail: automaticMute: true diff --git a/src/main/resources/en.yml b/src/main/resources/en.yml index 56ff447..09d1f60 100644 --- a/src/main/resources/en.yml +++ b/src/main/resources/en.yml @@ -4,6 +4,8 @@ language: blockplacing: 'placing a block' command: 'trying to use a command' croptrampling: 'trampling crops' + interactionBlocks: 'interacting with a block' + interactionItems: 'interacting with an item' general: alljails: 'all the jails' cellremoved: '&9Cell %0% has been successfully removed from the jail %1%.'