How to remove certain messages from players without the permission

Discussion in 'Plugin Development' started by AmethystBrake22, May 24, 2022.

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

    AmethystBrake22

    I need help making a plugin where when a player types in chat "fly on" or "fly off" it toggles their fly, I have already figured out the permissions and I need help figuring out how to make it so only players that have a permission can see the messages "fly on" or "fly off" here is my code so far:
    @EventHandlerpublic void onChat(PlayerChatEvent event) {
    Player player = event.getPlayer(); if (event.getMessage().equalsIgnoreCase("fly on")) {
    if (player.hasPermission("FlyPlugin.ChatToFly")) {
    event.getPlayer().setAllowFlight(true);event.getRecipients().removeIf(player -> player.getName().equals(event.getPlayer().getName()) || !player.isOp());
    } else {
    player.sendMessage(ChatColor.RED + "You do not have permission to toggle fly");
    }
    } else {
    }
    }
    }


    And it keeps giving me the message:
    "variable player is already defined in method onChat(org.bukkit.event.player.PlayerChatEvent)"
    and I cant seem to fix it (Probably because I'm beginner) so I came here for somebody else's help because searching on google didn't get me anywhere.
     
  2. Offline

    Shqep

    @AmethystBrake22
    That message means that you already have a variable named "player" already, you can't use the name anymore. Like you have
    Player player = event.getPlayer();

    So when you use the lambda player -> player.getName()... it doesn't work, because the name conflicts.
     
    Last edited: May 25, 2022
Thread Status:
Not open for further replies.

Share This Page