Skip to content

Commit

Permalink
Fix the proximity trigger
Browse files Browse the repository at this point in the history
Who wrote this memleaking nightmare bit of code!?
This needs far more work than this little bandaid, but this is all I
have time for.
  • Loading branch information
mcmonkey4eva committed Dec 18, 2014
1 parent 315c23d commit b2a8354
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
Expand Up @@ -101,7 +101,8 @@ public boolean animatesOnDeath() {
* information for this trait.
*
*/
@Override public void onSpawn() {
@Override
public void onSpawn() {
dying = false;
setHealth();

Expand Down
Expand Up @@ -33,6 +33,7 @@
//
// Visual effects:
// - iconcrack_[id] (item break effect - examples: iconcrack_7, iconcrack_268)
// - TODO: Update the below list. Mojang chamged some of 'em!
// - ENDER_SIGNAL, MOBSPAWNER_FLAMES, POTION_BREAK, SMOKE
// - HUGE_EXPLOSION, LARGE_EXPLODE, FIREWORKS_SPARK, BUBBLE, SUSPEND, DEPTH_SUSPEND, TOWN_AURA,
// CRIT, MAGIC_CRIT, MOB_SPELL, MOB_SPELL_AMBIENT, SPELL, INSTANT_SPELL, WITCH_MAGIC, NOTE, STEP_SOUND,
Expand Down
Expand Up @@ -17,10 +17,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
Expand Down Expand Up @@ -349,14 +346,14 @@ public void checkMaxProximities(ScriptReloadEvent event) {
}
}

private static Map<Player, Set<Integer>> proximityTracker = new ConcurrentHashMap<Player, Set<Integer>>(8, 0.9f, 1);
private static Map<UUID, Set<Integer>> proximityTracker = new ConcurrentHashMap<UUID, Set<Integer>>(8, 0.9f, 1);

//
// Ensures that a Player who has entered proximity of an NPC also fires Exit Proximity.
//
private boolean hasExitedProximityOf(Player player, dNPC npc) {
// If Player hasn't entered proximity, it's not in the Map. Return true, must be exited.
Set<Integer> existing = proximityTracker.get(player);
Set<Integer> existing = proximityTracker.get(player.getUniqueId());
if (existing == null) return true;
// If Player has no entry for this NPC, return true.
if (!existing.contains(npc.getId())) return true;
Expand All @@ -372,10 +369,10 @@ private boolean hasExitedProximityOf(Player player, dNPC npc) {
* @param npc the NPC
*/
private void enterProximityOf(Player player, dNPC npc) {
Set<Integer> npcs = proximityTracker.get(player);
Set<Integer> npcs = proximityTracker.get(player.getUniqueId());
if (npcs == null) {
npcs = new HashSet<Integer>();
proximityTracker.put(player, npcs);
proximityTracker.put(player.getUniqueId(), npcs);
}
npcs.add(npc.getId());
}
Expand All @@ -388,10 +385,10 @@ private void enterProximityOf(Player player, dNPC npc) {
* @param npc the NPC
*/
private void exitProximityOf(Player player, dNPC npc) {
Set<Integer> npcs = proximityTracker.get(player);
Set<Integer> npcs = proximityTracker.get(player.getUniqueId());
if (npcs == null) {
npcs = new HashSet<Integer>();
proximityTracker.put(player, npcs);
proximityTracker.put(player.getUniqueId(), npcs);
}
npcs.remove(npc.getId());
}
Expand Down

0 comments on commit b2a8354

Please sign in to comment.