Solved [Help] public void onNewPlayerJoin (PlayerJoinEvent event){}

Discussion in 'Plugin Development' started by Cheesepro, Aug 30, 2014.

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

    Cheesepro

    Here is my Code:
    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST)
    2. public void onNewPlayerJoin(PlayerJoinEvent event){
    3. if(!event.getPlayer().hasPlayedBefore()) {
    4. int x = Integer.parseInt(getConfig().getString("Hub" + ".X"));
    5. int y = Integer.parseInt(getConfig().getString("Hub" + ".Y"));
    6. int z = Integer.parseInt(getConfig().getString("Hub" + ".Z"));
    7. World w = event.getPlayer().getServer().getWorld(getConfig().getString("Hub" + ".W"));
    8. Location loc = new Location(w, x, y, z);
    9. event.getPlayer().teleport(loc);
    10. event.getPlayer().sendMessage("Debug Message");
    11. System.out.println("Console Debug Message");
    12. }
    13. }


    So I did register the event in OnEnable()
    Code:
    Bukkit.getServer().getPluginManager().registerEvents(this, this);
    And I did set the priority to HIGHEST
    Code:
    @EventHandler(priority = EventPriority.HIGHEST)
    Also both of the debug message printed out..

    Last but not least this part of code does work on my onPlayerRespawn()
    Code:java
    1. public void onPlayerRespawn(PlayerRespawnEvent event){
    2. int x = Integer.parseInt(getConfig().getString("Hub" + ".X"));
    3. int y = Integer.parseInt(getConfig().getString("Hub" + ".Y"));
    4. int z = Integer.parseInt(getConfig().getString("Hub" + ".Z"));
    5. World w = event.getPlayer().getServer().getWorld(getConfig().getString("Hub" + ".W"));
    6. Location loc = new Location(w, x, y, z);
    7. event.setRespawnLocation(loc);
    8. }


    The Problem is when a new player join, the player will not get teleport to where I said in the code, but the default location...
    Uhamm.. So if you know where I did wrong.. please help me! Thank you! :D


    Note: if you wonder how I test the code out since I already played on the server.. I change the line
    Code:java
    1. if(!event.getPlayer().hasPlayedBefore())

    To this:
    Code:java
    1. if(event.getPlayer().hasPlayedBefore())

    and you know whats weird.. if I changed the code to above it will teleport me... but when I change back it will not teleport the new player.. D:
     
  2. Offline

    dchaosknight

    Cheesepro

    What exactly is wrong? Is it not teleporting the player, are you getting an error message, or is it something else?
     
  3. Offline

    Cheesepro


    dchaosknight

    oh... I am soo sorry.. I forgot to mention the main problem.. :p
    so when a new player join, the player will not get teleport to where I said in the code, but the default location

    NOTE: and there are no error messages printed in the Console
     
  4. Offline

    dchaosknight

    Cheesepro

    What plugins are installed in the server that you're testing on? Is it just your plugin?
     
  5. Offline

    Cheesepro

    dchaosknight
    Plugin list:
    Chestshop
    clearlag
    colorchatformat
    Griefprevention
    homespawnwarp <---- Maybe is casued by this?
    iconomy
    minigames
    multiworld
    permissionsex
    simpleautomessage
    vault
    worldedit
    worldguard
     
  6. Offline

    dchaosknight

    Cheesepro

    It could be that a plugin is interfering with yours. You can try setting the priority to EventPriority.MONITOR and see if that changes anything.
     
  7. Offline

    AoH_Ruthless

    dchaosknight
    It is not a conflicting plugin. Your second statement is bad advice. You should NEVER use the MONITOR priority unless your plugin is of logging intention or something similar. When changing or altering an outcome, leave MONITOR alone.

    Cheesepro
    Schedule a 1-tick task before teleporting the player. When the event is called, the player can't be teleported right away because they aren't fully spawned in; waiting 1 tick should do the trick.
     
    Cheesepro likes this.
  8. Offline

    Cheesepro

    dchaosknight
    AoH_Ruthless
    Thank you for your help xD I used Java decomplier and I saw a plugin that have a listener too.. so I fixed it! Thankyou!
    oh but by the way what do EventPriority.MONITOR actually do?
     
  9. Offline

    AoH_Ruthless

    Cheesepro
    MONITOR is a priority higher than HIGHEST. It is bad practice to use it for the plugin you are coding ... just don't release it publicly I suppose because any server using your plugin could see some of their other plugins break.
     
  10. Offline

    dchaosknight

    AoH_Ruthless

    It doesn't appear to me that the plugin is altering anything having to do with the actual event itself, though; that's why I recommended it.
     
Thread Status:
Not open for further replies.

Share This Page