Solved Adding a new tag to HeroChat.

Discussion in 'Plugin Development' started by Me4502, Apr 14, 2013.

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

    Me4502

    Hi,

    So a few months ago I made a small custom plugin for a friend's server that I am hosting for him. Recently he has switched to HeroChat, which has caused my addition to the front of the chat to stop working. I was just adding the tag to the beginning of the chat message. On the HeroChat dbo page, I see
    Which leads me to believe it is possible to add my own tags to the plugin. If this is not possible, is there a workaround to still have my chat tag displayed?

    Thanks

    ~ Me4502.
     
  2. Offline

    Nitnelave

    You should have a look at how Factions or Towny add their prefix, and do the same for your plugin.
     
  3. Offline

    Me4502


    Thankyou :p

    I now feel like a complete idiot lol

    Edit:

    To any onlookers, you need to just make the modifications to their special chat event it seems.

    Edit: So I added a replacer for my tag, and nothing has happened. it doesn't seem the event is even called?

    Edit: The event is definately called. I am actually trying every possible method now to get it replaced, but nothing happens. Here is my method.

    Code:
        @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
        public void onChannelChatEvent(ChannelChatEvent event) {
     
            if(!shrines.config.showReligionInChat)
                return;
     
            for(Religion religion : shrines.config.religions) {
     
                if(!religion.isAMember(event.getSender().getPlayer()))
                    continue;
     
                String format = event.getFormat();
                String bukkitFormat = event.getBukkitFormat();
                String message = event.getMessage();
     
                format = format.replace("{religion}", ChatColor.translateAlternateColorCodes('&', religion.displayName));
                bukkitFormat = bukkitFormat.replace("{religion}", ChatColor.translateAlternateColorCodes('&', religion.displayName));
                message = message.replace("{religion}", ChatColor.translateAlternateColorCodes('&', religion.displayName));
     
                event.setFormat(format);
                event.setBukkitFormat(bukkitFormat);
                event.setMessage(message);
                return;
            }
     
            String format = event.getFormat();
            String bukkitFormat = event.getBukkitFormat();
            String message = event.getMessage();
     
            format = format.replace("{religion}", "");
            bukkitFormat = bukkitFormat.replace("{religion}", "");
            message = message.replace("{religion}", "");
     
            event.setFormat(format);
            event.setBukkitFormat(bukkitFormat);
            event.setMessage(message);
        }
    
     
  4. Offline

    Nitnelave

    Try with priority.HIGHEST, with event.setFormat
     
  5. Offline

    Me4502

    Just tried that, it doesn't work. Maybe I need to do something special for it to work with HeroChat?
     
  6. Offline

    Nitnelave

    That's how they do it in Factions, at least. I'm no expert, so I can't help you more than that. Have a look at other project's sources, to see how they do it.
     
  7. Offline

    devilquak

    Me4502

    They might be using something like Vault, which can override this stuff.
     
  8. Offline

    Me4502


    Hmm maybe. I ended up just using the normal chat event but calling it before HeroChat does its stuff, so I can't use it as a tag.. but it still shows up.
     
  9. Offline

    xize

    I use this to get the prefix and suffix from, and set though:

    Code:
         } else if(plugin.getServer().getPluginManager().isPluginEnabled("HeroChat")) {
          String herochat = Herochat.getChatService().getPlayerSuffix(e.getPlayer().getWorld(), e.getPlayer().getName());
          e.setMessage(ChatColor.translateAlternateColorCodes('&', getMessage(e.getMessage(), herochat)));
          for(Player p : Bukkit.getOnlinePlayers()) {
           if(e.getMessage().contains(p.getName())) {
            effects(p);
           } else {
            
           }
          }
    
    I used this for the PlayerChatEvent for highlight names:p
    but I believe you can also set a prefix or suffix or add it by getting it and replace it as String;)
     
  10. Offline

    Me4502


    Thanks, that looks like it will do something similar to what I've currently got, so I'll stick with what I have for now.

    If any mod sees this they can close it.
     
Thread Status:
Not open for further replies.

Share This Page