1.15.2 Gapple enchant change help

Discussion in 'Spigot Plugin Development' started by Joshuak52, Feb 21, 2020.

Thread Status:
Not open for further replies.
  1. Hey so I wanted to make gapples less op for normal players on my server so this is what I came up with

    Code (Text):
    @EventHandler
        public void onGodApple(PlayerItemConsumeEvent event) {
            Player player = (Player) event.getPlayer();
            if(event.getItem().getType().equals(Material.ENCHANTED_GOLDEN_APPLE)) {
                if(!player.hasPermission("Guards.Trainee") || !player.hasPermission("Guards.Guard") || !player.hasPermission("Guards.HeadGuard")) {
                    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                        public void run() {
                            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "effect clear " + event.getPlayer().getName() + " resistance");
                            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "effect clear " + event.getPlayer().getName() + " absorption");
                        }
                    }, 10L);
                }
            }
        }
    but this is removing the effects even with players with the correct permissions
     
  2. because you're using or operants. this means that a player has to have all 3 of those permissions for nothing to happen. use &&
     
  3. As @Warren1001 said use the AND Operator
    Code (Java):
    if(!p.hasPermission("1") && !p.hasPermission("2") && !p.hasPermission("3")) {
    since the logical || operator doesn't check second condition if first condition is true. so let's say someone is guard, but no trainee, since he is not one of those (you choose OR), he will be cleared.
    -> Operators in Java

    Could you elaborate? Why does "or" mean that he has to have all 3 for nothing to happen?
     
    #3 Rawora, Feb 21, 2020
    Last edited: Feb 21, 2020
  4. no, he can think for himself. if he needs to post over a simple boolean value issue, hes not going to enjoy coding if he ever takes on any more difficult projects that require self thinking and self testing. encouraging him to think about why the player has to have all 3 ranks.
     
    • Agree Agree x 2
Thread Status:
Not open for further replies.