Solved Could not pass event PlayerInteractEvent to

Discussion in 'Plugin Development' started by jonassvensson44, Jul 8, 2014.

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

    jonassvensson44

    So im getting this error when im trying to teleport to a certain location usings signs.
    I've been removing some of the code and figured out its the player.teleport who is the problem.

    I'm new on coding so the code doesn't look that smooth.

    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3. Player player = event.getPlayer();
    4. Block block = event.getClickedBlock();
    5. Action action = event.getAction();
    6. if(action == Action.RIGHT_CLICK_BLOCK) {
    7.  
    8. if(((block.getType() == Material.SIGN)
    9. || (block.getType() == Material.SIGN_POST)
    10. || (block.getType() == Material.WALL_SIGN)
    11. )){
    12.  
    13. Sign sign = (Sign) block.getState();
    14.  
    15. String textFromSign = sign.getLine(1);
    16. ConfigurationSection section = this.getConfig().getConfigurationSection("root.arenor");
    17.  
    18. if(sign.getLine(0).contains("[Join]")) {
    19. if(section.contains(textFromSign)) {
    20.  
    21. String world = section.getString("world");
    22. double x = section.getDouble( "x" );
    23. double y = section.getDouble( "y" );
    24. double z = section.getDouble( "z" );
    25.  
    26. //problem? player.teleport( new Location( this.getServer().getWorld( world ), x, y, z ) );
    27.  
    28. }else{
    29. player.sendMessage(ChatColor.RED + "That arena does not exist");
    30. }
    31. }
    32. }
    33. }
    34. }


    ERROR CODE:
    [08:40:26 ERROR]: Could not pass event PlayerInteractEvent to Event v1 org.bukkit.event.EventException at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks] at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks] at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks] at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks] at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:216) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks] at net.minecraft.server.v1_7_R3.PlayerInteractManager.interact(PlayerInteractManager.java:374) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks] at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:629) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks] at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.a(SourceFile:60) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks] at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.handle(SourceFile:9) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks] at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks] at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks] at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks] at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks] at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks] at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks] at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks] Caused by: java.lang.NullPointerException at event.main.Event.onPlayerInteract(Event.java:73) ~[?:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_51] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_51] at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks] ... 15 more
     
  2. Offline

    simolus3

    If the commented line is your problem source, the world from your config (section.getString("world")) is most likely not yet loaded. To load a world, you could run this code:
    Code:java
    1. public World getWorldByName(String name) {
    2. World w = Bukkit.getWorld(name);
    3. if (w == null) {
    4. WorldCreator creator = new WorldCreator(name);
    5. creator.environment(World.Environment.NORMAL);
    6. creator.generateStructures(true);
    7. w = creator.createWorld();
    8. }
    9. //Start of optional code
    10. w.setThundering(false);
    11. w.setTime(7 * 1000);
    12. w.setThundering(false);
    13. w.setThunderDuration(999999999);
    14. w.setWeatherDuration(999999999);
    15. //End of optional code
    16. return w;
    17. }
    It tries to load the world and if it hasn't been loaded yet it generates it. If there already is a folder with the world name, it won't get gererated but the world from the folder gets loaded and returned.
     
  3. Offline

    jonassvensson44

    simolus3 I added that code to mine and i still getting the same error. When i remove this line and replace it with an
    player.sendMessage just to see if it works it works.
    Code:java
    1. player.teleport( new Location( this.getServer().getWorld( world ), x, y, z ) );


    And another thing that i noticed was that i cant get the coords from my configfile. I just tested to print out the world + coords from the config and all i got was null00,00.000.00..
    And this is how i save the config:
    Code:java
    1. this.getConfig().set("root.arenor." + args[0] + ".world", world);
    2. this.getConfig().set("root.arenor." + args[0] + ".x", x);
    3. this.getConfig().set("root.arenor." + args[0] + ".y", y);
    4. this.getConfig().set("root.arenor." + args[0] + ".z", z);
     
  4. Offline

    welsar55

  5. Offline

    simolus3

    jonassvensson44 Seriously? How about using the method I gave you?
    Code:java
    1. player.teleport( new Location( getWorldByName(world), x, y, z ) );

    Please check the file config.yml manually to get the values to test whether you can't just read your config or also have problems with saving values.
     
  6. Offline

    jonassvensson44

    simolus3 You're right, i can't get the config. But as i mentioned in the first post im new on coding.

    This is how i get the config.
    Code:java
    1. this.getConfig().getConfigurationSection("root.arenor");
    2.  


    This is how i save to config.
    Code:java
    1. this.getConfig().set("root.arenor." + args[0] + ".world", world);
    2. this.getConfig().set("root.arenor." + args[0] + ".x", x);
    3. this.getConfig().set("root.arenor." + args[0] + ".y", y);
    4. this.getConfig().set("root.arenor." + args[0] + ".z", z);
    5.  
    6. this.saveConfig();


    And this is how my config file looks like.

    Code:
    root:
      arenor:
        test:
          world: world
          x: 1003.7116403305627
          y: 32.0
          z: -1693.7635332338823
    
     
  7. Offline

    simolus3

    jonassvensson44 If your config looks like this, the error occurs when you're trying to read data from it. I think the mistake is
    Code:java
    1. ConfigurationSection section = this.getConfig().getConfigurationSection("root.arenor");
    To get the values, you'd have to set that to "root.arenor.arenaName", so after you have checked "section.containts" the sign value, you'd hat to set section to
    Code:java
    1. section = this.getConfig().getConfigurationSection("root.arenor." + textFromSign);
     
  8. Offline

    jonassvensson44

  9. Offline

    simolus3

Thread Status:
Not open for further replies.

Share This Page