diff options
Diffstat (limited to 'src/main/java/com/example/CrashCommand.java')
-rw-r--r-- | src/main/java/com/example/CrashCommand.java | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/src/main/java/com/example/CrashCommand.java b/src/main/java/com/example/CrashCommand.java index 516708d..4fb9cbb 100644 --- a/src/main/java/com/example/CrashCommand.java +++ b/src/main/java/com/example/CrashCommand.java @@ -1,13 +1,26 @@ package com.example; +import net.minecraft.client.Minecraft; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; +import net.minecraft.scoreboard.ScoreObjective; +import net.minecraft.scoreboard.ScorePlayerTeam; +import net.minecraft.scoreboard.Scoreboard; +import net.minecraft.util.BlockPos; +import net.minecraft.util.ChatComponentText; +import org.apache.logging.log4j.LogManager; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; +import java.util.stream.Collectors; public class CrashCommand extends CommandBase { @Override public String getCommandName() { - return "crashme"; + return "randomutils"; } @Override @@ -17,7 +30,50 @@ public class CrashCommand extends CommandBase { @Override public void processCommand(ICommandSender sender, String[] args) throws CommandException { - ExampleMod.screenToOpenNextTick = new MyGuiScreen(); + if (args.length == 0) { + sender.addChatMessage(new ChatComponentText("§cPlease use an argument")); + } else if (args[0].equals("weather")) { + sender.addChatMessage(new ChatComponentText("§bCurrent Weather: " + + (Minecraft.getMinecraft().theWorld.isRaining() ? "§7Rainy!" : "§eSunny!"))); + } else if (args[0].equals("coinflip")) { + sender.addChatMessage(new ChatComponentText("§bCoinflip: " + + (ThreadLocalRandom.current().nextBoolean() ? "§eHeads" : "§eTails"))); + } else if (args[0].equals("scoreboard")) { + final int SIDEBAR_SLOT = 1; + + Scoreboard scoreboard = Minecraft.getMinecraft().theWorld.getScoreboard(); + ScoreObjective objective = scoreboard.getObjectiveInDisplaySlot(SIDEBAR_SLOT); + List<String> scoreList = scoreboard.getSortedScores(objective) + .stream() + .limit(15) + .map(score -> + ScorePlayerTeam.formatPlayerName( + scoreboard.getPlayersTeam(score.getPlayerName()), + score.getPlayerName())) + .map(text -> { + StringBuilder sb = new StringBuilder(); + for (char c : text.toCharArray()) { + if (Minecraft.getMinecraft().fontRendererObj.getCharWidth(c) > 0 || c == '§') + sb.append(c); + } + return sb.toString(); + }) + .collect(Collectors.toList()); + Collections.reverse(scoreList); + for (String s : scoreList) { + LogManager.getLogger("Scoreboard").info(s); + sender.addChatMessage(new ChatComponentText(s)); + } + } else { + sender.addChatMessage(new ChatComponentText("§cUnknown subcommand")); + } + } + + @Override + public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) { + if (args.length == 1) + return getListOfStringsMatchingLastWord(args, "weather", "coinflip", "scoreboard"); + return Arrays.asList(); } @Override |