Solved HELP! PlayerJoinEvent doesnt seem to be working??

Discussion in 'Plugin Development' started by MrAw3omeZz, Dec 26, 2014.

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

    MrAw3omeZz

    So I'm new to all this and have looked at many tutorials that involve what I want but no matter what i do i cant get what I want.

    What i want to happen: When a player joins the plugin checks the players name and if it is a certain name broadcast a message or execute a command

    What is happening: No broadcast/execution.

    My Main.java(this is just a start, but im slowly making my own deny all spam/hacked accounts plugin)
    "Sup3rNinj4" is my MC and i was using it to test but it doesnt check the name as i would like it to..
    Code:
    package me.Sup3r.DenySpambots;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    
    public class Main extends JavaPlugin implements Listener {
    
        @Override
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this, this);
            getServer().getPluginManager().registerEvents(this, this);
        }
       
        @Override
        public void onDisable() {
           
        }
       
       
        //LISTENER CODE
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            if (cmd.getName().equalsIgnoreCase("BLANK") && sender instanceof Player) {
               
                Player player = (Player) sender;
               
                return true;
               
            }
           
            return false;   
           
        }
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
    
            if(e.getPlayer().getDisplayName() == "Sup3rNinj4"){
                for (Player player : Bukkit.getOnlinePlayers())
                {
                  player.sendMessage(ChatColor.BLACK + "[" + ChatColor.RED + ChatColor.BOLD + "Deny" + ChatColor.BLACK + "]" + ChatColor.GOLD + " Player: " + ChatColor.AQUA + ChatColor.ITALIC + "Sup3rNinj4" + ChatColor.GOLD + " Is a " + ChatColor.RED + ChatColor.BOLD + "Hacked Account");
                }
            }
        }
       
    }
     
  2. Offline

    bobthefish

    I am not sure how much of the problem this is, however you have this:

    if(e.getPlayer().getDisplayName()=="Sup3rNinj4"){

    the == does not the contents of a string, it tests objects (I Think) but try switching it to

    if(e.getPlayer().getDisplayName().equals("Sup3rNinj4")){
     
  3. Offline

    MrAw3omeZz

    Thank you, this works! Sends the message twice but ill see what i can do about that.

    I got a bigger problem ahead of me but im sure i can find a way :p
     
Thread Status:
Not open for further replies.

Share This Page