gamingod

Bukkit tutorial commands | main class

Jan 12th, 2014
81
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.gamingod.BukkitCoding;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.command.Command;
  6. import org.bukkit.command.CommandSender;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.event.Listener;
  9. import org.bukkit.plugin.java.JavaPlugin;
  10.  
  11. public class Main extends JavaPlugin implements Listener {
  12.  
  13.     @Override
  14.     public void onEnable() {
  15.         Bukkit.getServer().getPluginManager().registerEvents(this, this);
  16.     }
  17.    
  18.     //The Command
  19.     public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
  20.        
  21.         //Checking if they are a player
  22.         if (!(sender instanceof Player)) {
  23.             sender.sendMessage(ChatColor.RED + "Only players can do this!");
  24.             return true;
  25.         }
  26.        
  27.         //If the command is /tutorial
  28.         if (cmd.getName().equalsIgnoreCase("tutorial")) {
  29.             Player p = (Player) sender;
  30.             p.sendMessage(ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "IT WORKS!");
  31.             p.setDisplayName(ChatColor.LIGHT_PURPLE + p.getName() + ChatColor.RESET);
  32.             p.setPlayerListName(ChatColor.LIGHT_PURPLE + p.getName() + ChatColor.RESET);
  33.         }
  34.        
  35.         //If the command is /commandtwo
  36.         if (cmd.getName().equalsIgnoreCase("commandtwo")) {
  37.             Player p = (Player) sender;
  38.            
  39.             //If there are no args
  40.             if (args.length == 0) {
  41.                 p.sendMessage(ChatColor.RED + "Usage: /commandtwo <true|false>");
  42.                
  43.                 //If there is one argument
  44.             } else if (args.length == 1) {
  45.                
  46.                 //If the command is /commandtwo true
  47.                 if (args[0].equalsIgnoreCase("true")) {
  48.                     p.sendMessage("commandtwo is now a true");
  49.                    
  50.                     //If the command is /comandtwo false
  51.                 } else if (args[0].equalsIgnoreCase("false")) {
  52.                     p.sendMessage("commandtwo is now false");
  53.                 } else {
  54.                    
  55.                     //If the command is /commandtwo <anything>
  56.                     p.sendMessage(ChatColor.RED + "Usage: /commandtwo <true|false>");
  57.                 }
  58.             } else {
  59.                
  60.                 //Two or more arguments
  61.                 p.sendMessage(ChatColor.RED + "Usage: /commandtwo <true|false>");
  62.             }
  63.         }
  64.        
  65.         return true;
  66.     }
  67.    
  68. }
RAW Paste Data