Teleportation

Discussion in 'Spigot Plugin Development' started by Sunique, Jun 14, 2016.

  1. Hi I'm trying to make it so they cant use /prison in the prison world and if they use it outside of the world it teleports them to the world.
    Im getting this error:
    Code (Text):
    [11:49:50 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'prison' in plugin ApexNation v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-d97e08b-5e85956]
            at me.incomprehendable.dev.pwp.FakeSimpleCommandMap.dispatch(FakeSimpleCommandMap.java:98) ~[?:?]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:640) ~[spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_72]
            at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_72]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:714) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:653) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:556) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at java.lang.Thread.run(Thread.java:745) [?:1.8.0_72]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
            at me.sunique.ApexNation.Main.onCommand(Main.java:236) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-d97e08b-5e85956]
            ... 15 more
    This is my code
    Code (Text):
            if(p.getWorld().getName().equalsIgnoreCase("Prison") || p.getWorld().getName().equalsIgnoreCase("Prison-1") && cmd.getName().equalsIgnoreCase("spawn")){
                    p.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "" + ChatColor.ITALIC + "APEXNATION" + ChatColor.DARK_GRAY + "" + ChatColor.ITALIC + " >> " + ChatColor.GRAY + "Teleporting...");
                    Location loc = new Location(Bukkit.getWorld("Prison"), -71.518, 67.0, -840.548);
                    loc.setYaw((float) 0.9);
                    loc.setPitch((float) -28.2);
                    p.teleport(loc);
                }else{
                    p.sendMessage("Sorry but, thats not a command!");
                    return false;
            }
     
  2. if (this || this && this)

    if ((this || this) && this)

    if ((!this || !this) && this)

    Check if they are not in the world, then make sure you are properly clarifying your if statement with parentheses.
     
  3. This is wrong.
    Try this:

    Code (Text):
    if((p.getWorld().getName().equalsIgnoreCase("Prison") || p.getWorld().getName().equalsIgnoreCase("Prison-1")) && cmd.getName().equalsIgnoreCase("spawn")){
     
  4. Thanks I will try this now.
     
  5. I have this:
    Code (Text):
            if((p.getWorld().getName().equalsIgnoreCase("Prison") || p.getWorld().getName().equalsIgnoreCase("Prison-1")) && cmd.getName().equalsIgnoreCase("spawn")){
                p.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "" + ChatColor.ITALIC + "APEXNATION" + ChatColor.DARK_GRAY + "" + ChatColor.ITALIC + " >> " + ChatColor.GRAY + "Teleporting...");
                Location loc = new Location(Bukkit.getWorld("Prison"), -71.518, 67.0, -840.548);
                loc.setYaw((float) 0.9);
                loc.setPitch((float) -28.2);
                p.teleport(loc);
            }else{
                p.sendMessage("Sorry but, thats not a command!");
                return false;
            }
    Getting this error:
    Code (Text):
    [12:55:47 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'prison' in plugin ApexNation v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-d97e08b-5e85956]
            at me.incomprehendable.dev.pwp.FakeSimpleCommandMap.dispatch(FakeSimpleCommandMap.java:98) ~[?:?]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:640) ~[spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_72]
            at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_72]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:714) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:653) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:556) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at java.lang.Thread.run(Thread.java:745) [?:1.8.0_72]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
            at me.sunique.ApexNation.Main.onCommand(Main.java:242) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-d97e08b-5e85956]
            ... 15 more
     
  6. link the code for this line :
    Code (Text):
    at me.sunique.ApexNation.Main.onCommand(Main.java:242)
     
  7. I'm guessing you're not properly using the arguments in your command :)

    Code (Text):
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
            at me.sunique.ApexNation.Main.onCommand(Main.java:242) ~[?:?]
     
  8. Line 242 is
    Code (Text):
        if(p.getWorld().getName().equals("HUB")&&args[0].equalsIgnoreCase("hub")){
     
  9. Are you trying to do something like: "/server hub" or just "/hub"?
     
  10. What command are you using?
    This error most likely means that args[0] doesn't exist.
     
  11. Well, just pointing something out, you have a new location with x, y, and z. Well, you just need to add two ints at the end of the new Location for Yaw And Pitch. Not after as seperate code:
    Code (Text):
    loc.setYaw(yaw);
     
  12. I do /spawn and get this error:
    Code (Text):
    [12:55:47 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'prison' in plugin ApexNation v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-d97e08b-5e85956]
            at me.incomprehendable.dev.pwp.FakeSimpleCommandMap.dispatch(FakeSimpleCommandMap.java:98) ~[?:?]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:640) ~[spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_72]
            at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_72]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:714) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:653) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:556) [spigot.jar:git-Spigot-d97e08b-5e85956]
            at java.lang.Thread.run(Thread.java:745) [?:1.8.0_72]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
            at me.sunique.ApexNation.Main.onCommand(Main.java:242) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-d97e08b-5e85956]
            ... 15 more
    This is my code...
    Code (Text):
            if((p.getWorld().getName().equalsIgnoreCase("Prison") || p.getWorld().getName().equalsIgnoreCase("Prison-1")) && cmd.getName().equalsIgnoreCase("spawn")){
                p.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "" + ChatColor.ITALIC + "APEXNATION" + ChatColor.DARK_GRAY + "" + ChatColor.ITALIC + " >> " + ChatColor.GRAY + "Teleporting...");
                Location loc = new Location(Bukkit.getWorld("Prison"), -71.518, 67.0, -840.548);
                loc.setYaw((float) 0.9);
                loc.setPitch((float) -28.2);
                p.teleport(loc);
            }else{
                p.sendMessage("Sorry but, thats not a command!");
                return false;
            }
     
  13. What's line 242?
     
  14. Something is going out of bounds... Can you send full code?
     
  15. people got to stop assuming the error in in certain small selection of code.
    send your whole class.

    Also, learn to read errors
     
    • Funny Funny x 1
  16. Assuming? It literally says:

    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
    at me.sunique.ApexNation.Main.onCommand(Main.java:242) ~[?:?]
     
  17. the line from the error does not always cause the error.
    and thats what i meant by learn to read errors
     
  18. It says multiple times throughout the stack-trace that the first argument is null, therefore when trying to access an argument that isn't there will of course throw an ArrayIndexOutOfBoundsException.
     
  19.