Permit periodic task instead of PlayerMoveEvent through NPCLibOptions

Adds NPCLibOptions as an optional parameter to NPCLib's constructor. The
movement handling specified by the NPCLibOptions will determine whether
to use the PlayerMoveEvent or a task.
This commit is contained in:
A248
2020-04-20 15:16:24 -04:00
parent dfd916dc97
commit b00850b19d
6 changed files with 192 additions and 31 deletions
+18 -1
View File
@@ -4,11 +4,14 @@
package net.jitse.npclib;
import net.jitse.npclib.NPCLibOptions.MovementHandling;
import net.jitse.npclib.api.NPC;
import net.jitse.npclib.api.utilities.Logger;
import net.jitse.npclib.listeners.ChunkListener;
import net.jitse.npclib.listeners.PacketListener;
import net.jitse.npclib.listeners.PeriodicMoveListener;
import net.jitse.npclib.listeners.PlayerListener;
import net.jitse.npclib.listeners.PlayerMoveEventListener;
import net.jitse.npclib.metrics.NPCLibMetrics;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
@@ -23,7 +26,7 @@ public final class NPCLib {
private double autoHideDistance = 50.0;
public NPCLib(JavaPlugin plugin) {
private NPCLib(JavaPlugin plugin, MovementHandling moveHandling) {
this.plugin = plugin;
this.logger = new Logger("NPCLib");
@@ -49,6 +52,12 @@ public final class NPCLib {
pluginManager.registerEvents(new PlayerListener(this), plugin);
pluginManager.registerEvents(new ChunkListener(this), plugin);
if (moveHandling.usePme) {
pluginManager.registerEvents(new PlayerMoveEventListener(), plugin);
} else {
pluginManager.registerEvents(new PeriodicMoveListener(this, moveHandling.updateInterval), plugin);
}
// Boot the according packet listener.
new PacketListener().start(this);
@@ -59,6 +68,14 @@ public final class NPCLib {
logger.info("Enabled for Minecraft " + versionName);
}
public NPCLib(JavaPlugin plugin) {
this(plugin, MovementHandling.playerMoveEvent());
}
public NPCLib(JavaPlugin plugin, NPCLibOptions options) {
this(plugin, options.moveHandling);
}
/**
* @return The JavaPlugin instance.
*/