From 4eae8778ea572afaae31fcf43e7a27f7a2ff29c9 Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Mon, 20 Jan 2014 15:24:27 -0600 Subject: [PATCH] Enable food control --- .../com/graywolf336/jail/PrisonerManager.java | 4 ++-- .../com/graywolf336/jail/enums/Settings.java | 5 +++-- .../jail/listeners/PlayerListener.java | 17 +++++++++++++++++ src/main/resources/config.yml | 5 +++-- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/graywolf336/jail/PrisonerManager.java b/src/main/java/com/graywolf336/jail/PrisonerManager.java index 133bdaa..927e5b9 100644 --- a/src/main/java/com/graywolf336/jail/PrisonerManager.java +++ b/src/main/java/com/graywolf336/jail/PrisonerManager.java @@ -178,8 +178,8 @@ public class PrisonerManager { } //Get the max and min food level in the config - int maxFood = pl.getConfig().getInt(Settings.MAXFOODLEVEL.getPath(), 20); - int minFood = pl.getConfig().getInt(Settings.MINFOODLEVEL.getPath(), 10); + int maxFood = pl.getConfig().getInt(Settings.FOODCONTROLMAX.getPath(), 20); + int minFood = pl.getConfig().getInt(Settings.FOODCONTROLMIN.getPath(), 10); //If their food level is less than the min food level, set it to the min //but if it is higher than the max, set it to the max diff --git a/src/main/java/com/graywolf336/jail/enums/Settings.java b/src/main/java/com/graywolf336/jail/enums/Settings.java index 8c905f8..2cc7abb 100644 --- a/src/main/java/com/graywolf336/jail/enums/Settings.java +++ b/src/main/java/com/graywolf336/jail/enums/Settings.java @@ -18,14 +18,15 @@ public enum Settings { DEFAULTJAIL("jailing.jail.defaultJail"), DELETEINVENTORY("jailing.jail.deleteInventory"), EXPLOSIONPROTECTION("jailing.during.explosionProtection"), + FOODCONTROL("jailing.during.foodControl"), + FOODCONTROLMAX("jailing.during.foodControlMax"), + FOODCONTROLMIN("jailing.during.foodControlMin"), IGNORESLEEPINGSTATE("jailing.during.ignoreSleeping"), JAILDEFAULTTIME("jailing.jail.defaultTime"), JAILEDGAMEMODE("jailing.jail.gameMode"), JAILEDSTOREINVENTORY("jailing.jail.storeInventory"), LOGJAILING("jailing.jail.logToConsole"), MAXAFKTIME("jailing.during.maxAFKTime"), - MAXFOODLEVEL("jailing.during.maxFoodLevel"), - MINFOODLEVEL("jailing.during.minFoodLevel"), RECIEVEMESSAGES("jailing.during.recieveMessages"), RELEASETOPREVIOUSPOSITION("jailing.release.backToPreviousPosition"), RESTOREPREVIOUSGAMEMODE("jailing.release.restorePreviousGameMode"), diff --git a/src/main/java/com/graywolf336/jail/listeners/PlayerListener.java b/src/main/java/com/graywolf336/jail/listeners/PlayerListener.java index 4ffa8da..dab1914 100644 --- a/src/main/java/com/graywolf336/jail/listeners/PlayerListener.java +++ b/src/main/java/com/graywolf336/jail/listeners/PlayerListener.java @@ -8,6 +8,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; +import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; @@ -83,4 +84,20 @@ public class PlayerListener implements Listener { } } } + + @EventHandler + public void foodControl(FoodLevelChangeEvent event) { + if(pl.getConfig().getBoolean(Settings.FOODCONTROL.getPath())) { + if(pl.getJailManager().isPlayerJailed(event.getEntity().getName())) { + int min = pl.getConfig().getInt(Settings.FOODCONTROLMIN.getPath()); + int max = pl.getConfig().getInt(Settings.FOODCONTROLMAX.getPath()); + + if (event.getFoodLevel() < min) { + event.setFoodLevel(min); + }else { + event.setFoodLevel(max); + } + } + } + } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 26436be..b776811 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -24,10 +24,11 @@ jailing: commandWhitelist: ['/ping', '/list'] countDownTimeWhileOffline: false explosionProtection: true + foodControl: true + foodControlMax: 20 + foodControlMin: 10 ignoreSleeping: true maxAFKTime: 10m #in minutes - maxFoodLevel: 20 - minFoodLevel: 10 openChest: true recieveMessages: true jail: