Start work on the protection and penalties. First up is Block Place
This commit is contained in:
parent
d9d0de046d
commit
95649e7f03
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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"),
|
||||
|
||||
|
@ -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"),
|
||||
|
@ -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.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -13,7 +13,9 @@ storage:
|
||||
password: 'password'
|
||||
jailing:
|
||||
during:
|
||||
blockBreakPenalty: 5m
|
||||
blockBreakProtection: true
|
||||
blockPlacePenalty: 5m
|
||||
blockPlaceProtection: true
|
||||
countDownTimeWhileOffline: false
|
||||
explosionProtection: true
|
||||
|
@ -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.'
|
||||
|
Loading…
Reference in New Issue
Block a user