VanillaModuleCommand.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package me.km.api;
  2. import java.util.List;
  3. import me.km.KajetansMod;
  4. import me.km.permissions.Permissions;
  5. import net.minecraft.command.CommandException;
  6. import net.minecraft.command.ICommand;
  7. import net.minecraft.command.ICommandSender;
  8. import net.minecraft.server.MinecraftServer;
  9. import net.minecraft.util.math.BlockPos;
  10. import net.minecraft.util.text.TextComponentTranslation;
  11. import net.minecraft.util.text.TextFormatting;
  12. public class VanillaModuleCommand extends ModuleCommand
  13. {
  14. private final ICommand vanillaCommand;
  15. public VanillaModuleCommand(ICommand command, Module m, Permissions perm)
  16. {
  17. super(command.getName(), m);
  18. super.setDescription("A vanilla command");
  19. TextComponentTranslation text = new TextComponentTranslation(command.getUsage(null));
  20. super.setUsage(text.getFormattedText());
  21. super.setPermission(perm);
  22. vanillaCommand = command;
  23. }
  24. @Override
  25. public boolean execute(ICommandSender cs, String[] arg)
  26. {
  27. try
  28. {
  29. vanillaCommand.execute(KajetansMod.server, cs, arg);
  30. }
  31. catch (CommandException ex)
  32. {
  33. TextComponentTranslation text = new TextComponentTranslation(ex.getMessage(), ex.getErrorObjects());
  34. text.getStyle().setColor(TextFormatting.RED);
  35. cs.sendMessage(text);
  36. }
  37. return true;
  38. }
  39. @Override
  40. public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos targetPos)
  41. {
  42. return vanillaCommand.getTabCompletions(server, sender, args, targetPos);
  43. }
  44. @Override
  45. public List<String> getAliases()
  46. {
  47. return vanillaCommand.getAliases();
  48. }
  49. }