Advertisement
YoFuzzy3

Plugin help for someone

Oct 9th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. package me.Envy.plugs;
  2.  
  3. import org.bukkit.ChatColor;
  4. import org.bukkit.command.Command;
  5. import org.bukkit.command.CommandSender;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.plugin.java.JavaPlugin;
  8.  
  9. public class basics extends JavaPlugin{
  10.  
  11.     public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
  12.         if(commandLabel.equalsIgnoreCase("fly")){
  13.             if(sender instanceof Player){ // Check if the sender is a player
  14.                 if(args.length == 1){ // Check if argument on/off is given, length 1 means given
  15.                     Player player = (Player) sender; // Cast the sender to a player
  16.                     if(args[0].equalsIgnoreCase("on")){ // Check if first argument is on
  17.                         player.setAllowFlight(true); // Allow them to fly
  18.                         player.sendMessage(ChatColor.GREEN + "Fly enabled!");
  19.                     }else if(args[0].equalsIgnoreCase("off")){ // Check if first argument is off
  20.                         player.setAllowFlight(false); // Disallow them to fly
  21.                         player.sendMessage(ChatColor.GREEN + "Fly disabled!");
  22.                     }else{ // First argument incorrect
  23.                         sender.sendMessage(ChatColor.RED + "/fly <on/off>");
  24.                     }
  25.                 }else{ // Correct length not given
  26.                     sender.sendMessage(ChatColor.RED + "/fly <on/off>");
  27.                 }
  28.             }else{
  29.                 sender.sendMessage(ChatColor.RED + "Only players can use that command."); // If not, tell them
  30.             }
  31.         }
  32.         return true;
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement