Allow resisting arrests via the jail stick.

This commit is contained in:
graywolf336 2014-07-15 00:11:36 -05:00
parent c9b0fc8480
commit 86082e2f63
6 changed files with 63 additions and 37 deletions

View File

@ -54,7 +54,7 @@ public class JailStickManager {
} }
try { try {
this.sticks.put(m, new Stick(a[2], a[3], Long.valueOf(a[1]))); this.sticks.put(m, new Stick(a[2], a[3], Long.valueOf(a[1]), Double.valueOf(a[4])));
}catch (Exception e) { }catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
pl.getLogger().severe(s); pl.getLogger().severe(s);

View File

@ -11,27 +11,42 @@ package com.graywolf336.jail.beans;
public class Stick { public class Stick {
private String jail, reason; private String jail, reason;
private long time; private long time;
private double health;
public Stick(String jail, String reason, long time) { public Stick(String jail, String reason, long time, double health) {
this.jail = jail; this.jail = jail;
this.reason = reason; this.reason = reason;
this.time = time; this.time = time;
this.health = health;
} }
/** Gets the name of the jail a player will be sent when jailed via this jail stick. */
public String getJail() { public String getJail() {
return this.jail; return this.jail;
} }
/** Gets the reason a player will be jailed for when jailed via this stick. */
public String getReason() { public String getReason() {
return this.reason; return this.reason;
} }
/** Gets the amount of time a player has to serve when they are jailed via this stick. */
public long getTime() { public long getTime() {
return this.time; return this.time;
} }
/** Gets the amount of health a player has to have before getting jailed via this stick.
*
* <p />
*
* See here for reference: http://dev.bukkit.org/bukkit-plugins/jail/tickets/415/
*/
public double getHealth() {
return this.health;
}
@Override @Override
public String toString() { public String toString() {
return time + "," + jail + "," + reason; return time + "," + jail + "," + reason + "," + health;
} }
} }

View File

@ -70,6 +70,10 @@ public enum LangString {
PROVIDEAPLAYER ("jailing"), PROVIDEAPLAYER ("jailing"),
/** The message sent to the sender when they need to provide a jail. */ /** The message sent to the sender when they need to provide a jail. */
PROVIDEAJAIL ("jailing"), PROVIDEAJAIL ("jailing"),
/** The message sent to someone trying to jail someone else with a jail stick that requires health below a certain amount. */
RESISTEDARRESTJAILER ("jailing"),
/** The message sent to the person someone else is trying to jail that requires their health below a certain amount. */
RESISTEDARRESTPLAYER ("jailing"),
/** The message sent when to a prisoner about their status in jail. */ /** The message sent when to a prisoner about their status in jail. */
STATUS ("jailing"), STATUS ("jailing"),
/** The message sent to the sender of a command when suggesting a cell. */ /** The message sent to the sender of a command when suggesting a cell. */

View File

@ -223,42 +223,47 @@ public class PlayerListener implements Listener {
}else { }else {
Stick s = pl.getJailStickManager().getStick(attacker.getItemInHand().getType()); Stick s = pl.getJailStickManager().getStick(attacker.getItemInHand().getType());
Prisoner p = new Prisoner(player.getUniqueId().toString(), player.getName(), if(player.getHealth() <= s.getHealth() || s.getHealth() == -1) {
pl.getConfig().getBoolean(Settings.AUTOMATICMUTE.getPath()), Prisoner p = new Prisoner(player.getUniqueId().toString(), player.getName(),
s.getTime(), attacker.getName(), s.getReason()); pl.getConfig().getBoolean(Settings.AUTOMATICMUTE.getPath()),
s.getTime(), attacker.getName(), s.getReason());
PrePrisonerJailedByJailStickEvent jEvent = new PrePrisonerJailedByJailStickEvent( PrePrisonerJailedByJailStickEvent jEvent = new PrePrisonerJailedByJailStickEvent(
pl.getJailManager().getJail(s.getJail()), null, p, player, attacker.getName(), s); pl.getJailManager().getJail(s.getJail()), null, p, player, attacker.getName(), s);
pl.getServer().getPluginManager().callEvent(jEvent); pl.getServer().getPluginManager().callEvent(jEvent);
if(jEvent.isCancelled()) { if(jEvent.isCancelled()) {
if(jEvent.getCancelledMessage().isEmpty()) if(jEvent.getCancelledMessage().isEmpty())
attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.CANCELLEDBYANOTHERPLUGIN, player.getName())); attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.CANCELLEDBYANOTHERPLUGIN, player.getName()));
else else
attacker.sendMessage(jEvent.getCancelledMessage()); attacker.sendMessage(jEvent.getCancelledMessage());
}else {
//recall data from the event
Jail j = jEvent.getJail();
Cell c = jEvent.getCell();
p = jEvent.getPrisoner();
player = jEvent.getPlayer();
//Player is not online
if(player == null) {
attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.OFFLINEJAIL,
new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
}else { }else {
//Player *is* online //recall data from the event
attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.ONLINEJAIL, Jail j = jEvent.getJail();
new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) })); Cell c = jEvent.getCell();
} p = jEvent.getPrisoner();
player = jEvent.getPlayer();
try { //Player is not online
pl.getPrisonerManager().prepareJail(j, c, player, p); if(player == null) {
} catch (Exception e) { attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.OFFLINEJAIL,
attacker.sendMessage(ChatColor.RED + e.getMessage()); new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
}else {
//Player *is* online
attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.ONLINEJAIL,
new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
}
try {
pl.getPrisonerManager().prepareJail(j, c, player, p);
} catch (Exception e) {
attacker.sendMessage(ChatColor.RED + e.getMessage());
}
} }
}else {
attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.RESISTEDARRESTJAILER, player.getName()));
player.sendMessage(pl.getJailIO().getLanguageString(LangString.RESISTEDARRESTPLAYER, attacker.getName()));
} }
} }
} }

View File

@ -77,4 +77,4 @@ jailpay:
priceInfinite: 10000 priceInfinite: 10000
jailstick: jailstick:
enabled: true enabled: true
sticks: ["stick,30,,Running away"] sticks: ["stick,30,,Running away,-1", "blaze_rod,15,,Having too much fun,6"]

View File

@ -63,6 +63,8 @@ language:
protectionmessagenopenalty: '&cProtection enabled for %0%, do not do it again.' protectionmessagenopenalty: '&cProtection enabled for %0%, do not do it again.'
provideaplayer: '&cPlease provide a player when %0% &cthem.' provideaplayer: '&cPlease provide a player when %0% &cthem.'
provideajail: '&cPlease provide a jail to %0% &cthem to.' provideajail: '&cPlease provide a jail to %0% &cthem to.'
resistedarrestjailer: '&c%0% has resisted arrest thanks to having more health than you can jail at.'
resistedarrestplayer: '&cYou have resisted arrest due to having more health than %0% can jail at.'
status: "&2You have been jailed with a reason of '%0%' by %1% and have %2% minutes remaining." status: "&2You have been jailed with a reason of '%0%' by %1% and have %2% minutes remaining."
suggestedcell: '&cAn empty cell in the same jail, %0%, was found: %1%' suggestedcell: '&cAn empty cell in the same jail, %0%, was found: %1%'
telein: "&9Teleported %0% to %1%'s teleport in location." telein: "&9Teleported %0% to %1%'s teleport in location."