From 95649e7f03c2d84eb7598c32baa63ed97b0406a9 Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Sun, 19 Jan 2014 14:40:39 -0600 Subject: [PATCH] Start work on the protection and penalties. First up is Block Place --- .../java/com/graywolf336/jail/JailMain.java | 2 + .../com/graywolf336/jail/beans/Prisoner.java | 9 ++++ .../graywolf336/jail/enums/LangString.java | 9 ++++ .../com/graywolf336/jail/enums/Settings.java | 2 + .../jail/listeners/ProtectionListener.java | 43 +++++++++++++++++++ src/main/resources/config.yml | 2 + src/main/resources/en.yml | 4 ++ 7 files changed, 71 insertions(+) create mode 100644 src/main/java/com/graywolf336/jail/listeners/ProtectionListener.java diff --git a/src/main/java/com/graywolf336/jail/JailMain.java b/src/main/java/com/graywolf336/jail/JailMain.java index e9f1648..94e5b25 100644 --- a/src/main/java/com/graywolf336/jail/JailMain.java +++ b/src/main/java/com/graywolf336/jail/JailMain.java @@ -12,6 +12,7 @@ import com.graywolf336.jail.listeners.BlockListener; import com.graywolf336.jail.listeners.EntityListener; import com.graywolf336.jail.listeners.HandCuffListener; import com.graywolf336.jail.listeners.PlayerListener; +import com.graywolf336.jail.listeners.ProtectionListener; /** * The main class for this Jail plugin, holds instances of vital classes. @@ -47,6 +48,7 @@ public class JailMain extends JavaPlugin { plm.registerEvents(new EntityListener(this), this); plm.registerEvents(new HandCuffListener(this), this); plm.registerEvents(new PlayerListener(this), this); + plm.registerEvents(new ProtectionListener(this), this); jt = new JailTimer(this); diff --git a/src/main/java/com/graywolf336/jail/beans/Prisoner.java b/src/main/java/com/graywolf336/jail/beans/Prisoner.java index 70ab5ad..d3f656d 100644 --- a/src/main/java/com/graywolf336/jail/beans/Prisoner.java +++ b/src/main/java/com/graywolf336/jail/beans/Prisoner.java @@ -85,6 +85,15 @@ public class Prisoner { this.time = time; } + /** + * Adds the given time to the remaining time the prisoner has left. + * + * @param time to add to the prisoner's remaining time. + */ + public void addTime(long time) { + this.time += time; + } + /** Gets whether the player is offline or not. */ public boolean isOfflinePending() { return this.offlinePending; diff --git a/src/main/java/com/graywolf336/jail/enums/LangString.java b/src/main/java/com/graywolf336/jail/enums/LangString.java index ab75046..996ea9c 100644 --- a/src/main/java/com/graywolf336/jail/enums/LangString.java +++ b/src/main/java/com/graywolf336/jail/enums/LangString.java @@ -1,6 +1,13 @@ package com.graywolf336.jail.enums; public enum LangString { + //actions section + + /** Section for when they break a block. */ + BLOCKBREAKING ("actions"), + /** Section for when they place a block. */ + BLOCKPLACING ("actions"), + //Jailing section /** The message displayed when players are kicked for being afk. */ @@ -19,6 +26,8 @@ public enum LangString { JAILEDWITHREASON ("jailing"), /** The message sent when players are jailed and they try to talk. */ MUTED ("jailing"), + /** The message sent to the prisoner when they try to do something but it is protected. */ + PROTECTIONMESSAGE ("jailing"), /** The message sent when players are released from jail. */ UNJAILED ("jailing"), diff --git a/src/main/java/com/graywolf336/jail/enums/Settings.java b/src/main/java/com/graywolf336/jail/enums/Settings.java index 3a60e9c..8224fe9 100644 --- a/src/main/java/com/graywolf336/jail/enums/Settings.java +++ b/src/main/java/com/graywolf336/jail/enums/Settings.java @@ -2,7 +2,9 @@ package com.graywolf336.jail.enums; public enum Settings { BROADCASTJAILING("jailing.jail.broadcastJailing"), + BLOCKBREAKPENALTY("jailing.during.blockBreakPenalty"), BLOCKBREAKPROTECTION("jailing.during.blockBreakProtection"), + BLOCKPLACEPENALTY("jailing.during.blockPlacePenalty"), BLOCKPLACEPROTECTION("jailing.during.blockPlaceProtection"), COMMANDSONJAIL("jailing.jail.commands"), COMMANDSONRELEASE("jailing.release.commands"), diff --git a/src/main/java/com/graywolf336/jail/listeners/ProtectionListener.java b/src/main/java/com/graywolf336/jail/listeners/ProtectionListener.java new file mode 100644 index 0000000..acccdef --- /dev/null +++ b/src/main/java/com/graywolf336/jail/listeners/ProtectionListener.java @@ -0,0 +1,43 @@ +package com.graywolf336.jail.listeners; + +import java.util.concurrent.TimeUnit; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; + +import com.graywolf336.jail.JailMain; +import com.graywolf336.jail.Util; +import com.graywolf336.jail.enums.LangString; +import com.graywolf336.jail.enums.Settings; + +public class ProtectionListener implements Listener { + private JailMain pl; + + public ProtectionListener(JailMain plugin) { + this.pl = plugin; + } + + @EventHandler(ignoreCancelled=true) + public void protectionBlockBreaking(BlockBreakEvent event) { + //Before we check if the player is jailed, let's save a + //tiny bit of resources and check if this protection is enabled + if(pl.getConfig().getBoolean(Settings.BLOCKBREAKPROTECTION.getPath())) { + if(pl.getJailManager().isPlayerJailed(event.getPlayer().getName())) { + try { + long add = Util.getTime(pl.getConfig().getString(Settings.BLOCKBREAKPENALTY.getPath())); + pl.getJailManager().getPrisoner(event.getPlayer().getName()).addTime(add); + + String msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGE, + new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)), + pl.getJailIO().getLanguageString(LangString.BLOCKBREAKING) }); + + event.getPlayer().sendMessage(msg); + }catch (Exception e) { + pl.getLogger().severe("Block break penalty's time is in the wrong format, please fix."); + } + + } + } + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 523a1b5..baee63d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -13,7 +13,9 @@ storage: password: 'password' jailing: during: + blockBreakPenalty: 5m blockBreakProtection: true + blockPlacePenalty: 5m blockPlaceProtection: true countDownTimeWhileOffline: false explosionProtection: true diff --git a/src/main/resources/en.yml b/src/main/resources/en.yml index 7721e49..4963504 100644 --- a/src/main/resources/en.yml +++ b/src/main/resources/en.yml @@ -1,4 +1,7 @@ language: + actions: + blockbreaking: 'breaking a block' + blockplacing: 'placing a block' general: unknowncommand: '&cNo commands registered by the name of %0%.' nopermission: '&cInsufficient permission.' @@ -13,6 +16,7 @@ language: jailed: '&cYou have been jailed!' jailedwithreason: '&cYou have been jailed for: %0%' muted: '&cStop talking, you are in jail.' + protectionmessage: '&c%0% minutes has been added to your time for %1%.' unjailed: '&2You have been released! Please respect the server rules.' handcuffing: cantbehandcuffed: '&9%0% &ccan not be handcuffed.'