Checked if token was already made. If so,just give said token
This commit is contained in:
@@ -25,7 +25,7 @@ import com.redstoner.modules.Module;
|
|||||||
import net.nemez.chatapi.click.Message;
|
import net.nemez.chatapi.click.Message;
|
||||||
|
|
||||||
@Commands(CommandHolderType.File)
|
@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 {
|
public class Discord implements Module {
|
||||||
private MysqlTable table;
|
private MysqlTable table;
|
||||||
|
|
||||||
@@ -66,8 +66,9 @@ public class Discord implements Module {
|
|||||||
|
|
||||||
MysqlField token = new MysqlField("token", new VarChar(8), false);
|
MysqlField token = new MysqlField("token", new VarChar(8), false);
|
||||||
MysqlField uuid = new MysqlField("uuid", new VarChar(36), 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"));
|
table = database.getTable(config.get("table"));
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
@@ -86,28 +87,34 @@ public class Discord implements Module {
|
|||||||
String token = null;
|
String token = null;
|
||||||
int tries = 0;
|
int tries = 0;
|
||||||
|
|
||||||
while (token == null) {
|
Object[] existingToken = table.get("token", new MysqlConstraint("uuid", ConstraintOperator.EQUAL, pUUID));
|
||||||
token = randomToken(8);
|
|
||||||
Object[] results = table.get("token", new MysqlConstraint("token", ConstraintOperator.EQUAL, token));
|
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) {
|
if (results.length > 0) {
|
||||||
token = null;
|
token = null;
|
||||||
tries++;
|
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 ")
|
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 ")
|
.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();
|
.appendSuggestHover("&e" + token, token, "&aClick to Copy").appendText("&7 into &3#rank-sync&7.\n").send();
|
||||||
|
|||||||
Reference in New Issue
Block a user