Solved .teleport() not working?

Discussion in 'Spigot Plugin Development' started by Griffdragon, Jul 13, 2018.

  1. Error:
    Code (Text):
    [07:33:12 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'warpland' in plugin BaronRaces v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchCommand(CraftServer.java:650) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.PlayerConnection.handleCommand(PlayerConnection.java:1354) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:1189) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:?]
            at java.base/java.util.concurrent.FutureTask.run(Unknown Source) [?:?]
            at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:747) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at java.base/java.lang.Thread.run(Unknown Source) [?:?]
    Caused by: java.lang.NullPointerException
            at org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer.teleport(CraftPlayer.java:497) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity.teleport(CraftEntity.java:260) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at me.griffdragon.races.Main.onCommand(Main.java:87) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            ... 15 more
    My Code:

    Code (Text):
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("race") && sender instanceof Player) {
                Player p = (Player) sender;
                inv(p);
            }
            if (cmd.getName().equalsIgnoreCase("setland") && sender instanceof Player) {
                Player p = (Player) sender;
                if (args.length == 1) {
                    String land = String.valueOf(args[0]);
                    if (land.equalsIgnoreCase("Forest")) {
                        int x = (int) p.getLocation().getX();
                        int y = (int) p.getLocation().getY();
                        int z = (int) p.getLocation().getZ();
                        World world = p.getLocation().getWorld();
                        config.set("LandConfig.Forest.X", x);
                        config.set("LandConfig.Forest.Y", y);
                        config.set("LandConfig.Forest.Z", z);
                        config.set("LandConfig.Forest.World", world.getName());
                        saveConfig();
                        p.sendMessage(ChatColor.GREEN + "Successfully set location for Forest!");
                    }
                }
            }
            if (cmd.getName().equalsIgnoreCase("warpland") && sender instanceof Player) {
                Player p = (Player) sender;
                if (args.length == 1) {
                    String land = String.valueOf(args[0]);
                    if (land.equalsIgnoreCase("Forest")) {
                        if (config != null) {
                            int x = config.getInt("LandConfig.Forest.X");
                            int y = config.getInt("LandConfig.Forest.Y");
                            int z = config.getInt("LandConfig.Forest.Z");
                            World world = Bukkit.getServer().getWorld("LandConfig.Forest.World");
                            Location loc = new Location(world, (double) x, (double) y, (double) z);
                            p.teleport(loc);
                        }
                    }
                }
            }
            return true;
        }
    I dont see why it isnt working...
     
  2. My config file...
    Code (Text):
    LandConfig:
      Desert:
        World: openworld
        X: 1
        Y: 1
        Z: 1
        Owner: none
      Forest:
        World: world
        X: -186
        Y: 63
        Z: -76
      Mountain:
        World: openworld
        X: 1
        Y: 1
        Z: 1
        Owner: none
      Tundra:
        World: openworld
        X: 1
        Y: 1
        Z: 1
        Owner: none
      Jungle:
        World: openworld
        X: 1
        Y: 1
        Z: 1
        Owner: none
     
     
  3. What's line 87 in Main.java?
     
  4. already checked that
    Code (Text):
    p.teleport(loc);
    not much help
     
  5. Location is configuration serialisable, instead of saving its x, y, z simply save the object.
    config.set("location", new Location(...)); would work.

    Then do Location loc = (Location) config.get("location");
     
  6. MiniDigger

    Supporter

    I bet that you don't successfully load the world from the config, that world is null
     
  7. hmm okay ill give it a go
     
  8. That worked! thanks!