Chat

Discussion in 'Plugin Development' started by Jayyy, Sep 19, 2015.

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

    Jayyy

    So I'm making a few rank commands such as /Mod and /Admin and what they do is if an OP does /Mod <UserName> then it sets their display name to Purple as well as Admin but Red. Although I'm currently having issues when a player gets /Modded *Or Admin'd* if they logout and log back in they lose that, I tried adding an ArrayList but that didn't work I don't know why it would But I tried and it wouldn't seem to work so if you know what I'm not doing / messing up on please let me know :) Thanks :D
     
  2. Offline

    teej107

    @Jayyy Post code attempt.
     
  3. Offline

    Jayyy



    Code:
    package me.jay.dopekits;
    
    import java.util.ArrayList;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    
    public class Mod implements CommandExecutor, Listener {
    
        ArrayList<String> mod = new ArrayList<String>();
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("mod")) {
                if(sender instanceof Player) {
                    if(args.length == 0){
                        Player p = (Player)sender;
                        p.sendMessage(ChatColor.RED + "Usage: /Mod <Player>");
                    }
                    if(args.length == 1){
                        Player p = (Player)sender;
                        Player tp = Bukkit.getServer().getPlayer(args[0]);
                        mod.add(tp.getName());
                        tp.setDisplayName("§5" + tp.getName() + ChatColor.RESET);
                        tp.sendMessage(ChatColor.GRAY + "You are now a " +
                                ChatColor.DARK_PURPLE + "Moderator.");
                    }
                }
            }
            return false;
        }
    }
    I was thinking about making a PlayerJoinEvent but I don't know how to check if the player is a mod :<

    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
     
    Last edited by a moderator: Sep 19, 2015
  4. Offline

    teej107

    @Jayyy I'm guessing the player's display name get's reset on disconnect. S0 yes, you would have to use the PlayerJoinEvent to check if a player is a mod. I would recommend saving your ArrayList to a config so the data won't get lost on plugin reloads/restarts.
     
  5. Offline

    Jayyy

    Hmm cant seem
    So I added when you do /mod <name> it adds them to arraylist and then when they join it checks to see if the player contains mod arraylist then it would again set their displayname but that isnt working neither
     
  6. Offline

    boomboompower

    Just asking, why in your code are you using the § symbol and ChatColor?
     
  7. Offline

    Jayyy

    cause i didnt want to take the time to look up the code for reset but i guess i could've just used chat color for both LOL
     
Thread Status:
Not open for further replies.

Share This Page