From d851cebb6c7128094f432d89f6d315a375ab477f Mon Sep 17 00:00:00 2001 From: Simon Chuu Date: Sat, 6 Apr 2019 03:06:53 -0400 Subject: [PATCH 1/9] Start v1.1.1-snapshot: Fix metrics value --- build.gradle | 2 +- src/main/java/com/simonorj/mc/phantomsmp/PhantomSMP.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 6fb3fe2..4a2c58e 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group 'com.simonorj.mc.phantomsmp' -version '1.1.0' +version '1.1.1-snapshot' sourceCompatibility = 1.8 diff --git a/src/main/java/com/simonorj/mc/phantomsmp/PhantomSMP.java b/src/main/java/com/simonorj/mc/phantomsmp/PhantomSMP.java index 5551677..c5dd3f5 100644 --- a/src/main/java/com/simonorj/mc/phantomsmp/PhantomSMP.java +++ b/src/main/java/com/simonorj/mc/phantomsmp/PhantomSMP.java @@ -35,8 +35,8 @@ public void onEnable() { private void setupMetrics() { Metrics metrics = new Metrics(this); - metrics.addCustomChart(new Metrics.SimplePie("remove-targeting-rested", () -> String.valueOf(removeTargetingRested))); - metrics.addCustomChart(new Metrics.SimplePie("remove-targeting-rested", () -> String.valueOf(removeWhenSleeping))); + metrics.addCustomChart(new Metrics.SimplePie("removeTargetingRested", () -> String.valueOf(removeTargetingRested))); + metrics.addCustomChart(new Metrics.SimplePie("removeWhenSleeping", () -> String.valueOf(removeWhenSleeping))); } @Override From 025b4aad4f2cfb6b8df40e60d1565026b9d60821 Mon Sep 17 00:00:00 2001 From: Simon Chuu Date: Sat, 6 Apr 2019 03:07:38 -0400 Subject: [PATCH 2/9] Captialize SNAPSHOT --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 4a2c58e..51ea478 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group 'com.simonorj.mc.phantomsmp' -version '1.1.1-snapshot' +version '1.1.1-SNAPSHOT' sourceCompatibility = 1.8 From 5b49b5ca11697288e26f79eeb4ba5e3728beb8fa Mon Sep 17 00:00:00 2001 From: Simon Chuu Date: Wed, 10 Apr 2019 22:06:02 -0400 Subject: [PATCH 3/9] Update to v1.1.1-SNAPSHOT --- .idea/compiler.xml | 13 +++++++++++++ pom.xml | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .idea/compiler.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..baaea04 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8ad78db..08d2262 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.simonorj.mc.phantomsmp PhantomSMP - 1.1.0 + 1.1.1-SNAPSHOT https://github.com/SimonOrJ/PhantomSMP https://github.com/SimonOrJ/PhantomSMP/issues From b58b48bf04c6f52377fecd8cc5ad1e014cbc6fc8 Mon Sep 17 00:00:00 2001 From: Simon Chuu Date: Wed, 29 May 2019 02:06:51 -0400 Subject: [PATCH 4/9] Add Chunk Unload Event + Update bukkit api and bStats version --- .idea/PhantomSMP.iml | 2 ++ .idea/compiler.xml | 13 ++++++++++ pom.xml | 4 +-- .../mc/phantomsmp/PhantomListener.java | 25 ++++++++++++++----- 4 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 .idea/PhantomSMP.iml create mode 100644 .idea/compiler.xml diff --git a/.idea/PhantomSMP.iml b/.idea/PhantomSMP.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/.idea/PhantomSMP.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..baaea04 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8ad78db..0306467 100644 --- a/pom.xml +++ b/pom.xml @@ -28,13 +28,13 @@ org.bukkit bukkit - 1.13.1-R0.1-SNAPSHOT + 1.13.2-R0.1-SNAPSHOT provided org.bstats bstats-bukkit - 1.4 + 1.5 compile diff --git a/src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java b/src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java index e440388..39aaee1 100644 --- a/src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java +++ b/src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java @@ -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.*; @@ -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<>()); @@ -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()); } } From eeeac813e794c1345db075e1b80056ff45b2ca77 Mon Sep 17 00:00:00 2001 From: Simon Chuu Date: Wed, 29 May 2019 02:28:03 -0400 Subject: [PATCH 5/9] Trigger warning when player leave event fires without join event being called Join event sets up the phantom list for specific player(s). --- .../com/simonorj/mc/phantomsmp/PhantomListener.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java b/src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java index 39aaee1..d9320ee 100644 --- a/src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java +++ b/src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java @@ -132,7 +132,14 @@ public void onPlayerJoin(PlayerJoinEvent e) { public void onPlayerLeave(PlayerQuitEvent e) { Player p = e.getPlayer(); - for (Phantom phantom : playerPhantomMap.get(p)) { + Set phantoms = playerPhantomMap.get(p); + + if (phantoms == null) { + plugin.getLogger().warning("Phantom list for '" + p.getName() + "' was not initiated! Was there an error during login?"); + return; + } + + for (Phantom phantom : phantoms) { if (phantom.getTarget() == p) { phantom.setTarget(null); phantomPlayerMap.remove(phantom); @@ -173,7 +180,6 @@ public void onPhantomTargeting(EntityTargetLivingEntityEvent e) { targeting((Phantom) e.getEntity(), (Player) e.getTarget(), e); } - // Check phantom in loaded chunks @EventHandler public void onPhantomInLoadedChunk(ChunkLoadEvent e) { if (e.getWorld().getEnvironment() != World.Environment.NORMAL) @@ -184,7 +190,6 @@ public void onPhantomInLoadedChunk(ChunkLoadEvent e) { targeting((Phantom) ent, null, null); } - // Untrack phantoms in unloaded chunks @EventHandler public void onPhantomInUnloadedChunk(ChunkUnloadEvent e) { if (e.getWorld().getEnvironment() != World.Environment.NORMAL) From d535203a48380f188488b2b017097c6251e20642 Mon Sep 17 00:00:00 2001 From: Simon Chuu Date: Wed, 29 May 2019 02:50:48 -0400 Subject: [PATCH 6/9] Ignore new chunks on chunk load event --- src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java b/src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java index d9320ee..218d684 100644 --- a/src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java +++ b/src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java @@ -25,7 +25,7 @@ public class PhantomListener implements Listener { private static final String DISALLOW_SPAWN_PERM = "phantomsmp.disallowspawn"; private static final String IGNORE_PERM = "phantomsmp.ignore"; - private final Map> playerPhantomMap = new HashMap<>(); + private final Map> playerPhantomMap = new HashMap<>(); private final Map phantomPlayerMap = new HashMap<>(); private final Set newPhantom = new LinkedHashSet<>(); private final PhantomSMP plugin; @@ -182,7 +182,7 @@ public void onPhantomTargeting(EntityTargetLivingEntityEvent e) { @EventHandler public void onPhantomInLoadedChunk(ChunkLoadEvent e) { - if (e.getWorld().getEnvironment() != World.Environment.NORMAL) + if (e.isNewChunk() || e.getWorld().getEnvironment() != World.Environment.NORMAL) return; for (Entity ent : e.getChunk().getEntities()) From 2f810401f0782c9946fa728e675125c2c507ace4 Mon Sep 17 00:00:00 2001 From: Simon Chuu Date: Tue, 4 Jun 2019 04:32:21 -0400 Subject: [PATCH 7/9] Promote v1.1.1 --- pom.xml | 2 +- readme.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index c48bb9f..c00378a 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.simonorj.mc.phantomsmp PhantomSMP - 1.1.1-SNAPSHOT + 1.1.1 https://github.com/SimonOrJ/PhantomSMP https://github.com/SimonOrJ/PhantomSMP/issues diff --git a/readme.md b/readme.md index 8e273cf..3982240 100644 --- a/readme.md +++ b/readme.md @@ -20,7 +20,7 @@ the next sunrise. This plugin addresses this issue. Features: * Phantoms will ignore players who used the bed within last three Minecraft - days. In addition, this duration is configurable. + days. (The duration is configurable) * Phantoms will ignore or despawn on players who uses the bed or is killed. This is configurable as well. * Control if the phantoms should despawn when they try to target a rested From 1014aeb79af6ef4d81fa2a1a6eea5ebbb35f70e4 Mon Sep 17 00:00:00 2001 From: Simon Chuu Date: Tue, 4 Jun 2019 05:03:46 -0400 Subject: [PATCH 8/9] Simplify Phantom Removal Code --- .../mc/phantomsmp/PhantomListener.java | 27 ++++++------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java b/src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java index 218d684..f713c2b 100644 --- a/src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java +++ b/src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java @@ -67,29 +67,14 @@ else if (phantom.getTarget() instanceof Player) else return; - boolean ignore = p.hasPermission(IGNORE_PERM); - - // If newly spawned phantom - if (newPhantom.remove(phantom)) { - if (ignore || p.hasPermission(DISALLOW_SPAWN_PERM) || recentlyRested(p)) { - if (e != null) - e.setCancelled(true); - phantom.remove(); - return; - } - } - - // If targeting is not allowed - if (ignore || recentlyRested(p)) { + boolean newlySpawned = newPhantom.remove(phantom); + if (ignorePlayer(p, newlySpawned)) { if (e != null) e.setCancelled(true); + else if (newlySpawned || !p.hasPermission(IGNORE_PERM) && plugin.removeTargetingRested && phantom.getCustomName() == null) + phantom.remove(); else phantom.setTarget(null); - - if (!ignore && plugin.removeTargetingRested && phantom.getCustomName() == null) - phantom.remove(); - - return; } // Phantom target is legal @@ -97,6 +82,10 @@ else if (phantom.getTarget() instanceof Player) phantomPlayerMap.put(phantom, p); } + private boolean ignorePlayer(Player p, boolean newlySpawnedPhantom) { + return p.hasPermission(IGNORE_PERM) || newlySpawnedPhantom && p.hasPermission(DISALLOW_SPAWN_PERM) || recentlyRested(p); + } + private void spawned(Phantom phantom) { newPhantom.add(phantom); } From 48fc94222262d198ee66aceaa66591ee94d066eb Mon Sep 17 00:00:00 2001 From: Simon Chuu Date: Tue, 4 Jun 2019 05:15:57 -0400 Subject: [PATCH 9/9] Fix phantom not being removed when newly spawned --- src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java b/src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java index f713c2b..cab92d3 100644 --- a/src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java +++ b/src/main/java/com/simonorj/mc/phantomsmp/PhantomListener.java @@ -71,7 +71,8 @@ else if (phantom.getTarget() instanceof Player) if (ignorePlayer(p, newlySpawned)) { if (e != null) e.setCancelled(true); - else if (newlySpawned || !p.hasPermission(IGNORE_PERM) && plugin.removeTargetingRested && phantom.getCustomName() == null) + + if (newlySpawned || !p.hasPermission(IGNORE_PERM) && plugin.removeTargetingRested && phantom.getCustomName() == null) phantom.remove(); else phantom.setTarget(null);