How to change the "You don't have permission for this area." message?

Discussion in 'Plugin Development' started by BrassDuck, May 19, 2013.

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

    BrassDuck

    I was wondering how you would change the "You dont have permission for this area." message created by world guard.
     
    gogobebe2 likes this.
  2. Offline

    rsod

    it's hardcoded so only way is decompile classes with message, change and compile again
     
    gogobebe2 likes this.
  3. Offline

    BrassDuck

    Where would the code be? I could open the code with jd-gui and edit it with eclipse.
     
    gogobebe2 likes this.
  4. Offline

    Cirno

    Not necessarily true.

    If WorldGuard stores the message in a variable, you can use the Reflection API to "forcefully" change the string to something else. Do note that the Reflection API isn't nice and bites a lot (it has a lot of exceptions that can be thrown).
     
    gogobebe2 likes this.
  5. Offline

    Minnymin3

    Last edited by a moderator: Jun 1, 2016
    gogobebe2 likes this.
  6. Offline

    Comphenix

    You could also intercept the chat packet and modify the message there:
    Code:java
    1. @Override
    2. public void onEnable() {
    3. ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(this, ConnectionSide.SERVER_SIDE, Packets.Server.CHAT) {
    4. @Override
    5. public void onPacketSending(PacketEvent event) {
    6. String message = event.getPacket().getStrings().read(0);
    7.  
    8. // Modify this exact message regardless of the coloring
    9. if ("You don't have permission for this area.".equals(ChatColor.stripColor(message))) {
    10. event.getPacket().getStrings().write(0, "Stop it! No peeking behind the curtain!");
    11. }
    12. }
    13. });
    14. }
    15.  
    16. @Override
    17. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    18. sender.sendMessage(ChatColor.RED + "You don't have permission for this area.");
    19. return true;
    20. }
     
    gogobebe2, rsod and Minnymin3 like this.
  7. Offline

    skipperguy12

    Or you can just download the source from git, change what you need, and run mvn package with Maven and compile it.
     
    gogobebe2 likes this.
  8. Offline

    Minnymin3

    But then you have to distribute your own version of WorldGuard which is inconvenient for users (assuming the plugin is public)
     
    gogobebe2 likes this.
  9. Offline

    rsod

    best way is modify source so it will be using config file for messages and send it to developer so he will apply it
     
    gogobebe2 likes this.
Thread Status:
Not open for further replies.

Share This Page