SteamWar/BungeeCore
Archiviert
13
2

Adding sessions

Dieser Commit ist enthalten in:
Lixfel 2019-12-16 09:50:56 +01:00
Ursprung 53d44cb628
Commit 439ef96bac
5 geänderte Dateien mit 51 neuen und 13 gelöschten Zeilen

Datei anzeigen

@ -5,14 +5,6 @@ import net.md_5.bungee.config.Configuration;
import java.util.*;
public class ArenaMode {
/*AirShip,
WarShip,
WarGear,
MiniWarGear,
WarGear7,
GearUp,
EisZeit,
UNKNOWN;*/
private static Map<String, ArenaMode> byChat = new HashMap<>();
private static Map<String, ArenaMode> byInternal = new HashMap<>();

Datei anzeigen

@ -11,7 +11,8 @@ class Broadcaster {
Broadcaster(){
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
BungeeCore.broadcast(BungeeCore.CHAT_PREFIX + broadCastMsgs[lastBroadCast]);
if(!ProxyServer.getInstance().getPlayers().isEmpty())
BungeeCore.broadcast(BungeeCore.CHAT_PREFIX + broadCastMsgs[lastBroadCast]);
lastBroadCast++;
if(lastBroadCast == broadCastMsgs.length){
lastBroadCast = 0;

Datei anzeigen

@ -1,10 +1,7 @@
package de.steamwar.bungeecore;
import de.steamwar.bungeecore.commands.*;
import de.steamwar.bungeecore.listeners.BanListener;
import de.steamwar.bungeecore.listeners.ChatListener;
import de.steamwar.bungeecore.listeners.ConnectionListener;
import de.steamwar.bungeecore.listeners.PollSystem;
import de.steamwar.bungeecore.listeners.*;
import de.steamwar.bungeecore.listeners.mods.Forge;
import de.steamwar.bungeecore.listeners.mods.LabyMod;
import de.steamwar.bungeecore.sql.SQL;
@ -86,6 +83,7 @@ public class BungeeCore extends Plugin {
new EventStarter();
new Broadcaster();
new SessionManager();
getProxy().getScheduler().schedule(this, () -> {
SteamwarUser.clearCache();

Datei anzeigen

@ -0,0 +1,28 @@
package de.steamwar.bungeecore.listeners;
import de.steamwar.bungeecore.sql.Session;
import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.event.PostLoginEvent;
import net.md_5.bungee.event.EventHandler;
import java.util.HashMap;
import java.util.Map;
public class SessionManager extends BasicListener {
private Map<ProxiedPlayer, Session> sessions = new HashMap<>();
@EventHandler
public void onPostLogin(PostLoginEvent event){
sessions.put(event.getPlayer(), new Session(SteamwarUser.get(event.getPlayer()).getId()));
}
@EventHandler
public void onDisconnect(PlayerDisconnectEvent e){
Session session = sessions.remove(e.getPlayer());
if(session != null)
session.stopSession();
}
}

Datei anzeigen

@ -0,0 +1,19 @@
package de.steamwar.bungeecore.sql;
import java.sql.Timestamp;
import java.time.Instant;
public class Session {
private final int userID;
private Timestamp startTime;
public Session(int userID){
this.userID = userID;
startTime = Timestamp.from(Instant.now());
}
public void stopSession(){
SQL.update("INSERT INTO Session (UserID, StartTime, EndTime) VALUES ("+ userID + ", '" + startTime.toString() + "', NOW())");
}
}