Archived
0

Checked if token was already made. If so,just give said token

This commit is contained in:
Minenash
2019-01-27 18:15:14 -05:00
parent 5f07772074
commit 5462a5fd44

View File

@@ -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 (results.length > 0) {
token = null;
tries++;
}
if (tries > 10) break;
}
if (tries > 10) break;
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, "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();