Advertisement
Guest User

Untitled

a guest
May 25th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.90 KB | None | 0 0
  1. package com.ericlam.mc.bungee.hnmc.commands;
  2.  
  3. import com.ericlam.mc.bungee.hnmc.exception.ArgTooShortException;
  4. import com.ericlam.mc.bungee.hnmc.exception.CommandNotFoundException;
  5. import com.ericlam.mc.bungee.hnmc.exception.NoPermissionException;
  6. import com.ericlam.mc.bungee.hnmc.main.HyperNiteMC;
  7. import net.md_5.bungee.api.CommandSender;
  8. import net.md_5.bungee.api.plugin.Command;
  9. import net.md_5.bungee.api.plugin.Plugin;
  10. import net.md_5.bungee.api.plugin.TabExecutor;
  11.  
  12. /**
  13.  * 快速預設指令的類。
  14.  *
  15.  * 使用後無需處理指令及自動完成列,只需處理 Exception 即可。
  16.  *
  17.  * @see CommandHandle
  18.  */
  19. public abstract class HNMCCommand extends Command implements TabExecutor {
  20.  
  21.     private Plugin plugin;
  22.     private CommandHandle handle;
  23.  
  24.     /**
  25.      *
  26.      * @param name 指令名稱
  27.      * @param plugin 插件
  28.      */
  29.     public HNMCCommand(String name, Plugin plugin) {
  30.         super(name);
  31.         this.plugin = plugin;
  32.         this.handle = HyperNiteMC.getAPI().getCommandHandler();
  33.     }
  34.  
  35.     /**
  36.      *
  37.      * @param plugin 插件
  38.      * @param name 指令名稱
  39.      * @param permission 權限
  40.      * @param aliases 縮寫
  41.      */
  42.     public HNMCCommand(Plugin plugin, String name, String permission, String... aliases) {
  43.         super(name, permission, aliases);
  44.         this.plugin = plugin;
  45.         this.handle = HyperNiteMC.getAPI().getCommandHandler();
  46.     }
  47.  
  48.     /**
  49.      * 已自動處理
  50.      * @param commandSender 指令發送者
  51.      * @param strings 指令參數
  52.      */
  53.     @Override
  54.     public void execute(CommandSender commandSender, String[] strings) {
  55.         try {
  56.             handle.handle(commandSender, strings, this, plugin);
  57.         } catch (ArgTooShortException e) {
  58.             this.onArgTooShort(commandSender, e);
  59.         } catch (CommandNotFoundException e) {
  60.             this.onCommandNotFound(commandSender, e);
  61.         } catch (NoPermissionException e) {
  62.             this.onNoPermission(commandSender, e);
  63.         }
  64.     }
  65.  
  66.     /**
  67.      * 已自動處理
  68.      * @param commandSender 指令發送者
  69.      * @param strings 指令參數
  70.      * @return Tab 列
  71.      */
  72.     @Override
  73.     public Iterable<String> onTabComplete(CommandSender commandSender, String[] strings) {
  74.         return handle.tapComplete(commandSender, this, strings, plugin);
  75.     }
  76.  
  77.     /**
  78.      *
  79.      * @param sender 指令發送者
  80.      * @param e 參數過短時
  81.      */
  82.     public abstract void onArgTooShort(CommandSender sender, ArgTooShortException e);
  83.  
  84.     /**
  85.      *
  86.      * @param sender 指令發送者
  87.      * @param e 找不到指令時
  88.      */
  89.     public abstract void onCommandNotFound(CommandSender sender, CommandNotFoundException e);
  90.  
  91.     /**
  92.      *
  93.      * @param sender 指令發送者
  94.      * @param e 沒有權限時
  95.      */
  96.     public abstract void onNoPermission(CommandSender sender, NoPermissionException e);
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement