mirror of
https://github.com/JonasunderscoreJones/McWebserver.git
synced 2025-10-23 03:19:19 +02:00
Fixed token not showing when generated from server
Fixed an issue where the server token was never shown when the server
This commit is contained in:
parent
97e695536c
commit
5ae0fc1096
1 changed files with 27 additions and 15 deletions
|
@ -30,28 +30,40 @@ public class McWebCommand {
|
||||||
.executes(context -> {
|
.executes(context -> {
|
||||||
String name = StringArgumentType.getString(context, "Name");
|
String name = StringArgumentType.getString(context, "Name");
|
||||||
String expires = StringArgumentType.getString(context, "Expiration Time (example: 1y3d4h -> 1 Year, 3 Days, 4 Hours)");
|
String expires = StringArgumentType.getString(context, "Expiration Time (example: 1y3d4h -> 1 Year, 3 Days, 4 Hours)");
|
||||||
|
if (context.getSource().isExecutedByPlayer()) {
|
||||||
String result = registerToken(name, expires);
|
String result = registerToken(name, expires);
|
||||||
if (result.equals("exists")) {
|
if (result.equals("exists")) {
|
||||||
context.getSource().sendFeedback(() -> Text.of("A token with that name already exists"), false);
|
context.getSource().sendFeedback(() -> Text.of("A token with that name already exists"), false);
|
||||||
return 0;
|
return 0;
|
||||||
} else if (result.equals("failed")) {
|
} else if (result.equals("failed")) {
|
||||||
context.getSource().sendFeedback(() -> Text.of("Failed to create token (Unknown Error)"), false);
|
context.getSource().sendFeedback(() -> Text.of("Failed to create token (Unknown Error)"), false);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
context.getSource().sendFeedback(() -> Text.of("Token Created!\nExpires " + convertToHumanReadable(convertExpirationDate(expires))), true);
|
context.getSource().sendFeedback(() -> Text.of("Token Created! - Expires " + convertToHumanReadable(convertExpirationDate(expires))), true);
|
||||||
if (MC_SERVER != null) {
|
if (MC_SERVER != null) {
|
||||||
// get the player name
|
if (context.getSource().isExecutedByPlayer()) {
|
||||||
String playerName = Objects.requireNonNull(context.getSource().getPlayer()).getName().getString();
|
// get the player name
|
||||||
MC_SERVER.getCommandManager().executeWithPrefix(MC_SERVER.getCommandSource(), "tellraw " + playerName + " [\"\",\"Token (will only show once): \",\"\\n\",\"[\",{\"text\":\"" + result + "\",\"color\":\"green\",\"clickEvent\":{\"action\":\"copy_to_clipboard\",\"value\":\"\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"Click to Copy to Clipboard\"]}},\"]\"]");
|
String playerName = Objects.requireNonNull(context.getSource().getPlayer()).getName().getString();
|
||||||
return 1;
|
MC_SERVER.getCommandManager().executeWithPrefix(MC_SERVER.getCommandSource(), "tellraw " + playerName + " [\"\",\"Token (will only show once): \",\"\\n\",\"[\",{\"text\":\"" + result + "\",\"color\":\"green\",\"clickEvent\":{\"action\":\"copy_to_clipboard\",\"value\":\"\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"Click to Copy to Clipboard\"]}},\"]\"]");
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
context.getSource().sendFeedback(() -> Text.of("Failed to create token (Unknown Error)"), false);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
context.getSource().sendFeedback(() -> Text.of("Failed to create token (Unknown Error)"), false);
|
} else {
|
||||||
|
context.getSource().sendFeedback(() -> Text.of("ERROR: Due to Security concerns it is not possible to generate tokens from the server console as they are saved in server logs. Tokens must be created by a player! (more info at: https://wiki.jonasjones.dev/McWebserver/Tokens)"), false);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}))))
|
}))))
|
||||||
.then(literal("list")
|
.then(literal("list")
|
||||||
.executes(context -> {
|
.executes(context -> {
|
||||||
context.getSource().sendFeedback(() -> Text.of(listTokens()), false);
|
try {
|
||||||
|
context.getSource().sendFeedback(() -> Text.of(listTokens()), false);
|
||||||
|
return 1;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}))
|
}))
|
||||||
.then(literal("delete")
|
.then(literal("delete")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue