diff --git a/src/de/steamwar/bungeecore/EventStarter.java b/src/de/steamwar/bungeecore/EventStarter.java index 54628c42..e2a44f8b 100644 --- a/src/de/steamwar/bungeecore/EventStarter.java +++ b/src/de/steamwar/bungeecore/EventStarter.java @@ -28,14 +28,14 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.scheduler.ScheduledTask; import java.sql.Timestamp; -import java.util.HashMap; import java.util.Map; import java.util.Queue; import java.util.concurrent.TimeUnit; +import static de.steamwar.bungeecore.Storage.eventServer; + public class EventStarter implements Runnable { - private static final Map eventServer = new HashMap<>(); private static ScheduledTask task = null; EventStarter(){ @@ -47,7 +47,7 @@ public class EventStarter implements Runnable { ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), this, 1, 10, TimeUnit.SECONDS); } - public static Map getEventServer() { + public static Map getEventServer() { return eventServer; } @@ -67,8 +67,8 @@ public class EventStarter implements Runnable { if(leiter != null) subserver.sendPlayer(leiter); - eventServer.put(blue, subserver); - eventServer.put(red, subserver); + eventServer.put(blue.getTeamId(), subserver); + eventServer.put(red.getTeamId(), subserver); BungeeCore.broadcast(BungeeCore.CHAT_PREFIX + "§7Hier §eklicken §7für den Kampf §e" + blue.getTeamName() + " §8vs §e" + red.getTeamName(), "§eEvent beitreten", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/event " + blue.getTeamKuerzel())); diff --git a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java index 21832a33..de1eecc6 100644 --- a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java +++ b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java @@ -28,9 +28,9 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.*; -public class ChallengeCommand extends BasicCommand { +import static de.steamwar.bungeecore.Storage.challenges; - private static final Map> challenges = new HashMap<>(); +public class ChallengeCommand extends BasicCommand { public ChallengeCommand() { super("challenge", ""); diff --git a/src/de/steamwar/bungeecore/commands/EventCommand.java b/src/de/steamwar/bungeecore/commands/EventCommand.java index 24c6d889..4a93cc19 100644 --- a/src/de/steamwar/bungeecore/commands/EventCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventCommand.java @@ -68,7 +68,7 @@ public class EventCommand extends BasicCommand { return; } - Subserver eventArena = EventStarter.getEventServer().get(team); + Subserver eventArena = EventStarter.getEventServer().get(team.getTeamId()); if(eventArena == null || !Subserver.getServerList().contains(eventArena)){ BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDas Team kämpft derzeit nicht"); return; diff --git a/src/de/steamwar/bungeecore/commands/MsgCommand.java b/src/de/steamwar/bungeecore/commands/MsgCommand.java index 31541dd4..5d5baba3 100644 --- a/src/de/steamwar/bungeecore/commands/MsgCommand.java +++ b/src/de/steamwar/bungeecore/commands/MsgCommand.java @@ -27,12 +27,11 @@ import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.ArrayList; -import java.util.HashMap; + +import static de.steamwar.bungeecore.Storage.lastChats; public class MsgCommand extends BasicCommand { - static final HashMap lastChats = new HashMap<>(); - public MsgCommand() { super("msg", "", "w", "tell"); } @@ -78,8 +77,8 @@ public class MsgCommand extends BasicCommand { BungeeCore.send(target, msg); BungeeCore.log(msg); - lastChats.put(player.getName().toLowerCase(), target); - lastChats.put(target.getName().toLowerCase(), player); + lastChats.put(player, target); + lastChats.put(target, player); } } @@ -90,4 +89,8 @@ public class MsgCommand extends BasicCommand { } return new ArrayList<>(); } + + public static void remove(ProxiedPlayer player){ + lastChats.remove(player); + } } diff --git a/src/de/steamwar/bungeecore/commands/RCommand.java b/src/de/steamwar/bungeecore/commands/RCommand.java index 3602b5d0..566dbcf8 100644 --- a/src/de/steamwar/bungeecore/commands/RCommand.java +++ b/src/de/steamwar/bungeecore/commands/RCommand.java @@ -25,6 +25,8 @@ import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; +import static de.steamwar.bungeecore.Storage.lastChats; + public class RCommand extends BasicCommand { public RCommand() { @@ -46,12 +48,13 @@ public class RCommand extends BasicCommand { return; } - ProxiedPlayer target = MsgCommand.lastChats.get(player.getName().toLowerCase()); + ProxiedPlayer target = lastChats.get(player); if(target == null){ BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDu hast bisher mit niemandem geschrieben!"); return; }else if(!target.isConnected()){ BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler ist derzeit nicht online!"); + lastChats.remove(player); return; }else if (IgnoreSystem.isIgnored(target, player)) { BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler hat dich geblockt!"); @@ -71,7 +74,7 @@ public class RCommand extends BasicCommand { BungeeCore.send(target, msg); BungeeCore.log(msg); - MsgCommand.lastChats.put(target.getName().toLowerCase(), player); + lastChats.put(target, player); } } } diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index 937f991d..4d8ff64f 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -36,14 +36,14 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import java.time.Instant; import java.util.*; +import static de.steamwar.bungeecore.Storage.teamInvitations; + public class TeamCommand extends BasicCommand { public TeamCommand() { super("team", ""); } - private static Map> invitations = new HashMap<>(); - private void help(CommandSender sender){ BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§7Mit §e/team §7verwaltest du dein Team"); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§eteam list §8- §7Liste alle Teams auf"); @@ -152,13 +152,13 @@ public class TeamCommand extends BasicCommand { if(notDuringEvent(player)) return; - if(!invitations.containsKey(user)){ + if(!teamInvitations.containsKey(user.getId())){ BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast keine Einladungen erhalten."); return; } - List invs = invitations.get(user); - Team t = null; + List invs = teamInvitations.get(user.getId()); + Integer t = null; if(invs.size() == 1){ t = invs.get(0); @@ -166,15 +166,17 @@ public class TeamCommand extends BasicCommand { if(args.length != 2){ BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§8/§eteam join §8[§eTeam§8]"); StringBuilder sb = new StringBuilder().append("§7Du wurdest von diesen Teams eingeladen§8: §e"); - for(Team inv : invs){ - sb.append(inv.getTeamName()).append(" "); + for(int inv : invs){ + Team team = Team.get(inv); + sb.append(team.getTeamName()).append(" "); } BungeeCore.send(player, sb.toString()); return; } - for(Team inv : invs){ - if(inv.getTeamName().equals(args[1])){ + for(int inv : invs){ + Team team = Team.get(inv); + if(team.getTeamName().equals(args[1])){ t = inv; break; } @@ -186,9 +188,9 @@ public class TeamCommand extends BasicCommand { } } - user.setTeam(t.getTeamId()); - invitations.remove(user); - BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du bist dem Team §e" + t.getTeamName() + " §7beigetreten!"); + user.setTeam(t); + teamInvitations.remove(user.getId()); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du bist dem Team §e" + Team.get(t).getTeamName() + " §7beigetreten!"); } private void leave(ProxiedPlayer player, SteamwarUser user, Team team){ @@ -231,15 +233,15 @@ public class TeamCommand extends BasicCommand { return; } - if(!invitations.containsKey(target)) - invitations.put(target, new LinkedList<>()); + if(!teamInvitations.containsKey(target.getId())) + teamInvitations.put(target.getId(), new LinkedList<>()); - if(invitations.get(target).contains(team)){ + if(teamInvitations.get(target.getId()).contains(team.getTeamId())){ BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDu hast diesen Spieler bereits eingeladen"); return; } - invitations.get(target).add(team); + teamInvitations.get(target.getId()).add(team.getTeamId()); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast §e" + args[1] + " §7in das Team eingeladen!"); ProxiedPlayer p = ProxyServer.getInstance().getPlayer(target.getUuid()); @@ -262,11 +264,11 @@ public class TeamCommand extends BasicCommand { return; } - if(invitations.containsKey(target)){ - if(invitations.get(target).remove(team)){ + if(teamInvitations.containsKey(target.getId())){ + if(teamInvitations.get(target.getId()).remove((Integer) team.getTeamId())){ BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Die Einladung wurde zurückgezogen"); - if(invitations.get(target).isEmpty()) - invitations.remove(target); + if(teamInvitations.get(target.getId()).isEmpty()) + teamInvitations.remove(target.getId()); }else{ BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler hat keine Einladung erhalten"); } diff --git a/src/de/steamwar/bungeecore/commands/TpCommand.java b/src/de/steamwar/bungeecore/commands/TpCommand.java index a30b9f27..26143225 100644 --- a/src/de/steamwar/bungeecore/commands/TpCommand.java +++ b/src/de/steamwar/bungeecore/commands/TpCommand.java @@ -83,7 +83,7 @@ public class TpCommand extends BasicCommand { if(server == null){ Team team = Team.get(args[0]); if(team != null){ - Subserver eventArena = EventStarter.getEventServer().get(team); + Subserver eventArena = EventStarter.getEventServer().get(team.getTeamId()); if(eventArena != null && Subserver.getServerList().contains(eventArena)) server = eventArena.getServer(); } diff --git a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java index 651a4312..f34022c2 100644 --- a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java +++ b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java @@ -23,6 +23,7 @@ import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Subserver; import de.steamwar.bungeecore.commands.ChallengeCommand; +import de.steamwar.bungeecore.commands.MsgCommand; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.AbstractReconnectHandler; import net.md_5.bungee.api.ProxyServer; @@ -153,6 +154,7 @@ public class ConnectionListener extends BasicListener { @EventHandler public void onDisconnect(PlayerDisconnectEvent e){ ChallengeCommand.remove(e.getPlayer()); + MsgCommand.remove(e.getPlayer()); } @EventHandler diff --git a/src/de/steamwar/bungeecore/listeners/SessionManager.java b/src/de/steamwar/bungeecore/listeners/SessionManager.java index 885a5c04..599ca08a 100644 --- a/src/de/steamwar/bungeecore/listeners/SessionManager.java +++ b/src/de/steamwar/bungeecore/listeners/SessionManager.java @@ -21,27 +21,26 @@ 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; +import java.sql.Timestamp; +import java.time.Instant; + +import static de.steamwar.bungeecore.Storage.sessions; public class SessionManager extends BasicListener { - private Map sessions = new HashMap<>(); - @EventHandler public void onPostLogin(PostLoginEvent event){ - sessions.put(event.getPlayer(), new Session(SteamwarUser.get(event.getPlayer()).getId())); + sessions.put(event.getPlayer(), Timestamp.from(Instant.now())); } @EventHandler public void onDisconnect(PlayerDisconnectEvent e){ - Session session = sessions.remove(e.getPlayer()); - if(session != null) - session.stopSession(); + Timestamp timestamp = sessions.remove(e.getPlayer()); + if(timestamp != null) + Session.insertSession(SteamwarUser.get(e.getPlayer()).getId(), timestamp); } } diff --git a/src/de/steamwar/bungeecore/sql/Session.java b/src/de/steamwar/bungeecore/sql/Session.java index 419b9e19..7f48659a 100644 --- a/src/de/steamwar/bungeecore/sql/Session.java +++ b/src/de/steamwar/bungeecore/sql/Session.java @@ -20,19 +20,11 @@ package de.steamwar.bungeecore.sql; import java.sql.Timestamp; -import java.time.Instant; public class Session { + private Session(){} - private final int userID; - private Timestamp startTime; - - public Session(int userID){ - this.userID = userID; - startTime = Timestamp.from(Instant.now()); - } - - public void stopSession(){ + public static void insertSession(int userID, Timestamp startTime){ SQL.update("INSERT INTO Session (UserID, StartTime, EndTime) VALUES (?, ?, NOW())", userID, startTime); } }