staffchat config?

Discussion in 'Plugin Development' started by _Chazzie_, Jun 22, 2017.

Thread Status:
Not open for further replies.
  1. hello
    i was making an staffchat plugin but i have an problem:
    i don't know how to make an config for the prefix.
    my code is like this:
    Code:
    package chat;
    
    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.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener{
      
        public void onEnable() {
            getConfig().addDefault("Prefix", ChatColor.translateAlternateColorCodes('&', "&a[&cStaff&3Chat&a]&r"));
            getConfig().options().copyDefaults(true);
            saveConfig();
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
      
        }      
        public boolean onCommand(CommandSender s, Command cmd,    String label, String[] args) {
            if (s instanceof Player) {
                Player p = (Player) s;
                if (cmd.getName().equalsIgnoreCase("staffchat")) {
                    if (!s.hasPermission("staffchat.use")) {
                        s.sendMessage("§a[§cStaff§3Chat§a] " + ChatColor.RED + "je hebt geen permissies om dit te doen!");
                        return true;
                    }
                    if (args.length == 0) {
                        s.sendMessage("§a[§cStaff§3Chat§a] " + ChatColor.RED + "Sorry, maar dit kunnen we helaas niet sturen naar de andere staff leden, omdat er niks staat!");
                        return true;
                    }
                    if (args.length > 0) {
                        StringBuilder b = new StringBuilder();
                        for (int i = 0; i < args.length; i++) {
                            b.append(" ");
                            b.append(args[i]);
                        }
                        String message = b.toString();
                        for (Player all : Bukkit.getServer().getOnlinePlayers()) {
                            if (all.hasPermission("staffchat.use")) {
                              
                                all.sendMessage("§a[§cStaff§3Chat§a] " + ChatColor.RESET + p.getDisplayName() + ": " + ChatColor.WHITE + ChatColor.translateAlternateColorCodes('&', message));
                            }
                        }
                    }
                }
            }
          
            return false;      
        }
      
    }
    i have 1 section of the config set. but i don't know how to add it in the rest of the build
     
  2. Offline

    YoloSanta

    @_Chazzie_
    Your trying to add the prefix to the config ? Then you have to add the ChatColor.translateAlternateColorCodes then get the config then string
     
  3. yes and how should i add it? and this is my first time trying to add an config
     
  4. Offline

    YoloSanta

    Well good job already having this.

    On you s.sendmessage you would need to (if using color codes) add ChatColor.translateAlertanceColorCodes then get config for example,
    Code:java
    1. player.sendMessage(ChatColor.translateAlternateColorCodes(getConfig().getString("STRING");
     
Thread Status:
Not open for further replies.

Share This Page