Problem/Bug Multiple Door Closing Problem

Discussion in 'Plugin Help/Development/Requests' started by ProSl3nderMan, Jul 30, 2015.

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

    ProSl3nderMan

    Alright, so previously I've gotten some code to work that closes a door on a player interact event. Now that I had 1 door, I needed to do code for other doors too. So I went door galore and the plugin stops working on the second door function.

    Code:
    Code:
                        int x1 = AccessControl.plugin.getConfig().getInt("map1.cell1.door1.x");
                        int y1 = AccessControl.plugin.getConfig().getInt("map1.cell1.door1.y");
                        int z1 = AccessControl.plugin.getConfig().getInt("map1.cell1.door1.z");
                        Block irondoor1 = Bukkit.getWorld((AccessControl.plugin.getConfig().getString("map1.world"))).getBlockAt(x1, y1, z1);
                        BlockState state1 = irondoor1.getState(); Openable openable1 = (Openable) state1.getData(); openable1.setOpen(false); state1.setData((MaterialData) state1.getData());state1.update();
                       
                        int x2 = AccessControl.plugin.getConfig().getInt("map1.cell1.door2.x");
                        int y2 = AccessControl.plugin.getConfig().getInt("map1.cell1.door2.y");
                        int z2 = AccessControl.plugin.getConfig().getInt("map1.cell1.door2.z");
                        Block irondoor2 = Bukkit.getWorld((AccessControl.plugin.getConfig().getString("map1.world"))).getBlockAt(x2, y2, z2);
                        BlockState state2 = irondoor2.getState(); Openable openable2 = (Openable) state2.getData(); openable2.setOpen(false); state2.setData((MaterialData) state2.getData());state2.update();
                       
                        int x3 = AccessControl.plugin.getConfig().getInt("map1.cell1.door3.x");
                        int y3 = AccessControl.plugin.getConfig().getInt("map1.cell1.door3.y");
                        int z3 = AccessControl.plugin.getConfig().getInt("map1.cell1.door3.z");
                        Block irondoor3 = Bukkit.getWorld((AccessControl.plugin.getConfig().getString("map1.world"))).getBlockAt(x3, y3, z3);
                        BlockState state3 = irondoor3.getState(); Openable openable3 = (Openable) state3.getData(); openable3.setOpen(false); state3.setData((MaterialData) state3.getData());state3.update();
                       
                        int x4 = AccessControl.plugin.getConfig().getInt("map1.cell1.door4.x");
                        int y4 = AccessControl.plugin.getConfig().getInt("map1.cell1.door4.y");
                        int z4 = AccessControl.plugin.getConfig().getInt("map1.cell1.door4.z");
                        Block irondoor4 = Bukkit.getWorld((AccessControl.plugin.getConfig().getString("map1.world"))).getBlockAt(x4, y4, z4);
                        BlockState state4 = irondoor4.getState(); Openable openable4 = (Openable) state4.getData(); openable4.setOpen(false); state4.setData((MaterialData) state4.getData());state4.update();
                       
                        int x5 = AccessControl.plugin.getConfig().getInt("map1.cell1.door5.x");
                        int y5 = AccessControl.plugin.getConfig().getInt("map1.cell1.door5.y");
                        int z5 = AccessControl.plugin.getConfig().getInt("map1.cell1.door5.z");
                        Block irondoor5 = Bukkit.getWorld((AccessControl.plugin.getConfig().getString("map1.world"))).getBlockAt(x5, y5, z5);
                        BlockState state5 = irondoor5.getState(); Openable openable5 = (Openable) state5.getData(); openable5.setOpen(false); state5.setData((MaterialData) state5.getData());state5.update();
                       
                        int x6 = AccessControl.plugin.getConfig().getInt("map1.cell1.door6.x");
                        int y6 = AccessControl.plugin.getConfig().getInt("map1.cell1.door6.y");
                        int z6 = AccessControl.plugin.getConfig().getInt("map1.cell1.door6.z");
                        Block irondoor6 = Bukkit.getWorld((AccessControl.plugin.getConfig().getString("map1.world"))).getBlockAt(x6, y6, z6);
                        BlockState state6 = irondoor6.getState(); Openable openable6 = (Openable) state6.getData(); openable6.setOpen(false); state6.setData((MaterialData) state6.getData());state6.update();
                       
                        int x7 = AccessControl.plugin.getConfig().getInt("map1.cell1.door7.x");
                        int y7 = AccessControl.plugin.getConfig().getInt("map1.cell1.door7.y");
                        int z7 = AccessControl.plugin.getConfig().getInt("map1.cell1.door7.z");
                        Block irondoor7 = Bukkit.getWorld((AccessControl.plugin.getConfig().getString("map1.world"))).getBlockAt(x7, y7, z7);
                        BlockState state7 = irondoor7.getState(); Openable openable7 = (Openable) state7.getData(); openable7.setOpen(false); state7.setData((MaterialData) state7.getData());state7.update();
                       
                        int x8 = AccessControl.plugin.getConfig().getInt("map1.cell1.door8.x");
                        int y8 = AccessControl.plugin.getConfig().getInt("map1.cell1.door8.y");
                        int z8 = AccessControl.plugin.getConfig().getInt("map1.cell1.door8.z");
                        Block irondoor8 = Bukkit.getWorld((AccessControl.plugin.getConfig().getString("map1.world"))).getBlockAt(x8, y8, z8);
                        BlockState state8 = irondoor8.getState(); Openable openable8 = (Openable) state8.getData(); openable8.setOpen(false); state8.setData((MaterialData) state8.getData());state8.update();
                       
                        int x9 = AccessControl.plugin.getConfig().getInt("map1.cell1.door9.x");
                        int y9 = AccessControl.plugin.getConfig().getInt("map1.cell1.door9.y");
                        int z9 = AccessControl.plugin.getConfig().getInt("map1.cell1.door9.z");
                        Block irondoor9 = Bukkit.getWorld((AccessControl.plugin.getConfig().getString("map1.world"))).getBlockAt(x9, y9, z9);
                        BlockState state9 = irondoor9.getState(); Openable openable9 = (Openable) state9.getData(); openable9.setOpen(false); state9.setData((MaterialData) state9.getData());state9.update();
                       
                        int x10 = AccessControl.plugin.getConfig().getInt("map1.cell1.door10.x");
                        int y10 = AccessControl.plugin.getConfig().getInt("map1.cell1.door10.y");
                        int z10 = AccessControl.plugin.getConfig().getInt("map1.cell1.door10.z");
                        Block irondoor10 = Bukkit.getWorld((AccessControl.plugin.getConfig().getString("map1.world"))).getBlockAt(x10, y10, z10);
                        BlockState state10 = irondoor10.getState(); Openable openable10 = (Openable) state10.getData(); openable10.setOpen(false); state10.setData((MaterialData) state10.getData());state10.update();
    Error I get in the console is this:
    Code:
    [01:31:22] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to AccessControl v0.1
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-f928e7a-e91aed8]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-f928e7a-e91aed8]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-f928e7a-e91aed8]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-f928e7a-e91aed8]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:227) [spigot.jar:git-Spigot-f928e7a-e91aed8]
        at net.minecraft.server.v1_8_R3.PlayerInteractManager.interact(PlayerInteractManager.java:463) [spigot.jar:git-Spigot-f928e7a-e91aed8]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:736) [spigot.jar:git-Spigot-f928e7a-e91aed8]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:52) [spigot.jar:git-Spigot-f928e7a-e91aed8]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) [spigot.jar:git-Spigot-f928e7a-e91aed8]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-f928e7a-e91aed8]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_51]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_51]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SystemUtils.java:19) [spigot.jar:git-Spigot-f928e7a-e91aed8]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:718) [spigot.jar:git-Spigot-f928e7a-e91aed8]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:367) [spigot.jar:git-Spigot-f928e7a-e91aed8]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:657) [spigot.jar:git-Spigot-f928e7a-e91aed8]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:560) [spigot.jar:git-Spigot-f928e7a-e91aed8]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_51]
    Caused by: java.lang.ClassCastException: org.bukkit.material.MaterialData cannot be cast to org.bukkit.material.Openable
        at me.ProSl3nderMan.AccessControl.RightClickListener.onInteract(RightClickListener.java:74) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_51]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-f928e7a-e91aed8]
        ... 17 
    Line 74 is line 12 on here. If someone could help me resolve this problem, that would be terrific. Thanks in advance :)
     
  2. Moved to Bukkit Alternates.
     
  3. Offline

    ProSl3nderMan

    But... the other one is more active D;

    Bump, can someone help me?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
  4. Offline

    Boomer

    First, this is a perfect example of why you'd make a method to take parameters and do the action... make one method that is passed some values, and have it do the repetitious work. Then call the method n times with the parameters. If it works in some cases but not in others at that point, well, you know the code works exactly right since its not changed from case to case to case, but it must be something in the data obtained via that code - the reading of the data values from the config, the atual values in the config (might be off by 1 or missing a negative sign), etc. The copy/paste/modify of blocks like you have means hving to be really careful to make changes each time, and use those name changes consistantly, without accidentally referring to object3 in object4's section..

    Your first block of code works - that means, the general code is okay.
    The fact that the second one says it can not be cast to an openable type means... the block at those coordinates is not a door. Reasons?
    1) The coordinates are incorrect, and could be off by one or a minus sign missing
    2) Do you really have 10 doors on a single cell? Or is the system defaulting to null //default values for the coordinates.
    Does your config actually look like:

    Code:
    map1:
      cell1:
        door1:
          x: ##
          y: ##
          z: ##
        door2:
          x: ##
          y: ##
          z: ##
        door3:
          x: ##
          y: ##
          z: ##
    ....
    [code]
    You can always have a debug statment (broadcast) to spit out the x,y,z gotten, and to spit out the getType() data from that coordinate... "A log? Why is it thinking irongate #2 is a log??" forces you to examine why that is...
     
    Last edited: Jul 31, 2015
Thread Status:
Not open for further replies.

Share This Page