1.14.4 Config Creation

Discussion in 'Spigot Plugin Development' started by NexonKingdom, Mar 29, 2020.

  1. How can I use chat colors in my messages in the config?

    Main Class:
    Code (Java):
    package com.zayden.staffjoin;

    import com.zayden.staffjoin.event.StaffJEvent;
    import com.zayden.staffjoin.event.StaffLEvent;
    import org.bukkit.ChatColor;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    public final class StaffJoin extends JavaPlugin implements Listener
    {

        @Override
        public void onEnable() {
            this.saveDefaultConfig();
            this.getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "[StaffJoin] " + ChatColor.GREEN + "Has Now Been Enabled!");
            PluginManager pm = getServer().getPluginManager();
            getServer().getPluginManager().registerEvents(new StaffJEvent(), this);
            getServer().getPluginManager().registerEvents(new StaffLEvent(), this);

        }

        @Override
        public void onDisable() {
            this.getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "[StaffJoin] " + ChatColor.RED + "Has Now Been Disabled!");
        }
    }
     
    StaffJEvent (Join):
    Code (Java):
    package com.zayden.staffjoin.event;


    import com.zayden.staffjoin.StaffJoin;
    import net.md_5.bungee.api.ChatColor;
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;

    public class StaffJEvent implements Listener
    {

        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            for (Player p : Bukkit.getOnlinePlayers()) {
                if (player.hasPermission("sj.join")) {
                    Bukkit.broadcastMessage("placeholder");
                }
            }
        }
    }
     
    StaffLEvent (Leave):
    Code (Java):
    package com.zayden.staffjoin.event;


    import com.zayden.staffjoin.StaffJoin;
    import net.md_5.bungee.api.ChatColor;
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerQuitEvent;

    public class StaffLEvent implements Listener
    {

        @EventHandler
        public void onQuit(PlayerQuitEvent event) {
            Player player = event.getPlayer();
                for (Player p : Bukkit.getOnlinePlayers()) {
                    if (player.hasPermission("sj.leave")) {
                    Bukkit.broadcastMessage("placeholder");

                }
            }
        }
    }
     
     
  2. ChatColors.translateAlternateColorCodes('&', text)
     
    • Agree Agree x 1
  3. What do I put for text?
     
  4. `text` refers to the string within your configuration file as the translateAlternateColorCodes method returns a string with the proper colors.
    If you don't know how to make and manage a plugin's configuration, please see this.
     
  5. Okay! Does the message are separate from them?