Cherry-pick the changes for the jail stick

This commit is contained in:
graywolf336 2016-05-30 15:13:37 -05:00
parent 9e281a821f
commit 543a862c98
No known key found for this signature in database
GPG Key ID: 63D2D655DA5B3643
3 changed files with 63 additions and 52 deletions

View File

@ -67,7 +67,7 @@ public class JailStickManager implements IJailStickManager {
}
try {
this.sticks.put(m, new Stick(jail, a[3], time, a.length > 5 ? Double.valueOf(a[4]) : -1));
this.sticks.put(m, new Stick(jail, a[3], time, a.length >= 5 ? Double.valueOf(a[4]) : -1));
}catch (Exception e) {
e.printStackTrace();
pl.getLogger().severe(s);

View File

@ -240,62 +240,73 @@ public class PlayerListener implements Listener {
Player attacker = (Player) event.getDamager();
Player player = (Player) event.getEntity();
//They aren't using the jail stick, they need to toggle themselves
if(!pl.getJailStickManager().isUsingJailStick(attacker.getUniqueId())) return;
//They don't have a valid jail stick type
if(!pl.getJailStickManager().isValidStick(attacker.getInventory().getItemInMainHand().getType())) return;
//They don't have permission for that type of jail stick
if(!attacker.hasPermission("jail.usejailstick." + attacker.getInventory().getItemInMainHand().getType().toString().toLowerCase())) return;
//The player they hit is already jailed.
if(pl.getJailManager().isPlayerJailed(player.getUniqueId())) {
attacker.sendMessage(Lang.ALREADYJAILED.get(player.getName()));
return;
}
if(pl.getJailStickManager().isUsingJailStick(attacker.getUniqueId())) {
if(pl.getJailStickManager().isValidStick(attacker.getInventory().getItemInMainHand().getType())) {
if(attacker.hasPermission("jail.usejailstick." + attacker.getInventory().getItemInMainHand().getType().toString().toLowerCase())) {
//The person the attacker is trying to jail stick is already jailed, don't handle that
if(pl.getJailManager().isPlayerJailed(player.getUniqueId())) {
attacker.sendMessage(Lang.ALREADYJAILED.get(player.getName()));
}else {
if(player.hasPermission("jail.cantbejailed")) {
attacker.sendMessage(Lang.CANTBEJAILED.get());
}else {
Stick s = pl.getJailStickManager().getStick(attacker.getInventory().getItemInMainHand().getType());
//The player can't be jailed due to permissions.
if(player.hasPermission("jail.cantbejailed")) {
attacker.sendMessage(Lang.CANTBEJAILED.get());
return;
}
//Get the stick the attacker (police) is using
Stick s = pl.getJailStickManager().getStick(attacker.getInventory().getItemInMainHand().getType());
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());
//Check if the player can resist arrest via health with this stick
pl.debug("Jail stick health resist check: " + "(" + s.getHealth() + "," + player.getHealth() + ") - " + (s.getHealth() <= player.getHealth() && s.getHealth() != -1));
if(s.getHealth() < player.getHealth() && s.getHealth() != -1) {
attacker.sendMessage(Lang.RESISTEDARRESTJAILER.get(player.getName()));
player.sendMessage(Lang.RESISTEDARRESTPLAYER.get(attacker.getName()));
return;
}
//The player can be jailed.
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()), new AnyCell(), p, player, attacker.getName(), s);
PrePrisonerJailedByJailStickEvent jEvent = new PrePrisonerJailedByJailStickEvent(
pl.getJailManager().getJail(s.getJail()), new AnyCell(), p, player, attacker.getName(), s);
pl.getServer().getPluginManager().callEvent(jEvent);
pl.getServer().getPluginManager().callEvent(jEvent);
if(jEvent.isCancelled()) {
if(jEvent.getCancelledMessage().isEmpty())
attacker.sendMessage(Lang.CANCELLEDBYANOTHERPLUGIN.get(player.getName()));
else
attacker.sendMessage(jEvent.getCancelledMessage());
}else {
//recall data from the event
Jail j = jEvent.getJail();
ICell c = jEvent.getCell();
p = jEvent.getPrisoner();
player = jEvent.getPlayer();
if(jEvent.isCancelled()) {
if(jEvent.getCancelledMessage().isEmpty())
attacker.sendMessage(Lang.CANCELLEDBYANOTHERPLUGIN.get(player.getName()));
else
attacker.sendMessage(jEvent.getCancelledMessage());
}else {
//recall data from the event
Jail j = jEvent.getJail();
ICell c = jEvent.getCell();
p = jEvent.getPrisoner();
player = jEvent.getPlayer();
//Player is not online
if(player == null) {
attacker.sendMessage(Lang.OFFLINEJAIL.get(new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
}else {
//Player *is* online
attacker.sendMessage(Lang.ONLINEJAIL.get(new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
}
//Player is not online
if(player == null) {
attacker.sendMessage(Lang.OFFLINEJAIL.get(new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
}else {
//Player *is* online
attacker.sendMessage(Lang.ONLINEJAIL.get(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(Lang.RESISTEDARRESTJAILER.get(player.getName()));
player.sendMessage(Lang.RESISTEDARRESTPLAYER.get(attacker.getName()));
}
}
}
}
try {
pl.getPrisonerManager().prepareJail(j, c, player, p);
} catch (Exception e) {
attacker.sendMessage(ChatColor.RED + e.getMessage());
}
}
}

View File

@ -135,9 +135,9 @@ permissions:
default: true
jail.modifyjail:
default: op
jail.usejailstick280:
jail.usejailstick.stick:
default: op
description: change 280 for another jailstick item
description: change stick for another jailstick item
jail.canbestickjailed:
default: true
jail.openchest: