dispatchCommand dont work

Discussion in 'Spigot Plugin Help' started by szymek1223, Jul 15, 2021.

  1. Someone knows what to do when I have some command on the server (/ server TntRun) and in the plugin I added the / leave command and added Bukkit.getServer (). DispatchCommand (Bukkit.getConsoleSender (), "server TntRun"); and when I type / leave, nothing shows up to me and in the console I write that the command is incorrect?
    Or do you know any other solution to make it work?
     
  2. The console cannot use /server command on itself… the console cannot teleport between servers.
     
  3. I replaced getconsolesender with commandsender and it still doesn't work, it says "Unkown command. Type / help ..."

    My all code:
    package cmds;
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import manager.GameManager;
    public class ArenaQuitCommand implements CommandExecutor {
    private GameManager gameManager;

    public ArenaQuitCommand(GameManager gameManager) {
    this.gameManager = gameManager;
    }

    public boolean onCommand(CommandSender commandsender, Command command, String s, String[] args) {

    Bukkit.getServer().dispatchCommand(commandsender, "server TntRun");

    return false;
    }


    }
     
  4. I think u r doing this in a wrong way if wanna do /leave and send the player to a certain server is that what u mean?

    u have to use a method that send the player to the server u want :D

    or maybe i didn't understand what u want exactly.
     
  5. Code (Java):
    public static void connect(Player player, String serverName){
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
            try {
                dataOutputStream.writeUTF("Connect");
                dataOutputStream.writeUTF(serverName);
            } catch (IOException exception){
                exception.printStackTrace();
            }
            player.sendPluginMessage(Main.getInstance(), "BungeeCord", byteArrayOutputStream.toByteArray());
        }

    //You must put this @ onEnable [ Main class ]:
    Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
    i hope this method will help u
     
    • Like Like x 1
  6. Answer on top of this one is the way to go. /server isn’t a spigot command so the server doesn’t know what to do with it and says it doesn’t exist.
     
    • Like Like x 1
  7. You can't send a specific player to a specific server via the server console. You want to use the BungeeCord API to transfer players between servers.