diff --git a/gradle.properties b/gradle.properties index 6a7d1ae..259adbe 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,6 +10,6 @@ loader_version=0.12.8 fabric_version=0.43.1+1.18 # Mod Properties -mod_version=1.3.5 +mod_version=1.4.0 maven_group=br.com.brforgers.mods archives_base_name=disfabric diff --git a/src/main/java/br/com/brforgers/mods/disfabric/listeners/DiscordEventListener.java b/src/main/java/br/com/brforgers/mods/disfabric/listeners/DiscordEventListener.java index b860c20..99f1bee 100644 --- a/src/main/java/br/com/brforgers/mods/disfabric/listeners/DiscordEventListener.java +++ b/src/main/java/br/com/brforgers/mods/disfabric/listeners/DiscordEventListener.java @@ -6,6 +6,9 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.scoreboard.ScoreboardObjective; +import net.minecraft.scoreboard.ScoreboardPlayerScore; +import net.minecraft.scoreboard.ServerScoreboard; import net.minecraft.server.MinecraftServer; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; @@ -62,9 +65,31 @@ public void onMessageReceived(@NotNull MessageReceivedEvent e) { !online: list server online players !tps: shows loaded dimensions tps´s !console : executes commands in the server console (admins only) + !scoreboard : displays the scoreboard for an objective ```"""; e.getChannel().sendMessage(help).queue(); + } else if (e.getMessage().getContentRaw().startsWith("!scoreboard")) { + String objName = e.getMessage().getContentRaw().replace("!scoreboard ", ""); + ServerScoreboard scoreboard = server.getScoreboard(); + ScoreboardObjective objective = scoreboard.getObjective(objName); + if (objective == null) { + e.getChannel().sendMessage("Scoreboard not found.").queue(); + return; + } + + String message = "```\n=============== " + objName + " ===============\n"; + + for (ScoreboardPlayerScore sps : scoreboard.getAllPlayerScores(objective)) { + message += ( + sps.getPlayerName() + + ": " + + sps.getScore() + + "\n" + ); + } + message += "\n```"; + e.getChannel().sendMessage(message).queue(); } else { LiteralText discord = new LiteralText(DisFabric.config.texts.coloredText.replace("%discordname%", Objects.requireNonNull(e.getMember()).getEffectiveName()).replace("%message%",e.getMessage().getContentDisplay().replace("§", DisFabric.config.texts.removeVanillaFormattingFromDiscord ? "&" : "§").replace("\n", DisFabric.config.texts.removeLineBreakFromDiscord ? " " : "\n") + ((e.getMessage().getAttachments().size() > 0) ? " " : "") + ((e.getMessage().getEmbeds().size() > 0) ? " " : ""))); discord.setStyle(discord.getStyle().withColor(TextColor.fromRgb(Objects.requireNonNull(e.getMember()).getColorRaw())));