World Change Processing

This commit is contained in:
Rsl1122 2017-08-22 12:10:37 +03:00
parent a5eb08e39d
commit cc8fcbe5b8

View File

@ -1,8 +1,7 @@
package main.java.com.djrapitops.plan.data.listeners;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.handling.info.InfoType;
import main.java.com.djrapitops.plan.data.handling.info.PlaytimeDependentInfo;
import main.java.com.djrapitops.plan.data.Session;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -10,6 +9,7 @@ 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 {
@ -22,17 +22,16 @@ public class PlanWorldChangeListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onWorldChange(PlayerChangedWorldEvent event) {
Player p = event.getPlayer();
String previousWorld = event.getFrom().getName();
String worldName = p.getWorld().getName();
if (previousWorld.equals(worldName)) {
return;
}
UUID uuid = p.getUniqueId();
String gameMode = p.getGameMode().name();
long time = MiscUtils.getTime();
plugin.addToProcessQueue(new PlaytimeDependentInfo(uuid, InfoType.WORLD, time, gameMode, worldName));
Optional<Session> cachedSession = plugin.getDataCache().getCachedSession(uuid);
if (cachedSession.isPresent()) {
Session session = cachedSession.get();
session.changeState(worldName, gameMode, time);
}
}
}