Only interaction with the jail stick manager when enabled. Closes #30

This commit is contained in:
graywolf336 2014-07-27 12:42:50 -05:00
parent 34acf4bbaa
commit 57e304f7c4
2 changed files with 72 additions and 70 deletions

View File

@ -105,13 +105,10 @@ public class JailMain extends JavaPlugin {
plm.registerEvents(this.mpl, this); plm.registerEvents(this.mpl, this);
} }
if(getConfig().getBoolean(Settings.JAILSTICKENABLED.getPath())) {
jsm = new JailStickManager(this);
}
jt = new JailTimer(this); jt = new JailTimer(this);
sbm = new ScoreBoardManager(this); sbm = new ScoreBoardManager(this);
reloadJailPayManager(); reloadJailPayManager();
reloadJailSticks();
reloadUpdateCheck(); reloadUpdateCheck();
new JailsAPI(this); new JailsAPI(this);
@ -201,8 +198,11 @@ public class JailMain extends JavaPlugin {
/** Reloads the Jail Sticks, so the new ones can be loaded from the config. */ /** Reloads the Jail Sticks, so the new ones can be loaded from the config. */
public void reloadJailSticks() { public void reloadJailSticks() {
if(getConfig().getBoolean(Settings.JAILSTICKENABLED.getPath())) { if(getConfig().getBoolean(Settings.JAILSTICKENABLED.getPath())) {
this.jsm.removeAllStickUsers(); if(this.jsm != null) {
this.jsm = null; this.jsm.removeAllStickUsers();
this.jsm = null;
}
this.jsm = new JailStickManager(this); this.jsm = new JailStickManager(this);
} }
} }

View File

@ -214,69 +214,71 @@ public class PlayerListener implements Listener {
@EventHandler(ignoreCancelled=true) @EventHandler(ignoreCancelled=true)
public void jailStickHandling(EntityDamageByEntityEvent event) { public void jailStickHandling(EntityDamageByEntityEvent event) {
//If the damager and the entity getting damage is not a player, if(pl.getConfig().getBoolean(Settings.JAILSTICKENABLED.getPath())) {
//we don't want to handle it in this method //If the damager and the entity getting damage is not a player,
if(!(event.getDamager() instanceof Player) || !(event.getEntity() instanceof Player)) return; //we don't want to handle it in this method
if(!(event.getDamager() instanceof Player) || !(event.getEntity() instanceof Player)) return;
Player attacker = (Player) event.getDamager(); Player attacker = (Player) event.getDamager();
Player player = (Player) event.getEntity(); Player player = (Player) event.getEntity();
if(pl.getJailStickManager().isUsingJailStick(attacker.getUniqueId())) { if(pl.getJailStickManager().isUsingJailStick(attacker.getUniqueId())) {
if(pl.getJailStickManager().isValidStick(attacker.getItemInHand().getType())) { if(pl.getJailStickManager().isValidStick(attacker.getItemInHand().getType())) {
if(attacker.hasPermission("jail.usejailstick." + attacker.getItemInHand().getType().toString().toLowerCase())) { if(attacker.hasPermission("jail.usejailstick." + attacker.getItemInHand().getType().toString().toLowerCase())) {
//The person the attacker is trying to jail stick is already jailed, don't handle that //The person the attacker is trying to jail stick is already jailed, don't handle that
if(pl.getJailManager().isPlayerJailed(player.getUniqueId())) { if(pl.getJailManager().isPlayerJailed(player.getUniqueId())) {
attacker.sendMessage(Lang.ALREADYJAILED.get(player.getName())); attacker.sendMessage(Lang.ALREADYJAILED.get(player.getName()));
}else { }else {
if(player.hasPermission("jail.cantbejailed")) { if(player.hasPermission("jail.cantbejailed")) {
attacker.sendMessage(Lang.CANTBEJAILED.get()); attacker.sendMessage(Lang.CANTBEJAILED.get());
}else { }else {
Stick s = pl.getJailStickManager().getStick(attacker.getItemInHand().getType()); Stick s = pl.getJailStickManager().getStick(attacker.getItemInHand().getType());
if(player.getHealth() <= s.getHealth() || s.getHealth() == -1) { if(player.getHealth() <= s.getHealth() || s.getHealth() == -1) {
Prisoner p = new Prisoner(player.getUniqueId().toString(), player.getName(), Prisoner p = new Prisoner(player.getUniqueId().toString(), player.getName(),
pl.getConfig().getBoolean(Settings.AUTOMATICMUTE.getPath()), pl.getConfig().getBoolean(Settings.AUTOMATICMUTE.getPath()),
s.getTime(), attacker.getName(), s.getReason()); 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(Lang.CANCELLEDBYANOTHERPLUGIN.get(player.getName())); attacker.sendMessage(Lang.CANCELLEDBYANOTHERPLUGIN.get(player.getName()));
else else
attacker.sendMessage(jEvent.getCancelledMessage()); attacker.sendMessage(jEvent.getCancelledMessage());
}else { }else {
//recall data from the event //recall data from the event
Jail j = jEvent.getJail(); Jail j = jEvent.getJail();
Cell c = jEvent.getCell(); Cell c = jEvent.getCell();
p = jEvent.getPrisoner(); p = jEvent.getPrisoner();
player = jEvent.getPlayer(); player = jEvent.getPlayer();
//Player is not online //Player is not online
if(player == null) { if(player == null) {
attacker.sendMessage(Lang.OFFLINEJAIL.get(new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) })); attacker.sendMessage(Lang.OFFLINEJAIL.get(new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
}else { }else {
//Player *is* online //Player *is* online
attacker.sendMessage(Lang.ONLINEJAIL.get(new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) })); attacker.sendMessage(Lang.ONLINEJAIL.get(new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
} }
try { try {
pl.getPrisonerManager().prepareJail(j, c, player, p); pl.getPrisonerManager().prepareJail(j, c, player, p);
} catch (Exception e) { } catch (Exception e) {
attacker.sendMessage(ChatColor.RED + e.getMessage()); attacker.sendMessage(ChatColor.RED + e.getMessage());
} }
} }
}else { }else {
attacker.sendMessage(Lang.RESISTEDARRESTJAILER.get(player.getName())); attacker.sendMessage(Lang.RESISTEDARRESTJAILER.get(player.getName()));
player.sendMessage(Lang.RESISTEDARRESTPLAYER.get(attacker.getName())); player.sendMessage(Lang.RESISTEDARRESTPLAYER.get(attacker.getName()));
} }
} }
} }
} }
} }
} }
}
} }
} }