Skip to content

Commit

Permalink
prefix cross server
Browse files Browse the repository at this point in the history
  • Loading branch information
Kahzerx committed May 21, 2023
1 parent 34aeec2 commit bc91bec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ public static void sendChatMessage(ServerPlayerEntity player, String msg, String
}
WebhookMessageBuilder builder = new WebhookMessageBuilder();
String playerName = player.getName().getString();
builder.setUsername(String.format("[%s] %s", prefix, playerName));
if (prefix.equals("")) {
builder.setUsername(String.format("%s", playerName));
} else {
builder.setUsername(String.format("[%s] %s", prefix, playerName));
}
String uuid = player.getUuid().toString();
builder.setAvatarUrl(String.format("https://crafatar.com/avatars/%s?overlay", uuid));
builder.setContent(msg);
Expand All @@ -135,7 +139,11 @@ public static void sendSysMessage(String msg, String prefix){
return;
}
WebhookMessageBuilder builder = new WebhookMessageBuilder();
builder.setUsername(String.format("[%s] System :D", prefix));
if (prefix.equals("")) {
builder.setUsername("System :D");
} else {
builder.setUsername(String.format("[%s] System :D", prefix));
}
builder.setAvatarUrl("https://crafatar.com/avatars/749126bc-4467-41b4-be12-d24f4496cfad?overlay");
builder.setContent(msg);
webhookC.send(builder.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public void onServerRun(MinecraftServer minecraftServer) {
if (!extensionSettings().isEnabled()) {
return;
}
if (extensionSettings().getPrefix().equals("")) {
extensionSettings().setCrossServerChat(false);
ExtensionManager.saveSettings();
}
DiscordListener.start(minecraftServer, extensionSettings().getToken(), String.valueOf(extensionSettings().getChatChannelID()), this);
}

Expand Down Expand Up @@ -183,6 +187,10 @@ public void settingsCommand(LiteralArgumentBuilder<ServerCommandSource> builder)
then(literal("crossServerChat").
then(argument("enabled", BoolArgumentType.bool()).
executes(context -> {
if (extensionSettings().getPrefix().equals("")) {
context.getSource().sendFeedback(Text.literal("You need to set a prefix!"), false);
return 1;
}
extensionSettings().setCrossServerChat(BoolArgumentType.getBool(context, "enabled"));
context.getSource().sendFeedback(Text.literal("[CrossServerChat] > " + extensionSettings().isCrossServerChat() + "."), false);
ExtensionManager.saveSettings();
Expand Down

0 comments on commit bc91bec

Please sign in to comment.