Colors

Discussion in 'Plugin Development' started by xCyanide, Jun 26, 2013.

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

    xCyanide

    How would I make death messages colored? Like the original minecraft death messages, but colored. Also, how do I make some one have a set color. So, in the playerchatevent if a player is op they would have a red name, is it possible for the player to have a red name in the death messages as well?
    I hope I explained it well enough
     
  2. Yes,
    Code:
    @EventHandler
    public void onDeath(PlayerDeathEvent event){
    Player player = event.getPlayer();
    String message = event.getMessage(); //or getDeathMessage I'm not sure
    String finalmsg = message.replaceAll(player.getName(), player.getDisplayName());
    event.setMessage(finalmsg); // or setDeathMessage(), also not sure
    }
     
  3. Offline

    xCyanide

    CaptainBern
    That looks like it will work, but how can I make it so the messages are colored like "player1 &4has slain player2"
     
  4. Just get the message and replace the things you want. You can also set your own messages...
     
  5. Offline

    xCyanide

    How would I replace multiple things? Like the color code in the death message after I replaced the player name
     
  6. Offline

    Limeth

    Code:java
    1. String string = "&1Ahoy!";
    2. string = ChatColor.translateAlternateColorCodes('&', string);
     
  7. Offline

    xCyanide

    Limeth
    That is not what I meant, I should've been a bit more descriptive. I meant like I already use this to change the player name
    Code:java
    1. String message = event.getDeathMessage();
    2. String deathmsg = message.replaceAll(player.getName(), player.getDisplayName());

    Now I want to replace like "player1 has been slain by player2" I want to replace it with "player1 &5has been slain by &r player2
     
  8. Offline

    Limeth

    xCyanide
    Oops, my bad.
    Why don't you just create your own death messages?
    Code:text
    1. ChatColor msgColor = ChatColor.YELLOW;
    2. ChatColor killerColor = ChatColor.GREEN;
    3. ChatColor victimColor = ChatColor.RED;
    4. Player victim = event.getPlayer();
    5. Player killer = victim.getKiller();
    6. String victimName = victim.getName();
    7. String killerName = killer.getName();
    8. event.setDeathMessage(victimColor + victimName + msgColor + " has been slain by " + killerColor + killerName)
     
  9. Offline

    xCyanide

    Limeth
    Yeah, but I just wanted to recolor the original minecraft death messages
     
Thread Status:
Not open for further replies.

Share This Page