Sending a message as a player

Discussion in 'Plugin Development' started by SniperBrob, Feb 15, 2014.

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

    SniperBrob

    Hey! So I'm working on making a chat filter plugin for my server, but I seem to be having one major problem with it. All of the players on my server have prefixes in EssentialsChat, so when I try to send a message as that player, I don't get their formatted chat with essentials chat. How can I do this? Does Essentials have some sort of API I can import to do this? Currently this is how I'm getting the player name:
    Code:
    string message = event.getMessage();
    string sender = event.getPlayer().getDisplayName();
    
    I'm making a chat filter plugin and I want it to be togglable per player. So if I say "fuck" one player will see "[Owner] Sniper » Fuck" and another will see "[Owner] Sniper » ****". Currently, if a censored worded is said in chat, players will see "Sniper Fuck" or "Sniper ****"
     
  2. Offline

    Arcoz

    Wait so you're trying to force another player to say something? SniperBrob
     
  3. Offline

    viper_monster

  4. Offline

    mastermustard

    Could you not just use the /sudo command from essentials?
     
  5. Offline

    SniperBrob

    I should have been a bit more specific. I'm making a chat filter plugin and I want it to be togglable per player. So if I say "fuck" one player will see "[Owner] Sniper » Fuck" and another will see "[Owner] Sniper » ****". Currently, if a censored worded is said in chat, players will see "Sniper Fuck" or "Sniper ****"
     
  6. Offline

    Bionicrm

    I'm thinking you'll have to disable chat all together and manage it yourself, unless there is a way to set the message in an AsyncPlayChatEvent for a specific player that I don't know about. But if there isn't, I'd say you send the player who sent the original message their own message, then for each online player, send them the filtered message.
     
  7. Offline

    SniperBrob

    Bionicrm that kinda defeats the whole point of my plugin. I would like for the filter to be togglable so some players dont have to see all the swears in the chat, but still allow players to express themselves freely
     
  8. Offline

    Bionicrm

    SniperBrob Well for players to toggle it, you'd just put their name and true/false in a HashMap.
     
  9. Offline

    SniperBrob

    Bionicrm Anddddddd you've lost me. What in Sam Hell is a HashMap? :p I think this plugin may have been a little too much to take on as my first one.
     
  10. Offline

    Bionicrm

    A HashMap is a key & value... map? It will store something as a key, and when you get that key, it will return a value. So when the player types the command to toggle it, just use something like playerCurseToggles.put(player.getName(), true).
     
  11. Offline

    idontcare1025

    Cancel the event. Then use this:
    Code:java
    1. for (Player p : getServer().getOnlinePlayers()) {
    2. if (p.hasPermission("mature") {
    3. p.sendMessage(message);
    4. } else p.sendMessage(filtered message);
    5. }

    Not sure if it's getServer().getOnlinePlayers(), but I know it's something like that.
     
  12. Offline

    SniperBrob

    idontcare1025 but how does that help with my problem? I need the filtered messaged to have the players prefix and suffix. Actually... I think I may have just thought of a way. Is there any method to get what group a user is in (GroupManager)? If so, I can easily fix this issue
     
  13. Offline

    mazentheamazin

  14. Offline

    alex123099

    Use vault:
    Code:
    public static Chat chat = null;
    private boolean setupChat()
        {
            RegisteredServiceProvider<Chat> chatProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.chat.Chat.class);
            if (chatProvider != null) {
                chat = chatProvider.getProvider();
            }
     
            return (chat != null);
        }
     
    
    then you have a getPrefix method.
     
  15. Offline

    CubieX

    You also need to hook into vaults permission API to get the players group and then assemble everything to look like the original message format.
     
Thread Status:
Not open for further replies.

Share This Page