Help with color

Discussion in 'Plugin Development' started by linkrock4, Nov 6, 2012.

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

    linkrock4

    Hey, so i want to change the text this gives to something else.
    Heres the code i have:
    Code:
                    sender.sendMessage(ChatColor.DARK_RED + "You have punched " + punchedName);
                    punched.sendMessage(ChatColor.DARK_RED + "You have been punched by " + senderName);
    Now obviously that gives something around this:
    You have punched <NAME>
    You have been punched by <NAME>

    But... I want it to look like this...
    [iEmotions] You have been punched by <NAME>
    [iEmotions] You have punched <NAME>

    Any idea of what the code has to look like?
    (Heres my full code)
    Code:
    package net.skydevs.src;
     
    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;
     
    public class ChatPlugin extends JavaPlugin{
     
        public void onEnable(){ //Server Starts
            getLogger().info("iEmotions has loaded!");
        }
     
        public void onDisable(){ //Server Stops
            getLogger().info("iEmotions has been disabled!");
        }
     
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            //Code
           
            String senderName = sender.getName();
           
            if (cmd.getName().equalsIgnoreCase("punch") && args.length == 1) {
               
                String punchedName = args[0];
                Player punched = sender.getServer().getPlayer(punchedName);
     
                if(punched == null){
                    //Code
                    sender.sendMessage(ChatColor.DARK_RED + "You cannot punch an offline player!");
                } else {
                    //Code for Punch
                    int currentHealth = punched.getHealth();
                    if (currentHealth > 0)
                    {
                    currentHealth--;
                    }
                    punched.setHealth(currentHealth);
     
                    sender.sendMessage(ChatColor.DARK_RED + "You have punched " + punchedName);
                    punched.sendMessage(ChatColor.DARK_RED + "You have been punched by " + senderName);
     
                }
     
            }
           
            if (cmd.getName().equalsIgnoreCase("kiss") && args.length == 1) {
     
                String kissedName = args[0];
                Player kissed = sender.getServer().getPlayer(kissedName);
     
                if(kissed == null){
                    //Code
                    sender.sendMessage(ChatColor.DARK_RED + "You cannot kiss an offline player!");
                } else {
                    //Code for Kiss
                    int currentHealth = kissed.getHealth();
                    if (currentHealth < 0)
                    {
                    currentHealth++;
                    }
                    kissed.setHealth(currentHealth);
     
                    sender.sendMessage(ChatColor.DARK_RED + "You have kissed " + kissedName);
                    kissed.sendMessage(ChatColor.DARK_RED + "You have been kissed by " + senderName);
     
                }
     
            }
     
            if (cmd.getName().equalsIgnoreCase("kick") && args.length == 1) {
                String kickedName = args[0];
                Player kicked = sender.getServer().getPlayer(kickedName);
     
                if(kicked == null){
                    //Code
                    sender.sendMessage(ChatColor.DARK_RED + "You cannot kick an offline player!");
                } else {
                    //Code for Kicks
                    int currentHealth = kicked.getHealth();
                    if(currentHealth > 0) // Warning, this will kill the player
                    {
                        currentHealth--;
                    }
                    kicked.setHealth(currentHealth);
     
                    sender.sendMessage(ChatColor.DARK_RED + "You have kicked " + kickedName);
                    kicked.sendMessage(ChatColor.DARK_RED + "You have been kicked by " + senderName);
     
                }
     
            }
     
            if (cmd.getName().equalsIgnoreCase("hug") && args.length == 1) {
                String huggeeName = args[0];
                Player huggee = sender.getServer().getPlayer(huggeeName);
     
                if(huggee == null){
                    //Code
                    sender.sendMessage(ChatColor.DARK_RED + "You cannot hug an offline player!");
                } else {
                    //Code for Hugs
                    int currentHealth = huggee.getHealth();
                    if (currentHealth < 0)
                    {
                        currentHealth++;
                      }
                    huggee.setHealth(currentHealth);
     
                    sender.sendMessage(ChatColor.DARK_RED + "You have hugged " + huggeeName);
                    huggee.sendMessage(ChatColor.DARK_RED + "You have been hugged by " + senderName);
     
                }
     
            }
     
            return false;
        }
     
    }
     
  2. Offline

    cman1885

    You can just interject different color codes...
    "§4You have been punched by §a"+punchedName

    etc
     
  3. Offline

    linkrock4

    Kinda new to java (started like a day ago) and i dont understand much about what your saying :/
     
  4. Offline

    fireblast709

    [iEmotions] You have been punched by <NAME> would be:
    Code:java
    1. String s = "["+ChatColor.
    Code:java
    1. [COLOR=#000000]LIGHT_PURPLE+"iEmotions"+ChatColor.WHITE+"]"+ChatColor.RED+" you have been punched by "+ChatColor.GREEN+name;[/COLOR]

    You cannot do the .
    Damnit bukkit, screwing with my text.
     
  5. Offline

    orange451

    Yes you can :)
     
  6. Offline

    fireblast709

    orange451 Can you now? Another thread ended up with another conclusion... If you really are convinced, show me the proof >:3 (in code)
     
  7. Offline

    orange451

    player.sendMessage("♥♥♥You're wrong♥♥♥");
    [​IMG]
    :)
     
  8. Offline

    linkrock4

    The code is not working :/
     
  9. Offline

    fireblast709

    linkrock4 yea bukkit is screwing up my code tag, sorry.
    String s ="["+ChatColor.LIGHT_PURPLE+"iEmotions"+ChatColor.WHITE+"]"+ChatColor.RED+" you have been punched by "+ChatColor.GREEN+name; hard to see, but works
     
  10. Offline

    linkrock4

    Thanks but the String s apparently is an error :/
     
  11. Offline

    cman1885

    I recommend you learn the basics of java first.
     
  12. Offline

    linkrock4

    I am learning it right now :/ but i would like it to work pleash
     
  13. Offline

    fireblast709

    orange451 mmh weird always thought it would not. Could be due all the testing with §

    linkrock4 the only error my IDE gives me is that name is undefined, as I never defined it. I hope you replaced 'name' with 'punchedName' or 'senderName'. If you get errors in the console, please post those

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  14. Offline

    linkrock4

    the name is replaced with senderName but its the String s is the problem, it says: the value of the local variable s is not used.
     
  15. Offline

    cman1885

    Yes, so when you go to sendmessage you send them s..
     
  16. Offline

    linkrock4

    :confused: so what should i do to fix this?
     
  17. Offline

    fireblast709

    le sigh, you really need the tutorials I guess :3
    Code:java
    1. punched.sendMessage("["+ChatColor.RED+"♥"+ChatColor.LIGHT_PURPLE+"iEmotions"+ChatColor.RED+"♥"+ChatColor.WHITE+"]"+ChatColor.RED+" You have been punched by "+ChatColor.GREEN+senderName);
    2. sender.sendMessage("["+ChatColor.RED+"♥"+ChatColor.LIGHT_PURPLE+"iEmotions"+ChatColor.RED+"♥"+ChatColor.WHITE+"]"+ChatColor.RED+" You have punched "+ChatColor.GREEN+punchedName);

    So yea this is what you do
     
  18. Offline

    cman1885

    I recommend a global header variable.
     
    fireblast709 likes this.
  19. Offline

    linkrock4

    Wanna be my tutor!? :D And thanks alot, it works :D

    Oh and btw...the ♥ wont let me save :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  20. Offline

    xXSniperzzXx_SD

    When you go to save the class, just save it as the mtf5(Just a guess i seriously forget the name of it) or what ever it asks you if you wanna save it as, it'll still work
     
  21. Offline

    linkrock4

    It asks me to save it as a .java ...
    Nvm it saved as Utf-8 :D
    Thanks!
     
  22. Offline

    cman1885

    Sigh^sigh^sigh^sigh^sigh
     
  23. Offline

    xXSniperzzXx_SD

    Well it worked for my plugin Infected :p i used to have a nuclear/radiation symbol in the prefix
     
  24. Offline

    linkrock4

    Lol ya edited my reply, it works!
    Thanks :D
     
  25. Offline

    fireblast709

Thread Status:
Not open for further replies.

Share This Page