Is there a way to block .sendMessage() from another plugin?

Discussion in 'Spigot Plugin Development' started by BlackBeltPanda, Jun 5, 2017.

  1. For plugins who send hardcoded (often less than ideally translated) messages to the player using player.sendMessage(), is there a way to get and block/cancel these?
  2. Cancel their packets? (Or somehow inject code in the CraftPlayer class)
  3. I tried to find a solution that didn't involve cancelling packets, but I didn't find any results.

    One option would be to extend the class sending the message, override the method that has the bad message code (& recode it) - And then replace the object of the plugin with your new object that extends the class.

    If the plugin is poorly divided into methods & has few methods for setting the variables, the replacing might be tricky.
    Accessing private fields & methods:

    If the method sending the message is static though.. no replacing that.
    • Like Like x 1
  4. Looks like the messages are hardcoded into the method, as well, so there's no variables to replace. =/
    It's along the format of:
    Code (Text):
    private void doStuff(String[] args){
        if (args.length > 1) player.sendMessage("Message");
  5. Ah dang so it's a command executor (or something similar), I think it might be possible to register another command on top of that with a replacing class

    Code (Text):
    public class NewClass extends OldClass {

    private void doStuff(String[] args){
        //Rewritten method

        if (args.length > 1) player.sendMessage("New Message");
    (I'm not sure if this will do anything since it's a private method)

    Code (Text):
    getPlugin(PluginInQuestion.class).getCommand("oldcommand").setExecutor(new NewClass());
    • Like Like x 1
  6. I'm pretty sure you can't override private methods. =/
  7. Why wouldn't you be able to? If you extend the class Im sure you would be able to Override it. You aren't overriding private methods, you are overriding the method and making it private.
    • Informative Informative x 1
  8. Thanks for the help. =)
    I decided to just fork it and modify the messages, at least for the time being.