Solved PlayerJoinEvent not working?

Discussion in 'Plugin Development' started by minezbot, Mar 3, 2013.

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

    minezbot

    I am making a plugin and i want it to msg the player when they join
    I have use both PlayerJoinEvent and PlayerLoginEvent but after looking around i found i should use PlayerJoinEvent

    this is what i have:
    @EventHandler(priority=EventPriority.HIGH)
    public void onPlayerLogin(PlayerLoginEvent event){
    Player player = event.getPlayer();
    player.sendMessage("This is a test! :p");
    }

    but when you join the server nothing happends?
    is there something i am doing wrong?
     
  2. Offline

    Lolmewn

    So you're saying you should use PlayerJoinEvent, but use PlayerLoginEvent still? I can tell you that PlayerLoginEvent is not going to work on cracked servers.
     
  3. Offline

    minezbot

    I typed it out and put the wrong one. I have edited it now
    and i am not useing a cracked server
     
  4. Offline

    Lolmewn

    You better. Did you register the event class? Implements Listener? All that?
     
  5. Offline

    minezbot

    Yes i added all that in the main class
     
  6. Offline

    Lolmewn

    Can I see the actual main class? And the plugin.yml would be useful too, I think.
     
  7. Offline

    minezbot

    sure http://pastebin.com/MCWxDsZj (will be gone in 1 day)

    And plugin.yml (forgot) http://pastebin.com/v8PGDLau

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

    Lolmewn

    The join listener should work. The others aren't going to work, though. You need to use @EventHandler above each and every event.
     
  9. Offline

    minezbot

    Thx for the tip but it still will not work?

    Wait! NVM it works now :D

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

    Lolmewn

    Err, okay. Tell us what you changed or did, so that others with the same issue can fix it too ;)
     
  11. Offline

    minezbot

    Befor:
    Code:
    package com.minezbot.mehpvp;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Fireball;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
     
    public class MyPlayerListener implements Listener {
            public static main plugin;
         
            @EventHandler(priority=EventPriority.HIGH)
            public void onPlayerJoin(PlayerJoinEvent event){
                    Player player = event.getPlayer();
                    player.sendMessage("This is a test! :P");
            }
            public void onPlayerDeath(PlayerDeathEvent event){
                    Player player = event.getEntity();
                    if(player.getWorld().getName().equalsIgnoreCase("mehpvp")){
                            player.sendMessage(ChatColor.DARK_RED + "[MehPVP] " + ChatColor.RED + "You lost " + ChatColor.GOLD + "3" + ChatColor.RED + " points due to your death!");
                            player.sendMessage(ChatColor.DARK_RED + "[MehPVP] " + ChatColor.GOLD + "Your new point total is: " + ChatColor.BLUE + "97");
                    }else{
                         
                    }
            }
            public void onPlayerInteract(PlayerInteractEvent event){
                    Player player = event.getPlayer();
                    if(player.getLocation().getWorld().getName().equalsIgnoreCase("mehpvp")){
                    if(player.getItemInHand().getType() == Material.BLAZE_ROD){
                            Fireball fire = player.getWorld().spawn(event.getPlayer().getLocation(), Fireball.class);
                    fire.setShooter(player);
                    }else{}
            }
            }
    }
    After:
    Code:
    package com.minezbot.mehpvp;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Fireball;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
     
    public class MyPlayerListener implements Listener {
            public static main plugin;
         
            @EventHandler(priority=EventPriority.HIGH)
            public void onPlayerJoin(PlayerJoinEvent event){
                    Player player = event.getPlayer();
                    player.sendMessage("This is a test! :P");
            }
            @EventHandler(priority=EventPriority.HIGH)
            public void onPlayerDeath(PlayerDeathEvent event){
                    Player player = event.getEntity();
                    if(player.getWorld().getName().equalsIgnoreCase("mehpvp")){
                            player.sendMessage(ChatColor.DARK_RED + "[MehPVP] " + ChatColor.RED + "You lost " + ChatColor.GOLD + "3" + ChatColor.RED + " points due to your death!");
                            player.sendMessage(ChatColor.DARK_RED + "[MehPVP] " + ChatColor.GOLD + "Your new point total is: " + ChatColor.BLUE + "97");
                    }else{
                         
                    }
            }
            @EventHandler(priority=EventPriority.HIGH)
            public void onPlayerInteract(PlayerInteractEvent event){
                    Player player = event.getPlayer();
                    if(player.getLocation().getWorld().getName().equalsIgnoreCase("mehpvp")){
                    if(player.getItemInHand().getType() == Material.BLAZE_ROD){
                            Fireball fire = player.getWorld().spawn(event.getPlayer().getLocation(), Fireball.class);
                    fire.setShooter(player);
                    }else{}
            }
            }
    }
    After i added the @EventHandler(priority=EventPriority.HIGH) to all of them it worked
     
Thread Status:
Not open for further replies.

Share This Page