TNT_Block

HelpCommand

Sep 25th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. package de.cryptonicdev.cryptonic.commands.impl;
  2.  
  3. import java.util.Iterator;
  4.  
  5. import de.cryptonicdev.cryptonic.commands.Command;
  6. import de.cryptonicdev.cryptonic.main.Cryptonic;
  7. import de.cryptonicdev.cryptonic.utils.CryptoUtils;
  8. import net.minecraft.init.Blocks;
  9. import net.minecraft.item.ItemStack;
  10. import net.minecraft.util.ChatComponentText;
  11. import net.minecraft.util.ChatStyle;
  12. import net.minecraft.util.EnumChatFormatting;
  13.  
  14. public class HelpCmd extends Command {
  15.  
  16. private static String[] syntax = { "[<Seite>]", "[<Befehl>]" };
  17.  
  18. public HelpCmd() {
  19. super("Help", "Zeigt die Befehlsliste oder die Hilfe für einen Befehl an.", syntax);
  20. }
  21.  
  22. @Override
  23. public void onCommand(String input, String[] args) throws Exception {
  24. if (args.length == 0) {
  25. onCommand("#help 1", new String[] { "1" });
  26. return;
  27. }
  28.  
  29. int countCommands = getCommandManager().getCommands().size();
  30.  
  31. int pages = (int) Math.ceil(countCommands / 8D);
  32. if (CryptoUtils.isInteger(args[0])) {
  33. int page = Integer.valueOf(args[0]);
  34. if (page > pages || page < 1)
  35. getChat().syntaxError("§cUngültige Seite: " + page);
  36. getChat().sendMessage("§2Verfügbare Befehle: " + countCommands);
  37. Iterator<Command> itr = getCommandManager().getCommands().iterator();
  38. for (int i = 0; itr.hasNext(); i++) {
  39. Command cmd = itr.next();
  40. if (i >= (page - 1) * 8 && i < (page - 1) * 8 + 8)
  41. getChat().sendMessage("§b#" + cmd.getCommand());
  42. }
  43. getChat().sendMessage("§2Befehlsliste (Seite " + page + "/" + pages + "):");
  44. } else {
  45. Command cmd = getCommandManager().getCommandByName(args[0]);
  46. if (cmd != null) {
  47. getChat().sendMessage("§3Verfügbare Hilfe für #" + args[0] + ":");
  48. getChat().component(new ChatComponentText(cmd.getDescription())
  49. .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.GREEN)));
  50. for (String syntax : cmd.getSyntax()) {
  51. getChat().component(new ChatComponentText("§bSyntax: ").appendSibling(new ChatComponentText(syntax)
  52. .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.LIGHT_PURPLE))));
  53. }
  54. } else
  55. getChat().sendMessage("§cDer Befehl \"" + args[0] + "\" konnte nicht gefunden werden.");
  56. }
  57. }
  58.  
  59. }
Add Comment
Please, Sign In to add comment