Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.golde.bukkit.tab; //name if your plugin (like a UUID but with words and dots)
- import java.util.ArrayList;
- import java.util.List;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.entity.*;
- //Imports everything needed
- public class MyPlugin extends JavaPlugin { //creates your plugin and tells the server to register your plugin as a bukkit plugin
- //when the server enables the plugin print a message in the console saying that it has been enabled
- public void onEnable() {
- getCommand("tab").setExecutor(this); //tells bukkit to register a command
- getLogger().info("TAB plugin is starting."); //prints message
- }
- //when the server disables the plugin print a message in the console saying that it has been disabled
- public void onDisable() {
- getLogger().info("TAB plugin in stopping."); //prints message
- }
- //
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- if(cmd.getName().equalsIgnoreCase("tab")){ // your command name
- if (! (sender instanceof Player)) //this makes sure its a player executing the command
- return true;
- //argument checker and definer
- //also prints the correct syntax if the user gets it wrong
- if(args.length < 2 ){
- sender.sendMessage("Incorrect Syntax!!"); //prints "incorrect syntax"
- sender.sendMessage("/tab <1-2> <a-b>"); // prints the correct syntax
- return true;
- }
- //Store which argument goes with which possibility
- String S12 = args[0]; //first argument
- String Sab = args[1]; //second argument
- if(S12.equalsIgnoreCase("1")){ //Retrieving and plugging in the arguments that are stored and running different commands depending on which arguments are were
- if(Sab.equalsIgnoreCase("A")) //Retrieving and plugging in the arguments that are stored and running different commands depending on which arguments are were
- sender.sendMessage("1 a"); //sends a message to the player who send the command depending what the arguments are
- else
- sender.sendMessage("1 b"); //sends a message to the player who send the command depending what the arguments are
- }
- else
- {
- if(Sab.equalsIgnoreCase("a")) //Retrieving and plugging in the arguments that are stored and running different commands depending on which arguments are were
- sender.sendMessage("2 a"); //sends a message to the player who send the command depending what the arguments are
- else
- sender.sendMessage("2 b"); //sends a message to the player who send the command depending what the arguments are
- }
- }
- return false; //this is a little confusing but just put it there
- //it just returns false if nothing matches the arguments needed
- }
- //list all possible tab arguments
- public List<String> onTabComplete(CommandSender sender, //registers the auto tab completer
- Command command,
- String alias,
- String[] args){
- if(command.getName().equalsIgnoreCase("tab")){ //your command name
- List<String> l = new ArrayList<String>(); //makes a ArrayList
- //define the possible possibility's for argument 1
- if (args.length==1){
- l.add("1"); //Possibility #1
- l.add("2"); //Possibility #2
- }
- //define the possible possibility's for argument 2
- else if (args.length==2){
- l.add("a"); //Possibility #1
- l.add("b"); //Possibility #2
- }
- return l; //returns the possibility's to the client
- }
- return null; //this is a little confusing but just put it there
- //it just returns NULL if absolutely nothing has happened
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement