geforkt von SteamWar/BungeeCore
Move first storage to persistency
Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
67b1fda7f4
Commit
a798d8f915
@ -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<Team, Subserver> 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<Team, Subserver> getEventServer() {
|
||||
public static Map<Integer, Subserver> 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()));
|
||||
|
@ -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<ProxiedPlayer, List<ProxiedPlayer>> challenges = new HashMap<>();
|
||||
public class ChallengeCommand extends BasicCommand {
|
||||
|
||||
public ChallengeCommand() {
|
||||
super("challenge", "");
|
||||
|
@ -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;
|
||||
|
@ -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<String, ProxiedPlayer> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<SteamwarUser, List<Team>> 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<Team> invs = invitations.get(user);
|
||||
Team t = null;
|
||||
List<Integer> 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");
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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<ProxiedPlayer, Session> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren