turt2live

Untitled

Dec 21st, 2012
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. import org.bukkit.command.Command;
  2. import org.bukkit.command.CommandSender;
  3. import org.bukkit.plugin.java.JavaPlugin;
  4.  
  5. import com.turt2live.xmail.XMail;
  6. import com.turt2live.xmail.api.XMailAPI;
  7. import com.turt2live.xmail.commands.ArgumentHandler;
  8.  
  9. public class SampleCustomArgument extends JavaPlugin {
  10.  
  11.     @Override
  12.     public void onEnable(){
  13.  
  14.         // Insert xMail-is-actually-here check
  15.  
  16.         // Get the xMail plugin, you can do this in 2 ways...
  17.         // Way 1:
  18.         XMail xmail = XMail.getInstance();
  19.  
  20.         // Way 2:
  21.         xmail = new XMailAPI().getPlugin();
  22.  
  23.         // Create your argument handler object
  24.         MyArgumentHandler handler = new MyArgumentHandler();
  25.  
  26.         // Tell xMail to use that handler for that argument
  27.         xmail.getCommandHandler().registerArgument("myargument", handler);
  28.         xmail.getCommandHandler().registerArgument("myargument2", handler);
  29.         // You can use the same handler for 2 arguments!
  30.     }
  31.  
  32.     // Usually this would go in another file...
  33.     public static class MyArgumentHandler implements ArgumentHandler {
  34.  
  35.         @Override
  36.         public void runArgument(CommandSender sender, Command command, String[] args, String passedArgument){
  37.             // sender = Who sent the command
  38.             // command = xMail
  39.             // args = Arguments after your argument. So "/xmail 1 2" would have the args "2" (if "1" was our defined argument)
  40.             // passedArgument = "1" in the previous listing
  41.  
  42.             // Here you can run whatever code you need. Note that xMail's command handler does not
  43.             // work like Bukkit's. You will need to do usage handling on your own (sorry!)
  44.         }
  45.  
  46.     }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment