commit
7bdefc97a0
|
@ -0,0 +1,2 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4" />
|
|
@ -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>
|
6
pom.xml
6
pom.xml
|
@ -5,7 +5,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.simonorj.mc.phantomsmp</groupId>
|
||||
<artifactId>PhantomSMP</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<version>1.1.1</version>
|
||||
<url>https://github.com/SimonOrJ/PhantomSMP</url>
|
||||
<issueManagement>
|
||||
<url>https://github.com/SimonOrJ/PhantomSMP/issues</url>
|
||||
|
@ -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>
|
||||
|
|
|
@ -24,7 +24,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
|
||||
|
|
|
@ -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.*;
|
||||
|
||||
|
@ -24,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<Player, LinkedHashSet<Phantom>> playerPhantomMap = new HashMap<>();
|
||||
private final Map<Player, Set<Phantom>> playerPhantomMap = new HashMap<>();
|
||||
private final Map<Phantom, Player> phantomPlayerMap = new HashMap<>();
|
||||
private final Set<Phantom> newPhantom = new LinkedHashSet<>();
|
||||
private final PhantomSMP plugin;
|
||||
|
@ -66,29 +67,15 @@ public class PhantomListener implements Listener {
|
|||
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);
|
||||
|
||||
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
|
||||
|
@ -96,6 +83,10 @@ public class PhantomListener implements Listener {
|
|||
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);
|
||||
}
|
||||
|
@ -115,6 +106,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<>());
|
||||
|
@ -124,7 +122,14 @@ public class PhantomListener implements Listener {
|
|||
public void onPlayerLeave(PlayerQuitEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
|
||||
for (Phantom phantom : playerPhantomMap.get(p)) {
|
||||
Set<Phantom> 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);
|
||||
|
@ -165,10 +170,9 @@ public class PhantomListener implements Listener {
|
|||
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)
|
||||
if (e.isNewChunk() || e.getWorld().getEnvironment() != World.Environment.NORMAL)
|
||||
return;
|
||||
|
||||
for (Entity ent : e.getChunk().getEntities())
|
||||
|
@ -176,17 +180,21 @@ public class PhantomListener implements Listener {
|
|||
targeting((Phantom) ent, null, null);
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ public class PhantomSMP extends JavaPlugin {
|
|||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue