Add Chunk Unload Event + Update bukkit api and bStats version

This commit is contained in:
Simon Chuu 2019-05-29 02:06:51 -04:00
parent 819b4f1e31
commit b58b48bf04
4 changed files with 37 additions and 9 deletions

2
.idea/PhantomSMP.iml Normal file
View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />

13
.idea/compiler.xml Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="PhantomSMP" />
</profile>
</annotationProcessing>
</component>
</project>

View File

@ -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>

View File

@ -17,6 +17,7 @@ import org.bukkit.event.player.PlayerBedEnterEvent;
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.*;
@ -115,6 +116,13 @@ public class PhantomListener implements Listener {
}
}
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<>());
@ -176,17 +184,22 @@ public class PhantomListener implements Listener {
targeting((Phantom) ent, null, null);
}
// Untrack phantoms in unloaded chunks
@EventHandler
public void onPhantomInUnloadedChunk(ChunkUnloadEvent e) {
if (e.getWorld().getEnvironment() != World.Environment.NORMAL)
return;
for (Entity ent : e.getChunk().getEntities())
if (ent instanceof Phantom)
removePhantom((Phantom) ent);
}
@EventHandler
public void onPhantomDeath(EntityDeathEvent e) {
if (!(e.getEntity() instanceof Phantom))
return;
Phantom phantom = (Phantom) e.getEntity();
Player p = phantomPlayerMap.remove(phantom);
if (p == null)
return;
playerPhantomMap.get(p).remove(phantom);
removePhantom((Phantom) e.getEntity());
}
}