diff --git a/src/main/java/com/graywolf336/jail/enums/LangString.java b/src/main/java/com/graywolf336/jail/enums/LangString.java index 2843544..b0b26c4 100644 --- a/src/main/java/com/graywolf336/jail/enums/LangString.java +++ b/src/main/java/com/graywolf336/jail/enums/LangString.java @@ -9,6 +9,8 @@ public enum LangString { BLOCKPLACING ("actions"), /** Section for when they try to do a command that isn't whitelisted. */ COMMAND ("actions"), + /** Section for when a player tramples a crop and protection is enabled. */ + CROPTRAMPLING ("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 631983d..bb8c422 100644 --- a/src/main/java/com/graywolf336/jail/enums/Settings.java +++ b/src/main/java/com/graywolf336/jail/enums/Settings.java @@ -15,6 +15,8 @@ public enum Settings { COMMANDPROTECTION("jailing.during.commandProtection"), COMMANDWHITELIST("jailing.during.commandWhitelist"), COUNTDOWNTIMEOFFLINE("jailing.during.countDownTimeWhileOffline"), + CROPTRAMPLINGPENALTY("jailing.during.cropTramplingPenalty"), + CROPTRAMPLINGPROTECTION("jailing.during.cropTramplingProtection"), DEBUG("system.debug"), DEFAULTJAIL("jailing.jail.defaultJail"), DELETEINVENTORY("jailing.jail.deleteInventory"), diff --git a/src/main/java/com/graywolf336/jail/listeners/ProtectionListener.java b/src/main/java/com/graywolf336/jail/listeners/ProtectionListener.java index 0d5da5e..97034da 100644 --- a/src/main/java/com/graywolf336/jail/listeners/ProtectionListener.java +++ b/src/main/java/com/graywolf336/jail/listeners/ProtectionListener.java @@ -206,4 +206,42 @@ public class ProtectionListener implements Listener { } } } + + @EventHandler(ignoreCancelled=true) + public void cropTramplingProtection(PlayerInteractEvent event) { + //First thing is first, let's be sure the player we're dealing with is in jail + if(pl.getJailManager().isPlayerJailed(event.getPlayer().getName())) { + //Next, check if crap trampling protection is enabled + if(pl.getConfig().getBoolean(Settings.CROPTRAMPLINGPROTECTION.getPath())) { + if(event.getAction() == Action.PHYSICAL && event.getClickedBlock().getType() == Material.SOIL) { + if(pl.getJailManager().getJailFromLocation(event.getClickedBlock().getLocation()) != null) { + try { + long add = Util.getTime(pl.getConfig().getString(Settings.CROPTRAMPLINGPENALTY.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.CROPTRAMPLING)); + }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.CROPTRAMPLING) }); + } + + //Send the message + event.getPlayer().sendMessage(msg); + }catch (Exception e) { + pl.getLogger().severe("Crop Trampling 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 2cf7ea6..d430edf 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -26,6 +26,8 @@ jailing: commandProtection: true commandWhitelist: ['/ping', '/list'] countDownTimeWhileOffline: false + cropTramplingPenalty: 5m + cropTramplingProtection: true foodControl: true foodControlMax: 20 foodControlMin: 10 diff --git a/src/main/resources/en.yml b/src/main/resources/en.yml index aba0b20..56ff447 100644 --- a/src/main/resources/en.yml +++ b/src/main/resources/en.yml @@ -3,6 +3,7 @@ language: blockbreaking: 'breaking a block' blockplacing: 'placing a block' command: 'trying to use a command' + croptrampling: 'trampling crops' general: alljails: 'all the jails' cellremoved: '&9Cell %0% has been successfully removed from the jail %1%.'