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 player = (Player) event.getEntity(); Player attacker = (Player) event.getDamager();
Player player = (Player) event.getEntity();
if(pl.getJailStickManager().isUsingJailStick(attacker.getUniqueId())) {
if(pl.getJailStickManager().isValidStick(attacker.getItemInHand().getType())) { if(pl.getJailStickManager().isUsingJailStick(attacker.getUniqueId())) {
if(attacker.hasPermission("jail.usejailstick." + attacker.getItemInHand().getType().toString().toLowerCase())) { if(pl.getJailStickManager().isValidStick(attacker.getItemInHand().getType())) {
//The person the attacker is trying to jail stick is already jailed, don't handle that if(attacker.hasPermission("jail.usejailstick." + attacker.getItemInHand().getType().toString().toLowerCase())) {
if(pl.getJailManager().isPlayerJailed(player.getUniqueId())) { //The person the attacker is trying to jail stick is already jailed, don't handle that
attacker.sendMessage(Lang.ALREADYJAILED.get(player.getName())); if(pl.getJailManager().isPlayerJailed(player.getUniqueId())) {
}else { attacker.sendMessage(Lang.ALREADYJAILED.get(player.getName()));
if(player.hasPermission("jail.cantbejailed")) { }else {
attacker.sendMessage(Lang.CANTBEJAILED.get()); if(player.hasPermission("jail.cantbejailed")) {
}else { attacker.sendMessage(Lang.CANTBEJAILED.get());
Stick s = pl.getJailStickManager().getStick(attacker.getItemInHand().getType()); }else {
Stick s = pl.getJailStickManager().getStick(attacker.getItemInHand().getType());
if(player.getHealth() <= s.getHealth() || s.getHealth() == -1) {
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(
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()) if(jEvent.isCancelled()) {
attacker.sendMessage(Lang.CANCELLEDBYANOTHERPLUGIN.get(player.getName())); if(jEvent.getCancelledMessage().isEmpty())
else attacker.sendMessage(Lang.CANCELLEDBYANOTHERPLUGIN.get(player.getName()));
attacker.sendMessage(jEvent.getCancelledMessage()); else
}else { attacker.sendMessage(jEvent.getCancelledMessage());
//recall data from the event }else {
Jail j = jEvent.getJail(); //recall data from the event
Cell c = jEvent.getCell(); Jail j = jEvent.getJail();
p = jEvent.getPrisoner(); Cell c = jEvent.getCell();
player = jEvent.getPlayer(); p = jEvent.getPrisoner();
player = jEvent.getPlayer();
//Player is not online
if(player == null) { //Player is not online
attacker.sendMessage(Lang.OFFLINEJAIL.get(new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) })); if(player == null) {
}else { attacker.sendMessage(Lang.OFFLINEJAIL.get(new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
//Player *is* online }else {
attacker.sendMessage(Lang.ONLINEJAIL.get(new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) })); //Player *is* online
} attacker.sendMessage(Lang.ONLINEJAIL.get(new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
}
try {
pl.getPrisonerManager().prepareJail(j, c, player, p); try {
} catch (Exception e) { pl.getPrisonerManager().prepareJail(j, c, player, p);
attacker.sendMessage(ChatColor.RED + e.getMessage()); } catch (Exception e) {
} attacker.sendMessage(ChatColor.RED + e.getMessage());
} }
}else { }
attacker.sendMessage(Lang.RESISTEDARRESTJAILER.get(player.getName())); }else {
player.sendMessage(Lang.RESISTEDARRESTPLAYER.get(attacker.getName())); attacker.sendMessage(Lang.RESISTEDARRESTJAILER.get(player.getName()));
} player.sendMessage(Lang.RESISTEDARRESTPLAYER.get(attacker.getName()));
} }
} }
} }
} }
} }
}
}
} }
} }