How to rewrite event.getType?

Discussion in 'Plugin Development' started by sethgandy, Nov 25, 2012.

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

    sethgandy

    So I'm stuck on this one, how would I rewrite this to work with the current event system?
    Code:
    public void run() {
            if (event.getType() == Type.PLAYER_JOIN) {
                
     
  2. Offline

    kyran_

    Listen for that particular event type in your event listener?
    Code:
    @EventHandler
    public void onPlayerLogin(PlayerLoginEvent event) {
        // Your code here...
    }
    
    from: http://wiki.bukkit.org/Event_API_Reference
     
  3. Offline

    cocoson

    hell i'm still using this way to get player_join and it seems to work just fine

    Code:
    @EventHandler (priority = EventPriority.NORMAL)
        public void onPlayerJoin(PlayerJoinEvent event){
            Player player = event.getPlayer();
    
     
  4. Offline

    sethgandy

    Hmm, here's my dilemma. This is the full code, more or less:
    Code:
    @EventHandler
        public void run() {
            if (event.getType() == Type.PLAYER_JOIN) {
               
                PlayerJoinEvent joinevent = (PlayerJoinEvent) event;
                Player plr = joinevent.getPlayer();
                String name = plr.getName();
               // TONS OF JUNK HERE
            }
            if (event.getType() == Type.PLAYER_TELEPORT) {
                PlayerTeleportEvent teleportevent = (PlayerTeleportEvent) event;
                Player plr = teleportevent.getPlayer();
                String name = plr.getName();
                String world = teleportevent.getTo().getWorld().getName();
                // TONS MORE JUNK HERE
                }
    So the problem being, unless I split the RUN function into two separate functions, I have errors using those methods?
     
  5. Offline

    kyran_

    Why not just use the standard event listener model outlined in the link I posted and then create threads from there if necessary?
     
  6. Offline

    sethgandy

    I'll give it a shot
     
  7. Offline

    cocoson

    looks like ur trying to make it to complicated

    i have never messed with the teleport before but here is a video he uses a simple teleport idea and i'm sure from it u can modify it to work the way u want
     
  8. Offline

    kyran_

    Also be careful about what you run in separate threads. Read about synchronous vs asynchronous tasks in the sticky or do a forum search. My guess is that cocoson is right and you're just overcomplicating things. If you follow the instructions on the eventAPI page above you should be fine.
     
Thread Status:
Not open for further replies.

Share This Page