From 5462a5fd443d8bfecca45d20dfbb9b12fad9aa00 Mon Sep 17 00:00:00 2001 From: Minenash Date: Sun, 27 Jan 2019 18:15:14 -0500 Subject: Checked if token was already made. If so,just give said token --- .../com/redstoner/modules/discord/Discord.java | 45 +++++++++++++--------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/main/java/com/redstoner/modules/discord/Discord.java b/src/main/java/com/redstoner/modules/discord/Discord.java index e5005ca..4c2a61c 100644 --- a/src/main/java/com/redstoner/modules/discord/Discord.java +++ b/src/main/java/com/redstoner/modules/discord/Discord.java @@ -25,7 +25,7 @@ import com.redstoner.modules.Module; import net.nemez.chatapi.click.Message; @Commands(CommandHolderType.File) -@Version(major = 5, minor = 0, revision = 1, compatible = 4) +@Version(major = 5, minor = 0, revision = 2, compatible = 4) public class Discord implements Module { private MysqlTable table; @@ -66,8 +66,9 @@ public class Discord implements Module { MysqlField token = new MysqlField("token", new VarChar(8), false); MysqlField uuid = new MysqlField("uuid", new VarChar(36), false); + MysqlField used = new MysqlField("used", new TinyInt(1), false); - database.createTableIfNotExists((String) config.get("table"), token, uuid); + database.createTableIfNotExists((String) config.get("table"), token, uuid, used); table = database.getTable(config.get("table")); } catch (NullPointerException e) { @@ -86,28 +87,34 @@ public class Discord implements Module { String token = null; int tries = 0; - while (token == null) { - token = randomToken(8); - Object[] results = table.get("token", new MysqlConstraint("token", ConstraintOperator.EQUAL, token)); + Object[] existingToken = table.get("token", new MysqlConstraint("uuid", ConstraintOperator.EQUAL, pUUID)); + + if (existingToken.length > 0) + token = (String) existingToken[0]; + else { + while (token == null) { + token = randomToken(8); + Object[] results = table.get("token", new MysqlConstraint("token", ConstraintOperator.EQUAL, token)); + + if (results.length > 0) { + token = null; + tries++; + } + + if (tries > 10) break; + } - if (results.length > 0) { - token = null; - tries++; + if (token == null) { + new Message(sender, null).appendText( + "\n&4Could not find an unused token in 10 tries (a 1 in over 20 trillion chance)! Please take a screenshot and run the command again!") + .send(); + return; } - if (tries > 10) break; - } + table.delete(new MysqlConstraint("uuid", ConstraintOperator.EQUAL, pUUID)); + table.insert(token, pUUID, "0"); - if (token == null) { - new Message(sender, null).appendText( - "\n&4Could not find an unused token in 10 tries (a 1 in over 20 trillion chance)! Please take a screenshot and run the command again!") - .send(); - return; } - - table.delete(new MysqlConstraint("uuid", ConstraintOperator.EQUAL, pUUID)); - table.insert(token, pUUID); - new Message(sender, null).appendText("\n&cRedstoner&7 has a &2Discord&7 Now! \nClick ") .appendLinkHover("&e" + inviteLink, inviteLink, "&aClick to Join").appendText("&7 to join. \n\nTo sync you rank, copy ") .appendSuggestHover("&e" + token, token, "&aClick to Copy").appendText("&7 into &3#rank-sync&7.\n").send(); -- cgit v1.2.3