Solved Locations HELP || Error teleporting to a loc

Discussion in 'Plugin Development' started by Hexcit, Aug 3, 2014.

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

    Hexcit

    Code:
    [12:51:13 ERROR]: Could not pass event PlayerInteractEntityEvent to Timeout v1.0
     
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:294) ~[craftbukkit-1.7.9-R0.2.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks
    ]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[craftbukkit-1.7.9-R0.2.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:501) [craftbukkit-1.7.9-R0.2.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks
    ]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:486) [craftbukkit-1.7.9-R0.2.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks
    ]
            at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java
    :1072) [craftbukkit-1.7.9-R0.2.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.PacketPlayInUseEntity.a(SourceFile:55) [
    craftbukkit-1.7.9-R0.2.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.PacketPlayInUseEntity.handle(SourceFile:
    10) [craftbukkit-1.7.9-R0.2.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157
    ) [craftbukkit-1.7.9-R0.2.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craf
    tbukkit-1.7.9-R0.2.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:6
    67) [craftbukkit-1.7.9-R0.2.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:2
    60) [craftbukkit-1.7.9-R0.2.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:5
    58) [craftbukkit-1.7.9-R0.2.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java
    :469) [craftbukkit-1.7.9-R0.2.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:6
    28) [craftbukkit-1.7.9-R0.2.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    Caused by: java.lang.NullPointerException
            at org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer.teleport(CraftPlaye
    r.java:484) ~[craftbukkit-1.7.9-R0.2.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092
    jnks]
            at org.bukkit.craftbukkit.v1_7_R3.entity.CraftEntity.teleport(CraftEntit
    y.java:200) ~[craftbukkit-1.7.9-R0.2.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092
    jnks]
            at me.connor.timeout.main.touchytouchy(main.java:58) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0
    _65]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0
    _65]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .7.0_65]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_65]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:292) ~[craftbukkit-1.7.9-R0.2.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks
    ]
    That is the error. When I try to click a player with a fishing rod it does this. This is the code:
    Code:java
    1. package me.connor.timeout;
    2.  
    3. import java.util.HashMap;
    4.  
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandExecutor;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.player.PlayerInteractEntityEvent;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14. import org.bukkit.ChatColor;
    15. import org.bukkit.Location;
    16. import org.bukkit.Material;
    17. public class main extends JavaPlugin implements Listener, CommandExecutor{
    18. HashMap<Player, Location> getTimeoutLoc = new HashMap<Player, Location>();
    19. ItemStack TimeoutItem = new ItemStack(Material.FISHING_ROD);
    20. int time = getConfig().getInt("TimeoutTime");
    21. boolean isEnabled;
    22. @Override
    23. public void onDisable() {
    24. getLogger().info(":'( Bye bye Timeout");
    25. }
    26.  
    27. @Override
    28. public void onEnable() {
    29. getLogger().info("Timeout Enabled!");
    30. this.getServer().getPluginManager().registerEvents(this, this);
    31. this.getConfig().options().copyDefaults(true);
    32. getConfig().options().copyDefaults(true);
    33. saveConfig();
    34. }
    35. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    36. Player p = (Player) sender;
    37. Location ploc = p.getLocation();
    38. if(label.equalsIgnoreCase("timoutloc")) {
    39. getTimeoutLoc.put(null, ploc);
    40. p.sendMessage(ChatColor.BLACK + "[" + ChatColor.GREEN + "Timeout" + ChatColor.BLACK + "]");
    41. }
    42.  
    43.  
    44.  
    45.  
    46.  
    47.  
    48. return false;
    49.  
    50. }
    51. @EventHandler
    52. public void onHit(PlayerInteractEntityEvent event){
    53. final Player player = event.getPlayer();
    54. Player rightclick = (Player) event.getRightClicked();
    55. final Location spawn = player.getBedSpawnLocation();
    56. if(rightclick instanceof Player && player.hasPermission("timeout.use") && player.getItemInHand().equals(TimeoutItem)){
    57. Location timeoutLocation = getTimeoutLoc.get(rightclick);
    58. player.teleport(timeoutLocation);
    59. player.getWorld().createExplosion(player.getLocation(), 0f);
    60. rightclick.damage(1.0);
    61. this.getServer().getScheduler().runTaskLater(this, new Runnable() {
    62.  
    63. @Override
    64. public void run() {
    65. player.teleport(spawn);
    66.  
    67. }
    68. }, (int) time);
    69. }
    70. }
    71. }


    I'm really stumped on this one. :/

    Thanks,
    Connor.

    I also have a question. When it says stuff in the error about net.minecraft and craftbukkit and stuff, does that mean it's the build or me using the build wrong?

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

    xXMaTTHDXx

    Well, that means you are using a craftbukkit build, use a bukkit build instead dl.craftbukkit.org/bukkit I believe.

    EDIT: You are trying to teleport a player to a null location, that is why you are getting a npe.
     
  3. Offline

    zDylann

    At:
    Code:java
    1. Location timeoutLocation = getTimeoutLoc.get(rightclick);

    You are trying to get the value of the key player without checking if that key exists first. Also under your command it looks like you are setting the key to null at
    Code:java
    1. getTimeoutLoc.put(null, ploc);

    You can't teleport a player to a null location. You should probably not add a player object to a hashmap, thats just asking for issues. Use the player's name.
     
  4. Offline

    Hexcit

    zDylann Sorry, I don't understand. Could you show me code and explain?
     
  5. Offline

    leon3001

    Hexcit
    You are never adding the location of rightclick to the HashMap.
     
  6. Offline

    Hexcit

    leon3001 It's really much easier if you show me a quick example. In the meantime I'm going to try and understand what that m :) eans.
     
  7. Offline

    FabeGabeMC

    Hexcit
    We are not here to give you the code.
    Also, store the player's UUID to avoid memory leak.
     
  8. Offline

    Hexcit

    FabeGabeMC. I'm not asking for a full code. Just an example of what that is. Like 2 lines and a comment (//).
     
  9. Offline

    FabeGabeMC

    Hexcit
    okay then.
    Code:java
    1. //Your hashmap
    2. private Map<UUID, Location> playerLoc = new HashMap<UUID, Location>();
    3. //Set location
    4. playerLoc.put(yourPlayer.getUniqueId(), yourPlayer.getLocation());
    5. //TP
    6. yourPlayer.teleport(playerLoc.get(yourPlayer.getUniqueId()));
    7. //onDisable()
    8. playerLoc.clear();
     
    leon3001 likes this.
  10. Offline

    fireblast709

    WeakHashMap
     
    Konkz likes this.
  11. Offline

    Konkz

    I suggest learning some Java, I can tell from your replies your knowledge is very limited.
     
  12. Offline

    Hexcit

    Konkz. I fixed it. I really am trying to get better at coding, so while I'm waiting for my book I might as well ask around here. Java tuts on YouTube don't do it for me. I'm not trying to say that I'm awesome at coding, not even good.
     
Thread Status:
Not open for further replies.

Share This Page