From 24456458dea7b8743f5201f4cb06825a49aa360d Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Sat, 21 Jan 2023 16:18:47 +0100 Subject: [PATCH 01/31] Rework two commands --- src/de/steamwar/bungeecore/BungeeCore.java | 4 +- .../bungeecore/commands/BauCommand.java | 7 +- .../bungeecore/commands/HelpCommand.java | 107 ++++++++---------- .../bungeecore/commands/TeamchatCommand.java | 18 ++- 4 files changed, 65 insertions(+), 71 deletions(-) diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 6d3a3d7..f9e937c 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -136,7 +136,7 @@ public class BungeeCore extends Plugin { new KickCommand(); new JoinmeCommand(); new TpCommand(); - new HelpCommand(); + HelpCommand helpCommand = new HelpCommand(); new TeamCommand(); new ServerTeamchatCommand(); new DevCommand(); @@ -176,7 +176,7 @@ public class BungeeCore extends Plugin { new PunishmentCommand("note", Punishment.PunishmentType.Note); if(!EVENT_MODE){ - new BauCommand(); + new BauCommand(helpCommand); new WebpasswordCommand(); new FightCommand(); new ChallengeCommand(); diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 06dc3bc..7bf45b9 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -41,13 +41,16 @@ import java.util.Map; public class BauCommand extends SWCommand { - public BauCommand(){ + private final HelpCommand command; + + public BauCommand(HelpCommand command){ super("bau", null, "b", "build", "gs"); + this.command = command; } @Register(help = true) public void genericHelp(ProxiedPlayer p, String... args) { - HelpCommand.sendBauHelp(ChatSender.of(p)); + this.command.sendBauHelp(p); } @Register diff --git a/src/de/steamwar/bungeecore/commands/HelpCommand.java b/src/de/steamwar/bungeecore/commands/HelpCommand.java index d3fb3fe..7da1ba7 100644 --- a/src/de/steamwar/bungeecore/commands/HelpCommand.java +++ b/src/de/steamwar/bungeecore/commands/HelpCommand.java @@ -20,72 +20,61 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; +import de.steamwar.command.SWCommand; import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.protocol.packet.Chat; -public class HelpCommand extends BasicCommand { +public class HelpCommand extends SWCommand { public HelpCommand() { super("help", "", "?"); } - @Override - public void execute(CommandSender s, String[] args) { - ChatSender sender = ChatSender.of(s); - if (args.length < 1) { - printPage(sender, ClickEvent.Action.RUN_COMMAND, - "HELP_LOBBY", "/l", - "HELP_BAU", "/build", - "HELP_BAUSERVER", "/help build", - "HELP_FIGHT", "/fight", - "HELP_CHALLENGE", "/challenge", - "HELP_HISTORIC", "/historic", - "HELP_TEAM", "/team", - "HELP_JOIN", "/join", - "HELP_LOCAL", "/local"); - }else if (args[0].equalsIgnoreCase("buildserver")) { - sendBauHelp(sender); - }else if (args[0].equalsIgnoreCase("build")) { - bauHelpGroup(sender, args); - } - } + @Register + public void genericCommand(ProxiedPlayer player) { + ChatSender sender = ChatSender.of(player); - private static void bauHelpGroup(ChatSender sender, String[] args) { - if (args.length < 2) { - sendBauHelpGroup(sender); - return; - } - - switch (args[1].toLowerCase()) { - case "admin": - case "owner": - case "bauwelt": - sender.system("HELP_BAU_GROUP_ADMIN_TITLE"); - sendBauHelp(sender); - return; - case "world": - printPage(sender, "HELP_BAU_GROUP_WORLD_TITLE", "HELP_TNT", "HELP_FIRE", "HELP_FREEZE", "HELP_TPSLIMIT", "HELP_PROTECT", "HELP_RESET"); - return; - case "player": - printPage(sender, "HELP_BAU_GROUP_PLAYER_TITLE", "HELP_SPEED", "HELP_NV", "HELP_WV", "HELP_DEBUGSTICK", "HELP_TRACE", "HELP_LOADER"); - return; - case "worldedit": - case "we": - case "world-edit": - case "edit": - printPage(sender, "HELP_BAU_GROUP_WE_TITLE", "HELP_WE_POS1", "HELP_WE_POS2", "HELP_WE_COPY", "HELP_WE_PASTE", "HELP_WE_FLOPY", "HELP_WE_FLOPYP", "HELP_WE_ROTATE_90", "HELP_WE_ROTATE_180", "HELP_WE_ROTATE_N90"); - return; - case "other": - printPage(sender, "HELP_BAU_GROUP_OTHER_TITLE", "HELP_TESTBLOCK", "HELP_SKULL", "HELP_BAUINFO"); - return; - default: - sendBauHelpGroup(sender); - } - } - - private static void sendBauHelpGroup(ChatSender sender) { printPage(sender, ClickEvent.Action.RUN_COMMAND, + "HELP_LOBBY", "/l", + "HELP_BAU", "/build", + "HELP_BAUSERVER", "/help build", + "HELP_FIGHT", "/fight", + "HELP_CHALLENGE", "/challenge", + "HELP_HISTORIC", "/historic", + "HELP_TEAM", "/team", + "HELP_JOIN", "/join", + "HELP_LOCAL", "/local"); + } + + @Register({"build","world"}) + public void buildWorld(ProxiedPlayer player) { + printPage(ChatSender.of(player), "HELP_BAU_GROUP_WORLD_TITLE", "HELP_TNT", "HELP_FIRE", "HELP_FREEZE", "HELP_TPSLIMIT", "HELP_PROTECT", "HELP_RESET"); + } + + @Register({"build","player"}) + public void buildPlayer(ProxiedPlayer player) { + printPage(ChatSender.of(player), "HELP_BAU_GROUP_PLAYER_TITLE", "HELP_SPEED", "HELP_NV", "HELP_WV", "HELP_DEBUGSTICK", "HELP_TRACE", "HELP_LOADER"); + } + + @Register({"build","worldedit"}) + @Register({"build","we"}) + @Register({"build","world-edit"}) + @Register({"build","edit"}) + public void buildWorldedit(ProxiedPlayer player) { + printPage(ChatSender.of(player), "HELP_BAU_GROUP_WE_TITLE", "HELP_WE_POS1", "HELP_WE_POS2", "HELP_WE_COPY", "HELP_WE_PASTE", "HELP_WE_FLOPY", "HELP_WE_FLOPYP", "HELP_WE_ROTATE_90", "HELP_WE_ROTATE_180", "HELP_WE_ROTATE_N90"); + } + + @Register({"build","other"}) + public void buildOther(ProxiedPlayer player) { + printPage(ChatSender.of(player), "HELP_BAU_GROUP_OTHER_TITLE", "HELP_TESTBLOCK", "HELP_SKULL", "HELP_BAUINFO"); + } + + @Register("build") + public void sendBauHelpGroup(ProxiedPlayer player) { + printPage(ChatSender.of(player), ClickEvent.Action.RUN_COMMAND, "HELP_BAU_GROUP_ADMIN", "/help build admin", "HELP_BAU_GROUP_WORLD", "/help build world", "HELP_BAU_GROUP_PLAYER", "/help build player", @@ -93,8 +82,12 @@ public class HelpCommand extends BasicCommand { "HELP_BAU_GROUP_OTHER", "/help build other"); } - static void sendBauHelp(ChatSender sender) { - printPage(sender, ClickEvent.Action.SUGGEST_COMMAND, + @Register("buildserver") + @Register({"build","admin"}) + @Register({"build","owner"}) + @Register({"build","bauwelt"}) + public void sendBauHelp(ProxiedPlayer player) { + printPage(ChatSender.of(player), ClickEvent.Action.SUGGEST_COMMAND, "HELP_BAU_TP", "/build tp ", "HELP_BAU_ADDMEMBER", "/build addmember ", "HELP_BAU_DELMEMBER", "/build delmember ", diff --git a/src/de/steamwar/bungeecore/commands/TeamchatCommand.java b/src/de/steamwar/bungeecore/commands/TeamchatCommand.java index 60e57dc..8d5e3e3 100644 --- a/src/de/steamwar/bungeecore/commands/TeamchatCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamchatCommand.java @@ -21,29 +21,27 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.listeners.ChatListener; import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.command.SWCommand; import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.connection.ProxiedPlayer; -public class TeamchatCommand extends BasicCommand { +public class TeamchatCommand extends SWCommand { public TeamchatCommand() { super("tc", "","teamchat"); } - @Override - public void execute(CommandSender s, String[] args) { - ChatSender sender = ChatSender.of(s); - if(args.length == 0){ - sender.system("TC_USAGE"); - return; - } - + @Register + public void genericCommand(ProxiedPlayer player, @ErrorMessage(value = "TC_USAGE", allowEAs = false) String... args) { + ChatSender sender = ChatSender.of(player); SteamwarUser user = sender.user(); + if(user.getTeam() == 0){ sender.system("TC_NO_TEAM"); return; } - ChatListener.sendChat(sender, ChatSender.allReceivers().filter(player -> player.user().getTeam() == user.getTeam()), "CHAT_TEAM", null, String.join(" ", args)); + ChatListener.sendChat(sender, ChatSender.allReceivers().filter(p -> p.user().getTeam() == user.getTeam()), "CHAT_TEAM", null, String.join(" ", args)); } } From 9f9d0820420eb8b3f92b0b857ea2772a2b78e56b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 21 Jan 2023 16:49:39 +0100 Subject: [PATCH 02/31] Update TpCommand --- .../bungeecore/commands/TpCommand.java | 81 ++++++++++++------- 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/TpCommand.java b/src/de/steamwar/bungeecore/commands/TpCommand.java index de61885..d9dd23d 100644 --- a/src/de/steamwar/bungeecore/commands/TpCommand.java +++ b/src/de/steamwar/bungeecore/commands/TpCommand.java @@ -22,6 +22,8 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.sql.*; import de.steamwar.bungeecore.util.Chat19; +import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeMapper; import de.steamwar.messages.ChatSender; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.CommandSender; @@ -30,45 +32,62 @@ import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.ArrayList; +import java.util.Collection; +import java.util.List; -public class TpCommand extends BasicCommand { +public class TpCommand extends SWCommand { public TpCommand(){ super("join", null, "tp", "teleport"); } - @Override - public void execute(CommandSender s, String[] args) { - if(!(s instanceof ProxiedPlayer)) - return; - ProxiedPlayer player = (ProxiedPlayer) s; - - ChatSender sender = ChatSender.of(player); - if(args.length == 0){ - if(Event.get() == null) - sender.system("TP_USAGE"); - else - sender.system("TP_USAGE_EVENT"); - return; - } - - ServerInfo server = getTarget(args[0]); - boolean onTeamServer = Storage.teamServers.containsValue(player.getServer().getInfo()); - - //Give control of teleport command to server - if (server == player.getServer().getInfo() || onTeamServer || server == null) { - Chat19.chat(player, "/tp " + String.join(" ", args)); - return; - } - - teleport(player, server); + @Register + public void genericCommand(ProxiedPlayer p) { + ChatSender.of(p).system(Event.get() == null ? "TP_USAGE" : "TP_USAGE_EVENT"); } - @Override - public Iterable onTabComplete(CommandSender commandSender, String[] args) { - if(args.length > 0) - return allPlayers(args[args.length - 1]); - return new ArrayList<>(); + @Register + public void teleportCommand(ProxiedPlayer p, @Mapper("to") String to, String... rest) { + ServerInfo server = getTarget(to); + + //Give control of teleport command to server + if (server == p.getServer().getInfo() || server == null) { + if (rest.length == 0) { + Chat19.chat(p, "/tp " + to); + } else { + Chat19.chat(p, "/tp " + to + " " + String.join(" ", rest)); + } + return; + } + + teleport(p, server); + } + + @Mapper("to") + @Cached(cacheDuration = 10, global = true) + public TypeMapper tabCompleter() { + return new TypeMapper() { + @Override + public String map(CommandSender commandSender, String[] previousArguments, String s) { + return s; + } + + @Override + public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { + List list = new ArrayList<>(); + for (ProxiedPlayer player : BungeeCord.getInstance().getPlayers()) { + list.add(player.getName()); + } + if (Event.get() != null) { + EventStarter.getEventServer().keySet().forEach(teamId -> { + Team team = Team.get(teamId); + list.add(team.getTeamName()); + list.add(team.getTeamKuerzel()); + }); + } + return list; + } + }; } public static void teleport(ProxiedPlayer player, ServerInfo server){ From 29945a351bb8ae227053a07b9c815e95125fdab7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 21 Jan 2023 22:17:41 +0100 Subject: [PATCH 03/31] Update EventCommand --- .../bungeecore/commands/EventCommand.java | 75 ++++++++++--------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/EventCommand.java b/src/de/steamwar/bungeecore/commands/EventCommand.java index 75f718f..966ae06 100644 --- a/src/de/steamwar/bungeecore/commands/EventCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventCommand.java @@ -21,54 +21,33 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.sql.*; -import net.md_5.bungee.api.CommandSender; +import de.steamwar.command.SWCommand; +import de.steamwar.command.SWCommandUtils; +import de.steamwar.command.TypeMapper; +import de.steamwar.command.TypeValidator; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.time.Instant; import java.time.format.DateTimeFormatter; +import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; -public class EventCommand extends BasicCommand { +public class EventCommand extends SWCommand { public EventCommand() { - super("event", ""); + super("event"); } - @Override - public void execute(CommandSender sender, String[] args) { - if(!(sender instanceof ProxiedPlayer)) - return; - ProxiedPlayer player = (ProxiedPlayer) sender; - - Event currentEvent = Event.get(); - - if(currentEvent == null) { - noCurrentEvent(player); - return; - } - - if(args.length != 1){ - eventOverview(player, currentEvent); - return; - } - - Team team = Team.get(args[0]); - if(team == null){ - Message.send("EVENT_NO_TEAM", player); - return; - } - - Subserver eventArena = EventStarter.getEventServer().get(team.getTeamId()); - if(eventArena == null || !Subserver.getServerList().contains(eventArena)){ - Message.send("EVENT_NO_FIGHT_TEAM", player); - return; - } - - SubserverSystem.sendPlayer(eventArena, player); + @Validator("noEvent") + public TypeValidator noEventValidator() { + return (sender, value, messageSender) -> Event.get() == null; } - private void noCurrentEvent(ProxiedPlayer player){ + @Register + public void noCurrentEvent(@Validator("noEvent") ProxiedPlayer player){ Message.send("EVENT_NO_CURRENT", player); List coming = Event.getComing(); Instant now = Instant.now(); @@ -99,7 +78,9 @@ public class EventCommand extends BasicCommand { } } - private void eventOverview(ProxiedPlayer player, Event currentEvent){ + @Register + public void eventOverview(@Validator(value = "noEvent", invert = true) ProxiedPlayer player) { + Event currentEvent = Event.get(); Message.send("EVENT_USAGE", player); List fights = EventFight.getEvent(currentEvent.getEventID()); @@ -129,4 +110,26 @@ public class EventCommand extends BasicCommand { BungeeCore.send(player, fline.toString()); } } + + @Register + public void eventWithTeam(@Validator(value = "noEvent", invert = true) ProxiedPlayer player, @ErrorMessage("EVENT_NO_TEAM") Team team) { + Subserver eventArena = EventStarter.getEventServer().get(team.getTeamId()); + if(eventArena == null || !Subserver.getServerList().contains(eventArena)){ + Message.send("EVENT_NO_FIGHT_TEAM", player); + return; + } + SubserverSystem.sendPlayer(eventArena, player); + } + + @ClassMapper(Team.class) + @Cached(cacheDuration = 10, global = true) + public TypeMapper teamMapper() { + return SWCommandUtils.createMapper(Team::get, s -> EventStarter.getEventServer() + .keySet() + .stream() + .map(Team::get) + .map(t -> Arrays.asList(t.getTeamKuerzel(), t.getTeamColor())) + .flatMap(Collection::stream) + .collect(Collectors.toList())); + } } From 647702c0b0a29593de866c0a2e480f8279b01fd4 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 21 Jan 2023 22:22:55 +0100 Subject: [PATCH 04/31] Update JoinmeCommand --- .../bungeecore/commands/JoinmeCommand.java | 98 ++++++++----------- 1 file changed, 41 insertions(+), 57 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java index e897ba0..7f966fd 100644 --- a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java +++ b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java @@ -21,77 +21,61 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.sql.BauweltMember; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.ProxyServer; +import de.steamwar.command.SWCommand; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; -import java.util.ArrayList; - -public class JoinmeCommand extends BasicCommand { +public class JoinmeCommand extends SWCommand { public JoinmeCommand() { - super("joinme", ""); + super("joinme"); } - @Override - public void execute(CommandSender sender, String[] args) { - if(sender instanceof ProxiedPlayer) { - ProxiedPlayer player = (ProxiedPlayer) sender; + @Register(description = "JOINME_USAGE") + public void genericCommand(ProxiedPlayer player) { + if (!player.hasPermission("bungeecore.joinme")) return; + Message.broadcast("JOINME_BROADCAST", "JOINME_BROADCAST_HOVER", + new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()), player.getName(), player.getServer().getInfo().getName()); + } - if (args.length == 0 && player.hasPermission("bungeecore.joinme")) { - Message.broadcast("JOINME_BROADCAST", "JOINME_BROADCAST_HOVER" - , new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()), player.getName(), player.getServer().getInfo().getName()); - } else if (args.length == 1) { - ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]); - if(target == null || !target.isConnected()){ - Message.send("JOINME_PLAYER_OFFLINE", player); - return; - }else if(target.equals(player)){ - Message.send("JOINME_PLAYER_SELF", player); - return; - } - ServerInfo server = target.getServer().getInfo(); - String serverPerm = BungeeCore.serverPermissions.get(server.getName()); - Subserver subserver = Subserver.getSubserver(target); + @Register + public void genericCommand(ProxiedPlayer player, ProxiedPlayer target) { + if(target == null || !target.isConnected()){ + Message.send("JOINME_PLAYER_OFFLINE", player); + return; + }else if(target.equals(player)){ + Message.send("JOINME_PLAYER_SELF", player); + return; + } + ServerInfo server = target.getServer().getInfo(); + String serverPerm = BungeeCore.serverPermissions.get(server.getName()); + Subserver subserver = Subserver.getSubserver(target); - if(subserver != null) { - Servertype type = subserver.getType(); - if (type == Servertype.ARENA) { - SubserverSystem.sendPlayer(subserver, player); - } else if (type == Servertype.BAUSERVER) { - Bauserver bauserver = (Bauserver) subserver; - if (bauserver.getOwner().equals(player.getUniqueId()) || - BauweltMember.getBauMember(bauserver.getOwner(), player.getUniqueId()) != null) { - SubserverSystem.sendPlayer(subserver, player); - } else { - SubserverSystem.sendDeniedMessage(player, bauserver.getOwner()); - Message.send("JOIN_PLAYER_BLOCK", player); - } - } else if(type == Servertype.BUILDER && !player.hasPermission("bungeecore.server.team")) { - Message.send("JOIN_PLAYER_BLOCK", player); - } else { - SubserverSystem.sendPlayer(subserver, player); - } - }else if(serverPerm != null && !player.hasPermission(serverPerm)){ + if(subserver != null) { + Servertype type = subserver.getType(); + if (type == Servertype.ARENA) { + SubserverSystem.sendPlayer(subserver, player); + } else if (type == Servertype.BAUSERVER) { + Bauserver bauserver = (Bauserver) subserver; + if (bauserver.getOwner().equals(player.getUniqueId()) || + BauweltMember.getBauMember(bauserver.getOwner(), player.getUniqueId()) != null) { + SubserverSystem.sendPlayer(subserver, player); + } else { + SubserverSystem.sendDeniedMessage(player, bauserver.getOwner()); Message.send("JOIN_PLAYER_BLOCK", player); - }else if(serverPerm == null && !player.getGroups().contains("team")) { - Message.send("JOIN_PLAYER_BLOCK", player); - }else{ - player.connect(server); } + } else if(type == Servertype.BUILDER && !player.hasPermission("bungeecore.server.team")) { + Message.send("JOIN_PLAYER_BLOCK", player); } else { - Message.send("JOINME_USAGE", player); + SubserverSystem.sendPlayer(subserver, player); } + }else if(serverPerm != null && !player.hasPermission(serverPerm)){ + Message.send("JOIN_PLAYER_BLOCK", player); + }else if(serverPerm == null && !player.getGroups().contains("team")) { + Message.send("JOIN_PLAYER_BLOCK", player); + }else{ + player.connect(server); } } - - @Override - public Iterable onTabComplete(CommandSender commandSender, String[] args) { - if(args.length == 1){ - return allPlayers(args[0]); - } - return new ArrayList<>(); - } } From a15cf2c94e639e1ef09a73d6516bcf9da33885b6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 21 Jan 2023 22:28:46 +0100 Subject: [PATCH 05/31] Update JoinmeCommand --- .../bungeecore/commands/JoinmeCommand.java | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java index 7f966fd..953655d 100644 --- a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java +++ b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java @@ -21,11 +21,18 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.sql.BauweltMember; +import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeMapper; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; +import java.util.Collection; +import java.util.stream.Collectors; + public class JoinmeCommand extends SWCommand { public JoinmeCommand() { @@ -40,11 +47,8 @@ public class JoinmeCommand extends SWCommand { } @Register - public void genericCommand(ProxiedPlayer player, ProxiedPlayer target) { - if(target == null || !target.isConnected()){ - Message.send("JOINME_PLAYER_OFFLINE", player); - return; - }else if(target.equals(player)){ + public void genericCommand(ProxiedPlayer player, @Validator ProxiedPlayer target) { + if (target.equals(player)){ Message.send("JOINME_PLAYER_SELF", player); return; } @@ -78,4 +82,28 @@ public class JoinmeCommand extends SWCommand { player.connect(server); } } + + @ClassMapper(ProxiedPlayer.class) + public TypeMapper playerMapper() { + return new TypeMapper() { + @Override + public ProxiedPlayer map(CommandSender commandSender, String[] previousArguments, String s) { + return ProxyServer.getInstance().getPlayer(s); + } + + @Override + public boolean validate(CommandSender sender, ProxiedPlayer value, MessageSender messageSender) { + if (value == null || !value.isConnected()) { + messageSender.send("JOINME_PLAYER_OFFLINE", sender); + return false; + } + return true; + } + + @Override + public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { + return ProxyServer.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()); + } + }; + } } From be5833c0d0a0effb028a0d91c59ffd679881548d Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 23 Jan 2023 16:30:35 +0100 Subject: [PATCH 06/31] WIP CommonDB 2 Signed-off-by: Lixfel --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index d12fbbd..e2654e7 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit d12fbbd339f6f34108301aa08d1377eceea250a5 +Subproject commit e2654e72bf99334682d2e09f3e9b204595c40e8a From 9c73ce868dc9c9577b80f3ef5c14c2e20182f6da Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 23 Jan 2023 16:31:13 +0100 Subject: [PATCH 07/31] WIP CommonDB 2 Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/ErrorLogger.java | 4 +- src/de/steamwar/bungeecore/EventStarter.java | 2 +- src/de/steamwar/bungeecore/ServerStarter.java | 4 +- .../bungeecore/bot/SteamwarDiscordBot.java | 2 +- .../bot/commands/BasicDiscordCommand.java | 2 +- .../bungeecore/bot/commands/TeamCommand.java | 4 +- .../bot/config/SteamwarDiscordBotConfig.java | 2 +- .../bungeecore/bot/events/EventManager.java | 4 +- .../bot/listeners/DiscordEventListener.java | 4 +- .../bungeecore/commands/BauCommand.java | 2 + .../bungeecore/commands/BugCommand.java | 4 +- .../bungeecore/commands/EventCommand.java | 6 +- .../commands/EventRescheduleCommand.java | 2 +- .../bungeecore/commands/PollCommand.java | 2 +- .../commands/PollresultCommand.java | 10 +- .../bungeecore/commands/ReplayCommand.java | 1 - .../bungeecore/commands/TeamCommand.java | 6 +- .../bungeecore/commands/TpCommand.java | 7 +- .../bungeecore/commands/TutorialCommand.java | 23 +-- .../bungeecore/commands/WhoisCommand.java | 1 + .../bungeecore/listeners/BanListener.java | 2 +- .../bungeecore/listeners/ChatListener.java | 1 + .../listeners/ConnectionListener.java | 2 +- .../listeners/EventModeListener.java | 4 +- .../bungeecore/listeners/PollSystem.java | 8 +- .../bungeecore/listeners/SessionManager.java | 2 +- .../bungeecore/listeners/mods/Fabric.java | 4 +- .../bungeecore/listeners/mods/Utils.java | 2 +- .../bungeecore/network/NetworkReceiver.java | 4 +- .../bungeecore/sql/BannedUserIPs.java | 77 ---------- src/de/steamwar/bungeecore/sql/BauLock.java | 52 ------- .../steamwar/bungeecore/sql/BauLockState.java | 27 ---- src/de/steamwar/bungeecore/sql/Event.java | 133 ------------------ src/de/steamwar/bungeecore/sql/Fight.java | 34 ++++- .../steamwar/bungeecore/sql/FightPlayer.java | 56 -------- .../steamwar/bungeecore/sql/PollAnswer.java | 75 ---------- .../steamwar/bungeecore/sql/SWException.java | 32 ----- src/de/steamwar/bungeecore/sql/SchemElo.java | 2 + src/de/steamwar/bungeecore/sql/Season.java | 54 ------- src/de/steamwar/bungeecore/sql/Session.java | 35 ----- .../steamwar/bungeecore/sql/SteamwarUser.java | 6 +- src/de/steamwar/bungeecore/sql/Team.java | 1 + .../bungeecore/sql/TeamTeilnahme.java | 71 ---------- src/de/steamwar/bungeecore/sql/Tutorial.java | 72 ++++------ .../steamwar/bungeecore/sql/UserConfig.java | 48 ------- src/de/steamwar/bungeecore/sql/UserElo.java | 3 +- src/de/steamwar/bungeecore/sql/UserGroup.java | 84 ----------- .../bungeecore/tablist/TablistPart.java | 2 +- src/de/steamwar/bungeecore/util/BauLock.java | 54 +++++++ .../bungeecore/util/BauLockState.java | 27 ++++ 50 files changed, 216 insertions(+), 850 deletions(-) delete mode 100644 src/de/steamwar/bungeecore/sql/BannedUserIPs.java delete mode 100644 src/de/steamwar/bungeecore/sql/BauLock.java delete mode 100644 src/de/steamwar/bungeecore/sql/BauLockState.java delete mode 100644 src/de/steamwar/bungeecore/sql/Event.java delete mode 100644 src/de/steamwar/bungeecore/sql/FightPlayer.java delete mode 100644 src/de/steamwar/bungeecore/sql/PollAnswer.java delete mode 100644 src/de/steamwar/bungeecore/sql/SWException.java delete mode 100644 src/de/steamwar/bungeecore/sql/Season.java delete mode 100644 src/de/steamwar/bungeecore/sql/Session.java delete mode 100644 src/de/steamwar/bungeecore/sql/TeamTeilnahme.java delete mode 100644 src/de/steamwar/bungeecore/sql/UserConfig.java delete mode 100644 src/de/steamwar/bungeecore/sql/UserGroup.java create mode 100644 src/de/steamwar/bungeecore/util/BauLock.java create mode 100644 src/de/steamwar/bungeecore/util/BauLockState.java diff --git a/src/de/steamwar/bungeecore/ErrorLogger.java b/src/de/steamwar/bungeecore/ErrorLogger.java index d1af128..279a627 100644 --- a/src/de/steamwar/bungeecore/ErrorLogger.java +++ b/src/de/steamwar/bungeecore/ErrorLogger.java @@ -19,7 +19,7 @@ package de.steamwar.bungeecore; -import de.steamwar.bungeecore.sql.SWException; +import de.steamwar.sql.SWException; import java.io.ByteArrayOutputStream; import java.io.PrintStream; @@ -61,7 +61,7 @@ public class ErrorLogger extends Handler { } - SWException.log("Bungee", message, stacktrace); + SWException.log(message, stacktrace); } @Override diff --git a/src/de/steamwar/bungeecore/EventStarter.java b/src/de/steamwar/bungeecore/EventStarter.java index 0de5667..7113e5d 100644 --- a/src/de/steamwar/bungeecore/EventStarter.java +++ b/src/de/steamwar/bungeecore/EventStarter.java @@ -19,10 +19,10 @@ package de.steamwar.bungeecore; -import de.steamwar.bungeecore.sql.Event; import de.steamwar.bungeecore.sql.EventFight; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.Team; +import de.steamwar.sql.Event; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; diff --git a/src/de/steamwar/bungeecore/ServerStarter.java b/src/de/steamwar/bungeecore/ServerStarter.java index 9373b57..f3b805a 100644 --- a/src/de/steamwar/bungeecore/ServerStarter.java +++ b/src/de/steamwar/bungeecore/ServerStarter.java @@ -144,8 +144,8 @@ public class ServerStarter { public ServerStarter tutorial(ProxiedPlayer owner, Tutorial tutorial) { directory = new File(SERVER_PATH, "Tutorial"); buildWithTemp(owner); - tempWorld(TUTORIAL_PATH + tutorial.id()); - arguments.put("tutorial", String.valueOf(tutorial.id())); + tempWorld(TUTORIAL_PATH + tutorial.getId()); + arguments.put("tutorial", String.valueOf(tutorial.getId())); return send(owner); } diff --git a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java b/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java index 3811c18..759edcc 100644 --- a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java +++ b/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java @@ -28,8 +28,8 @@ import de.steamwar.bungeecore.bot.listeners.*; import de.steamwar.bungeecore.bot.util.DiscordRolesMessage; import de.steamwar.bungeecore.bot.util.DiscordRulesMessage; import de.steamwar.bungeecore.bot.util.DiscordTicketMessage; -import de.steamwar.bungeecore.sql.Event; import de.steamwar.messages.ChatSender; +import de.steamwar.sql.Event; import lombok.Getter; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; diff --git a/src/de/steamwar/bungeecore/bot/commands/BasicDiscordCommand.java b/src/de/steamwar/bungeecore/bot/commands/BasicDiscordCommand.java index 29bbe85..00ec1b8 100644 --- a/src/de/steamwar/bungeecore/bot/commands/BasicDiscordCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/BasicDiscordCommand.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.bot.commands; import de.steamwar.bungeecore.sql.SteamwarUser; -import de.steamwar.bungeecore.sql.UserGroup; +import de.steamwar.sql.UserGroup; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.build.CommandData; diff --git a/src/de/steamwar/bungeecore/bot/commands/TeamCommand.java b/src/de/steamwar/bungeecore/bot/commands/TeamCommand.java index e0b3545..c6448eb 100644 --- a/src/de/steamwar/bungeecore/bot/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/TeamCommand.java @@ -19,10 +19,10 @@ package de.steamwar.bungeecore.bot.commands; -import de.steamwar.bungeecore.sql.Event; +import de.steamwar.sql.Event; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.Team; -import de.steamwar.bungeecore.sql.TeamTeilnahme; +import de.steamwar.sql.TeamTeilnahme; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Emoji; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; diff --git a/src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java b/src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java index 34c65e8..844d1e2 100644 --- a/src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java +++ b/src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java @@ -19,7 +19,7 @@ package de.steamwar.bungeecore.bot.config; -import de.steamwar.bungeecore.sql.UserGroup; +import de.steamwar.sql.UserGroup; import net.md_5.bungee.config.Configuration; import java.util.ArrayList; diff --git a/src/de/steamwar/bungeecore/bot/events/EventManager.java b/src/de/steamwar/bungeecore/bot/events/EventManager.java index 79ef2e3..cd57767 100644 --- a/src/de/steamwar/bungeecore/bot/events/EventManager.java +++ b/src/de/steamwar/bungeecore/bot/events/EventManager.java @@ -21,10 +21,10 @@ package de.steamwar.bungeecore.bot.events; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; -import de.steamwar.bungeecore.sql.Event; import de.steamwar.bungeecore.sql.EventFight; import de.steamwar.bungeecore.sql.Team; -import de.steamwar.bungeecore.sql.TeamTeilnahme; +import de.steamwar.sql.TeamTeilnahme; +import de.steamwar.sql.Event; import lombok.experimental.UtilityClass; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.MessageBuilder; diff --git a/src/de/steamwar/bungeecore/bot/listeners/DiscordEventListener.java b/src/de/steamwar/bungeecore/bot/listeners/DiscordEventListener.java index a08f74d..33054ee 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/DiscordEventListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/DiscordEventListener.java @@ -21,10 +21,10 @@ package de.steamwar.bungeecore.bot.listeners; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.bot.events.EventManager; -import de.steamwar.bungeecore.sql.Event; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.Team; -import de.steamwar.bungeecore.sql.TeamTeilnahme; +import de.steamwar.sql.TeamTeilnahme; +import de.steamwar.sql.Event; import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent; import net.dv8tion.jda.api.interactions.components.Component; import org.jetbrains.annotations.NotNull; diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 06dc3bc..9740cc7 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -24,12 +24,14 @@ import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.bungeecore.network.NetworkSender; import de.steamwar.bungeecore.sql.*; +import de.steamwar.bungeecore.util.BauLock; import de.steamwar.bungeecore.util.Chat19; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; import de.steamwar.messages.ChatSender; import de.steamwar.network.packets.server.BaumemberUpdatePacket; +import de.steamwar.bungeecore.util.BauLockState; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; diff --git a/src/de/steamwar/bungeecore/commands/BugCommand.java b/src/de/steamwar/bungeecore/commands/BugCommand.java index 9648423..b3e5990 100644 --- a/src/de/steamwar/bungeecore/commands/BugCommand.java +++ b/src/de/steamwar/bungeecore/commands/BugCommand.java @@ -19,7 +19,7 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.sql.SWException; +import de.steamwar.sql.SWException; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.command.SWCommand; import de.steamwar.messages.ChatSender; @@ -34,7 +34,7 @@ public class BugCommand extends SWCommand { public void bugMessage(ProxiedPlayer player, String... message) { String server = player.getServer().getInfo().getName(); SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - SWException.log(server, String.join(" ", message), player.getName() + " " + user.getId()); + SWException.log(String.join(" ", message), server + " " + player.getName() + " " + user.getId()); ChatSender.of(player).system("BUG_MESSAGE"); } } diff --git a/src/de/steamwar/bungeecore/commands/EventCommand.java b/src/de/steamwar/bungeecore/commands/EventCommand.java index 75f718f..e106d59 100644 --- a/src/de/steamwar/bungeecore/commands/EventCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventCommand.java @@ -20,7 +20,11 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; -import de.steamwar.bungeecore.sql.*; +import de.steamwar.bungeecore.sql.EventFight; +import de.steamwar.bungeecore.sql.SchematicType; +import de.steamwar.bungeecore.sql.Team; +import de.steamwar.sql.TeamTeilnahme; +import de.steamwar.sql.Event; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; diff --git a/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java b/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java index 4a95e46..e44a318 100644 --- a/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java @@ -20,11 +20,11 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.sql.Event; import de.steamwar.bungeecore.sql.EventFight; import de.steamwar.bungeecore.sql.Team; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; +import de.steamwar.sql.Event; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; diff --git a/src/de/steamwar/bungeecore/commands/PollCommand.java b/src/de/steamwar/bungeecore/commands/PollCommand.java index 5e179cd..4e3a3bd 100644 --- a/src/de/steamwar/bungeecore/commands/PollCommand.java +++ b/src/de/steamwar/bungeecore/commands/PollCommand.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.listeners.PollSystem; -import de.steamwar.bungeecore.sql.PollAnswer; +import de.steamwar.sql.PollAnswer; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; diff --git a/src/de/steamwar/bungeecore/commands/PollresultCommand.java b/src/de/steamwar/bungeecore/commands/PollresultCommand.java index 554efcc..4951771 100644 --- a/src/de/steamwar/bungeecore/commands/PollresultCommand.java +++ b/src/de/steamwar/bungeecore/commands/PollresultCommand.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.listeners.PollSystem; -import de.steamwar.bungeecore.sql.PollAnswer; +import de.steamwar.sql.PollAnswer; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -36,10 +36,10 @@ public class PollresultCommand extends SWCommand { @Register public void genericCommand(@Validator ProxiedPlayer player) { - Map voted = PollAnswer.getCurrentResults(); - Message.send("POLLRESULT_HEADER", player, voted.values().stream().reduce(Integer::sum).orElse(0), PollSystem.getQuestion()); - for (Map.Entry e: voted.entrySet()) { - Message.send("POLLRESULT_LIST", player, e.getKey(), e.getValue()); + Map voted = PollAnswer.getCurrentResults(); + Message.send("POLLRESULT_HEADER", player, voted.values().stream().reduce(Integer::sum).orElse(0), PollAnswer.getCurrentPoll()); + for (Map.Entry e: voted.entrySet()) { + Message.send("POLLRESULT_LIST", player, PollSystem.getAnswer(e.getKey()), e.getValue()); } } diff --git a/src/de/steamwar/bungeecore/commands/ReplayCommand.java b/src/de/steamwar/bungeecore/commands/ReplayCommand.java index 1130108..ff012b9 100644 --- a/src/de/steamwar/bungeecore/commands/ReplayCommand.java +++ b/src/de/steamwar/bungeecore/commands/ReplayCommand.java @@ -29,7 +29,6 @@ import de.steamwar.bungeecore.sql.SchematicType; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.command.SWCommand; import de.steamwar.messages.ChatSender; -import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.ArrayList; diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index 9ae3799..3f45be6 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -23,8 +23,12 @@ import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Storage; import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.bungeecore.inventory.SWListInv; -import de.steamwar.bungeecore.sql.*; +import de.steamwar.bungeecore.sql.Punishment; +import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.bungeecore.sql.Team; +import de.steamwar.sql.TeamTeilnahme; import de.steamwar.messages.ChatSender; +import de.steamwar.sql.Event; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; diff --git a/src/de/steamwar/bungeecore/commands/TpCommand.java b/src/de/steamwar/bungeecore/commands/TpCommand.java index de61885..7025b10 100644 --- a/src/de/steamwar/bungeecore/commands/TpCommand.java +++ b/src/de/steamwar/bungeecore/commands/TpCommand.java @@ -20,9 +20,14 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; -import de.steamwar.bungeecore.sql.*; +import de.steamwar.bungeecore.sql.BauweltMember; +import de.steamwar.bungeecore.sql.Punishment; +import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.bungeecore.sql.Team; +import de.steamwar.bungeecore.util.BauLock; import de.steamwar.bungeecore.util.Chat19; import de.steamwar.messages.ChatSender; +import de.steamwar.sql.Event; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; diff --git a/src/de/steamwar/bungeecore/commands/TutorialCommand.java b/src/de/steamwar/bungeecore/commands/TutorialCommand.java index d0ff147..c9dc9d7 100644 --- a/src/de/steamwar/bungeecore/commands/TutorialCommand.java +++ b/src/de/steamwar/bungeecore/commands/TutorialCommand.java @@ -96,36 +96,37 @@ public class TutorialCommand extends SWCommand { player, Message.parse("TUTORIAL_TITLE", player), (click, tutorial) -> { - if(!released && click.isShiftClick() && user.getUserGroup().isTeamGroup() && user != tutorial.creator()) { + if(!released && click.isShiftClick() && user.getUserGroup().isTeamGroup() && user.getId() != tutorial.getCreator()) { tutorial.release(); openInventory(player, released, own); return; } else if(own && click.isShiftClick() && click.isRightClick()) { tutorial.delete(); + SubserverSystem.deleteFolder(BungeeCore.local, world(tutorial).getPath()); openInventory(player, released, own); return; } new ServerStarter().tutorial(player, tutorial).start(); }, - page -> (own ? Tutorial.getOwn(user, page, 45) : Tutorial.getPage(page, 45, released)).stream().map(tutorial -> new SWListInv.SWListEntry<>(getTutorialItem(player, tutorial, own), tutorial)).collect(Collectors.toList()) + page -> (own ? Tutorial.getOwn(user.getId(), page, 45) : Tutorial.getPage(page, 45, released)).stream().map(tutorial -> new SWListInv.SWListEntry<>(getTutorialItem(player, tutorial, own), tutorial)).collect(Collectors.toList()) ).open(); } private SWItem getTutorialItem(ProxiedPlayer player, Tutorial tutorial, boolean personalHighlights) { - SWItem item = new SWItem(tutorial.item(), Message.parse("TUTORIAL_NAME", player, tutorial.name())); + SWItem item = new SWItem(tutorial.getItem(), Message.parse("TUTORIAL_NAME", player, tutorial.getName())); item.setHideAttributes(true); List lore = new ArrayList<>(); - lore.add(Message.parse("TUTORIAL_BY", player, tutorial.creator().getUserName())); - lore.add(Message.parse("TUTORIAL_STARS", player, String.format("%.1f", tutorial.stars()))); + lore.add(Message.parse("TUTORIAL_BY", player, SteamwarUser.get(tutorial.getCreator()).getUserName())); + lore.add(Message.parse("TUTORIAL_STARS", player, String.format("%.1f", tutorial.getStars()))); if (personalHighlights) lore.add(Message.parse("TUTORIAL_DELETE", player)); item.setLore(lore); - if (personalHighlights && tutorial.released()) + if (personalHighlights && tutorial.isReleased()) item.setEnchanted(true); return item; @@ -136,7 +137,7 @@ public class TutorialCommand extends SWCommand { int[] rates = new int[]{1, 2, 3, 4, 5}; new SWListInv<>(player, Message.parse("TUTORIAL_RATE_TITLE", player), Arrays.stream(rates).mapToObj(rate -> new SWListInv.SWListEntry<>(new SWItem("NETHER_STAR", Message.parse("TUTORIAL_RATE", player, rate)), rate)).collect(Collectors.toList()), (click, rate) -> { - tutorial.rate(user, rate); + tutorial.rate(user.getId(), rate); SWInventory.close(player); }).open(); } @@ -153,8 +154,8 @@ public class TutorialCommand extends SWCommand { subserver.execute("save-all"); ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { - Tutorial tutorial = Tutorial.create(user, name, item); - File tutorialWorld = tutorial.world(); + Tutorial tutorial = Tutorial.create(user.getId(), name, item); + File tutorialWorld = world(tutorial); if (tutorialWorld.exists()) SubserverSystem.deleteFolder(BungeeCore.local, tutorialWorld.getPath()); @@ -162,4 +163,8 @@ public class TutorialCommand extends SWCommand { Message.send("TUTORIAL_CREATED", player); }, 1, TimeUnit.SECONDS); } + + private File world(Tutorial tutorial) { + return new File(ServerStarter.TUTORIAL_PATH, String.valueOf(tutorial.getId())); + } } diff --git a/src/de/steamwar/bungeecore/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/commands/WhoisCommand.java index 1b80d75..095f0fc 100644 --- a/src/de/steamwar/bungeecore/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/commands/WhoisCommand.java @@ -26,6 +26,7 @@ import de.steamwar.bungeecore.sql.*; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; +import de.steamwar.sql.UserGroup; import lombok.Getter; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.CommandSender; diff --git a/src/de/steamwar/bungeecore/listeners/BanListener.java b/src/de/steamwar/bungeecore/listeners/BanListener.java index a868ba3..f5b31bb 100644 --- a/src/de/steamwar/bungeecore/listeners/BanListener.java +++ b/src/de/steamwar/bungeecore/listeners/BanListener.java @@ -22,7 +22,7 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.listeners.mods.Forge; -import de.steamwar.bungeecore.sql.BannedUserIPs; +import de.steamwar.sql.BannedUserIPs; import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.messages.ChatSender; diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index 827fe3e..68e86f7 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -26,6 +26,7 @@ import de.steamwar.bungeecore.sql.*; import de.steamwar.bungeecore.util.Chat19; import de.steamwar.messages.ChatSender; import de.steamwar.network.packets.server.PingPacket; +import de.steamwar.sql.UserGroup; import net.md_5.bungee.api.*; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.ChatEvent; diff --git a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java index 5256709..a5123d3 100644 --- a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java +++ b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java @@ -30,7 +30,7 @@ import de.steamwar.bungeecore.commands.CheckCommand; import de.steamwar.bungeecore.commands.MsgCommand; import de.steamwar.bungeecore.listeners.mods.Utils; import de.steamwar.bungeecore.sql.SteamwarUser; -import de.steamwar.bungeecore.sql.UserGroup; +import de.steamwar.sql.UserGroup; import net.md_5.bungee.api.AbstractReconnectHandler; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; diff --git a/src/de/steamwar/bungeecore/listeners/EventModeListener.java b/src/de/steamwar/bungeecore/listeners/EventModeListener.java index 852703c..48d498f 100644 --- a/src/de/steamwar/bungeecore/listeners/EventModeListener.java +++ b/src/de/steamwar/bungeecore/listeners/EventModeListener.java @@ -1,10 +1,10 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.sql.Event; import de.steamwar.bungeecore.sql.EventFight; import de.steamwar.bungeecore.sql.SteamwarUser; -import de.steamwar.bungeecore.sql.TeamTeilnahme; +import de.steamwar.sql.TeamTeilnahme; +import de.steamwar.sql.Event; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.event.PostLoginEvent; import net.md_5.bungee.event.EventHandler; diff --git a/src/de/steamwar/bungeecore/listeners/PollSystem.java b/src/de/steamwar/bungeecore/listeners/PollSystem.java index 85ca553..69a4fb3 100644 --- a/src/de/steamwar/bungeecore/listeners/PollSystem.java +++ b/src/de/steamwar/bungeecore/listeners/PollSystem.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.sql.PollAnswer; +import de.steamwar.sql.PollAnswer; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -40,6 +40,8 @@ public class PollSystem extends BasicListener { if(noCurrentPoll()) return; + + PollAnswer.setCurrentPoll(question); new PollSystem(); } @@ -70,10 +72,6 @@ public class PollSystem extends BasicListener { return question == null || question.equals(""); } - public static String getQuestion() { - return question; - } - public static int answers(){ return answers.size(); } diff --git a/src/de/steamwar/bungeecore/listeners/SessionManager.java b/src/de/steamwar/bungeecore/listeners/SessionManager.java index aa3e5c8..dcc8d96 100644 --- a/src/de/steamwar/bungeecore/listeners/SessionManager.java +++ b/src/de/steamwar/bungeecore/listeners/SessionManager.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.sql.Session; +import de.steamwar.sql.Session; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.event.PlayerDisconnectEvent; diff --git a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java index 440ab12..318bdd9 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java @@ -28,7 +28,7 @@ import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Storage; import de.steamwar.bungeecore.listeners.BasicListener; import de.steamwar.bungeecore.sql.Mod; -import de.steamwar.bungeecore.sql.SWException; +import de.steamwar.sql.SWException; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -158,7 +158,7 @@ public class Fabric extends BasicListener { } public void logMessage(SteamwarUser user, String reason, String data) { - SWException.log("Bungee", "FabricModSender " + user.getUserName() + ": " + reason, data); + SWException.log("FabricModSender " + user.getUserName() + ": " + reason, data); } public static void remove(ProxiedPlayer player) { diff --git a/src/de/steamwar/bungeecore/listeners/mods/Utils.java b/src/de/steamwar/bungeecore/listeners/mods/Utils.java index db569c1..d4739c6 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Utils.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Utils.java @@ -68,7 +68,7 @@ public class Utils { static boolean handleMods(UUID uuid, Locale locale, Consumer disconnect, List mods){ SteamwarUser user = SteamwarUser.get(uuid); - boolean privileged = user.getUserGroup().privilegedMods(); + boolean privileged = user.getUserGroup().isPrivilegedMods(); playerModMap.put(uuid,new ArrayList<>(mods)); ModType max = ModType.YELLOW; diff --git a/src/de/steamwar/bungeecore/network/NetworkReceiver.java b/src/de/steamwar/bungeecore/network/NetworkReceiver.java index f01bf44..f1fcd5a 100644 --- a/src/de/steamwar/bungeecore/network/NetworkReceiver.java +++ b/src/de/steamwar/bungeecore/network/NetworkReceiver.java @@ -22,7 +22,7 @@ package de.steamwar.bungeecore.network; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.commands.TeamCommand; import de.steamwar.bungeecore.listeners.BasicListener; -import de.steamwar.bungeecore.sql.SWException; +import de.steamwar.sql.SWException; import de.steamwar.network.packets.NetworkPacket; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.Server; @@ -42,7 +42,7 @@ public class NetworkReceiver extends BasicListener { @EventHandler(priority = EventPriority.HIGHEST) public void onPluginMessage(PluginMessageEvent event) { if (blockedTags.contains(event.getTag()) && !TeamCommand.isLocalhost(((InetSocketAddress) event.getSender().getSocketAddress()).getAddress())) { - SWException.log("Bungee", ((InetSocketAddress) event.getSender().getSocketAddress()).getHostString() + " tried to send a plugin message with tag " + event.getTag(), Base64.getEncoder().encodeToString(event.getData())); + SWException.log(((InetSocketAddress) event.getSender().getSocketAddress()).getHostString() + " tried to send a plugin message with tag " + event.getTag(), Base64.getEncoder().encodeToString(event.getData())); event.setCancelled(true); return; } diff --git a/src/de/steamwar/bungeecore/sql/BannedUserIPs.java b/src/de/steamwar/bungeecore/sql/BannedUserIPs.java deleted file mode 100644 index 3d77919..0000000 --- a/src/de/steamwar/bungeecore/sql/BannedUserIPs.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.sql.internal.Statement; - -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.List; - -public class BannedUserIPs { - - private static final Statement getByID = new Statement("SELECT * FROM BannedUserIPs WHERE UserID = ? ORDER BY Timestamp ASC"); - private static final Statement getByIP = new Statement("SELECT * FROM BannedUserIPs WHERE IP = ? ORDER BY Timestamp DESC"); - private static final Statement banIP = new Statement("INSERT INTO BannedUserIPs (UserID, Timestamp, IP) VALUES (?, NOW(), ?) ON DUPLICATE KEY UPDATE Timestamp=NOW()"); - - private final int userID; - private final Timestamp timestamp; - - private BannedUserIPs(int userID, Timestamp timestamp){ - this.userID = userID; - this.timestamp = timestamp; - } - - public static List get(int userID){ - return getByID.select(rs -> { - List userIPs = new ArrayList<>(); - while(rs.next()) { - userIPs.add(new BannedUserIPs( - userID, - rs.getTimestamp("Timestamp"))); - } - return userIPs; - }, userID); - } - - public static List get(String ip){ - return getByIP.select(rs -> { - List userIDs = new ArrayList<>(); - while(rs.next()) { - userIDs.add(new BannedUserIPs( - rs.getInt("UserID"), - rs.getTimestamp("Timestamp"))); - } - return userIDs; - }, ip); - } - - static void banIP(SteamwarUser user, String ip){ - banIP.update(user.getId(), ip); - } - - public int getUserID() { - return userID; - } - - public java.sql.Timestamp getTimestamp() { - return timestamp; - } -} diff --git a/src/de/steamwar/bungeecore/sql/BauLock.java b/src/de/steamwar/bungeecore/sql/BauLock.java deleted file mode 100644 index f69a771..0000000 --- a/src/de/steamwar/bungeecore/sql/BauLock.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.bungeecore.Message; -import lombok.experimental.UtilityClass; -import net.md_5.bungee.api.connection.ProxiedPlayer; - -@UtilityClass -public class BauLock { - - private static final String BAU_LOCK_CONFIG_NAME = "baulockstate"; - public static void setLocked(ProxiedPlayer p, BauLockState state) { - SteamwarUser owner = SteamwarUser.get(p.getUniqueId()); - UserConfig.updateUserConfig(owner.getId(), BAU_LOCK_CONFIG_NAME, state == BauLockState.OPEN ? null : state.name()); - Message.send("BAU_LOCKED_" + state.name(), owner.getPlayer()); - } - - public static boolean isLocked(SteamwarUser owner, SteamwarUser target) { - if (owner.getId() == target.getId()) - return false; - - String state = UserConfig.getConfig(owner.getId(), BAU_LOCK_CONFIG_NAME); - switch (state == null ? BauLockState.OPEN : BauLockState.valueOf(state)) { - case NOBODY: - return true; - case TEAM: - return owner.getTeam() != target.getTeam(); - case OPEN: - default: - return false; - } - } - -} diff --git a/src/de/steamwar/bungeecore/sql/BauLockState.java b/src/de/steamwar/bungeecore/sql/BauLockState.java deleted file mode 100644 index 5d75fc3..0000000 --- a/src/de/steamwar/bungeecore/sql/BauLockState.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2022 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.sql; - -public enum BauLockState { - - NOBODY, // Locks the build server for all users - TEAM, //opens the build server only for every added user which is in the same team as the buildOwner - OPEN //unlocks the build server for all users -} diff --git a/src/de/steamwar/bungeecore/sql/Event.java b/src/de/steamwar/bungeecore/sql/Event.java deleted file mode 100644 index c2ad2ad..0000000 --- a/src/de/steamwar/bungeecore/sql/Event.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.sql.internal.Statement; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.time.Instant; -import java.util.ArrayList; -import java.util.List; - -public class Event { - - private static final Statement byCurrent = new Statement("SELECT * FROM Event WHERE Start < now() AND End > now()"); - private static final Statement byId = new Statement("SELECT * FROM Event WHERE EventID = ?"); - private static final Statement byName = new Statement("SELECT * FROM Event WHERE lower(EventName) = ?"); - private static final Statement byComing = new Statement("SELECT * FROM Event WHERE Start > now()"); - - private final int eventID; - private final String eventName; - private final Timestamp start; - private final Timestamp end; - private final int maximumTeamMembers; - private final boolean publicSchemsOnly; - private final boolean spectateSystem; - private final Timestamp deadline; - private final String schemType; - - private static Event current = null; - - private Event(ResultSet rs) throws SQLException{ - this.eventID = rs.getInt("EventID"); - this.eventName = rs.getString("EventName"); - this.start = rs.getTimestamp("Start"); - this.end = rs.getTimestamp("End"); - this.maximumTeamMembers = rs.getInt("MaximumTeamMembers"); - this.publicSchemsOnly = rs.getBoolean("PublicSchemsOnly"); - this.spectateSystem = rs.getBoolean("SpectateSystem"); - this.deadline = rs.getTimestamp("Deadline"); - this.schemType = rs.getString("SchemType"); - } - - public static Event get(){ - if(current != null && current.now()) - return current; - - return byCurrent.select(rs -> { - if(rs.next()) - current = new Event(rs); - else - current = null; - return current; - }); - } - - public static Event get(int eventID){ - return byId.select(rs -> { - if(!rs.next()) - throw new SQLException("Couldn't find event " + eventID); - return new Event(rs); - }, eventID); - } - - public static Event get(String eventName){ - return byName.select(rs -> { - if(!rs.next()) - return null; - - return new Event(rs); - }, eventName.toLowerCase()); - } - - public static List getComing(){ - return byComing.select(rs -> { - List events = new ArrayList<>(); - while(rs.next()) - events.add(new Event(rs)); - return events; - }); - } - - private boolean now(){ - Instant now = Instant.now(); - return now.isAfter(start.toInstant()) && now.isBefore(end.toInstant()); - } - - public int getEventID() { - return eventID; - } - public String getEventName() { - return eventName; - } - public Timestamp getStart() { - return start; - } - public Timestamp getEnd() { - return end; - } - public int getMaximumTeamMembers() { - return maximumTeamMembers; - } - public boolean publicSchemsOnly() { - return publicSchemsOnly; - } - public boolean spectateSystem(){ - return spectateSystem; - } - public Timestamp getDeadline() { - return deadline; - } - public String getSchemType() { - return schemType; - } -} diff --git a/src/de/steamwar/bungeecore/sql/Fight.java b/src/de/steamwar/bungeecore/sql/Fight.java index 6cde50c..463dee7 100644 --- a/src/de/steamwar/bungeecore/sql/Fight.java +++ b/src/de/steamwar/bungeecore/sql/Fight.java @@ -1,5 +1,25 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package de.steamwar.bungeecore.sql; +import de.steamwar.sql.FightPlayer; import de.steamwar.sql.internal.Statement; import de.steamwar.bungeecore.ArenaMode; @@ -62,17 +82,17 @@ public class Fight { return f; }, page * elementsPerPage, elementsPerPage); - List fightPlayers = FightPlayer.batchGet(fights.stream().map(f -> f.fightID).collect(Collectors.toSet())); + List fightPlayers = FightPlayer.batchGet(fights.stream().map(f -> f.fightID).toArray(Integer[]::new)); for(Fight fight : fights) { fight.initPlayers(fightPlayers); } - SteamwarUser.batchCache(fightPlayers.stream().map(FightPlayer::getUserID).collect(Collectors.toSet())); + de.steamwar.bungeecore.sql.SteamwarUser.batchCache(fightPlayers.stream().map(FightPlayer::getUserID).collect(Collectors.toSet())); return fights; } - public SchematicType getSchemType() { - return SchematicType.fromDB(gameMode); + public de.steamwar.bungeecore.sql.SchematicType getSchemType() { + return de.steamwar.bungeecore.sql.SchematicType.fromDB(gameMode); } public ArenaMode getGameMode() { @@ -90,11 +110,11 @@ public class Fight { return startTime; } - public SteamwarUser getBlueLeader() { - return SteamwarUser.get(blueLeader); + public de.steamwar.bungeecore.sql.SteamwarUser getBlueLeader() { + return de.steamwar.bungeecore.sql.SteamwarUser.get(blueLeader); } - public SteamwarUser getRedLeader() { + public de.steamwar.bungeecore.sql.SteamwarUser getRedLeader() { return SteamwarUser.get(redLeader); } diff --git a/src/de/steamwar/bungeecore/sql/FightPlayer.java b/src/de/steamwar/bungeecore/sql/FightPlayer.java deleted file mode 100644 index 8416cb0..0000000 --- a/src/de/steamwar/bungeecore/sql/FightPlayer.java +++ /dev/null @@ -1,56 +0,0 @@ -package de.steamwar.bungeecore.sql; - -import de.steamwar.sql.internal.Statement; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -public class FightPlayer { - - private final int fightID; - private final int userID; - private final int team; - private final String kit; - private final int kills; - private final boolean isOut; - - private FightPlayer(ResultSet rs) throws SQLException { - fightID = rs.getInt("FightID"); - userID = rs.getInt("UserID"); - team = rs.getInt("Team"); - kit = rs.getString("Kit"); - kills = rs.getInt("Kills"); - isOut = rs.getBoolean("IsOut"); - } - - public static List batchGet(Set fightIds) { - List fightPlayers = new ArrayList<>(); - if(fightIds.isEmpty()) - return fightPlayers; - - try (Statement batch = new Statement("SELECT * FROM FightPlayer WHERE FightID IN (" + fightIds.stream().map(Object::toString).collect(Collectors.joining(", ")) + ")")) { - batch.select(rs -> { - while(rs.next()) - fightPlayers.add(new FightPlayer(rs)); - return null; - }); - } - return fightPlayers; - } - - public int getFightID() { - return fightID; - } - - public int getTeam() { - return team; - } - - public int getUserID() { - return userID; - } -} diff --git a/src/de/steamwar/bungeecore/sql/PollAnswer.java b/src/de/steamwar/bungeecore/sql/PollAnswer.java deleted file mode 100644 index 8f9a64e..0000000 --- a/src/de/steamwar/bungeecore/sql/PollAnswer.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.sql.internal.Statement; -import de.steamwar.bungeecore.listeners.PollSystem; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; - -public class PollAnswer { - - private static final Statement get = new Statement("SELECT * FROM PollAnswer WHERE UserID = ? AND Question = ?"); - private static final Statement getResults = new Statement("SELECT Count(UserID) AS Times, Answer FROM PollAnswer WHERE Question = ? GROUP BY Answer ORDER BY `Times` ASC"); - private static final Statement insert = new Statement("INSERT INTO PollAnswer (UserID, Question, Answer) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Answer = VALUES(Answer)"); - - private final int userID; - private final String question; - private int answer; - - private PollAnswer(ResultSet rs) throws SQLException { - this(rs.getInt("UserID"), rs.getString("Question")); - answer = rs.getInt("Answer"); - } - private PollAnswer(int userID, String question){ - this.userID = userID; - this.question = question; - answer = 0; - } - - public static PollAnswer get(int userID){ - return get.select(rs -> { - if(rs.next()) - return new PollAnswer(rs); - return new PollAnswer(userID, PollSystem.getQuestion()); - }, userID, PollSystem.getQuestion()); - } - - public static Map getCurrentResults() { - return getResults.select(rs -> { - Map retMap = new HashMap<>(); - while (rs.next()) - retMap.put(PollSystem.getAnswer(rs.getInt("Answer")-1), rs.getInt("Times")); - return retMap; - }, PollSystem.getQuestion()); - } - - public boolean hasAnswered(){ - return answer != 0; - } - - public void setAnswer(int answer){ - this.answer = answer; - insert.update(userID, question, answer); - } -} diff --git a/src/de/steamwar/bungeecore/sql/SWException.java b/src/de/steamwar/bungeecore/sql/SWException.java deleted file mode 100644 index 29e127a..0000000 --- a/src/de/steamwar/bungeecore/sql/SWException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.sql.internal.Statement; - -public class SWException { - private SWException(){} - - private static final Statement insert = new Statement("INSERT INTO Exception (server, message, stacktrace) VALUES (?, ?, ?)"); - - public static void log(String server, String message, String stacktrace){ - insert.update(server, message, stacktrace); - } -} diff --git a/src/de/steamwar/bungeecore/sql/SchemElo.java b/src/de/steamwar/bungeecore/sql/SchemElo.java index c5f0a34..8f58e13 100644 --- a/src/de/steamwar/bungeecore/sql/SchemElo.java +++ b/src/de/steamwar/bungeecore/sql/SchemElo.java @@ -19,7 +19,9 @@ package de.steamwar.bungeecore.sql; +import de.steamwar.sql.Season; import de.steamwar.sql.internal.Statement; + import static de.steamwar.bungeecore.sql.UserElo.ELO_DEFAULT; public class SchemElo { diff --git a/src/de/steamwar/bungeecore/sql/Season.java b/src/de/steamwar/bungeecore/sql/Season.java deleted file mode 100644 index 093165f..0000000 --- a/src/de/steamwar/bungeecore/sql/Season.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bungeecore.sql; - -import java.util.Calendar; - -public class Season { - private Season() {} - - public static int getSeason() { - Calendar calendar = Calendar.getInstance(); - int yearIndex = calendar.get(Calendar.MONTH) / 4; - return (calendar.get(Calendar.YEAR) * 3 + yearIndex); - } - - public static String getSeasonStart() { - Calendar calendar = Calendar.getInstance(); - return calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) / 4 * 3 + 1) + "-1"; - } - - public static String convertSeasonToString(int season){ - if (season == -1) return ""; - int yearSeason = season % 3; - int year = (season - yearSeason) / 3; - return String.format("%d-%d", year, yearSeason); - } - - public static int convertSeasonToNumber(String season){ - if (season.isEmpty()) return -1; - String[] split = season.split("-"); - try { - return Integer.parseInt(split[0]) * 3 + Integer.parseInt(split[1]); - } catch (NumberFormatException e) { - return -1; - } - } -} diff --git a/src/de/steamwar/bungeecore/sql/Session.java b/src/de/steamwar/bungeecore/sql/Session.java deleted file mode 100644 index f5eae0d..0000000 --- a/src/de/steamwar/bungeecore/sql/Session.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.sql.internal.Statement; - -import java.sql.Timestamp; - -public class Session { - - private static final Statement insert = new Statement("INSERT INTO Session (UserID, StartTime, EndTime) VALUES (?, ?, NOW())"); - - private Session(){} - - public static void insertSession(int userID, Timestamp startTime){ - insert.update(userID, startTime); - } -} diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index 3fad94e..f42f53e 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -19,7 +19,6 @@ package de.steamwar.bungeecore.sql; -import de.steamwar.sql.internal.Statement; import com.google.gson.JsonParser; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; @@ -28,6 +27,9 @@ import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.bungeecore.network.NetworkSender; import de.steamwar.messages.ChatSender; import de.steamwar.network.packets.server.LocaleInvalidationPacket; +import de.steamwar.sql.BannedUserIPs; +import de.steamwar.sql.UserGroup; +import de.steamwar.sql.internal.Statement; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.PendingConnection; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -350,7 +352,7 @@ public class SteamwarUser { } public void updateBanIP(String ip) { - BannedUserIPs.banIP(this, ip); + BannedUserIPs.banIP(id, ip); } public double getOnlinetime() { diff --git a/src/de/steamwar/bungeecore/sql/Team.java b/src/de/steamwar/bungeecore/sql/Team.java index 83e8e0a..4cb71d8 100644 --- a/src/de/steamwar/bungeecore/sql/Team.java +++ b/src/de/steamwar/bungeecore/sql/Team.java @@ -19,6 +19,7 @@ package de.steamwar.bungeecore.sql; +import de.steamwar.sql.TeamTeilnahme; import de.steamwar.sql.internal.Statement; import java.sql.ResultSet; diff --git a/src/de/steamwar/bungeecore/sql/TeamTeilnahme.java b/src/de/steamwar/bungeecore/sql/TeamTeilnahme.java deleted file mode 100644 index a77f33d..0000000 --- a/src/de/steamwar/bungeecore/sql/TeamTeilnahme.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.sql.internal.Statement; - -import java.sql.ResultSet; -import java.util.HashSet; -import java.util.Set; - -public class TeamTeilnahme { - private TeamTeilnahme(){} - - private static final Statement insert = new Statement("INSERT INTO TeamTeilnahme (TeamID, EventID) VALUES (?, ?)"); - private static final Statement delete = new Statement("DELETE FROM TeamTeilnahme WHERE TeamID = ? AND EventID = ?"); - private static final Statement deleteFuture = new Statement("DELETE t FROM TeamTeilnahme t INNER JOIN Event e ON t.EventID = e.EventID WHERE t.TeamID = ? AND e.Start > NOW()"); - private static final Statement byEventTeam = new Statement("SELECT * FROM TeamTeilnahme WHERE TeamID = ? AND EventID = ?"); - private static final Statement byEvent = new Statement("SELECT * FROM TeamTeilnahme WHERE EventID = ?"); - private static final Statement byTeam = new Statement("SELECT * FROM TeamTeilnahme WHERE TeamID = ?"); - - public static void teilnehmen(int teamID, int eventID){ - insert.update(teamID, eventID); - } - - public static void notTeilnehmen(int teamID, int eventID){ - delete.update(teamID, eventID); - } - - public static boolean nimmtTeil(int teamID, int eventID){ - return byEventTeam.select(ResultSet::next, teamID, eventID); - } - - public static void deleteFuture(int teamID) { - deleteFuture.update(teamID); - } - - public static Set getTeams(int eventID){ - return byEvent.select(rs -> { - Set teams = new HashSet<>(); - while(rs.next()) - teams.add(Team.get(rs.getInt("TeamID"))); - return teams; - }, eventID); - } - - public static Set getEvents(int teamID){ - return byTeam.select(rs -> { - Set events = new HashSet<>(); - while(rs.next()) - events.add(Event.get(rs.getInt("EventID"))); - return events; - }, teamID); - } -} diff --git a/src/de/steamwar/bungeecore/sql/Tutorial.java b/src/de/steamwar/bungeecore/sql/Tutorial.java index 6196ad6..b28b0cd 100644 --- a/src/de/steamwar/bungeecore/sql/Tutorial.java +++ b/src/de/steamwar/bungeecore/sql/Tutorial.java @@ -19,29 +19,31 @@ package de.steamwar.bungeecore.sql; +import de.steamwar.sql.internal.Field; import de.steamwar.sql.internal.Statement; +import de.steamwar.sql.internal.Table; +import lombok.AllArgsConstructor; +import lombok.Getter; -import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.ServerStarter; -import de.steamwar.bungeecore.SubserverSystem; - -import java.io.File; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; +@AllArgsConstructor public class Tutorial { + private static final Table table = new Table<>(Tutorial.class); + private static final Statement release = table.update(Table.PRIMARY, "released"); + private static final Statement delete = table.delete(Table.PRIMARY); + private static final Statement by_popularity = new Statement("SELECT t.*, AVG(r.Stars) AS Stars FROM Tutorial t LEFT OUTER JOIN TutorialRating r ON t.TutorialID = r.TutorialID WHERE t.Released = ? GROUP BY t.TutorialID ORDER BY SUM(r.Stars) DESC LIMIT ?, ?"); private static final Statement own = new Statement("SELECT t.*, AVG(r.Stars) AS Stars FROM Tutorial t LEFT OUTER JOIN TutorialRating r ON t.TutorialID = r.TutorialID WHERE t.Creator = ? GROUP BY t.TutorialID ORDER BY t.TutorialID ASC LIMIT ?, ?"); private static final Statement by_creator_name = new Statement("SELECT t.*, AVG(r.Stars) AS Stars FROM Tutorial t LEFT OUTER JOIN TutorialRating r ON t.TutorialID = r.TutorialID WHERE t.Creator = ? AND t.Name = ? GROUP BY t.TutorialID"); private static final Statement by_id = new Statement("SELECT t.*, AVG(r.Stars) AS Stars FROM Tutorial t LEFT OUTER JOIN TutorialRating r ON t.TutorialID = r.TutorialID WHERE t.TutorialID = ? GROUP BY t.TutorialID"); private static final Statement rate = new Statement("INSERT INTO TutorialRating (TutorialID, UserID, Stars) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Stars = VALUES(Stars)"); private static final Statement create = new Statement("INSERT INTO Tutorial (Creator, Name, Item) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Item = VALUES(Item), Released = 0"); - private static final Statement release = new Statement("UPDATE Tutorial SET Released = 1 WHERE TutorialID = ?"); - private static final Statement delete = new Statement("DELETE FROM Tutorial WHERE TutorialID = ?"); public static List getPage(int page, int elementsPerPage, boolean released) { List tutorials = by_popularity.select(rs -> { @@ -55,21 +57,21 @@ public class Tutorial { return tutorials; } - public static List getOwn(SteamwarUser user, int page, int elementsPerPage) { + public static List getOwn(int user, int page, int elementsPerPage) { return own.select(rs -> { List t = new ArrayList<>(); while(rs.next()) t.add(new Tutorial(rs)); return t; - }, user.getId(), page * elementsPerPage, elementsPerPage); + }, user, page * elementsPerPage, elementsPerPage); } - public static Tutorial create(SteamwarUser creator, String name, String item) { - create.update(creator.getId(), name, item); + public static Tutorial create(int creator, String name, String item) { + create.update(creator, name, item); return by_creator_name.select(rs -> { rs.next(); return new Tutorial(rs); - }, creator.getId(), name); + }, creator, name); } public static Tutorial get(int id) { @@ -80,12 +82,23 @@ public class Tutorial { }, id); } + @Getter + @Field(keys = {Table.PRIMARY}, autoincrement = true) private final int id; + @Getter + @Field(keys = {"CreatorName"}) private final int creator; + @Getter + @Field(keys = {"CreatorName"}) private final String name; + @Getter + @Field(def = "'BOOK'") private final String item; - private final double stars; + @Getter + @Field(def = "0") private final boolean released; + @Getter + private final double stars; public Tutorial(ResultSet rs) throws SQLException { this.id = rs.getInt("TutorialID"); @@ -96,44 +109,15 @@ public class Tutorial { this.stars = rs.getDouble("Stars"); } - public SteamwarUser creator() { - return SteamwarUser.get(creator); - } - - public double stars() { - return stars; - } - - public int id() { - return id; - } - - public String name() { - return name; - } - - public String item() { - return item; - } - - public boolean released() { - return released; - } - public void release() { release.update(id); } public void delete() { delete.update(id); - SubserverSystem.deleteFolder(BungeeCore.local, world().getPath()); } - public File world() { - return new File(ServerStarter.TUTORIAL_PATH, String.valueOf(id)); - } - - public void rate(SteamwarUser user, int rating) { - rate.update(id, user.getId(), rating); + public void rate(int user, int rating) { + rate.update(id, user, rating); } } diff --git a/src/de/steamwar/bungeecore/sql/UserConfig.java b/src/de/steamwar/bungeecore/sql/UserConfig.java deleted file mode 100644 index b2c79bd..0000000 --- a/src/de/steamwar/bungeecore/sql/UserConfig.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2022 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - - -package de.steamwar.bungeecore.sql; - -import de.steamwar.sql.internal.Statement; - -public class UserConfig { - private UserConfig() {} - - private static final Statement insert = new Statement("INSERT INTO UserConfig (User, Config, Value) VALUES (?,?,?) ON DUPLICATE KEY UPDATE Value = VALUES(Value)"); - private static final Statement select = new Statement("SELECT Value FROM UserConfig WHERE User = ? AND Config = ?"); - private static final Statement delete = new Statement("DELETE FROM UserConfig WHERE User = ? AND Config = ?"); - - public static String getConfig(int userID, String config) { - return select.select(rs -> { - if(rs.next()) - return rs.getString("Value"); - return null; - }, userID, config); - } - - public static void updateUserConfig(int userID, String config, String value) { - if(value == null) { - delete.update(userID, config); - return; - } - - insert.update(userID, config, value); - } -} diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index ed5df18..3b26c30 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -19,9 +19,10 @@ package de.steamwar.bungeecore.sql; -import de.steamwar.sql.internal.Statement; import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.Message; +import de.steamwar.sql.Season; +import de.steamwar.sql.internal.Statement; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.HashMap; diff --git a/src/de/steamwar/bungeecore/sql/UserGroup.java b/src/de/steamwar/bungeecore/sql/UserGroup.java deleted file mode 100644 index 6ca7a9a..0000000 --- a/src/de/steamwar/bungeecore/sql/UserGroup.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.bungeecore.sql; - -import java.util.Arrays; -import java.util.stream.Collectors; - -public enum UserGroup { - - Admin("§4", "§e", "Admin", true, true, true, true), - Developer("§3", "§f", "Dev", true, true, true, true), - Moderator("§c", "§f", "Mod", true, true, true, true), - Supporter("§9", "§f", "Sup", false, true, true, true), - Builder("§2", "§f", "Arch", false, true, false, true), - YouTuber("§5", "§f", "YT", false, false, false, true), - Member("§7", "§7", "", false, false, false, false); - - private final String colorCode; - private final String chatColorCode; - private final String chatPrefix; - private final boolean adminGroup; - private final boolean teamGroup; - private final boolean checkSchematics; - private final boolean privilegedMods; - - UserGroup(String colorCode, String chatColorCode, String chatPrefix, boolean adminGroup, boolean teamGroup, boolean checkSchematics, boolean privilegedMods) { - this.colorCode = colorCode; - this.chatColorCode = chatColorCode; - this.chatPrefix = chatPrefix; - this.adminGroup = adminGroup; - this.teamGroup = teamGroup; - this.checkSchematics = checkSchematics; - this.privilegedMods = privilegedMods; - } - - public String getColorCode() { - return colorCode; - } - - public boolean isAdminGroup() { - return adminGroup; - } - - public boolean isTeamGroup() { - return teamGroup; - } - - public boolean isCheckSchematics() { - return checkSchematics; - } - - public boolean privilegedMods() { - return privilegedMods; - } - - public String getChatColorCode() { - return chatColorCode; - } - - public static UserGroup getUsergroup(String name) { - return Arrays.stream(UserGroup.values()).filter(userGroup -> userGroup.name().equalsIgnoreCase(name)).collect(Collectors.toList()).get(0); - } - - public String getChatPrefix() { - return chatPrefix; - } -} \ No newline at end of file diff --git a/src/de/steamwar/bungeecore/tablist/TablistPart.java b/src/de/steamwar/bungeecore/tablist/TablistPart.java index b140114..cdc8666 100644 --- a/src/de/steamwar/bungeecore/tablist/TablistPart.java +++ b/src/de/steamwar/bungeecore/tablist/TablistPart.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.tablist; import de.steamwar.bungeecore.sql.SteamwarUser; -import de.steamwar.bungeecore.sql.UserGroup; +import de.steamwar.sql.UserGroup; import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; diff --git a/src/de/steamwar/bungeecore/util/BauLock.java b/src/de/steamwar/bungeecore/util/BauLock.java new file mode 100644 index 0000000..2eb4c38 --- /dev/null +++ b/src/de/steamwar/bungeecore/util/BauLock.java @@ -0,0 +1,54 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bungeecore.util; + +import de.steamwar.bungeecore.Message; +import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.UserConfig; +import lombok.experimental.UtilityClass; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +@UtilityClass +public class BauLock { + + private static final String BAU_LOCK_CONFIG_NAME = "baulockstate"; + public static void setLocked(ProxiedPlayer p, BauLockState state) { + SteamwarUser owner = SteamwarUser.get(p.getUniqueId()); + UserConfig.updatePlayerConfig(owner.getId(), BAU_LOCK_CONFIG_NAME, state == BauLockState.OPEN ? null : state.name()); + Message.send("BAU_LOCKED_" + state.name(), owner.getPlayer()); + } + + public static boolean isLocked(SteamwarUser owner, SteamwarUser target) { + if (owner.getId() == target.getId()) + return false; + + String state = UserConfig.getConfig(owner.getId(), BAU_LOCK_CONFIG_NAME); + switch (state == null ? BauLockState.OPEN : BauLockState.valueOf(state)) { + case NOBODY: + return true; + case TEAM: + return owner.getTeam() != target.getTeam(); + case OPEN: + default: + return false; + } + } + +} diff --git a/src/de/steamwar/bungeecore/util/BauLockState.java b/src/de/steamwar/bungeecore/util/BauLockState.java new file mode 100644 index 0000000..a5626b1 --- /dev/null +++ b/src/de/steamwar/bungeecore/util/BauLockState.java @@ -0,0 +1,27 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bungeecore.util; + +public enum BauLockState { + + NOBODY, // Locks the build server for all users + TEAM, //opens the build server only for every added user which is in the same team as the buildOwner + OPEN //unlocks the build server for all users +} From 88ff8d8e747099e623841825085cacbd7735a595 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 23 Jan 2023 16:37:08 +0100 Subject: [PATCH 08/31] Update TeamCommand (not finished) --- .../bungeecore/commands/TeamCommand.java | 147 ++++++++---------- 1 file changed, 64 insertions(+), 83 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index 9ae3799..ce2ee75 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -24,6 +24,7 @@ import de.steamwar.bungeecore.Storage; import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.bungeecore.inventory.SWListInv; import de.steamwar.bungeecore.sql.*; +import de.steamwar.command.SWCommand; import de.steamwar.messages.ChatSender; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.ChatColor; @@ -49,7 +50,7 @@ import java.util.stream.Collectors; import static de.steamwar.bungeecore.Storage.teamInvitations; -public class TeamCommand extends BasicCommand { +public class TeamCommand extends SWCommand { private static final List> COLOR_CODES = new ArrayList<>(); @@ -77,16 +78,17 @@ public class TeamCommand extends BasicCommand { } public TeamCommand() { - super("team", ""); + super("team"); } - private void help(CommandSender sender){ + @Register + public void help(CommandSender sender, String... args){ Message.send("TEAM_HELP_HEADER", sender); Message.send("TEAM_HELP_LIST", sender); Message.send("TEAM_HELP_INFO", sender); - Message.send("TEAM_HELP_TP", sender); if(!(sender instanceof ProxiedPlayer)) return; + Message.send("TEAM_HELP_TP", sender); ProxiedPlayer player = (ProxiedPlayer) sender; SteamwarUser user = SteamwarUser.get(player.getUniqueId()); @@ -111,72 +113,10 @@ public class TeamCommand extends BasicCommand { } } - @Override - public void execute(CommandSender sender, String[] args){ - if(args.length < 1){ - help(sender); - return; - } - - if(!(sender instanceof ProxiedPlayer)) - return; - - ProxiedPlayer player = (ProxiedPlayer) sender; + @Register("create") + public void create(ProxiedPlayer player, String... args){ SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Team team = Team.get(user.getTeam()); - - switch(args[0].toLowerCase()){ - case "create": - create(player, user, team, args); - break; - case "join": - join(player, user, args); - break; - case "stepback": - stepBack(player,user,team); - break; - case "leave": - leave(player, user, team); - break; - case "invite": - invite(player, user, team, args); - break; - case "remove": - remove(player, user, team, args); - break; - case "changekuerzel": - changekuerzel(player, user, team, args); - break; - case "changename": - changename(player, user, team, args); - break; - case "promote": - promote(player, user, team, args); - break; - case "changecolor": - changeColor(player, user, team); - break; - case "info": - info(player, user, team, args); - break; - case "list": - list(player, args); - break; - case "event": - event(player, user, team, args); - break; - case "tp": - tp(player, user, team, args); - break; - case "server": - server(player, user, team, args); - break; - default: - help(player); - } - } - - private void create(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ if(unwantedInTeam(player, user)) return; @@ -197,7 +137,9 @@ public class TeamCommand extends BasicCommand { Message.send("TEAM_CREATE_CREATED", player, args[2]); } - private void join(ProxiedPlayer player, SteamwarUser user, String[] args){ + @Register("join") + public void join(ProxiedPlayer player, String... args){ + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); if(unwantedInTeam(player, user)) return; @@ -245,7 +187,10 @@ public class TeamCommand extends BasicCommand { Message.send("TEAM_JOIN_JOINED", player, Team.get(t).getTeamName()); } - private void stepBack(ProxiedPlayer player, SteamwarUser user, Team team) { + @Register("stepback") + public void stepBack(ProxiedPlayer player) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + Team team = Team.get(user.getTeam()); if(notLeader(player, user, team)) return; @@ -258,7 +203,10 @@ public class TeamCommand extends BasicCommand { Message.send("TEAM_STEP_BACK", player); } - private void leave(ProxiedPlayer player, SteamwarUser user, Team team){ + @Register("leave") + public void leave(ProxiedPlayer player){ + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + Team team = Team.get(user.getTeam()); if(notInTeam(player, user)) return; @@ -278,7 +226,10 @@ public class TeamCommand extends BasicCommand { } - private void invite(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ + @Register("invite") + public void invite(ProxiedPlayer player, String... args){ + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + Team team = Team.get(user.getTeam()); if(notLeader(player, user, team)) return; @@ -315,7 +266,10 @@ public class TeamCommand extends BasicCommand { Message.send("TEAM_INVITE_INVITED_TARGET", p, team.getTeamColor(), team.getTeamName()); } - private void remove(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ + @Register("remove") + public void remove(ProxiedPlayer player, String... args){ + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + Team team = Team.get(user.getTeam()); if(notLeader(player, user, team)) return; @@ -359,7 +313,10 @@ public class TeamCommand extends BasicCommand { Message.send("TEAM_REMOVE_REMOVED_TARGET", player); } - private void changekuerzel(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ + @Register("changekurzel") + public void changekuerzel(ProxiedPlayer player, String... args){ + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + Team team = Team.get(user.getTeam()); if(notLeader(player, user, team)) return; @@ -378,7 +335,10 @@ public class TeamCommand extends BasicCommand { Message.send("TEAM_KUERZEL_CHANGED", player); } - private void changename(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ + @Register("changename") + public void changename(ProxiedPlayer player, String... args){ + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + Team team = Team.get(user.getTeam()); if(notLeader(player, user, team)) return; @@ -397,7 +357,10 @@ public class TeamCommand extends BasicCommand { Message.send("TEAM_NAME_CHANGED", player); } - private void promote(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ + @Register("promote") + public void promote(ProxiedPlayer player, String... args){ + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + Team team = Team.get(user.getTeam()); if(notLeader(player, user, team)) return; @@ -428,7 +391,10 @@ public class TeamCommand extends BasicCommand { return ProxyServer.getInstance().getPlayer(user.getUuid()) != null ? "§a" + user.getUserName() : "§e" + user.getUserName(); } - private void info(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ + @Register("info") + public void info(ProxiedPlayer player, String... args){ + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + Team team = Team.get(user.getTeam()); if(args.length == 1 && user.getTeam() == 0){ Message.send("TEAM_INFO_USAGE", player); return; @@ -469,7 +435,10 @@ public class TeamCommand extends BasicCommand { return sb.toString(); } - private void list(ProxiedPlayer player, String[] args){ + @Register("list") + public void list(ProxiedPlayer player, String... args){ + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + Team team = Team.get(user.getTeam()); final int TEAMS_PER_PAGE = 10; @@ -520,7 +489,10 @@ public class TeamCommand extends BasicCommand { player.sendMessage(beforePage); } - private void event(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ + @Register("event") + public void event(ProxiedPlayer player, String[] args){ + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + Team team = Team.get(user.getTeam()); if(notInTeam(player, user)) return; @@ -563,7 +535,10 @@ public class TeamCommand extends BasicCommand { } } - private void tp(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ + @Register("tp") + public void tp(ProxiedPlayer player, String... args){ + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + Team team = Team.get(user.getTeam()); if(args.length == 1){ if(notInTeam(player, user)) return; @@ -609,7 +584,10 @@ public class TeamCommand extends BasicCommand { */ } - private void server(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ + @Register("server") + public void server(ProxiedPlayer player, String[] args){ + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + Team team = Team.get(user.getTeam()); if(notLeader(player, user, team)) return; if (user.isPunishedWithMessage(ChatSender.of(player), Punishment.PunishmentType.NoTeamServer)) { @@ -661,7 +639,10 @@ public class TeamCommand extends BasicCommand { } } - private void changeColor(ProxiedPlayer player, SteamwarUser user, Team team) { + @Register("color") + public void changeColor(ProxiedPlayer player) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + Team team = Team.get(user.getTeam()); if(notLeader(player, user, team)) return; @@ -745,7 +726,7 @@ public class TeamCommand extends BasicCommand { return false; } - @Override + // @Override public Iterable onTabComplete(CommandSender commandSender, String[] args){ List tab = new ArrayList<>(); if(args.length == 1){ From d559c61846f21a8bfff69066d87b7a03243a55ce Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 23 Jan 2023 18:00:06 +0100 Subject: [PATCH 09/31] Update TeamCommand (not finished) --- .../bungeecore/commands/TeamCommand.java | 55 +++++-------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index ce2ee75..3a3b2e9 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -113,28 +113,23 @@ public class TeamCommand extends SWCommand { } } - @Register("create") - public void create(ProxiedPlayer player, String... args){ + @Register(value = "create", description = "TEAM_CREATE_USAGE") + public void create(ProxiedPlayer player, @Length(min = 2, max = 4) @ErrorMessage("TEAM_KUERZEL_LENGHT") String kuerzel, @Length(min = 4, max = 15) @ErrorMessage("TEAM_NAME_LENGHT") String name){ SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Team team = Team.get(user.getTeam()); if(unwantedInTeam(player, user)) return; - if(args.length < 3){ - Message.send("TEAM_CREATE_USAGE", player); - return; - } - - if(checkTeamKuerzel(player, team, args[1])) + if(checkTeamKuerzel(player, team, kuerzel)) return; - if(checkTeamName(player, team, args[2])) + if(checkTeamName(player, team, name)) return; - Team.create(args[1], args[2]); - user.setTeam(Team.get(args[1]).getTeamId()); + Team.create(kuerzel, name); + user.setTeam(Team.get(kuerzel).getTeamId()); user.setLeader(true); - Message.send("TEAM_CREATE_CREATED", player, args[2]); + Message.send("TEAM_CREATE_CREATED", player, name); } @Register("join") @@ -313,8 +308,8 @@ public class TeamCommand extends SWCommand { Message.send("TEAM_REMOVE_REMOVED_TARGET", player); } - @Register("changekurzel") - public void changekuerzel(ProxiedPlayer player, String... args){ + @Register(value = "changekurzel", description = "TEAM_KUERZEL_USAGE") + public void changekuerzel(ProxiedPlayer player, @Length(min = 2, max = 4) @ErrorMessage("TEAM_KUERZEL_LENGHT") String kuerzel){ SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Team team = Team.get(user.getTeam()); if(notLeader(player, user, team)) @@ -323,20 +318,15 @@ public class TeamCommand extends SWCommand { if(notDuringEvent(player)) return; - if(args.length < 2){ - Message.send("TEAM_KUERZEL_USAGE", player); - return; - } - - if(checkTeamKuerzel(player, team, args[1])) + if(checkTeamKuerzel(player, team, kuerzel)) return; - team.setTeamKuerzel(args[1]); + team.setTeamKuerzel(kuerzel); Message.send("TEAM_KUERZEL_CHANGED", player); } - @Register("changename") - public void changename(ProxiedPlayer player, String... args){ + @Register(value = "changename", description = "TEAM_NAME_USAGE") + public void changename(ProxiedPlayer player, @Length(min = 4, max = 15) @ErrorMessage("TEAM_NAME_LENGHT") String name){ SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Team team = Team.get(user.getTeam()); if(notLeader(player, user, team)) @@ -345,15 +335,10 @@ public class TeamCommand extends SWCommand { if(notDuringEvent(player)) return; - if(args.length < 2){ - Message.send("TEAM_NAME_USAGE", player); - return; - } - - if(checkTeamName(player, team, args[1])) + if(checkTeamName(player, team, name)) return; - team.setTeamName(args[1]); + team.setTeamName(name); Message.send("TEAM_NAME_CHANGED", player); } @@ -665,11 +650,6 @@ public class TeamCommand extends SWCommand { } private boolean checkTeamName(ProxiedPlayer player, Team team, String arg){ - if(arg.length() < 4 || arg.length() > 15){ - Message.send("TEAM_NAME_LENGHT", player); - return true; - } - Team t = Team.get(arg); if(t != null && t.getTeamId() != team.getTeamId()){ Message.send("TEAM_NAME_TAKEN", player); @@ -679,11 +659,6 @@ public class TeamCommand extends SWCommand { } private boolean checkTeamKuerzel(ProxiedPlayer player, Team team, String arg){ - if(arg.length() < 2 || arg.length() > 4){ - Message.send("TEAM_KUERZEL_LENGHT", player); - return true; - } - Team t = Team.get(arg); if(t != null && (team == null || t.getTeamId() != team.getTeamId())){ Message.send("TEAM_KUERZEL_TAKEN", player); From 561289b5a679a101aafdab7aedfae4e6af437ec1 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 23 Jan 2023 18:15:37 +0100 Subject: [PATCH 10/31] Update TeamCommand (not finished) --- .../bungeecore/commands/TeamCommand.java | 119 +++++------------- .../steamwar/messages/BungeeCore.properties | 4 +- .../messages/BungeeCore_de.properties | 4 +- 3 files changed, 33 insertions(+), 94 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index 3a3b2e9..6185129 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -186,7 +186,7 @@ public class TeamCommand extends SWCommand { public void stepBack(ProxiedPlayer player) { SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Team team = Team.get(user.getTeam()); - if(notLeader(player, user, team)) + if(notLeader(player, user)) return; if(team.size() > 1 && team.getMembers().stream().map(SteamwarUser::get).filter(member -> user != member).noneMatch(SteamwarUser::isLeader)){ @@ -221,22 +221,17 @@ public class TeamCommand extends SWCommand { } - @Register("invite") - public void invite(ProxiedPlayer player, String... args){ + @Register(value = "invite", description = "TEAM_INVITE_USAGE") + public void invite(ProxiedPlayer player, String toInvite){ SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Team team = Team.get(user.getTeam()); - if(notLeader(player, user, team)) + if(notLeader(player, user)) return; if(notDuringEvent(player)) return; - if(args.length != 2){ - Message.send("TEAM_INVITE_USAGE", player); - return; - } - - SteamwarUser target = SteamwarUser.get(args[1]); + SteamwarUser target = SteamwarUser.get(toInvite); if(target == null){ Message.send("TEAM_INVITE_NO_PLAYER", player); return; @@ -255,25 +250,20 @@ public class TeamCommand extends SWCommand { teamInvitations.get(target.getId()).add(team.getTeamId()); - Message.send("TEAM_INVITE_INVITED", player, args[1]); + Message.send("TEAM_INVITE_INVITED", player, toInvite); ProxiedPlayer p = ProxyServer.getInstance().getPlayer(target.getUuid()); if(p != null) Message.send("TEAM_INVITE_INVITED_TARGET", p, team.getTeamColor(), team.getTeamName()); } - @Register("remove") - public void remove(ProxiedPlayer player, String... args){ + @Register(value = "remove", description = "TEAM_REMOVE_USAGE") + public void remove(ProxiedPlayer player, String toRemove){ SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Team team = Team.get(user.getTeam()); - if(notLeader(player, user, team)) + if(notLeader(player, user)) return; - if(args.length != 2){ - Message.send("TEAM_REMOVE_USAGE", player); - return; - } - - SteamwarUser target = SteamwarUser.get(args[1]); + SteamwarUser target = SteamwarUser.get(toRemove); if(target == null){ Message.send("TEAM_REMOVE_NOT_PLAYER", player); return; @@ -312,7 +302,7 @@ public class TeamCommand extends SWCommand { public void changekuerzel(ProxiedPlayer player, @Length(min = 2, max = 4) @ErrorMessage("TEAM_KUERZEL_LENGHT") String kuerzel){ SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Team team = Team.get(user.getTeam()); - if(notLeader(player, user, team)) + if(notLeader(player, user)) return; if(notDuringEvent(player)) @@ -326,10 +316,10 @@ public class TeamCommand extends SWCommand { } @Register(value = "changename", description = "TEAM_NAME_USAGE") - public void changename(ProxiedPlayer player, @Length(min = 4, max = 15) @ErrorMessage("TEAM_NAME_LENGHT") String name){ + public void changename(ProxiedPlayer player, @Length(min = 4, max = 15) @ErrorMessage("TEAM_NAME_LENGTH") String name){ SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Team team = Team.get(user.getTeam()); - if(notLeader(player, user, team)) + if(notLeader(player, user)) return; if(notDuringEvent(player)) @@ -342,24 +332,18 @@ public class TeamCommand extends SWCommand { Message.send("TEAM_NAME_CHANGED", player); } - @Register("promote") - public void promote(ProxiedPlayer player, String... args){ + @Register(value = "promote", description = "TEAM_LEADER_USAGE") + public void promote(ProxiedPlayer player, String toPromote){ SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - Team team = Team.get(user.getTeam()); - if(notLeader(player, user, team)) + if(notLeader(player, user)) return; if(notDuringEvent(player)) return; - if(args.length < 2){ - Message.send("TEAM_LEADER_USAGE", player); - return; - } - - SteamwarUser target = SteamwarUser.get(args[1]); + SteamwarUser target = SteamwarUser.get(toPromote); if(target == null){ - Message.send("TEAM_LEADER_NOT_USER", player, args[1]); + Message.send("TEAM_LEADER_NOT_USER", player, toPromote); return; } @@ -369,7 +353,7 @@ public class TeamCommand extends SWCommand { } target.setLeader(true); - Message.send("TEAM_LEADER_PROMOTED", player, args[1]); + Message.send("TEAM_LEADER_PROMOTED", player, toPromote); } private String playerName(SteamwarUser user){ @@ -421,23 +405,9 @@ public class TeamCommand extends SWCommand { } @Register("list") - public void list(ProxiedPlayer player, String... args){ - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - Team team = Team.get(user.getTeam()); - + public void list(ProxiedPlayer player, @Min(intValue = 1) @OptionalValue("1") @ErrorMessage("TEAM_LIST_NOT_PAGE") int page){ final int TEAMS_PER_PAGE = 10; - int page; - if(args.length > 1){ - try{ - page = Integer.parseInt(args[1]); - }catch(NumberFormatException e){ - Message.send("TEAM_LIST_NOT_PAGE", player); - return; - } - }else - page = 1; - List all = Team.getAll(); final int lastPage = ((all.size() - 1) / 10) + 1; if(page < 1 || page > lastPage){ @@ -493,7 +463,7 @@ public class TeamCommand extends SWCommand { return; } - if(notLeader(player, user, team)) + if(notLeader(player, user)) return; if(notDuringEvent(player)) @@ -569,20 +539,16 @@ public class TeamCommand extends SWCommand { */ } - @Register("server") - public void server(ProxiedPlayer player, String[] args){ + @Register(value = "server", description = "TEAM_SERVER_USAGE") + public void server(ProxiedPlayer player, String server, @Min(intValue = 1) @Max(intValue = 65535) @ErrorMessage("TEAM_SERVER_PORT_INVALID") int port){ SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Team team = Team.get(user.getTeam()); - if(notLeader(player, user, team)) + if(notLeader(player, user)) return; if (user.isPunishedWithMessage(ChatSender.of(player), Punishment.PunishmentType.NoTeamServer)) { return; } - if (args.length < 2) { - Message.send("TEAM_SERVER_USAGE", player); - return; - } - String server = args[1]; + try { if (isLocalhost(InetAddress.getByName(server))) { Message.send("TEAM_SERVER_ADDRESS_INVALID", player); @@ -592,19 +558,7 @@ public class TeamCommand extends SWCommand { Message.send("TEAM_SERVER_ADDRESS_INVALID", player); return; } - int port = 25565; - if (args.length == 3) { - try { - port = Integer.parseInt(args[2]); - if (port < 1 || port > 65535) { - Message.send("TEAM_SERVER_PORT_INVALID", player); - return; - } - } catch (NumberFormatException e) { - Message.send("TEAM_SERVER_PORT_INVALID", player); - return; - } - } + team.setAddress(server); team.setPort(port); Storage.teamServers.remove(team.getTeamId()); @@ -628,7 +582,7 @@ public class TeamCommand extends SWCommand { public void changeColor(ProxiedPlayer player) { SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Team team = Team.get(user.getTeam()); - if(notLeader(player, user, team)) + if(notLeader(player, user)) return; if(notDuringEvent(player)) @@ -683,7 +637,7 @@ public class TeamCommand extends SWCommand { return false; } - private boolean notLeader(ProxiedPlayer player, SteamwarUser user, Team team){ + private boolean notLeader(ProxiedPlayer player, SteamwarUser user){ if(notInTeam(player, user)) return true; if(!user.isLeader()){ @@ -704,22 +658,7 @@ public class TeamCommand extends SWCommand { // @Override public Iterable onTabComplete(CommandSender commandSender, String[] args){ List tab = new ArrayList<>(); - if(args.length == 1){ - tab.add("create"); - tab.add("join"); - tab.add("invite"); - tab.add("stepback"); - tab.add("leave"); - tab.add("info"); - tab.add("remove"); - tab.add("event"); - tab.add("changekuerzel"); - tab.add("changename"); - tab.add("promote"); - tab.add("changecolor"); - tab.add("tp"); - tab.add("server"); - }else if(args.length == 2){ + if(args.length == 2){ if(args[1].equalsIgnoreCase("event")){ List coming = Event.getComing(); coming.forEach(event -> tab.add(event.getEventName())); diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 23060c2..ec1d480 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -444,13 +444,13 @@ TEAM_REMOVE_REMOVED_TARGET=§cYou were removed from the team. #Team Kuerzel TEAM_KUERZEL_USAGE=§8/§7team changekuerzel §8[§eshortcut§8] TEAM_KUERZEL_CHANGED=§7You changed your teams shortcut! -TEAM_KUERZEL_LENGHT=§cA team shortcut has to consist of 2 to 4 characters. +TEAM_KUERZEL_LENGTH=§cA team shortcut has to consist of 2 to 4 characters. TEAM_KUERZEL_TAKEN=§cThere is already a team with that shortcut. #Team Name TEAM_NAME_USAGE=§8/§7team changename §8[§eteam name§8] TEAM_NAME_CHANGED=§7You have renamed your team! -TEAM_NAME_LENGHT=§cA team name has to consist of 4 to 15 characters. +TEAM_NAME_LENGTH=§cA team name has to consist of 4 to 15 characters. TEAM_NAME_TAKEN=§cThere is already a team with that name. #Team Leader diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index f9b11af..8cfc82f 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -422,13 +422,13 @@ TEAM_REMOVE_REMOVED_TARGET=§cDu wurdest aus dem Team entfernt. #Team Kuerzel TEAM_KUERZEL_USAGE=§8/§7team changekuerzel §8[§eTeamkürzel§8] TEAM_KUERZEL_CHANGED=§7Du hast das Kürzel des Teams geändert! -TEAM_KUERZEL_LENGHT=§cEin Teamkürzel muss aus 2 bis 4 Buchstaben bestehen. +TEAM_KUERZEL_LENGTH=§cEin Teamkürzel muss aus 2 bis 4 Buchstaben bestehen. TEAM_KUERZEL_TAKEN=§cEs gibt bereits ein Team mit diesem Namen. #Team Name TEAM_NAME_USAGE=§8/§7team changename §8[§eTeamname§8] TEAM_NAME_CHANGED=§7Du hast das Team umbenannt! -TEAM_NAME_LENGHT=§cEin Teamname muss aus 4 bis 15 Buchstaben bestehen. +TEAM_NAME_LENGTH=§cEin Teamname muss aus 4 bis 15 Buchstaben bestehen. TEAM_NAME_TAKEN=§cEs gibt bereits ein Team mit diesem Namen. #Team Leader From 7611abe4dcb6c8ac9330031181d6472fa4c0c557 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 23 Jan 2023 18:28:12 +0100 Subject: [PATCH 11/31] Remove BasicCommand --- .../bungeecore/commands/BasicCommand.java | 69 ------------------- 1 file changed, 69 deletions(-) delete mode 100644 src/de/steamwar/bungeecore/commands/BasicCommand.java diff --git a/src/de/steamwar/bungeecore/commands/BasicCommand.java b/src/de/steamwar/bungeecore/commands/BasicCommand.java deleted file mode 100644 index d4b9c0a..0000000 --- a/src/de/steamwar/bungeecore/commands/BasicCommand.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.commands; - -import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.sql.SteamwarUser; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.plugin.Command; -import net.md_5.bungee.api.plugin.TabExecutor; - -import java.util.ArrayList; -import java.util.List; - -abstract class BasicCommand extends Command implements TabExecutor { - - public BasicCommand(String name, String permission, String... aliases) { - super(name, permission, aliases); - BungeeCore.commands.put("/" + name, permission); - ProxyServer.getInstance().getPluginManager().registerCommand(BungeeCore.get(), this); - } - - Iterable allPlayers(String begin) { - List suggestions = new ArrayList<>(); - for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){ - String playerName = player.getName(); - if(playerName.startsWith(begin)) - suggestions.add(playerName); - } - return suggestions; - } - - public Iterable onTabComplete(CommandSender commandSender, String[] args) { - return new ArrayList<>(); - } - - protected SteamwarUser existingUser(CommandSender sender, String arg){ - SteamwarUser target = SteamwarUser.get(arg); - if(target == null) - Message.send("UNKNOWN_PLAYER", sender); - return target; - } - - protected SteamwarUser unsafeUser(CommandSender sender, String arg){ - SteamwarUser target = SteamwarUser.getOrCreateOfflinePlayer(arg); - if(target == null) - Message.send("UNKNOWN_PLAYER", sender); - return target; - } -} From 871e45ffbbf422f475e3b237079158ff70d16efc Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 4 Feb 2023 12:55:08 +0100 Subject: [PATCH 12/31] WIP CommonDB Signed-off-by: Lixfel --- CommonCore | 2 +- src/de/steamwar/bungeecore/ArenaMode.java | 2 +- .../bungeecore/bot/events/EventManager.java | 2 +- .../bungeecore/commands/BauCommand.java | 3 +- .../bungeecore/commands/CheckCommand.java | 13 +- .../bungeecore/commands/EventCommand.java | 6 +- .../bungeecore/commands/JoinmeCommand.java | 2 +- .../bungeecore/commands/ReplayCommand.java | 2 +- .../bungeecore/commands/TpCommand.java | 2 +- .../bungeecore/listeners/CheckListener.java | 2 +- .../network/handlers/FightEndsHandler.java | 1 + .../network/handlers/PrepareSchemHandler.java | 2 +- .../bungeecore/sql/BauweltMember.java | 118 ------------ src/de/steamwar/bungeecore/sql/Fight.java | 5 +- .../bungeecore/sql/SchematicNode.java | 1 + .../bungeecore/sql/SchematicType.java | 177 ------------------ src/de/steamwar/sql/SQLWrapperImpl.java | 22 ++- 17 files changed, 47 insertions(+), 315 deletions(-) delete mode 100644 src/de/steamwar/bungeecore/sql/BauweltMember.java delete mode 100644 src/de/steamwar/bungeecore/sql/SchematicType.java diff --git a/CommonCore b/CommonCore index fca45b0..d439ecb 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit fca45b084e22653391b526d57396ec386fa7444f +Subproject commit d439ecb8d01d576310766e497c970bce7eb1db2f diff --git a/src/de/steamwar/bungeecore/ArenaMode.java b/src/de/steamwar/bungeecore/ArenaMode.java index abb6b77..d33aeeb 100644 --- a/src/de/steamwar/bungeecore/ArenaMode.java +++ b/src/de/steamwar/bungeecore/ArenaMode.java @@ -19,7 +19,7 @@ package de.steamwar.bungeecore; -import de.steamwar.bungeecore.sql.SchematicType; +import de.steamwar.sql.SchematicType; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.config.Configuration; import net.md_5.bungee.config.ConfigurationProvider; diff --git a/src/de/steamwar/bungeecore/bot/events/EventManager.java b/src/de/steamwar/bungeecore/bot/events/EventManager.java index cd57767..1cd09d3 100644 --- a/src/de/steamwar/bungeecore/bot/events/EventManager.java +++ b/src/de/steamwar/bungeecore/bot/events/EventManager.java @@ -22,7 +22,7 @@ package de.steamwar.bungeecore.bot.events; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.sql.EventFight; -import de.steamwar.bungeecore.sql.Team; +import de.steamwar.sql.Team; import de.steamwar.sql.TeamTeilnahme; import de.steamwar.sql.Event; import lombok.experimental.UtilityClass; diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 9740cc7..b73855f 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -32,6 +32,7 @@ import de.steamwar.command.TypeValidator; import de.steamwar.messages.ChatSender; import de.steamwar.network.packets.server.BaumemberUpdatePacket; import de.steamwar.bungeecore.util.BauLockState; +import de.steamwar.sql.BauweltMember; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; @@ -122,7 +123,7 @@ public class BauCommand extends SWCommand { @Register(value = "addmember", description = "BAU_ADDMEMBER_USAGE") public void addmember(ProxiedPlayer p, @Validator("addMemberTarget") SteamwarUser target) { - new BauweltMember(p.getUniqueId(), target.getUuid(), false, false); + BauweltMember.addMember(p.getUniqueId(), target.getUuid()); Message.send("BAU_ADDMEMBER_ADDED", p); ProxiedPlayer z = ProxyServer.getInstance().getPlayer(target.getUuid()); diff --git a/src/de/steamwar/bungeecore/commands/CheckCommand.java b/src/de/steamwar/bungeecore/commands/CheckCommand.java index 02fc7a8..e231f75 100644 --- a/src/de/steamwar/bungeecore/commands/CheckCommand.java +++ b/src/de/steamwar/bungeecore/commands/CheckCommand.java @@ -24,11 +24,10 @@ import de.steamwar.bungeecore.bot.util.DiscordSchemAlert; import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.bungeecore.sql.CheckedSchematic; import de.steamwar.bungeecore.sql.SchematicNode; -import de.steamwar.bungeecore.sql.SchematicType; +import de.steamwar.sql.SchematicType; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.command.SWCommand; import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.TextComponent; @@ -37,12 +36,12 @@ import net.md_5.bungee.config.Configuration; import java.sql.Timestamp; import java.time.Instant; -import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.logging.Level; public class CheckCommand extends SWCommand { + private static final Map fightTypes = new HashMap<>(); private static Map> checkQuestions = new HashMap<>(); private static Map> ranks = new HashMap<>(); @@ -55,6 +54,10 @@ public class CheckCommand extends SWCommand { ranks.put(checkType, config.getStringList("Ranks")); } + public static void addFightType(SchematicType checkType, SchematicType fightType) { + fightTypes.put(checkType, fightType); + } + public static boolean isChecking(ProxiedPlayer player){ return currentCheckers.containsKey(player.getUniqueId()); } @@ -215,7 +218,7 @@ public class CheckCommand extends SWCommand { this.checkList = checkQuestions.get(schematic.getSchemtype()).listIterator(); ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { - ArenaMode mode = ArenaMode.getBySchemType(schematic.getSchemtype().fightType()); + ArenaMode mode = ArenaMode.getBySchemType(fightTypes.get(schematic.getSchemtype())); if(new ServerStarter().test(mode, mode.getRandomMap(), checker).check(schematic.getId()).start() == null) { remove(); return; @@ -273,7 +276,7 @@ public class CheckCommand extends SWCommand { schematic.setRank(rank); } - schematic.setType(schematic.getSchemtype().fightType().toDB()); + schematic.setType(fightTypes.get(schematic.getSchemtype()).toDB()); CheckedSchematic.create(schematic, SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "freigegeben"); SteamwarUser user = SteamwarUser.get(schematic.getOwner()); ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid()); diff --git a/src/de/steamwar/bungeecore/commands/EventCommand.java b/src/de/steamwar/bungeecore/commands/EventCommand.java index e106d59..082b9b7 100644 --- a/src/de/steamwar/bungeecore/commands/EventCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventCommand.java @@ -21,8 +21,8 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.sql.EventFight; -import de.steamwar.bungeecore.sql.SchematicType; -import de.steamwar.bungeecore.sql.Team; +import de.steamwar.sql.SchematicType; +import de.steamwar.sql.Team; import de.steamwar.sql.TeamTeilnahme; import de.steamwar.sql.Event; import net.md_5.bungee.api.CommandSender; @@ -88,7 +88,7 @@ public class EventCommand extends BasicCommand { String schemType = e.getSchemType(); if (schemType != null) { SchematicType schematicType = SchematicType.fromDB(schemType); - if (schematicType != null && schematicType.deadline() != null && now.isBefore(schematicType.deadline().toInstant())) { + if (schematicType != null && schematicType.getDeadline() != null && now.isBefore(schematicType.getDeadline().toInstant())) { Message.send("EVENT_COMING_SCHEM_DEADLINE", player, e.getDeadline()); } } diff --git a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java index e897ba0..5c9d589 100644 --- a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java +++ b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; -import de.steamwar.bungeecore.sql.BauweltMember; +import de.steamwar.sql.BauweltMember; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; diff --git a/src/de/steamwar/bungeecore/commands/ReplayCommand.java b/src/de/steamwar/bungeecore/commands/ReplayCommand.java index ff012b9..86aca8f 100644 --- a/src/de/steamwar/bungeecore/commands/ReplayCommand.java +++ b/src/de/steamwar/bungeecore/commands/ReplayCommand.java @@ -25,7 +25,7 @@ import de.steamwar.bungeecore.inventory.SWListInv; import de.steamwar.bungeecore.inventory.SWStreamInv; import de.steamwar.bungeecore.sql.Fight; import de.steamwar.bungeecore.sql.Punishment; -import de.steamwar.bungeecore.sql.SchematicType; +import de.steamwar.sql.SchematicType; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.command.SWCommand; import de.steamwar.messages.ChatSender; diff --git a/src/de/steamwar/bungeecore/commands/TpCommand.java b/src/de/steamwar/bungeecore/commands/TpCommand.java index 7025b10..9b48eaa 100644 --- a/src/de/steamwar/bungeecore/commands/TpCommand.java +++ b/src/de/steamwar/bungeecore/commands/TpCommand.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; -import de.steamwar.bungeecore.sql.BauweltMember; +import de.steamwar.sql.BauweltMember; import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.Team; diff --git a/src/de/steamwar/bungeecore/listeners/CheckListener.java b/src/de/steamwar/bungeecore/listeners/CheckListener.java index 1370a0d..0f236d6 100644 --- a/src/de/steamwar/bungeecore/listeners/CheckListener.java +++ b/src/de/steamwar/bungeecore/listeners/CheckListener.java @@ -22,7 +22,7 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.commands.CheckCommand; import de.steamwar.bungeecore.sql.SchematicNode; -import de.steamwar.bungeecore.sql.SchematicType; +import de.steamwar.sql.SchematicType; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.PlayerDisconnectEvent; diff --git a/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java index b6a3f6b..d6dc4a0 100644 --- a/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java @@ -23,6 +23,7 @@ import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.sql.*; import de.steamwar.network.packets.PacketHandler; import de.steamwar.network.packets.common.FightEndsPacket; +import de.steamwar.sql.SchematicType; import lombok.RequiredArgsConstructor; import java.util.*; diff --git a/src/de/steamwar/bungeecore/network/handlers/PrepareSchemHandler.java b/src/de/steamwar/bungeecore/network/handlers/PrepareSchemHandler.java index c59c8df..2f25c44 100644 --- a/src/de/steamwar/bungeecore/network/handlers/PrepareSchemHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/PrepareSchemHandler.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.network.handlers; import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.ServerStarter; -import de.steamwar.bungeecore.sql.SchematicType; +import de.steamwar.sql.SchematicType; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.network.packets.PacketHandler; import de.steamwar.network.packets.client.PrepareSchemPacket; diff --git a/src/de/steamwar/bungeecore/sql/BauweltMember.java b/src/de/steamwar/bungeecore/sql/BauweltMember.java deleted file mode 100644 index 66222bf..0000000 --- a/src/de/steamwar/bungeecore/sql/BauweltMember.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.sql.internal.Statement; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class BauweltMember{ - - private static final Statement delete = new Statement("DELETE FROM BauweltMember WHERE BauweltID = ? AND MemberID = ?"); - private static final Statement update = new Statement("INSERT INTO BauweltMember (BauweltID, MemberID, WorldEdit, World) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE WorldEdit = VALUES(WorldEdit), World = VALUES(World)"); - private static final Statement getMember = new Statement("SELECT * FROM BauweltMember WHERE BauweltID = ? AND MemberID = ?"); - private static final Statement getMembers = new Statement("SELECT * FROM BauweltMember WHERE BauweltID = ?"); - - private final int bauweltID; - private final int memberID; - private boolean worldEdit; - private boolean world; - - - private BauweltMember(int ownerID, int memberID, boolean worldEdit, boolean world, boolean updateDB){ - bauweltID = ownerID; - this.memberID = memberID; - this.worldEdit = worldEdit; - this.world = world; - if(updateDB) - updateDB(); - } - - public BauweltMember(int ownerID, int memberID, boolean worldEdit, boolean world){ - this(ownerID, memberID, worldEdit, world, true); - } - - public BauweltMember(UUID ownerID, UUID memberID, boolean worldEdit, boolean world){ - this(SteamwarUser.get(ownerID).getId(), SteamwarUser.get(memberID).getId(), worldEdit, world); - } - - public void remove(){ - delete.update(bauweltID, memberID); - } - - private void updateDB(){ - update.update(bauweltID, memberID, worldEdit, world); - } - - public static BauweltMember getBauMember(UUID ownerID, UUID memberID){ - return getBauMember(SteamwarUser.get(ownerID).getId(), SteamwarUser.get(memberID).getId()); - } - - public static BauweltMember getBauMember(int ownerID, int memberID){ - return getMember.select(rs -> { - if(!rs.next()) - return null; - - return new BauweltMember(ownerID, memberID, rs.getBoolean("WorldEdit"), rs.getBoolean("World"), false); - }, ownerID, memberID); - } - - public static List getMembers(UUID bauweltID){ - return getMembers(SteamwarUser.get(bauweltID).getId()); - } - - public static List getMembers(int bauweltID){ - return getMembers.select(rs -> { - List members = new ArrayList<>(); - while(rs.next()){ - members.add(new BauweltMember(bauweltID, rs.getInt("MemberID"), rs.getBoolean("WorldEdit"), rs.getBoolean("World"), false)); - } - return members; - }, bauweltID); - } - - public int getBauweltID() { - return bauweltID; - } - - public int getMemberID() { - return memberID; - } - - public boolean isWorldEdit() { - return worldEdit; - } - - public void setWorldEdit(boolean worldEdit) { - this.worldEdit = worldEdit; - updateDB(); - } - - public boolean isWorld() { - return world; - } - - public void setWorld(boolean world) { - this.world = world; - updateDB(); - } -} diff --git a/src/de/steamwar/bungeecore/sql/Fight.java b/src/de/steamwar/bungeecore/sql/Fight.java index 463dee7..7de3de0 100644 --- a/src/de/steamwar/bungeecore/sql/Fight.java +++ b/src/de/steamwar/bungeecore/sql/Fight.java @@ -20,6 +20,7 @@ package de.steamwar.bungeecore.sql; import de.steamwar.sql.FightPlayer; +import de.steamwar.sql.SchematicType; import de.steamwar.sql.internal.Statement; import de.steamwar.bungeecore.ArenaMode; @@ -91,8 +92,8 @@ public class Fight { return fights; } - public de.steamwar.bungeecore.sql.SchematicType getSchemType() { - return de.steamwar.bungeecore.sql.SchematicType.fromDB(gameMode); + public SchematicType getSchemType() { + return SchematicType.fromDB(gameMode); } public ArenaMode getGameMode() { diff --git a/src/de/steamwar/bungeecore/sql/SchematicNode.java b/src/de/steamwar/bungeecore/sql/SchematicNode.java index 66a9183..9c91c02 100644 --- a/src/de/steamwar/bungeecore/sql/SchematicNode.java +++ b/src/de/steamwar/bungeecore/sql/SchematicNode.java @@ -20,6 +20,7 @@ package de.steamwar.bungeecore.sql; +import de.steamwar.sql.SchematicType; import de.steamwar.sql.internal.Statement; import java.io.InputStream; diff --git a/src/de/steamwar/bungeecore/sql/SchematicType.java b/src/de/steamwar/bungeecore/sql/SchematicType.java deleted file mode 100644 index 9592070..0000000 --- a/src/de/steamwar/bungeecore/sql/SchematicType.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.bungeecore.commands.CheckCommand; -import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.config.Configuration; -import net.md_5.bungee.config.ConfigurationProvider; -import net.md_5.bungee.config.YamlConfiguration; - -import java.io.File; -import java.io.IOException; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.*; - -public class SchematicType { - public static final SchematicType Normal = new SchematicType("Normal", "", null, Type.NORMAL, null, null); //Has to stay publicly availible - - private static final Map fromDB; - private static final Map fightType; - private static final List types; - - static { - File folder = new File(ProxyServer.getInstance().getPluginsFolder(), "FightSystem"); - - List tmpTypes = new LinkedList<>(); - Map tmpFromDB = new HashMap<>(); - Map tmpFightType = new HashMap<>(); - - tmpTypes.add(Normal); - tmpFromDB.put(Normal.name().toLowerCase(), Normal); - - if(folder.exists()) { - for(File configFile : folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))) { - Configuration config; - try { - config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); - } catch (IOException e) { - throw new SecurityException("Could not load SchematicTypes", e); - } - - if(!config.contains("Schematic")) - continue; - - String type = config.getString("Schematic.Type"); - assert type != null; - String shortcut = config.getString("Schematic.Shortcut"); - if(tmpFromDB.containsKey(type.toLowerCase())) - continue; - - String material = config.getString("Schematic.Material"); - - SchematicType checktype = null; - if(!config.getStringList("CheckQuestions").isEmpty()) { - checktype = new SchematicType("C" + type, "C" + shortcut, material, Type.CHECK_TYPE, null, null); - tmpTypes.add(checktype); - tmpFromDB.put(checktype.toDB(), checktype); - CheckCommand.setCheckQuestions(checktype, config); - } - - Date deadline; - String deadlineString = config.getString("deadline", null); - if (deadlineString != null) { - try { - SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm"); - deadline = dateFormat.parse(deadlineString); - } catch (ParseException e) { - throw new SecurityException(e.getMessage(), e); - } - } else { - deadline = null; - } - - SchematicType current = new SchematicType(type, shortcut, material, config.getKeys().contains("Server") ? Type.FIGHT_TYPE : Type.NORMAL, checktype, deadline); - if(checktype != null) - tmpFightType.put(checktype, current); - tmpFromDB.put(type.toLowerCase(), current); - } - } - - fromDB = Collections.unmodifiableMap(tmpFromDB); - fightType = Collections.unmodifiableMap(tmpFightType); - types = Collections.unmodifiableList(tmpTypes); - } - - private final String name; - private final String kuerzel; - private final String material; - private final Type type; - private final SchematicType checkType; - private final Date deadline; - - private SchematicType(String name, String kuerzel, String material, Type type, SchematicType checkType, Date deadline){ - this.name = name; - this.kuerzel = kuerzel; - this.material = material != null && !"".equals(material) ? material : "STONE_BUTTON"; - this.type = type; - this.checkType = checkType; - this.deadline = deadline; - } - - public boolean isAssignable(){ - return type == Type.NORMAL || (type == Type.FIGHT_TYPE && checkType != null); - } - - public SchematicType checkType(){ - return checkType; - } - - public SchematicType fightType(){ - return fightType.get(this); - } - - public boolean check(){ - return type == Type.CHECK_TYPE; - } - - public boolean fight(){ - return type == Type.FIGHT_TYPE; - } - - public boolean writeable(){ - return type == Type.NORMAL; - } - - public String name(){ - return name; - } - - public String getMaterial() { - return material; - } - - public String getKuerzel() { - return kuerzel; - } - - public String toDB(){ - return name.toLowerCase(); - } - - public Date deadline() { - return deadline; - } - - public static SchematicType fromDB(String input){ - return fromDB.getOrDefault(input.toLowerCase(), null); - } - - public static List values(){ - return types; - } - - enum Type{ - NORMAL, - CHECK_TYPE, - FIGHT_TYPE - } -} diff --git a/src/de/steamwar/sql/SQLWrapperImpl.java b/src/de/steamwar/sql/SQLWrapperImpl.java index f564ff2..176dfd4 100644 --- a/src/de/steamwar/sql/SQLWrapperImpl.java +++ b/src/de/steamwar/sql/SQLWrapperImpl.java @@ -20,6 +20,7 @@ package de.steamwar.sql; import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.commands.CheckCommand; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -29,12 +30,28 @@ import net.md_5.bungee.config.YamlConfiguration; import java.io.File; import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.Arrays; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class SQLWrapperImpl implements SQLWrapper { + + private static final SimpleDateFormat deadlineFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm"); + private static Date parseDeadline(String deadline) { + if(deadline == null) + return null; + + try { + return deadlineFormat.parse(deadline); + } catch (ParseException e) { + throw new SecurityException(e.getMessage(), e); + } + } + @Override public void loadSchemTypes(List tmpTypes, Map tmpFromDB) { File folder = new File(BungeeCore.get().getDataFolder().getParentFile(), "FightSystem"); @@ -63,11 +80,14 @@ public class SQLWrapperImpl implements SQLWrapper { checktype = new SchematicType("C" + type, "C" + shortcut, SchematicType.Type.CHECK_TYPE, null, material); tmpTypes.add(checktype); tmpFromDB.put(checktype.toDB(), checktype); + CheckCommand.setCheckQuestions(checktype, config); } - SchematicType current = new SchematicType(type, shortcut, !config.contains("Server") ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material); + SchematicType current = new SchematicType(type, shortcut, !config.contains("Server") ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, parseDeadline(config.getString("deadline", null))); tmpTypes.add(current); tmpFromDB.put(type.toLowerCase(), current); + if(checktype != null) + CheckCommand.addFightType(checktype, current); } } } From be6538c78d1b42286566bcd9a4cc3b8bcda0cf70 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 17 Feb 2023 11:47:58 +0100 Subject: [PATCH 13/31] WIP CommonDB Signed-off-by: Lixfel --- CommonCore | 2 +- src/de/steamwar/bungeecore/BungeeCore.java | 3 +- src/de/steamwar/bungeecore/EventStarter.java | 2 +- src/de/steamwar/bungeecore/ServerStarter.java | 2 +- .../bungeecore/bot/commands/TeamCommand.java | 2 +- .../bungeecore/bot/commands/WhoisCommand.java | 2 +- .../bot/listeners/DiscordEventListener.java | 2 +- .../commands/EventRescheduleCommand.java | 2 +- .../bungeecore/commands/TeamCommand.java | 2 +- .../bungeecore/commands/TpCommand.java | 2 +- .../bungeecore/commands/WhoisCommand.java | 1 + .../bungeecore/listeners/ChatListener.java | 1 + src/de/steamwar/bungeecore/sql/Team.java | 185 ------------------ 13 files changed, 13 insertions(+), 195 deletions(-) delete mode 100644 src/de/steamwar/bungeecore/sql/Team.java diff --git a/CommonCore b/CommonCore index d439ecb..3e1c4e9 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit d439ecb8d01d576310766e497c970bce7eb1db2f +Subproject commit 3e1c4e9059ef2400c79aaa5089eaafca075640c6 diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 6d3a3d7..cd52b48 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -34,6 +34,7 @@ import de.steamwar.command.SWCommandUtils; import de.steamwar.command.SWTypeMapperCreator; import de.steamwar.command.TabCompletionCache; import de.steamwar.command.TypeMapper; +import de.steamwar.sql.Team; import de.steamwar.sql.internal.Statement; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.ChatMessageType; @@ -200,7 +201,7 @@ public class BungeeCore extends Plugin { getProxy().getScheduler().schedule(this, () -> { SteamwarUser.clearCache(); UserElo.clearCache(); - Team.clearCache(); + Team.clear(); }, 1, 1, TimeUnit.HOURS); if (SteamwarDiscordBotConfig.loaded) { diff --git a/src/de/steamwar/bungeecore/EventStarter.java b/src/de/steamwar/bungeecore/EventStarter.java index 7113e5d..67a2d7e 100644 --- a/src/de/steamwar/bungeecore/EventStarter.java +++ b/src/de/steamwar/bungeecore/EventStarter.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore; import de.steamwar.bungeecore.sql.EventFight; import de.steamwar.bungeecore.sql.SteamwarUser; -import de.steamwar.bungeecore.sql.Team; +import de.steamwar.sql.Team; import de.steamwar.sql.Event; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; diff --git a/src/de/steamwar/bungeecore/ServerStarter.java b/src/de/steamwar/bungeecore/ServerStarter.java index f3b805a..5ad9a6f 100644 --- a/src/de/steamwar/bungeecore/ServerStarter.java +++ b/src/de/steamwar/bungeecore/ServerStarter.java @@ -2,7 +2,7 @@ package de.steamwar.bungeecore; import de.steamwar.bungeecore.sql.EventFight; import de.steamwar.bungeecore.sql.SteamwarUser; -import de.steamwar.bungeecore.sql.Team; +import de.steamwar.sql.Team; import de.steamwar.bungeecore.sql.Tutorial; import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.connection.ProxiedPlayer; diff --git a/src/de/steamwar/bungeecore/bot/commands/TeamCommand.java b/src/de/steamwar/bungeecore/bot/commands/TeamCommand.java index c6448eb..b8c5d4e 100644 --- a/src/de/steamwar/bungeecore/bot/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/TeamCommand.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.bot.commands; import de.steamwar.sql.Event; import de.steamwar.bungeecore.sql.SteamwarUser; -import de.steamwar.bungeecore.sql.Team; +import de.steamwar.sql.Team; import de.steamwar.sql.TeamTeilnahme; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Emoji; diff --git a/src/de/steamwar/bungeecore/bot/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/bot/commands/WhoisCommand.java index 8608047..0ce37b3 100644 --- a/src/de/steamwar/bungeecore/bot/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/WhoisCommand.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.bot.commands; import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; -import de.steamwar.bungeecore.sql.Team; +import de.steamwar.sql.Team; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; diff --git a/src/de/steamwar/bungeecore/bot/listeners/DiscordEventListener.java b/src/de/steamwar/bungeecore/bot/listeners/DiscordEventListener.java index 33054ee..c6f61e9 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/DiscordEventListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/DiscordEventListener.java @@ -22,7 +22,7 @@ package de.steamwar.bungeecore.bot.listeners; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.bot.events.EventManager; import de.steamwar.bungeecore.sql.SteamwarUser; -import de.steamwar.bungeecore.sql.Team; +import de.steamwar.sql.Team; import de.steamwar.sql.TeamTeilnahme; import de.steamwar.sql.Event; import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent; diff --git a/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java b/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java index e44a318..16e98e1 100644 --- a/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.sql.EventFight; -import de.steamwar.bungeecore.sql.Team; +import de.steamwar.sql.Team; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.sql.Event; diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index 3f45be6..e7ee335 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -25,7 +25,7 @@ import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.bungeecore.inventory.SWListInv; import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; -import de.steamwar.bungeecore.sql.Team; +import de.steamwar.sql.Team; import de.steamwar.sql.TeamTeilnahme; import de.steamwar.messages.ChatSender; import de.steamwar.sql.Event; diff --git a/src/de/steamwar/bungeecore/commands/TpCommand.java b/src/de/steamwar/bungeecore/commands/TpCommand.java index 9b48eaa..d7bb956 100644 --- a/src/de/steamwar/bungeecore/commands/TpCommand.java +++ b/src/de/steamwar/bungeecore/commands/TpCommand.java @@ -23,7 +23,7 @@ import de.steamwar.bungeecore.*; import de.steamwar.sql.BauweltMember; import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; -import de.steamwar.bungeecore.sql.Team; +import de.steamwar.sql.Team; import de.steamwar.bungeecore.util.BauLock; import de.steamwar.bungeecore.util.Chat19; import de.steamwar.messages.ChatSender; diff --git a/src/de/steamwar/bungeecore/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/commands/WhoisCommand.java index 095f0fc..856e99a 100644 --- a/src/de/steamwar/bungeecore/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/commands/WhoisCommand.java @@ -26,6 +26,7 @@ import de.steamwar.bungeecore.sql.*; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; +import de.steamwar.sql.Team; import de.steamwar.sql.UserGroup; import lombok.Getter; import net.md_5.bungee.BungeeCord; diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index 68e86f7..dd84a9f 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -26,6 +26,7 @@ import de.steamwar.bungeecore.sql.*; import de.steamwar.bungeecore.util.Chat19; import de.steamwar.messages.ChatSender; import de.steamwar.network.packets.server.PingPacket; +import de.steamwar.sql.Team; import de.steamwar.sql.UserGroup; import net.md_5.bungee.api.*; import net.md_5.bungee.api.connection.ProxiedPlayer; diff --git a/src/de/steamwar/bungeecore/sql/Team.java b/src/de/steamwar/bungeecore/sql/Team.java deleted file mode 100644 index 4cb71d8..0000000 --- a/src/de/steamwar/bungeecore/sql/Team.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.sql.TeamTeilnahme; -import de.steamwar.sql.internal.Statement; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -public class Team { - - private static final Statement insert = new Statement("INSERT INTO Team (TeamKuerzel, TeamName) VALUES (?, ?)"); - private static final Statement delete = new Statement("UPDATE Team SET TeamDeleted = 1 WHERE TeamID = ?"); - private static final Statement update = new Statement("INSERT INTO Team (TeamID, TeamKuerzel, TeamName, TeamColor, Address, Port) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE TeamName = VALUES(TeamName), TeamKuerzel = VALUES(TeamKuerzel), TeamColor = VALUES(TeamColor), Address = VALUES(Address), Port = VALUES(Port)"); - private static final Statement getSize = new Statement("SELECT COUNT(id) FROM UserData WHERE Team = ?"); - private static final Statement getMembers = new Statement("SELECT id FROM UserData WHERE Team = ?"); - private static final Statement byId = new Statement("SELECT * FROM Team WHERE TeamID = ?"); - private static final Statement byName = new Statement("SELECT * FROM Team WHERE (lower(TeamName) = ? OR lower(TeamKuerzel) = ?) AND NOT TeamDeleted"); - private static final Statement all = new Statement("SELECT * FROM Team WHERE NOT TeamDeleted"); - - private static final List teamCache = new LinkedList<>(); - private static final Team pub = new Team(0, "PUB", "Öffentlich", "8", null, 25565); - - private final int teamId; - private String teamKuerzel; - private String teamName; - private String teamColor; - private String address; - private int port; - - private Team(int id, String kuerzel, String name, String color, String address, int port){ - teamId = id; - teamKuerzel = kuerzel; - teamName = name; - teamColor = color; - if (id != 0) { - teamCache.add(this); - } - this.address = address; - this.port = port; - } - - private Team(ResultSet rs) throws SQLException { - this(rs.getInt("TeamID"), rs.getString("TeamKuerzel"), rs.getString("TeamName"), rs.getString("TeamColor"), rs.getString("Address"), rs.getInt("Port")); - } - - public static void create(String kuerzel, String name){ - insert.update(kuerzel, name); - } - - public static Team get(int id){ - if(id == -1) - return new Team(-1, "?", "?", "8", null, 25565); - if(id == 0) - return pub; - for(Team team : teamCache) - if(team.teamId == id) - return team; - return byId.select(rs -> { - rs.next(); - return new Team(rs); - }, id); - } - - public static Team get(String name){ - for(Team team : teamCache) - if(team.teamName.equalsIgnoreCase(name) || team.teamKuerzel.equalsIgnoreCase(name)) - return team; - return byName.select(rs -> { - if(rs.next()) - return new Team(rs); - return null; - }, name.toLowerCase(), name.toLowerCase()); - } - - public static List getAll(){ - clearCache(); - return all.select(rs -> { - while(rs.next()) - new Team(rs); - return teamCache; - }); - } - - public static void clearCache(){ - teamCache.clear(); - } - - private void updateDB(){ - update.update(teamId, teamKuerzel, teamName, teamColor, address, port); - } - - public int getTeamId() { - return teamId; - } - - public String getTeamKuerzel() { - return teamKuerzel; - } - - public void setTeamKuerzel(String teamKuerzel) { - this.teamKuerzel = teamKuerzel; - updateDB(); - } - - public String getTeamName() { - return teamName; - } - - public void setTeamName(String teamName) { - this.teamName = teamName; - updateDB(); - } - - public String getTeamColor() { - return teamColor; - } - - public void setTeamColor(String teamColor) { - this.teamColor = teamColor; - updateDB(); - } - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address; - updateDB(); - } - - public int getPort() { - return port; - } - - public void setPort(int port) { - this.port = port; - updateDB(); - } - - public int size(){ - return getSize.select(rs -> { - rs.next(); - return rs.getInt("COUNT(id)"); - }, teamId); - } - - public void disband(SteamwarUser user){ - user.setLeader(false); - delete.update(teamId); - teamCache.remove(this); - TeamTeilnahme.deleteFuture(teamId); - } - - public List getMembers(){ - return getMembers.select(rs -> { - List members = new ArrayList<>(); - while(rs.next()) - members.add(rs.getInt("id")); - return members; - }, teamId); - } -} From f524cb61dc311cf62998a87526217a82438d8106 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 17 Feb 2023 14:57:23 +0100 Subject: [PATCH 14/31] Final fixes --- .../bungeecore/commands/TeamCommand.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index 6185129..f8afef5 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -654,22 +654,4 @@ public class TeamCommand extends SWCommand { } return false; } - - // @Override - public Iterable onTabComplete(CommandSender commandSender, String[] args){ - List tab = new ArrayList<>(); - if(args.length == 2){ - if(args[1].equalsIgnoreCase("event")){ - List coming = Event.getComing(); - coming.forEach(event -> tab.add(event.getEventName())); - }else if(args[1].equalsIgnoreCase("join") || args[1].equalsIgnoreCase("info") || args[1].equalsIgnoreCase("tp")){ - List teams = Team.getAll(); - teams.forEach(team -> { - tab.add(team.getTeamName()); - tab.add(team.getTeamKuerzel()); - }); - } - } - return tab; - } } From b3a4c93c5947c60b059a4174d06283b01d66d832 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 17 Feb 2023 15:08:55 +0100 Subject: [PATCH 15/31] Update stuff --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index d12fbbd..89b0c14 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit d12fbbd339f6f34108301aa08d1377eceea250a5 +Subproject commit 89b0c14da664589a7c9699d73bf72028cdf9dd0d From 6de8ed282b4794687947bc0555e299cb084f9a79 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 17 Feb 2023 15:22:05 +0100 Subject: [PATCH 16/31] Add usage messsage on no permission --- src/de/steamwar/bungeecore/commands/JoinmeCommand.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java index 953655d..3b165ca 100644 --- a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java +++ b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java @@ -41,7 +41,10 @@ public class JoinmeCommand extends SWCommand { @Register(description = "JOINME_USAGE") public void genericCommand(ProxiedPlayer player) { - if (!player.hasPermission("bungeecore.joinme")) return; + if (!player.hasPermission("bungeecore.joinme")) { + Message.send("JOINME_USAGE", player); + return; + } Message.broadcast("JOINME_BROADCAST", "JOINME_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()), player.getName(), player.getServer().getInfo().getName()); } From 9dd3cb76970f04bf5a01bdad7c2426e043f4cd88 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 17 Feb 2023 15:27:20 +0100 Subject: [PATCH 17/31] Update JoinmeCommand ProxiedPlayer Validator Fix typos in TeamCommand --- .../bungeecore/commands/JoinmeCommand.java | 32 ++++--------------- .../bungeecore/commands/TeamCommand.java | 4 +-- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java index 3b165ca..7b707e5 100644 --- a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java +++ b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java @@ -21,18 +21,13 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.sql.BauweltMember; -import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; -import de.steamwar.command.TypeMapper; +import de.steamwar.command.TypeValidator; import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; -import java.util.Collection; -import java.util.stream.Collectors; - public class JoinmeCommand extends SWCommand { public JoinmeCommand() { @@ -87,26 +82,13 @@ public class JoinmeCommand extends SWCommand { } @ClassMapper(ProxiedPlayer.class) - public TypeMapper playerMapper() { - return new TypeMapper() { - @Override - public ProxiedPlayer map(CommandSender commandSender, String[] previousArguments, String s) { - return ProxyServer.getInstance().getPlayer(s); - } - - @Override - public boolean validate(CommandSender sender, ProxiedPlayer value, MessageSender messageSender) { - if (value == null || !value.isConnected()) { - messageSender.send("JOINME_PLAYER_OFFLINE", sender); - return false; - } - return true; - } - - @Override - public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { - return ProxyServer.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()); + public TypeValidator playerMapper() { + return (sender, value, messageSender) -> { + if (value == null || !value.isConnected()) { + messageSender.send("JOINME_PLAYER_OFFLINE", sender); + return false; } + return true; }; } } diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index f8afef5..dbe2ad7 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -114,7 +114,7 @@ public class TeamCommand extends SWCommand { } @Register(value = "create", description = "TEAM_CREATE_USAGE") - public void create(ProxiedPlayer player, @Length(min = 2, max = 4) @ErrorMessage("TEAM_KUERZEL_LENGHT") String kuerzel, @Length(min = 4, max = 15) @ErrorMessage("TEAM_NAME_LENGHT") String name){ + public void create(ProxiedPlayer player, @Length(min = 2, max = 4) @ErrorMessage("TEAM_KUERZEL_LENGTH") String kuerzel, @Length(min = 4, max = 15) @ErrorMessage("TEAM_NAME_LENGTH") String name){ SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Team team = Team.get(user.getTeam()); if(unwantedInTeam(player, user)) @@ -299,7 +299,7 @@ public class TeamCommand extends SWCommand { } @Register(value = "changekurzel", description = "TEAM_KUERZEL_USAGE") - public void changekuerzel(ProxiedPlayer player, @Length(min = 2, max = 4) @ErrorMessage("TEAM_KUERZEL_LENGHT") String kuerzel){ + public void changekuerzel(ProxiedPlayer player, @Length(min = 2, max = 4) @ErrorMessage("TEAM_KUERZEL_LENGTH") String kuerzel){ SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Team team = Team.get(user.getTeam()); if(notLeader(player, user)) From 42c23e452194ae270c076443b3cb333093fe309b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 18 Feb 2023 11:04:29 +0100 Subject: [PATCH 18/31] Add exception log --- .../bungeecore/listeners/NonFabricFabricCheck.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java b/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java index b903b9c..2a1fd2b 100644 --- a/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java +++ b/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java @@ -22,6 +22,8 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Storage; +import de.steamwar.bungeecore.sql.SWException; +import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.connection.Connection; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -80,7 +82,12 @@ public class NonFabricFabricCheck extends BasicListener { @EventHandler public void onPlayerDisconnect(PlayerDisconnectEvent e) { if (checking.remove(e.getPlayer())) { + logMessage(SteamwarUser.get(e.getPlayer().getUniqueId()), "Player is potentially using rebranded Fabric"); usingFabric.add(e.getPlayer().getUniqueId()); } } + + public void logMessage(SteamwarUser user, String reason) { + SWException.log("Bungee", "NonFabricFabricCheck " + user.getUserName() + ": " + reason, ""); + } } From 05b6b3ac66748186405e5142823ad9a5b48e611b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 18 Feb 2023 12:49:24 +0100 Subject: [PATCH 19/31] Add even better fabric check --- .../listeners/NonFabricFabricCheck.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java b/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java index 2a1fd2b..08f44a0 100644 --- a/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java +++ b/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java @@ -22,8 +22,6 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Storage; -import de.steamwar.bungeecore.sql.SWException; -import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.connection.Connection; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -43,6 +41,7 @@ public class NonFabricFabricCheck extends BasicListener { private final Set usingFabric = new HashSet<>(); private final Set checking = new HashSet<>(); + private final Set vanilla = new HashSet<>(); { BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), usingFabric::clear, 0, 15, TimeUnit.MINUTES); @@ -54,14 +53,23 @@ public class NonFabricFabricCheck extends BasicListener { if(!(sender instanceof ProxiedPlayer)) return; - if(!e.getTag().equals("minecraft:brand")) - return; - - if(!new String(e.getData()).equals("vanilla")){ + ProxiedPlayer p = (ProxiedPlayer) sender; + if (e.getTag().equals("minecraft:register") && new String(e.getData()).contains("fabric")) { + BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { + if (!sender.isConnected()) return; + if (!vanilla.remove(p)) return; + if (Storage.fabricCheckedPlayers.containsKey(p)) return; + p.disconnect(Message.parse("MOD_USE_MODSENDER", p)); + }, 5, TimeUnit.SECONDS); return; } - ProxiedPlayer p = (ProxiedPlayer) sender; + if(!e.getTag().equals("minecraft:brand")) + return; + + if(!new String(e.getData()).equals("vanilla")) + return; + vanilla.add(p); BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { if (!p.isConnected()) return; @@ -82,12 +90,8 @@ public class NonFabricFabricCheck extends BasicListener { @EventHandler public void onPlayerDisconnect(PlayerDisconnectEvent e) { if (checking.remove(e.getPlayer())) { - logMessage(SteamwarUser.get(e.getPlayer().getUniqueId()), "Player is potentially using rebranded Fabric"); usingFabric.add(e.getPlayer().getUniqueId()); } - } - - public void logMessage(SteamwarUser user, String reason) { - SWException.log("Bungee", "NonFabricFabricCheck " + user.getUserName() + ": " + reason, ""); + vanilla.remove(e.getPlayer()); } } From 0dd50c7e09ec42402825ae13fb001426cad2340e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 18 Feb 2023 12:54:34 +0100 Subject: [PATCH 20/31] Update timings --- src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java b/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java index 08f44a0..3c2dbb8 100644 --- a/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java +++ b/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java @@ -60,7 +60,7 @@ public class NonFabricFabricCheck extends BasicListener { if (!vanilla.remove(p)) return; if (Storage.fabricCheckedPlayers.containsKey(p)) return; p.disconnect(Message.parse("MOD_USE_MODSENDER", p)); - }, 5, TimeUnit.SECONDS); + }, 25, TimeUnit.SECONDS); return; } From c4bafb459186e000cf962baec7865422ce1c3c21 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 21 Feb 2023 18:22:42 +0100 Subject: [PATCH 21/31] WIP CommonDB: Milestone SWUser Signed-off-by: Lixfel --- CommonCore | 2 +- src/de/steamwar/bungeecore/BungeeCore.java | 7 +- src/de/steamwar/bungeecore/EventStarter.java | 6 +- src/de/steamwar/bungeecore/ServerStarter.java | 10 +- .../steamwar/bungeecore/SubserverSystem.java | 2 +- .../steamwar/bungeecore/bot/AuthManager.java | 2 +- .../bungeecore/bot/commands/BanCommand.java | 7 +- .../bot/commands/BasicDiscordCommand.java | 2 +- .../bungeecore/bot/commands/MuteCommand.java | 6 +- .../bungeecore/bot/commands/TeamCommand.java | 4 +- .../bungeecore/bot/commands/UnbanCommand.java | 9 +- .../bungeecore/bot/commands/WhoisCommand.java | 6 +- .../bungeecore/bot/events/EventManager.java | 2 +- .../bot/events/SchematicsManager.java | 2 +- .../bot/listeners/DiscordAuthListener.java | 2 +- .../bot/listeners/DiscordChatListener.java | 4 +- .../bot/listeners/DiscordEventListener.java | 2 +- .../bot/listeners/DiscordTicketListener.java | 4 +- .../bot/listeners/PrivateMessageListener.java | 5 +- .../bungeecore/bot/util/DiscordRanks.java | 2 +- .../bot/util/DiscordSchemAlert.java | 2 +- .../bungeecore/commands/BasicCommand.java | 4 +- .../bungeecore/commands/BauCommand.java | 30 +- .../bungeecore/commands/BugCommand.java | 2 +- .../bungeecore/commands/CalendarCommand.java | 4 +- .../bungeecore/commands/CheckCommand.java | 6 +- .../bungeecore/commands/DevCommand.java | 8 +- .../bungeecore/commands/EventCommand.java | 2 +- .../commands/EventRescheduleCommand.java | 2 +- .../commands/EventreloadCommand.java | 2 +- .../bungeecore/commands/FightCommand.java | 3 - .../bungeecore/commands/GDPRQuery.java | 14 +- .../bungeecore/commands/IgnoreCommand.java | 3 +- .../bungeecore/commands/ModCommand.java | 4 +- .../bungeecore/commands/PlaytimeCommand.java | 8 +- .../bungeecore/commands/PollCommand.java | 2 +- .../commands/PunishmentCommand.java | 95 ++++- .../bungeecore/commands/RankCommand.java | 3 +- .../bungeecore/commands/ReplayCommand.java | 10 +- .../bungeecore/commands/SetLocaleCommand.java | 3 + .../bungeecore/commands/TeamCommand.java | 12 +- .../bungeecore/commands/TeamchatCommand.java | 2 +- .../bungeecore/commands/TpCommand.java | 8 +- .../bungeecore/commands/TutorialCommand.java | 4 +- .../bungeecore/commands/TypeMappers.java | 5 +- .../bungeecore/commands/UnIgnoreCommand.java | 2 +- .../bungeecore/commands/VerifyCommand.java | 2 +- .../bungeecore/commands/WhoisCommand.java | 16 +- .../bungeecore/inventory/SWInventory.java | 10 +- .../bungeecore/listeners/BanListener.java | 16 +- .../bungeecore/listeners/ChatListener.java | 12 +- .../bungeecore/listeners/CheckListener.java | 2 +- .../listeners/ConnectionListener.java | 2 +- .../listeners/EventModeListener.java | 4 +- .../bungeecore/listeners/PollSystem.java | 2 +- .../bungeecore/listeners/SessionManager.java | 4 +- .../listeners/SettingsChangedListener.java | 8 +- .../bungeecore/listeners/mods/Fabric.java | 6 +- .../bungeecore/listeners/mods/Forge.java | 2 +- .../bungeecore/listeners/mods/Forge12.java | 2 +- .../bungeecore/listeners/mods/LabyMod.java | 2 +- .../bungeecore/listeners/mods/Utils.java | 10 +- .../listeners/mods/WorldDownloader.java | 2 +- .../handlers/ExecuteCommandHandler.java | 4 +- .../network/handlers/FightEndsHandler.java | 6 +- .../handlers/InventoryCallbackHandler.java | 6 +- .../network/handlers/PrepareSchemHandler.java | 4 +- .../bungeecore/sql/CheckedSchematic.java | 1 + .../steamwar/bungeecore/sql/EventFight.java | 150 ------- src/de/steamwar/bungeecore/sql/Fight.java | 145 ------- .../steamwar/bungeecore/sql/IgnoreSystem.java | 1 + src/de/steamwar/bungeecore/sql/Mod.java | 127 ------ .../steamwar/bungeecore/sql/NodeMember.java | 86 ---- .../steamwar/bungeecore/sql/Punishment.java | 160 ------- src/de/steamwar/bungeecore/sql/SchemElo.java | 52 --- .../bungeecore/sql/SchematicNode.java | 2 + .../steamwar/bungeecore/sql/SteamwarUser.java | 398 ------------------ src/de/steamwar/bungeecore/sql/Tutorial.java | 123 ------ src/de/steamwar/bungeecore/sql/UserElo.java | 1 + .../bungeecore/tablist/TablistPart.java | 2 +- .../bungeecore/tablist/TablistServer.java | 4 +- src/de/steamwar/bungeecore/util/BauLock.java | 4 +- src/de/steamwar/command/TypeUtils.java | 2 +- src/de/steamwar/messages/ChatSender.java | 2 +- 84 files changed, 278 insertions(+), 1430 deletions(-) delete mode 100644 src/de/steamwar/bungeecore/sql/EventFight.java delete mode 100644 src/de/steamwar/bungeecore/sql/Fight.java delete mode 100644 src/de/steamwar/bungeecore/sql/Mod.java delete mode 100644 src/de/steamwar/bungeecore/sql/NodeMember.java delete mode 100644 src/de/steamwar/bungeecore/sql/Punishment.java delete mode 100644 src/de/steamwar/bungeecore/sql/SchemElo.java delete mode 100644 src/de/steamwar/bungeecore/sql/SteamwarUser.java delete mode 100644 src/de/steamwar/bungeecore/sql/Tutorial.java diff --git a/CommonCore b/CommonCore index 3e1c4e9..8dbf62e 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 3e1c4e9059ef2400c79aaa5089eaafca075640c6 +Subproject commit 8dbf62e560de95615d93057481e8202ec11c85c4 diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 1ff556b..f1aec11 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -28,9 +28,8 @@ import de.steamwar.bungeecore.listeners.ping.PingListener; import de.steamwar.bungeecore.network.BungeeNetworkHandler; import de.steamwar.bungeecore.network.NetworkReceiver; import de.steamwar.bungeecore.network.SWScriptSyntaxForwarder; -import de.steamwar.bungeecore.sql.Punishment; -import de.steamwar.bungeecore.sql.SteamwarUser; -import de.steamwar.bungeecore.sql.Team; +import de.steamwar.sql.Punishment; +import de.steamwar.sql.SteamwarUser; import de.steamwar.bungeecore.sql.UserElo; import de.steamwar.bungeecore.tablist.TablistManager; import de.steamwar.command.SWCommandUtils; @@ -206,7 +205,7 @@ public class BungeeCore extends Plugin { new SettingsChangedListener(); getProxy().getScheduler().schedule(this, () -> { - SteamwarUser.clearCache(); + SteamwarUser.clear(); UserElo.clearCache(); Team.clear(); }, 1, 1, TimeUnit.HOURS); diff --git a/src/de/steamwar/bungeecore/EventStarter.java b/src/de/steamwar/bungeecore/EventStarter.java index 67a2d7e..ddf78bd 100644 --- a/src/de/steamwar/bungeecore/EventStarter.java +++ b/src/de/steamwar/bungeecore/EventStarter.java @@ -19,8 +19,8 @@ package de.steamwar.bungeecore; -import de.steamwar.bungeecore.sql.EventFight; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.EventFight; +import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.Team; import de.steamwar.sql.Event; import net.md_5.bungee.api.ProxyServer; @@ -66,7 +66,7 @@ public class EventStarter implements Runnable { if(BungeeCore.EVENT_MODE || !Event.get(next.getEventID()).spectateSystem()) { ServerStarter starter = new ServerStarter().event(next); - ProxiedPlayer leiter = ProxyServer.getInstance().getPlayer(SteamwarUser.get(next.getKampfleiter()).getUuid()); + ProxiedPlayer leiter = ProxyServer.getInstance().getPlayer(SteamwarUser.get(next.getKampfleiter()).getUUID()); if(leiter != null) starter.send(leiter); diff --git a/src/de/steamwar/bungeecore/ServerStarter.java b/src/de/steamwar/bungeecore/ServerStarter.java index 5ad9a6f..d2ec14f 100644 --- a/src/de/steamwar/bungeecore/ServerStarter.java +++ b/src/de/steamwar/bungeecore/ServerStarter.java @@ -1,9 +1,9 @@ package de.steamwar.bungeecore; -import de.steamwar.bungeecore.sql.EventFight; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.EventFight; +import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.Team; -import de.steamwar.bungeecore.sql.Tutorial; +import de.steamwar.sql.Tutorial; import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -67,13 +67,13 @@ public class ServerStarter { } public ServerStarter event(EventFight eventFight) { - arena(eventFight.getSpielmodus(), eventFight.getMap()); + arena(ArenaMode.getByInternal(eventFight.getSpielmodus()), eventFight.getMap()); node = BungeeCore.local; worldDir = EVENT_PATH; worldCleanup = () -> {}; arguments.put("fightID", String.valueOf(eventFight.getFightID())); fightMap = eventFight.getMap(); - gameMode = eventFight.getSpielmodus().getInternalName(); + gameMode = eventFight.getSpielmodus(); String serverName = Team.get(eventFight.getTeamBlue()).getTeamKuerzel() + " vs " + Team.get(eventFight.getTeamRed()).getTeamKuerzel(); serverNameProvider = port -> serverName; diff --git a/src/de/steamwar/bungeecore/SubserverSystem.java b/src/de/steamwar/bungeecore/SubserverSystem.java index 9842154..b751f6e 100644 --- a/src/de/steamwar/bungeecore/SubserverSystem.java +++ b/src/de/steamwar/bungeecore/SubserverSystem.java @@ -22,7 +22,7 @@ package de.steamwar.bungeecore; import de.steamwar.bungeecore.network.NetworkSender; import de.steamwar.bungeecore.network.handlers.FightInfoHandler; import de.steamwar.bungeecore.sql.IgnoreSystem; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.network.packets.server.StartingServerPacket; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; diff --git a/src/de/steamwar/bungeecore/bot/AuthManager.java b/src/de/steamwar/bungeecore/bot/AuthManager.java index ac4f553..8500f12 100644 --- a/src/de/steamwar/bungeecore/bot/AuthManager.java +++ b/src/de/steamwar/bungeecore/bot/AuthManager.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.bot; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.entities.Emoji; import net.dv8tion.jda.api.entities.Member; diff --git a/src/de/steamwar/bungeecore/bot/commands/BanCommand.java b/src/de/steamwar/bungeecore/bot/commands/BanCommand.java index e328997..ed6569e 100644 --- a/src/de/steamwar/bungeecore/bot/commands/BanCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/BanCommand.java @@ -21,8 +21,7 @@ package de.steamwar.bungeecore.bot.commands; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.commands.PunishmentCommand; -import de.steamwar.bungeecore.sql.Punishment; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; @@ -45,7 +44,7 @@ public class BanCommand extends BasicDiscordCommand { } SteamwarUser sender = SteamwarUser.get(event.getMember().getIdLong()); - SteamwarUser target = SteamwarUser.getOrCreateOfflinePlayer(event.getOption("user").getAsString()); + SteamwarUser target = PunishmentCommand.getOrCreateOfflinePlayer(event.getOption("user").getAsString()); if (target == null) { event.reply("Angegebener User invalide").setEphemeral(true).queue(); return; @@ -60,7 +59,7 @@ public class BanCommand extends BasicDiscordCommand { String msg = event.getOption("reason").getAsString(); boolean isPerma = event.getOption("time").getAsString().equals("perma"); - target.punish(Punishment.PunishmentType.Ban, time, msg, sender.getId(), isPerma); + PunishmentCommand.ban(target, time, msg, sender, isPerma); Message.team("BAN_TEAM", new Message("PREFIX"), target.getUserName(), sender.getUserName(), new Message((isPerma ? "BAN_PERMA" : "BAN_UNTIL"), time), msg); event.reply("Erfolgreich " + target.getUserName() + (isPerma ? " permanent" : " bis " + time) + " gebannt").setEphemeral(true).queue(); } diff --git a/src/de/steamwar/bungeecore/bot/commands/BasicDiscordCommand.java b/src/de/steamwar/bungeecore/bot/commands/BasicDiscordCommand.java index 00ec1b8..8dbb58b 100644 --- a/src/de/steamwar/bungeecore/bot/commands/BasicDiscordCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/BasicDiscordCommand.java @@ -19,7 +19,7 @@ package de.steamwar.bungeecore.bot.commands; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserGroup; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; diff --git a/src/de/steamwar/bungeecore/bot/commands/MuteCommand.java b/src/de/steamwar/bungeecore/bot/commands/MuteCommand.java index 086cf77..3c296f4 100644 --- a/src/de/steamwar/bungeecore/bot/commands/MuteCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/MuteCommand.java @@ -21,8 +21,8 @@ package de.steamwar.bungeecore.bot.commands; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.commands.PunishmentCommand; -import de.steamwar.bungeecore.sql.Punishment; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.Punishment; +import de.steamwar.sql.SteamwarUser; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; @@ -45,7 +45,7 @@ public class MuteCommand extends BasicDiscordCommand { } SteamwarUser sender = SteamwarUser.get(event.getMember().getIdLong()); - SteamwarUser target = SteamwarUser.getOrCreateOfflinePlayer(event.getOption("user").getAsString()); + SteamwarUser target = PunishmentCommand.getOrCreateOfflinePlayer(event.getOption("user").getAsString()); if (target == null) { event.reply("Angegebener User invalide").setEphemeral(true).complete(); return; diff --git a/src/de/steamwar/bungeecore/bot/commands/TeamCommand.java b/src/de/steamwar/bungeecore/bot/commands/TeamCommand.java index b8c5d4e..c07dbf2 100644 --- a/src/de/steamwar/bungeecore/bot/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/TeamCommand.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.bot.commands; import de.steamwar.sql.Event; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.Team; import de.steamwar.sql.TeamTeilnahme; import net.dv8tion.jda.api.EmbedBuilder; @@ -91,6 +91,6 @@ public class TeamCommand extends BasicDiscordCommand { } private boolean isOnline(SteamwarUser user) { - return ProxyServer.getInstance().getPlayer(user.getUuid()) != null; + return ProxyServer.getInstance().getPlayer(user.getUUID()) != null; } } diff --git a/src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java b/src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java index f8d6185..61d5c0d 100644 --- a/src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java @@ -19,8 +19,10 @@ package de.steamwar.bungeecore.bot.commands; -import de.steamwar.bungeecore.sql.Punishment; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.bungeecore.commands.PunishmentCommand; +import de.steamwar.sql.BannedUserIPs; +import de.steamwar.sql.Punishment; +import de.steamwar.sql.SteamwarUser; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; @@ -42,7 +44,7 @@ public class UnbanCommand extends BasicDiscordCommand { } SteamwarUser sender = SteamwarUser.get(event.getMember().getIdLong()); - SteamwarUser target = SteamwarUser.getOrCreateOfflinePlayer(event.getOption("user").getAsString()); + SteamwarUser target = PunishmentCommand.getOrCreateOfflinePlayer(event.getOption("user").getAsString()); if (target == null) { event.reply("Angegebener User invalide").setEphemeral(true).queue(); return; @@ -54,6 +56,7 @@ public class UnbanCommand extends BasicDiscordCommand { } target.punish(Punishment.PunishmentType.Ban, Timestamp.from(new Date().toInstant()), "Unban", sender.getId(), false); + BannedUserIPs.unbanIPs(target.getId()); event.reply("Erfolgreich " + target.getUserName() + " entbannt").setEphemeral(true).queue(); } } diff --git a/src/de/steamwar/bungeecore/bot/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/bot/commands/WhoisCommand.java index 0ce37b3..d253372 100644 --- a/src/de/steamwar/bungeecore/bot/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/WhoisCommand.java @@ -19,8 +19,8 @@ package de.steamwar.bungeecore.bot.commands; -import de.steamwar.bungeecore.sql.Punishment; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.Punishment; +import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.Team; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; @@ -72,7 +72,7 @@ public class WhoisCommand extends BasicDiscordCommand { EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder.setTitle("Whois: " + user.getUserName()); StringBuilder st = new StringBuilder(); - st.append("UUID: ").append(user.getUuid()).append("\n"); + st.append("UUID: ").append(user.getUUID()).append("\n"); st.append("ID: ").append(user.getId()).append("\n"); if (user.getDiscordId() != null) { st.append("DiscordID: ").append(user.getDiscordId()).append("\n"); diff --git a/src/de/steamwar/bungeecore/bot/events/EventManager.java b/src/de/steamwar/bungeecore/bot/events/EventManager.java index 1cd09d3..884dd28 100644 --- a/src/de/steamwar/bungeecore/bot/events/EventManager.java +++ b/src/de/steamwar/bungeecore/bot/events/EventManager.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.bot.events; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; -import de.steamwar.bungeecore.sql.EventFight; +import de.steamwar.sql.EventFight; import de.steamwar.sql.Team; import de.steamwar.sql.TeamTeilnahme; import de.steamwar.sql.Event; diff --git a/src/de/steamwar/bungeecore/bot/events/SchematicsManager.java b/src/de/steamwar/bungeecore/bot/events/SchematicsManager.java index e407cf9..e53bf9a 100644 --- a/src/de/steamwar/bungeecore/bot/events/SchematicsManager.java +++ b/src/de/steamwar/bungeecore/bot/events/SchematicsManager.java @@ -22,7 +22,7 @@ package de.steamwar.bungeecore.bot.events; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.commands.CheckCommand; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import lombok.experimental.UtilityClass; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.MessageBuilder; diff --git a/src/de/steamwar/bungeecore/bot/listeners/DiscordAuthListener.java b/src/de/steamwar/bungeecore/bot/listeners/DiscordAuthListener.java index 8ad3428..947ed5e 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/DiscordAuthListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/DiscordAuthListener.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.bot.listeners; import de.steamwar.bungeecore.bot.AuthManager; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import net.dv8tion.jda.api.entities.ChannelType; import net.dv8tion.jda.api.events.interaction.GenericComponentInteractionCreateEvent; import net.dv8tion.jda.api.interactions.InteractionType; diff --git a/src/de/steamwar/bungeecore/bot/listeners/DiscordChatListener.java b/src/de/steamwar/bungeecore/bot/listeners/DiscordChatListener.java index 70004ac..13b5fca 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/DiscordChatListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/DiscordChatListener.java @@ -22,8 +22,8 @@ package de.steamwar.bungeecore.bot.listeners; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.listeners.ChatListener; -import de.steamwar.bungeecore.sql.Punishment; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.Punishment; +import de.steamwar.sql.SteamwarUser; import de.steamwar.messages.ChatSender; import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.entities.Member; diff --git a/src/de/steamwar/bungeecore/bot/listeners/DiscordEventListener.java b/src/de/steamwar/bungeecore/bot/listeners/DiscordEventListener.java index c6f61e9..b21f427 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/DiscordEventListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/DiscordEventListener.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.bot.listeners; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.bot.events.EventManager; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.Team; import de.steamwar.sql.TeamTeilnahme; import de.steamwar.sql.Event; diff --git a/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java b/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java index f7a2fa2..525dd08 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java @@ -23,7 +23,7 @@ import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.bot.config.DiscordTicketType; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.Permission; @@ -138,7 +138,7 @@ public class DiscordTicketListener extends BasicDiscordListener { if(!event.getChannel().getId().equals(SteamwarDiscordBotConfig.TICKET_CHANNEL) && !event.getChannel().getId().equals(SteamwarDiscordBotConfig.TICKET_LOG)) { BungeeCore.get().getProxy().getPlayers().forEach(player -> { if(event.getAuthor().isBot() || event.getAuthor().isSystem()) return; - SteamwarUser user = SteamwarUser.get(player); + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); boolean sendMessage; if(user.getDiscordId() == null) { sendMessage = user.getUserGroup().isCheckSchematics(); diff --git a/src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java b/src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java index 8aafe2f..0891c87 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java @@ -19,14 +19,13 @@ package de.steamwar.bungeecore.bot.listeners; import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.sql.Punishment; +import de.steamwar.sql.Punishment; import de.steamwar.bungeecore.sql.SchematicNode; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent; import java.io.InputStream; -import java.util.concurrent.CompletableFuture; public class PrivateMessageListener extends BasicDiscordListener { diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java b/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java index 7224576..e9ec857 100644 --- a/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java +++ b/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.bot.util; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import lombok.experimental.UtilityClass; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Role; diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java b/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java index f0d9d7b..9d9e2c7 100644 --- a/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java +++ b/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.bot.util; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; import de.steamwar.bungeecore.sql.SchematicNode; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import lombok.experimental.UtilityClass; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.MessageBuilder; diff --git a/src/de/steamwar/bungeecore/commands/BasicCommand.java b/src/de/steamwar/bungeecore/commands/BasicCommand.java index d4b9c0a..bb62a6e 100644 --- a/src/de/steamwar/bungeecore/commands/BasicCommand.java +++ b/src/de/steamwar/bungeecore/commands/BasicCommand.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -61,7 +61,7 @@ abstract class BasicCommand extends Command implements TabExecutor { } protected SteamwarUser unsafeUser(CommandSender sender, String arg){ - SteamwarUser target = SteamwarUser.getOrCreateOfflinePlayer(arg); + SteamwarUser target = PunishmentCommand.getOrCreateOfflinePlayer(arg); if(target == null) Message.send("UNKNOWN_PLAYER", sender); return target; diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index b73855f..9cc60da 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -23,7 +23,6 @@ import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.bungeecore.network.NetworkSender; -import de.steamwar.bungeecore.sql.*; import de.steamwar.bungeecore.util.BauLock; import de.steamwar.bungeecore.util.Chat19; import de.steamwar.command.SWCommand; @@ -33,6 +32,7 @@ import de.steamwar.messages.ChatSender; import de.steamwar.network.packets.server.BaumemberUpdatePacket; import de.steamwar.bungeecore.util.BauLockState; import de.steamwar.sql.BauweltMember; +import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; @@ -123,10 +123,10 @@ public class BauCommand extends SWCommand { @Register(value = "addmember", description = "BAU_ADDMEMBER_USAGE") public void addmember(ProxiedPlayer p, @Validator("addMemberTarget") SteamwarUser target) { - BauweltMember.addMember(p.getUniqueId(), target.getUuid()); + BauweltMember.addMember(p.getUniqueId(), target.getUUID()); Message.send("BAU_ADDMEMBER_ADDED", p); - ProxiedPlayer z = ProxyServer.getInstance().getPlayer(target.getUuid()); + ProxiedPlayer z = ProxyServer.getInstance().getPlayer(target.getUUID()); if(z != null) Message.send("BAU_ADDMEMBER_ADDED_TARGET", z, p.getName()); } @@ -138,11 +138,11 @@ public class BauCommand extends SWCommand { messageSender.send("UNKNOWN_PLAYER"); return false; } - if (((ProxiedPlayer) sender).getUniqueId().equals(value.getUuid())) { + if (((ProxiedPlayer) sender).getUniqueId().equals(value.getUUID())) { messageSender.send("BAU_ADDMEMBER_SELFADD"); return false; } - if (BauweltMember.getBauMember(((ProxiedPlayer) sender).getUniqueId(), value.getUuid()) != null) { + if (BauweltMember.getBauMember(((ProxiedPlayer) sender).getUniqueId(), value.getUUID()) != null) { messageSender.send("BAU_ADDMEMBER_ISADDED"); return false; } @@ -154,9 +154,9 @@ public class BauCommand extends SWCommand { @Register("teleport") public void teleport(ProxiedPlayer p, @Validator("teleportTarget") SteamwarUser worldOwner, @Mapper("version") @OptionalValue(value = "", onlyUINIG = true) int version) { versionSelector(version, - () -> new ServerStarter().build12(worldOwner.getUuid()).send(p).start(), - () -> new ServerStarter().build15(worldOwner.getUuid()).send(p).start(), - () -> new ServerStarter().build19(worldOwner.getUuid()).send(p).start() + () -> new ServerStarter().build12(worldOwner.getUUID()).send(p).start(), + () -> new ServerStarter().build15(worldOwner.getUUID()).send(p).start(), + () -> new ServerStarter().build19(worldOwner.getUUID()).send(p).start() ); } @@ -168,12 +168,12 @@ public class BauCommand extends SWCommand { return false; } ProxiedPlayer p = (ProxiedPlayer) sender; - if (!p.getUniqueId().equals(value.getUuid()) && BauweltMember.getBauMember(value.getUuid(), p.getUniqueId()) == null) { - SubserverSystem.sendDeniedMessage(p, value.getUuid()); + if (!p.getUniqueId().equals(value.getUUID()) && BauweltMember.getBauMember(value.getUUID(), p.getUniqueId()) == null) { + SubserverSystem.sendDeniedMessage(p, value.getUUID()); messageSender.send("BAU_TP_NOALLOWED"); return false; } - if(BauLock.isLocked(value, SteamwarUser.get(p))) { + if(BauLock.isLocked(value, SteamwarUser.get(p.getUniqueId()))) { messageSender.send("BAU_LOCKED_NOALLOWED"); return false; } @@ -232,13 +232,13 @@ public class BauCommand extends SWCommand { if (target == null) return; - if(SteamwarUser.get(target.getMemberID()).getUuid().equals(p.getUniqueId())) { + if(SteamwarUser.get(target.getMemberID()).getUUID().equals(p.getUniqueId())) { Message.send("BAU_DELMEMBER_SELFDEL", p); return; } target.remove(); - ProxiedPlayer toRemove = ProxyServer.getInstance().getPlayer(SteamwarUser.get(target.getMemberID()).getUuid()); + ProxiedPlayer toRemove = ProxyServer.getInstance().getPlayer(SteamwarUser.get(target.getMemberID()).getUUID()); if(toRemove != null){ Message.send("BAU_DELMEMBER_DELETED_TARGET", toRemove, p.getName()); Subserver currentServer = Subserver.getSubserver(toRemove.getServer().getInfo()); @@ -309,7 +309,7 @@ public class BauCommand extends SWCommand { return null; } - BauweltMember target = BauweltMember.getBauMember(p.getUniqueId(), member.getUuid()); + BauweltMember target = BauweltMember.getBauMember(p.getUniqueId(), member.getUUID()); if (target == null) { Message.send("BAU_MEMBER_NOMEMBER", p); return null; @@ -318,7 +318,7 @@ public class BauCommand extends SWCommand { } private static void isAllowedTo(boolean permission, ProxiedPlayer p, BauweltMember target, String what){ - ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(target.getMemberID()).getUuid()); + ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(target.getMemberID()).getUUID()); if(permission){ if(player != null) diff --git a/src/de/steamwar/bungeecore/commands/BugCommand.java b/src/de/steamwar/bungeecore/commands/BugCommand.java index b3e5990..f93e23d 100644 --- a/src/de/steamwar/bungeecore/commands/BugCommand.java +++ b/src/de/steamwar/bungeecore/commands/BugCommand.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.sql.SWException; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.connection.ProxiedPlayer; diff --git a/src/de/steamwar/bungeecore/commands/CalendarCommand.java b/src/de/steamwar/bungeecore/commands/CalendarCommand.java index 5d203db..d3163ca 100644 --- a/src/de/steamwar/bungeecore/commands/CalendarCommand.java +++ b/src/de/steamwar/bungeecore/commands/CalendarCommand.java @@ -22,9 +22,9 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.inventory.SWItem; -import de.steamwar.bungeecore.sql.NodeMember; +import de.steamwar.sql.NodeMember; import de.steamwar.bungeecore.sql.SchematicNode; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; import net.md_5.bungee.api.connection.ProxiedPlayer; diff --git a/src/de/steamwar/bungeecore/commands/CheckCommand.java b/src/de/steamwar/bungeecore/commands/CheckCommand.java index 5cab0c2..521eef1 100644 --- a/src/de/steamwar/bungeecore/commands/CheckCommand.java +++ b/src/de/steamwar/bungeecore/commands/CheckCommand.java @@ -25,7 +25,7 @@ import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.bungeecore.sql.CheckedSchematic; import de.steamwar.bungeecore.sql.SchematicNode; import de.steamwar.sql.SchematicType; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ProxyServer; @@ -279,7 +279,7 @@ public class CheckCommand extends SWCommand { schematic.setType(fightTypes.get(schematic.getSchemtype()).toDB()); SteamwarUser user = SteamwarUser.get(schematic.getOwner()); - ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid()); + ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUUID()); if(player != null) { Message.send("CHECK_ACCEPTED", player, schematic.getSchemtype().name(), schematic.getName()); } else { @@ -293,7 +293,7 @@ public class CheckCommand extends SWCommand { private void decline(String reason){ if(createLog(reason)) { SteamwarUser user = SteamwarUser.get(schematic.getOwner()); - ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid()); + ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUUID()); if(player != null) { Message.send("CHECK_DECLINED", player, schematic.getSchemtype().name(), schematic.getName(), reason); } else { diff --git a/src/de/steamwar/bungeecore/commands/DevCommand.java b/src/de/steamwar/bungeecore/commands/DevCommand.java index 5858a49..834f96d 100644 --- a/src/de/steamwar/bungeecore/commands/DevCommand.java +++ b/src/de/steamwar/bungeecore/commands/DevCommand.java @@ -20,8 +20,8 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.sql.Punishment; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.Punishment; +import de.steamwar.sql.SteamwarUser; import de.steamwar.command.*; import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.ProxyServer; @@ -79,9 +79,9 @@ public class DevCommand extends SWCommand { @ClassValidator(value = ProxiedPlayer.class, local = true) public TypeValidator punishmentGuardChecker() { return (sender, value, messageSender) -> { - SteamwarUser user = SteamwarUser.get(value); + SteamwarUser user = SteamwarUser.get(value.getUniqueId()); if (user.isPunished(Punishment.PunishmentType.NoDevServer)) { - Message message = user.punishmentMessage(Punishment.PunishmentType.NoDevServer); + Message message = PunishmentCommand.punishmentMessage(user, Punishment.PunishmentType.NoDevServer); messageSender.send(message.getFormat(), message.getParams()); return false; } diff --git a/src/de/steamwar/bungeecore/commands/EventCommand.java b/src/de/steamwar/bungeecore/commands/EventCommand.java index 082b9b7..e71eeed 100644 --- a/src/de/steamwar/bungeecore/commands/EventCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventCommand.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; -import de.steamwar.bungeecore.sql.EventFight; +import de.steamwar.sql.EventFight; import de.steamwar.sql.SchematicType; import de.steamwar.sql.Team; import de.steamwar.sql.TeamTeilnahme; diff --git a/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java b/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java index 16e98e1..13e8f59 100644 --- a/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.sql.EventFight; +import de.steamwar.sql.EventFight; import de.steamwar.sql.Team; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; diff --git a/src/de/steamwar/bungeecore/commands/EventreloadCommand.java b/src/de/steamwar/bungeecore/commands/EventreloadCommand.java index 9d5008a..1c3d173 100644 --- a/src/de/steamwar/bungeecore/commands/EventreloadCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventreloadCommand.java @@ -19,7 +19,7 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.sql.EventFight; +import de.steamwar.sql.EventFight; import de.steamwar.command.SWCommand; import net.md_5.bungee.api.CommandSender; diff --git a/src/de/steamwar/bungeecore/commands/FightCommand.java b/src/de/steamwar/bungeecore/commands/FightCommand.java index 5911db5..e5cf3e4 100644 --- a/src/de/steamwar/bungeecore/commands/FightCommand.java +++ b/src/de/steamwar/bungeecore/commands/FightCommand.java @@ -22,13 +22,10 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.inventory.SWItem; -import de.steamwar.bungeecore.listeners.mods.ModLoaderBlocker; -import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.command.SWCommand; import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatMessageType; -import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; diff --git a/src/de/steamwar/bungeecore/commands/GDPRQuery.java b/src/de/steamwar/bungeecore/commands/GDPRQuery.java index 25e37fa..0158edf 100644 --- a/src/de/steamwar/bungeecore/commands/GDPRQuery.java +++ b/src/de/steamwar/bungeecore/commands/GDPRQuery.java @@ -3,7 +3,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.sql.internal.Statement; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -25,7 +25,7 @@ public class GDPRQuery extends SWCommand { @Register public void generate(ProxiedPlayer player, ProxiedPlayer forPlayer) { - SteamwarUser user = SteamwarUser.get(forPlayer); + SteamwarUser user = SteamwarUser.get(forPlayer.getUniqueId()); if(user == null) { Message.send("UNKNOWN_PLAYER", player); return; @@ -49,7 +49,7 @@ public class GDPRQuery extends SWCommand { copy(getClass().getClassLoader().getResourceAsStream("GDPRQueryREADME.md"), out, "README.txt"); printUpdate(player, "GDPR_STATUS_WORLD"); - copyBauwelt(user, out, "/home/minecraft/userworlds/" + user.getUuid().toString(), "BuildWorld12"); + copyBauwelt(user, out, "/home/minecraft/userworlds/" + user.getUUID().toString(), "BuildWorld12"); copyBauwelt(user, out, "/home/minecraft/userworlds15/" + user.getId(), "BuildWorld15"); printUpdate(player, "GDPR_STATUS_INVENTORIES"); @@ -214,14 +214,14 @@ public class GDPRQuery extends SWCommand { } } - File playerdata = new File(world, "playerdata/" + user.getUuid().toString() + ".dat"); + File playerdata = new File(world, "playerdata/" + user.getUUID().toString() + ".dat"); if(playerdata.exists()) - copy(playerdata, out, outDir + "/playerdata/" + user.getUuid().toString() + ".dat"); + copy(playerdata, out, outDir + "/playerdata/" + user.getUUID().toString() + ".dat"); } private void copyPlayerdata(SteamwarUser user, ZipOutputStream out, String inDir, String outDir) throws IOException { File worlds = new File(inDir); - String path = "playerdata/" + user.getUuid().toString() + ".dat"; + String path = "playerdata/" + user.getUUID().toString() + ".dat"; int i = 0; for(File world : worlds.listFiles()) { @@ -229,7 +229,7 @@ public class GDPRQuery extends SWCommand { if(!playerdata.exists()) continue; - copy(playerdata, out, outDir + "/" + (i++) + "/" + user.getUuid().toString() + ".dat"); + copy(playerdata, out, outDir + "/" + (i++) + "/" + user.getUUID().toString() + ".dat"); } } diff --git a/src/de/steamwar/bungeecore/commands/IgnoreCommand.java b/src/de/steamwar/bungeecore/commands/IgnoreCommand.java index 0c11ee0..b7c26f7 100644 --- a/src/de/steamwar/bungeecore/commands/IgnoreCommand.java +++ b/src/de/steamwar/bungeecore/commands/IgnoreCommand.java @@ -21,12 +21,11 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.sql.IgnoreSystem; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.stream.Collectors; diff --git a/src/de/steamwar/bungeecore/commands/ModCommand.java b/src/de/steamwar/bungeecore/commands/ModCommand.java index f5b4c66..ed6bbd7 100644 --- a/src/de/steamwar/bungeecore/commands/ModCommand.java +++ b/src/de/steamwar/bungeecore/commands/ModCommand.java @@ -24,8 +24,8 @@ import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.bungeecore.inventory.SWListInv; import de.steamwar.bungeecore.inventory.SWStreamInv; -import de.steamwar.bungeecore.sql.*; import de.steamwar.command.SWCommand; +import de.steamwar.sql.Mod; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -39,7 +39,7 @@ public class ModCommand extends SWCommand { super("mod", "bungeecore.softreload", "mods"); } - public static final Map playerFilterType = new HashMap<>(); + public static final Map playerFilterType = new HashMap<>(); @Register public void genericCommand(ProxiedPlayer p) { diff --git a/src/de/steamwar/bungeecore/commands/PlaytimeCommand.java b/src/de/steamwar/bungeecore/commands/PlaytimeCommand.java index c9c3850..c483ec9 100644 --- a/src/de/steamwar/bungeecore/commands/PlaytimeCommand.java +++ b/src/de/steamwar/bungeecore/commands/PlaytimeCommand.java @@ -20,15 +20,11 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; -import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; -import org.apache.commons.lang3.LocaleUtils; -import java.text.DecimalFormat; import java.text.NumberFormat; -import java.util.Locale; public class PlaytimeCommand extends SWCommand { @@ -40,7 +36,7 @@ public class PlaytimeCommand extends SWCommand { public void genericCommand(ProxiedPlayer player) { NumberFormat format = NumberFormat.getNumberInstance((player).getLocale()); format.setMaximumFractionDigits(2); - String formattedText = format.format((SteamwarUser.get(player).getOnlinetime() / (double) 3600)); + String formattedText = format.format((SteamwarUser.get(player.getUniqueId()).getOnlinetime() / (double) 3600)); Message.send("HOURS_PLAYED", player, formattedText); } diff --git a/src/de/steamwar/bungeecore/commands/PollCommand.java b/src/de/steamwar/bungeecore/commands/PollCommand.java index 4e3a3bd..6cae84d 100644 --- a/src/de/steamwar/bungeecore/commands/PollCommand.java +++ b/src/de/steamwar/bungeecore/commands/PollCommand.java @@ -22,7 +22,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.listeners.PollSystem; import de.steamwar.sql.PollAnswer; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; import net.md_5.bungee.api.connection.ProxiedPlayer; diff --git a/src/de/steamwar/bungeecore/commands/PunishmentCommand.java b/src/de/steamwar/bungeecore/commands/PunishmentCommand.java index 62e9831..23ba5f2 100644 --- a/src/de/steamwar/bungeecore/commands/PunishmentCommand.java +++ b/src/de/steamwar/bungeecore/commands/PunishmentCommand.java @@ -19,13 +19,20 @@ package de.steamwar.bungeecore.commands; +import com.google.gson.JsonParser; +import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.sql.Punishment; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; +import de.steamwar.messages.ChatSender; +import de.steamwar.sql.BannedUserIPs; +import de.steamwar.sql.Punishment; import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; +import java.io.IOException; +import java.net.URL; import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -33,17 +40,84 @@ import java.time.Duration; import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.Date; -import java.util.regex.MatchResult; -import java.util.regex.Matcher; +import java.util.NoSuchElementException; +import java.util.Scanner; +import java.util.UUID; +import java.util.logging.Level; import java.util.regex.Pattern; public class PunishmentCommand { + private static final String API_URL = "https://api.mojang.com/users/profiles/minecraft/"; + private static final JsonParser jsonParser = new JsonParser(); + + public static SteamwarUser getOrCreateOfflinePlayer(String name) { + SteamwarUser user = SteamwarUser.get(name); + if (user != null) { + return user; + } + + UUID uuid = getUUIDofOfflinePlayer(name); + if (uuid == null) { + return null; + } + + return SteamwarUser.getOrCreate(uuid, name, u -> {}, (o, n) -> {}); + } + + private static UUID getUUIDofOfflinePlayer(String playerName) { + try { + final URL url = new URL(API_URL + playerName); + String uuid = jsonParser.parse(new Scanner(url.openConnection().getInputStream()).nextLine()).getAsJsonObject().get("id").getAsString(); + return UUID.fromString(uuid.replaceFirst("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5")); + } catch (NoSuchElementException e) { + // ignore, player does not exist + } catch (IOException e) { + BungeeCore.get().getLogger().log(Level.SEVERE, "Could not get offline player UUID " + playerName, e); + } + return null; + } + + public static boolean isPunishedWithMessage(ChatSender player, Punishment.PunishmentType punishment) { + SteamwarUser user = player.user(); + if (!user.isPunished(punishment)) { + return false; + } + player.system(punishmentMessage(user, punishment)); + return true; + } + + public static void ban(SteamwarUser user, Timestamp time, String banReason, SteamwarUser punisher, boolean perma) { + user.punish(Punishment.PunishmentType.Ban, time, banReason, punisher.getId(), perma); + + ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUUID()); + if (player != null) { + ChatSender.disconnect(player).system(punishmentMessage(user, Punishment.PunishmentType.Ban)); + for (BannedUserIPs banned : BannedUserIPs.get(player.getAddress().getAddress().getHostAddress())) { + SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID()); + if (bannedUser.isPunished(Punishment.PunishmentType.Ban) && bannedUser.getPunishment(Punishment.PunishmentType.Ban).getEndTime().before(time)) { + bannedUser.punish(Punishment.PunishmentType.Ban, time, banReason, punisher.getId(), perma); + } + } + BannedUserIPs.banIP(user.getId(), player.getAddress().getAddress().getHostAddress()); + } + } + + public static Message punishmentMessage(SteamwarUser user, Punishment.PunishmentType punishment) { + Punishment currentPunishment = user.getPunishment(punishment); + if (currentPunishment.isPerma()) { + return new Message(punishment.getPlayerMessagePerma(), currentPunishment.getReason()); + } else { + return new Message(punishment.getPlayerMessageUntil(), currentPunishment.getEndTime(), currentPunishment.getReason()); + } + } + public PunishmentCommand(String command, Punishment.PunishmentType punishmentType) { new SWCommand(command, "bungeecore.ban") { @Register(description = "PUNISHMENT_USAGE") public void genericCommand(ProxiedPlayer player, String toPunish, String date, String... message) { - if (punishmentType.isNeedsAdmin() && !SteamwarUser.get(player).getUserGroup().isAdminGroup()) { + SteamwarUser punisher = SteamwarUser.get(player.getUniqueId()); + if (punishmentType.isNeedsAdmin() && !punisher.getUserGroup().isAdminGroup()) { return; } @@ -57,7 +131,10 @@ public class PunishmentCommand { boolean isPerma = date.equalsIgnoreCase("perma"); String msg = String.join(" ", message); - target.punish(punishmentType, banTime, msg, SteamwarUser.get(player.getName()).getId(), isPerma); + if(punishmentType == Punishment.PunishmentType.Ban) + ban(target, banTime, msg, punisher, isPerma); + else + target.punish(punishmentType, banTime, msg, punisher.getId(), isPerma); Message.team(punishmentType.getTeamMessage(), new Message("PREFIX"), target.getUserName(), player.getName(), new Message((isPerma ? "PUNISHMENT_PERMA" : "PUNISHMENT_UNTIL"), banTime), msg); } }; @@ -68,7 +145,7 @@ public class PunishmentCommand { new SWCommand(antiCommand, "bungeecore.ban") { @Register(description = "PUNISHMENT_USAGE") public void genericCommand(ProxiedPlayer player, String toUnpunish) { - if (punishmentType.isNeedsAdmin() && !SteamwarUser.get(player).getUserGroup().isAdminGroup()) { + if (punishmentType.isNeedsAdmin() && !SteamwarUser.get(player.getUniqueId()).getUserGroup().isAdminGroup()) { return; } @@ -83,6 +160,8 @@ public class PunishmentCommand { Message.send(punishmentType.getUnpunishmentMessage(), player, target.getUserName()); target.punish(punishmentType, Timestamp.from(new Date().toInstant()), antiCommand, SteamwarUser.get(player.getName()).getId(), false); + if(punishmentType == Punishment.PunishmentType.Ban) + BannedUserIPs.unbanIPs(target.getId()); } }; } @@ -95,7 +174,7 @@ public class PunishmentCommand { } protected SteamwarUser unsafeUser(CommandSender sender, String arg){ - SteamwarUser target = SteamwarUser.getOrCreateOfflinePlayer(arg); + SteamwarUser target = getOrCreateOfflinePlayer(arg); if(target == null) Message.send("UNKNOWN_PLAYER", sender); return target; diff --git a/src/de/steamwar/bungeecore/commands/RankCommand.java b/src/de/steamwar/bungeecore/commands/RankCommand.java index eca5518..c661009 100644 --- a/src/de/steamwar/bungeecore/commands/RankCommand.java +++ b/src/de/steamwar/bungeecore/commands/RankCommand.java @@ -21,13 +21,12 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.bungeecore.sql.UserElo; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.Optional; diff --git a/src/de/steamwar/bungeecore/commands/ReplayCommand.java b/src/de/steamwar/bungeecore/commands/ReplayCommand.java index 86aca8f..e318938 100644 --- a/src/de/steamwar/bungeecore/commands/ReplayCommand.java +++ b/src/de/steamwar/bungeecore/commands/ReplayCommand.java @@ -23,10 +23,10 @@ import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.bungeecore.inventory.SWListInv; import de.steamwar.bungeecore.inventory.SWStreamInv; -import de.steamwar.bungeecore.sql.Fight; -import de.steamwar.bungeecore.sql.Punishment; +import de.steamwar.sql.Fight; +import de.steamwar.sql.Punishment; import de.steamwar.sql.SchematicType; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -44,12 +44,12 @@ public class ReplayCommand extends SWCommand { @Register public void genericCommand(ProxiedPlayer player, @OptionalValue("") String optionalMap) { ChatSender sender = ChatSender.of(player); - if (sender.user().isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) + if (PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) return; new SWStreamInv<>(player, Message.parse("REPLAY_TITLE", player), (click, fight) -> { SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - ArenaMode mode = fight.getGameMode(); + ArenaMode mode = ArenaMode.getBySchemType(fight.getSchemType()); ServerStarter starter = new ServerStarter().replay(fight.getFightID()).blueLeader(player); String map = mode.getRandomMap(); diff --git a/src/de/steamwar/bungeecore/commands/SetLocaleCommand.java b/src/de/steamwar/bungeecore/commands/SetLocaleCommand.java index 798a58c..d02c53c 100644 --- a/src/de/steamwar/bungeecore/commands/SetLocaleCommand.java +++ b/src/de/steamwar/bungeecore/commands/SetLocaleCommand.java @@ -19,8 +19,10 @@ package de.steamwar.bungeecore.commands; +import de.steamwar.bungeecore.network.NetworkSender; import de.steamwar.command.SWCommand; import de.steamwar.messages.ChatSender; +import de.steamwar.network.packets.server.LocaleInvalidationPacket; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.Objects; @@ -35,6 +37,7 @@ public class SetLocaleCommand extends SWCommand { public void genericCommand(ProxiedPlayer player) { ChatSender sender = ChatSender.of(player); sender.user().setLocale(Objects.requireNonNull(player.getLocale()), true); + NetworkSender.send(player, new LocaleInvalidationPacket(sender.user().getId())); sender.system("LOCK_LOCALE_CHANGED"); } } diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index e7ee335..b28eb61 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -23,8 +23,8 @@ import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Storage; import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.bungeecore.inventory.SWListInv; -import de.steamwar.bungeecore.sql.Punishment; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.Punishment; +import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.Team; import de.steamwar.sql.TeamTeilnahme; import de.steamwar.messages.ChatSender; @@ -314,7 +314,7 @@ public class TeamCommand extends BasicCommand { teamInvitations.get(target.getId()).add(team.getTeamId()); Message.send("TEAM_INVITE_INVITED", player, args[1]); - ProxiedPlayer p = ProxyServer.getInstance().getPlayer(target.getUuid()); + ProxiedPlayer p = ProxyServer.getInstance().getPlayer(target.getUUID()); if(p != null) Message.send("TEAM_INVITE_INVITED_TARGET", p, team.getTeamColor(), team.getTeamName()); } @@ -358,7 +358,7 @@ public class TeamCommand extends BasicCommand { target.setTeam(0); Message.send("TEAM_REMOVE_REMOVED", player); - ProxiedPlayer p = ProxyServer.getInstance().getPlayer(target.getUuid()); + ProxiedPlayer p = ProxyServer.getInstance().getPlayer(target.getUUID()); if(p != null) Message.send("TEAM_REMOVE_REMOVED_TARGET", player); } @@ -429,7 +429,7 @@ public class TeamCommand extends BasicCommand { } private String playerName(SteamwarUser user){ - return ProxyServer.getInstance().getPlayer(user.getUuid()) != null ? "§a" + user.getUserName() : "§e" + user.getUserName(); + return ProxyServer.getInstance().getPlayer(user.getUUID()) != null ? "§a" + user.getUserName() : "§e" + user.getUserName(); } private void info(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ @@ -616,7 +616,7 @@ public class TeamCommand extends BasicCommand { private void server(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ if(notLeader(player, user, team)) return; - if (user.isPunishedWithMessage(ChatSender.of(player), Punishment.PunishmentType.NoTeamServer)) { + if (PunishmentCommand.isPunishedWithMessage(ChatSender.of(player), Punishment.PunishmentType.NoTeamServer)) { return; } if (args.length < 2) { diff --git a/src/de/steamwar/bungeecore/commands/TeamchatCommand.java b/src/de/steamwar/bungeecore/commands/TeamchatCommand.java index 60e57dc..1f9a491 100644 --- a/src/de/steamwar/bungeecore/commands/TeamchatCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamchatCommand.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.listeners.ChatListener; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.CommandSender; diff --git a/src/de/steamwar/bungeecore/commands/TpCommand.java b/src/de/steamwar/bungeecore/commands/TpCommand.java index d7bb956..ac93796 100644 --- a/src/de/steamwar/bungeecore/commands/TpCommand.java +++ b/src/de/steamwar/bungeecore/commands/TpCommand.java @@ -21,8 +21,8 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.sql.BauweltMember; -import de.steamwar.bungeecore.sql.Punishment; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.Punishment; +import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.Team; import de.steamwar.bungeecore.util.BauLock; import de.steamwar.bungeecore.util.Chat19; @@ -87,14 +87,14 @@ public class TpCommand extends BasicCommand { Subserver subserver = Subserver.getSubserver(server); if (subserver != null && subserver.getType() == Servertype.ARENA) { - if (!sender.user().isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) + if (!PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) SubserverSystem.sendPlayer(subserver, player); } else if(subserver instanceof Bauserver) { Bauserver bauserver = (Bauserver) subserver; ProxiedPlayer checker = BungeeCord.getInstance().getPlayer(bauserver.getOwner()); if (checker != null && CheckCommand.isChecking(checker)) { - SteamwarUser steamwarUser = SteamwarUser.get(player); + SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); if (steamwarUser.getUserGroup().isCheckSchematics() || CheckCommand.getCheckingSchem(checker).getOwner() == steamwarUser.getId()) { SubserverSystem.sendPlayer(subserver, player); } else { diff --git a/src/de/steamwar/bungeecore/commands/TutorialCommand.java b/src/de/steamwar/bungeecore/commands/TutorialCommand.java index c9dc9d7..57dec80 100644 --- a/src/de/steamwar/bungeecore/commands/TutorialCommand.java +++ b/src/de/steamwar/bungeecore/commands/TutorialCommand.java @@ -24,8 +24,8 @@ import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.bungeecore.inventory.SWListInv; import de.steamwar.bungeecore.inventory.SWStreamInv; -import de.steamwar.bungeecore.sql.SteamwarUser; -import de.steamwar.bungeecore.sql.Tutorial; +import de.steamwar.sql.SteamwarUser; +import de.steamwar.sql.Tutorial; import de.steamwar.bungeecore.util.Chat19; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; diff --git a/src/de/steamwar/bungeecore/commands/TypeMappers.java b/src/de/steamwar/bungeecore/commands/TypeMappers.java index bf882fd..5b5b409 100644 --- a/src/de/steamwar/bungeecore/commands/TypeMappers.java +++ b/src/de/steamwar/bungeecore/commands/TypeMappers.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.listeners.mods.ModLoaderBlocker; -import de.steamwar.bungeecore.sql.Punishment; +import de.steamwar.sql.Punishment; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; @@ -33,7 +33,6 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.stream.Collectors; @UtilityClass public class TypeMappers { @@ -48,7 +47,7 @@ public class TypeMappers { private static TypeValidator arenaPlayer() { return (sender, value, messageSender) -> { ChatSender player = ChatSender.of(value); - if (player.user().isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer)) { + if (PunishmentCommand.isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer)) { return false; } diff --git a/src/de/steamwar/bungeecore/commands/UnIgnoreCommand.java b/src/de/steamwar/bungeecore/commands/UnIgnoreCommand.java index d0755bd..a7d7f72 100644 --- a/src/de/steamwar/bungeecore/commands/UnIgnoreCommand.java +++ b/src/de/steamwar/bungeecore/commands/UnIgnoreCommand.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.sql.IgnoreSystem; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; import net.md_5.bungee.api.connection.ProxiedPlayer; diff --git a/src/de/steamwar/bungeecore/commands/VerifyCommand.java b/src/de/steamwar/bungeecore/commands/VerifyCommand.java index 08aee06..4d2cf64 100644 --- a/src/de/steamwar/bungeecore/commands/VerifyCommand.java +++ b/src/de/steamwar/bungeecore/commands/VerifyCommand.java @@ -22,7 +22,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.bot.AuthManager; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; import net.dv8tion.jda.api.entities.Member; import net.md_5.bungee.api.connection.ProxiedPlayer; diff --git a/src/de/steamwar/bungeecore/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/commands/WhoisCommand.java index 856e99a..581e618 100644 --- a/src/de/steamwar/bungeecore/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/commands/WhoisCommand.java @@ -22,12 +22,10 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Storage; import de.steamwar.bungeecore.listeners.mods.Utils; -import de.steamwar.bungeecore.sql.*; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; -import de.steamwar.sql.Team; -import de.steamwar.sql.UserGroup; +import de.steamwar.sql.*; import lombok.Getter; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.CommandSender; @@ -89,7 +87,7 @@ public class WhoisCommand extends SWCommand { if (!userGroup.isTeamGroup()) return; if (userGroup.isAdminGroup()) { - Message.send("WHOIS_UUID", player, Message.parse("WHOIS_UUID_HOVER", player), new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, user.getUuid().toString()), user.getUuid().toString()); + Message.send("WHOIS_UUID", player, Message.parse("WHOIS_UUID_HOVER", player), new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, user.getUUID().toString()), user.getUUID().toString()); Message.send("WHOIS_ID", player, user.getId()); if (user.getDiscordId() != null) { Message.send("WHOIS_DISCORD_ID", player, user.getDiscordId()); @@ -104,20 +102,20 @@ public class WhoisCommand extends SWCommand { } Message.send("WHOIS_HOURS_PLAYED", player, new DecimalFormat("###.##").format(user.getOnlinetime() / 3600d)); - if(BungeeCord.getInstance().getPlayer(user.getUuid()) != null) { - ProxiedPlayer target = BungeeCord.getInstance().getPlayer(user.getUuid()); + if(BungeeCord.getInstance().getPlayer(user.getUUID()) != null) { + ProxiedPlayer target = BungeeCord.getInstance().getPlayer(user.getUUID()); Message.send("WHOIS_CURRENT_PLAYED", player, new DecimalFormat("####.##").format((Instant.now().getEpochSecond() - Storage.sessions.get(target).toInstant().getEpochSecond()) / 60d)); Message.send("WHOIS_CURRENT_SERVER", player, target.getServer().getInfo().getName()); Message.send("WHOIS_CURRENT_PROTOCOL", player, target.getPendingConnection().getVersion()); } - if (Utils.playerModMap.containsKey(user.getUuid())) { - Mod.Platform modPlatform = Utils.playerModMap.get(user.getUuid()).get(0).getPlatform(); + if (Utils.playerModMap.containsKey(user.getUUID())) { + Mod.Platform modPlatform = Utils.playerModMap.get(user.getUUID()).get(0).getPlatform(); Message.send("WHOIS_PLATFORM", player, modPlatform.toString()); } if (parameterTypes.contains(WhoisParameterTypes.MOD)) { - List activeMods = Utils.playerModMap.get(user.getUuid()); + List activeMods = Utils.playerModMap.get(user.getUUID()); if (activeMods != null && !activeMods.isEmpty()) { Message.send("WHOIS_ACTIVE_MODS", player,activeMods.size()); diff --git a/src/de/steamwar/bungeecore/inventory/SWInventory.java b/src/de/steamwar/bungeecore/inventory/SWInventory.java index dac6be9..637668c 100644 --- a/src/de/steamwar/bungeecore/inventory/SWInventory.java +++ b/src/de/steamwar/bungeecore/inventory/SWInventory.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.inventory; import de.steamwar.bungeecore.network.NetworkSender; import de.steamwar.bungeecore.network.handlers.InventoryCallbackHandler; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.network.packets.server.CloseInventoryPacket; import de.steamwar.network.packets.server.InventoryPacket; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -46,7 +46,7 @@ public class SWInventory { public SWInventory(ProxiedPlayer proxiedPlayer, int size, String title) { itemMap = new HashMap<>(); - InventoryCallbackHandler.inventoryHashMap.put(SteamwarUser.get(proxiedPlayer).getId(), this); + InventoryCallbackHandler.inventoryHashMap.put(SteamwarUser.get(proxiedPlayer.getUniqueId()).getId(), this); this.player = proxiedPlayer; this.size = size; this.title = title; @@ -114,7 +114,7 @@ public class SWInventory { public void handleClose() { if(processingClick.compareAndSet(false, true)) { - InventoryCallbackHandler.inventoryHashMap.remove(SteamwarUser.get(player).getId(), this); + InventoryCallbackHandler.inventoryHashMap.remove(SteamwarUser.get(player.getUniqueId()).getId(), this); if(close != null) close.clicked(null); processingClick.set(false); @@ -122,7 +122,7 @@ public class SWInventory { } public void open() { - InventoryPacket inv = new InventoryPacket(title, SteamwarUser.get(player).getId(), size, map(itemMap, (integer, swItem) -> swItem.writeToString(integer).toString())); + InventoryPacket inv = new InventoryPacket(title, SteamwarUser.get(player.getUniqueId()).getId(), size, map(itemMap, (integer, swItem) -> swItem.writeToString(integer).toString())); NetworkSender.send(player, inv); } @@ -137,7 +137,7 @@ public class SWInventory { } public static void close(ProxiedPlayer player) { - NetworkSender.send(player, new CloseInventoryPacket(SteamwarUser.get(player).getId())); + NetworkSender.send(player, new CloseInventoryPacket(SteamwarUser.get(player.getUniqueId()).getId())); } public void setClose(InvCallback close) { diff --git a/src/de/steamwar/bungeecore/listeners/BanListener.java b/src/de/steamwar/bungeecore/listeners/BanListener.java index f5b31bb..51ded5c 100644 --- a/src/de/steamwar/bungeecore/listeners/BanListener.java +++ b/src/de/steamwar/bungeecore/listeners/BanListener.java @@ -21,16 +21,19 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; +import de.steamwar.bungeecore.commands.PunishmentCommand; +import de.steamwar.bungeecore.commands.WebpasswordCommand; import de.steamwar.bungeecore.listeners.mods.Forge; import de.steamwar.sql.BannedUserIPs; -import de.steamwar.bungeecore.sql.Punishment; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.Punishment; +import de.steamwar.sql.SteamwarUser; import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.connection.PendingConnection; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.LoginEvent; import net.md_5.bungee.event.EventHandler; @@ -45,16 +48,17 @@ public class BanListener extends BasicListener { public void onLogin(LoginEvent event) { event.registerIntent(BungeeCore.get()); ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { - SteamwarUser user = SteamwarUser.getOrCreate(event.getConnection()); + PendingConnection connection = event.getConnection(); + SteamwarUser user = SteamwarUser.getOrCreate(connection.getUniqueId(), connection.getName(), ConnectionListener::newPlayer, WebpasswordCommand::changeUsername); if (user.isPunished(Punishment.PunishmentType.Ban)) { - user.updateBanIP(event.getConnection().getAddress().getAddress().getHostAddress()); event.setCancelled(true); - ChatSender.of(event).system(user.punishmentMessage(Punishment.PunishmentType.Ban)); + BannedUserIPs.banIP(user.getId(), connection.getAddress().getAddress().getHostAddress()); + ChatSender.of(event).system(PunishmentCommand.punishmentMessage(user, Punishment.PunishmentType.Ban)); event.completeIntent(BungeeCore.get()); return; } - List ips = BannedUserIPs.get(event.getConnection().getAddress().getAddress().getHostAddress()); + List ips = BannedUserIPs.get(connection.getAddress().getAddress().getHostAddress()); if(!ips.isEmpty()){ Timestamp highestBan = ips.get(0).getTimestamp(); diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index dd84a9f..4ac8851 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -21,11 +21,14 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; +import de.steamwar.bungeecore.commands.PunishmentCommand; import de.steamwar.bungeecore.network.NetworkSender; import de.steamwar.bungeecore.sql.*; import de.steamwar.bungeecore.util.Chat19; import de.steamwar.messages.ChatSender; import de.steamwar.network.packets.server.PingPacket; +import de.steamwar.sql.Punishment; +import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.Team; import de.steamwar.sql.UserGroup; import net.md_5.bungee.api.*; @@ -39,6 +42,7 @@ import net.md_5.bungee.event.EventHandler; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.logging.Level; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -61,7 +65,9 @@ public class ChatListener extends BasicListener { e.setCancelled(true); if (message.contains("jndi:ldap")) { - SteamwarUser.get(player).punishPerma(Punishment.PunishmentType.Ban, "Versuchte Exploit-Ausnutzung", 0); + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + PunishmentCommand.ban(user, Punishment.PERMA_TIME, "Versuchte Exploit-Ausnutzung", SteamwarUser.get(-1), true); + BungeeCore.log(Level.SEVERE, user.getUserName() + " " + user.getId() + " wurde automatisch wegen jndi:ldap gebannt."); return; } @@ -155,7 +161,7 @@ public class ChatListener extends BasicListener { return true; } - if (user.isPunishedWithMessage(sender, Punishment.PunishmentType.Mute)) + if (PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.Mute)) return true; if (message.contains("LIXFEL")) @@ -204,7 +210,7 @@ public class ChatListener extends BasicListener { String mark = "@" + player.user().getUserName(); return Arrays.stream(message.split(" ")).map(cur -> { if(cur.equalsIgnoreCase(mark)) { - NetworkSender.send(player.user().getPlayer(), new PingPacket(player.user().getId())); + NetworkSender.send(ProxyServer.getInstance().getPlayer(player.user().getUUID()), new PingPacket(player.user().getId())); return "§e" + cur + returnColor; } return cur; diff --git a/src/de/steamwar/bungeecore/listeners/CheckListener.java b/src/de/steamwar/bungeecore/listeners/CheckListener.java index 0f236d6..e7b1e84 100644 --- a/src/de/steamwar/bungeecore/listeners/CheckListener.java +++ b/src/de/steamwar/bungeecore/listeners/CheckListener.java @@ -23,7 +23,7 @@ import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.commands.CheckCommand; import de.steamwar.bungeecore.sql.SchematicNode; import de.steamwar.sql.SchematicType; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.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; diff --git a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java index 33fd29e..ddde4f7 100644 --- a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java +++ b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java @@ -30,7 +30,7 @@ import de.steamwar.bungeecore.commands.CheckCommand; import de.steamwar.bungeecore.commands.ModCommand; import de.steamwar.bungeecore.commands.MsgCommand; import de.steamwar.bungeecore.listeners.mods.Utils; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserGroup; import net.md_5.bungee.api.AbstractReconnectHandler; import net.md_5.bungee.api.ProxyServer; diff --git a/src/de/steamwar/bungeecore/listeners/EventModeListener.java b/src/de/steamwar/bungeecore/listeners/EventModeListener.java index 48d498f..4d2b23f 100644 --- a/src/de/steamwar/bungeecore/listeners/EventModeListener.java +++ b/src/de/steamwar/bungeecore/listeners/EventModeListener.java @@ -1,8 +1,8 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.sql.EventFight; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.EventFight; +import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.TeamTeilnahme; import de.steamwar.sql.Event; import net.md_5.bungee.api.chat.TextComponent; diff --git a/src/de/steamwar/bungeecore/listeners/PollSystem.java b/src/de/steamwar/bungeecore/listeners/PollSystem.java index 69a4fb3..b0bf952 100644 --- a/src/de/steamwar/bungeecore/listeners/PollSystem.java +++ b/src/de/steamwar/bungeecore/listeners/PollSystem.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.Message; import de.steamwar.sql.PollAnswer; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.PostLoginEvent; diff --git a/src/de/steamwar/bungeecore/listeners/SessionManager.java b/src/de/steamwar/bungeecore/listeners/SessionManager.java index dcc8d96..db5a820 100644 --- a/src/de/steamwar/bungeecore/listeners/SessionManager.java +++ b/src/de/steamwar/bungeecore/listeners/SessionManager.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.sql.Session; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.event.PlayerDisconnectEvent; import net.md_5.bungee.api.event.PostLoginEvent; @@ -43,7 +43,7 @@ public class SessionManager extends BasicListener { public void onDisconnect(PlayerDisconnectEvent e){ Timestamp timestamp = sessions.remove(e.getPlayer()); if(timestamp != null) { - ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> Session.insertSession(SteamwarUser.get(e.getPlayer()).getId(), timestamp)); + ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> Session.insertSession(SteamwarUser.get(e.getPlayer().getUniqueId()).getId(), timestamp)); } } } diff --git a/src/de/steamwar/bungeecore/listeners/SettingsChangedListener.java b/src/de/steamwar/bungeecore/listeners/SettingsChangedListener.java index 5affb64..ec11c46 100644 --- a/src/de/steamwar/bungeecore/listeners/SettingsChangedListener.java +++ b/src/de/steamwar/bungeecore/listeners/SettingsChangedListener.java @@ -20,7 +20,9 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.bungeecore.network.NetworkSender; +import de.steamwar.sql.SteamwarUser; +import de.steamwar.network.packets.server.LocaleInvalidationPacket; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.SettingsChangedEvent; @@ -32,7 +34,9 @@ public class SettingsChangedListener extends BasicListener { public void onSettingsChanged(SettingsChangedEvent event) { BungeeCord.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { ProxiedPlayer player = event.getPlayer(); - SteamwarUser.get(player).setLocale(player.getLocale(), false); + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + user.setLocale(player.getLocale(), false); + NetworkSender.send(player, new LocaleInvalidationPacket(user.getId())); }); } } diff --git a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java index c9c9d2a..9bed4e0 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java @@ -27,9 +27,9 @@ import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Storage; import de.steamwar.bungeecore.listeners.BasicListener; -import de.steamwar.bungeecore.sql.Mod; +import de.steamwar.sql.Mod; import de.steamwar.sql.SWException; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.PluginMessageEvent; @@ -58,7 +58,7 @@ public class Fabric extends BasicListener { continue; } if (System.currentTimeMillis() - entry.getValue() > TimeUnit.SECONDS.toMillis(20)) { - logMessage(SteamwarUser.get(entry.getKey()), "Expected message not received", String.valueOf(entry.getValue())); + logMessage(SteamwarUser.get(entry.getKey().getUniqueId()), "Expected message not received", String.valueOf(entry.getValue())); return; } } diff --git a/src/de/steamwar/bungeecore/listeners/mods/Forge.java b/src/de/steamwar/bungeecore/listeners/mods/Forge.java index d6ebf21..ff5efb9 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Forge.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Forge.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.listeners.mods; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.listeners.BasicListener; -import de.steamwar.bungeecore.sql.Mod; +import de.steamwar.sql.Mod; import io.netty.channel.ChannelPipeline; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.PendingConnection; diff --git a/src/de/steamwar/bungeecore/listeners/mods/Forge12.java b/src/de/steamwar/bungeecore/listeners/mods/Forge12.java index 2bdd5a8..02a9082 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Forge12.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Forge12.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.listeners.mods; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.listeners.BasicListener; -import de.steamwar.bungeecore.sql.Mod; +import de.steamwar.sql.Mod; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; import net.md_5.bungee.api.ProxyServer; diff --git a/src/de/steamwar/bungeecore/listeners/mods/LabyMod.java b/src/de/steamwar/bungeecore/listeners/mods/LabyMod.java index 22887d4..20fcaca 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/LabyMod.java +++ b/src/de/steamwar/bungeecore/listeners/mods/LabyMod.java @@ -23,7 +23,7 @@ import com.google.gson.JsonObject; import com.google.gson.stream.JsonReader; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.listeners.BasicListener; -import de.steamwar.bungeecore.sql.Mod; +import de.steamwar.sql.Mod; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.Connection; import net.md_5.bungee.api.connection.ProxiedPlayer; diff --git a/src/de/steamwar/bungeecore/listeners/mods/Utils.java b/src/de/steamwar/bungeecore/listeners/mods/Utils.java index d4739c6..15e66bb 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Utils.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Utils.java @@ -21,11 +21,11 @@ package de.steamwar.bungeecore.listeners.mods; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.sql.Mod; -import de.steamwar.bungeecore.sql.Mod.ModType; -import de.steamwar.bungeecore.sql.Punishment; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.bungeecore.commands.PunishmentCommand; +import de.steamwar.sql.SteamwarUser; import de.steamwar.messages.ChatSender; +import de.steamwar.sql.Mod; +import de.steamwar.sql.Mod.ModType; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -97,7 +97,7 @@ public class Utils { } if(max == ModType.RED) { - user.punish(Punishment.PunishmentType.Ban, Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), message, 0, false); + PunishmentCommand.ban(user, Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), message, SteamwarUser.get(-1), false); BungeeCore.log(Level.SEVERE, user.getUserName() + " " + user.getId() + " wurde automatisch wegen der Mods " + modList + " gebannt."); } diff --git a/src/de/steamwar/bungeecore/listeners/mods/WorldDownloader.java b/src/de/steamwar/bungeecore/listeners/mods/WorldDownloader.java index 1b39625..f003098 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/WorldDownloader.java +++ b/src/de/steamwar/bungeecore/listeners/mods/WorldDownloader.java @@ -3,7 +3,7 @@ package de.steamwar.bungeecore.listeners.mods; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import de.steamwar.bungeecore.listeners.BasicListener; -import de.steamwar.bungeecore.sql.Mod; +import de.steamwar.sql.Mod; import net.md_5.bungee.api.connection.Connection; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.PluginMessageEvent; diff --git a/src/de/steamwar/bungeecore/network/handlers/ExecuteCommandHandler.java b/src/de/steamwar/bungeecore/network/handlers/ExecuteCommandHandler.java index ae31db5..91f8027 100644 --- a/src/de/steamwar/bungeecore/network/handlers/ExecuteCommandHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/ExecuteCommandHandler.java @@ -19,7 +19,7 @@ package de.steamwar.bungeecore.network.handlers; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.network.packets.PacketHandler; import de.steamwar.network.packets.client.ExecuteCommandPacket; import net.md_5.bungee.api.ProxyServer; @@ -31,6 +31,6 @@ public class ExecuteCommandHandler extends PacketHandler { SteamwarUser target = SteamwarUser.get(packet.getPlayerId()); String command = packet.getCommand(); - ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getPlayer(target.getUuid()), command); + ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getPlayer(target.getUUID()), command); } } diff --git a/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java index d6dc4a0..3487915 100644 --- a/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java @@ -23,7 +23,9 @@ import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.sql.*; import de.steamwar.network.packets.PacketHandler; import de.steamwar.network.packets.common.FightEndsPacket; +import de.steamwar.sql.SchemElo; import de.steamwar.sql.SchematicType; +import de.steamwar.sql.SteamwarUser; import lombok.RequiredArgsConstructor; import java.util.*; @@ -91,8 +93,8 @@ public class FightEndsHandler extends PacketHandler { gameModeGames.computeIfAbsent(fightEndsPacket.getGameMode(), s -> new LinkedList<>()).add(new Game(fightEndsPacket.getBluePlayers(), fightEndsPacket.getRedPlayers())); } - int blueSchemElo = SchemElo.getElo(fightEndsPacket.getBlueSchem()); - int redSchemElo = SchemElo.getElo(fightEndsPacket.getRedSchem()); + int blueSchemElo = SchemElo.getCurrentElo(fightEndsPacket.getBlueSchem()); + int redSchemElo = SchemElo.getCurrentElo(fightEndsPacket.getRedSchem()); int blueTeamElo = fightEndsPacket.getBluePlayers().stream().mapToInt(player -> UserElo.getEloOrDefault(player, fightEndsPacket.getGameMode())).sum(); int redTeamElo = fightEndsPacket.getRedPlayers().stream().mapToInt(player -> UserElo.getEloOrDefault(player, fightEndsPacket.getGameMode())).sum(); diff --git a/src/de/steamwar/bungeecore/network/handlers/InventoryCallbackHandler.java b/src/de/steamwar/bungeecore/network/handlers/InventoryCallbackHandler.java index 03da0f9..b759f8c 100644 --- a/src/de/steamwar/bungeecore/network/handlers/InventoryCallbackHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/InventoryCallbackHandler.java @@ -22,15 +22,13 @@ package de.steamwar.bungeecore.network.handlers; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.inventory.InvCallback; import de.steamwar.bungeecore.inventory.SWInventory; -import de.steamwar.bungeecore.network.NetworkReceiver; import de.steamwar.bungeecore.network.NetworkSender; import de.steamwar.bungeecore.network.ServerMetaInfo; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.network.packets.PacketHandler; import de.steamwar.network.packets.client.InventoryCallbackPacket; import de.steamwar.network.packets.server.CloseInventoryPacket; import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.config.ServerInfo; import java.util.HashMap; import java.util.Map; @@ -44,7 +42,7 @@ public class InventoryCallbackHandler extends PacketHandler { SteamwarUser owner = SteamwarUser.get(packet.getOwner()); InventoryCallbackPacket.CallbackType type = packet.getType(); if(!inventoryHashMap.containsKey(owner.getId())) { - BungeeCore.send(ProxyServer.getInstance().getPlayer(owner.getUuid()), BungeeCore.CHAT_PREFIX + "§cBitte erneut versuchen. Durch ein Softwareupdate konnte die übliche Aktion nicht durchgeführt werden."); + BungeeCore.send(ProxyServer.getInstance().getPlayer(owner.getUUID()), BungeeCore.CHAT_PREFIX + "§cBitte erneut versuchen. Durch ein Softwareupdate konnte die übliche Aktion nicht durchgeführt werden."); if(type == InventoryCallbackPacket.CallbackType.CLICK) { NetworkSender.send(((ServerMetaInfo) packet.getMetaInfos()).getSender(), new CloseInventoryPacket(owner.getId())); } diff --git a/src/de/steamwar/bungeecore/network/handlers/PrepareSchemHandler.java b/src/de/steamwar/bungeecore/network/handlers/PrepareSchemHandler.java index 2f25c44..d9eae09 100644 --- a/src/de/steamwar/bungeecore/network/handlers/PrepareSchemHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/PrepareSchemHandler.java @@ -22,7 +22,7 @@ package de.steamwar.bungeecore.network.handlers; import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.ServerStarter; import de.steamwar.sql.SchematicType; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.network.packets.PacketHandler; import de.steamwar.network.packets.client.PrepareSchemPacket; import net.md_5.bungee.api.ProxyServer; @@ -32,7 +32,7 @@ public class PrepareSchemHandler extends PacketHandler { @Handler public void handle(PrepareSchemPacket packet) { - ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(packet.getPlayer()).getUuid()); + ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(packet.getPlayer()).getUUID()); int schematicID = packet.getSchem(); ArenaMode mode = ArenaMode.getBySchemType(SchematicType.fromDB(packet.getSchemType())); diff --git a/src/de/steamwar/bungeecore/sql/CheckedSchematic.java b/src/de/steamwar/bungeecore/sql/CheckedSchematic.java index 77815c4..44a9010 100644 --- a/src/de/steamwar/bungeecore/sql/CheckedSchematic.java +++ b/src/de/steamwar/bungeecore/sql/CheckedSchematic.java @@ -19,6 +19,7 @@ package de.steamwar.bungeecore.sql; +import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.internal.Statement; import java.sql.ResultSet; diff --git a/src/de/steamwar/bungeecore/sql/EventFight.java b/src/de/steamwar/bungeecore/sql/EventFight.java deleted file mode 100644 index 0a7072e..0000000 --- a/src/de/steamwar/bungeecore/sql/EventFight.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.sql.internal.Statement; -import de.steamwar.bungeecore.ArenaMode; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.util.*; - -import static java.time.temporal.ChronoUnit.SECONDS; - -public class EventFight implements Comparable { - - private static final Statement reschedule = new Statement("UPDATE EventFight SET StartTime = ? WHERE EventID = ? AND FightID = ?"); - private static final Statement allComing = new Statement("SELECT * FROM EventFight WHERE StartTime > now() ORDER BY `StartTime` ASC"); - private static final Statement event = new Statement("SELECT * FROM EventFight WHERE EventID = ? ORDER BY `StartTime` ASC"); - - private static final Queue fights = new PriorityQueue<>(); - - private final int eventID; - private final int fightID; - private Timestamp startTime; - private final ArenaMode spielmodus; - private final String map; - private final int teamBlue; - private final int teamRed; - private final int kampfleiter; - private final int ergebnis; - private final int fight; - - private EventFight(ResultSet rs) throws SQLException { - eventID = rs.getInt("EventID"); - fightID = rs.getInt("FightID"); - startTime = rs.getTimestamp("StartTime"); - spielmodus = ArenaMode.getByInternal(rs.getString("Spielmodus")); - map = rs.getString("Map"); - teamBlue = rs.getInt("TeamBlue"); - teamRed = rs.getInt("TeamRed"); - kampfleiter = rs.getInt("Kampfleiter"); - ergebnis = rs.getInt("Ergebnis"); - fight = rs.getInt("Fight"); - } - - public void reschedule(){ - startTime = Timestamp.from(new Date().toInstant().plus(30, SECONDS)); - reschedule.update(startTime, eventID, fightID); - } - - public static void loadAllComingFights(){ - allComing.select(rs -> { - fights.clear(); - while(rs.next()){ - fights.add(new EventFight(rs)); - } - return null; - }); - } - - public static List getEvent(int eventID){ - return event.select(rs -> { - List fights = new LinkedList<>(); - while(rs.next()) - fights.add(new EventFight(rs)); - return fights; - }, eventID); - } - - public static Queue getFights() { - return fights; - } - - public Timestamp getStartTime() { - return startTime; - } - - public ArenaMode getSpielmodus() { - return spielmodus; - } - - public String getMap() { - return map; - } - - public int getTeamBlue() { - return teamBlue; - } - - public int getTeamRed() { - return teamRed; - } - - public int getEventID() { - return eventID; - } - - public int getFightID() { - return fightID; - } - - public int getKampfleiter() { - return kampfleiter; - } - - public int getErgebnis() { - return ergebnis; - } - - public boolean hasFinished() { - return fight != 0; - } - - @Override - public int hashCode(){ - return fightID; - } - - @Override - public boolean equals(Object o){ - if(o == null) - return false; - if(!(o instanceof EventFight)) - return false; - return fightID == ((EventFight) o).fightID; - } - - @Override - public int compareTo(EventFight o) { - return startTime.compareTo(o.startTime); - } -} diff --git a/src/de/steamwar/bungeecore/sql/Fight.java b/src/de/steamwar/bungeecore/sql/Fight.java deleted file mode 100644 index 7de3de0..0000000 --- a/src/de/steamwar/bungeecore/sql/Fight.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2023 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.sql.FightPlayer; -import de.steamwar.sql.SchematicType; -import de.steamwar.sql.internal.Statement; -import de.steamwar.bungeecore.ArenaMode; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -public class Fight { - - private static final Statement getPage = new Statement("SELECT f.FightID, f.GameMode, f.Server, f.StartTime, f.BlueLeader, f.RedLeader, (b.NodeId IS NULL OR b.AllowReplay) AND (r.NodeId IS NULL OR r.AllowReplay) AS ReplayAllowed, f.Win, (SELECT COUNT(1) FROM Replay WHERE Replay.FightID = f.FightID) as ReplayAvailable FROM Fight f LEFT OUTER JOIN SchematicNode b ON f.BlueSchem = b.NodeId LEFT OUTER JOIN SchematicNode r ON f.RedSchem = r.NodeId ORDER BY FightID DESC LIMIT ?, ?"); - - private final int fightID; - private final String gameMode; - private final String server; - private final Timestamp startTime; - - private final int blueLeader; - private final int redLeader; - private final int win; - - private final boolean replayAllowed; - private final boolean replayAvailable; - - private final List bluePlayers = new ArrayList<>(); - private final List redPlayers = new ArrayList<>(); - - private Fight(ResultSet rs) throws SQLException { - fightID = rs.getInt("FightID"); - gameMode = rs.getString("GameMode"); - server = rs.getString("Server"); - startTime = rs.getTimestamp("StartTime"); - blueLeader = rs.getInt("BlueLeader"); - redLeader = rs.getInt("RedLeader"); - replayAllowed = rs.getBoolean("ReplayAllowed"); - replayAvailable = rs.getBoolean("ReplayAvailable"); - win = rs.getInt("Win"); - } - - private void initPlayers(List fightPlayers) { - for(FightPlayer fp : fightPlayers) { - if(fp.getFightID() != fightID) - continue; - - if(fp.getTeam() == 1) - bluePlayers.add(fp); - else - redPlayers.add(fp); - } - } - - public static List getPage(int page, int elementsPerPage) { - List fights = getPage.select(rs -> { - List f = new ArrayList<>(); - while(rs.next()){ - f.add(new Fight(rs)); - } - return f; - }, page * elementsPerPage, elementsPerPage); - - List fightPlayers = FightPlayer.batchGet(fights.stream().map(f -> f.fightID).toArray(Integer[]::new)); - for(Fight fight : fights) { - fight.initPlayers(fightPlayers); - } - - de.steamwar.bungeecore.sql.SteamwarUser.batchCache(fightPlayers.stream().map(FightPlayer::getUserID).collect(Collectors.toSet())); - return fights; - } - - public SchematicType getSchemType() { - return SchematicType.fromDB(gameMode); - } - - public ArenaMode getGameMode() { - SchematicType schemType = getSchemType(); - if(schemType == null) - return null; - return ArenaMode.getBySchemType(schemType); - } - - public int getFightID() { - return fightID; - } - - public Timestamp getStartTime() { - return startTime; - } - - public de.steamwar.bungeecore.sql.SteamwarUser getBlueLeader() { - return de.steamwar.bungeecore.sql.SteamwarUser.get(blueLeader); - } - - public de.steamwar.bungeecore.sql.SteamwarUser getRedLeader() { - return SteamwarUser.get(redLeader); - } - - public int getWin() { - return win; - } - - public String getServer() { - return server; - } - - public List getBluePlayers() { - return bluePlayers; - } - - public List getRedPlayers() { - return redPlayers; - } - - public boolean replayAllowed() { - return replayExists() && replayAllowed; - } - - public boolean replayExists() { - return getGameMode() != null && replayAvailable; - } -} diff --git a/src/de/steamwar/bungeecore/sql/IgnoreSystem.java b/src/de/steamwar/bungeecore/sql/IgnoreSystem.java index b152805..9631f5a 100644 --- a/src/de/steamwar/bungeecore/sql/IgnoreSystem.java +++ b/src/de/steamwar/bungeecore/sql/IgnoreSystem.java @@ -19,6 +19,7 @@ package de.steamwar.bungeecore.sql; +import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.internal.Statement; import net.md_5.bungee.api.connection.ProxiedPlayer; diff --git a/src/de/steamwar/bungeecore/sql/Mod.java b/src/de/steamwar/bungeecore/sql/Mod.java deleted file mode 100644 index 897b7f9..0000000 --- a/src/de/steamwar/bungeecore/sql/Mod.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.sql.internal.Statement; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -public class Mod { - - private static final Statement get = new Statement("SELECT * FROM Mods WHERE ModName = ? AND Platform = ?"); - private static final Statement insert = new Statement("INSERT INTO Mods (ModName, Platform) VALUES (?, ?)"); - - private static final Statement set = new Statement("UPDATE Mods Set ModType = ? WHERE ModName = ? AND Platform = ?"); - private static final Statement findFirst = new Statement("SELECT * FROM Mods WHERE ModType = 0 LIMIT 1"); - - private static final Statement getPageOfType = new Statement("SELECT * FROM Mods WHERE ModType = ? ORDER BY ModName DESC LIMIT ?, ?"); - - private final String modName; - private final Platform platform; - private final ModType modType; - - private Mod(String modName, Platform platform, ModType modType) { - this.modName = modName; - this.platform = platform; - this.modType = modType; - } - - private Mod(ResultSet resultSet) throws SQLException { - this(resultSet.getString("ModName"), Mod.Platform.values()[resultSet.getInt("Platform")], ModType.values()[resultSet.getInt("ModType")]); - } - - public static Mod get(String name, Platform platform) { - return get.select(rs -> { - if(rs.next()) - return new Mod(rs); - return null; - }, name, platform.ordinal()); - } - - public static Mod getOrCreate(String name, Platform platform) { - Mod mod = get(name, platform); - if(mod != null) - return mod; - - insert.update(name, platform.ordinal()); - return new Mod(name, platform, ModType.UNKLASSIFIED); - } - - public void setModType(Mod.ModType newModType) { - set.update(newModType.ordinal(), modName, platform.ordinal()); - } - - public static List getAllModsFiltered(int page,int elementsPerPage, Mod.ModType filter) { - return Mod.getPageOfType.select(rs -> { - List f = new ArrayList<>(); - - while(rs.next()) - f.add(new Mod(rs)); - - return f; - },filter.ordinal(), page * elementsPerPage, elementsPerPage); - } - - public static Mod findFirstMod() { - return findFirst.select(rs -> { - if(rs.next()) - return new Mod(rs); - return null; - }); - } - - public String getModName() { - return modName; - } - - public Platform getPlatform() { - return platform; - } - - public ModType getModType() { - return modType; - } - - public enum Platform{ - FORGE, - LABYMOD, - FABRIC - } - - public enum ModType { - UNKLASSIFIED("7"), - GREEN("a"), - YELLOW("e"), - RED("c"), - YOUTUBER_ONLY("6"); - - ModType(String colorcode) { - this.colorcode = colorcode; - } - private final String colorcode; - - public String getColorCode() { - return colorcode; - } - } -} diff --git a/src/de/steamwar/bungeecore/sql/NodeMember.java b/src/de/steamwar/bungeecore/sql/NodeMember.java deleted file mode 100644 index 878982c..0000000 --- a/src/de/steamwar/bungeecore/sql/NodeMember.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.sql.internal.Statement; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.HashSet; -import java.util.Set; - -public class NodeMember { - private static final Statement getNodeMember = new Statement("SELECT * FROM NodeMember WHERE NodeId = ? AND UserId = ?"); - private static final Statement getNodeMembers = new Statement("SELECT * FROM NodeMember WHERE NodeId = ?"); - private static final Statement getSchematics = new Statement("SELECT * FROM NodeMember WHERE UserId = ?"); - private static final Statement createNodeMember = new Statement("INSERT INTO NodeMember (NodeId, UserId) VALUES (?, ?)"); - private static final Statement deleteNodeMember = new Statement("DELETE FROM NodeMember WHERE NodeId = ? AND UserId = ?"); - - public static NodeMember getNodeMember(int node, int member) { - return getNodeMember.select(rs -> { - if(!rs.next()) - return null; - return new NodeMember(rs); - }, node, member); - } - - public static Set getNodeMembers(int node) { - return getNodeMembers.select(rs -> { - Set members = new HashSet<>(); - while (rs.next()) - members.add(new NodeMember(rs)); - return members; - }, node); - } - - public static Set getSchematics(int member) { - return getSchematics.select(rs -> { - Set members = new HashSet<>(); - while (rs.next()) - members.add(new NodeMember(rs)); - return members; - }, member); - } - - public static NodeMember createNodeMember(int node, int member) { - createNodeMember.update(node, member); - return getNodeMember(node, member); - } - - final int node; - final int member; - - private NodeMember(ResultSet set) throws SQLException { - node = set.getInt("NodeId"); - member = set.getInt("UserId"); - } - - public int getNode() { - return node; - } - - public int getMember() { - return member; - } - - public void delete() { - deleteNodeMember.update(node, member); - } -} diff --git a/src/de/steamwar/bungeecore/sql/Punishment.java b/src/de/steamwar/bungeecore/sql/Punishment.java deleted file mode 100644 index 8bc3b4a..0000000 --- a/src/de/steamwar/bungeecore/sql/Punishment.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.sql.internal.Statement; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.time.Instant; -import java.time.format.DateTimeFormatter; -import java.util.*; - -public class Punishment { - - private static final Statement getPunishment = new Statement("SELECT * FROM Punishments WHERE UserId = ? AND Type = ? ORDER BY PunishmentId DESC LIMIT 1"); - private static final Statement getPunishments = new Statement("SELECT * FROM Punishments WHERE PunishmentId IN (SELECT MAX(PunishmentId) FROM Punishments WHERE UserId = ? GROUP BY Type)"); - private static final Statement getAllPunishments = new Statement("SELECT * FROM Punishments WHERE UserId = ? ORDER BY `PunishmentId` DESC"); - private static final Statement insert = new Statement("INSERT INTO Punishments (UserId, Punisher, Type, Reason, EndTime, Perma) VALUES (?, ?, ?, ?, ?, ?)"); - - public static final Timestamp PERMA_TIME = Timestamp.from(Instant.ofEpochSecond(946674800)); - - public static Punishment getPunishmentOfPlayer(int user, PunishmentType type) { - return getPunishment.select(rs -> { - if (rs.next()) - return new Punishment(rs); - return null; - }, user, type.name()); - } - - public static Map getPunishmentsOfPlayer(int user) { - return getPunishments.select(rs -> { - Map punishments = new HashMap<>(); - while (rs.next()) - punishments.put(PunishmentType.valueOf(rs.getString("Type")), new Punishment(rs)); - return punishments; - }, user); - } - - public static List getAllPunishmentsOfPlayer(int user) { - return getAllPunishments.select(rs -> { - List punishments = new ArrayList<>(); - while (rs.next()) - punishments.add(new Punishment(rs)); - return punishments; - }, user); - } - - public static Punishment createPunishment(int user, int executor, PunishmentType type, String reason, Timestamp endTime, boolean perma) { - if(perma && !endTime.equals(PERMA_TIME)) { - throw new IllegalArgumentException("Permanent punishments must have an end time of `Punishment.PERMA_TIME`"); - } - insert.update(user, executor, type.name(), reason, endTime, perma); - return getPunishmentOfPlayer(user, type); - } - - private final Timestamp startTime; - private Timestamp endTime; - private final PunishmentType type; - private final int user; - private final int id; - private String reason; - private final int punisher; - private boolean perma; - - private Punishment(ResultSet set) throws SQLException { - user = set.getInt("UserId"); - reason = set.getString("Reason"); - type = PunishmentType.valueOf(set.getString("Type")); - startTime = set.getTimestamp("StartTime"); - endTime = set.getTimestamp("EndTime"); - punisher = set.getInt("Punisher"); - perma = set.getBoolean("Perma"); - id = set.getInt("PunishmentId"); - } - - public Timestamp getStartTime() { - return startTime; - } - - public Timestamp getEndTime() { - return endTime; - } - - public PunishmentType getType() { - return type; - } - - public int getUser() { - return user; - } - - public String getReason() { - return reason; - } - - public int getPunisher() { - return punisher; - } - - public boolean isPerma() { - return perma; - } - - public String getBantime(Timestamp endTime, boolean perma) { - if (perma) { - return "permanent"; - } else { - return endTime.toLocalDateTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")); - } - } - - public boolean isCurrent() { - return isPerma() || getEndTime().after(new Date()); - } - - @AllArgsConstructor - @RequiredArgsConstructor - @Getter - public enum PunishmentType { - Ban(false, "BAN_TEAM", "BAN_PERMA", "BAN_UNTIL", "UNBAN_ERROR", "UNBAN"), - Mute( false, "MUTE_TEAM", "MUTE_PERMA", "MUTE_UNTIL", "UNMUTE_ERROR", "UNMUTE"), - NoSchemReceiving(false, "NOSCHEMRECEIVING_TEAM", "NOSCHEMRECEIVING_PERMA", "NOSCHEMRECEIVING_UNTIL", "UNNOSCHEMRECEIVING_ERROR", "UNNOSCHEMRECEIVING"), - NoSchemSharing(false, "NOSCHEMSHARING_TEAM", "NOSCHEMSHARING_PERMA", "NOSCHEMSHARING_UNTIL", "UNNOSCHEMSHARING_ERROR", "UNNOSCHEMSHARING"), - NoSchemSubmitting(true, "NOSCHEMSUBMITTING_TEAM", "NOSCHEMSUBMITTING_PERMA", "NOSCHEMSUBMITTING_UNTIL", "UNNOSCHEMSUBMITTING_ERROR", "UNNOSCHEMSUBMITTING"), - NoDevServer(true, "NODEVSERVER_TEAM", "NODEVSERVER_PERMA", "NODEVSERVER_UNTIL", "UNNODEVSERVER_ERROR", "UNNODEVSERVER"), - NoFightServer(false, "NOFIGHTSERVER_TEAM", "NOFIGHTSERVER_PERMA", "NOFIGHTSERVER_UNTIL", "UNNOFIGHTSERVER_ERROR", "UNNOFIGHTSERVER"), - NoTeamServer(true, "NOTEAMSERVER_TEAM", "NOTEAMSERVER_PERMA", "NOTEAMSERVER_UNTIL", "UNNOTEAMSERVER_ERROR", "UNNOTEAMSERVER"), - Note(false, "NOTE_TEAM", null, null, null, null, true), - ; - - private final boolean needsAdmin; - private final String teamMessage; - private final String playerMessagePerma; - private final String playerMessageUntil; - private final String usageNotPunished; - private final String unpunishmentMessage; - private boolean multi = false; - } -} diff --git a/src/de/steamwar/bungeecore/sql/SchemElo.java b/src/de/steamwar/bungeecore/sql/SchemElo.java deleted file mode 100644 index 8f58e13..0000000 --- a/src/de/steamwar/bungeecore/sql/SchemElo.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.sql.Season; -import de.steamwar.sql.internal.Statement; - -import static de.steamwar.bungeecore.sql.UserElo.ELO_DEFAULT; - -public class SchemElo { - private SchemElo() {} - - private static final Statement elo = new Statement("SELECT Elo FROM SchemElo WHERE SchemID = ? AND Season = ?"); - private static final Statement setElo = new Statement("INSERT INTO SchemElo (Season, SchemID, Elo) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Elo = VALUES(Elo)"); - - public static int getElo(int schemID) { - return getElo(Season.getSeason(), schemID); - } - - public static int getElo(int season, int schemID) { - return elo.select(rs -> { - if (rs.next()) - return rs.getInt("Elo"); - return ELO_DEFAULT; - }, schemID, season); - } - - public static void setElo(int schemID, int elo) { - setElo(Season.getSeason(), schemID, elo); - } - - public static void setElo(int season, int schemID, int elo) { - setElo.update(season, schemID, elo); - } -} diff --git a/src/de/steamwar/bungeecore/sql/SchematicNode.java b/src/de/steamwar/bungeecore/sql/SchematicNode.java index 9c91c02..e8bca5b 100644 --- a/src/de/steamwar/bungeecore/sql/SchematicNode.java +++ b/src/de/steamwar/bungeecore/sql/SchematicNode.java @@ -20,7 +20,9 @@ package de.steamwar.bungeecore.sql; +import de.steamwar.sql.NodeMember; import de.steamwar.sql.SchematicType; +import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.internal.Statement; import java.io.InputStream; diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java deleted file mode 100644 index f42f53e..0000000 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ /dev/null @@ -1,398 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.sql; - -import com.google.gson.JsonParser; -import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.commands.WebpasswordCommand; -import de.steamwar.bungeecore.listeners.ConnectionListener; -import de.steamwar.bungeecore.network.NetworkSender; -import de.steamwar.messages.ChatSender; -import de.steamwar.network.packets.server.LocaleInvalidationPacket; -import de.steamwar.sql.BannedUserIPs; -import de.steamwar.sql.UserGroup; -import de.steamwar.sql.internal.Statement; -import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.connection.PendingConnection; -import net.md_5.bungee.api.connection.ProxiedPlayer; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.URL; -import java.net.UnknownHostException; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.util.*; -import java.util.logging.Level; -import java.util.stream.Collectors; - - -public class SteamwarUser { - - private static final Statement updateName = new Statement("UPDATE UserData SET UserName = ? WHERE id = ?"); - private static final Statement updateBedrock = new Statement("UPDATE UserData SET Bedrock = ? WHERE id = ?"); - private static final Statement updateLocale = new Statement("UPDATE UserData SET Locale = ?, ManualLocale = ? WHERE id = ?"); - private static final Statement insert = new Statement("INSERT INTO UserData (UUID, UserName, UserGroup) VALUES (?, ?, 'Member')"); - private static final Statement byUUID = new Statement("SELECT * FROM UserData WHERE UUID = ?"); - private static final Statement byName = new Statement("SELECT * FROM UserData WHERE lower(UserName) = ?"); - private static final Statement byID = new Statement("SELECT * FROM UserData WHERE id = ?"); - private static final Statement byDiscord = new Statement("SELECT * FROM UserData WHERE DiscordId = ?"); - private static final Statement updateTeam = new Statement("Update UserData SET Team = ? WHERE id = ?"); - private static final Statement updateDiscord = new Statement("Update UserData SET DiscordId = ? WHERE id = ?"); - private static final Statement deleteIPs = new Statement("DELETE FROM BannedUserIPs WHERE UserID = ?"); - private static final Statement updateLeader = new Statement("Update UserData SET Leader = ? WHERE id = ?"); - private static final Statement getPlaytime = new Statement("SELECT SUM(UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime)) as Playtime FROM Session WHERE UserID = ?"); - private static final Statement getFirstjoin = new Statement("SELECT MIN(StartTime) AS FirstJoin FROM Session WHERE UserID = ?"); - - private static final Map usersByName = new HashMap<>(); - private static final Map usersByUUID = new HashMap<>(); - private static final Map usersById = new HashMap<>(); - private static final Map usersByDiscord = new HashMap<>(); - private static final InetAddress LIXFEL_DE; - private static final String API_URL = "https://api.mojang.com/users/profiles/minecraft/"; - private static final JsonParser jsonParser = new JsonParser(); - - private final int id; - private final UUID uuid; - private String userName; - private final UserGroup userGroup; - private int team; - private boolean leader; - private final Map punishments; - private Long discordId; - - private Locale locale; - private boolean manualLocale; - - static { - try { - LIXFEL_DE = InetAddress.getByAddress(new byte[]{(byte) 195, (byte) 201, (byte) 242, 43}); - } catch (UnknownHostException e) { - ProxyServer.getInstance().stop(); - throw new SecurityException("Could not initialise address!", e); - } - } - - private SteamwarUser(ResultSet rs) throws SQLException { - id = rs.getInt("id"); - uuid = UUID.fromString(rs.getString("UUID")); - userName = rs.getString("UserName"); - userGroup = UserGroup.getUsergroup(rs.getString("UserGroup")); - team = rs.getInt("Team"); - leader = rs.getBoolean("Leader"); - discordId = rs.getLong("DiscordId"); - if(rs.wasNull()) { - discordId = null; - } - - String dbLocale = rs.getString("Locale"); - locale = dbLocale != null ? Locale.forLanguageTag(dbLocale) : null; - manualLocale = rs.getBoolean("ManualLocale"); - - usersById.put(id, this); - usersByName.put(userName.toLowerCase(), this); - usersByUUID.put(uuid, this); - if (discordId != null) { - usersByDiscord.put(discordId, this); - } - punishments = Punishment.getPunishmentsOfPlayer(id); - } - - public static SteamwarUser getOrCreate(PendingConnection connection) { - SteamwarUser user = SteamwarUser.get(connection.getUniqueId()); - - if (user != null) { - String userName = connection.getName(); - if (!user.userName.equals(userName)) { - updateName.update(userName, user.id); - WebpasswordCommand.changeUsername(user.userName, userName); - user.userName = userName; - } - } else { - user = SteamwarUser.createUserInDatabase(connection.getUniqueId(), connection.getName()); - if (user == null) { - throw new SecurityException("user == null"); - } - ConnectionListener.newPlayer(user.uuid); - } - - boolean bedrock = connection.getAddress().getAddress().equals(LIXFEL_DE); - updateBedrock.update(bedrock, user.id); - return user; - } - - public static SteamwarUser getOrCreateOfflinePlayer(String name) { - SteamwarUser user = SteamwarUser.get(name); - if (user != null) { - return user; - } - - UUID uuid = SteamwarUser.getUUIDofOfflinePlayer(name); - if (uuid == null) { - return null; - } - - user = SteamwarUser.get(uuid); - if (user != null) { - return user; - } - - return SteamwarUser.createUserInDatabase(uuid, name); - } - - private static SteamwarUser createUserInDatabase(UUID uuid, String name) { - insert.update(uuid.toString(), name); - return get(uuid); - } - - public static SteamwarUser get(String userName) { - userName = userName.toLowerCase(); - if (usersByName.containsKey(userName)) { - return usersByName.get(userName); - } - return byName.select(rs -> { - if (rs.next()) - return new SteamwarUser(rs); - return null; - }, userName); - } - - public static SteamwarUser get(UUID uuid) { - if (usersByUUID.containsKey(uuid)) { - return usersByUUID.get(uuid); - } - return byUUID.select(rs -> { - if (rs.next()) - return new SteamwarUser(rs); - return null; - }, uuid.toString()); - } - - public static SteamwarUser get(ProxiedPlayer player) { - return get(player.getUniqueId()); - } - - public static SteamwarUser get(int id) { - if (usersById.containsKey(id)) { - return usersById.get(id); - } - return byID.select(rs -> { - rs.next(); - return new SteamwarUser(rs); - }, id); - } - - public static void batchCache(Set ids) { - ids.removeIf(usersById::containsKey); - if(ids.isEmpty()) - return; - - try (Statement batch = new Statement("SELECT * FROM UserData WHERE id IN (" + ids.stream().map(Object::toString).collect(Collectors.joining(", ")) + ")")) { - batch.select(rs -> { - while (rs.next()) - new SteamwarUser(rs); - return null; - }); - } - } - - public static SteamwarUser get(Long discordId) { - if(usersByDiscord.containsKey(discordId)) - return usersByDiscord.get(discordId); - return byDiscord.select(rs -> { - if (rs.next()) - return new SteamwarUser(rs); - return null; - }, discordId); - } - - public static void clearCache() { - usersById.clear(); - usersByName.clear(); - usersByUUID.clear(); - usersByDiscord.clear(); - } - - private static UUID getUUIDofOfflinePlayer(String playerName) { - try { - final URL url = new URL(API_URL + playerName); - String uuid = jsonParser.parse(new Scanner(url.openConnection().getInputStream()).nextLine()).getAsJsonObject().get("id").getAsString(); - return UUID.fromString(uuid.replaceFirst("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5")); - } catch (NoSuchElementException e) { - // ignore, player does not exist - } catch (IOException e) { - BungeeCore.get().getLogger().log(Level.SEVERE, "Could not get offline player UUID " + playerName, e); - } - return null; - } - - public void setTeam(int team) { - this.team = team; - updateTeam.update(team, id); - setLeader(false); - } - - public int getId() { - return id; - } - - public UUID getUuid() { - return uuid; - } - - public String getUserName() { - return userName; - } - - public UserGroup getUserGroup() { - return userGroup; - } - - public int getTeam() { - return team; - } - - @Deprecated - public ProxiedPlayer getPlayer() { - return ProxyServer.getInstance().getPlayer(uuid); - } - - public Punishment getPunishment(Punishment.PunishmentType type) { - return punishments.getOrDefault(type, null); - } - - public Long getDiscordId() { - return discordId; - } - - public void setDiscordId(Long discordId) { - usersByDiscord.remove(this.discordId); - this.discordId = discordId; - updateDiscord.update(discordId, id); - if (discordId != null) { - usersByDiscord.put(discordId, this); - } - } - - public boolean isPunished(Punishment.PunishmentType punishment) { - if (!punishments.containsKey(punishment)) { - return false; - } - if (!punishments.get(punishment).isCurrent()) { - if (punishment == Punishment.PunishmentType.Ban) { - deleteIPs.update(id); - } - punishments.remove(punishment); - return false; - } - return true; - } - - public boolean isPunishedWithMessage(ChatSender player, Punishment.PunishmentType punishment) { - if (!isPunished(punishment)) { - return false; - } - player.system(punishmentMessage(punishment)); - return true; - } - - public void punishPerma(Punishment.PunishmentType type, String reason, int from) { - punish(type, Punishment.PERMA_TIME, reason, from, true); - } - - public void punish(Punishment.PunishmentType punishment, Timestamp time, String banReason, int from, boolean perma) { - punishments.remove(punishment); - punishments.put(punishment, Punishment.createPunishment(id, from, punishment, banReason, time, perma)); - - if (punishment != Punishment.PunishmentType.Ban) { - return; - } - - ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid); - if (player != null) { - ChatSender.disconnect(player).system(punishmentMessage(punishment)); - for (BannedUserIPs banned : BannedUserIPs.get(player.getAddress().getAddress().getHostAddress())) { - SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID()); - if (bannedUser.isPunished(punishment) && bannedUser.getPunishment(punishment).getEndTime().before(time)) { - bannedUser.punish(punishment, time, banReason, from, perma); - } - } - updateBanIP(player.getAddress().getAddress().getHostAddress()); - } else { - updateBanIP(""); - } - } - - public Message punishmentMessage(Punishment.PunishmentType punishment) { - Punishment currentPunishment = punishments.get(punishment); - if (currentPunishment.isPerma()) { - return new Message(punishment.getPlayerMessagePerma(), currentPunishment.getReason()); - } else { - return new Message(punishment.getPlayerMessageUntil(), currentPunishment.getEndTime(), currentPunishment.getReason()); - } - } - - public void updateBanIP(String ip) { - BannedUserIPs.banIP(id, ip); - } - - public double getOnlinetime() { - return getPlaytime.select(rs -> { - if (rs.next() && rs.getBigDecimal("Playtime") != null) - return rs.getBigDecimal("Playtime").doubleValue(); - return 0.0; - }, id); - } - - public Timestamp getFirstjoin() { - return getFirstjoin.select(rs -> { - if (rs.next()) - return rs.getTimestamp("FirstJoin"); - return null; - }, id); - } - - public boolean isLeader() { - return leader; - } - - public void setLeader(boolean leader) { - this.leader = leader; - updateLeader.update(leader, id); - } - - public Locale getLocale() { - if (locale != null) - return locale; - return Locale.getDefault(); - } - - public void setLocale(Locale locale, boolean manualLocale) { - if (locale == null || (this.manualLocale && !manualLocale)) - return; - - this.locale = locale; - this.manualLocale = manualLocale; - updateLocale.update(locale.toLanguageTag(), manualLocale, id); - NetworkSender.send(getPlayer(), new LocaleInvalidationPacket(id)); - } -} diff --git a/src/de/steamwar/bungeecore/sql/Tutorial.java b/src/de/steamwar/bungeecore/sql/Tutorial.java deleted file mode 100644 index b28b0cd..0000000 --- a/src/de/steamwar/bungeecore/sql/Tutorial.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.sql.internal.Field; -import de.steamwar.sql.internal.Statement; -import de.steamwar.sql.internal.Table; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -@AllArgsConstructor -public class Tutorial { - - private static final Table table = new Table<>(Tutorial.class); - private static final Statement release = table.update(Table.PRIMARY, "released"); - private static final Statement delete = table.delete(Table.PRIMARY); - - private static final Statement by_popularity = new Statement("SELECT t.*, AVG(r.Stars) AS Stars FROM Tutorial t LEFT OUTER JOIN TutorialRating r ON t.TutorialID = r.TutorialID WHERE t.Released = ? GROUP BY t.TutorialID ORDER BY SUM(r.Stars) DESC LIMIT ?, ?"); - private static final Statement own = new Statement("SELECT t.*, AVG(r.Stars) AS Stars FROM Tutorial t LEFT OUTER JOIN TutorialRating r ON t.TutorialID = r.TutorialID WHERE t.Creator = ? GROUP BY t.TutorialID ORDER BY t.TutorialID ASC LIMIT ?, ?"); - private static final Statement by_creator_name = new Statement("SELECT t.*, AVG(r.Stars) AS Stars FROM Tutorial t LEFT OUTER JOIN TutorialRating r ON t.TutorialID = r.TutorialID WHERE t.Creator = ? AND t.Name = ? GROUP BY t.TutorialID"); - private static final Statement by_id = new Statement("SELECT t.*, AVG(r.Stars) AS Stars FROM Tutorial t LEFT OUTER JOIN TutorialRating r ON t.TutorialID = r.TutorialID WHERE t.TutorialID = ? GROUP BY t.TutorialID"); - private static final Statement rate = new Statement("INSERT INTO TutorialRating (TutorialID, UserID, Stars) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Stars = VALUES(Stars)"); - private static final Statement create = new Statement("INSERT INTO Tutorial (Creator, Name, Item) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Item = VALUES(Item), Released = 0"); - - public static List getPage(int page, int elementsPerPage, boolean released) { - List tutorials = by_popularity.select(rs -> { - List t = new ArrayList<>(); - while(rs.next()) - t.add(new Tutorial(rs)); - return t; - }, released, page * elementsPerPage, elementsPerPage); - - SteamwarUser.batchCache(tutorials.stream().map(tutorial -> tutorial.creator).collect(Collectors.toSet())); - return tutorials; - } - - public static List getOwn(int user, int page, int elementsPerPage) { - return own.select(rs -> { - List t = new ArrayList<>(); - while(rs.next()) - t.add(new Tutorial(rs)); - return t; - }, user, page * elementsPerPage, elementsPerPage); - } - - public static Tutorial create(int creator, String name, String item) { - create.update(creator, name, item); - return by_creator_name.select(rs -> { - rs.next(); - return new Tutorial(rs); - }, creator, name); - } - - public static Tutorial get(int id) { - return by_id.select(rs -> { - if(rs.next()) - return new Tutorial(rs); - return null; - }, id); - } - - @Getter - @Field(keys = {Table.PRIMARY}, autoincrement = true) - private final int id; - @Getter - @Field(keys = {"CreatorName"}) - private final int creator; - @Getter - @Field(keys = {"CreatorName"}) - private final String name; - @Getter - @Field(def = "'BOOK'") - private final String item; - @Getter - @Field(def = "0") - private final boolean released; - @Getter - private final double stars; - - public Tutorial(ResultSet rs) throws SQLException { - this.id = rs.getInt("TutorialID"); - this.creator = rs.getInt("Creator"); - this.name = rs.getString("Name"); - this.item = rs.getString("Item"); - this.released = rs.getBoolean("Released"); - this.stars = rs.getDouble("Stars"); - } - - public void release() { - release.update(id); - } - - public void delete() { - delete.update(id); - } - - public void rate(int user, int rating) { - rate.update(id, user, rating); - } -} diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index 3b26c30..ba708cb 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -22,6 +22,7 @@ package de.steamwar.bungeecore.sql; import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.Message; import de.steamwar.sql.Season; +import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.internal.Statement; import net.md_5.bungee.api.connection.ProxiedPlayer; diff --git a/src/de/steamwar/bungeecore/tablist/TablistPart.java b/src/de/steamwar/bungeecore/tablist/TablistPart.java index 151c320..061ae92 100644 --- a/src/de/steamwar/bungeecore/tablist/TablistPart.java +++ b/src/de/steamwar/bungeecore/tablist/TablistPart.java @@ -19,7 +19,7 @@ package de.steamwar.bungeecore.tablist; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserGroup; import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.chat.TextComponent; diff --git a/src/de/steamwar/bungeecore/tablist/TablistServer.java b/src/de/steamwar/bungeecore/tablist/TablistServer.java index 5480940..812588d 100644 --- a/src/de/steamwar/bungeecore/tablist/TablistServer.java +++ b/src/de/steamwar/bungeecore/tablist/TablistServer.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.tablist; import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Subserver; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.messages.ChatSender; import de.steamwar.network.packets.common.FightInfoPacket; import net.md_5.bungee.BungeeCord; @@ -82,7 +82,7 @@ public class TablistServer implements TablistPart { private void addPlayers(String prefix, List teamPlayers, Collection onlinePlayers){ teamPlayers.stream().map(SteamwarUser::get).map( - user -> onlinePlayers.stream().filter(player -> player.getUniqueId().equals(user.getUuid())).findAny() + user -> onlinePlayers.stream().filter(player -> player.getUniqueId().equals(user.getUUID())).findAny() ).filter(Optional::isPresent).map(Optional::get).sorted( (p1, p2) -> p1.getName().compareToIgnoreCase(p2.getName()) ).forEachOrdered(player -> players.add(new Item(player.getUniqueId(), prefix + player.getName(), Item.playerProperties(player)))); diff --git a/src/de/steamwar/bungeecore/util/BauLock.java b/src/de/steamwar/bungeecore/util/BauLock.java index 2eb4c38..43926dd 100644 --- a/src/de/steamwar/bungeecore/util/BauLock.java +++ b/src/de/steamwar/bungeecore/util/BauLock.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.util; import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserConfig; import lombok.experimental.UtilityClass; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -32,7 +32,7 @@ public class BauLock { public static void setLocked(ProxiedPlayer p, BauLockState state) { SteamwarUser owner = SteamwarUser.get(p.getUniqueId()); UserConfig.updatePlayerConfig(owner.getId(), BAU_LOCK_CONFIG_NAME, state == BauLockState.OPEN ? null : state.name()); - Message.send("BAU_LOCKED_" + state.name(), owner.getPlayer()); + Message.send("BAU_LOCKED_" + state.name(), p); } public static boolean isLocked(SteamwarUser owner, SteamwarUser target) { diff --git a/src/de/steamwar/command/TypeUtils.java b/src/de/steamwar/command/TypeUtils.java index 833cd4b..b83cb96 100644 --- a/src/de/steamwar/command/TypeUtils.java +++ b/src/de/steamwar/command/TypeUtils.java @@ -20,7 +20,7 @@ package de.steamwar.command; import de.steamwar.bungeecore.commands.TypeMappers; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import lombok.experimental.UtilityClass; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.connection.ProxiedPlayer; diff --git a/src/de/steamwar/messages/ChatSender.java b/src/de/steamwar/messages/ChatSender.java index 5b79204..65834f6 100644 --- a/src/de/steamwar/messages/ChatSender.java +++ b/src/de/steamwar/messages/ChatSender.java @@ -21,7 +21,7 @@ package de.steamwar.messages; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.bot.listeners.DiscordChatListener; -import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; From 734de7178b45ed54c64ea6c675ca9e7e901d441d Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 21 Feb 2023 20:03:36 +0100 Subject: [PATCH 22/31] Es ist vollbracht Signed-off-by: Lixfel --- CommonCore | 2 +- src/de/steamwar/bungeecore/BungeeCore.java | 4 +- .../steamwar/bungeecore/SubserverSystem.java | 4 +- .../bot/listeners/PrivateMessageListener.java | 5 +- .../bot/util/DiscordSchemAlert.java | 2 +- .../bungeecore/commands/CalendarCommand.java | 2 +- .../bungeecore/commands/ChallengeCommand.java | 4 +- .../bungeecore/commands/CheckCommand.java | 4 +- .../bungeecore/commands/IgnoreCommand.java | 2 +- .../bungeecore/commands/MsgCommand.java | 4 +- .../bungeecore/commands/RankCommand.java | 12 +- .../bungeecore/commands/UnIgnoreCommand.java | 2 +- .../bungeecore/listeners/ChatListener.java | 10 +- .../bungeecore/listeners/CheckListener.java | 2 +- .../network/handlers/FightEndsHandler.java | 5 +- .../bungeecore/sql/CheckedSchematic.java | 123 ----- .../steamwar/bungeecore/sql/IgnoreSystem.java | 53 -- .../bungeecore/sql/SchematicNode.java | 507 ------------------ src/de/steamwar/bungeecore/sql/UserElo.java | 179 ------- src/de/steamwar/sql/SchematicData.java | 47 ++ 20 files changed, 81 insertions(+), 892 deletions(-) delete mode 100644 src/de/steamwar/bungeecore/sql/CheckedSchematic.java delete mode 100644 src/de/steamwar/bungeecore/sql/IgnoreSystem.java delete mode 100644 src/de/steamwar/bungeecore/sql/SchematicNode.java delete mode 100644 src/de/steamwar/bungeecore/sql/UserElo.java create mode 100644 src/de/steamwar/sql/SchematicData.java diff --git a/CommonCore b/CommonCore index 8dbf62e..9b53ad7 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 8dbf62e560de95615d93057481e8202ec11c85c4 +Subproject commit 9b53ad748b32cc38ade1ccc606b116c0d6fbf1fb diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index f1aec11..997f8c6 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -30,7 +30,7 @@ import de.steamwar.bungeecore.network.NetworkReceiver; import de.steamwar.bungeecore.network.SWScriptSyntaxForwarder; import de.steamwar.sql.Punishment; import de.steamwar.sql.SteamwarUser; -import de.steamwar.bungeecore.sql.UserElo; +import de.steamwar.sql.UserElo; import de.steamwar.bungeecore.tablist.TablistManager; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.SWTypeMapperCreator; @@ -206,7 +206,7 @@ public class BungeeCore extends Plugin { getProxy().getScheduler().schedule(this, () -> { SteamwarUser.clear(); - UserElo.clearCache(); + UserElo.clear(); Team.clear(); }, 1, 1, TimeUnit.HOURS); diff --git a/src/de/steamwar/bungeecore/SubserverSystem.java b/src/de/steamwar/bungeecore/SubserverSystem.java index b751f6e..71b5809 100644 --- a/src/de/steamwar/bungeecore/SubserverSystem.java +++ b/src/de/steamwar/bungeecore/SubserverSystem.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore; import de.steamwar.bungeecore.network.NetworkSender; import de.steamwar.bungeecore.network.handlers.FightInfoHandler; -import de.steamwar.bungeecore.sql.IgnoreSystem; +import de.steamwar.sql.IgnoreSystem; import de.steamwar.sql.SteamwarUser; import de.steamwar.network.packets.server.StartingServerPacket; import net.md_5.bungee.api.ProxyServer; @@ -41,7 +41,7 @@ public class SubserverSystem { ProxiedPlayer o = ProxyServer.getInstance().getPlayer(owner); if(o == null) return; - if(IgnoreSystem.isIgnored(o, p)){ + if(IgnoreSystem.isIgnored(owner, p.getUniqueId())){ Message.send("SERVER_IGNORED", p); return; } diff --git a/src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java b/src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java index 0891c87..d6ef0d4 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java @@ -20,7 +20,8 @@ package de.steamwar.bungeecore.bot.listeners; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.sql.Punishment; -import de.steamwar.bungeecore.sql.SchematicNode; +import de.steamwar.sql.SchematicData; +import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent; @@ -66,7 +67,7 @@ public class PrivateMessageListener extends BasicDiscordListener { try { InputStream in = attachment.retrieveInputStream().get(); - node.saveFromStream(in, newFormat); + new SchematicData(node).saveFromStream(in, newFormat); in.close(); event.getMessage().reply("`" + name + "` wurde erfolgreich hochgeladen").queue(); } catch (Exception e) { diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java b/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java index 9d9e2c7..b0f48eb 100644 --- a/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java +++ b/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.bot.util; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; -import de.steamwar.bungeecore.sql.SchematicNode; +import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; import lombok.experimental.UtilityClass; import net.dv8tion.jda.api.EmbedBuilder; diff --git a/src/de/steamwar/bungeecore/commands/CalendarCommand.java b/src/de/steamwar/bungeecore/commands/CalendarCommand.java index d3163ca..b1d3c9f 100644 --- a/src/de/steamwar/bungeecore/commands/CalendarCommand.java +++ b/src/de/steamwar/bungeecore/commands/CalendarCommand.java @@ -23,7 +23,7 @@ import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.sql.NodeMember; -import de.steamwar.bungeecore.sql.SchematicNode; +import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; import net.md_5.bungee.api.connection.ProxiedPlayer; diff --git a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java index 6f050ac..51bfa43 100644 --- a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java +++ b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; -import de.steamwar.bungeecore.sql.IgnoreSystem; +import de.steamwar.sql.IgnoreSystem; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; import net.md_5.bungee.api.chat.ClickEvent; @@ -74,7 +74,7 @@ public class ChallengeCommand extends SWCommand { messageSender.send("CHALLENGE_SELF"); return false; } - if (IgnoreSystem.isIgnored(value, (ProxiedPlayer) sender)) { + if (IgnoreSystem.isIgnored(value.getUniqueId(), ((ProxiedPlayer) sender).getUniqueId())) { messageSender.send("CHALLENGE_IGNORED"); return false; } diff --git a/src/de/steamwar/bungeecore/commands/CheckCommand.java b/src/de/steamwar/bungeecore/commands/CheckCommand.java index 521eef1..b2aee64 100644 --- a/src/de/steamwar/bungeecore/commands/CheckCommand.java +++ b/src/de/steamwar/bungeecore/commands/CheckCommand.java @@ -22,8 +22,8 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.bot.util.DiscordSchemAlert; import de.steamwar.bungeecore.listeners.ConnectionListener; -import de.steamwar.bungeecore.sql.CheckedSchematic; -import de.steamwar.bungeecore.sql.SchematicNode; +import de.steamwar.sql.CheckedSchematic; +import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; diff --git a/src/de/steamwar/bungeecore/commands/IgnoreCommand.java b/src/de/steamwar/bungeecore/commands/IgnoreCommand.java index b7c26f7..e52e35f 100644 --- a/src/de/steamwar/bungeecore/commands/IgnoreCommand.java +++ b/src/de/steamwar/bungeecore/commands/IgnoreCommand.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.sql.IgnoreSystem; +import de.steamwar.sql.IgnoreSystem; import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; diff --git a/src/de/steamwar/bungeecore/commands/MsgCommand.java b/src/de/steamwar/bungeecore/commands/MsgCommand.java index 8dd8e50..9bd550c 100644 --- a/src/de/steamwar/bungeecore/commands/MsgCommand.java +++ b/src/de/steamwar/bungeecore/commands/MsgCommand.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.listeners.ChatListener; -import de.steamwar.bungeecore.sql.IgnoreSystem; +import de.steamwar.sql.IgnoreSystem; import de.steamwar.command.SWCommand; import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -47,7 +47,7 @@ public class MsgCommand extends SWCommand { return; } - if (IgnoreSystem.isIgnored(target, player)) { + if (IgnoreSystem.isIgnored(target.getUniqueId(), player.getUniqueId())) { sender.system("MSG_IGNORED"); return; } diff --git a/src/de/steamwar/bungeecore/commands/RankCommand.java b/src/de/steamwar/bungeecore/commands/RankCommand.java index c661009..b009872 100644 --- a/src/de/steamwar/bungeecore/commands/RankCommand.java +++ b/src/de/steamwar/bungeecore/commands/RankCommand.java @@ -22,7 +22,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.Message; import de.steamwar.sql.SteamwarUser; -import de.steamwar.bungeecore.sql.UserElo; +import de.steamwar.sql.UserElo; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; @@ -67,10 +67,18 @@ public class RankCommand extends SWCommand { } else { Message.send("RANK_UNPLACED", player); } - Message.send("RANK_EMBLEM", player, UserElo.getEmblemProgression(player, mode.getChatName(), user.getId())); + Message.send("RANK_EMBLEM", player, getEmblemProgression(player, mode.getChatName(), user.getId())); } } + private static String getEmblemProgression(ProxiedPlayer player, String gameMode, int userId) { + int fightsOfSeason = UserElo.getFightsOfSeason(userId, gameMode); + if (fightsOfSeason < 10) + return Message.parse("RANK_NEEDED_FIGHTS_LEFT", player, "§8✧ ✦ ✶ ✷ ✸ ✹ ❂", 10 - fightsOfSeason); + + return UserElo.getEmblemProgression(gameMode, userId); + } + @Mapper(value = "player", local = true) public TypeMapper playerTypeMapper() { return SWCommandUtils.createMapper(s -> s, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList())); diff --git a/src/de/steamwar/bungeecore/commands/UnIgnoreCommand.java b/src/de/steamwar/bungeecore/commands/UnIgnoreCommand.java index a7d7f72..bbd0dd4 100644 --- a/src/de/steamwar/bungeecore/commands/UnIgnoreCommand.java +++ b/src/de/steamwar/bungeecore/commands/UnIgnoreCommand.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.sql.IgnoreSystem; +import de.steamwar.sql.IgnoreSystem; import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; import net.md_5.bungee.api.connection.ProxiedPlayer; diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index 4ac8851..622d6bd 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -23,14 +23,10 @@ import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; import de.steamwar.bungeecore.commands.PunishmentCommand; import de.steamwar.bungeecore.network.NetworkSender; -import de.steamwar.bungeecore.sql.*; import de.steamwar.bungeecore.util.Chat19; import de.steamwar.messages.ChatSender; import de.steamwar.network.packets.server.PingPacket; -import de.steamwar.sql.Punishment; -import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.Team; -import de.steamwar.sql.UserGroup; +import de.steamwar.sql.*; import net.md_5.bungee.api.*; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.ChatEvent; @@ -48,6 +44,8 @@ import java.util.stream.Stream; public class ChatListener extends BasicListener { + private static final List rankedModes = ArenaMode.getAllModes().stream().filter(ArenaMode::isRanked).map(ArenaMode::getSchemType).collect(Collectors.toList()); + private static final Set coloredTeams = new HashSet<>(); static { coloredTeams.add(12); @@ -179,7 +177,7 @@ public class ChatListener extends BasicListener { msgReceiver == null ? receiver : msgReceiver, highlightMentions(message, group.getChatColorCode(), receiver), sender.getTeam() == 0 ? "" : "§" + Team.get(sender.getTeam()).getTeamColor() + Team.get(sender.getTeam()).getTeamKuerzel() + " ", - UserElo.getEmblem(sender), + UserElo.getEmblem(sender, rankedModes), group.getColorCode(), group.getChatPrefix().length() == 0 ? "§f" : group.getChatPrefix() + " ", group.getChatColorCode())); diff --git a/src/de/steamwar/bungeecore/listeners/CheckListener.java b/src/de/steamwar/bungeecore/listeners/CheckListener.java index e7b1e84..8d27ba0 100644 --- a/src/de/steamwar/bungeecore/listeners/CheckListener.java +++ b/src/de/steamwar/bungeecore/listeners/CheckListener.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.commands.CheckCommand; -import de.steamwar.bungeecore.sql.SchematicNode; +import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.connection.ProxiedPlayer; diff --git a/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java index 3487915..48de642 100644 --- a/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java @@ -20,12 +20,9 @@ package de.steamwar.bungeecore.network.handlers; import de.steamwar.bungeecore.ArenaMode; -import de.steamwar.bungeecore.sql.*; import de.steamwar.network.packets.PacketHandler; import de.steamwar.network.packets.common.FightEndsPacket; -import de.steamwar.sql.SchemElo; -import de.steamwar.sql.SchematicType; -import de.steamwar.sql.SteamwarUser; +import de.steamwar.sql.*; import lombok.RequiredArgsConstructor; import java.util.*; diff --git a/src/de/steamwar/bungeecore/sql/CheckedSchematic.java b/src/de/steamwar/bungeecore/sql/CheckedSchematic.java deleted file mode 100644 index 44a9010..0000000 --- a/src/de/steamwar/bungeecore/sql/CheckedSchematic.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.internal.Statement; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class CheckedSchematic { - - private static final Statement checkHistory = new Statement("SELECT * FROM CheckedSchematic WHERE NodeId IN (SELECT NodeId FROM SchematicNode WHERE NodeOwner = ?) AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' AND NodeId is not NULL ORDER BY EndTime DESC"); - private static final Statement nodeHistory = new Statement("SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC"); - private static final Statement insert = new Statement("INSERT INTO CheckedSchematic (NodeId, NodeName, NodeOwner, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?, ?, ?)"); - - private final Integer node; - private final int validator; - private final Timestamp startTime; - private final Timestamp endTime; - private final String declineReason; - - private CheckedSchematic(ResultSet rs) throws SQLException { - this.node = rs.getInt("NodeId"); - this.validator = rs.getInt("Validator"); - this.startTime = rs.getTimestamp("StartTime"); - this.endTime = rs.getTimestamp("EndTime"); - this.declineReason = rs.getString("DeclineReason"); - } - - public static void create(int nodeId, String name, int owner, int validator, Timestamp startTime, Timestamp endTime, String reason){ - insert.update(nodeId, name, owner, validator, startTime, endTime, reason); - } - - public static void create(SchematicNode node, int validator, Timestamp startTime, Timestamp endTime, String reason){ - create(node.getId(), node.getName(), node.getOwner(), validator, startTime, endTime, reason); - } - - public static List previousChecks(SchematicNode node){ - return nodeHistory.select(rs -> { - List schematics = new ArrayList<>(); - while(rs.next()) - schematics.add(new CheckedSchematic(rs)); - return schematics; - }, node.getId()); - } - - public static List getLastDeclinedOfNode(SchematicNode node){ - return getLastDeclinedOfNode(node.getId()); - } - - public static List getLastDeclinedOfNode(int node){ - return nodeHistory.select(rs -> { - List lastDeclined = new ArrayList<>(); - while(rs.next()){ - lastDeclined.add(new CheckedSchematic(rs)); - } - return lastDeclined; - }, node); - } - - public static List getLastDeclined(UUID uuid){ - return getLastDelined(SteamwarUser.get(uuid).getId()); - } - - public static List getLastDelined(int schemOwner){ - return checkHistory.select(rs -> { - List history = new ArrayList<>(); - while(rs.next()) - history.add(new CheckedSchematic(rs)); - return history; - }, schemOwner); - } - - public int getValidator() { - return validator; - } - - public Timestamp getStartTime() { - return startTime; - } - - public Timestamp getEndTime() { - return endTime; - } - - public String getDeclineReason() { - return declineReason; - } - - public int getNode() { - return node; - } - - public String getSchemName() { - return SchematicNode.getSchematicNode(node).getName(); - } - - public int getSchemOwner() { - return SchematicNode.getSchematicNode(node).getId(); - } -} diff --git a/src/de/steamwar/bungeecore/sql/IgnoreSystem.java b/src/de/steamwar/bungeecore/sql/IgnoreSystem.java deleted file mode 100644 index 9631f5a..0000000 --- a/src/de/steamwar/bungeecore/sql/IgnoreSystem.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.internal.Statement; -import net.md_5.bungee.api.connection.ProxiedPlayer; - -import java.sql.ResultSet; - -public class IgnoreSystem{ - - private static final Statement select = new Statement("SELECT * FROM IgnoredPlayers WHERE Ignorer = ? AND Ignored = ?"); - private static final Statement insert = new Statement("INSERT INTO IgnoredPlayers (Ignorer, Ignored) VALUES (?, ?)"); - private static final Statement delete = new Statement("DELETE FROM IgnoredPlayers WHERE Ignorer = ? AND Ignored = ?"); - - private IgnoreSystem(){} - - public static boolean isIgnored(ProxiedPlayer ignorer, ProxiedPlayer ignored){ - SteamwarUser user = SteamwarUser.get(ignorer.getUniqueId()); - SteamwarUser target = SteamwarUser.get(ignored.getUniqueId()); - return isIgnored(user, target); - } - - public static boolean isIgnored(SteamwarUser ignorer, SteamwarUser ignored) { - return select.select(ResultSet::next, ignorer.getId(), ignored.getId()); - } - - public static void ignore(SteamwarUser ignorer, SteamwarUser ignored) { - insert.update(ignorer.getId(), ignored.getId()); - } - - public static void unIgnore(SteamwarUser ignorer, SteamwarUser ignored) { - delete.update(ignorer.getId(), ignored.getId()); - } -} diff --git a/src/de/steamwar/bungeecore/sql/SchematicNode.java b/src/de/steamwar/bungeecore/sql/SchematicNode.java deleted file mode 100644 index e8bca5b..0000000 --- a/src/de/steamwar/bungeecore/sql/SchematicNode.java +++ /dev/null @@ -1,507 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bungeecore.sql; - - -import de.steamwar.sql.NodeMember; -import de.steamwar.sql.SchematicType; -import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.internal.Statement; - -import java.io.InputStream; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.time.Instant; -import java.util.*; -import java.util.function.Predicate; - -public class SchematicNode { - private static final Statement createNode = new Statement("INSERT INTO SchematicNode (NodeName, NodeOwner, ParentNode, NodeType, NodeItem) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE NodeName = VALUES(NodeName), ParentNode = VALUES(ParentNode), NodeItem = VALUES(NodeItem), NodeType = VALUES(NodeType), NodeItem = VALUES(NodeItem)"); - private static final Statement getSchematicNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL"); - private static final Statement getSchematicNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?"); - private static final Statement getSchematicsInNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL"); - private static final Statement getSchematicsInNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ?"); - private static final Statement getDirsInNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL AND NodeType is NULL"); - private static final Statement getDirsInNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ? AND NodeType is NULL"); - private static final Statement getSchematicDirectory_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL"); - private static final Statement getSchematicDirectory = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?"); - private static final Statement getSchematicNodeO_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL"); - private static final Statement getSchematicNodeO = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?"); - private static final Statement getSchematicNodeId = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ?"); - private static final Statement getAllSchemsOfTypeOwner = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ?"); - private static final Statement getAllSchemsOfType = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeType = ?"); - private static final Statement getAccessibleByUser = new Statement("SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) AND ((s.NodeOwner = ? AND s.ParentNode IS NULL) OR NOT s.NodeOwner = ?) GROUP BY s.NodeId ORDER BY s.NodeName"); - private static final Statement getAccessibleByUserByTypeInNode = new Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode = ?"); - private static final Statement getAccessibleByUserByTypeInNode_Null = new Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode is null"); - private static final Statement getAccessibleByUserByType = new Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ?"); - private static final Statement getAllSchematicsAccessibleByUser = new Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN"); - private static final Statement isSchematicAccessibleForUser = new Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT COUNT(RSN.NodeId) AS `Accessible` FROM RSN LEFT Join NodeMember NM On NM.NodeId = RSN.NodeId WHERE NodeOwner = ? OR UserId = ? LIMIT 1"); - private static final Statement getAllParentsOfNode = new Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? UNION SELECT SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT * FROM RSN"); - private static final Statement countNodes = new Statement("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode"); - private static final Statement updateDB = new Statement("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ? WHERE NodeId = ?"); - private static final Statement updateDatabase = new Statement("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?"); - private static final Statement selSchemData = new Statement("SELECT NodeData FROM SchematicNode WHERE NodeId = ?"); - private static final Statement deleteNode = new Statement("DELETE FROM SchematicNode WHERE NodeId = ?"); - - public static SchematicNode createSchematic(int owner, String name, Integer parent) { - return createSchematicNode(owner, name, parent, SchematicType.Normal.toDB(), ""); - } - - public static SchematicNode createSchematicDirectory(int owner, String name, Integer parent) { - return createSchematicNode(owner, name, parent, null, ""); - } - - public static SchematicNode createSchematicNode(int owner, String name, Integer parent, String type, String item) { - if (parent != null && parent == 0) - parent = null; - createNode.update(name, owner, parent, type, item); - return getSchematicNode(owner, name, parent); - } - - private Timestamp lastUpdate; - - public static SchematicNode getSchematicNode(int owner, String name, SchematicNode parent) { - return getSchematicNode(owner, name, parent.getId()); - } - - private SchematicNode(ResultSet set) throws SQLException { - id = set.getInt("NodeId"); - owner = set.getInt("NodeOwner"); - name = set.getString("NodeName"); - parent = set.getInt("ParentNode"); - if(set.wasNull()) { - parent = null; - } - item = set.getString("NodeItem"); - type = set.getString("NodeType"); - lastUpdate = set.getTimestamp("LastUpdate"); - if (type != null) { - isDir = false; - rank = set.getInt("NodeRank"); - schemFormat = set.getBoolean("NodeFormat"); - } else { - isDir = true; - } - } - - public static List getSchematicNodeInNode(SchematicNode parent) { - return getSchematicNodeInNode(parent.getId()); - } - - public static SchematicNode getSchematicDirectory(String name, SchematicNode parent) { - return getSchematicDirectory(name, parent.getId()); - } - - public static SchematicNode getSchematicNode(int owner, String name, Integer parent) { - if (parent != null && parent == 0) { - parent = null; - } - Statement.ResultSetUser user = rs -> { - while (rs.next()) { - SchematicNode node = new SchematicNode(rs); - return node; - } - return null; - }; - if(parent == null) { - return getSchematicNode_Null.select(user, owner, name); - } else { - return getSchematicNode.select(user, owner, name, parent); - } - } - - public static List getSchematicNodeInNode(Integer parent) { - if(parent != null && parent == 0) - parent = null; - Statement.ResultSetUser> user = rs -> { - List nodes = new ArrayList<>(); - while (rs.next()) - nodes.add(new SchematicNode(rs)); - return nodes; - }; - if(parent == null) { - return getSchematicsInNode_Null.select(user); - }else { - return getSchematicsInNode.select(user, parent); - } - } - - public static List getSchematicDirectoryInNode(Integer parent) { - if(parent != null && parent == 0) - parent = null; - Statement.ResultSetUser> user = rs -> { - List nodes = new ArrayList<>(); - while (rs.next()) - nodes.add(new SchematicNode(rs)); - return nodes; - }; - if(parent == null) { - return getDirsInNode_Null.select(user); - }else { - return getDirsInNode.select(user, parent); - } - } - - public static SchematicNode getSchematicDirectory(String name, Integer parent) { - if(parent != null && parent == 0) - parent = null; - Statement.ResultSetUser user = rs -> { - while (rs.next()) { - SchematicNode node = new SchematicNode(rs); - if(node.isDir()) - return node; - } - return null; - }; - - if(parent == null) { - return getSchematicDirectory_Null.select(user, name); - }else { - return getSchematicDirectory.select(user, name, parent); - } - } - - public static SchematicNode getSchematicNode(String name, Integer parent) { - if(parent != null && parent == 0) - parent = null; - Statement.ResultSetUser user = rs -> { - while (rs.next()) { - return new SchematicNode(rs); - } - return null; - }; - if(parent == null) { - return getSchematicNodeO_Null.select(user, name); - }else { - return getSchematicNodeO.select(user, name, parent); - } - } - - public static SchematicNode getSchematicNode(int id) { - return getSchematicNodeId.select(rs -> { - if (!rs.next()) - return null; - return new SchematicNode(rs); - }, id); - } - - public static List getAccessibleSchematicsOfTypeInParent(int owner, String schemType, Integer parent) { - Statement.ResultSetUser> user = rs -> { - List nodes = new ArrayList<>(); - while (rs.next()) { - nodes.add(new SchematicNode(rs)); - } - return nodes; - }; - if(parent == null || parent == 0) { - return getAccessibleByUserByTypeInNode_Null.select(user, owner, owner, schemType); - } else { - return getAccessibleByUserByTypeInNode.select(user, owner, owner, schemType, parent); - } - } - - public static List getAllAccessibleSchematicsOfType(int user, String schemType) { - return getAccessibleByUserByType.select(rs -> { - List nodes = new ArrayList<>(); - while (rs.next()) { - nodes.add(new SchematicNode(rs)); - } - return nodes; - }, user, user, schemType); - } - - public static List getAllSchematicsOfType(int owner, String schemType) { - return getAllSchemsOfTypeOwner.select(rs -> { - List nodes = new ArrayList<>(); - while (rs.next()) - nodes.add(new SchematicNode(rs)); - return nodes; - }, owner, schemType); - } - - public static List getAllSchematicsOfType(String schemType) { - return getAllSchemsOfType.select(rs -> { - List nodes = new ArrayList<>(); - while (rs.next()) - nodes.add(new SchematicNode(rs)); - return nodes; - }, schemType); - } - - public static List deepGet(Integer parent, Predicate filter) { - List finalList = new ArrayList<>(); - List nodes = SchematicNode.getSchematicNodeInNode(parent); - nodes.forEach(node -> { - if (node.isDir()) { - finalList.addAll(deepGet(node.getId(), filter)); - } else { - if (filter.test(node)) - finalList.add(node); - } - }); - return finalList; - } - - public static List getSchematicsAccessibleByUser(int user, Integer parent) { - if (parent != null && parent != 0) { - if(isSchematicAccessibleForUser.select(rs -> { - rs.next(); - return rs.getInt("Accessible") > 0; - }, parent, user, user)) - return getSchematicNodeInNode(parent); - } else { - return getAccessibleByUser.select(rs -> { - List nodes = new ArrayList<>(); - while(rs.next()) - nodes.add(new SchematicNode(rs)); - return nodes; - }, user, user, user, user); - } - return Collections.emptyList(); - } - - public static List getAllSchematicsAccessibleByUser(int user) { - return getAllSchematicsAccessibleByUser.select(rs -> { - List nodes = new ArrayList<>(); - while(rs.next()) { - nodes.add(new SchematicNode(rs)); - } - return nodes; - }, user, user); - } - - public static List getAllParentsOfNode(SchematicNode node) { - return getAllParentsOfNode(node.getId()); - } - - public static List getAllParentsOfNode(int node) { - return getAllParentsOfNode.select(rs -> { - List nodes = new ArrayList<>(); - while(rs.next()) { - nodes.add(new SchematicNode(rs)); - } - return nodes; - }, node); - } - - private final int id; - private final int owner; - private String name; - private Integer parent; - private String item; - private String type; - private boolean schemFormat; - private int rank; - private final boolean isDir; - private Map brCache = new HashMap<>(); - - public static List filterSchems(int user, Predicate filter) { - List finalList = new ArrayList<>(); - List nodes = SchematicNode.getSchematicsAccessibleByUser(user, null); - nodes.forEach(node -> { - if (node.isDir()) { - finalList.addAll(deepGet(node.getId(), filter)); - } else { - if (filter.test(node)) - finalList.add(node); - } - }); - return finalList; - } - - public static Integer countNodes() { - return countNodes.select(rs -> { - if (rs.next()) { - return rs.getInt("count"); - } - return 0; - }); - } - - public int getId() { - return id; - } - - public int getOwner() { - return owner; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - updateDB(); - } - - public Integer getParent() { - return parent; - } - - public void setParent(Integer parent) { - this.parent = parent; - updateDB(); - } - - public String getItem() { - return item; - } - - public void setItem(String item) { - this.item = item; - updateDB(); - } - - public String getType() { - if(isDir) - throw new SecurityException("Node is Directory"); - return type; - } - - public void setType(String type) { - if(isDir) - throw new SecurityException("Node is Directory"); - this.type = type; - updateDB(); - } - - public boolean isDir() { - return isDir; - } - - public boolean getSchemFormat() { - if(isDir) - throw new SecurityException("Node is Directory"); - return schemFormat; - } - - public int getRank() { - if(isDir) - throw new SecurityException("Node is Directory"); - return rank; - } - - public void setRank(int rank) { - if(isDir) - throw new SecurityException("Node is Directory"); - this.rank = rank; - } - - public SchematicType getSchemtype() { - if(isDir()) - throw new RuntimeException("Is Directory"); - return SchematicType.fromDB(type); - } - - public SchematicNode getParentNode() { - if(parent == null) return null; - return SchematicNode.getSchematicNode(parent); - } - - public boolean accessibleByUser(int user) { - return NodeMember.getNodeMember(id, user) != null; - } - - public Set getMembers() { - return NodeMember.getNodeMembers(id); - } - - public Timestamp getLastUpdate() { - return lastUpdate; - } - - public String generateBreadcrumbs(SteamwarUser user) { - return brCache.computeIfAbsent(user.getId(), integer -> generateBreadcrumbs("/", user)); - } - - public String generateBreadcrumbs(String split, SteamwarUser user) { - StringBuilder builder = new StringBuilder(getName()); - SchematicNode currentNode = this; - if (currentNode.isDir()) builder.append("/"); - while (currentNode.getParentNode() != null) { - currentNode = currentNode.getParentNode(); - builder.insert(0, split) - .insert(0, currentNode.getName()); - if (currentNode.getMembers().stream().anyMatch(member -> member.getMember() == user.getId())) { - break; - } - } - return builder.toString(); - } - - private void updateDB() { - updateDB.update(name, owner, parent, item, type, rank, id); - this.lastUpdate = Timestamp.from(Instant.now()); - this.brCache.clear(); - } - - public void delete() { - if (isDir()) { - getSchematicNodeInNode(getId()).forEach(SchematicNode::delete); - } - deleteNode.update(id); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof SchematicNode)) - return false; - - SchematicNode node = (SchematicNode) obj; - return node.getId() == id; - } - - public void saveFromStream(InputStream stream, boolean newFormat) { - if(isDir) - throw new SecurityException("Node is Directory"); - updateDatabase(stream, newFormat); - } - - private void updateDatabase(InputStream blob, boolean newFormat) { - updateDatabase.update(blob, newFormat, id); - schemFormat = newFormat; - } - - private static final List FORBIDDEN_NAMES = Collections.unmodifiableList(Arrays.asList("public")); - - public static boolean invalidSchemName(String[] layers) { - for (String layer : layers) { - if (layer.isEmpty()) { - return true; - } - if (layer.contains("/") || - layer.contains("\\") || - layer.contains("<") || - layer.contains(">") || - layer.contains("^") || - layer.contains("°") || - layer.contains("'") || - layer.contains("\"")) { - return true; - } - if(FORBIDDEN_NAMES.contains(layer.toLowerCase())) { - return true; - } - } - return false; - } -} diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java deleted file mode 100644 index ba708cb..0000000 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.bungeecore.ArenaMode; -import de.steamwar.bungeecore.Message; -import de.steamwar.sql.Season; -import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.internal.Statement; -import net.md_5.bungee.api.connection.ProxiedPlayer; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; - -public class UserElo { - private UserElo() {} - - public static final int ELO_DEFAULT = 1000; - - private static final Map>> gameModeUserEloCache = new ConcurrentHashMap<>(); - private static final Map maxEloCache = new ConcurrentHashMap<>(); - private static final Map emblemCache = new ConcurrentHashMap<>(); - - private static final Statement elo = new Statement("SELECT Elo FROM UserElo WHERE UserID = ? AND GameMode = ? AND Season = ?"); - private static final Statement setElo = new Statement("INSERT INTO UserElo (Season, GameMode, UserID, Elo) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE Elo = VALUES(Elo)"); - private static final Statement maxElo = new Statement("SELECT MAX(Elo) AS MaxElo FROM UserElo WHERE Season = ? AND GameMode = ?"); - - private static final Statement place = new Statement("SELECT COUNT(*) AS Place FROM UserElo WHERE GameMode = ? AND Elo > ? AND Season = ?"); - private static final Statement fightsOfSeason = new Statement("SELECT COUNT(*) AS Fights FROM FightPlayer INNER JOIN Fight F on FightPlayer.FightID = F.FightID WHERE UserID = ? AND GameMode = ? AND UNIX_TIMESTAMP(StartTime) + Duration >= UNIX_TIMESTAMP(?)"); - - public static int getEloOrDefault(int userID, String gameMode) { - return getElo(userID, gameMode).orElse(ELO_DEFAULT); - } - - public static Optional getElo(int userID, String gameMode) { - return gameModeUserEloCache.computeIfAbsent(gameMode, gm -> new HashMap<>()).computeIfAbsent(userID, uid -> elo.select(rs -> { - if (rs.next()) - return Optional.of(rs.getInt("Elo")); - return Optional.empty(); - }, userID, gameMode, Season.getSeason())); - } - - public static int getFightsOfSeason(int userID, String gameMode) { - return fightsOfSeason.select(rs -> { - if (rs.next()) - return rs.getInt("Fights"); - return 0; - }, userID, gameMode, Season.getSeasonStart()); - } - - private static int getMaxElo(String gameMode) { - return maxEloCache.computeIfAbsent(gameMode, gm -> maxElo.select(rs -> { - if (rs.next()) - return rs.getInt("MaxElo"); - return 0; - }, Season.getSeason(), gameMode)); - } - - public static void setElo(int userId, String gameMode, int elo) { - emblemCache.remove(userId); - - Optional oldElo = Optional.ofNullable(gameModeUserEloCache.computeIfAbsent(gameMode, gm -> new HashMap<>()).put(userId, Optional.of(elo))).orElse(Optional.empty()); - int maxElo = getMaxElo(gameMode); - if (elo > maxElo || (oldElo.isPresent() && oldElo.get() == maxElo)) { - maxEloCache.remove(gameMode); - emblemCache.clear(); - } - - setElo.update(Season.getSeason(), gameMode, userId, elo); - } - - public static int getPlacement(int elo, String gameMode) { - return place.select(rs -> { - if (rs.next()) - return rs.getInt("Place") + 1; - return -1; - }, gameMode, elo, Season.getSeason()); - } - - public static String getEmblem(SteamwarUser user) { - return emblemCache.computeIfAbsent(user.getId(), userId -> { - switch( - ArenaMode.getAllModes().stream().filter( - ArenaMode::isRanked - ).filter( - mode -> UserElo.getFightsOfSeason(user.getId(), mode.getSchemType()) >= 10 - ).map( - mode -> getProgression(user.getId(), mode.getSchemType()) - ).max(Integer::compareTo).orElse(0) - ) { - case 0: - return ""; - case 1: - return "§7✧ "; - case 2: - return "§f✦ "; - case 3: - return "§e✶ "; - case 4: - return "§a✷ "; - case 5: - return "§b✸ "; - case 6: - return "§c✹ "; - case 7: - return "§5❂ "; - default: - throw new SecurityException("Progression out of range"); - } - }); - } - - public static String getEmblemProgression(ProxiedPlayer player, String gameMode, int userId) { - int fightsOfSeason = getFightsOfSeason(userId, gameMode); - if (fightsOfSeason < 10) - return Message.parse("RANK_NEEDED_FIGHTS_LEFT", player, "§8✧ ✦ ✶ ✷ ✸ ✹ ❂", 10 - fightsOfSeason); - - switch (getProgression(userId, gameMode)) { - case 0: - return "§8✧ ✦ ✶ ✷ ✸ ✹ ❂"; - case 1: - return "§7✧ §8✦ ✶ ✷ ✸ ✹ ❂"; - case 2: - return "§8✧ §f✦ §8✶ ✷ ✸ ✹ ❂"; - case 3: - return "§8✧ ✦ §e✶ §8✷ ✸ ✹ ❂"; - case 4: - return "§8✧ ✦ ✶ §a✷ §8✸ ✹ ❂"; - case 5: - return "§8✧ ✦ ✶ ✷ §b✸ §8✹ ❂"; - case 6: - return "§8✧ ✦ ✶ ✷ ✸ §c✹ §8❂"; - case 7: - return "§8✧ ✦ ✶ ✷ ✸ ✹ §5❂"; - default: - throw new SecurityException("Progression is not in range"); - } - } - - private static int getProgression(int userId, String gameMode) { - int elo = UserElo.getElo(userId, gameMode).orElse(0); - if(elo == 0) - return 0; - int maxElo = UserElo.getMaxElo(gameMode); - - if (elo > maxElo * 0.99) return 7; - if (elo > maxElo * 0.97) return 6; - if (elo > maxElo * 0.94) return 5; - if (elo > maxElo * 0.88) return 4; - if (elo > maxElo * 0.76) return 3; - if (elo > maxElo * 0.51) return 2; - return 1; - } - - public static void clearCache() { - gameModeUserEloCache.clear(); - maxEloCache.clear(); - emblemCache.clear(); - } -} diff --git a/src/de/steamwar/sql/SchematicData.java b/src/de/steamwar/sql/SchematicData.java new file mode 100644 index 0000000..6152ad9 --- /dev/null +++ b/src/de/steamwar/sql/SchematicData.java @@ -0,0 +1,47 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.sql; + +import de.steamwar.sql.internal.SqlTypeMapper; +import de.steamwar.sql.internal.Statement; + +import java.io.BufferedInputStream; +import java.io.InputStream; +import java.sql.PreparedStatement; + +public class SchematicData { + + static { + new SqlTypeMapper<>(BufferedInputStream.class, "BLOB", (rs, identifier) -> { throw new SecurityException("PipedInputStream is write only datatype"); }, PreparedStatement::setBinaryStream); + } + + private static final Statement updateDatabase = new Statement("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?"); + + private final SchematicNode node; + + public SchematicData(SchematicNode node) { + this.node = node; + } + + public void saveFromStream(InputStream blob, boolean newFormat) { + updateDatabase.update(new BufferedInputStream(blob), newFormat, node.getId()); + node.setNodeFormat(newFormat); + } +} \ No newline at end of file From 87db98a310649cceee6bd674dae0c1bc6c180762 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 21 Feb 2023 20:38:19 +0100 Subject: [PATCH 23/31] Fix 3 things --- src/de/steamwar/bungeecore/commands/JoinmeCommand.java | 2 +- src/de/steamwar/bungeecore/commands/TeamCommand.java | 2 +- src/de/steamwar/bungeecore/commands/TeamchatCommand.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java index 7b707e5..b705c8d 100644 --- a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java +++ b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java @@ -81,7 +81,7 @@ public class JoinmeCommand extends SWCommand { } } - @ClassMapper(ProxiedPlayer.class) + @ClassValidator(ProxiedPlayer.class) public TypeValidator playerMapper() { return (sender, value, messageSender) -> { if (value == null || !value.isConnected()) { diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index dbe2ad7..877b2a2 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -445,7 +445,7 @@ public class TeamCommand extends SWCommand { } @Register("event") - public void event(ProxiedPlayer player, String[] args){ + public void event(ProxiedPlayer player, String... args){ SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Team team = Team.get(user.getTeam()); if(notInTeam(player, user)) diff --git a/src/de/steamwar/bungeecore/commands/TeamchatCommand.java b/src/de/steamwar/bungeecore/commands/TeamchatCommand.java index 8d5e3e3..f96a793 100644 --- a/src/de/steamwar/bungeecore/commands/TeamchatCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamchatCommand.java @@ -32,7 +32,7 @@ public class TeamchatCommand extends SWCommand { super("tc", "","teamchat"); } - @Register + @Register(description = "TC_USAGE") public void genericCommand(ProxiedPlayer player, @ErrorMessage(value = "TC_USAGE", allowEAs = false) String... args) { ChatSender sender = ChatSender.of(player); SteamwarUser user = sender.user(); From ba064a1f9e864a9d15c00c798f414d37f8ac094b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 21 Feb 2023 20:45:00 +0100 Subject: [PATCH 24/31] Fix another one --- .../bungeecore/commands/TeamCommand.java | 65 +++++++++++++------ 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index 877b2a2..2e647eb 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -24,7 +24,9 @@ import de.steamwar.bungeecore.Storage; import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.bungeecore.inventory.SWListInv; import de.steamwar.bungeecore.sql.*; +import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeMapper; import de.steamwar.messages.ChatSender; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.ChatColor; @@ -42,10 +44,7 @@ import net.md_5.bungee.api.event.ServerConnectEvent; import java.net.*; import java.time.Instant; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import static de.steamwar.bungeecore.Storage.teamInvitations; @@ -445,23 +444,28 @@ public class TeamCommand extends SWCommand { } @Register("event") - public void event(ProxiedPlayer player, String... args){ + public void event(ProxiedPlayer player) { SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Team team = Team.get(user.getTeam()); if(notInTeam(player, user)) return; - if(args.length < 2){ - Message.send("TEAM_EVENT_USAGE", player); - Set events = TeamTeilnahme.getEvents(team.getTeamId()); - if(!events.isEmpty()){ - Message.send("TEAM_EVENT_HEADER", player); - DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern(Message.parse("EVENT_DATE_FORMAT", player)); - for(Event e : events) - Message.sendPrefixless("TEAM_EVENT_EVENT", player, e.getStart().toLocalDateTime().format(dateFormat), e.getEventName()); - } - return; + Message.send("TEAM_EVENT_USAGE", player); + Set events = TeamTeilnahme.getEvents(team.getTeamId()); + if(!events.isEmpty()){ + Message.send("TEAM_EVENT_HEADER", player); + DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern(Message.parse("EVENT_DATE_FORMAT", player)); + for(Event e : events) + Message.sendPrefixless("TEAM_EVENT_EVENT", player, e.getStart().toLocalDateTime().format(dateFormat), e.getEventName()); } + } + + @Register("event") + public void event(ProxiedPlayer player, Event event){ + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + Team team = Team.get(user.getTeam()); + if(notInTeam(player, user)) + return; if(notLeader(player, user)) return; @@ -469,12 +473,6 @@ public class TeamCommand extends SWCommand { if(notDuringEvent(player)) return; - Event event = Event.get(args[1]); - if(event == null){ - Message.send("TEAM_EVENT_NO_EVENT", player); - return; - } - if(Instant.now().isAfter(event.getDeadline().toInstant())){ Message.send("TEAM_EVENT_OVER", player); return; @@ -603,6 +601,31 @@ public class TeamCommand extends SWCommand { inv.open(); } + @ClassMapper(Event.class) + public TypeMapper eventTypeMapper() { + return new TypeMapper() { + @Override + public Event map(CommandSender commandSender, String[] previousArguments, String s) { + return Event.get(s); + } + + @Override + public boolean validate(CommandSender sender, Event value, MessageSender messageSender) { + if (value == null) { + messageSender.send("TEAM_EVENT_NO_EVENT", sender); + return false; + } else { + return true; + } + } + + @Override + public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { + return Event.getComing().stream().map(Event::getEventName).collect(Collectors.toList()); + } + }; + } + private boolean checkTeamName(ProxiedPlayer player, Team team, String arg){ Team t = Team.get(arg); if(t != null && t.getTeamId() != team.getTeamId()){ From 02c8538d76db2a086a66927ef6c6d2ab22c24ed6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 21 Feb 2023 20:49:38 +0100 Subject: [PATCH 25/31] Fix another some weird tab completes --- src/de/steamwar/bungeecore/commands/BauCommand.java | 2 +- src/de/steamwar/bungeecore/commands/TeamCommand.java | 2 +- src/de/steamwar/command/SWCommand.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 7bf45b9..51b33b9 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -48,7 +48,7 @@ public class BauCommand extends SWCommand { this.command = command; } - @Register(help = true) + @Register(noTabComplete = true) public void genericHelp(ProxiedPlayer p, String... args) { this.command.sendBauHelp(p); } diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index 2e647eb..39c1ac3 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -80,7 +80,7 @@ public class TeamCommand extends SWCommand { super("team"); } - @Register + @Register(noTabComplete = true) public void help(CommandSender sender, String... args){ Message.send("TEAM_HELP_HEADER", sender); Message.send("TEAM_HELP_LIST", sender); diff --git a/src/de/steamwar/command/SWCommand.java b/src/de/steamwar/command/SWCommand.java index 63bbace..83b4d8d 100644 --- a/src/de/steamwar/command/SWCommand.java +++ b/src/de/steamwar/command/SWCommand.java @@ -120,7 +120,7 @@ public class SWCommand extends AbstractSWCommand { ChatSender.of(sender).system(message, args); } - @Register(help = true) + @Register(noTabComplete = true) public void internalHelp(ProxiedPlayer p, String... args) { ChatSender chatSender = ChatSender.of(p); try { From 6e30c5e7bad559b1c27b34634520bda858da0869 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 22 Feb 2023 15:15:55 +0100 Subject: [PATCH 26/31] Hotfix TeamCommand info --- src/de/steamwar/bungeecore/commands/TeamCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index 39c1ac3..9b0a3e9 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -366,7 +366,7 @@ public class TeamCommand extends SWCommand { if(args.length == 1 && user.getTeam() == 0){ Message.send("TEAM_INFO_USAGE", player); return; - }else if(user.getTeam() == 0 || args.length == 2){ + }else if(user.getTeam() == 0 || args.length == 1){ team = Team.get(args[1]); } From 99750ca767d4fc861299266e1102b3aeaebedcd7 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 22 Feb 2023 16:18:16 +0100 Subject: [PATCH 27/31] Fix Bugs Signed-off-by: Lixfel --- CommonCore | 2 +- src/de/steamwar/bungeecore/ServerStarter.java | 4 ++-- src/de/steamwar/bungeecore/commands/EventCommand.java | 5 ++--- src/de/steamwar/bungeecore/commands/TutorialCommand.java | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/CommonCore b/CommonCore index 9b53ad7..588d3c9 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 9b53ad748b32cc38ade1ccc606b116c0d6fbf1fb +Subproject commit 588d3c9dda47a8e61e4e01eea9c915f9d853eb3b diff --git a/src/de/steamwar/bungeecore/ServerStarter.java b/src/de/steamwar/bungeecore/ServerStarter.java index d2ec14f..48aa65a 100644 --- a/src/de/steamwar/bungeecore/ServerStarter.java +++ b/src/de/steamwar/bungeecore/ServerStarter.java @@ -144,8 +144,8 @@ public class ServerStarter { public ServerStarter tutorial(ProxiedPlayer owner, Tutorial tutorial) { directory = new File(SERVER_PATH, "Tutorial"); buildWithTemp(owner); - tempWorld(TUTORIAL_PATH + tutorial.getId()); - arguments.put("tutorial", String.valueOf(tutorial.getId())); + tempWorld(TUTORIAL_PATH + tutorial.getTutorialId()); + arguments.put("tutorial", String.valueOf(tutorial.getTutorialId())); return send(owner); } diff --git a/src/de/steamwar/bungeecore/commands/EventCommand.java b/src/de/steamwar/bungeecore/commands/EventCommand.java index fd8d88c..9ea7c9b 100644 --- a/src/de/steamwar/bungeecore/commands/EventCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventCommand.java @@ -64,10 +64,9 @@ public class EventCommand extends SWCommand { if(now.isBefore(e.getDeadline().toInstant())) { Message.send("EVENT_COMING_DEADLINE", player, e.getDeadline()); } - String schemType = e.getSchemType(); + SchematicType schemType = e.getSchematicType(); if (schemType != null) { - SchematicType schematicType = SchematicType.fromDB(schemType); - if (schematicType != null && schematicType.getDeadline() != null && now.isBefore(schematicType.getDeadline().toInstant())) { + if (schemType.getDeadline() != null && now.isBefore(schemType.getDeadline().toInstant())) { Message.send("EVENT_COMING_SCHEM_DEADLINE", player, e.getDeadline()); } } diff --git a/src/de/steamwar/bungeecore/commands/TutorialCommand.java b/src/de/steamwar/bungeecore/commands/TutorialCommand.java index 57dec80..9fdc967 100644 --- a/src/de/steamwar/bungeecore/commands/TutorialCommand.java +++ b/src/de/steamwar/bungeecore/commands/TutorialCommand.java @@ -165,6 +165,6 @@ public class TutorialCommand extends SWCommand { } private File world(Tutorial tutorial) { - return new File(ServerStarter.TUTORIAL_PATH, String.valueOf(tutorial.getId())); + return new File(ServerStarter.TUTORIAL_PATH, String.valueOf(tutorial.getTutorialId())); } } From b096f8251c89d00ec43a19a4014cd040b6c8ff0a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 22 Feb 2023 16:51:45 +0100 Subject: [PATCH 28/31] Hotfix TeamCommand info --- src/de/steamwar/bungeecore/commands/TeamCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index 9b0a3e9..2bf5ddc 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -367,7 +367,7 @@ public class TeamCommand extends SWCommand { Message.send("TEAM_INFO_USAGE", player); return; }else if(user.getTeam() == 0 || args.length == 1){ - team = Team.get(args[1]); + team = Team.get(args[0]); } if(team == null){ From 242e19adb2ab58952aca569534c5399334317733 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 22 Feb 2023 20:07:06 +0100 Subject: [PATCH 29/31] Hotfix TeamCommand tp and join --- src/de/steamwar/bungeecore/commands/TeamCommand.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index 2bf5ddc..ab010db 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -151,7 +151,7 @@ public class TeamCommand extends SWCommand { if(invs.size() == 1){ t = invs.get(0); }else{ - if(args.length != 2){ + if(args.length != 1){ Message.send("TEAM_JOIN_USAGE", player); StringBuilder sb = new StringBuilder(); for(int inv : invs){ @@ -164,7 +164,7 @@ public class TeamCommand extends SWCommand { for(int inv : invs){ Team team = Team.get(inv); - if(team.getTeamName().equals(args[1])){ + if(team.getTeamName().equals(args[0])){ t = inv; break; } @@ -492,13 +492,13 @@ public class TeamCommand extends SWCommand { public void tp(ProxiedPlayer player, String... args){ SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Team team = Team.get(user.getTeam()); - if(args.length == 1){ + if(args.length == 0){ if(notInTeam(player, user)) return; tp(player, team); return; } - Team targetTeam = Team.get(args[1]); + Team targetTeam = Team.get(args[0]); if(targetTeam == null){ Message.send("TEAM_TP_NO_TEAM", player); return; From 06432868cc16757de55edb55a960002b843c74be Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 23 Feb 2023 08:07:29 +0100 Subject: [PATCH 30/31] Update to CommonCore master Signed-off-by: Lixfel --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index 588d3c9..b2b96cf 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 588d3c9dda47a8e61e4e01eea9c915f9d853eb3b +Subproject commit b2b96cff0477dc3078c1abfd8f8b047e3a6d903d From 0d6e1f54bd838ec5517f00ea4b5f510a8f822b07 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 23 Feb 2023 08:35:43 +0100 Subject: [PATCH 31/31] Update check --- src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java b/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java index 3c2dbb8..0f825ab 100644 --- a/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java +++ b/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java @@ -54,7 +54,7 @@ public class NonFabricFabricCheck extends BasicListener { return; ProxiedPlayer p = (ProxiedPlayer) sender; - if (e.getTag().equals("minecraft:register") && new String(e.getData()).contains("fabric")) { + if (e.getTag().equals("minecraft:register") && new String(e.getData()).contains("fabric-screen-handler-api-v1:open_screen")) { BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { if (!sender.isConnected()) return; if (!vanilla.remove(p)) return;