Dispatch Command Multiple Arguments

Discussion in 'Plugin Development' started by AppleBabies, Nov 24, 2015.

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

    AppleBabies

    Title says it all. I need multiple args, like:
    Code:
    Bukkit.getServer().dispatchCommand(p, "/server creative");
    Multiple arguments don't work. I get unknown command when I do it. What can I do for multiple args?
     
  2. Offline

    pie_flavor

    @AppleBabies This is just a shot in the dark here, but maybe the method that specifically exists to run commands doesn't need a slash to prefix it seeing as the slash's only purpose is to define it as a command. Have you ever tried "server creative"
     
  3. Offline

    AppleBabies

    @pie_flavor Doesn't matter. Still gives the same error each time.
     
  4. Offline

    pie_flavor

    @AppleBabies Well, what's the error? A stack trace would be useful.
     
  5. Offline

    AppleBabies

    @pie_flavor No, not a stack trace, just a simple unknown command in Minecraft because of the arguments.
     
  6. Offline

    pie_flavor

    @AppleBabies And you are absolutely sure that you have a plugin on this server that contains the /server command.
     
  7. Offline

    AppleBabies

    @pie_flavor Wait.../server is a command, but trying to execute it doesn't work I guess...
     
  8. Offline

    pie_flavor

    @AppleBabies Try going in game and doing the same command and seeing if that works. Because I'm pretty sure that dispatchCommand is how every command is run naturally.
     
  9. Offline

    AppleBabies

    @pie_flavor Ah, I see. The command belongs to BungeeCord...
     
  10. Offline

    pie_flavor

    @AppleBabies well, yeah. did you think it was a vanilla command?
     
  11. Offline

    AppleBabies

    @pie_flavor I was under the impression it was a Bukkit command at first...stupid me. Could I use the Bungee API to run the command?
     
  12. Offline

    pie_flavor

    @AppleBabies Now I'm confused. Unless Bungee is filtering every PlayerChatEvent, of course they have it registered through Bukkit. Why wouldn't they?
    Or do you mean that you don't have Bungee installed?
    If you do have it installed, why even run the command? Never use Bungee myself, but it seems like it would have to have a method in the API that actually sends them to the server.
     
  13. Offline

    xXMaTTHDXx

  14. Offline

    Xerox262

  15. Offline

    AppleBabies

  16. Offline

    Xerox262

  17. Offline

    AppleBabies

    @Xerox262 Okay...well, now it runs fine, no errors, but doesn't connect.
    Code:
     @EventHandler
            public void onInventoryClick(InventoryClickEvent e) {
                Player p = (Player) e.getWhoClicked();
               
                    if (!e.getInventory().getName().equalsIgnoreCase(inv.getName())) return;
                    if (e.getCurrentItem().getItemMeta() == null) return;
                    if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Creative")) {
                            e.setCancelled(true);
                            p.playSound(p.getLocation(), Sound.NOTE_PIANO, 1, 10);
                            p.playSound(p.getLocation(), Sound.NOTE_BASS_GUITAR, 1, 10);
                           
                            out.writeUTF("ConnectOther");
                            out.writeUTF(p.getName());
                            out.writeUTF("creative");
                     
                            e.getWhoClicked().closeInventory();
                           
                    }
                    if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Minigames")) {
                            e.setCancelled(true);
                            p.playSound(p.getLocation(), Sound.NOTE_PIANO, 1, 10);
                            p.playSound(p.getLocation(), Sound.NOTE_BASS_GUITAR, 1, 10);
                           
                            out.writeUTF("ConnectOther");
                            out.writeUTF(p.getName());
                            out.writeUTF("minigames");
                           
                            e.getWhoClicked().closeInventory();
                    }
                  
                }
    
            public void onPluginMessageReceived(String arg0, Player arg1,
                    byte[] arg2) {
               
               
            }
             }
     
  18. Offline

    Xerox262

    You never actually send it
    Player#sendPluginMessage(Plugin, "BungeeCord", out.toByteArray());

    Also, storing the ByteArrayDataOutput might cause errors for other connects, if it's just going to write the utf onto the current one. Creating a new object when it runs is probably the better option. Also, as I said you can use Connect rather than ConnectOther if you're going to send the message from that player.
     
  19. Offline

    AppleBabies

    @Xerox262 I'm confused...it's still not being sent.
    Code:
    package me.applebabies.ahc;
    
    import java.util.Arrays;
    
    import net.md_5.bungee.api.ChatColor;
    
    import org.bukkit.Material;
    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.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.plugin.messaging.PluginMessageListener;
    
    import com.google.common.io.ByteArrayDataOutput;
    import com.google.common.io.ByteStreams;
    
    public class Main extends JavaPlugin implements Listener, PluginMessageListener{
    
        private static Main instance;
        private ItemStack watch = new ItemStack(Material.WATCH);
        public ByteArrayDataOutput out = ByteStreams.newDataOutput();
       
       
        public static Main getInstance()
        {
            return instance;
        }
       
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
              this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
            this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", this);
        }
        public void onDisable(){
           
        }
        public void onPluginMessageReceived(String arg0, Player p, byte[] arg2) {
            p.sendPluginMessage(instance, "BungeeCord", out.toByteArray());
           
        }
       
        @EventHandler
         public void onPlayerInteract(PlayerInteractEvent e) {
                 if(e.getPlayer().getItemInHand() == watch){
                     if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK ||
                             e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_AIR){
                        out.writeUTF("ConnectOther");
                        out.writeUTF(e.getPlayer().getName());
                        out.writeUTF("lobby");
             }
                 }
             }
            
             @EventHandler
             public void onPlayerJoin(PlayerJoinEvent e){
                
                 Player p = e.getPlayer();
                 Inventory inv = p.getInventory();
                
                 ItemMeta meta = (ItemMeta) watch.getItemMeta();
                 meta.setDisplayName("Hub");
                 meta.setLore(Arrays.asList(ChatColor.WHITE + "Sends you back to the hub"));
                 watch.setItemMeta(meta);
                
                 if(!inv.contains(watch)) inv.addItem(watch);
                
                
                
             }
       
       
       
    }
    
     
  20. Offline

    megamichiel

    @AppleBabies
    Don't keep the ByteArrayOutputStream reference in your class, or else the stream will get bigger and bigger by time .-.
    You're still not doing
     
  21. Offline

    AppleBabies

    @megamichiel Well, where else would I keep the ByteArrayOutputStream? And also, Eclipse gives me a big fat error when I do
    Code:
    Player#sendPluginMessage(Plugin, "BungeeCord", out.toByteArray());
    so I don't know what to do with it...p.sendPluginMessage is acceptable, but not the other one.
     
  22. Offline

    pie_flavor

    @AppleBabies The # means that it can only be used in an instance, and is not static. Player#sendPluginMessage means that you get a player instance, and call sendPluginMessage on it. So if your player variable is p, you do p.sendPluginMessage.
    And don't keep it anywhere. Make a new one each time you do this, and make sure to close it after using it.
     
  23. Offline

    timtower Moderator Moderator

    Locked.
    Bungeecord is not supported.
     
Thread Status:
Not open for further replies.

Share This Page