From be5833c0d0a0effb028a0d91c59ffd679881548d Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 23 Jan 2023 16:30:35 +0100 Subject: [PATCH 1/8] WIP CommonDB 2 Signed-off-by: Lixfel --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index d12fbbd3..e2654e72 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 2/8] 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 d1af1286..279a6273 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 0de56678..7113e5d8 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 9373b57f..f3b805a0 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 3811c185..759edcca 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 29bbe85d..00ec1b8a 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 e0b35453..c6448ebb 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 34c65e88..844d1e29 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 79ef2e3b..cd577675 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 a08f74d2..33054ee3 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 06dc3bcc..9740cc7a 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 96484236..b3e5990a 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 75f718f8..e106d59e 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 4a95e462..e44a3187 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 5e179cda..4e3a3bd5 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 554efcce..49517711 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 1130108a..ff012b9e 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 9ae37990..3f45be6b 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 de618858..7025b10b 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 d0ff1473..c9dc9d7d 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 1b80d754..095f0fcd 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 a868ba30..f5b31bb3 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 827fe3eb..68e86f72 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 5256709c..a5123d31 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 852703ce..48d498f7 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 85ca553b..69a4fb37 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 aa3e5c86..dcc8d960 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 440ab121..318bdd9c 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 db569c1f..d4739c6d 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 f01bf446..f1fcd5a5 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 3d779190..00000000 --- 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 f69a7719..00000000 --- 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 5d75fc35..00000000 --- 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 c2ad2adf..00000000 --- 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 6cde50c8..463dee7e 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 8416cb0f..00000000 --- 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 8f9a64e5..00000000 --- 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 29e127af..00000000 --- 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 c5f0a344..8f58e137 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 093165fc..00000000 --- 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 f5eae0df..00000000 --- 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 3fad94e0..f42f53e4 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 83e8e0af..4cb71d84 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 a77f33dd..00000000 --- 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 6196ad61..b28b0cdb 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 b2c79bd2..00000000 --- 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 ed5df184..3b26c30c 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 6ca7a9ae..00000000 --- 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 b140114d..cdc86668 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 00000000..2eb4c38a --- /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 00000000..a5626b1c --- /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 871e45ffbbf422f475e3b237079158ff70d16efc Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 4 Feb 2023 12:55:08 +0100 Subject: [PATCH 3/8] 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 fca45b08..d439ecb8 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 abb6b77d..d33aeeb8 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 cd577675..1cd09d3e 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 9740cc7a..b73855fd 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 02fc7a87..e231f75b 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 e106d59e..082b9b7c 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 e897ba0e..5c9d589e 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 ff012b9e..86aca8f6 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 7025b10b..9b48eaa4 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 1370a0db..0f236d6c 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 b6a3f6be..d6dc4a0b 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 c59c8df9..2f25c444 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 66222bf6..00000000 --- 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 463dee7e..7de3de00 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 66a91832..9c91c02b 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 95920708..00000000 --- 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 f564ff25..176dfd4d 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 4/8] 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 d439ecb8..3e1c4e90 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 6d3a3d7c..cd52b485 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 7113e5d8..67a2d7ee 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 f3b805a0..5ad9a6f7 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 c6448ebb..b8c5d4e4 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 8608047c..0ce37b3a 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 33054ee3..c6f61e9f 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 e44a3187..16e98e14 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 3f45be6b..e7ee3353 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 9b48eaa4..d7bb956d 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 095f0fcd..856e99a6 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 68e86f72..dd84a9f1 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 4cb71d84..00000000 --- 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 c4bafb459186e000cf962baec7865422ce1c3c21 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 21 Feb 2023 18:22:42 +0100 Subject: [PATCH 5/8] 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 3e1c4e90..8dbf62e5 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 1ff556b4..f1aec11c 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 67a2d7ee..ddf78bd7 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 5ad9a6f7..d2ec14f2 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 98421541..b751f6eb 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 ac4f5539..8500f12a 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 e3289975..ed6569ef 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 00ec1b8a..8dbb58b5 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 086cf778..3c296f4d 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 b8c5d4e4..c07dbf2f 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 f8d6185d..61d5c0de 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 0ce37b3a..d2533727 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 1cd09d3e..884dd287 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 e407cf98..e53bf9a0 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 8ad34282..947ed5e5 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 70004ac4..13b5fca9 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 c6f61e9f..b21f427c 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 f7a2fa22..525dd086 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 8aafe2f6..0891c878 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 7224576b..e9ec8572 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 f0d9d7b6..9d9e2c71 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 d4b9c0ad..bb62a6eb 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 b73855fd..9cc60dae 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 b3e5990a..f93e23d0 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 5d203dbd..d3163caa 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 5cab0c27..521eef17 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 5858a49e..834f96df 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 082b9b7c..e71eeed8 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 16e98e14..13e8f594 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 9d5008a3..1c3d173b 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 5911db55..e5cf3e4c 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 25e37fa1..0158edfc 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 0c11ee0c..b7c26f7c 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 f5b4c667..ed6bbd7b 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 c9c3850d..c483ec98 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 4e3a3bd5..6cae84db 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 62e98315..23ba5f24 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 eca55186..c6610098 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 86aca8f6..e3189386 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 798a58cc..d02c53cd 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 e7ee3353..b28eb611 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 60e57dcb..1f9a491f 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 d7bb956d..ac93796f 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 c9dc9d7d..57dec807 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 bf882fd3..5b5b409b 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 d0755bdb..a7d7f72c 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 08aee06b..4d2cf645 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 856e99a6..581e618f 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 dac6be9e..637668c4 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 f5b31bb3..51ded5c6 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 dd84a9f1..4ac8851d 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 0f236d6c..e7b1e84a 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 33fd29ea..ddde4f79 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 48d498f7..4d2b23f0 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 69a4fb37..b0bf9527 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 dcc8d960..db5a8204 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 5affb64a..ec11c46d 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 c9c9d2ae..9bed4e08 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 d6ebf21c..ff5efb96 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 2bdd5a8e..02a90822 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 22887d49..20fcaca8 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 d4739c6d..15e66bb3 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 1b396256..f0030984 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 ae31db5a..91f80273 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 d6dc4a0b..34879156 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 03da0f95..b759f8ca 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 2f25c444..d9eae095 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 77815c49..44a90107 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 0a7072e1..00000000 --- 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 7de3de00..00000000 --- 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 b152805e..9631f5aa 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 897b7f92..00000000 --- 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 878982c8..00000000 --- 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 8bc3b4a3..00000000 --- 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 8f58e137..00000000 --- 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 9c91c02b..e8bca5b4 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 f42f53e4..00000000 --- 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 b28b0cdb..00000000 --- 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 3b26c30c..ba708cbb 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 151c320d..061ae927 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 54809408..812588df 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 2eb4c38a..43926dd7 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 833cd4b3..b83cb966 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 5b79204f..65834f68 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 6/8] 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 8dbf62e5..9b53ad74 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 f1aec11c..997f8c6b 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 b751f6eb..71b58096 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 0891c878..d6ef0d45 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 9d9e2c71..b0f48eb5 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 d3163caa..b1d3c9f3 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 6f050ac9..51bfa431 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 521eef17..b2aee641 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 b7c26f7c..e52e35ff 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 8dd8e50a..9bd550c9 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 c6610098..b0098720 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 a7d7f72c..bbd0dd4e 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 4ac8851d..622d6bd1 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 e7b1e84a..8d27ba0e 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 34879156..48de642f 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 44a90107..00000000 --- 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 9631f5aa..00000000 --- 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 e8bca5b4..00000000 --- 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 ba708cbb..00000000 --- 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 00000000..6152ad93 --- /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 99750ca767d4fc861299266e1102b3aeaebedcd7 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 22 Feb 2023 16:18:16 +0100 Subject: [PATCH 7/8] 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 9b53ad74..588d3c9d 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 d2ec14f2..48aa65a2 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 fd8d88ce..9ea7c9b6 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 57dec807..9fdc9677 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 06432868cc16757de55edb55a960002b843c74be Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 23 Feb 2023 08:07:29 +0100 Subject: [PATCH 8/8] Update to CommonCore master Signed-off-by: Lixfel --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index 588d3c9d..b2b96cff 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 588d3c9dda47a8e61e4e01eea9c915f9d853eb3b +Subproject commit b2b96cff0477dc3078c1abfd8f8b047e3a6d903d