Solved Force Location Spawn

Discussion in 'Plugin Development' started by Markyroson, Jun 22, 2014.

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

    Markyroson

    HeyAwesomePeople HeyAwesomePeople I tried it but it didn't work and filled the console with errors.

    here is what the class looks like with the cahnges:

    Code:java
    1. package me.Markyroson.plugins.ServerTeleportation2;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Location;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.player.PlayerJoinEvent;
    9.  
    10. @SuppressWarnings("unused")
    11. public class PlayerJoin implements Listener{
    12. public Main plugin;
    13.  
    14. @EventHandler
    15. public void onPlayerJoin(PlayerJoinEvent event){
    16. String w = plugin.getConfig().getString("hub_tp_location.world");
    17. int x = plugin.getConfig().getInt("hub_tp_location.x");
    18. int y = plugin.getConfig().getInt("hub_tp_location.y");
    19. int z = plugin.getConfig().getInt("hub_tp_location.z");
    20. float pitch = (float) plugin.getConfig().getDouble("hub_tp_location.pitch");
    21. float yaw = (float) plugin.getConfig().getDouble("hub_tp_location.yaw");
    22. event.getPlayer().teleport(new Location(Bukkit.getWorld(w), x, y, z, yaw, pitch));
    23. // p1.sendMessage("§6Teleporting to hub.");
    24. }
    25.  
    26. }
    27.  


    did I do something wrong?
     
  2. Markyroson plugin is null, or so it seems. Let us see the errors
     
  3. Offline

    Markyroson

    Here they are (warning, is a long list):

    Code:
    [20:30:26] [User Authenticator #3/INFO]: UUID of player Markyroson is 9bca29855d3344cfa2d6a67c5fc22646
    [20:30:26] [Server thread/INFO]: Markyroson[/127.0.0.1:55480] logged in with entity id 3666 at ([world] 488.29918795016937, 71.0, 46.424455383608084)
    [20:30:26] [Server thread/ERROR]: Could not pass event PlayerJoinEvent to ServerTP v1.6
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.PlayerList.c(PlayerList.java:225) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.PlayerList.a(PlayerList.java:116) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.LoginListener.c(LoginListener.java:78) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.LoginListener.a(LoginListener.java:42) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:149) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
    Caused by: java.lang.NullPointerException
        at me.Markyroson.plugins.ServerTeleportation2.PlayerJoin.onPlayerJoin(PlayerJoin.java:16) ~[?:?]
        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-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        ... 14 more
    [20:30:46] [Server thread/INFO]: Markyroson lost connection: Disconnected
    [20:30:46] [Server thread/INFO]: Markyroson left the game.
    [20:30:52] [User Authenticator #4/INFO]: UUID of player Markyroson is 9bca29855d3344cfa2d6a67c5fc22646
    [20:30:52] [Server thread/INFO]: Markyroson[/127.0.0.1:55493] logged in with entity id 3714 at ([world] 499.15845890184903, 64.0, 31.26094546516006)
    [20:30:52] [Server thread/ERROR]: Could not pass event PlayerJoinEvent to ServerTP v1.6
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.PlayerList.c(PlayerList.java:225) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.PlayerList.a(PlayerList.java:116) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.LoginListener.c(LoginListener.java:78) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.LoginListener.a(LoginListener.java:42) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:149) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
    Caused by: java.lang.NullPointerException
        at me.Markyroson.plugins.ServerTeleportation2.PlayerJoin.onPlayerJoin(PlayerJoin.java:16) ~[?:?]
        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-1.7.2-R0.4-20140316.221310-4.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        ... 14 more
     
  4. Offline

    bubba1234119

    What is at line 16.
    Edit:
    Guessing it is this, make sure it is spelled correctly in your config.yml
    Offtopic: I mean this in the nicest way possible, learning java outside of learning to program Bukkit plugins would benefit you greatly as you seem to be really struggling.
     
  5. Offline

    unrealdesign

    bubba1234119 I think it is a great way to learn. You have a constant motive (finishing the plugin), fast/fun/easy results for learning to code, and your friends can see what you've made and enjoy it with you. I just believe asking syntax questions is pointless though because better discussions can be held on StackOverflow and other sites.
     
  6. Offline

    fireblast709

    Markyroson plugin was never instantiated. Also note that you need to delay the teleport by 1 tick (as said in the first reply)
     
  7. Offline

    Markyroson

    fireblast709 fireblast709 All I simply want is to fix this problem. If someone can please help me with the code in the classes then please do. That way I can finish this thread and fix this problem and possibly provide answers for anyone else with a problem lie this (whether they are a java coding veteran or a notice [like me]). Also, I plan to start learning java soon but please help (with this).

    PlayerJoin class:

    Code:java
    1. package me.Markyroson.plugins.ServerTeleportation2;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Location;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.player.PlayerJoinEvent;
    9.  
    10. @SuppressWarnings("unused")
    11. public class PlayerJoin implements Listener{
    12. public Main plugin;
    13.  
    14. @EventHandler
    15. public void onPlayerJoin(PlayerJoinEvent event){
    16. String w = plugin.getConfig().getString("hub_tp_location.world");
    17. int x = plugin.getConfig().getInt("hub_tp_location.x");
    18. int y = plugin.getConfig().getInt("hub_tp_location.y");
    19. int z = plugin.getConfig().getInt("hub_tp_location.z");
    20. float pitch = (float) plugin.getConfig().getDouble("hub_tp_location.pitch");
    21. float yaw = (float) plugin.getConfig().getDouble("hub_tp_location.yaw");
    22. event.getPlayer().teleport(new Location(Bukkit.getWorld(w), x, y, z, yaw, pitch));
    23. // p1.sendMessage("§6Teleporting to hub.");
    24. }
    25.  
    26. }
    27.  


    Main class:

    Code:java
    1. package me.Markyroson.plugins.ServerTeleportation2;
    2.  
    3. import java.io.IOException;
    4. import java.util.logging.Logger;
    5.  
    6. import me.Markyroson.plugins.ServerTeleportation2.Metrics.Metrics;
    7. import me.Markyroson.plugins.ServerTeleportation2.Shop;
    8. import me.Markyroson.plugins.ServerTeleportation2.hub;
    9. import me.Markyroson.plugins.ServerTeleportation2.sethub;
    10. import me.Markyroson.plugins.ServerTeleportation2.setshop;
    11. import me.Markyroson.plugins.ServerTeleportation2.info.Cl;
    12. import me.Markyroson.plugins.ServerTeleportation2.updater.Updater;
    13. import me.Markyroson.plugins.ServerTeleportation2.updater.Updater.UpdateResult;
    14. import org.bukkit.Bukkit;
    15. import org.bukkit.plugin.java.JavaPlugin;
    16.  
    17.  
    18. public class Main extends JavaPlugin {
    19.  
    20. private final Logger l = Logger.getLogger("Minecraft");
    21.  
    22. // public final PlayerJoin pj = new PlayerJoin();
    23.  
    24. public void onEnable()
    25. {
    26. this.l.info("[ServerTeleportation] Enabled. Registering events & commands.");
    27.  
    28. // Register commands
    29. sethub s = new sethub(this);
    30. getCommand("sethub").setExecutor(s);
    31. hub s1 = new hub(this);
    32. getCommand("hub").setExecutor(s1);
    33.  
    34. // Cl contains sub-commands "reload", "info", and "version"
    35. Cl s2 = new Cl(this);
    36. getCommand("servertp").setExecutor(s2);
    37. getCommand("st").setExecutor(s2);
    38. setshop s3 = new setshop(this);
    39. getCommand("setshop").setExecutor(s3);
    40. Shop s4 = new Shop(this);
    41. getCommand("shop").setExecutor(s4);
    42.  
    43. this.l.info("[ServerTeleportation] Events & commands registered. Loading config.");
    44.  
    45. saveDefaultConfig();
    46. this.l.info("[ServerTeleportation] Config Loaded. Loading updater (updater can be disabled in settings, see main page for details).");
    47. //for updater
    48. Updater updater = new Updater(this, 80176, this.getFile(), Updater.UpdateType.DEFAULT, false);
    49. if (updater.getResult() == UpdateResult.UPDATE_AVAILABLE) {
    50. this.getLogger().info("New version available! " + updater.getLatestName());
    51. }
    52. this.l.info("[ServerTeleportation] Updater Loaded. Loading metrics (metrics can be disabled in settings, see main page for details).");
    53. // for plugin stats/metrics
    54. try {
    55. Metrics metrics = new Metrics(this);
    56. metrics.start();
    57. } catch (IOException e) {
    58. // Failed to submit the stats :-(
    59. }
    60. this.l.info("[ServerTeleportation] Enabled. Thank you for using ServerTP!");
    61.  
    62. Bukkit.getServer().getPluginManager().registerEvents(new PlayerJoin(), this);
    63. }
    64.  
    65.  
    66. public void onDisable()
    67. {
    68. this.l.info("[ServerTeleportation] Thank you for using ServerTP! Disabling...");
    69. this.l.info("[ServerTeleportation] ...Disabled.");
    70. }
    71.  
    72.  
    73. }


    Hub class (for the teleport code refered to previously):

    Code:java
    1. package me.Markyroson.plugins.ServerTeleportation2;
    2.  
    3.  
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.Location;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandExecutor;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10.  
    11. public class hub implements CommandExecutor{
    12. public static Main plugin;
    13.  
    14. public hub(Main i)
    15. {
    16. plugin = i;
    17. }
    18. @Override
    19. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    20. if(sender instanceof Player)
    21. if (label.equalsIgnoreCase("hub"))
    22. {
    23. Player p1 = (Player)sender;
    24. {
    25. String w = plugin.getConfig().getString("hub_tp_location.world");
    26. int x = plugin.getConfig().getInt("hub_tp_location.x");
    27. int y = plugin.getConfig().getInt("hub_tp_location.y");
    28. int z = plugin.getConfig().getInt("hub_tp_location.z");
    29. float pitch = (float) plugin.getConfig().getDouble("hub_tp_location.pitch");
    30. float yaw = (float) plugin.getConfig().getDouble("hub_tp_location.yaw");
    31. p1.teleport(new Location(Bukkit.getWorld(w), x, y, z, yaw, pitch));
    32. p1.sendMessage("§6Teleporting to hub.");
    33. }
    34. }
    35.  
    36.  
    37.  
    38. return false;
    39.  
    40. }
    41.  
    42. }
    43.  
     
  8. Offline

    fireblast709

    Markyroson don't plan to start Java when using Bukkit, learn Java before Bukkit. The plugin dev section is there to help you solving your issues, not to finish your code for you.
     
  9. Offline

    Jaaakee224

  10. Offline

    Markyroson

    Jaaakee224 sure. Here it is:

    Code:
    ######################################################
    #              ServerTP Config File                #
    ######################################################
    #
    no_perms_message: '&4You do not have permission to do that command!'
    #
    #
    # This is the hub location
    # For if a player does /hub
    # they will be teleported to this
    # spot
    # Location of the hub
    hub_tp_location:
      world: 'world'
      x: '0'
      y: '64'
      z: '0'
    # Location of the shop
    shop_tp_location:
      world: 'world'
      x: '0'
      y: '64'
      z: '0'
     
  11. Offline

    dsouzamatt

    If you're just asking someone to fix your code without any explanation so that "we can all happily go our own way", not even interested in learning Java (which, may I add, you inadvertently do in making a Bukkit plugin), you'd probably be better off asking someone to make this for you in the plugin requests section.
     
  12. Offline

    Jaaakee224

    Markyroson Try something like this
    Code:
    Hub:
    world:
    x:
    y:
    z:
    yaw:
    pitch:
     
  13. Offline

    Markyroson

    dsouzamatt I am interested in learning java and am actively doing it now. I created this thread for help. Not to be attacked.
     
  14. Offline

    Gater12

    Markyroson
    And they are helping you. Again you are not instantiating your plugin variable for PlayerJoin class thus it is null.

    You should learn to accept criticism as they help and shape you into a better programmer and, in general, person.
     
  15. Offline

    Markyroson

    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page