teleport at

Discussion in 'Plugin Development' started by ramptoetsenbord, Sep 22, 2017.

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

    ramptoetsenbord

    I am making a plugin where you can teleport at a player with a command but that player needs to accept or diny it. But whenever I try to use it my console gives me a error.

    My code is:
    Code:
    package Server.plugin.commands;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    import net.md_5.bungee.api.ChatColor;
    
    public class TPA implements CommandExecutor {
    
        public boolean onCommand(CommandSender cmdsender, Command cmd, String cmdLabel, String[] args) {
    
            String TPplayerName = args[1];
    
            Player player = (Player) cmdsender;
            Player TPplayer = Bukkit.getPlayer(TPplayerName);
    
            if (TPplayer != null) {
    
                player.sendMessage(org.bukkit.ChatColor.DARK_PURPLE + "Your invitation has been send!");
    
                TPplayer.sendMessage(
                        org.bukkit.ChatColor.DARK_PURPLE + "The player " + player + " wants to teleprt to you.");
                TPplayer.sendMessage(
                        org.bukkit.ChatColor.DARK_GRAY + "To accept do: " + org.bukkit.ChatColor.DARK_PURPLE + "/tpaccept");
                TPplayer.sendMessage(
                        org.bukkit.ChatColor.DARK_GRAY + "To deny do: " + org.bukkit.ChatColor.DARK_PURPLE + "/tpdeny");
    
                boolean accepted = false;
                while (accepted == false) {
    
                    if (TPplayer.performCommand("tpaccept")) {
                        player.sendMessage(
                                org.bukkit.ChatColor.DARK_PURPLE + " " + TPplayer + " has accepted your invitation!");
                        TPplayer.sendMessage(org.bukkit.ChatColor.DARK_PURPLE + "You accepted your invitation!");
    
                        Location L = TPplayer.getLocation();
    
                        player.teleport(L);
    
                        accepted = true;
    
                        return true;
    
                    } else if (TPplayer.performCommand("tpdeny")) {
    
                        player.sendMessage(org.bukkit.ChatColor.DARK_PURPLE + "The invitation you send is denied.");
                       
                        TPplayer.sendMessage(org.bukkit.ChatColor.DARK_PURPLE + "You denied the invitation that you got.");
                    }
                }
    
            } else {
    
                player.sendMessage(ChatColor.RED + "Sorry, player (" + TPplayer + ") could not be found.");
    
            }
    
            return false;
        }
    
    }
    
    and here 's the error:
    Code:
     Could not load 'plugins\ServerSurvivalPlugin.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidDescriptionException: Invalid plugin.yml
            at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPluginLoader.java:162) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:133) [spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.loadPlugins(CraftServer.java:302) [spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:205) [spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:544) [spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_144]
    Caused by: org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next token
    found character '\t(TAB)' that cannot start any token. (Do not use \t(TAB) for indentation)
    in 'reader', line 9, column 3:
            description: teleports to anoth ...
          ^
    
            at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:420) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:226) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingValue.produce(ParserImpl.java:585) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:157) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:147) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:133) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.yaml.snakeyaml.composer.Composer.composeValueNode(Composer.java:246) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.yaml.snakeyaml.composer.Composer.composeMappingChildren(Composer.java:237) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:225) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:154) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.yaml.snakeyaml.composer.Composer.composeValueNode(Composer.java:246) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.yaml.snakeyaml.composer.Composer.composeMappingChildren(Composer.java:237) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:225) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:154) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:122) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:122) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:505) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.yaml.snakeyaml.Yaml.load(Yaml.java:436) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.bukkit.plugin.PluginDescriptionFile.<init>(PluginDescriptionFile.java:226) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPluginLoader.java:157) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            ... 5 more






    if anyone could help, thath would be great!
     
  2. Offline

    Zombie_Striker

    @ramptoetsenbord
    You can't use tabs in your YML. You need to use spaces in multiples of three (I.e, Use the spaces " ")
     
  3. Offline

    ramptoetsenbord

    this error is fixed now but now i get another error:

    Code:
    [07:03:35 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'tpa' in plugin SurvivalServer v0.0.5
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:645) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at net.minecraft.server.v1_12_R1.PlayerConnection.handleCommand(PlayerConnection.java:1385) [spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1220) [spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_144]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_144]
            at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:747) [spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:405) [spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot-1.12.jar:git-Spigot-7228328-af1c013]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_144]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
            at Server.plugin.commands.TPA.onCommand(TPA.java:16) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot-1.12.jar:git-Spigot-7228328-af1c013]
            ... 15 more
     
  4. Offline

    Zombie_Striker

    @ramptoetsenbord
    You are getting the second arg before you even know if it exists. Make sure the args length is equal to 2 before getting the second arg.
     
  5. Offline

    ramptoetsenbord

    I added:
    Code:
    if (args[1] == null) {
               
                return false;
            }
    but it gives still the same error
     
  6. Offline

    Caderape2

    @ramptoetsenbord if there is not argument, the array of args will be empty.
    So check if args.lengh is not equal to 0 or equal to whatever you want
     
  7. Offline

    Minesuchtiiii

    I'd put them both in a hashmap and if the player accepts teleport him and remove them both from the hashmap
    if he denies also remove them
    if he doesn't "answer" remove him after... idk like 60 seconds, and send the player who requested the tp the message that he didnt answer in time
     
  8. Offline

    ramptoetsenbord


    Could you give a demonstration or something how you would do it?

    I tried this but it still gives the same error

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Sep 23, 2017
  9. Offline

    Zombie_Striker

    @ramptoetsenbord
    What is the command you are trying to send? The way you currently have it set up will require it to look like /tpa Something The_Player. Looking at your code, it seems you are not doing anything with the first arg. Are you sure you want to get the second arg using arg[1], or is it that you want to get the first arg using args[0]?
     
  10. Offline

    ramptoetsenbord

    I am trying to set it up like this:
     
  11. Offline

    Minesuchtiiii

    @ramptoetsenbord
    something like

    Code:
    HashMap<String, String> map = new HashMap<String, String>();
    
    //when player types /tp [name]
    map.put(teleportto.getName(), playerwhowantstoteleport.getName());
    
    //sent request to the other player and also start a scheduler, if nothing happens after 60 seconds remove the entry from the HashMap
    
    //if the other player types /tpaccept and got a key entry in the HashMap  teleport the other player, after this remove the entry from the HashMap
     
Thread Status:
Not open for further replies.

Share This Page