Skip to content

Commit

Permalink
Fix up KillListener (Should be working fully now)
Browse files Browse the repository at this point in the history
  • Loading branch information
aufdemrand committed Aug 3, 2013
1 parent ba44c80 commit 645fcd8
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 36 deletions.
Expand Up @@ -2,16 +2,14 @@

import net.aufdemrand.denizen.events.ReplaceableTagEvent;
import net.aufdemrand.denizen.listeners.AbstractListener;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.objects.dCuboid;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.objects.dList;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.depends.Depends;
import net.aufdemrand.denizen.utilities.depends.WorldGuardUtilities;

import net.citizensnpcs.api.CitizensAPI;

import net.citizensnpcs.trait.LookClose;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
Expand Down Expand Up @@ -184,65 +182,109 @@ public void listen(EntityDeathEvent event) {
if (cuboid != null)
if (!cuboid.isInsideCuboid(player.getLocation())) return;

// Check type!
//
// ENTITY type Kill Listener
//
if (type == KillType.ENTITY) {

// Get entity killed
dEntity ent = new dEntity(event.getEntity());
dB.log("Entity killed: " + ent.identify());
boolean count_it = false;

// Check targets, if any match entity killed, count_it!
for (String target : targets) {
if (dEntity.valueOf(target) != null)
if (ent.comparesTo(dEntity.valueOf(target)) == 1)
count_it = true;
}

if (count_it
|| targets.contains("*")) {
// If an entity was found, or targets is '*', increment the
// kills_so_far
if (count_it || targets.contains("*")) {
kills_so_far++;
dB.log(player.getName() + " killed a "
+ ent.identify() + ". Current progress '"
+ kills_so_far + "/" + required + "'.");
// Check the number of kills so far
check();
}
}

} else if (type == KillType.NPC) {
if (CitizensAPI.getNPCRegistry().isNPC(event.getEntity()))
if (targets.contains(CitizensAPI.getNPCRegistry().getNPC(event.getEntity()).getName().toUpperCase())
|| targets.contains("*")
|| targets.contains(String.valueOf(CitizensAPI.getNPCRegistry().getNPC(event.getEntity()).getId() ))) {
kills_so_far++;
dB.log(player.getName() + " killed "
+ String.valueOf(CitizensAPI.getNPCRegistry().getNPC(event.getEntity()).getId())
+ "/" + CitizensAPI.getNPCRegistry().getNPC(event.getEntity()).getName()
+ ". Current progress '" + kills_so_far + "/" + required + "'.");
check();
}
//
// NPC type Kill Listener
//
else if (type == KillType.NPC) {
// If a NPC wasn't killed, return.
if (!CitizensAPI.getNPCRegistry().isNPC(event.getEntity())) return;
// Get the NPC killed
dNPC npc = dNPC.mirrorCitizensNPC(CitizensAPI.getNPCRegistry().getNPC(event.getEntity()));
boolean count_it = false;

} else if (type == KillType.PLAYER) {
if (event.getEntityType() == EntityType.PLAYER)
if (targets.contains(((Player) event.getEntity()).getName().toUpperCase())
|| targets.contains("*")
|| targets.isEmpty()) {
kills_so_far++;
dB.log(player.getName() + " killed "
+ ((Player) event.getEntity()).getName().toUpperCase()
+ ". Current progress '" + kills_so_far + "/" + required + "'.");
check();
// Check targets, if any match entity killed, count_it!
for (String target : targets) {
// Check IDs
if (dNPC.valueOf(target) != null) {
if (dNPC.valueOf(target).getId() == npc.getId())
count_it = true;
}
// Check Names
else if (npc.getName().equalsIgnoreCase(target))
count_it = true;
}
// If NPC was matched or targets contains '*', increment
// the kills so far.
if (count_it || targets.contains("*")) {
kills_so_far++;
dB.log(player.getName() + " killed "
+ npc.toString() + ". Current progress '"
+ kills_so_far + "/" + required + "'.");
// Check the number of kills so far
check();
}
}

//
// PLAYER type Kill Listener
//
else if (type == KillType.PLAYER) {
// Check to make sure entity is a Player, and not a NPC
if (event.getEntityType() != EntityType.PLAYER) return;
if (CitizensAPI.getNPCRegistry().isNPC(event.getEntity())) return;

// Get player killed
dPlayer player = dPlayer.mirrorBukkitPlayer((Player) event.getEntity());
boolean count_it = false;
// Check targets, if any match entity killed, count_it!
for (String target : targets) {
if (dPlayer.valueOf(target) != null)
if (dPlayer.valueOf(target).getName().equalsIgnoreCase(player.getName()))
count_it = true;
}
// If an entity was found, or targets is '*', increment the
// kills_so_far
if (count_it || targets.contains("*")) {
kills_so_far++;
dB.log(player.getName() + " killed "
+ player.getName() + ". Current progress '"
+ kills_so_far + "/" + required + "'.");
// Check the number of kills so far
check();
}
}

} else if (type == KillType.GROUP) {
//
// GROUP type Kill Listener
//
else if (type == KillType.GROUP) {
// Require the entity to be a Player
if (event.getEntityType() == EntityType.PLAYER)
// Iterate through groups on the Player
for (String group : Depends.permissions.getPlayerGroups((Player) event.getEntity()))
// If a group matches, count it!
if (targets.contains(group.toUpperCase())) {
kills_so_far++;
dB.log(player.getName() + " killed " + ((Player) event.getEntity()).getName().toUpperCase() + " of group " + group + ".");
check();
break;
}
}


}


Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/aufdemrand/denizen/utilities/Utilities.java
Expand Up @@ -16,6 +16,8 @@
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.tags.TagManager;

import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
Expand Down

0 comments on commit 645fcd8

Please sign in to comment.