Solved LoadLocation?

Discussion in 'Plugin Help/Development/Requests' started by nastasescu, Mar 27, 2015.

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

    nastasescu

    Hi i have this code:
    Code:
        public void loadLocation(int i) {
            if (!(getConfig().getString("menu-name-" + i).length() == 0)) {
                name = getConfig().getString("menu-name-" + i);
                description = getConfig().getString("menu-description-" + i);
                item = getConfig().getInt("menu-item-" + i);
                slot = getConfig().getInt("menu-slot-" + i);
                world = getServer().getWorld(
                        getConfig().getString("menu-location-world-" + i));
                x = getConfig().getInt("menu-location-x-" + i);
                y = getConfig().getInt("menu-location-y-" + i);
                z = getConfig().getInt("menu-location-z-" + i);
                usepermission = getConfig().getBoolean("menu-usepermission-" + i);
                permission = getConfig().getString("menu-permission-" + i);
            }
        }
    and i want to get from config.cfg this, but it gives me error, my config.yml:

    menu-slot-1: 1
    menu-name-1: Test
    menu-description-1: Test_test
    menu-item-1: 2
    menu-location-world-1: world
    menu-location-x-1: 219.5
    menu-location-y-1: 67.0
    menu-location-z-1: 247.0
    menu-usepermission-1: false
    menu-permission-1: none

    I made an debug and that's the code who gives error:
    Code:
        @SuppressWarnings("deprecation")
        public void openTeleportMenu(Player p) {
            Inventory inv = Bukkit.createInventory(null,
                    9 * getConfig().getInt("horizontal-lines"), "ยง"
                            + getConfig().getString("menu-color")
                            + getConfig().getString("menu-text"));
            for (int i = 0; i < 55; i++) {
                if (!(getConfig().getString("menu-name-" + i).length() == 0)) {
                    loadLocation(i);
                    ArrayList<String> lore = new ArrayList<String>();
                    lore.set(0, description);
                    ItemStack material = new ItemStack(Material.getMaterial(item));
                    ItemMeta im = material.getItemMeta();
                    im.setDisplayName(name);
                    im.setLore(lore);
                    inv.setItem(slot, material);
                    material.setItemMeta(im);
                }
            }
            p.openInventory(inv);
        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  2. Offline

    nastasescu

    Code:
    [16:33:32 ERROR]: Could not pass event PlayerInteractEvent to FastTravel v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:305) ~[spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:502) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:487) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInte
    ractEvent(CraftEventFactory.java:226) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3
    ]
            at net.minecraft.server.v1_8_R1.PlayerInteractManager.interact(PlayerInt
    eractManager.java:463) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java
    :724) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlo
    ckPlace.java:50) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlo
    ckPlace.java:80) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spi
    got-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_40]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_40]
            at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:6
    96) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:3
    16) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:6
    34) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java
    :537) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_40]
    Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
            at java.util.ArrayList.rangeCheck(Unknown Source) ~[?:1.8.0_40]
            at java.util.ArrayList.set(Unknown Source) ~[?:1.8.0_40]
            at me.covrigutul.fasttravel.ft.openTeleportMenu(ft.java:60) ~[?:?]
            at me.covrigutul.fasttravel.ft.OnPlayerInteract(ft.java:133) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0
    _40]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0
    _40]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .8.0_40]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_40]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:301) ~[spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            ... 16 more
    >
    That's the error after your modification.
    @FisheyLP

    Resolved.

    <Edit by mrCookieSlime: Merged posts. Please don't double post. There is an Edit Button right next to the Date.>
     
    Last edited by a moderator: Mar 27, 2015
  3. Offline

    mrCookieSlime

    Moved to Alternatives Section.
     
  4. There is your problem.
    You set a value to an index that doesnt exist in the List because the list is empty (line 60 and line 133):
    Code:
    ArrayList<String> lore = new ArrayList<String>();
    lore.set(0, description);
    use instead:
    Code:
    lore.add(description);
     
Thread Status:
Not open for further replies.

Share This Page