Little potion help

Discussion in 'Plugin Development' started by ZomBlade_Shadow, May 9, 2015.

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

    ZomBlade_Shadow

    Hey!
    So I'm making a kitpvp plugin, with arenas and all.
    It's a potion pvp plugin, I want it so only your opponent and yourself can get healed by the thrown potions.
    Because there are going to be like 20 people in an arena, but i do .hidePlayer & .showPlayer so you can only see your opponent.
    With ProtocolLib, I removed the sounds and the particles to the other players that are hidden.
    Now I just need it so your opponent and yourself ONLY can get healed by the potions.
    I found a bit of code, but I don't know how to use it.
    Code:
    public void onPotionSplash(PotionSplashEvent e){
    
        Collection<LivingEntity> affected = e.getAffectedEntities();
    
        for(LivingEntity ent : affected){  //HERE
            if(ent instanceof Player){  //HERE         HOW CAN I ONLY GET PLAYER1 AND PLAYER2, AND NOT CANCEL THE EVENT? AND SET THE INTENSITY TO 0(CANCEL EVENT) FOR THE REST OF THE PLAYERS (so potions don't heal them)
                e.setIntensity(ent, 0); //HERE
            }
        }
    }
     
  2. Offline

    MrJossy

    Put permissions.
    Code:
    for(LivingEntity ent : affected){
            if(ent instanceof Player || p.hasPermission("this.use")){
                e.setIntensity(ent, 0);
            }
        }
    Also, you forgot the @EventHandler
    @ZomBlade_Shadow
     
  3. Offline

    Totom3

    No no no no, permissions are meant to be permanent, they were not made for this kind of things.

    @ZomBlade_Shadow Simply check if the LivingEntity is equal to player1 or player2:
    Code:
    for (LivingEntity entity: affectedEntities) {
        if (!entity.equals(<player1>) && !entity.equals(<player2>)) { // if the entity is not player1 nor player2
            // Cancel with setIntensity()
        }
    }
     
  4. Offline

    Garnetty

    Give me a min to look at something

    Yup just use a PotionSplashEvent and go for e.getAffectedEntities() and remove the player from it that you want

    maybe you can store the players in a map to check if they are player1 and player2

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  5. Offline

    ZomBlade_Shadow

    Thanks everyone! But I actually changed ideas and stuff, not going to be using this :p but this'll be useful to whoever has the same problem! <3
     
  6. Offline

    Garnetty

    I've had the same idea before but for my 1v1 plugin I ended up coding an arena class, if you need help going forwards send me a message
     
Thread Status:
Not open for further replies.

Share This Page