Falling Sand

Discussion in 'Plugin Development' started by ItsMees, Dec 5, 2013.

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

    ItsMees

    Hi Guys,
    I am working on project and I want it to make that if you do: /fall 1, there will drop an stone because 1 is the itemid of stone!
    But my code gives an error!
    My code: (I added the line numbers!)
    Code:java
    1. (39): Player player = (Player) sender;
    2. (40): Location dest = new Location(player.getWorld(), player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ());
    3. (41): Entity fallingblock = player.getWorld().spawnFallingBlock(dest, Material.getMaterial((Integer.parseInt(args[1]))), (byte) 4);
    4. (42): fallingblock.setTicksLived(1);


    The error: (It says theres an error on line 40!)
    Code:
    [23:49:38 INFO]: meesvdw issued server command: /fall 1
    [23:49:38 WARN]: dec 05, 2013 11:49:38 PM net.minecraft.server.v1_7_R1.PlayerConnection handleCommand
    SEVERE: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'fall' in plugin FallingBlock v0.1
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:192)
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServer.java:543)
            at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerConnection.java:923)
            at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:803)
            at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java:28)
            at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat.java:47)
            at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146)
            at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134)
            at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:645)
            at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:243)
            at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:535)
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:447)
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
            at com.itsmees.fallingblock.commands.CommandExecutor_Fall.onCommand(CommandExecutor_Fall.java:40)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
            ... 13 more
    I hope someona can help me out!
     
  2. Offline

    Wolfey

    For the location, try Location dest = player.getLocation(); It says the error is coming from line 40, but it seems to me it's coming from 41 because args[1] is out of bounds - does not exist, instead try args[0] because java likes to start at 0.
     
  3. Offline

    fireblast709

    Arrays start at index 0. So in your case, /fall 1
    args[0] = 1
     
  4. Offline

    The_Doctor_123

    Indices start at 0. So you're trying to get the second value in the array(which doesn't exist).
     
Thread Status:
Not open for further replies.

Share This Page