From e0a1542b03f4e5f4527a35c07941ec87f4a442e1 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Wed, 4 Jan 2023 15:15:16 +0100 Subject: [PATCH] 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 29a788d..e9c7077 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);