diff options
Diffstat (limited to 'src/main/java/com/thatgravyboat/skyblockhud/commands')
3 files changed, 121 insertions, 5 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/commands/Commands.java b/src/main/java/com/thatgravyboat/skyblockhud/commands/Commands.java index ef3df57..897c088 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/commands/Commands.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/commands/Commands.java @@ -1,17 +1,27 @@ package com.thatgravyboat.skyblockhud.commands; +import com.google.common.collect.ImmutableSet; import com.thatgravyboat.skyblockhud.SkyblockHud; +import com.thatgravyboat.skyblockhud.api.LeaderboardGetter; import com.thatgravyboat.skyblockhud.config.SBHConfigEditor; import com.thatgravyboat.skyblockhud.core.GuiScreenElementWrapper; import com.thatgravyboat.skyblockhud.handlers.MapHandler; import com.thatgravyboat.skyblockhud.location.LocationHandler; -import net.minecraft.client.Minecraft; +import com.thatgravyboat.skyblockhud.playerstats.ActionBarParsing; import net.minecraft.command.ICommandSender; +import net.minecraft.entity.boss.BossStatus; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.client.ClientCommandHandler; import org.apache.commons.lang3.StringUtils; +import java.awt.*; +import java.awt.datatransfer.StringSelection; + public class Commands { + private static boolean devMode = false; + private static final SimpleCommand.ProcessCommandRunnable settingsRunnable = new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { if (args.length > 0) { @@ -22,6 +32,46 @@ public class Commands { } }; + private static final SimpleSubCommand devCommand = new SimpleSubCommand("sbhdev", ImmutableSet.of("copyBossBar", "copyScoreboard", "copyActionBar")) { + + @Override + void processSubCommand(ICommandSender sender, String subCommand, String[] args) { + StringSelection clipboard = null; + switch (subCommand) { + case "copyBossBar": + clipboard = new StringSelection(BossStatus.bossName); + break; + case "copyScoreboard": + StringBuilder builder = new StringBuilder(); + LeaderboardGetter.getCachedScores().forEach(s -> builder.append(s).append("\n")); + clipboard = new StringSelection(builder.toString()); + break; + case "copyActionBar": + clipboard = new StringSelection(ActionBarParsing.lastLowActionBar); + break; + } + if (clipboard != null) { + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(clipboard, clipboard); + sender.addChatMessage(new ChatComponentText( + "[" + + EnumChatFormatting.RED + + EnumChatFormatting.BOLD + + "SkyBlockHud" + + EnumChatFormatting.RESET + + "] : " + + EnumChatFormatting.GRAY + + "Info copied to clipboard!" + )); + } + } + + @Override + void processNoSubCommand(ICommandSender sender) { + devMode = !devMode; + sender.addChatMessage(new ChatComponentText("Dev Mode " + (devMode ? "Enabled" : "Disabled") + "!")); + } + }; + private static final SimpleCommand settingsCommand = new SimpleCommand("sbh", settingsRunnable); private static final SimpleCommand settingsCommand2 = new SimpleCommand("sbhsettings", settingsRunnable); private static final SimpleCommand settingsCommand3 = new SimpleCommand("sbhud", settingsRunnable); @@ -30,7 +80,8 @@ public class Commands { "sbhmap", new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { - if (LocationHandler.getCurrentLocation().getCategory().getMap() != null) SkyblockHud.screenToOpen = new MapHandler.MapScreen(); + if (LocationHandler.getCurrentLocation().getCategory().getMap() != null && SkyblockHud.hasSkyblockScoreboard()) + SkyblockHud.screenToOpen = new MapHandler.MapScreen(); } } ); @@ -40,5 +91,6 @@ public class Commands { ClientCommandHandler.instance.registerCommand(settingsCommand2); ClientCommandHandler.instance.registerCommand(settingsCommand3); ClientCommandHandler.instance.registerCommand(mapCommand); + ClientCommandHandler.instance.registerCommand(devCommand); } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/commands/SimpleCommand.java b/src/main/java/com/thatgravyboat/skyblockhud/commands/SimpleCommand.java index db23b8e..d5d3c57 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/commands/SimpleCommand.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/commands/SimpleCommand.java @@ -1,11 +1,11 @@ package com.thatgravyboat.skyblockhud.commands; -import java.util.List; import net.minecraft.command.CommandBase; -import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.util.BlockPos; +import java.util.List; + /** @author Moulberry **/ @@ -48,10 +48,12 @@ public class SimpleCommand extends CommandBase { return "/" + commandName; } - public void processCommand(ICommandSender sender, String[] args) throws CommandException { + @Override + public void processCommand(ICommandSender sender, String[] args) { runnable.processCommand(sender, args); } + @Override public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) { if (tabRunnable != null) return tabRunnable.tabComplete(sender, args, pos); return null; diff --git a/src/main/java/com/thatgravyboat/skyblockhud/commands/SimpleSubCommand.java b/src/main/java/com/thatgravyboat/skyblockhud/commands/SimpleSubCommand.java new file mode 100644 index 0000000..7169c6d --- /dev/null +++ b/src/main/java/com/thatgravyboat/skyblockhud/commands/SimpleSubCommand.java @@ -0,0 +1,62 @@ +package com.thatgravyboat.skyblockhud.commands; + +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; +import net.minecraft.util.BlockPos; +import org.apache.commons.lang3.ArrayUtils; + +import java.util.List; +import java.util.Set; + +public abstract class SimpleSubCommand extends CommandBase { + + private final String commandName; + private final Set<String> subCommands; + + public SimpleSubCommand(String commandName, Set<String> subCommands) { + this.commandName = commandName; + this.subCommands = subCommands; + } + + @Override + public String getCommandName() { + return commandName; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "/"+commandName; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + if (args.length == 0) { + processNoSubCommand(sender); + return; + } + if (subCommands.contains(args[0])){ + processSubCommand(sender, args[0], ArrayUtils.remove(args, 0)); + return; + } + processBadSubCommand(sender, args[0]); + } + + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return true; + } + + @Override + public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) { + if (args.length == 1){ + return getListOfStringsMatchingLastWord(args,subCommands); + } + return null; + } + + abstract void processSubCommand(ICommandSender sender, String subCommand, String[] args); + + abstract void processNoSubCommand(ICommandSender sender); + + public void processBadSubCommand(ICommandSender sender, String subCommand){} +} |