[Plugin] [HELP]

Discussion in 'Plugin Development' started by egetheking, Oct 29, 2013.

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


    I have a minigame server..
    And i have alot of minigames!
    But i dont like the [SurvivalGames] [Spleef] Prefixes
    I want to change the colors on the prefixes in the Main file!
    How do i change it?

    Help [zombie]

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 5, 2016
  2. Offline


    You could try something with protocollib to alter the chat packets. It's possible since I've done it before.
    Here's what I did (this is actually just copy-pasted from a custom plugin I made, but it should be very easy to understand):
    1. private ProtocolManager protocolManager;
    3. public void onLoad() {
    4. protocolManager = ProtocolLibrary.getProtocolManager();
    5. }
    7. public void onEnable(){
    8. if(!new File(getDataFolder(), "config.yml").exists()){
    9. saveDefaultConfig();
    10. reloadConfig();
    11. }
    12. protocolManager.addPacketListener(new PacketAdapter(this,
    13. ConnectionSide.CLIENT_SIDE, ListenerPriority.NORMAL,
    14. Packets.Client.CHAT) {
    15. @Override
    16. public void onPacketReceiving(PacketEvent event) {
    17. if (event.getPacketID() == Packets.Client.CHAT) {
    18. PacketContainer packet = event.getPacket();
    19. String message = packet.getStrings().read(0);
    20. String list1 = getConfig().getString("DenyCreds");
    21. String fin = ChatColor.translateAlternateColorCodes('&', list1);
    22. if(message.contains(fin)){
    23. message.replaceAll(message, "");
    24. event.setCancelled(true);
    25. }
    26. }
    27. }
    28. });
    29. }

    What this does is grabs the string from the config, checks if the config's string is in the message, and if so, cancels the message (does not display message). You can use this code to make the config into a list (or not), and have it detect if the string contains [SurvivalGames] and alter the color by replacing text.
    Something to note is that (at least from my knowledge) you can't check if a player's name is included- unless directly in the message. For example:
    [default]noobboon: Hello!
    "Hello!" is the only thing you can check. You can't check if the player sent the message through protocollib from my understanding.
    There is an event called AsyncPlayerChatEvent, so that may come to hand in terms of checking if a player sent it or not.
    In any case, good luck.
    Protocollib: http://dev.bukkit.org/bukkit-plugins/protocollib/
    sgavster likes this.
  3. Offline


    But i need to paste this to all my plugins?

    Or just create a plugin that will change the prefix of the minigame when the message runs

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 5, 2016
  4. Offline


Thread Status:
Not open for further replies.

Share This Page