Solved Making Sure My Main Class Listens For An Event

Discussion in 'Plugin Development' started by KingOfTheEast01, Dec 26, 2016.

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

    KingOfTheEast01

    Hey guys, my name is Lucas. Here's my problem. I don't know how to get my main class to listen for my event. Basically, what my event does, is listens for a player to teleport from one world to another. I think I have it right, but what it should be doing when the event occurs, is setting that location as the player's spawn in that world, so when they go back to that specific world, they'll go back to that position. This hasn't been working on my server, which had the plug in on it, however, there haven't been any errors in my console from it. I'm not sure what's wrong, so I was hoping you guys could help me. Thanks for the help!

    Here's my code:

    My Main Class:

    Code:
    package com.weebly.gamersngeeks;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class TPFront extends JavaPlugin {
       
        @Override
        public void onEnable() {
           
            new TPLogger();
           
        }
       
        @Override
        public void onDisable() {
           
        }
    
    }
    My Event Class

    Code:
    package com.weebly.gamersngeeks;
    
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerTeleportEvent;
    import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
    
    public class TPLogger{
       
        @EventHandler
        public void onTeleport(PlayerTeleportEvent playertpe, PlayerTeleportEvent event) {
           
            if (event.getCause().equals(TeleportCause.COMMAND)) {
               
                if (event.getFrom().getWorld().equals(event.getTo().getWorld())) {
                   
                    int locX = event.getFrom().getBlockX();
                    int locY = event.getFrom().getBlockY();
                    int locZ = event.getFrom().getBlockZ();
                   
                    event.getFrom().getWorld().setSpawnLocation(locX, locY, locZ);
                   
                }
               
            }
       
        }
    
    My plugin.yml file

    Code:
    name: TestPlugin
    version: 0.1
    main: com.weebly.gamersngeeks.TPFront
    author: TheChocolateDev
    
    Sent from my SM-G935V using Tapatalk
     
  2. Offline

    ipodtouch0218

    1. onDisable() doesn't do anything, remove it.
    2. TPLogger must implement Listener
    3. Register your event handler class using "getServer().getPluginManager().registerEvents(new <Class>(), this)"
    4. The onTeleport method should only have one PlayerTeleportEvent
     
    KingOfTheEast01 likes this.
  3. Offline

    KingOfTheEast01

    Eclipse excepted the new code, but somethings still not right. Whenever I kill myself in-game or TP back to the world after leaving it using /mv tp, from the Multiverse-Core plugin, I end up in a different spot from where I left. Either the spawn point isn't being set or I'm not being TPed back to the correct spot. Do you think I could create a command that TP's you per world back to that specific spawnpoint, or should I simply try to continue fixing this event/spawn point setter?
     
  4. Offline

    KingOfTheEast01

    I've disbanded this project, but thanks for the help mate! :D

    Sent from my SM-G935V using Tapatalk
     
Thread Status:
Not open for further replies.

Share This Page