Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add !scoreboard command #50

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,9 +65,31 @@ public void onMessageReceived(@NotNull MessageReceivedEvent e) {
!online: list server online players
!tps: shows loaded dimensions tps´s
!console <command>: executes commands in the server console (admins only)
!scoreboard <objective>: 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) ? " <att>" : "") + ((e.getMessage().getEmbeds().size() > 0) ? " <embed>" : "")));
discord.setStyle(discord.getStyle().withColor(TextColor.fromRgb(Objects.requireNonNull(e.getMember()).getColorRaw())));
Expand Down