Solved Exclude event player

Discussion in 'Plugin Development' started by loman, Feb 26, 2020.

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

    loman

    How can I exclude myself bt included all the players online?
    I have tried doing in this way bt i fail.........
    Code:
    @EventHandler
        public void playerInteract(PlayerInteractEvent e) {
            Player player = e.getPlayer();
            for(Player other :  Bukkit.getOnlinePlayers()) {
                if (e.getAction() == Action.RIGHT_CLICK_AIR && player.getInventory().getItemInMainHand().equals(thor)) {
                    other.getWorld().strikeLightning(other.getLocation()) ;
                }
            }
     
  2. Offline

    timtower Administrator Administrator Moderator

    @loman If player.getUUID()==other.getUUID() continue?
     
  3. Offline

    loman

    @timtower thanks for your suggestion but i am new to bukkit plugins :(
    so where should i change :) and thx again
     
  4. Offline

    timtower Administrator Administrator Moderator

    @loman Has nothing to do with plugin, it is just java.
    First line inside of the loop.
     
  5. Offline

    loman

    @timtower
    hmmmmm
    actually i am new to java too XD
    so i should do in this way ? :)
    Code:
        @EventHandler
        public void playerInteract(PlayerInteractEvent e) {
            for(Player player = e.getPlayer();
            Player other :  Bukkit.getOnlinePlayers()) {
                if (e.getAction() == Action.RIGHT_CLICK_AIR && player.getInventory().getItemInMainHand().equals(thor)) {
                    other.getWorld().strikeLightning(other.getLocation()) ;
                }
            }
     
  6. Offline

    timtower Administrator Administrator Moderator

    @loman You might want to improve on your java first then. At least learn the basics.
    Because that won't compile.
    Your previous posted code was better.
     
  7. Offline

    loman

    @timtower
    I see and I will do it later : )
    So what should I correct in case I can exclude the event player? ._.
     
  8. Offline

    timtower Administrator Administrator Moderator

    @loman You check if the player uuid is the same as the other uuid, if so then you continue the loop.
     
  9. Offline

    loman

    @timtower

    oh! What a clever idea!
    But how if the uuid looped to the event player's?
    Will it continue looping to others?
     
  10. Offline

    timtower Administrator Administrator Moderator

    @loman You make an if statement.
    And that is an answer that you would have known if you knew basic java. Not gonna answer that one.
     
  11. Offline

    loman

    @timtower
    Ok~ thanks so much for your generous help~
     
Thread Status:
Not open for further replies.

Share This Page