Cleaned up task registration

This commit is contained in:
Rsl1122 2018-01-13 21:20:29 +02:00
parent fb09f327ef
commit 91e58d29e2
14 changed files with 90 additions and 579 deletions

View File

@ -17,6 +17,7 @@ import com.djrapitops.plan.system.processing.ProcessingQueue;
import com.djrapitops.plan.system.processing.processors.Processor;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.config.ConfigSystem;
import com.djrapitops.plan.system.tasks.TaskSystem;
import com.djrapitops.plan.system.update.VersionCheckSystem;
import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plan.system.webserver.WebServerSystem;
@ -24,7 +25,6 @@ import com.djrapitops.plan.systems.Systems;
import com.djrapitops.plan.systems.info.BungeeInformationManager;
import com.djrapitops.plan.systems.info.InformationManager;
import com.djrapitops.plan.systems.info.server.BungeeServerInfoManager;
import com.djrapitops.plan.system.tasks.TaskSystem;
import com.djrapitops.plan.utilities.file.export.HtmlExport;
import com.djrapitops.plugin.BungeePlugin;
import com.djrapitops.plugin.StaticHolder;
@ -148,6 +148,7 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
}
@Override
@Deprecated
public InformationManager getInfoManager() {
return infoManager;
}

View File

@ -70,6 +70,7 @@ public class ServerVariableHolder {
*
* @return if the server is using PaperSpigot.
*/
@Deprecated
public boolean isUsingPaper() {
return usingPaper;
}

View File

@ -8,16 +8,12 @@ import com.djrapitops.plan.Plan;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.locale.Msg;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.tasks.bukkit.BukkitTPSCountTimer;
import com.djrapitops.plan.system.tasks.bukkit.PaperTPSCountTimer;
import com.djrapitops.plan.systems.info.InformationManager;
import com.djrapitops.plan.system.tasks.bukkit.*;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.ITask;
import com.djrapitops.plugin.task.RunnableFactory;
/**
* //TODO Class Javadoc Comment
@ -39,51 +35,27 @@ public class BukkitTaskSystem extends TaskSystem {
registerTasks();
}
// TODO Clean Up
private void registerTasks() {
String bootAnalysisMsg = Locale.get(Msg.ENABLE_BOOT_ANALYSIS_INFO).toString();
String bootAnalysisRunMsg = Locale.get(Msg.ENABLE_BOOT_ANALYSIS_RUN_INFO).toString();
Benchmark.start("Task Registration");
tpsCountTimer = Check.isPaperAvailable()
? new PaperTPSCountTimer(plugin)
: new BukkitTPSCountTimer(plugin);
registerTask(tpsCountTimer).runTaskTimer(1000, TimeAmount.SECOND.ticks());
// Analysis refresh settings
int analysisRefreshMinutes = Settings.ANALYSIS_AUTO_REFRESH.getNumber();
boolean analysisRefreshTaskIsEnabled = analysisRefreshMinutes > 0;
long analysisPeriod = analysisRefreshMinutes * TimeAmount.MINUTE.ticks();
Log.info(bootAnalysisMsg);
Log.info(Locale.get(Msg.ENABLE_BOOT_ANALYSIS_INFO).toString());
InformationManager infoManager = plugin.getInfoManager();
bootAnalysisTask = RunnableFactory.createNew("BootAnalysisTask", new AbsRunnable() {
@Override
public void run() {
Log.info(bootAnalysisRunMsg);
infoManager.refreshAnalysis(Plan.getServerUUID());
this.cancel();
}
}).runTaskLaterAsynchronously(30 * TimeAmount.SECOND.ticks());
registerTask(tpsCountTimer).runTaskTimer(1000, TimeAmount.SECOND.ticks());
registerTask(new NetworkPageRefreshTask()).runTaskTimerAsynchronously(20L, 5L * TimeAmount.MINUTE.ticks());
bootAnalysisTask = registerTask(new BootAnalysisTask()).runTaskLaterAsynchronously(30L * TimeAmount.SECOND.ticks());
if (analysisRefreshTaskIsEnabled) {
RunnableFactory.createNew("PeriodicalAnalysisTask", new AbsRunnable() {
@Override
public void run() {
infoManager.refreshAnalysis(Plan.getServerUUID());
}
}).runTaskTimerAsynchronously(analysisPeriod, analysisPeriod);
registerTask(new PeriodicAnalysisTask()).runTaskTimerAsynchronously(analysisPeriod, analysisPeriod);
}
registerTask("PeriodicNetworkBoxRefreshTask", new AbsRunnable() {
@Override
public void run() {
infoManager.updateNetworkPageContent();
}
}).runTaskTimerAsynchronously(TimeAmount.SECOND.ticks(), TimeAmount.MINUTE.ticks() * 5L);
Benchmark.stop("Enable", "Task Registration");
}

View File

@ -5,10 +5,11 @@
package com.djrapitops.plan.system.tasks;
import com.djrapitops.plan.PlanBungee;
import com.djrapitops.plan.system.tasks.bukkit.NetworkPageRefreshTask;
import com.djrapitops.plan.system.tasks.bungee.BungeeTPSCountTimer;
import com.djrapitops.plan.system.tasks.bungee.EnableConnectionTask;
import com.djrapitops.plan.systems.info.BungeeInformationManager;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.task.AbsRunnable;
/**
* //TODO Class Javadoc Comment
@ -21,6 +22,7 @@ public class BungeeTaskSystem extends TaskSystem {
public BungeeTaskSystem(PlanBungee plugin) {
this.plugin = plugin;
tpsCountTimer = new BungeeTPSCountTimer(plugin);
}
@Override
@ -31,20 +33,8 @@ public class BungeeTaskSystem extends TaskSystem {
private void registerTasks() {
BungeeInformationManager infoManager = ((BungeeInformationManager) PlanBungee.getInstance().getInfoManager());
registerTask("Enable Bukkit Connection Task", new AbsRunnable() {
@Override
public void run() {
infoManager.attemptConnection();
infoManager.sendConfigSettings();
}
}).runTaskAsynchronously();
registerTask("Player Count task", new BungeeTPSCountTimer(plugin))
.runTaskTimerAsynchronously(1000, TimeAmount.SECOND.ticks());
registerTask("NetworkPageContentUpdateTask", new AbsRunnable("NetworkPageContentUpdateTask") {
@Override
public void run() {
infoManager.updateNetworkPageContent();
}
}).runTaskTimerAsynchronously(1500, TimeAmount.MINUTE.ticks());
registerTask(new EnableConnectionTask()).runTaskAsynchronously();
registerTask(tpsCountTimer).runTaskTimerAsynchronously(1000, TimeAmount.SECOND.ticks());
registerTask(new NetworkPageRefreshTask()).runTaskTimerAsynchronously(1500, TimeAmount.MINUTE.ticks());
}
}

View File

@ -0,0 +1,22 @@
package com.djrapitops.plan.system.tasks.bukkit;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.locale.Msg;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.task.AbsRunnable;
public class BootAnalysisTask extends AbsRunnable {
public BootAnalysisTask() {
super(BootAnalysisTask.class.getSimpleName());
}
@Override
public void run() {
String bootAnalysisRunMsg = Locale.get(Msg.ENABLE_BOOT_ANALYSIS_RUN_INFO).toString();
Log.info(bootAnalysisRunMsg);
Plan.getInstance().getInfoManager().refreshAnalysis(Plan.getServerUUID());
cancel();
}
}

View File

@ -0,0 +1,16 @@
package com.djrapitops.plan.system.tasks.bukkit;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plugin.task.AbsRunnable;
public class NetworkPageRefreshTask extends AbsRunnable {
public NetworkPageRefreshTask() {
super(NetworkPageRefreshTask.class.getSimpleName());
}
@Override
public void run() {
PlanPlugin.getInstance().getInfoManager().updateNetworkPageContent();
}
}

View File

@ -0,0 +1,16 @@
package com.djrapitops.plan.system.tasks.bukkit;
import com.djrapitops.plan.Plan;
import com.djrapitops.plugin.task.AbsRunnable;
public class PeriodicAnalysisTask extends AbsRunnable {
public PeriodicAnalysisTask() {
super(PeriodicAnalysisTask.class.getSimpleName());
}
@Override
public void run() {
Plan.getInstance().getInfoManager().refreshAnalysis(Plan.getServerUUID());
}
}

View File

@ -0,0 +1,20 @@
package com.djrapitops.plan.system.tasks.bungee;
import com.djrapitops.plan.PlanBungee;
import com.djrapitops.plan.systems.info.BungeeInformationManager;
import com.djrapitops.plugin.task.AbsRunnable;
public class EnableConnectionTask extends AbsRunnable {
public EnableConnectionTask() {
super(EnableConnectionTask.class.getSimpleName());
}
@Override
public void run() {
BungeeInformationManager infoManager = (BungeeInformationManager) PlanBungee.getInstance().getInfoManager();
infoManager.attemptConnection();
infoManager.sendConfigSettings();
cancel();
}
}

View File

@ -1,61 +0,0 @@
package com.djrapitops.plan.systems.listeners;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.systems.cache.DataCache;
import com.djrapitops.plan.systems.processing.player.NameProcessor;
import com.djrapitops.plugin.api.utility.log.Log;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import java.util.UUID;
/**
* Event Listener for AsyncPlayerChatEvents.
*
* @author Rsl1122
*/
public class PlanChatListener implements Listener {
private final Plan plugin;
private final DataCache dataCache;
/**
* Class Constructor.
*
* @param plugin Current instance of Plan
*/
public PlanChatListener(Plan plugin) {
this.plugin = plugin;
dataCache = plugin.getDataCache();
}
/**
* ChatEvent listener.
*
* @param event Fired Event
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onChat(AsyncPlayerChatEvent event) {
if (event.isCancelled()) {
return;
}
try {
Player p = event.getPlayer();
UUID uuid = p.getUniqueId();
String name = p.getName();
String displayName = p.getDisplayName();
if (dataCache.isFirstSession(uuid)) {
dataCache.firstSessionMessageSent(uuid);
}
plugin.addToProcessQueue(new NameProcessor(uuid, name, displayName));
} catch (Exception e) {
Log.toLog(this.getClass(), e);
}
}
}

View File

@ -1,77 +0,0 @@
package com.djrapitops.plan.systems.listeners;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.systems.processing.CommandProcessor;
import com.djrapitops.plugin.api.utility.log.Log;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
/**
* Event Listener for PlayerCommandPreprocessEvents.
*
* @author Rsl1122
*/
public class PlanCommandPreprocessListener implements Listener {
private final Plan plugin;
/**
* Class Constructor.
*
* @param plugin Current instance of Plan
*/
public PlanCommandPreprocessListener(Plan plugin) {
this.plugin = plugin;
}
/**
* Command use listener.
*
* @param event Fired event.
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
if (event.isCancelled()) {
return;
}
Player player = event.getPlayer();
try {
if (player.hasPermission(Permissions.IGNORE_COMMANDUSE.getPermission())) {
return;
}
String commandName = event.getMessage().substring(1).split(" ")[0].toLowerCase();
boolean logUnknownCommands = Settings.LOG_UNKNOWN_COMMANDS.isTrue();
boolean combineCommandAliases = Settings.COMBINE_COMMAND_ALIASES.isTrue();
if (!logUnknownCommands || combineCommandAliases) {
Command command = plugin.getServer().getPluginCommand(commandName);
if (command == null) {
try {
command = plugin.getServer().getCommandMap().getCommand(commandName);
} catch (NoSuchMethodError ignored) {
/* Ignored, Bukkit 1.8 has no such method */
}
}
if (command == null) {
if (!logUnknownCommands) {
return;
}
} else if (combineCommandAliases) {
commandName = command.getName();
}
}
plugin.addToProcessQueue(new CommandProcessor(commandName));
} catch (Exception e) {
Log.toLog(this.getClass(), e);
}
}
}

View File

@ -1,133 +0,0 @@
package com.djrapitops.plan.systems.listeners;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.systems.processing.player.DeathProcessor;
import com.djrapitops.plan.systems.processing.player.KillProcessor;
import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Format;
import org.bukkit.Material;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.projectiles.ProjectileSource;
/**
* Event Listener for EntityDeathEvents.
*
* @author Rsl1122
*/
public class PlanDeathEventListener implements Listener {
private final Plan plugin;
/**
* Class Constructor.
*
* @param plugin Current instance of Plan
*/
public PlanDeathEventListener(Plan plugin) {
this.plugin = plugin;
}
/**
* Command use listener.
*
* @param event Fired event.
*/
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR)
public void onDeath(EntityDeathEvent event) {
long time = MiscUtils.getTime();
LivingEntity dead = event.getEntity();
if (dead instanceof Player) {
plugin.addToProcessQueue(new DeathProcessor(dead.getUniqueId()));
}
try {
EntityDamageEvent entityDamageEvent = dead.getLastDamageCause();
if (!(entityDamageEvent instanceof EntityDamageByEntityEvent)) {
return;
}
EntityDamageByEntityEvent entityDamageByEntityEvent = (EntityDamageByEntityEvent) entityDamageEvent;
Entity killerEntity = entityDamageByEntityEvent.getDamager();
if (killerEntity instanceof Player) {
handlePlayerKill(time, dead, (Player) killerEntity);
} else if (killerEntity instanceof Wolf) {
handleWolfKill(time, dead, (Wolf) killerEntity);
} else if (killerEntity instanceof Arrow) {
handleArrowKill(time, dead, (Arrow) killerEntity);
}
} catch (Exception e) {
Log.toLog(this.getClass(), e);
}
}
private void handlePlayerKill(long time, LivingEntity dead, Player killer) {
Material itemInHand;
try {
itemInHand = killer.getInventory().getItemInMainHand().getType();
} catch (NoSuchMethodError e) {
try {
itemInHand = killer.getInventory().getItemInHand().getType(); // Support for non dual wielding versions.
} catch (Exception | NoSuchMethodError | NoSuchFieldError e2) {
itemInHand = Material.AIR;
}
}
plugin.addToProcessQueue(new KillProcessor(killer.getUniqueId(), time, dead, normalizeMaterialName(itemInHand)));
}
private void handleWolfKill(long time, LivingEntity dead, Wolf wolf) {
if (!wolf.isTamed()) {
return;
}
AnimalTamer owner = wolf.getOwner();
if (!(owner instanceof Player)) {
return;
}
plugin.addToProcessQueue(new KillProcessor(owner.getUniqueId(), time, dead, "Wolf"));
}
private void handleArrowKill(long time, LivingEntity dead, Arrow arrow) {
ProjectileSource source = arrow.getShooter();
if (!(source instanceof Player)) {
return;
}
Player player = (Player) source;
plugin.addToProcessQueue(new KillProcessor(player.getUniqueId(), time, dead, "Bow"));
}
/**
* Normalizes a material name
*
* @param material The material
* @return The normalized material name
*/
private String normalizeMaterialName(Material material) {
String[] parts = material.name().split("_");
StringBuilder builder = new StringBuilder();
for (int i = 0; i < parts.length; i++) {
String part = new Format(parts[i]).capitalize().toString();
builder.append(part);
if (i < parts.length - 1) {
builder.append(" ");
}
}
return builder.toString();
}
}

View File

@ -1,60 +0,0 @@
package com.djrapitops.plan.systems.listeners;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.settings.WorldAliasSettings;
import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plugin.api.utility.log.Log;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import java.util.Optional;
import java.util.UUID;
/**
* Event Listener for PlayerGameModeChangeEvents.
*
* @author Rsl1122
*/
public class PlanGamemodeChangeListener implements Listener {
private final Plan plugin;
/**
* Class Constructor.
*
* @param plugin Current instance of Plan
*/
public PlanGamemodeChangeListener(Plan plugin) {
this.plugin = plugin;
}
/**
* GM Change Event Listener.
*
* @param event Fired Event.
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onGamemodeChange(PlayerGameModeChangeEvent event) {
if (event.isCancelled()) {
return;
}
try {
Player p = event.getPlayer();
UUID uuid = p.getUniqueId();
long time = MiscUtils.getTime();
String gameMode = event.getNewGameMode().name();
String worldName = p.getWorld().getName();
new WorldAliasSettings().addWorld(worldName);
Optional<Session> cachedSession = plugin.getDataCache().getCachedSession(uuid);
cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time));
} catch (Exception e) {
Log.toLog(this.getClass(), e);
}
}
}

View File

@ -1,154 +0,0 @@
package com.djrapitops.plan.systems.listeners;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.systems.cache.DataCache;
import com.djrapitops.plan.systems.processing.info.NetworkPageUpdateProcessor;
import com.djrapitops.plan.systems.processing.player.*;
import com.djrapitops.plan.systems.tasks.TaskSystem;
import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plugin.api.systems.NotificationCenter;
import com.djrapitops.plugin.api.utility.log.Log;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.UUID;
/**
* Event Listener for PlayerJoin, PlayerQuit and PlayerKickEvents.
*
* @author Rsl1122
* @since 2.0.0
*/
public class PlanPlayerListener implements Listener {
private static boolean countKicks = true;
private final Plan plugin;
private final DataCache cache;
/**
* Class Constructor.
*
* @param plugin Current instance of Plan
*/
public PlanPlayerListener(Plan plugin) {
this.plugin = plugin;
cache = plugin.getDataCache();
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerLogin(PlayerLoginEvent event) {
try {
PlayerLoginEvent.Result result = event.getResult();
UUID uuid = event.getPlayer().getUniqueId();
boolean op = event.getPlayer().isOp();
if (result == PlayerLoginEvent.Result.KICK_BANNED) {
plugin.addToProcessQueue(new BanAndOpProcessor(uuid, true, op));
} else {
plugin.addToProcessQueue(new BanAndOpProcessor(uuid, false, op));
}
} catch (Exception e) {
Log.toLog(this.getClass(), e);
}
}
/**
* PlayerKickEvent Listener.
* <p>
* Adds processing information to the ProcessingQueue.
* After KickEvent, the QuitEvent is automatically called.
*
* @param event Fired event
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerKick(PlayerKickEvent event) {
try {
if (!countKicks || event.isCancelled()) {
return;
}
UUID uuid = event.getPlayer().getUniqueId();
plugin.addToProcessQueue(new KickProcessor(uuid));
} catch (Exception e) {
Log.toLog(this.getClass(), e);
}
}
/**
* PlayerJoinEvent Listener.
* <p>
* Adds processing information to the ProcessingQueue.
*
* @param event The Fired event.
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
try {
Player player = event.getPlayer();
NotificationCenter.checkNotifications(player);
UUID uuid = player.getUniqueId();
long time = MiscUtils.getTime();
String world = player.getWorld().getName();
String gm = player.getGameMode().name();
String ip = player.getAddress().getAddress().getHostAddress();
String playerName = player.getName();
String displayName = player.getDisplayName();
int playersOnline = TaskSystem.getInstance().getTpsCountTimer().getLatestPlayersOnline();
cache.cacheSession(uuid, Session.start(time, world, gm));
plugin.addToProcessQueue(
new RegisterProcessor(uuid, player.getFirstPlayed(), time, playerName, playersOnline,
new IPUpdateProcessor(uuid, ip, time),
new NameProcessor(uuid, playerName, displayName)
),
new NetworkPageUpdateProcessor(plugin.getInfoManager())
);
} catch (Exception e) {
Log.toLog(this.getClass(), e);
}
}
/**
* PlayerQuitEvent Listener.
* <p>
* Adds processing information to the ProcessingQueue.
*
* @param event Fired event
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
try {
long time = MiscUtils.getTime();
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
plugin.addToProcessQueue(
new BanAndOpProcessor(uuid, player.isBanned(), player.isOp()),
new EndSessionProcessor(uuid, time),
new NetworkPageUpdateProcessor(plugin.getInfoManager())
);
if (cache.isFirstSession(uuid)) {
int messagesSent = plugin.getDataCache().getFirstSessionMsgCount(uuid);
plugin.addToProcessQueue(new FirstLeaveProcessor(uuid, time, messagesSent));
}
} catch (Exception e) {
Log.toLog(this.getClass(), e);
}
}
public static void setCountKicks(boolean value) {
countKicks = value;
}
}

View File

@ -1,42 +0,0 @@
package com.djrapitops.plan.systems.listeners;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.settings.WorldAliasSettings;
import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plugin.api.utility.log.Log;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import java.util.Optional;
import java.util.UUID;
public class PlanWorldChangeListener implements Listener {
private final Plan plugin;
public PlanWorldChangeListener(Plan plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onWorldChange(PlayerChangedWorldEvent event) {
try {
Player p = event.getPlayer();
String worldName = p.getWorld().getName();
UUID uuid = p.getUniqueId();
String gameMode = p.getGameMode().name();
long time = MiscUtils.getTime();
new WorldAliasSettings().addWorld(worldName);
Optional<Session> cachedSession = plugin.getDataCache().getCachedSession(uuid);
cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time));
} catch (Exception e) {
Log.toLog(this.getClass(), e);
}
}
}