Changed 'evt' naming to 'event' naming to match rest of project

Code refactor from old PR
This commit is contained in:
Jitse Boonstra 2020-06-22 18:19:33 +02:00
parent d7fc0c81e5
commit e4dc20e3ce
1 changed files with 30 additions and 31 deletions

View File

@ -1,8 +1,6 @@
package net.jitse.npclib.listeners;
import java.util.HashMap;
import java.util.UUID;
import net.jitse.npclib.NPCLib;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -11,41 +9,42 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scheduler.BukkitTask;
import net.jitse.npclib.NPCLib;
import java.util.HashMap;
import java.util.UUID;
public class PeriodicMoveListener extends HandleMoveBase implements Listener {
private final NPCLib instance;
private final long updateInterval;
private final NPCLib instance;
private final long updateInterval;
private final HashMap<UUID, BukkitTask> tasks = new HashMap<>();
private final HashMap<UUID, BukkitTask> tasks = new HashMap<>();
public PeriodicMoveListener(NPCLib instance, long updateInterval) {
this.instance = instance;
this.updateInterval = updateInterval;
}
public PeriodicMoveListener(NPCLib instance, long updateInterval) {
this.instance = instance;
this.updateInterval = updateInterval;
}
private void startTask(UUID uuid) {
// purposefully using UUIDs and not holding player references
tasks.put(uuid, Bukkit.getScheduler().runTaskTimer(instance.getPlugin(), () -> {
Player player = Bukkit.getPlayer(uuid);
if (player != null) { // safety check
handleMove(player);
}
}, 1L, updateInterval));
}
private void startTask(UUID uuid) {
// purposefully using UUIDs and not holding player references
tasks.put(uuid, Bukkit.getScheduler().runTaskTimer(instance.getPlugin(), () -> {
Player player = Bukkit.getPlayer(uuid);
if (player != null) { // safety check
handleMove(player);
}
}, 1L, updateInterval));
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent evt) {
startTask(evt.getPlayer().getUniqueId());
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
startTask(event.getPlayer().getUniqueId());
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent evt) {
BukkitTask task = tasks.remove(evt.getPlayer().getUniqueId());
if (task != null) {
task.cancel();
}
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
BukkitTask task = tasks.remove(event.getPlayer().getUniqueId());
if (task != null) {
task.cancel();
}
}
}