Start work on the protection and penalties. First up is Block Place

This commit is contained in:
graywolf336 2014-01-19 14:40:39 -06:00
parent d9d0de046d
commit 95649e7f03
7 changed files with 71 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import com.graywolf336.jail.listeners.BlockListener;
import com.graywolf336.jail.listeners.EntityListener; import com.graywolf336.jail.listeners.EntityListener;
import com.graywolf336.jail.listeners.HandCuffListener; import com.graywolf336.jail.listeners.HandCuffListener;
import com.graywolf336.jail.listeners.PlayerListener; import com.graywolf336.jail.listeners.PlayerListener;
import com.graywolf336.jail.listeners.ProtectionListener;
/** /**
* The main class for this Jail plugin, holds instances of vital classes. * 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 EntityListener(this), this);
plm.registerEvents(new HandCuffListener(this), this); plm.registerEvents(new HandCuffListener(this), this);
plm.registerEvents(new PlayerListener(this), this); plm.registerEvents(new PlayerListener(this), this);
plm.registerEvents(new ProtectionListener(this), this);
jt = new JailTimer(this); jt = new JailTimer(this);

View File

@ -85,6 +85,15 @@ public class Prisoner {
this.time = time; 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. */ /** Gets whether the player is offline or not. */
public boolean isOfflinePending() { public boolean isOfflinePending() {
return this.offlinePending; return this.offlinePending;

View File

@ -1,6 +1,13 @@
package com.graywolf336.jail.enums; package com.graywolf336.jail.enums;
public enum LangString { 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 //Jailing section
/** The message displayed when players are kicked for being afk. */ /** The message displayed when players are kicked for being afk. */
@ -19,6 +26,8 @@ public enum LangString {
JAILEDWITHREASON ("jailing"), JAILEDWITHREASON ("jailing"),
/** The message sent when players are jailed and they try to talk. */ /** The message sent when players are jailed and they try to talk. */
MUTED ("jailing"), 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. */ /** The message sent when players are released from jail. */
UNJAILED ("jailing"), UNJAILED ("jailing"),

View File

@ -2,7 +2,9 @@ package com.graywolf336.jail.enums;
public enum Settings { public enum Settings {
BROADCASTJAILING("jailing.jail.broadcastJailing"), BROADCASTJAILING("jailing.jail.broadcastJailing"),
BLOCKBREAKPENALTY("jailing.during.blockBreakPenalty"),
BLOCKBREAKPROTECTION("jailing.during.blockBreakProtection"), BLOCKBREAKPROTECTION("jailing.during.blockBreakProtection"),
BLOCKPLACEPENALTY("jailing.during.blockPlacePenalty"),
BLOCKPLACEPROTECTION("jailing.during.blockPlaceProtection"), BLOCKPLACEPROTECTION("jailing.during.blockPlaceProtection"),
COMMANDSONJAIL("jailing.jail.commands"), COMMANDSONJAIL("jailing.jail.commands"),
COMMANDSONRELEASE("jailing.release.commands"), COMMANDSONRELEASE("jailing.release.commands"),

View File

@ -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.");
}
}
}
}
}

View File

@ -13,7 +13,9 @@ storage:
password: 'password' password: 'password'
jailing: jailing:
during: during:
blockBreakPenalty: 5m
blockBreakProtection: true blockBreakProtection: true
blockPlacePenalty: 5m
blockPlaceProtection: true blockPlaceProtection: true
countDownTimeWhileOffline: false countDownTimeWhileOffline: false
explosionProtection: true explosionProtection: true

View File

@ -1,4 +1,7 @@
language: language:
actions:
blockbreaking: 'breaking a block'
blockplacing: 'placing a block'
general: general:
unknowncommand: '&cNo commands registered by the name of %0%.' unknowncommand: '&cNo commands registered by the name of %0%.'
nopermission: '&cInsufficient permission.' nopermission: '&cInsufficient permission.'
@ -13,6 +16,7 @@ language:
jailed: '&cYou have been jailed!' jailed: '&cYou have been jailed!'
jailedwithreason: '&cYou have been jailed for: %0%' jailedwithreason: '&cYou have been jailed for: %0%'
muted: '&cStop talking, you are in jail.' 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.' unjailed: '&2You have been released! Please respect the server rules.'
handcuffing: handcuffing:
cantbehandcuffed: '&9%0% &ccan not be handcuffed.' cantbehandcuffed: '&9%0% &ccan not be handcuffed.'