Solved login message

Discussion in 'Spigot Plugin Development' started by yeongpin, Jun 9, 2017.

  1. hey everyone !
    im writting a plugin but dont know how to write when people login and he will get the message 5 time "please set a security, usage /xxx" this !
    anyone can help me this code how to write??
     
  2. ScarabCoder

    ScarabCoder Retired Resource Staff
    Retired

    Listen for the PlayerJoinEvent and send them the messages you want.
    If you're looking for a tutorial on events, this isn't really the place to ask.
     
  3. is this?
    @EventHandler
    public void onPlayerJoinEvent(PlayerJoinEvent event) {
    if(!event.getPlayer().hasPlayedBefore()) {
    event.getPlayer().sendMessage("please set security");
    }
    }
     
  4. Yep!
     
  5. To send it four more times add in a for loop.
     
  6. bro cant !
    Code (Text):
    package com.winde;


    import java.io.File;
    import java.io.IOException;

    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.ChatColor;
    import com.winde.Command.Delivery;
    import com.winde.Command.Security;
    import com.winde.csFile.Files;


    public class Main extends JavaPlugin {
         public static File blocks = null;
             
         @EventHandler
         public void onPlayerJoinEvent(PlayerJoinEvent event) {
         if(!event.getPlayer().hasPlayedBefore()) {
         event.getPlayer().sendMessage("please set security");
         }
         }
                   
                   
                   
        @Override
        public void onEnable() {
            Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN.toString() + "密保插件" + ChatColor.WHITE.toString() + "——" + ChatColor.GOLD.toString() + "[龍諸]" + ChatColor.GREEN.toString()+ "定制");
            Bukkit.getConsoleSender().sendMessage(ChatColor.AQUA.toString() + "作者:yeongpin冰封");
            Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN.toString() + "QQ:2776971369");
            Bukkit.getConsoleSender()
              .sendMessage(ChatColor.YELLOW.toString() + "版本: " + getDescription().getVersion());
              getCommand("mb").setExecutor(new Delivery(this));
              getCommand("mbcx").setExecutor(new Security(this));
              initconfig();
              blocks = new File(getDataFolder(), "mb.data");
              if (!blocks.exists()) {
                  try {
                    blocks.createNewFile();
                  } catch (IOException e) {
                      Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN.toString() + "密保无法创建data文件");
                  }
                }
              if (Files.loadBlocks()) {
                  Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN.toString() + "密保加载完成");
                 

                  }
                }
       

       
        @Override
        public void onDisable() {
            Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_RED.toString() + "密保卸载完成");
            Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN.toString() + "感谢" + ChatColor.GOLD.toString() + "[龍諸]" + ChatColor.GREEN.toString()+ "您的定制");
        }
       
     

        private void initconfig() {
            saveDefaultConfig();
        }
    }
     
  7. cant appear bro!
     
  8. You have to implement Listener and register the events in onEnable.
     
  9. Code (Text):
    package com.winde;

    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;

    public class Main2 implements Listener {
         @EventHandler
         public void onPlayerJoinEvent(PlayerJoinEvent event) {
         if(!event.getPlayer().hasPlayedBefore()) {
         event.getPlayer().sendMessage("please set security");
         }
         }
    }
    like this??
     
  10. Yes, and then register the events in your onEnable.
     
  11. how register the events in my onEnable?
    can u teach me