onPlayerTeleport problem - Not being called?

Discussion in 'Plugin Development' started by Relick, Dec 22, 2011.

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

    Relick

    I was under the impression that onPlayerTeleport would be called every time someone went between a world. I'm sure it does, still however it's just not being called for me. I've tried adding in debugging messages but even a log that is sent right at the start of the event doesn't get executed :/.

    My onEnable, where it is registered:

    Code:java
    1. PluginManager pm = getServer().getPluginManager();
    2. playerListener = new Listener_Player(this);
    3. pm.registerEvent(Event.Type.PLAYER_TELEPORT, playerListener, Event.Priority.High, this);


    And my onPlayerTeleport (in player listener):
    Code:java
    1. public void onPlayerTeleport(PlayerTeleportEvent event) {
    2. Player player = event.getPlayer();
    3. Location loc = event.getTo();
    4. if(!player.hasPermission("bensautomater.gamemode") && loc.getWorld().getName().equalsIgnoreCase("freebuild")) {
    5. player.setGameMode(GameMode.SURVIVAL);
    6. player.sendMessage("No creative mode in freebuild!");
    7. }
    8. }


    I'm using other events in this player listener, so it isn't the listener or the register :(.
     
  2. Offline

    Father Of Time

    From first glance the only thing I see (looking very fast) is that your listener, although declared, is never stored permanently.

    Code:
    playerListener = new Listener_Player(this);
    You declare a new Listener into a local variable, meaning as soon as the onEnable function is done being executed the listener is thrown into the trash collector.

    What you need to do is move the initiation of your listener to outside your onenable function, declare it, and then in the on enable register that instance of your listener.

    Code:
    private final playerListener mylistener = new Listener_Player(this);
    Give that a shot and let us know what happens, Good luck with your project!
     
  3. Offline

    NuclearW

    Relick likes this.
  4. Offline

    Relick

    @Father Of Time Oh no, I already had that earlier. As I said it works with other events such as onPlayerChat and onPlayerCommandPreprocess

    EDIT: Ok I'll give that a try, @NuclearW

    Yay! Thanks Nuclear! Works great, ty.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 22, 2016
  5. Offline

    NuclearW

    @Relick

    Glad to have helped.
     
  6. Offline

    Father Of Time

    Opps, sorry... Sometimes I try and spit out a quick response between work e-mails; thats the result of paying semi attention to a post...

    I'm just glad someone came along and provided you with what you need, take care. :)
     
Thread Status:
Not open for further replies.

Share This Page