Thread: [PI] Simple Message Coloring System *UPDATED*

Page 1 of 3 123 LastLast
Results 1 to 10 of 22
  1. #1 [PI] Simple Message Coloring System *UPDATED* 
    Banned

    Join Date
    Aug 2011
    Posts
    843
    Thanks given
    541
    Thanks received
    220
    Rep Power
    0
    Havent really been on in a while and started to get back into RSPS. Anyways, this took me about 5 minutes to write. Its nothing fancy and it's simple as the title says, it works and could be useful. Its not much of a system...but we'll consider it as one

    Colors: RED BLUE YELLOW ORANGE PURPLE WHITE BLACK

    NEW CODE:
    Slight adjustments, such as crowns and a better way of using colors.

    Message.java
    Code:
    /**
     * @description Uses the stream to send new messages using color and/or crown icons
     * @title Message.java
     * @author iExample
     * @link http://www.rune-server.org/
     */
    
    public class Message {
        
        /**
         * Sends message with crowns or color.
         * @param c
         * @param color
         * @param message
         * @param rankIcons
         * @param crownNumber
         * @return
         */
        public static boolean out(Client c, String color, String message, int crownNumber, boolean rankIcons) {
            if (c.getOutStream() != null) {
                c.outStream.createFrameVarSize(253);
                if(rankIcons == true) {
                    c.outStream.writeString("<img="+getCrown(crownNumber)+"><col="+getColor(color)+">"+message+"</col>");
                } else {
                    c.outStream.writeString("<col="+getColor(color)+">"+message+"</col>");
                }
                c.outStream.endFrameVarSize();
            }
            return false;
        }
        
        /**
         * Crowns.
         * @param crownNumber
         * @return
         */
        public static MessageCrowns getCrown(int crownNumber) {
            return getCrown(crownNumber);
        }
        
        /**
         * Colors.
         * @param color
         * @return
         */
        public static MessageColor getColor(String color) {
            return getColor(color);
        }
    }
    MessageColor.java
    Code:
    package server.world.messages;
    
    public enum MessageColor {
    
        RED("FF0000"),
        GREEN("00FF00"),
        YELLOW("FFFF00"),
        BLUE("0000FF"),
        ORANGE("FF7F00"),
        PURPLE("800080"),
        WHITE("FFFFFF"),
        BLACK("0"),
        CYAN("65535"),
        LIME("65280"),
        GREY("808080");
        
        private String hex;
        
        private MessageColor(String color) {
            this.hex = color;
        }
    
        public String getColor() {
            return this.hex;
        }
    
    }
    MessageCrowns.java:
    Code:
    package server.world.messages;
    
    public enum MessageCrowns {
    
        /**
         * You might have to update the int(s) to the correct crown id.
         */
        OWNER(1),
        MODERATOR(2),
        DONATOR(3);
        
        private int iconName;
        
        private MessageCrowns(int icon) {
            this.iconName = icon;
        }
    
        public int getRanking() {
            return this.iconName;
        }
    }
    Use(The boolean represents the use of crowns and the int represents the crown id):
    Code:
    Message.out(c, "RED", "Your message goes here", 1, true);
    OLD LAME CODE:

    Code:
    import server.model.players.Client;
    
    public class Message {
    
        public final static String
            RED = "ff0000", 
                GREEN = "00ff00", 
            YELLOW = "ffff00", 
                BLUE = "0000ff", 
            ORANGE = "ff7f00", 
                PURPLE = "800080", 
            WHITE = "ffffff", 
                GREY = "808080",
            BLACK = "000000";
        
        public static boolean out(Client player, String color, String message) {
            if (player.getOutStream() != null) {
                player.outStream.createFrameVarSize(253);
                player.outStream.writeString("<col="+color+">"+message+"</col>");
                player.outStream.endFrameVarSize();
            }
            return false;
        }
        
    }
    Use:
    Code:
    Message.out(c, Message.RED, "Your message goes here");

    Reply With Quote  
     

  2. #2  
    Banned

    Join Date
    Jul 2015
    Posts
    607
    Thanks given
    520
    Thanks received
    660
    Rep Power
    0
    why is it a boolean and why did u make an entire class for it lol
    also wrong section but thx for contributing
    Reply With Quote  
     

  3. #3  
    Banned

    Join Date
    Aug 2011
    Posts
    843
    Thanks given
    541
    Thanks received
    220
    Rep Power
    0
    Quote Originally Posted by Swiffy View Post
    why is it a boolean and why did u make an entire class for it lol
    also wrong section but thx for contributing
    i figured that since this is the snippets section, it would be the right section lol but okay and made a class so its less messy. Also thanks =) and boolean? I dont think I added one
    edit: just noticed its in the client section, oops
    Reply With Quote  
     

  4. #4  
    Community Veteran

    Dexter Morgan's Avatar
    Join Date
    Nov 2008
    Age
    28
    Posts
    4,419
    Thanks given
    1,184
    Thanks received
    757
    Rep Power
    3098
    Quote Originally Posted by iExample View Post
    i figured that since this is the snippets section, it would be the right section lol but okay and made a class so its less messy. Also thanks =) and boolean? I dont think I added one
    edit: just noticed its in the client section, oops
    You made the return type boolean of this method

    Code:
        public static boolean out(Client player, String color, String message) {
            if (player.getOutStream() != null) {
                player.outStream.createFrameVarSize(253);
                player.outStream.writeString("<col="+color+">"+message+"</col>");
                player.outStream.endFrameVarSize();
            }
            return false;
        }
    Reply With Quote  
     

  5. #5  
    Banned

    Join Date
    Aug 2011
    Posts
    843
    Thanks given
    541
    Thanks received
    220
    Rep Power
    0
    Quote Originally Posted by Dexter Morgan View Post
    You made the return type boolean of this method

    Code:
        public static boolean out(Client player, String color, String message) {
            if (player.getOutStream() != null) {
                player.outStream.createFrameVarSize(253);
                player.outStream.writeString("<col="+color+">"+message+"</col>");
                player.outStream.endFrameVarSize();
            }
            return false;
        }
    oh lol, yeah didn't see that
    Reply With Quote  
     

  6. #6  
    Registered Member Devo's Avatar
    Join Date
    Aug 2013
    Age
    25
    Posts
    514
    Thanks given
    38
    Thanks received
    47
    Rep Power
    70
    Code:
    public enum color {
    RED(new String[] {"FF0000"}),
    GREEN(new String[] {"00FF00"}),
    YELLOW(new String[] {"FFFF00"}),
    BLUE(new String[] {"0000FF"}),
    ORANGE(new String[] {"FF7F00"}),
    PURPLE(new String[] {"800080"}),
    WHITE(new String[] {"FFFFFF"}),
    GREY(new String[] {"808080"}),
    BLACK(new String[] {"0"});
    Code:
    public String[] colorName;
    Code:
    private ColorData(final String[] colorName) {
    this.colorName = colorName;
    }
    Enum?

    Reply With Quote  
     

  7. #7  
    ¯\_(ツ)_/¯


    Join Date
    Jul 2014
    Posts
    1,803
    Thanks given
    928
    Thanks received
    550
    Rep Power
    299
    Quote Originally Posted by Devo View Post
    Code:
    public enum color {
    RED(new String[] {"FF0000"}),
    GREEN(new String[] {"00FF00"}),
    YELLOW(new String[] {"FFFF00"}),
    BLUE(new String[] {"0000FF"}),
    ORANGE(new String[] {"FF7F00"}),
    PURPLE(new String[] {"800080"}),
    WHITE(new String[] {"FFFFFF"}),
    GREY(new String[] {"808080"}),
    BLACK(new String[] {"0"});
    Code:
    public String[] colorName;
    Code:
    private ColorData(final String[] colorName) {
    this.colorName = colorName;
    }
    Enum?

    That's a better way, but I don't know why you used a String[], you could've used integers, or just a normal String.

    Code:
    public enum Colors {
    RED("FF0000"),
    GREEN("00FF00"),
    YELLOW("FFFF00"),
    BLUE("0000FF"),
    ORANGE("FF7F00"),
    PURPLE("800080"),
    WHITE("FFFFFF"),
    GREEN("808080"),
    BLACK("0"),
    CYAN("65535"),
    LIME("65280"),
    ;
    private String color;
    
    private Colors(String colorValue) {
    this.color = colorValue;
    }
    
    public String getColor() {
    return "<col="+this.color+">";
    }
    }
    Code:
    c.sendMessage(""+Colors.RED.getColor()+"some text here lel.");
    *edited for easier use.



    IMO this is just overcomplicating things, and going to make your messages messy to read.
    Reply With Quote  
     

  8. #8  
    Banned

    Join Date
    Aug 2011
    Posts
    843
    Thanks given
    541
    Thanks received
    220
    Rep Power
    0
    Quote Originally Posted by GTFO View Post
    That's a better way, but I don't know why you used a String[], you could've used integers, or just a normal String.

    Code:
    public enum Colors {
    RED("FF0000"),
    GREEN("00FF00"),
    YELLOW("FFFF00"),
    BLUE("0000FF"),
    ORANGE("FF7F00"),
    PURPLE("800080"),
    WHITE("FFFFFF"),
    GREEN("808080"),
    BLACK("0"),
    CYAN("65535"),
    LIME("65280"),
    ;
    private String color;
    
    private Colors(String colorValue) {
    this.color = colorValue;
    }
    
    public String getColor() {
    return this.color;
    }
    }
    Code:
    c.sendMessage("<col="+Colors.RED.getColor()+">some text here lel.");


    IMO this is just overcomplicating things, and going to make your messages messy to read.
    Ahh, see i tried using an enum guys but didn't know how to make the string work with it. Thanks for pointing out the other ways of doing it, ill update it to the thread with my code =)
    good work
    Reply With Quote  
     

  9. #9  
    Registered Member Devo's Avatar
    Join Date
    Aug 2013
    Age
    25
    Posts
    514
    Thanks given
    38
    Thanks received
    47
    Rep Power
    70
    Quote Originally Posted by GTFO View Post
    That's a better way, but I don't know why you used a String[], you could've used integers, or just a normal String.
    It's just how I've always done it. Lol
    And using integers wouldn't work unless you were to start it with 0x###### because some hex codes start with letters, causing it to not be able to be read as an integer.

    -Edit
    It also depends what you have for a text engine, some use hexadecimal and some use decimal in their color codes. If you were to have the DECIMAL text engine, then you would be able to use integers no matter what, because there's no letter usage in the color codes.

    Reply With Quote  
     

  10. Thankful users:


  11. #10  
    Registered Member
    Join Date
    Oct 2012
    Posts
    205
    Thanks given
    10
    Thanks received
    17
    Rep Power
    30
    Thanks for the contribution

    Few improvements you could work on is that atm it's not that flexible. You have tons of colours you could choose from yet you're limiting them to ~10 and they're pretty standard colours. Instead of filling the enum with hundreds of elements for different colours, maybe add some extra parameter support for different colours. Also what if a player wants a message with multiple colours in it? This system wouldn't allow a player to do such a thing.

    Good stuff
    Reply With Quote  
     

Page 1 of 3 123 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [PI] Simple Music/Sound System
    By FuzzyAvacado in forum Tutorials
    Replies: 32
    Last Post: 07-25-2015, 09:34 PM
  2. [PI] Simple News Feed System
    By I'm A Jerk in forum Tutorials
    Replies: 9
    Last Post: 08-16-2012, 06:23 AM
  3. Adding A Simple Black Mark System [PI]
    By relex lawl in forum Snippets
    Replies: 5
    Last Post: 09-02-2011, 07:32 PM
  4. [PI]Simple but effective jailing system.[PI]
    By CoderNexus in forum Snippets
    Replies: 8
    Last Post: 07-02-2011, 11:58 PM
  5. [Pi] Changing the Color of Private Messages?
    By Jansen in forum Requests
    Replies: 8
    Last Post: 06-11-2011, 09:18 PM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •