Solved Command isn't working....

Discussion in 'Plugin Development' started by Azrex, May 14, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Azrex

    So if u look at the bottom of the code, the /go command does not work for some reason.
    Here is the code:
    Code:
    package me.cratekey.inventory;
    
    import java.util.Random;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener{
    
       
       
        @Override
        public void onDisable() {
           
        }
    
        @Override
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
        }
       
       
        public void openGUI(Player player) {
           
            Inventory inv = Bukkit.createInventory(null, 27, "Crate Keys");
           
           
               
           
           
           
        player.openInventory(inv);
       
        Bukkit.getServer().getScheduler().runTaskTimer(this, new Runnable() {
       
       
            public void run() {
           
            Random r = new Random();
            for (int i = 0; i < inv.getSize(); i++) {
            inv.setItem(i, new ItemStack(Material.STAINED_GLASS_PANE, 1, (byte) r.nextInt(16)));
           
            
            }
           
            }
           
       
       
            }, 0L, 7L);
       
       
         
        }
       
        @EventHandler
        public void PlayerInteract(PlayerInteractEvent event) {
           
            Action a = event.getAction();
            ItemStack is = event.getItem();
           
            if(a == Action.PHYSICAL || a == null || is.getType() == Material.AIR)
            return;   
           
            if(is.getType() == Material.COMPASS) {
               
               
               
                openGUI(event.getPlayer());
                event.getPlayer().sendMessage(ChatColor.GREEN + "Crate Key Box Opened!");
           
               
               
                   
                    String p = event.getPlayer().getDisplayName();
                    Bukkit.getServer().broadcastMessage(ChatColor.GREEN + "[BroadCast] " + ChatColor.GOLD + p +  ChatColor.BLUE + " Is Opening A Mystery Box!");
            }
               
               
            }
               
               
           
       
       
       
    
    
               
           
       
    
    public boolean onCommand2(CommandSender sender, Command cmd, String label, String[] args) {
           
            if (cmd.getName().equalsIgnoreCase("go") && sender instanceof Player) {
               
                Player player = (Player) sender;
               
                player.sendMessage("Hello, " + player.getName() + "!");
               
                return true;
               
            }   
                   
            return false;
        }
               
               
           
    }
    
    
       
    
    
     
  2. Offline

    caderape

    @Azrex onCommand2

    Remove the 2 and implement CommandExecutor
     
  3. Offline

    Zombie_Striker

    No need for Command Executor @caderape , Just make sure that there is an @override ontop of onCommand.​
     
    mine-care likes this.
  4. Offline

    Azrex

    Worked Thank You! :D
     
Thread Status:
Not open for further replies.

Share This Page