From 1bec6c4cd46d11777d01eaf0d54239a24532eb01 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Wed, 4 Jan 2023 12:00:27 +0100 Subject: [PATCH 01/22] Push initial implementation --- src/de/steamwar/bungeecore/BungeeCore.java | 2 + .../bungeecore/commands/ModCommand.java | 60 +++++++++++++++++++ .../bungeecore/commands/WhoisCommand.java | 2 - .../steamwar/messages/BungeeCore.properties | 10 +++- 4 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 src/de/steamwar/bungeecore/commands/ModCommand.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index d07ce131..4f4f10b5 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -163,6 +163,8 @@ public class BungeeCore extends Plugin { new CalendarCommand(); new CalendarListener(); + new ModCommand(); + // Punishment Commands: new PunishmentCommand("ban", Punishment.PunishmentType.Ban); new PunishmentCommand("mute", Punishment.PunishmentType.Mute); diff --git a/src/de/steamwar/bungeecore/commands/ModCommand.java b/src/de/steamwar/bungeecore/commands/ModCommand.java new file mode 100644 index 00000000..29a788de --- /dev/null +++ b/src/de/steamwar/bungeecore/commands/ModCommand.java @@ -0,0 +1,60 @@ +package de.steamwar.bungeecore.commands; + +import de.steamwar.bungeecore.Message; +import de.steamwar.bungeecore.sql.Statement; +import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.bungeecore.sql.UserGroup; +import de.steamwar.command.SWCommand; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +public class ModCommand extends SWCommand { + + private static final Statement set = new Statement("UPDATE Mods Set ModType = ? WHERE ModName = ?"); + private static final Statement findFirst = new Statement("SELECT * FROM Mods WHERE modType = 0 LIMIT 1"); + + private static final Statement exists = new Statement("SELECT * FROM Mods WHERE ModName = ?"); + + public ModCommand() { + super("mod", "bungeecore.teamchat", "mods"); + } + + @Register(value = {"set"},description = "MOD_COMMAND_SET_USAGE") + public void set(ProxiedPlayer p,String modName,Integer newModType) { + SteamwarUser user = SteamwarUser.get(p.getUniqueId()); + UserGroup group = user.getUserGroup(); + + if(!group.isAdminGroup()) { + Message.send("MOD_COMMAND_SET_USAGE",p); + return; + } + + set.update(newModType,modName); + + Message.send("MOD_CHANGED_TYPE",p,modName,newModType); + } + + @Register(value = {"next"},description = "MOD_COMMAND_NEXT_USAGE") + public void next(ProxiedPlayer p) { + SteamwarUser user = SteamwarUser.get(p.getUniqueId()); + UserGroup group = user.getUserGroup(); + + if(!group.isAdminGroup()) { + Message.send("MOD_COMMAND_NEXT_USAGE",p); + return; + } + + String foundMod = findFirst.select(rs -> { + if(rs.next()) { + return rs.getString("ModName"); + } + return null; + }); + + if(foundMod == null) { + Message.send("MOD_NO_MORE_UNCLASSIFIED_MODS",p); + return; + } + + Message.send("MOD_FOUND_NEXT_MOD",p,foundMod); + } +} diff --git a/src/de/steamwar/bungeecore/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/commands/WhoisCommand.java index bf016c3a..35592496 100644 --- a/src/de/steamwar/bungeecore/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/commands/WhoisCommand.java @@ -28,11 +28,9 @@ 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.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; -import java.net.InetSocketAddress; import java.sql.Timestamp; import java.text.DecimalFormat; import java.time.Instant; diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 314f26dc..3636dac9 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -655,4 +655,12 @@ ADVENT_CALENDAR_TITLE=§eAdvent Calendar ADVENT_CALENDAR_DAY=§7Day§8: §e{0} ADVENT_CALENDAR_MESSAGE=§eDid you already open your advent calendar? ADVENT_CALENDAR_MESSAGE_HOVER=§eClick to open! -ADVENT_CALENDAR_OPEN=§7You got §e{0} §7from the advent calendar! \ No newline at end of file +ADVENT_CALENDAR_OPEN=§7You got §e{0} §7from the advent calendar! + +#Mod Command +MOD_COMMAND_SET_USAGE=§7/mod [mod name] [ModType 1-4] +MOD_COMMAND_NEXT_USAGE=§7/mod next +MOD_CHANGED_TYPE=§7Successfully reclassified mod {0} to type {1}! +MOD_NO_MORE_UNCLASSIFIED_MODS=§7No more unclassified mods found in databank! +MOD_FOUND_NEXT_MOD=§7Next unclassified mod is {0}! +MOD_COMMAND_NOT_FOUND_IN_DATABASE=§7The Mod {0} was§c not §7found in the database! \ No newline at end of file From e0a1542b03f4e5f4527a35c07941ec87f4a442e1 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Wed, 4 Jan 2023 15:15:16 +0100 Subject: [PATCH 02/22] Check if mod exists in database --- .../bungeecore/commands/ModCommand.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/ModCommand.java b/src/de/steamwar/bungeecore/commands/ModCommand.java index 29a788de..e9c7077f 100644 --- a/src/de/steamwar/bungeecore/commands/ModCommand.java +++ b/src/de/steamwar/bungeecore/commands/ModCommand.java @@ -7,12 +7,16 @@ import de.steamwar.bungeecore.sql.UserGroup; import de.steamwar.command.SWCommand; import net.md_5.bungee.api.connection.ProxiedPlayer; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.SQLSyntaxErrorException; + public class ModCommand extends SWCommand { private static final Statement set = new Statement("UPDATE Mods Set ModType = ? WHERE ModName = ?"); - private static final Statement findFirst = new Statement("SELECT * FROM Mods WHERE modType = 0 LIMIT 1"); + private static final Statement findFirst = new Statement("SELECT * FROM Mods WHERE ModType = 0 LIMIT 1"); - private static final Statement exists = new Statement("SELECT * FROM Mods WHERE ModName = ?"); + private static final Statement get = new Statement("SELECT * FROM Mods WHERE ModName = ?"); public ModCommand() { super("mod", "bungeecore.teamchat", "mods"); @@ -28,6 +32,15 @@ public class ModCommand extends SWCommand { return; } + boolean modExists = get.select(ResultSet::next,modName); + + System.out.println(modExists); + + if(!modExists) { + Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE",p,modName); + return; + } + set.update(newModType,modName); Message.send("MOD_CHANGED_TYPE",p,modName,newModType); From dc234b2b33b9f01c18dffa3008495a6cdb7b8bad Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Wed, 4 Jan 2023 20:31:31 +0100 Subject: [PATCH 03/22] Push fixes --- .../bungeecore/commands/ModCommand.java | 42 ++++++------------- src/de/steamwar/bungeecore/sql/Mod.java | 11 +++++ .../steamwar/messages/BungeeCore.properties | 3 +- 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/ModCommand.java b/src/de/steamwar/bungeecore/commands/ModCommand.java index e9c7077f..a60233e2 100644 --- a/src/de/steamwar/bungeecore/commands/ModCommand.java +++ b/src/de/steamwar/bungeecore/commands/ModCommand.java @@ -1,40 +1,28 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; +import de.steamwar.bungeecore.sql.Mod; import de.steamwar.bungeecore.sql.Statement; -import de.steamwar.bungeecore.sql.SteamwarUser; -import de.steamwar.bungeecore.sql.UserGroup; import de.steamwar.command.SWCommand; +import jdk.internal.net.http.common.Pair; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.SQLSyntaxErrorException; public class ModCommand extends SWCommand { - private static final Statement set = new Statement("UPDATE Mods Set ModType = ? WHERE ModName = ?"); + private static final Statement set = new Statement("UPDATE Mods Set ModType = ? WHERE ModName = ? AND ModType = ?"); private static final Statement findFirst = new Statement("SELECT * FROM Mods WHERE ModType = 0 LIMIT 1"); private static final Statement get = new Statement("SELECT * FROM Mods WHERE ModName = ?"); public ModCommand() { - super("mod", "bungeecore.teamchat", "mods"); + super("mod", "bungeecore.softreload", "mods"); } @Register(value = {"set"},description = "MOD_COMMAND_SET_USAGE") - public void set(ProxiedPlayer p,String modName,Integer newModType) { - SteamwarUser user = SteamwarUser.get(p.getUniqueId()); - UserGroup group = user.getUserGroup(); - - if(!group.isAdminGroup()) { - Message.send("MOD_COMMAND_SET_USAGE",p); - return; - } - - boolean modExists = get.select(ResultSet::next,modName); - - System.out.println(modExists); + public void set(ProxiedPlayer p,String modName,String platform,Integer newModType) { + boolean modExists = get.select(ResultSet::next,modName,Mod.Platform.valueOf(platform)); if(!modExists) { Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE",p,modName); @@ -46,19 +34,13 @@ public class ModCommand extends SWCommand { Message.send("MOD_CHANGED_TYPE",p,modName,newModType); } - @Register(value = {"next"},description = "MOD_COMMAND_NEXT_USAGE") + @Register() public void next(ProxiedPlayer p) { - SteamwarUser user = SteamwarUser.get(p.getUniqueId()); - UserGroup group = user.getUserGroup(); - - if(!group.isAdminGroup()) { - Message.send("MOD_COMMAND_NEXT_USAGE",p); - return; - } - - String foundMod = findFirst.select(rs -> { + Pair foundMod = findFirst.select(rs -> { if(rs.next()) { - return rs.getString("ModName"); + String name = rs.getString("ModName"); + Integer platform = rs.getInt("Platform"); + return new Pair<>(name,platform); } return null; }); @@ -68,6 +50,6 @@ public class ModCommand extends SWCommand { return; } - Message.send("MOD_FOUND_NEXT_MOD",p,foundMod); + Message.send("MOD_FOUND_NEXT_MOD",p,foundMod.first, Mod.Platform.getByValue(foundMod.second)); } } diff --git a/src/de/steamwar/bungeecore/sql/Mod.java b/src/de/steamwar/bungeecore/sql/Mod.java index dcd69aee..81e90458 100644 --- a/src/de/steamwar/bungeecore/sql/Mod.java +++ b/src/de/steamwar/bungeecore/sql/Mod.java @@ -71,6 +71,17 @@ public class Mod { public int get() { return value; } + + public static String getByValue(int val) { + String platform; + switch (val) { + case 0 : platform = "Forge"; + case 1: platform = "Labymod"; + case 2: platform = "Fabric"; + default: platform = ""; + } + return platform; + } } public enum ModType { diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 3636dac9..177b360b 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -659,8 +659,7 @@ ADVENT_CALENDAR_OPEN=§7You got §e{0} §7from the advent calendar! #Mod Command MOD_COMMAND_SET_USAGE=§7/mod [mod name] [ModType 1-4] -MOD_COMMAND_NEXT_USAGE=§7/mod next MOD_CHANGED_TYPE=§7Successfully reclassified mod {0} to type {1}! MOD_NO_MORE_UNCLASSIFIED_MODS=§7No more unclassified mods found in databank! MOD_FOUND_NEXT_MOD=§7Next unclassified mod is {0}! -MOD_COMMAND_NOT_FOUND_IN_DATABASE=§7The Mod {0} was§c not §7found in the database! \ No newline at end of file +MOD_COMMAND_NOT_FOUND_IN_DATABASE=§7The Mod {0} on platform {1} was§c not §7found in the database! \ No newline at end of file From c59da8ff494b60b2a35dd04d1d6261c04e769390 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Fri, 6 Jan 2023 22:11:25 +0100 Subject: [PATCH 04/22] wip ingame gui --- .../bungeecore/commands/ModCommand.java | 101 +++++++++++++++--- src/de/steamwar/bungeecore/sql/Mod.java | 15 +-- .../steamwar/messages/BungeeCore.properties | 9 +- 3 files changed, 102 insertions(+), 23 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/ModCommand.java b/src/de/steamwar/bungeecore/commands/ModCommand.java index a60233e2..3b589ab1 100644 --- a/src/de/steamwar/bungeecore/commands/ModCommand.java +++ b/src/de/steamwar/bungeecore/commands/ModCommand.java @@ -1,46 +1,111 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.sql.Mod; -import de.steamwar.bungeecore.sql.Statement; +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 jdk.internal.net.http.common.Pair; import net.md_5.bungee.api.connection.ProxiedPlayer; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; import java.sql.ResultSet; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; public class ModCommand extends SWCommand { - private static final Statement set = new Statement("UPDATE Mods Set ModType = ? WHERE ModName = ? AND ModType = ?"); + 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 get = new Statement("SELECT * FROM Mods WHERE ModName = ?"); + private static final Statement get = new Statement("SELECT * FROM Mods WHERE ModName = ? AND Platform = ?"); + + private static final Statement getAll = new Statement("SELECT * FROM Mods WHERE ModType = 0 ORDER BY ModName DESC LIMIT ?, ?"); public ModCommand() { super("mod", "bungeecore.softreload", "mods"); } + @Register(value = "a") + public void genericCommand(ProxiedPlayer p) { + new SWStreamInv<>(p,Message.parse("MOD_COMMAND_GUI_TITLE",p), (click, element) -> { + SWInventory swInventory = new SWInventory(p,5,"Mod Changer"); + + String modName = element.modName; + int modPlatform = element.platform.get(); + + swInventory.addItem(0,new SWItem("GRAY_CONCRETE","Unclassified"), (click1 -> set.update(0,modName,modPlatform))); + + swInventory.addItem(1,new SWItem("GREEN_CONCRETE", "Allowed"), (click1 -> set.update(1,modName,modPlatform))); + swInventory.addItem(2,new SWItem("YELLOW_CONCRETE", "Pending"),(click1 -> set.update(2,modName,modPlatform))); + swInventory.addItem(3,new SWItem("RED_CONCRETE","Forbidden"),(click1 -> set.update(3,modName,modPlatform))); + swInventory.addItem(4,new SWItem("PURPLE_CONCRETE", "YT_only"),(click1 -> set.update(4,modName,modPlatform))); + + swInventory.open(); + + },page -> getMods(page,45).stream().map(mod -> new SWListInv.SWListEntry<>(getModItem(mod),mod)).collect(Collectors.toList())).open(); + } + + private SWItem getModItem(ModEntry modEntry) { + SWItem item = new SWItem("NAME_TAG", modEntry.modName); + + item.addLore(modEntry.platform.name()); + + return item; + } + + public List getMods(int page,int elementsPerPage) { + return getAll.select(rs -> { + List f = new ArrayList<>(); + while(rs.next()){ + ModEntry entry = new ModEntry(rs.getString("ModName"), Mod.Platform.getByValue(rs.getInt("Platform"))); + System.out.println(entry.modName); + f.add(entry); + } + return f; + }, page * elementsPerPage, elementsPerPage); + } + @Register(value = {"set"},description = "MOD_COMMAND_SET_USAGE") - public void set(ProxiedPlayer p,String modName,String platform,Integer newModType) { - boolean modExists = get.select(ResultSet::next,modName,Mod.Platform.valueOf(platform)); + public void set(ProxiedPlayer p,String modName,Mod.Platform platform,Mod.ModType newModType) { + int modPlatform = platform.get(); + boolean modExists = get.select(ResultSet::next,modName,modPlatform); if(!modExists) { Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE",p,modName); return; } - set.update(newModType,modName); + set.update(newModType.getValue(),modName,modPlatform); - Message.send("MOD_CHANGED_TYPE",p,modName,newModType); + Message.send("MOD_CHANGED_TYPE",p,modName,newModType.name(),newModType); } - @Register() + @Register(value = {"get"},description = "MOD_COMMAND_GET_USAGE") + public void get(ProxiedPlayer p,String modName,Mod.Platform platform) { + Message.send("MOD_COMMAND_INFO",p,modName,platform.name(),Mod.Platform.getByValue(getModType(modName,platform))); + } + + private int getModType(String modName,Mod.Platform modPlatform) { + return get.select(rs -> { + if(rs.next()) { + return rs.getInt("ModType"); + } else { + return 0; + } + },modName,modPlatform); + } + + @Register(value = {"next"}) public void next(ProxiedPlayer p) { Pair foundMod = findFirst.select(rs -> { if(rs.next()) { String name = rs.getString("ModName"); - Integer platform = rs.getInt("Platform"); - return new Pair<>(name,platform); + int platform = rs.getInt("Platform"); + return new ImmutablePair<>(name,platform); } return null; }); @@ -50,6 +115,16 @@ public class ModCommand extends SWCommand { return; } - Message.send("MOD_FOUND_NEXT_MOD",p,foundMod.first, Mod.Platform.getByValue(foundMod.second)); + Message.send("MOD_FOUND_NEXT_MOD",p,foundMod.getKey(), Mod.Platform.getByValue(foundMod.getValue())); + } + + private class ModEntry { + private final String modName; + private final Mod.Platform platform; + + public ModEntry(String modName, Mod.Platform platform) { + this.modName = modName; + this.platform = platform; + } } } diff --git a/src/de/steamwar/bungeecore/sql/Mod.java b/src/de/steamwar/bungeecore/sql/Mod.java index 81e90458..ef061c03 100644 --- a/src/de/steamwar/bungeecore/sql/Mod.java +++ b/src/de/steamwar/bungeecore/sql/Mod.java @@ -19,6 +19,8 @@ package de.steamwar.bungeecore.sql; +import lombok.Getter; + public class Mod { private static final Statement get = new Statement("SELECT * FROM Mods WHERE ModName = ? AND Platform = ?"); @@ -72,15 +74,13 @@ public class Mod { return value; } - public static String getByValue(int val) { - String platform; + public static Platform getByValue(int val) { switch (val) { - case 0 : platform = "Forge"; - case 1: platform = "Labymod"; - case 2: platform = "Fabric"; - default: platform = ""; + case 0 : return FORGE; + case 1: return LABYMOD; + case 2: return FABRIC; + default: return null; } - return platform; } } @@ -102,6 +102,7 @@ public class Mod { ModType(int value){ this.value = value; } + @Getter int value; } } diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 177b360b..d1d2b8ab 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -658,8 +658,11 @@ ADVENT_CALENDAR_MESSAGE_HOVER=§eClick to open! ADVENT_CALENDAR_OPEN=§7You got §e{0} §7from the advent calendar! #Mod Command -MOD_COMMAND_SET_USAGE=§7/mod [mod name] [ModType 1-4] -MOD_CHANGED_TYPE=§7Successfully reclassified mod {0} to type {1}! +MOD_COMMAND_SET_USAGE=§7/mod set [mod name] [platform] [ModType 1-4] +MOD_COMMAND_GET_USAGE=§7/mod get [mod name] [platform] +MOD_CHANGED_TYPE=§7Successfully reclassified mod {0} on platform {1} to type {2}! MOD_NO_MORE_UNCLASSIFIED_MODS=§7No more unclassified mods found in databank! MOD_FOUND_NEXT_MOD=§7Next unclassified mod is {0}! -MOD_COMMAND_NOT_FOUND_IN_DATABASE=§7The Mod {0} on platform {1} was§c not §7found in the database! \ No newline at end of file +MOD_COMMAND_NOT_FOUND_IN_DATABASE=§7The Mod {0} on platform {1} was§c not §7found in the database! +MOD_COMMAND_INFO=§7The mod {0} on platform {1} is of the type {2}. +MOD_COMMAND_GUI_TITLE="§7Unclassified Mods" \ No newline at end of file From d58ae049cf25436da4a03dae967b4226cc88808f Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Fri, 6 Jan 2023 23:41:03 +0100 Subject: [PATCH 05/22] Ingamegui Working --- .../bungeecore/commands/ModCommand.java | 28 +++++++++++-------- .../steamwar/messages/BungeeCore.properties | 3 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/ModCommand.java b/src/de/steamwar/bungeecore/commands/ModCommand.java index 3b589ab1..d352a3d7 100644 --- a/src/de/steamwar/bungeecore/commands/ModCommand.java +++ b/src/de/steamwar/bungeecore/commands/ModCommand.java @@ -23,7 +23,7 @@ public class ModCommand extends SWCommand { private static final Statement get = new Statement("SELECT * FROM Mods WHERE ModName = ? AND Platform = ?"); - private static final Statement getAll = new Statement("SELECT * FROM Mods WHERE ModType = 0 ORDER BY ModName DESC LIMIT ?, ?"); + private static final Statement getAll = new Statement("SELECT * FROM Mods ORDER BY ModName DESC LIMIT ?, ?"); public ModCommand() { super("mod", "bungeecore.softreload", "mods"); @@ -31,22 +31,26 @@ public class ModCommand extends SWCommand { @Register(value = "a") public void genericCommand(ProxiedPlayer p) { - new SWStreamInv<>(p,Message.parse("MOD_COMMAND_GUI_TITLE",p), (click, element) -> { - SWInventory swInventory = new SWInventory(p,5,"Mod Changer"); + SWStreamInv swStreamInv = new SWStreamInv<>(p,Message.parse("MOD_COMMAND_GUI_TITLE",p), (click, element) -> { + openGradingWindow(p,element); + },page -> getMods(page,45).stream().map(mod -> new SWListInv.SWListEntry<>(getModItem(mod),mod)).collect(Collectors.toList())); - String modName = element.modName; - int modPlatform = element.platform.get(); + swStreamInv.open(); + } - swInventory.addItem(0,new SWItem("GRAY_CONCRETE","Unclassified"), (click1 -> set.update(0,modName,modPlatform))); + private void openGradingWindow(ProxiedPlayer p,ModEntry element) { + SWInventory swInventory = new SWInventory(p,9,Message.parse("MOD_COMMAND_GUI",p)); - swInventory.addItem(1,new SWItem("GREEN_CONCRETE", "Allowed"), (click1 -> set.update(1,modName,modPlatform))); - swInventory.addItem(2,new SWItem("YELLOW_CONCRETE", "Pending"),(click1 -> set.update(2,modName,modPlatform))); - swInventory.addItem(3,new SWItem("RED_CONCRETE","Forbidden"),(click1 -> set.update(3,modName,modPlatform))); - swInventory.addItem(4,new SWItem("PURPLE_CONCRETE", "YT_only"),(click1 -> set.update(4,modName,modPlatform))); + String modName = element.modName; + int modPlatform = element.platform.get(); - swInventory.open(); + swInventory.addItem(2,new SWItem("GRAY_CONCRETE","Unclassified"), (click1 -> set.update(0,modName,modPlatform))); + swInventory.addItem(3,new SWItem("GREEN_CONCRETE", "Allowed"), (click1 -> set.update(1,modName,modPlatform))); + swInventory.addItem(4,new SWItem("YELLOW_CONCRETE", "Pending"),(click1 -> set.update(2,modName,modPlatform))); + swInventory.addItem(5,new SWItem("RED_CONCRETE","Forbidden"),(click1 -> set.update(3,modName,modPlatform))); + swInventory.addItem(6,new SWItem("PURPLE_CONCRETE", "YT_only"),(click1 -> set.update(4,modName,modPlatform))); - },page -> getMods(page,45).stream().map(mod -> new SWListInv.SWListEntry<>(getModItem(mod),mod)).collect(Collectors.toList())).open(); + swInventory.open(); } private SWItem getModItem(ModEntry modEntry) { diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index d1d2b8ab..8b16b701 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -665,4 +665,5 @@ MOD_NO_MORE_UNCLASSIFIED_MODS=§7No more unclassified mods found in databank! MOD_FOUND_NEXT_MOD=§7Next unclassified mod is {0}! MOD_COMMAND_NOT_FOUND_IN_DATABASE=§7The Mod {0} on platform {1} was§c not §7found in the database! MOD_COMMAND_INFO=§7The mod {0} on platform {1} is of the type {2}. -MOD_COMMAND_GUI_TITLE="§7Unclassified Mods" \ No newline at end of file +MOD_COMMAND_GUI_TITLE=§7Unclassified Mods +MOD_COMMAND_GUI=§7Mod Type Changer \ No newline at end of file From 60f6a9cb4c03cbe100c65a6225ae968a4e4e5736 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Fri, 6 Jan 2023 23:41:41 +0100 Subject: [PATCH 06/22] remove typo --- src/de/steamwar/bungeecore/commands/ModCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/commands/ModCommand.java b/src/de/steamwar/bungeecore/commands/ModCommand.java index d352a3d7..9967ef2c 100644 --- a/src/de/steamwar/bungeecore/commands/ModCommand.java +++ b/src/de/steamwar/bungeecore/commands/ModCommand.java @@ -29,7 +29,7 @@ public class ModCommand extends SWCommand { super("mod", "bungeecore.softreload", "mods"); } - @Register(value = "a") + @Register() public void genericCommand(ProxiedPlayer p) { SWStreamInv swStreamInv = new SWStreamInv<>(p,Message.parse("MOD_COMMAND_GUI_TITLE",p), (click, element) -> { openGradingWindow(p,element); From 69aa98e82eb3d3c30dd6ab702feb0976ec6e3fc9 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Sun, 8 Jan 2023 14:21:29 +0100 Subject: [PATCH 07/22] Finalise GUI and implement item names (not yet final) --- .../bungeecore/commands/ModCommand.java | 119 +++++++++++++----- src/de/steamwar/bungeecore/sql/Mod.java | 11 +- .../steamwar/messages/BungeeCore.properties | 10 +- 3 files changed, 106 insertions(+), 34 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/ModCommand.java b/src/de/steamwar/bungeecore/commands/ModCommand.java index 9967ef2c..21bfa5ca 100644 --- a/src/de/steamwar/bungeecore/commands/ModCommand.java +++ b/src/de/steamwar/bungeecore/commands/ModCommand.java @@ -1,5 +1,6 @@ package de.steamwar.bungeecore.commands; +import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.inventory.SWItem; @@ -7,6 +8,9 @@ import de.steamwar.bungeecore.inventory.SWListInv; import de.steamwar.bungeecore.inventory.SWStreamInv; import de.steamwar.bungeecore.sql.*; import de.steamwar.command.SWCommand; +import lombok.Getter; +import net.md_5.bungee.BungeeCord; +import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; @@ -14,43 +18,72 @@ import org.apache.commons.lang3.tuple.Pair; import java.sql.ResultSet; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; public class ModCommand extends SWCommand { - 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 get = new Statement("SELECT * FROM Mods WHERE ModName = ? AND Platform = ?"); - - private static final Statement getAll = new Statement("SELECT * FROM Mods ORDER BY ModName DESC LIMIT ?, ?"); - public ModCommand() { super("mod", "bungeecore.softreload", "mods"); } + private static FilterType filtertype = FilterType.ALL; @Register() public void genericCommand(ProxiedPlayer p) { + openGui(p); + } + + private void openGui(ProxiedPlayer p) { SWStreamInv swStreamInv = new SWStreamInv<>(p,Message.parse("MOD_COMMAND_GUI_TITLE",p), (click, element) -> { - openGradingWindow(p,element); - },page -> getMods(page,45).stream().map(mod -> new SWListInv.SWListEntry<>(getModItem(mod),mod)).collect(Collectors.toList())); + SWInventory swInventory = new SWInventory(p,9,Message.parse("MOD_COMMAND_GUI",p)); + + String modName = element.modName; + int modPlatform = element.platform.get(); + + swInventory.addItem(2, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), (click1 -> Mod.set.update(0, modName, modPlatform))); + swInventory.addItem(3, new SWItem(Message.parse("MOD_ALLOWED",p), 2), (click1 -> Mod.set.update(1, modName, modPlatform))); + swInventory.addItem(4, new SWItem(Message.parse("MOD_PENDING",p), 11), (click1 -> Mod.set.update(2, modName, modPlatform))); + swInventory.addItem(5, new SWItem(Message.parse("MOD_FORBIDDEN",p),1), (click1 -> Mod.set.update(3, modName, modPlatform))); + swInventory.addItem(6, new SWItem(Message.parse("MOD_YT",p), 13), (click1 -> Mod.set.update(4, modName, modPlatform))); + + swInventory.addItem(8,new SWItem("ARROW",Message.parse("MOD_ITEM_BACK",p)), click1 -> { + swInventory.close(); + openGui(p); + }); + + swInventory.open(); + },page -> { + if(filtertype == FilterType.ALL) { + return getAllMods(page,45).stream().map(mod -> new SWListInv.SWListEntry<>(getModItem(mod),mod)).collect(Collectors.toList()); + }else { + return getAllModsFiltered(page,45,filtertype.value).stream().map(mod -> new SWListInv.SWListEntry<>(getModItem(mod),mod)).collect(Collectors.toList()); + } + }); + + swStreamInv.addItem(52,new SWItem("NAME_TAG","Filter"), click -> { + swStreamInv.close(); + openFilterGui(p); + }); swStreamInv.open(); } - private void openGradingWindow(ProxiedPlayer p,ModEntry element) { - SWInventory swInventory = new SWInventory(p,9,Message.parse("MOD_COMMAND_GUI",p)); + private void openFilterGui(ProxiedPlayer p) { + SWInventory inv = new SWInventory(p, 9, "Filter"); - String modName = element.modName; - int modPlatform = element.platform.get(); + inv.addItem(1, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), click -> filtertype = FilterType.UNCLASSIFIED); + inv.addItem(2, new SWItem(Message.parse("MOD_ALLOWED",p),2), click -> filtertype = FilterType.ALLOWED); + inv.addItem(3, new SWItem(Message.parse("MOD_PENDING",p), 11),click -> filtertype = FilterType.PENDING); + inv.addItem(4, new SWItem(Message.parse("MOD_FORBIDDEN",p),1), click -> filtertype = FilterType.FORBIDDEN); + inv.addItem(5, new SWItem(Message.parse("MOD_YT",p),13), click -> filtertype = FilterType.YT); + inv.addItem(6, new SWItem(Message.parse("MOD_ALL",p),15), click -> filtertype = FilterType.ALL); - swInventory.addItem(2,new SWItem("GRAY_CONCRETE","Unclassified"), (click1 -> set.update(0,modName,modPlatform))); - swInventory.addItem(3,new SWItem("GREEN_CONCRETE", "Allowed"), (click1 -> set.update(1,modName,modPlatform))); - swInventory.addItem(4,new SWItem("YELLOW_CONCRETE", "Pending"),(click1 -> set.update(2,modName,modPlatform))); - swInventory.addItem(5,new SWItem("RED_CONCRETE","Forbidden"),(click1 -> set.update(3,modName,modPlatform))); - swInventory.addItem(6,new SWItem("PURPLE_CONCRETE", "YT_only"),(click1 -> set.update(4,modName,modPlatform))); + inv.addItem(8, new SWItem("ARROW", Message.parse("MOD_ITEM_BACK",p)), click -> { + inv.close(); + openGui(p); + }); - swInventory.open(); + inv.open(); } private SWItem getModItem(ModEntry modEntry) { @@ -61,51 +94,60 @@ public class ModCommand extends SWCommand { return item; } - public List getMods(int page,int elementsPerPage) { - return getAll.select(rs -> { + public List getAllMods(int page,int elementsPerPage) { + return Mod.getAll.select(rs -> { List f = new ArrayList<>(); while(rs.next()){ ModEntry entry = new ModEntry(rs.getString("ModName"), Mod.Platform.getByValue(rs.getInt("Platform"))); - System.out.println(entry.modName); f.add(entry); } return f; }, page * elementsPerPage, elementsPerPage); } + public List getAllModsFiltered(int page,int elementsPerPage, int filter) { + return Mod.getAllFiltered.select(rs -> { + List f = new ArrayList<>(); + while(rs.next()){ + ModEntry entry = new ModEntry(rs.getString("ModName"), Mod.Platform.getByValue(rs.getInt("Platform"))); + f.add(entry); + } + return f; + },filter, page * elementsPerPage, elementsPerPage); + } + @Register(value = {"set"},description = "MOD_COMMAND_SET_USAGE") public void set(ProxiedPlayer p,String modName,Mod.Platform platform,Mod.ModType newModType) { int modPlatform = platform.get(); - boolean modExists = get.select(ResultSet::next,modName,modPlatform); + boolean modExists = Mod.get.select(ResultSet::next,modName,modPlatform); if(!modExists) { Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE",p,modName); return; } - set.update(newModType.getValue(),modName,modPlatform); + Mod.set.update(newModType.getValue(),modName,modPlatform); Message.send("MOD_CHANGED_TYPE",p,modName,newModType.name(),newModType); } @Register(value = {"get"},description = "MOD_COMMAND_GET_USAGE") public void get(ProxiedPlayer p,String modName,Mod.Platform platform) { - Message.send("MOD_COMMAND_INFO",p,modName,platform.name(),Mod.Platform.getByValue(getModType(modName,platform))); + Message.send("MOD_COMMAND_INFO",p,modName,platform.name(),Mod.ModType.valueOf(getModType(modName,platform.get())).name()); } - private int getModType(String modName,Mod.Platform modPlatform) { - return get.select(rs -> { + private int getModType(String modName,int modPlatform) { + return Mod.get.select(rs -> { if(rs.next()) { return rs.getInt("ModType"); - } else { - return 0; } + return 0; },modName,modPlatform); } @Register(value = {"next"}) public void next(ProxiedPlayer p) { - Pair foundMod = findFirst.select(rs -> { + Pair foundMod = Mod.findFirst.select(rs -> { if(rs.next()) { String name = rs.getString("ModName"); int platform = rs.getInt("Platform"); @@ -119,7 +161,22 @@ public class ModCommand extends SWCommand { return; } - Message.send("MOD_FOUND_NEXT_MOD",p,foundMod.getKey(), Mod.Platform.getByValue(foundMod.getValue())); + Message.send("MOD_FOUND_NEXT_MOD",p,"MOD_OPEN_GUI",new ClickEvent(ClickEvent.Action.RUN_COMMAND,""),foundMod.getKey(),Mod.Platform.getByValue(foundMod.getValue())); + } + + private enum FilterType { + ALL(-1), + UNCLASSIFIED(0), + ALLOWED(1), + PENDING(2), + FORBIDDEN(3), + YT(4); + + final int value; + + FilterType(int value) { + this.value = value; + } } private class ModEntry { diff --git a/src/de/steamwar/bungeecore/sql/Mod.java b/src/de/steamwar/bungeecore/sql/Mod.java index ef061c03..1695f15f 100644 --- a/src/de/steamwar/bungeecore/sql/Mod.java +++ b/src/de/steamwar/bungeecore/sql/Mod.java @@ -23,9 +23,16 @@ import lombok.Getter; public class Mod { - private static final Statement get = new Statement("SELECT * FROM Mods WHERE ModName = ? AND Platform = ?"); + public 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 (?, ?)"); + public static final Statement set = new Statement("UPDATE Mods Set ModType = ? WHERE ModName = ? AND Platform = ?"); + public static final Statement findFirst = new Statement("SELECT * FROM Mods WHERE ModType = 0 LIMIT 1"); + + public static final Statement getAll = new Statement("SELECT * FROM Mods ORDER BY ModName DESC LIMIT ?, ?"); + + public static final Statement getAllFiltered = new Statement("SELECT * FROM Mods WHERE ModType = ? ORDER BY ModName DESC LIMIT ?, ?"); + private final String modName; private final Platform platform; private final ModType modType; @@ -91,7 +98,7 @@ public class Mod { RED(3), YOUTUBER_ONLY(4); - static ModType valueOf(int value){ + public static ModType valueOf(int value){ for(ModType mt : values()){ if(value == mt.value) return mt; diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 8b16b701..1dc88dc0 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -666,4 +666,12 @@ MOD_FOUND_NEXT_MOD=§7Next unclassified mod is {0}! MOD_COMMAND_NOT_FOUND_IN_DATABASE=§7The Mod {0} on platform {1} was§c not §7found in the database! MOD_COMMAND_INFO=§7The mod {0} on platform {1} is of the type {2}. MOD_COMMAND_GUI_TITLE=§7Unclassified Mods -MOD_COMMAND_GUI=§7Mod Type Changer \ No newline at end of file +MOD_COMMAND_GUI=§7Mod Type Changer +MOD_OPEN_GUI=§7Open Gui +MOD_UNCLASSIFIED=Unclassified +MOD_ALLOWED=Allowed +MOD_PENDING=Pending +MOD_FORBIDDEN=Forbidden +MOD_YT=YT Only +MOD_ALL=All +MOD_ITEM_BACK=Back From 8def39d376f2c2659642a2d530377ff812122251 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Tue, 10 Jan 2023 13:27:13 +0100 Subject: [PATCH 08/22] Finalise GUI and implement item names (not yet final) --- .../bungeecore/commands/ModCommand.java | 183 +++++++----------- .../listeners/ConnectionListener.java | 2 + src/de/steamwar/bungeecore/sql/Mod.java | 84 ++++++-- .../steamwar/messages/BungeeCore.properties | 6 +- 4 files changed, 143 insertions(+), 132 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/ModCommand.java b/src/de/steamwar/bungeecore/commands/ModCommand.java index 21bfa5ca..9825bec4 100644 --- a/src/de/steamwar/bungeecore/commands/ModCommand.java +++ b/src/de/steamwar/bungeecore/commands/ModCommand.java @@ -1,6 +1,24 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.inventory.SWItem; @@ -8,17 +26,11 @@ import de.steamwar.bungeecore.inventory.SWListInv; import de.steamwar.bungeecore.inventory.SWStreamInv; import de.steamwar.bungeecore.sql.*; import de.steamwar.command.SWCommand; -import lombok.Getter; -import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; -import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; - -import java.sql.ResultSet; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; +import java.util.HashMap; +import java.util.Map; import java.util.stream.Collectors; public class ModCommand extends SWCommand { @@ -26,38 +38,21 @@ public class ModCommand extends SWCommand { public ModCommand() { super("mod", "bungeecore.softreload", "mods"); } - private static FilterType filtertype = FilterType.ALL; - @Register() + public static final Map playerFilterType = new HashMap<>(); + + @Register public void genericCommand(ProxiedPlayer p) { + playerFilterType.putIfAbsent(p,Mod.ModType.UNKLASSIFIED); openGui(p); } private void openGui(ProxiedPlayer p) { - SWStreamInv swStreamInv = new SWStreamInv<>(p,Message.parse("MOD_COMMAND_GUI_TITLE",p), (click, element) -> { - SWInventory swInventory = new SWInventory(p,9,Message.parse("MOD_COMMAND_GUI",p)); - - String modName = element.modName; - int modPlatform = element.platform.get(); - - swInventory.addItem(2, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), (click1 -> Mod.set.update(0, modName, modPlatform))); - swInventory.addItem(3, new SWItem(Message.parse("MOD_ALLOWED",p), 2), (click1 -> Mod.set.update(1, modName, modPlatform))); - swInventory.addItem(4, new SWItem(Message.parse("MOD_PENDING",p), 11), (click1 -> Mod.set.update(2, modName, modPlatform))); - swInventory.addItem(5, new SWItem(Message.parse("MOD_FORBIDDEN",p),1), (click1 -> Mod.set.update(3, modName, modPlatform))); - swInventory.addItem(6, new SWItem(Message.parse("MOD_YT",p), 13), (click1 -> Mod.set.update(4, modName, modPlatform))); - - swInventory.addItem(8,new SWItem("ARROW",Message.parse("MOD_ITEM_BACK",p)), click1 -> { - swInventory.close(); - openGui(p); - }); - - swInventory.open(); + SWStreamInv swStreamInv = new SWStreamInv<>(p,Message.parse("MOD_COMMAND_GUI_TITLE",p), (click, element) -> { + openClassificationGui(p,element); },page -> { - if(filtertype == FilterType.ALL) { - return getAllMods(page,45).stream().map(mod -> new SWListInv.SWListEntry<>(getModItem(mod),mod)).collect(Collectors.toList()); - }else { - return getAllModsFiltered(page,45,filtertype.value).stream().map(mod -> new SWListInv.SWListEntry<>(getModItem(mod),mod)).collect(Collectors.toList()); - } + Mod.ModType filtertype = playerFilterType.get(p); + return Mod.getAllModsFiltered(page,45, filtertype).stream().map(mod -> new SWListInv.SWListEntry<>(getModItem(mod),mod)).collect(Collectors.toList()); }); swStreamInv.addItem(52,new SWItem("NAME_TAG","Filter"), click -> { @@ -68,15 +63,20 @@ public class ModCommand extends SWCommand { swStreamInv.open(); } + public void updateAndCloseGui(Mod.ModType modType,String modName,Mod.Platform modPlatform,SWInventory toClose,ProxiedPlayer p) { + Mod.setMod(modType, modName, modPlatform); + toClose.close(); + openGui(p); + } + private void openFilterGui(ProxiedPlayer p) { SWInventory inv = new SWInventory(p, 9, "Filter"); - inv.addItem(1, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), click -> filtertype = FilterType.UNCLASSIFIED); - inv.addItem(2, new SWItem(Message.parse("MOD_ALLOWED",p),2), click -> filtertype = FilterType.ALLOWED); - inv.addItem(3, new SWItem(Message.parse("MOD_PENDING",p), 11),click -> filtertype = FilterType.PENDING); - inv.addItem(4, new SWItem(Message.parse("MOD_FORBIDDEN",p),1), click -> filtertype = FilterType.FORBIDDEN); - inv.addItem(5, new SWItem(Message.parse("MOD_YT",p),13), click -> filtertype = FilterType.YT); - inv.addItem(6, new SWItem(Message.parse("MOD_ALL",p),15), click -> filtertype = FilterType.ALL); + inv.addItem(1, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), click -> playerFilterType.replace(p, Mod.ModType.UNKLASSIFIED)); + inv.addItem(2, new SWItem(Message.parse("MOD_ALLOWED",p),2), click -> playerFilterType.replace(p, Mod.ModType.GREEN)); + inv.addItem(3, new SWItem(Message.parse("MOD_PENDING",p), 11),click -> playerFilterType.replace(p, Mod.ModType.YELLOW)); + inv.addItem(4, new SWItem(Message.parse("MOD_FORBIDDEN",p),1), click -> playerFilterType.replace(p, Mod.ModType.RED)); + inv.addItem(5, new SWItem(Message.parse("MOD_YT",p),13), click -> playerFilterType.replace(p, Mod.ModType.YOUTUBER_ONLY)); inv.addItem(8, new SWItem("ARROW", Message.parse("MOD_ITEM_BACK",p)), click -> { inv.close(); @@ -86,106 +86,63 @@ public class ModCommand extends SWCommand { inv.open(); } - private SWItem getModItem(ModEntry modEntry) { - SWItem item = new SWItem("NAME_TAG", modEntry.modName); + private void openClassificationGui(ProxiedPlayer p,Mod element) { + SWInventory swInventory = new SWInventory(p,9,Message.parse("MOD_COMMAND_CLASSICIATION_GUI",p)); - item.addLore(modEntry.platform.name()); + String modName = element.getModName(); + Mod.Platform modPlatform = element.getPlatform(); + + swInventory.addItem(2, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), (click1 -> updateAndCloseGui(Mod.ModType.UNKLASSIFIED,modName,modPlatform,swInventory,p))); + swInventory.addItem(3, new SWItem(Message.parse("MOD_ALLOWED",p), 2), (click1 -> updateAndCloseGui(Mod.ModType.GREEN,modName,modPlatform,swInventory,p))); + swInventory.addItem(4, new SWItem(Message.parse("MOD_PENDING",p), 11), (click1 -> updateAndCloseGui(Mod.ModType.YELLOW,modName,modPlatform,swInventory,p))); + swInventory.addItem(5, new SWItem(Message.parse("MOD_FORBIDDEN",p),1), (click1 -> updateAndCloseGui(Mod.ModType.RED,modName,modPlatform,swInventory,p))); + swInventory.addItem(6, new SWItem(Message.parse("MOD_YT",p), 13), (click1 -> updateAndCloseGui(Mod.ModType.YOUTUBER_ONLY,modName,modPlatform,swInventory,p))); + + swInventory.addItem(8,new SWItem("ARROW",Message.parse("MOD_ITEM_BACK",p)), click1 -> { + swInventory.close(); + openGui(p); + }); + + swInventory.open(); + } + + private SWItem getModItem(Mod modEntry) { + SWItem item = new SWItem("NAME_TAG", modEntry.getModName()); + + item.addLore(modEntry.getPlatform().name()); return item; } - public List getAllMods(int page,int elementsPerPage) { - return Mod.getAll.select(rs -> { - List f = new ArrayList<>(); - while(rs.next()){ - ModEntry entry = new ModEntry(rs.getString("ModName"), Mod.Platform.getByValue(rs.getInt("Platform"))); - f.add(entry); - } - return f; - }, page * elementsPerPage, elementsPerPage); - } - - public List getAllModsFiltered(int page,int elementsPerPage, int filter) { - return Mod.getAllFiltered.select(rs -> { - List f = new ArrayList<>(); - while(rs.next()){ - ModEntry entry = new ModEntry(rs.getString("ModName"), Mod.Platform.getByValue(rs.getInt("Platform"))); - f.add(entry); - } - return f; - },filter, page * elementsPerPage, elementsPerPage); - } - @Register(value = {"set"},description = "MOD_COMMAND_SET_USAGE") public void set(ProxiedPlayer p,String modName,Mod.Platform platform,Mod.ModType newModType) { - int modPlatform = platform.get(); - boolean modExists = Mod.get.select(ResultSet::next,modName,modPlatform); + boolean modExists = Mod.doesModExist(modName,platform); if(!modExists) { Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE",p,modName); return; } - Mod.set.update(newModType.getValue(),modName,modPlatform); + Mod.setMod(newModType,modName,platform); - Message.send("MOD_CHANGED_TYPE",p,modName,newModType.name(),newModType); + Message.send("MOD_CHANGED_TYPE",p,modName,platform.name(),newModType.name()); } @Register(value = {"get"},description = "MOD_COMMAND_GET_USAGE") public void get(ProxiedPlayer p,String modName,Mod.Platform platform) { - Message.send("MOD_COMMAND_INFO",p,modName,platform.name(),Mod.ModType.valueOf(getModType(modName,platform.get())).name()); - } - - private int getModType(String modName,int modPlatform) { - return Mod.get.select(rs -> { - if(rs.next()) { - return rs.getInt("ModType"); - } - return 0; - },modName,modPlatform); + Message.send("MOD_COMMAND_INFO",p,modName,platform.name(),Mod.getModType(modName,platform).name()); } @Register(value = {"next"}) public void next(ProxiedPlayer p) { - Pair foundMod = Mod.findFirst.select(rs -> { - if(rs.next()) { - String name = rs.getString("ModName"); - int platform = rs.getInt("Platform"); - return new ImmutablePair<>(name,platform); - } - return null; - }); + Pair foundMod = Mod.findFirstMod(); + Mod mod = Mod.get(foundMod.getKey(),foundMod.getValue()); if(foundMod == null) { Message.send("MOD_NO_MORE_UNCLASSIFIED_MODS",p); return; } - Message.send("MOD_FOUND_NEXT_MOD",p,"MOD_OPEN_GUI",new ClickEvent(ClickEvent.Action.RUN_COMMAND,""),foundMod.getKey(),Mod.Platform.getByValue(foundMod.getValue())); - } - - private enum FilterType { - ALL(-1), - UNCLASSIFIED(0), - ALLOWED(1), - PENDING(2), - FORBIDDEN(3), - YT(4); - - final int value; - - FilterType(int value) { - this.value = value; - } - } - - private class ModEntry { - private final String modName; - private final Mod.Platform platform; - - public ModEntry(String modName, Mod.Platform platform) { - this.modName = modName; - this.platform = platform; - } + Message.send("MOD_FOUND_NEXT_MOD",p,"MOD_OPEN_GUI",new ClickEvent(ClickEvent.Action.RUN_COMMAND,""),mod.getModName(),mod.getPlatform().name()); } } diff --git a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java index 44bba9fe..491b0622 100644 --- a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java +++ b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java @@ -27,6 +27,7 @@ import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.bot.util.DiscordRanks; import de.steamwar.bungeecore.commands.ChallengeCommand; import de.steamwar.bungeecore.commands.CheckCommand; +import de.steamwar.bungeecore.commands.ModCommand; import de.steamwar.bungeecore.commands.MsgCommand; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.UserGroup; @@ -135,6 +136,7 @@ public class ConnectionListener extends BasicListener { public void onDisconnect(PlayerDisconnectEvent e){ ChallengeCommand.remove(e.getPlayer()); MsgCommand.remove(e.getPlayer()); + ModCommand.playerFilterType.remove(e.getPlayer()); } @EventHandler diff --git a/src/de/steamwar/bungeecore/sql/Mod.java b/src/de/steamwar/bungeecore/sql/Mod.java index 1695f15f..7f9a1d4b 100644 --- a/src/de/steamwar/bungeecore/sql/Mod.java +++ b/src/de/steamwar/bungeecore/sql/Mod.java @@ -20,18 +20,24 @@ package de.steamwar.bungeecore.sql; import lombok.Getter; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; + +import java.sql.ResultSet; +import java.util.ArrayList; +import java.util.List; public class Mod { - public static final Statement get = new Statement("SELECT * FROM Mods WHERE ModName = ? AND Platform = ?"); + 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 (?, ?)"); - public static final Statement set = new Statement("UPDATE Mods Set ModType = ? WHERE ModName = ? AND Platform = ?"); - public static final Statement findFirst = new Statement("SELECT * FROM Mods WHERE ModType = 0 LIMIT 1"); + 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"); - public static final Statement getAll = new Statement("SELECT * FROM Mods ORDER BY ModName DESC LIMIT ?, ?"); + private static final Statement getAll = new Statement("SELECT * FROM Mods ORDER BY ModName DESC LIMIT ?, ?"); - public static final Statement getAllFiltered = new Statement("SELECT * FROM Mods WHERE ModType = ? ORDER BY ModName DESC LIMIT ?, ?"); + private static final Statement getAllFiltered = new Statement("SELECT * FROM Mods WHERE ModType = ? ORDER BY ModName DESC LIMIT ?, ?"); private final String modName; private final Platform platform; @@ -56,6 +62,53 @@ public class Mod { return new Mod(modName, platform, ModType.UNKLASSIFIED); } + public static Mod get(String modName, int platform) { + return get(modName,Mod.Platform.valueOf(platform)); + } + + public static ModType getModType(String modName,Mod.Platform platform) { + return get(modName,platform).modType; + } + + public static void setMod(Mod.ModType newModType,String modName,Mod.Platform platform) { + set.update(newModType.value ,modName,platform.value); + } + + public static boolean doesModExist(String modName,Mod.Platform modPlatform) { + return get.select(ResultSet::next,modName,modPlatform.value); + } + + public static List getAll(int page, int elementsPerPage) { + return Mod.getAll.select(rs -> { + List f = new ArrayList<>(); + while(rs.next()){ + Mod entry = new Mod(rs.getString("ModName"), Mod.Platform.valueOf(rs.getInt("Platform")),Mod.ModType.valueOf(rs.getInt("ModType"))); + f.add(entry); + } + return f; + },page * elementsPerPage, elementsPerPage); + } + + public static List getAllModsFiltered(int page,int elementsPerPage, Mod.ModType filter) { + return Mod.getAllFiltered.select(rs -> { + List f = new ArrayList<>(); + while(rs.next()){ + Mod entry = new Mod(rs.getString("ModName"), Mod.Platform.valueOf(rs.getInt("Platform")),Mod.ModType.valueOf(rs.getInt("ModType"))); + f.add(entry); + } + return f; + },filter.value, page * elementsPerPage, elementsPerPage); + } + + public static Pair findFirstMod() { + findFirst.select(rs -> { + String name = rs.getString("ModName"); + int platform = rs.getInt("Platform"); + return new ImmutablePair<>(name,platform); + }); + return null; + } + public String getModName() { return modName; } @@ -76,19 +129,18 @@ public class Mod { Platform(int value){ this.value = value; } + + static Platform valueOf(int value){ + for(Platform mt : values()){ + if(value == mt.value) + return mt; + } + throw new EnumConstantNotPresentException(Platform.class, Integer.toString(value)); + } int value; public int get() { return value; } - - public static Platform getByValue(int val) { - switch (val) { - case 0 : return FORGE; - case 1: return LABYMOD; - case 2: return FABRIC; - default: return null; - } - } } public enum ModType { @@ -98,7 +150,7 @@ public class Mod { RED(3), YOUTUBER_ONLY(4); - public static ModType valueOf(int value){ + static ModType valueOf(int value){ for(ModType mt : values()){ if(value == mt.value) return mt; @@ -109,7 +161,7 @@ public class Mod { ModType(int value){ this.value = value; } - @Getter + int value; } } diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 1dc88dc0..5fa66bd0 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -662,11 +662,11 @@ MOD_COMMAND_SET_USAGE=§7/mod set [mod name] [platform] [ModType 1-4] MOD_COMMAND_GET_USAGE=§7/mod get [mod name] [platform] MOD_CHANGED_TYPE=§7Successfully reclassified mod {0} on platform {1} to type {2}! MOD_NO_MORE_UNCLASSIFIED_MODS=§7No more unclassified mods found in databank! -MOD_FOUND_NEXT_MOD=§7Next unclassified mod is {0}! +MOD_FOUND_NEXT_MOD=§7Next unclassified mod is {0} on platform {1}! MOD_COMMAND_NOT_FOUND_IN_DATABASE=§7The Mod {0} on platform {1} was§c not §7found in the database! MOD_COMMAND_INFO=§7The mod {0} on platform {1} is of the type {2}. -MOD_COMMAND_GUI_TITLE=§7Unclassified Mods -MOD_COMMAND_GUI=§7Mod Type Changer +MOD_COMMAND_GUI_TITLE=Unclassified Mods +MOD_COMMAND_CLASSICIATION_GUI=Mod Type Changer MOD_OPEN_GUI=§7Open Gui MOD_UNCLASSIFIED=Unclassified MOD_ALLOWED=Allowed From 5d979310ffba2f02c315792dc6c94394a8ade7d6 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Fri, 13 Jan 2023 22:05:13 +0100 Subject: [PATCH 09/22] Fix pushed commoncore --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index c6da22f0..bf480f6e 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit c6da22f0bee3865b7b3283bc17275e12c5de14af +Subproject commit bf480f6e6fc212362da34620385d4dee84250698 From aa9bd8b00f72bd325a373b4d9d2af7252991a469 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 13 Jan 2023 22:18:36 +0100 Subject: [PATCH 10/22] Revert CommonCore --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index bf480f6e..c6da22f0 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit bf480f6e6fc212362da34620385d4dee84250698 +Subproject commit c6da22f0bee3865b7b3283bc17275e12c5de14af From fe67ad4b60af955fd7c7e584e177271100223b83 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Mon, 16 Jan 2023 20:01:30 +0100 Subject: [PATCH 11/22] Update messanges --- src/de/steamwar/messages/BungeeCore.properties | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 5fa66bd0..4e03eb5c 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -668,10 +668,9 @@ MOD_COMMAND_INFO=§7The mod {0} on platform {1} is of the type {2}. MOD_COMMAND_GUI_TITLE=Unclassified Mods MOD_COMMAND_CLASSICIATION_GUI=Mod Type Changer MOD_OPEN_GUI=§7Open Gui -MOD_UNCLASSIFIED=Unclassified -MOD_ALLOWED=Allowed -MOD_PENDING=Pending -MOD_FORBIDDEN=Forbidden -MOD_YT=YT Only -MOD_ALL=All -MOD_ITEM_BACK=Back +MOD_UNCLASSIFIED=§7Unclassified +MOD_ALLOWED=§aAllowed +MOD_PENDING=§ePending +MOD_FORBIDDEN=§cForbidden +MOD_YT=§5YT Only +MOD_ITEM_BACK=§7Back From fc5c4922db273f2f3af1897f7eed65a66fcccab8 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Mon, 16 Jan 2023 20:03:33 +0100 Subject: [PATCH 12/22] Revert unwanted changes --- src/de/steamwar/bungeecore/commands/WhoisCommand.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/de/steamwar/bungeecore/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/commands/WhoisCommand.java index 35592496..bf016c3a 100644 --- a/src/de/steamwar/bungeecore/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/commands/WhoisCommand.java @@ -28,9 +28,11 @@ 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.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; +import java.net.InetSocketAddress; import java.sql.Timestamp; import java.text.DecimalFormat; import java.time.Instant; From 58fb831950f3347d98cecd5e6bdb8c14185a6894 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Mon, 16 Jan 2023 20:11:58 +0100 Subject: [PATCH 13/22] Push fixes --- .../bungeecore/commands/ModCommand.java | 9 ++++----- src/de/steamwar/bungeecore/sql/Mod.java | 18 +++--------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/ModCommand.java b/src/de/steamwar/bungeecore/commands/ModCommand.java index 9825bec4..0c35fe40 100644 --- a/src/de/steamwar/bungeecore/commands/ModCommand.java +++ b/src/de/steamwar/bungeecore/commands/ModCommand.java @@ -64,7 +64,7 @@ public class ModCommand extends SWCommand { } public void updateAndCloseGui(Mod.ModType modType,String modName,Mod.Platform modPlatform,SWInventory toClose,ProxiedPlayer p) { - Mod.setMod(modType, modName, modPlatform); + Mod.get(modName,modPlatform).setModType(modType,modName,modPlatform); toClose.close(); openGui(p); } @@ -123,7 +123,7 @@ public class ModCommand extends SWCommand { return; } - Mod.setMod(newModType,modName,platform); + Mod.get(modName,platform).setModType(newModType,modName,platform); Message.send("MOD_CHANGED_TYPE",p,modName,platform.name(),newModType.name()); } @@ -135,10 +135,9 @@ public class ModCommand extends SWCommand { @Register(value = {"next"}) public void next(ProxiedPlayer p) { - Pair foundMod = Mod.findFirstMod(); - Mod mod = Mod.get(foundMod.getKey(),foundMod.getValue()); + Mod mod = Mod.findFirstMod(); - if(foundMod == null) { + if(mod == null) { Message.send("MOD_NO_MORE_UNCLASSIFIED_MODS",p); return; } diff --git a/src/de/steamwar/bungeecore/sql/Mod.java b/src/de/steamwar/bungeecore/sql/Mod.java index 7f9a1d4b..dc46205a 100644 --- a/src/de/steamwar/bungeecore/sql/Mod.java +++ b/src/de/steamwar/bungeecore/sql/Mod.java @@ -70,25 +70,13 @@ public class Mod { return get(modName,platform).modType; } - public static void setMod(Mod.ModType newModType,String modName,Mod.Platform platform) { + public void setModType(Mod.ModType newModType,String modName,Mod.Platform platform) { set.update(newModType.value ,modName,platform.value); } public static boolean doesModExist(String modName,Mod.Platform modPlatform) { return get.select(ResultSet::next,modName,modPlatform.value); } - - public static List getAll(int page, int elementsPerPage) { - return Mod.getAll.select(rs -> { - List f = new ArrayList<>(); - while(rs.next()){ - Mod entry = new Mod(rs.getString("ModName"), Mod.Platform.valueOf(rs.getInt("Platform")),Mod.ModType.valueOf(rs.getInt("ModType"))); - f.add(entry); - } - return f; - },page * elementsPerPage, elementsPerPage); - } - public static List getAllModsFiltered(int page,int elementsPerPage, Mod.ModType filter) { return Mod.getAllFiltered.select(rs -> { List f = new ArrayList<>(); @@ -100,11 +88,11 @@ public class Mod { },filter.value, page * elementsPerPage, elementsPerPage); } - public static Pair findFirstMod() { + public static Mod findFirstMod() { findFirst.select(rs -> { String name = rs.getString("ModName"); int platform = rs.getInt("Platform"); - return new ImmutablePair<>(name,platform); + return get(name,Platform.valueOf(platform)); }); return null; } From 334459b8487a7d1175ee72f9a2380760842337c9 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Sat, 21 Jan 2023 16:31:19 +0100 Subject: [PATCH 14/22] Smaller tweaks --- .../bungeecore/commands/ModCommand.java | 6 ++-- .../bungeecore/listeners/mods/Fabric.java | 2 +- .../bungeecore/listeners/mods/Forge.java | 4 +-- .../bungeecore/listeners/mods/Forge12.java | 2 +- .../bungeecore/listeners/mods/LabyMod.java | 2 +- .../listeners/mods/WorldDownloader.java | 2 +- src/de/steamwar/bungeecore/sql/Mod.java | 28 +++++++++---------- 7 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/ModCommand.java b/src/de/steamwar/bungeecore/commands/ModCommand.java index 0c35fe40..cf91e7a8 100644 --- a/src/de/steamwar/bungeecore/commands/ModCommand.java +++ b/src/de/steamwar/bungeecore/commands/ModCommand.java @@ -28,7 +28,7 @@ import de.steamwar.bungeecore.sql.*; import de.steamwar.command.SWCommand; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; -import org.apache.commons.lang3.tuple.Pair; + import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; @@ -64,7 +64,7 @@ public class ModCommand extends SWCommand { } public void updateAndCloseGui(Mod.ModType modType,String modName,Mod.Platform modPlatform,SWInventory toClose,ProxiedPlayer p) { - Mod.get(modName,modPlatform).setModType(modType,modName,modPlatform); + Mod.getOrCreate(modName,modPlatform).setModType(modType); toClose.close(); openGui(p); } @@ -123,7 +123,7 @@ public class ModCommand extends SWCommand { return; } - Mod.get(modName,platform).setModType(newModType,modName,platform); + Mod.getOrCreate(modName,platform).setModType(newModType); Message.send("MOD_CHANGED_TYPE",p,modName,platform.name(),newModType.name()); } diff --git a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java index c8990a72..46c4f913 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java @@ -119,7 +119,7 @@ public class Fabric extends BasicListener { } for(JsonElement mod : array) { - mods.add(Mod.get(mod.getAsString(), Mod.Platform.FABRIC)); + mods.add(Mod.getOrCreate(mod.getAsString(), Mod.Platform.FABRIC)); } /* diff --git a/src/de/steamwar/bungeecore/listeners/mods/Forge.java b/src/de/steamwar/bungeecore/listeners/mods/Forge.java index 94a0fa28..d6ebf21c 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Forge.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Forge.java @@ -26,9 +26,7 @@ import io.netty.channel.ChannelPipeline; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.PendingConnection; import net.md_5.bungee.api.event.LoginEvent; -import net.md_5.bungee.api.event.ProxyPingEvent; import net.md_5.bungee.connection.InitialHandler; -import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.HandlerBoss; import net.md_5.bungee.netty.PacketHandler; @@ -135,7 +133,7 @@ public class Forge extends BasicListener { Utils.VarInt nameLength = Utils.readVarInt(data, pos); pos += nameLength.length; - mods.add(Mod.get(new String(data, pos, nameLength.value), Mod.Platform.FORGE)); + mods.add(Mod.getOrCreate(new String(data, pos, nameLength.value), Mod.Platform.FORGE)); pos += nameLength.value; } diff --git a/src/de/steamwar/bungeecore/listeners/mods/Forge12.java b/src/de/steamwar/bungeecore/listeners/mods/Forge12.java index eb463f40..2bdd5a8e 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Forge12.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Forge12.java @@ -92,7 +92,7 @@ public class Forge12 extends BasicListener { //Version information is unused bytePos += 1 + data[bytePos]; - mods.add(Mod.get(new String(name), Mod.Platform.FORGE)); + mods.add(Mod.getOrCreate(new String(name), Mod.Platform.FORGE)); } if (Utils.handleMods(p, mods)) { diff --git a/src/de/steamwar/bungeecore/listeners/mods/LabyMod.java b/src/de/steamwar/bungeecore/listeners/mods/LabyMod.java index e659b4d3..22887d49 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/LabyMod.java +++ b/src/de/steamwar/bungeecore/listeners/mods/LabyMod.java @@ -67,7 +67,7 @@ public class LabyMod extends BasicListener { try{ InfoPacket info = new InfoPacket(value.value); for(InfoPacket.Addon addon : info.addons) { - mods.add(Mod.get(addon.name, Mod.Platform.LABYMOD)); + mods.add(Mod.getOrCreate(addon.name, Mod.Platform.LABYMOD)); } }catch(IOException e){ BungeeCore.log("Could not read JSON", e); diff --git a/src/de/steamwar/bungeecore/listeners/mods/WorldDownloader.java b/src/de/steamwar/bungeecore/listeners/mods/WorldDownloader.java index 44270b61..1b396256 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/WorldDownloader.java +++ b/src/de/steamwar/bungeecore/listeners/mods/WorldDownloader.java @@ -28,6 +28,6 @@ public class WorldDownloader extends BasicListener { return; event.setCancelled(true); - Utils.handleMods((ProxiedPlayer) sender, Lists.newArrayList(Mod.get("wdl", Mod.Platform.FORGE))); + Utils.handleMods((ProxiedPlayer) sender, Lists.newArrayList(Mod.getOrCreate("wdl", Mod.Platform.FORGE))); } } diff --git a/src/de/steamwar/bungeecore/sql/Mod.java b/src/de/steamwar/bungeecore/sql/Mod.java index dc46205a..391c2cd4 100644 --- a/src/de/steamwar/bungeecore/sql/Mod.java +++ b/src/de/steamwar/bungeecore/sql/Mod.java @@ -19,11 +19,8 @@ package de.steamwar.bungeecore.sql; -import lombok.Getter; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; - import java.sql.ResultSet; +import java.sql.SQLException; import java.util.ArrayList; import java.util.List; @@ -49,7 +46,13 @@ public class Mod { this.modType = modType; } - public static Mod get(String modName, Platform platform){ + private Mod(ResultSet resultSet) throws SQLException { + this.modName = resultSet.getString("ModName"); + this.platform = Mod.Platform.valueOf(resultSet.getInt("Platform")); + this.modType = ModType.valueOf(resultSet.getInt("ModType")); + } + + public static Mod getOrCreate(String modName, Platform platform){ Mod mod = get.select(rs -> { if(rs.next()) return new Mod(modName, platform, ModType.valueOf(rs.getInt("ModType"))); @@ -62,15 +65,11 @@ public class Mod { return new Mod(modName, platform, ModType.UNKLASSIFIED); } - public static Mod get(String modName, int platform) { - return get(modName,Mod.Platform.valueOf(platform)); - } - public static ModType getModType(String modName,Mod.Platform platform) { - return get(modName,platform).modType; + return getOrCreate(modName,platform).modType; } - public void setModType(Mod.ModType newModType,String modName,Mod.Platform platform) { + public void setModType(Mod.ModType newModType) { set.update(newModType.value ,modName,platform.value); } @@ -81,7 +80,7 @@ public class Mod { return Mod.getAllFiltered.select(rs -> { List f = new ArrayList<>(); while(rs.next()){ - Mod entry = new Mod(rs.getString("ModName"), Mod.Platform.valueOf(rs.getInt("Platform")),Mod.ModType.valueOf(rs.getInt("ModType"))); + Mod entry = new Mod(rs); f.add(entry); } return f; @@ -89,12 +88,11 @@ public class Mod { } public static Mod findFirstMod() { - findFirst.select(rs -> { + return findFirst.select(rs -> { String name = rs.getString("ModName"); int platform = rs.getInt("Platform"); - return get(name,Platform.valueOf(platform)); + return new Mod(name,Platform.valueOf(platform),ModType.UNKLASSIFIED); }); - return null; } public String getModName() { From 7dee43c868d59fa79ae7ac8a532c90f70475b90e Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Mon, 23 Jan 2023 15:40:42 +0100 Subject: [PATCH 15/22] Resolve Merge Conflicts --- src/de/steamwar/bungeecore/listeners/ConnectionListener.java | 2 ++ src/de/steamwar/bungeecore/sql/Mod.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java index 5256709c..a1b2e82d 100644 --- a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java +++ b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java @@ -27,6 +27,7 @@ import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.bot.util.DiscordRanks; import de.steamwar.bungeecore.commands.ChallengeCommand; 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; @@ -137,6 +138,7 @@ public class ConnectionListener extends BasicListener { ChallengeCommand.remove(e.getPlayer()); MsgCommand.remove(e.getPlayer()); Utils.playerModMap.remove(e.getPlayer().getUniqueId()); + ModCommand.playerFilterType.remove(e.getPlayer()); } @EventHandler diff --git a/src/de/steamwar/bungeecore/sql/Mod.java b/src/de/steamwar/bungeecore/sql/Mod.java index 391c2cd4..824618ca 100644 --- a/src/de/steamwar/bungeecore/sql/Mod.java +++ b/src/de/steamwar/bungeecore/sql/Mod.java @@ -19,6 +19,8 @@ package de.steamwar.bungeecore.sql; +import de.steamwar.sql.internal.Statement; + import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; From 87efa9659de5139737cd951c13b27353400814a7 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Mon, 23 Jan 2023 15:44:31 +0100 Subject: [PATCH 16/22] Fix more weird errors --- src/de/steamwar/bungeecore/sql/Mod.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/de/steamwar/bungeecore/sql/Mod.java b/src/de/steamwar/bungeecore/sql/Mod.java index 824618ca..268d47d6 100644 --- a/src/de/steamwar/bungeecore/sql/Mod.java +++ b/src/de/steamwar/bungeecore/sql/Mod.java @@ -132,11 +132,11 @@ public class Mod { } public enum ModType { - UNKLASSIFIED(0), - GREEN(1), - YELLOW(2), - RED(3), - YOUTUBER_ONLY(4); + UNKLASSIFIED(0,"7"), + GREEN(1,"a"), + YELLOW(2,"e"), + RED(3,"c"), + YOUTUBER_ONLY(4,"6"); static ModType valueOf(int value){ for(ModType mt : values()){ @@ -146,10 +146,15 @@ public class Mod { throw new EnumConstantNotPresentException(ModType.class, Integer.toString(value)); } - ModType(int value){ + ModType(int value,String colorcode){ this.value = value; + this.colorcode = colorcode; } - int value; + String colorcode; + + public String getColorCode() { + return colorcode; + } } } From 48cdfe35f0ecfdbe5aacd4730ebfeabfff77bc47 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 2 Feb 2023 11:02:36 +0100 Subject: [PATCH 17/22] Fix Bugs and code problems Signed-off-by: Lixfel --- .../bungeecore/commands/ModCommand.java | 40 ++++---- src/de/steamwar/bungeecore/sql/Mod.java | 97 ++++++------------- .../steamwar/messages/BungeeCore.properties | 4 +- 3 files changed, 54 insertions(+), 87 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/ModCommand.java b/src/de/steamwar/bungeecore/commands/ModCommand.java index cf91e7a8..3cbd35c4 100644 --- a/src/de/steamwar/bungeecore/commands/ModCommand.java +++ b/src/de/steamwar/bungeecore/commands/ModCommand.java @@ -63,8 +63,8 @@ public class ModCommand extends SWCommand { swStreamInv.open(); } - public void updateAndCloseGui(Mod.ModType modType,String modName,Mod.Platform modPlatform,SWInventory toClose,ProxiedPlayer p) { - Mod.getOrCreate(modName,modPlatform).setModType(modType); + public void updateAndCloseGui(Mod.ModType modType, Mod mod, SWInventory toClose, ProxiedPlayer p) { + mod.setModType(modType); toClose.close(); openGui(p); } @@ -74,8 +74,8 @@ public class ModCommand extends SWCommand { inv.addItem(1, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), click -> playerFilterType.replace(p, Mod.ModType.UNKLASSIFIED)); inv.addItem(2, new SWItem(Message.parse("MOD_ALLOWED",p),2), click -> playerFilterType.replace(p, Mod.ModType.GREEN)); - inv.addItem(3, new SWItem(Message.parse("MOD_PENDING",p), 11),click -> playerFilterType.replace(p, Mod.ModType.YELLOW)); - inv.addItem(4, new SWItem(Message.parse("MOD_FORBIDDEN",p),1), click -> playerFilterType.replace(p, Mod.ModType.RED)); + inv.addItem(3, new SWItem(Message.parse("MOD_FORBIDDEN",p), 11), click -> playerFilterType.replace(p, Mod.ModType.YELLOW)); + inv.addItem(4, new SWItem(Message.parse("MOD_AUTOBAN",p),1), click -> playerFilterType.replace(p, Mod.ModType.RED)); inv.addItem(5, new SWItem(Message.parse("MOD_YT",p),13), click -> playerFilterType.replace(p, Mod.ModType.YOUTUBER_ONLY)); inv.addItem(8, new SWItem("ARROW", Message.parse("MOD_ITEM_BACK",p)), click -> { @@ -89,14 +89,11 @@ public class ModCommand extends SWCommand { private void openClassificationGui(ProxiedPlayer p,Mod element) { SWInventory swInventory = new SWInventory(p,9,Message.parse("MOD_COMMAND_CLASSICIATION_GUI",p)); - String modName = element.getModName(); - Mod.Platform modPlatform = element.getPlatform(); - - swInventory.addItem(2, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), (click1 -> updateAndCloseGui(Mod.ModType.UNKLASSIFIED,modName,modPlatform,swInventory,p))); - swInventory.addItem(3, new SWItem(Message.parse("MOD_ALLOWED",p), 2), (click1 -> updateAndCloseGui(Mod.ModType.GREEN,modName,modPlatform,swInventory,p))); - swInventory.addItem(4, new SWItem(Message.parse("MOD_PENDING",p), 11), (click1 -> updateAndCloseGui(Mod.ModType.YELLOW,modName,modPlatform,swInventory,p))); - swInventory.addItem(5, new SWItem(Message.parse("MOD_FORBIDDEN",p),1), (click1 -> updateAndCloseGui(Mod.ModType.RED,modName,modPlatform,swInventory,p))); - swInventory.addItem(6, new SWItem(Message.parse("MOD_YT",p), 13), (click1 -> updateAndCloseGui(Mod.ModType.YOUTUBER_ONLY,modName,modPlatform,swInventory,p))); + swInventory.addItem(2, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), (click1 -> updateAndCloseGui(Mod.ModType.UNKLASSIFIED,element,swInventory,p))); + swInventory.addItem(3, new SWItem(Message.parse("MOD_ALLOWED",p), 2), (click1 -> updateAndCloseGui(Mod.ModType.GREEN,element,swInventory,p))); + swInventory.addItem(4, new SWItem(Message.parse("MOD_FORBIDDEN",p), 11), (click1 -> updateAndCloseGui(Mod.ModType.YELLOW,element,swInventory,p))); + swInventory.addItem(5, new SWItem(Message.parse("MOD_AUTOBAN",p),1), (click1 -> updateAndCloseGui(Mod.ModType.RED,element,swInventory,p))); + swInventory.addItem(6, new SWItem(Message.parse("MOD_YT",p), 13), (click1 -> updateAndCloseGui(Mod.ModType.YOUTUBER_ONLY,element,swInventory,p))); swInventory.addItem(8,new SWItem("ARROW",Message.parse("MOD_ITEM_BACK",p)), click1 -> { swInventory.close(); @@ -116,27 +113,30 @@ public class ModCommand extends SWCommand { @Register(value = {"set"},description = "MOD_COMMAND_SET_USAGE") public void set(ProxiedPlayer p,String modName,Mod.Platform platform,Mod.ModType newModType) { - boolean modExists = Mod.doesModExist(modName,platform); - - if(!modExists) { - Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE",p,modName); + Mod mod = Mod.get(modName, platform); + if(mod == null) { + Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE",p,modName, platform.name()); return; } - Mod.getOrCreate(modName,platform).setModType(newModType); - + mod.setModType(newModType); Message.send("MOD_CHANGED_TYPE",p,modName,platform.name(),newModType.name()); } @Register(value = {"get"},description = "MOD_COMMAND_GET_USAGE") public void get(ProxiedPlayer p,String modName,Mod.Platform platform) { - Message.send("MOD_COMMAND_INFO",p,modName,platform.name(),Mod.getModType(modName,platform).name()); + Mod mod = Mod.get(modName, platform); + if(mod == null) { + Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE", p, modName, platform.name()); + return; + } + + Message.send("MOD_COMMAND_INFO", p, modName, platform.name(), mod.getModType().name()); } @Register(value = {"next"}) public void next(ProxiedPlayer p) { Mod mod = Mod.findFirstMod(); - if(mod == null) { Message.send("MOD_NO_MORE_UNCLASSIFIED_MODS",p); return; diff --git a/src/de/steamwar/bungeecore/sql/Mod.java b/src/de/steamwar/bungeecore/sql/Mod.java index 268d47d6..897b7f92 100644 --- a/src/de/steamwar/bungeecore/sql/Mod.java +++ b/src/de/steamwar/bungeecore/sql/Mod.java @@ -34,9 +34,7 @@ public class Mod { 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 getAll = new Statement("SELECT * FROM Mods ORDER BY ModName DESC LIMIT ?, ?"); - - private static final Statement getAllFiltered = new Statement("SELECT * FROM Mods WHERE ModType = ? ORDER BY ModName DESC LIMIT ?, ?"); + 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; @@ -49,51 +47,46 @@ public class Mod { } private Mod(ResultSet resultSet) throws SQLException { - this.modName = resultSet.getString("ModName"); - this.platform = Mod.Platform.valueOf(resultSet.getInt("Platform")); - this.modType = ModType.valueOf(resultSet.getInt("ModType")); + this(resultSet.getString("ModName"), Mod.Platform.values()[resultSet.getInt("Platform")], ModType.values()[resultSet.getInt("ModType")]); } - public static Mod getOrCreate(String modName, Platform platform){ - Mod mod = get.select(rs -> { + public static Mod get(String name, Platform platform) { + return get.select(rs -> { if(rs.next()) - return new Mod(modName, platform, ModType.valueOf(rs.getInt("ModType"))); + return new Mod(rs); return null; - }, modName, platform.value); + }, name, platform.ordinal()); + } + + public static Mod getOrCreate(String name, Platform platform) { + Mod mod = get(name, platform); if(mod != null) return mod; - insert.update(modName, platform.value); - return new Mod(modName, platform, ModType.UNKLASSIFIED); - } - - public static ModType getModType(String modName,Mod.Platform platform) { - return getOrCreate(modName,platform).modType; + insert.update(name, platform.ordinal()); + return new Mod(name, platform, ModType.UNKLASSIFIED); } public void setModType(Mod.ModType newModType) { - set.update(newModType.value ,modName,platform.value); + set.update(newModType.ordinal(), modName, platform.ordinal()); } - public static boolean doesModExist(String modName,Mod.Platform modPlatform) { - return get.select(ResultSet::next,modName,modPlatform.value); - } public static List getAllModsFiltered(int page,int elementsPerPage, Mod.ModType filter) { - return Mod.getAllFiltered.select(rs -> { + return Mod.getPageOfType.select(rs -> { List f = new ArrayList<>(); - while(rs.next()){ - Mod entry = new Mod(rs); - f.add(entry); - } + + while(rs.next()) + f.add(new Mod(rs)); + return f; - },filter.value, page * elementsPerPage, elementsPerPage); + },filter.ordinal(), page * elementsPerPage, elementsPerPage); } public static Mod findFirstMod() { return findFirst.select(rs -> { - String name = rs.getString("ModName"); - int platform = rs.getInt("Platform"); - return new Mod(name,Platform.valueOf(platform),ModType.UNKLASSIFIED); + if(rs.next()) + return new Mod(rs); + return null; }); } @@ -110,48 +103,22 @@ public class Mod { } public enum Platform{ - FORGE(0), - LABYMOD(1), - FABRIC(2); - - Platform(int value){ - this.value = value; - } - - static Platform valueOf(int value){ - for(Platform mt : values()){ - if(value == mt.value) - return mt; - } - throw new EnumConstantNotPresentException(Platform.class, Integer.toString(value)); - } - int value; - public int get() { - return value; - } + FORGE, + LABYMOD, + FABRIC } public enum ModType { - UNKLASSIFIED(0,"7"), - GREEN(1,"a"), - YELLOW(2,"e"), - RED(3,"c"), - YOUTUBER_ONLY(4,"6"); + UNKLASSIFIED("7"), + GREEN("a"), + YELLOW("e"), + RED("c"), + YOUTUBER_ONLY("6"); - static ModType valueOf(int value){ - for(ModType mt : values()){ - if(value == mt.value) - return mt; - } - throw new EnumConstantNotPresentException(ModType.class, Integer.toString(value)); - } - - ModType(int value,String colorcode){ - this.value = value; + ModType(String colorcode) { this.colorcode = colorcode; } - int value; - String colorcode; + private final String colorcode; public String getColorCode() { return colorcode; diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 910fe19a..fb44d5a8 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -674,7 +674,7 @@ MOD_COMMAND_CLASSICIATION_GUI=Mod Type Changer MOD_OPEN_GUI=§7Open Gui MOD_UNCLASSIFIED=§7Unclassified MOD_ALLOWED=§aAllowed -MOD_PENDING=§ePending -MOD_FORBIDDEN=§cForbidden +MOD_FORBIDDEN=§eForbidden +MOD_AUTOBAN=§cAutoban MOD_YT=§5YT Only MOD_ITEM_BACK=§7Back From 0c1330899710ac140fde4775e7213660da82ef1b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 3 Feb 2023 19:25:31 +0100 Subject: [PATCH 18/22] Fix quotes --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index d12fbbd3..69024c3b 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit d12fbbd339f6f34108301aa08d1377eceea250a5 +Subproject commit 69024c3bb9a432b71d94d28e7f5485e69d976b3f From a40ad699f5a5d2109fa8a6d593327c8404c05db3 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 5 Feb 2023 23:42:35 +0100 Subject: [PATCH 19/22] Fix Logging of Upload schem to fix the whole thing --- .../bungeecore/bot/listeners/PrivateMessageListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java b/src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java index c458e07b..8aafe2f6 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java @@ -72,7 +72,7 @@ public class PrivateMessageListener extends BasicDiscordListener { event.getMessage().reply("`" + name + "` wurde erfolgreich hochgeladen").queue(); } catch (Exception e) { event.getMessage().reply("`" + name + "` konnte nicht hochgeladen werden, bitte versuche es später nochmal oder wende dich an einen Developer").queue(); - BungeeCore.log("Could not Upload Schem \"" + name + "\" from User \"" + user.getUserName() + "\"" + e); + BungeeCore.log("Could not Upload Schem \"" + name + "\" from User \"" + user.getUserName() + "\"", e); } } } From e3f84c0b4d3fab3f3f707a166e89b74c4b573914 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Mon, 6 Feb 2023 17:19:10 +0100 Subject: [PATCH 20/22] Fix license header --- src/de/steamwar/bungeecore/commands/ModCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/commands/ModCommand.java b/src/de/steamwar/bungeecore/commands/ModCommand.java index 3cbd35c4..f5b4c667 100644 --- a/src/de/steamwar/bungeecore/commands/ModCommand.java +++ b/src/de/steamwar/bungeecore/commands/ModCommand.java @@ -1,7 +1,7 @@ /* This file is a part of the SteamWar software. - Copyright (C) 2020 SteamWar.de-Serverteam + 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 From 27c241f2d48f7d75ff5b38e2c8dadfe2df9676ef Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 17 Feb 2023 11:54:20 +0100 Subject: [PATCH 21/22] Fix CheckCommand schematic deleted Signed-off-by: Lixfel --- CommonCore | 2 +- .../bungeecore/commands/CheckCommand.java | 64 +++++++++++-------- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/CommonCore b/CommonCore index 69024c3b..89b0c14d 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 69024c3bb9a432b71d94d28e7f5485e69d976b3f +Subproject commit 89b0c14da664589a7c9699d73bf72028cdf9dd0d diff --git a/src/de/steamwar/bungeecore/commands/CheckCommand.java b/src/de/steamwar/bungeecore/commands/CheckCommand.java index 02fc7a87..061b2543 100644 --- a/src/de/steamwar/bungeecore/commands/CheckCommand.java +++ b/src/de/steamwar/bungeecore/commands/CheckCommand.java @@ -28,7 +28,6 @@ import de.steamwar.bungeecore.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,7 +36,6 @@ 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; @@ -265,43 +263,47 @@ public class CheckCommand extends SWCommand { } private void accept(int rank){ - if(ranks.containsKey(schematic.getSchemtype())){ - if(rank <= 0 || ranks.get(schematic.getSchemtype()).size() < rank){ - Message.send("CHECK_INVALID_RANK", checker); - return; + if(createLog("freigegeben")) { + if(ranks.containsKey(schematic.getSchemtype())){ + if(rank <= 0 || ranks.get(schematic.getSchemtype()).size() < rank){ + Message.send("CHECK_INVALID_RANK", checker); + return; + } + schematic.setRank(rank); } - schematic.setRank(rank); + + schematic.setType(schematic.getSchemtype().fightType().toDB()); + SteamwarUser user = SteamwarUser.get(schematic.getOwner()); + ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid()); + if(player != null) { + Message.send("CHECK_ACCEPTED", player, schematic.getSchemtype().name(), schematic.getName()); + } else { + DiscordSchemAlert.sendAccept(schematic, user); + } + Message.team("CHECK_ACCEPTED_TEAM", schematic.getName(), user.getUserName()); } - schematic.setType(schematic.getSchemtype().fightType().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()); - if(player != null) { - Message.send("CHECK_ACCEPTED", player, schematic.getSchemtype().name(), schematic.getName()); - } else { - DiscordSchemAlert.sendAccept(schematic, user); - } - Message.team("CHECK_ACCEPTED_TEAM", schematic.getName(), user.getUserName()); stop(); } private void decline(String reason){ - CheckedSchematic.create(schematic, SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), reason); - SteamwarUser user = SteamwarUser.get(schematic.getOwner()); - ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid()); - if(player != null) { - Message.send("CHECK_DECLINED", player, schematic.getSchemtype().name(), schematic.getName(), reason); - } else { - DiscordSchemAlert.sendDecline(schematic, user, reason); + if(createLog(reason)) { + SteamwarUser user = SteamwarUser.get(schematic.getOwner()); + ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid()); + if(player != null) { + Message.send("CHECK_DECLINED", player, schematic.getSchemtype().name(), schematic.getName(), reason); + } else { + DiscordSchemAlert.sendDecline(schematic, user, reason); + } + Message.team("CHECK_DECLINED_TEAM", schematic.getName(), user.getUserName(), reason); + schematic.setType(SchematicType.Normal.toDB()); } - Message.team("CHECK_DECLINED_TEAM", schematic.getName(), user.getUserName(), reason); - schematic.setType(SchematicType.Normal.toDB()); + stop(); } private void abort(){ - CheckedSchematic.create(schematic, SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "Prüfvorgang abgebrochen"); + createLog("Prüfvorgang abgebrochen"); stop(); } @@ -322,5 +324,13 @@ public class CheckCommand extends SWCommand { currentCheckers.remove(checker.getUniqueId()); currentSchems.remove(schematic.getId()); } + + private boolean createLog(String reason) { + if(SchematicNode.getSchematicNode(schematic.getId()) == null) // Schematic was deleted + return false; + + CheckedSchematic.create(schematic, SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), reason); + return true; + } } } From 3f9f9546f6a687b6c7302d07e2e70f7359b3237e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 17 Feb 2023 14:51:03 +0100 Subject: [PATCH 22/22] Improve needed mods check --- src/de/steamwar/bungeecore/listeners/mods/Fabric.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java index 440ab121..24b48045 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java @@ -122,12 +122,8 @@ public class Fabric extends BasicListener { mods.add(Mod.get(mod.getAsString(), Mod.Platform.FABRIC)); } - if(!neededModsContained(mods)) { - logMessage(user, "Needed mods are not contained", dataString); - return; - } - - if(Utils.handleMods(player,mods)) { + boolean neededMods = neededModsContained(mods); + if(Utils.handleMods(player,mods) && neededMods) { if (Storage.fabricCheckedPlayers.containsKey(player)) { long current = Storage.fabricCheckedPlayers.get(player); if (current != dataString.hashCode()) { @@ -139,6 +135,8 @@ public class Fabric extends BasicListener { Storage.fabricCheckedPlayers.put(player, dataString.hashCode()); } Storage.fabricPlayers.remove(player); + } else if (!neededMods) { + logMessage(user, "Needed mods are not contained", dataString); } }