Skip to content

Commit

Permalink
Add Chunk Unload Event + Update bukkit api and bStats version
Browse files Browse the repository at this point in the history
  • Loading branch information
chuushi committed May 29, 2019
1 parent 819b4f1 commit b58b48b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .idea/PhantomSMP.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.13.1-R0.1-SNAPSHOT</version>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.4</version>
<version>1.5</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
25 changes: 19 additions & 6 deletions src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;

import java.util.*;

Expand Down Expand Up @@ -115,6 +116,13 @@ private void untarget(Player p, boolean sleeping) {
}
}

private void removePhantom(Phantom phantom) {
Player p = phantomPlayerMap.remove(phantom);
if (p == null)
return;
playerPhantomMap.get(p).remove(phantom);
}

@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent e) {
playerPhantomMap.put(e.getPlayer(), new LinkedHashSet<>());
Expand Down Expand Up @@ -176,17 +184,22 @@ public void onPhantomInLoadedChunk(ChunkLoadEvent e) {
targeting((Phantom) ent, null, null);
}

// Untrack phantoms in unloaded chunks
@EventHandler
public void onPhantomDeath(EntityDeathEvent e) {
if (!(e.getEntity() instanceof Phantom))
public void onPhantomInUnloadedChunk(ChunkUnloadEvent e) {
if (e.getWorld().getEnvironment() != World.Environment.NORMAL)
return;

Phantom phantom = (Phantom) e.getEntity();
for (Entity ent : e.getChunk().getEntities())
if (ent instanceof Phantom)
removePhantom((Phantom) ent);
}

Player p = phantomPlayerMap.remove(phantom);
if (p == null)
@EventHandler
public void onPhantomDeath(EntityDeathEvent e) {
if (!(e.getEntity() instanceof Phantom))
return;

playerPhantomMap.get(p).remove(phantom);
removePhantom((Phantom) e.getEntity());
}
}

0 comments on commit b58b48b

Please sign in to comment.