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();
parent.getPartyMap().put(this.player.getName(), this);
// start listening
this.partyEvents = new PartyEvents(this.parent);
this.partyEvents = new PartyEvents(this.parent, this);
parent.getServer().getPluginManager().registerEvents(this.partyEvents, this.parent);
}

View File

@ -17,54 +17,54 @@ import org.bukkit.event.player.PlayerShearEntityEvent;
public class PartyEvents implements Listener {
DiscoSheep parent;
DiscoParty party;
public PartyEvents(DiscoSheep parent) {
public PartyEvents(DiscoSheep parent, DiscoParty party) {
this.parent = parent;
this.party = party;
}
// prevent sheep shearing
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerShear(PlayerShearEntityEvent e) {
if (e.getEntity() instanceof Sheep) {
for (DiscoParty party : parent.getParties()) {
if (party.getSheepList().contains((Sheep) e.getEntity())) {
e.setCancelled(true);
}
if (party.getSheepList().contains((Sheep) e.getEntity())) {
e.setCancelled(true);
}
}
}
// actually make sheep and other guests invincible
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onLivingEntityDamageEvent(EntityDamageEvent e) {
if (e.getEntity() instanceof Sheep) {
for (DiscoParty party : parent.getParties()) {
if (party.getSheepList().contains((Sheep) e.getEntity())) {
{
party.jump((LivingEntity) e.getEntity()); // for kicks
e.setCancelled(true);
}
if (party.getSheepList().contains((Sheep) e.getEntity())) {
{
party.jump((LivingEntity) e.getEntity()); // for kicks
e.setCancelled(true);
}
}
}
for (DiscoParty party : parent.getParties()) {
if (party.getGuestList().contains(e.getEntity())) {
party.jump((LivingEntity) e.getEntity());
e.setCancelled(true);
}
if (party.getGuestList().contains(e.getEntity())) {
party.jump((LivingEntity) e.getEntity());
e.setCancelled(true);
}
parent.getLogger().log(Level.INFO, "Debug: EVENT TRIGGERED");
}
// prevent uninvited guests from targetting players
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
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
e.setCancelled(true);
}
if (party.getGuestList().contains(e.getEntity())) { // safe; event is only triggered by LivingEntity targetting LivingEntity
e.setCancelled(true);
}
}
}