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 {
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) {
e.printStackTrace();
pl.getLogger().severe(s);

View File

@ -11,27 +11,42 @@ package com.graywolf336.jail.beans;
public class Stick {
private String jail, reason;
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.reason = reason;
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() {
return this.jail;
}
/** Gets the reason a player will be jailed for when jailed via this stick. */
public String getReason() {
return this.reason;
}
/** Gets the amount of time a player has to serve when they are jailed via this stick. */
public long getTime() {
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
public String toString() {
return time + "," + jail + "," + reason;
return time + "," + jail + "," + reason + "," + health;
}
}

View File

@ -70,6 +70,10 @@ public enum LangString {
PROVIDEAPLAYER ("jailing"),
/** The message sent to the sender when they need to provide a jail. */
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. */
STATUS ("jailing"),
/** 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 {
Stick s = pl.getJailStickManager().getStick(attacker.getItemInHand().getType());
Prisoner p = new Prisoner(player.getUniqueId().toString(), player.getName(),
pl.getConfig().getBoolean(Settings.AUTOMATICMUTE.getPath()),
s.getTime(), attacker.getName(), s.getReason());
if(player.getHealth() <= s.getHealth() || s.getHealth() == -1) {
Prisoner p = new Prisoner(player.getUniqueId().toString(), player.getName(),
pl.getConfig().getBoolean(Settings.AUTOMATICMUTE.getPath()),
s.getTime(), attacker.getName(), s.getReason());
PrePrisonerJailedByJailStickEvent jEvent = new PrePrisonerJailedByJailStickEvent(
pl.getJailManager().getJail(s.getJail()), null, p, player, attacker.getName(), s);
PrePrisonerJailedByJailStickEvent jEvent = new PrePrisonerJailedByJailStickEvent(
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.getCancelledMessage().isEmpty())
attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.CANCELLEDBYANOTHERPLUGIN, player.getName()));
else
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()) }));
if(jEvent.isCancelled()) {
if(jEvent.getCancelledMessage().isEmpty())
attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.CANCELLEDBYANOTHERPLUGIN, player.getName()));
else
attacker.sendMessage(jEvent.getCancelledMessage());
}else {
//Player *is* online
attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.ONLINEJAIL,
new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
}
//recall data from the event
Jail j = jEvent.getJail();
Cell c = jEvent.getCell();
p = jEvent.getPrisoner();
player = jEvent.getPlayer();
try {
pl.getPrisonerManager().prepareJail(j, c, player, p);
} catch (Exception e) {
attacker.sendMessage(ChatColor.RED + e.getMessage());
//Player is not online
if(player == null) {
attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.OFFLINEJAIL,
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
jailstick:
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.'
provideaplayer: '&cPlease provide a player when %0% &cthem.'
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."
suggestedcell: '&cAn empty cell in the same jail, %0%, was found: %1%'
telein: "&9Teleported %0% to %1%'s teleport in location."