How to add a command from another plugin to my plugin?

Discussion in 'Spigot Plugin Development' started by Nomar2005, Apr 24, 2017.

  1. I have 2 questions
    How to add a command from another plugin to my plugin?

    And
    If you click on the item in your menu that it uses a bungee command

    (My english is not good)
     
  2. 1. You can simply execute the command from the other plugin when your plugin's command is run.
    2. Use PlayerInteractEvent to execute the requirement bungee command.
     
  3. Thanks, but i don't understand the first one
     
  4. It means when you do your command (like /test)

    You can execute another command (like /test1) with player.performCommand("")

    Sorry if I typed it wrong. Im on phone
     
  5. Thanks! But now where do it need to put the first one?

    Code (Text):
    package inventory;

    import org.bukkit.ChatColor;
    import org.bukkit.Effect;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;

    public class InventoryClick implements Listener {
     
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
            Inventory inv = event.getInventory();
            if(!(inv.getTitle().equals("Server Travel")))
                return;
         
                if(!(event.getWhoClicked() instanceof Player))
                return;
         
            Player player =(Player) event.getWhoClicked();  
            ItemStack item = event.getCurrentItem();
            event.setCancelled(true);
         
            if(item.getType() == Material.GOLD_BLOCK) {
                player.teleport(player.getWorld().getSpawnLocation());
                player.sendMessage(ChatColor.GREEN + "Teleported to hub!");
             
                event.setCancelled(true);
                player.closeInventory();
             
                player.getWorld().playEffect(player.getLocation(), Effect.BLAZE_SHOOT, 1);
             
    }
        }
    }
    And the teleport thing is gonna be removed and the bungee thing is gonna be added
     
  6. Put it where you would like the command to be executed (so replace the teleport with preformCommand)
     
  7. Sorry, but I meant the second and i have this now (I'm very noob)

    Code (Text):
    package inventory;

    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;

    public class InventoryClick implements Listener {
       
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
            Inventory inv = event.getInventory();
            if(!(inv.getTitle().equals("Server Travel")))
                return;
           
                if(!(event.getWhoClicked() instanceof Player))
                return;
           
            Player player =(Player) event.getWhoClicked();  
            ItemStack item = event.getCurrentItem();
            event.setCancelled(true);
       
        }
           
            @EventHandler
            public void onPlayerInteract(PlayerInteractEvent e) {
               
                Player player = e.getPlayer();
               
                {
                }

                event.setCancelled(true);
                player.closeInventory();
           
               
                {
        }
            }
    }
    I get an error with this event.setCancelled(true); the last one and where do i need to put the bungee command? I don't understand xd
     
  8. What is the error? You should run the bungee command once all conditions have been met; In this case, you can put it after event.setCancelled(true);
     
  9. the error is: Syntax error
     
  10. i tried to fix it but it messed up and now there is a red line under event
     
  11. Your curly braces are stuffed up.
     
  12. i dont understand you xD
     
  13. Code (Text):
    {
                }
    Why do you have two unneeded braces?
     
  14. If you want to let the player execute a command, maybe use player.chat("/acommand");
     
  15. Why don't use preformCommand. It's made for that?
     
  16. Also possible, i most of all use player.chat because its shorter to write :D
    You can also use Bukkit.getServer().dispatchCommand(Player, "YourCommand"):