GameMode change Processing

This commit is contained in:
Rsl1122 2017-08-22 12:09:32 +03:00
parent 8002864c73
commit a5eb08e39d
3 changed files with 11 additions and 6 deletions

View File

@ -60,7 +60,7 @@ public class SessionCache {
* @param uuid UUID of the player. * @param uuid UUID of the player.
* @return Session or null if not cached. * @return Session or null if not cached.
*/ */
public Optional<Session> getSession(UUID uuid) { public Optional<Session> getCachedSession(UUID uuid) {
Session session = activeSessions.get(uuid); Session session = activeSessions.get(uuid);
if (session != null) { if (session != null) {
return Optional.of(session); return Optional.of(session);

View File

@ -12,6 +12,8 @@ import java.util.UUID;
/** /**
* Processor Class for KillEvent information when the killer is a * Processor Class for KillEvent information when the killer is a
* player. * player.
* <p>
* Adds KillData or a Mob kill to the active Session.
* *
* @author Rsl1122 * @author Rsl1122
* @since 4.0.0 * @since 4.0.0
@ -43,7 +45,7 @@ public class KillProcessor extends PlayerProcessor {
Plan plugin = Plan.getInstance(); Plan plugin = Plan.getInstance();
Optional<Session> cachedSession = plugin.getDataCache().getSession(uuid); Optional<Session> cachedSession = plugin.getDataCache().getCachedSession(uuid);
if (!cachedSession.isPresent()) { if (!cachedSession.isPresent()) {
return; return;
} }

View File

@ -1,8 +1,7 @@
package main.java.com.djrapitops.plan.data.listeners; package main.java.com.djrapitops.plan.data.listeners;
import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.handling.info.InfoType; import main.java.com.djrapitops.plan.data.Session;
import main.java.com.djrapitops.plan.data.handling.info.PlaytimeDependentInfo;
import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.MiscUtils;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -10,6 +9,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerGameModeChangeEvent; import org.bukkit.event.player.PlayerGameModeChangeEvent;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
/** /**
@ -40,13 +40,16 @@ public class PlanGamemodeChangeListener implements Listener {
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
} }
Player p = event.getPlayer(); Player p = event.getPlayer();
UUID uuid = p.getUniqueId(); UUID uuid = p.getUniqueId();
long time = MiscUtils.getTime(); long time = MiscUtils.getTime();
String gameMode = event.getNewGameMode().name(); String gameMode = event.getNewGameMode().name();
String worldName = p.getWorld().getName(); String worldName = p.getWorld().getName();
plugin.addToProcessQueue(new PlaytimeDependentInfo(uuid, InfoType.GM, time, gameMode, worldName)); Optional<Session> cachedSession = plugin.getDataCache().getCachedSession(uuid);
if (cachedSession.isPresent()) {
Session session = cachedSession.get();
session.changeState(worldName, gameMode, time);
}
} }
} }