Special characters in chat...

Discussion in 'Plugin Development' started by ZeusAllMighty11, Jan 20, 2013.

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

    ZeusAllMighty11

    [​IMG]


    The original thread by Father Of Time who seems to have disappeared from the face of the earth, got me wondering how to do this with other characters...

    I skimmed the thread, but it seemed like too much work for what I was trying to achieve.

    Code:
     public void ModifyAllowedCharacters() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException
     {
      Field field = SharedConstants.class.getDeclaredField("allowedCharacters");
      field.setAccessible(true);
      Field modifiersField = Field.class.getDeclaredField( "modifiers" );
      modifiersField.setAccessible( true );
      modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
      String oldallowedchars = (String)field.get(null);
      String suits = "\u2665\u2666\u2663\u2660";
      StringBuilder sb = new StringBuilder();
      sb.append( oldallowedchars );
      sb.append( suits );
      field.set( null, sb.toString() );
     }
    
    This is what it came down to, but I'm just curious why so much work for something that could probably be more simple?
     
  2. Offline

    gomeow

    Do you just need to call that once to allow more characters?
     
  3. Offline

    camyono

    ZeusAllMighty11 Maybe you should understand what it does to understand why so much work is needed.
    The class "net.minecraft.server.SharedConstants" is not a bukkit class. As long as bukkit builds on the mc server there is no other way to access the field "allowedCharacters" which holds the characters.

    gomeow yes, everytime you add new ones.
     
  4. Offline

    d33k40

    that screen is mine dude :) if you want the implementation just pm me.

    Well ill post her how i implement this (The code That @Father Of Time do)

    Atention, i do this in 1.2.5 and just to test @Father Of Time code.

    In your main class
    Code:
        //The code below is made by "Father Of Time" on bukkit forum.
        //Thanks you.
        public void ModifyAllowedCharacters() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException
        {
        Field field = SharedConstants.class.getDeclaredField("allowedCharacters");
        field.setAccessible(true);
        Field modifiersField = Field.class.getDeclaredField( "modifiers" );
        modifiersField.setAccessible( true );
        modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
        String oldallowedchars = (String)field.get(null);
        String suits = "\u2665\u2666\u2663\u2660\u263A\u263B\u266A\u266B\u2642\u2640\u2625\u2680\u2681\u2682\u2683\u2684\u2685";
        StringBuilder sb = new StringBuilder();
        sb.append( oldallowedchars );
        sb.append( suits );
        field.set( null, sb.toString() );
        }
    Then i test it in a PlayerChatEvent
    Code:
    @EventHandler
        public void Chat(PlayerChatEvent event){
            String mensaje = event.getMessage();
            Player player = event.getPlayer();
           
            char cara1 = 0x263A;
            char cara2 = 0x263B;
            char nota1 = 0x266A;
            char nota2 = 0x266B;
            char corazon = 0x2665;
            char rombo = 0x2666;
            char trebol = 0x2663;
            char picas = 0x2660;
            char hombre = 0x2642;
            char mujer = 0x2640;
            char ankh = 0x2625;
             
            char die1 = 0x2680;
            char die2 = 0x2681;
            char die3 = 0x2682;
            char die4 = 0x2683;
            char die5 = 0x2684;
            char die6 = 0x2685;
             
            if(player.isOp()){
                mensaje = mensaje.replace(":c1:", Character.toString(cara1));
                mensaje = mensaje.replace(":c2:", Character.toString(cara2));
                mensaje = mensaje.replace(":n1:", Character.toString(nota1));
                mensaje = mensaje.replace(":n2:", Character.toString(nota2));
                mensaje = mensaje.replace(":c:", Character.toString(corazon));
                mensaje = mensaje.replace(":r:", Character.toString(rombo));
                mensaje = mensaje.replace(":t:", Character.toString(trebol));
                mensaje = mensaje.replace(":p:", Character.toString(picas));
                mensaje = mensaje.replace(":h:", Character.toString(hombre));
                mensaje = mensaje.replace(":m:", Character.toString(mujer));
                mensaje = mensaje.replace(":ankh:", Character.toString(ankh));
               
                mensaje = mensaje.replace(":die1:", Character.toString(die1));
                mensaje = mensaje.replace(":die2:", Character.toString(die2));
                mensaje = mensaje.replace(":die3:", Character.toString(die3));
                mensaje = mensaje.replace(":die4:", Character.toString(die4));
                mensaje = mensaje.replace(":die5:", Character.toString(die5));
                mensaje = mensaje.replace(":die6:", Character.toString(die6));
               
                event.setMessage(mensaje);
            }
        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
    ZeusAllMighty11 likes this.
  5. Offline

    CoderCloud

    I edited the code, so you dont have to change the imports for the plugin.
    That means that plugins dont have to be updated for every bukkit version.

    Code:java
    1.  
    2. //The code below is made by "Father Of Time" on bukkit forum (edited by "CoderCloud").
    3. //Thanks you.
    4. public void modifyAllowedCharacters() throws Exception{
    5. String pack = Bukkit.getServer().getClass().getName();
    6. pack = (pack = pack.substring(0, pack.lastIndexOf("."))).substring(pack.lastIndexOf(".") + 1, pack.length());
    7. Class<?> c = getClass().getClassLoader().loadClass("net.minecraft.server." + pack + ".SharedConstants");
    8. Field f = c.getDeclaredField("allowedCharacters");
    9. f.setAccessible(true);
    10. Field mod = Field.class.getDeclaredField("modifiers");
    11. mod.setAccessible(true);
    12. mod.setInt(f, f.getModifiers() & ~Modifier.FINAL);
    13. String s = (String) f.get(null);
    14. s = s + "\u2665\u2666\u2663\u2660\u263A\u263B\u266A\u266B\u2642\u2640\u2625\u2680\u2681\u2682\u2683\u2684\u2685";
    15. f.set(null, s);
    16. }
    17.  
     
  6. Offline

    xize

  7. Offline

    creepers84

    You guys are really making this hard for yourselves. Read up on UTF-8 characters and implement them into the code replacing the chat with those symbols. You do not require any code in order to use these symbols!
    Utf Symbols : u2460: ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑪ ⑫ ⑬ ⑭ ⑮ ⑯ ⑰ ⑱ ⑲ ⑳ ⑴ ⑵ ⑶ ⑷ ⑸ ⑹ ⑺ ⑻ ⑼ ⑽ ⑾ ⑿
    u2480: ⒀ ⒁ ⒂ ⒃ ⒄ ⒅ ⒆ ⒇ ⒈ ⒉ ⒊ ⒋ ⒌ ⒍ ⒎ ⒏ ⒐ ⒑ ⒒ ⒓ ⒔ ⒕ ⒖ ⒗ ⒘ ⒙ ⒚ ⒛ ⒜ ⒝ ⒞ ⒟
    u24A0: ⒠ ⒡ ⒢ ⒣ ⒤ ⒥ ⒦ ⒧ ⒨ ⒩ ⒪ ⒫ ⒬ ⒭ ⒮ ⒯ ⒰ ⒱ ⒲ ⒳ ⒴ ⒵ Ⓐ Ⓑ Ⓒ Ⓓ Ⓔ Ⓕ Ⓖ Ⓗ Ⓘ Ⓙ
    u24C0: Ⓚ Ⓛ Ⓜ Ⓝ Ⓞ Ⓟ Ⓠ Ⓡ Ⓢ Ⓣ Ⓤ Ⓥ Ⓦ Ⓧ Ⓨ Ⓩ ⓐ ⓑ ⓒ ⓓ ⓔ ⓕ ⓖ ⓗ ⓘ ⓙ ⓚ ⓛ ⓜ ⓝ ⓞ ⓟ
    u24E0: ⓠ ⓡ ⓢ ⓣ ⓤ ⓥ ⓦ ⓧ ⓨ ⓩ ⓪ ⓫ ⓬ ⓭ ⓮ ⓯ ⓰ ⓱ ⓲ ⓳ ⓴ ⓵ ⓶ ⓷ ⓸ ⓹ ⓺ ⓻ ⓼ ⓽ ⓾ ⓿
    u2500: ─ ━ │ ┃ ┄ ┅ ┆ ┇ ┈ ┉ ┊ ┋ ┌ ┍ ┎ ┏ ┐ ┑ ┒ ┓ └ ┕ ┖ ┗ ┘ ┙ ┚ ┛ ├ ┝ ┞ ┟
    u2520: ┠ ┡ ┢ ┣ ┤ ┥ ┦ ┧ ┨ ┩ ┪ ┫ ┬ ┭ ┮ ┯ ┰ ┱ ┲ ┳ ┴ ┵ ┶ ┷ ┸ ┹ ┺ ┻ ┼ ┽ ┾ ┿
    u2540: ╀ ╁ ╂ ╃ ╄ ╅ ╆ ╇ ╈ ╉ ╊ ╋ ╌ ╍ ╎ ╏ ═ ║ ╒ ╓ ╔ ╕ ╖ ╗ ╘ ╙ ╚ ╛ ╜ ╝ ╞ ╟
    u2560: ╠ ╡ ╢ ╣ ╤ ╥ ╦ ╧ ╨ ╩ ╪ ╫ ╬ ╭ ╮ ╯ ╰ ╱ ╲ ╳ ╴ ╵ ╶ ╷ ╸ ╹ ╺ ╻ ╼ ╽ ╾ ╿
    u2580: ▀ ▁ ▂ ▃ ▄ ▅ ▆ ▇ █ ▉ ▊ ▋ ▌ ▍ ▎ ▏ ▐ ░ ▒ ▓ ▔ ▕ ▖ ▗ ▘ ▙ ▚ ▛ ▜ ▝ ▞ ▟
    u25A0: ■ □ ▢ ▣ ▤ ▥ ▦ ▧ ▨ ▩ ▪ ▫ ▬ ▭ ▮ ▯ ▰ ▱ ▲ △ ▴ ▵ ▶ ▷ ▸ ▹ ► ▻ ▼ ▽ ▾ ▿
    u25C0: ◀ ◁ ◂ ◃ ◄ ◅ ◆ ◇ ◈ ◉ ◊ ○ ◌ ◍ ◎ ● ◐ ◑ ◒ ◓ ◔ ◕ ◖ ◗ ◘ ◙ ◚ ◛ ◜ ◝ ◞ ◟
    u25E0: ◠ ◡ ◢ ◣ ◤ ◥ ◦ ◧ ◨ ◩ ◪ ◫ ◬ ◭ ◮ ◯ ◰ ◱ ◲ ◳ ◴ ◵ ◶ ◷ ◸ ◹ ◺ ◻ ◼ ◽ ◾ ◿
    u2600: ☀ ☁ ☂ ☃ ☄ ★ ☆ ☇ ☈ ☉ ☊ ☋ ☌ ☍ ☎ ☏ ☐ ☑ ☒ ☓ ☔ ☕ ☖ ☗ ☘ ☙ ☚ ☛ ☜ ☝ ☞ ☟
    u2620: ☠ ☡ ☢ ☣ ☤ ☥ ☦ ☧ ☨ ☩ ☪ ☫ ☬ ☭ ☮ ☯ ☰ ☱ ☲ ☳ ☴ ☵ ☶ ☷ ☸ ☹ ☺ ☻ ☼ ☽ ☾ ☿
    u2640: ♀ ♁ ♂ ♃ ♄ ♅ ♆ ♇ ♈ ♉ ♊ ♋ ♌ ♍ ♎ ♏ ♐ ♑ ♒ ♓ ♔ ♕ ♖ ♗ ♘ ♙ ♚ ♛ ♜ ♝ ♞ ♟
    u2660: ♠ ♡ ♢ ♣ ♤ ♥ ♦ ♧ ♨ ♩ ♪ ♫ ♬ ♭ ♮ ♯ ♰ ♱ ♲ ♳ ♴ ♵ ♶ ♷ ♸ ♹ ♺ ♻ ♼ ♽ ♾ ♿
    u2680: ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚆ ⚇ ⚈ ⚉ ⚊ ⚋ ⚌ ⚍ ⚎ ⚏ ⚐ ⚑ ⚒ ⚓ ⚔ ⚕ ⚖ ⚗ ⚘ ⚙ ⚚ ⚛ ⚜ ⚝ ⚞ ⚟
    u26A0: ⚠ ⚡ ⚢ ⚣ ⚤ ⚥ ⚦ ⚧ ⚨ ⚩ ⚪ ⚫ ⚬ ⚭ ⚮ ⚯ ⚰ ⚱ ⚲ ⚳ ⚴ ⚵ ⚶ ⚷ ⚸ ⚹ ⚺ ⚻ ⚼ ⚽ ⚾ ⚿
    u2700: ✀ ✁ ✂ ✃ ✄ ✅ ✆ ✇ ✈ ✉ ✊ ✋ ✌ ✍ ✎ ✏ ✐ ✑ ✒ ✓ ✔ ✕ ✖ ✗ ✘ ✙ ✚ ✛ ✜ ✝ ✞ ✟
    u2720: ✠ ✡ ✢ ✣ ✤ ✥ ✦ ✧ ✨ ✩ ✪ ✫ ✬ ✭ ✮ ✯ ✰ ✱ ✲ ✳ ✴ ✵ ✶ ✷ ✸ ✹ ✺ ✻ ✼ ✽ ✾ ✿
    u2740: ❀ ❁ ❂ ❃ ❄ ❅ ❆ ❇ ❈ ❉ ❊ ❋ ❌ ❍ ❎ ❏ ❐ ❑ ❒ ❓ ❔ ❕ ❖ ❗ ❘ ❙ ❚ ❛ ❜ ❝ ❞ ❟
    u2760: ❠ ❡ ❢ ❣ ❤ ❥ ❦ ❧ ❨ ❩ ❪ ❫ ❬ ❭ ❮ ❯ ❰ ❱ ❲ ❳ ❴ ❵ ❶ ❷ ❸ ❹ ❺ ❻ ❼ ❽ ❾ ❿
    u2780: ➀ ➁ ➂ ➃ ➄ ➅ ➆ ➇ ➈ ➉ ➊ ➋ ➌ ➍ ➎ ➏ ➐ ➑ ➒ ➓ ➔ ➕ ➖ ➗ ➘ ➙ ➚ ➛ ➜ ➝ ➞ ➟
    u27A0: ➠ ➡ ➢ ➣ ➤ ➥ ➦ ➧ ➨ ➩ ➪ ➫ ➬ ➭ ➮ ➯ ➰ ➱ ➲ ➳ ➴ ➵ ➶ ➷ ➸ ➹ ➺ ➻ ➼ ➽ ➾ ➿
    (Just copy and paste them into your code allowing the utf characters on export!)
    Link: http://www.csbruce.com/software/utf-8.html
     
Thread Status:
Not open for further replies.

Share This Page