Skip to content

Commit

Permalink
Merge branch 'master' into v1.1.1-snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
chuushi committed May 29, 2019
2 parents 5b49b5c + b58b48b commit 25759fa
Show file tree
Hide file tree
Showing 4 changed files with 24 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.

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
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# ![Logo](https://www.spigotmc.org/data/resource_icons/59/59721.jpg) PhantomSMP
[![Build Status](https://travis-ci.org/SimonOrJ/PhantomSMP.svg?branch=master)](https://travis-ci.org/SimonOrJ/PhantomSMP) [![Maintainability](https://api.codeclimate.com/v1/badges/ec57a5bdcfdb28f9d5cb/maintainability)](https://codeclimate.com/github/SimonOrJ/PhantomSMP/maintainability)

*Better Phantom handling for SMP*

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 25759fa

Please sign in to comment.