listeners only listen for their own parties

This commit is contained in:
Gibstick 2013-07-28 12:47:00 -04:00
parent 12cbf80d55
commit d8fe7b480d
2 changed files with 26 additions and 26 deletions

View File

@ -460,7 +460,7 @@ public class DiscoParty {
this.scheduleUpdate(); this.scheduleUpdate();
parent.getPartyMap().put(this.player.getName(), this); parent.getPartyMap().put(this.player.getName(), this);
// start listening // start listening
this.partyEvents = new PartyEvents(this.parent); this.partyEvents = new PartyEvents(this.parent, this);
parent.getServer().getPluginManager().registerEvents(this.partyEvents, this.parent); parent.getServer().getPluginManager().registerEvents(this.partyEvents, this.parent);
} }

View File

@ -17,20 +17,22 @@ import org.bukkit.event.player.PlayerShearEntityEvent;
public class PartyEvents implements Listener { public class PartyEvents implements Listener {
DiscoSheep parent; DiscoSheep parent;
DiscoParty party;
public PartyEvents(DiscoSheep parent) { public PartyEvents(DiscoSheep parent, DiscoParty party) {
this.parent = parent; this.parent = parent;
this.party = party;
} }
// prevent sheep shearing // prevent sheep shearing
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerShear(PlayerShearEntityEvent e) { public void onPlayerShear(PlayerShearEntityEvent e) {
if (e.getEntity() instanceof Sheep) { if (e.getEntity() instanceof Sheep) {
for (DiscoParty party : parent.getParties()) {
if (party.getSheepList().contains((Sheep) e.getEntity())) { if (party.getSheepList().contains((Sheep) e.getEntity())) {
e.setCancelled(true); e.setCancelled(true);
} }
}
} }
} }
@ -38,33 +40,31 @@ public class PartyEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onLivingEntityDamageEvent(EntityDamageEvent e) { public void onLivingEntityDamageEvent(EntityDamageEvent e) {
if (e.getEntity() instanceof Sheep) { if (e.getEntity() instanceof Sheep) {
for (DiscoParty party : parent.getParties()) {
if (party.getSheepList().contains((Sheep) e.getEntity())) { if (party.getSheepList().contains((Sheep) e.getEntity())) {
{ {
party.jump((LivingEntity) e.getEntity()); // for kicks party.jump((LivingEntity) e.getEntity()); // for kicks
e.setCancelled(true); e.setCancelled(true);
} }
} }
}
} }
for (DiscoParty party : parent.getParties()) {
if (party.getGuestList().contains(e.getEntity())) { if (party.getGuestList().contains(e.getEntity())) {
party.jump((LivingEntity) e.getEntity()); party.jump((LivingEntity) e.getEntity());
e.setCancelled(true); e.setCancelled(true);
} }
}
parent.getLogger().log(Level.INFO, "Debug: EVENT TRIGGERED"); parent.getLogger().log(Level.INFO, "Debug: EVENT TRIGGERED");
} }
// prevent uninvited guests from targetting players // prevent uninvited guests from targetting players
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityTargetLivingEntityEvent(EntityTargetEvent e) { public void onEntityTargetLivingEntityEvent(EntityTargetEvent e) {
for (DiscoParty party : parent.getParties()) {
if (party.getGuestList().contains(e.getEntity())) { // safe; event is only triggered by LivingEntity targetting LivingEntity if (party.getGuestList().contains(e.getEntity())) { // safe; event is only triggered by LivingEntity targetting LivingEntity
e.setCancelled(true); e.setCancelled(true);
} }
}
}
} }
}