FirecatHD's Question Thread

Discussion in 'Plugin Development' started by FirecatHD, Nov 15, 2013.

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

    L33m4n123

    You would need to save the player in a List/Set once he typed /kit fragger and then basicly all you need to do is check if the List/Set contains the player launching the snowball if yes let it explode
     
  2. Offline

    FirecatHD

    L33m4n123
    An arrayList? In that case i am not sure how to do that, can you explain further?
     
  3. Offline

    L33m4n123

    Create the arrayList

    Code:java
    1. ArrayList<String> fraggerKit = new ArrayList<String>();


    and in the onCommand class you add the person to the ArrayList

    Code:java
    1. fraggerKit.add(player.getName());


    and in the event you check if the player is in there

    Code:java
    1. fraggerKit.contains(player.getName());


    If you copy&pase my code just like that it won't work. You will need to adjust it for your needs ofc.
     
  4. Offline

    FirecatHD

    L33m4n123
    This is what i came up with:
    Code:java
    1. package me.FirecatHD.TBS_PvP;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import org.bukkit.entity.HumanEntity;
    7. import org.bukkit.entity.LivingEntity;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.entity.Projectile;
    10. import org.bukkit.entity.Snowball;
    11. import org.bukkit.event.EventHandler;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.event.entity.ProjectileHitEvent;
    14.  
    15. public class BombListener implements Listener {
    16.  
    17. ArrayList<String> fraggerKit = new ArrayList<String>();
    18.  
    19. @EventHandler
    20. public void onProjectileHit(ProjectileHitEvent e) {
    21. Projectile p = e.getEntity();
    22. if (!(p.getShooter() instanceof Player)) return;
    23. if (!(p instanceof Snowball)) return;
    24. if(!p.getWorld().getName().equals("minigame")) return;
    25. Snowball s = (Snowball) p;
    26. if (!(fraggerKit.contains (((HumanEntity) p.getShooter()).getName())));
    27. s.getWorld().createExplosion(s.getLocation(), 0); {
    28.  
    29. List<org.bukkit.entity.Entity> nearbyEntities = s.getNearbyEntities(2, 2, 2);
    30. for (int i = 0; i < nearbyEntities.size(); i++) {
    31. if (nearbyEntities.get(i) instanceof LivingEntity) {
    32. LivingEntity living = (LivingEntity) nearbyEntities.get(i);
    33. living.damage(8D);
    34. }
    35. }
    36. }
    37. }
    38. }
    39.  


    But, how do i remove them from the arraylist after getting the kit? Because snowballs still explode.
     
  5. Offline

    L33m4n123

    fraggerKit.remove(player.getName());

    However the way you do it its not working. Since you check if it does NOT contain the player.

    You would need to create the ArrayList in the command class and refere to it from the Listener Class
     
  6. Offline

    FirecatHD

    L33m4n123
    Ok, but how do you reference? And where do i remove the player? Btw i am learning :D

    SkillSam L33m4n123
    Acually this was just what i did, but forgot to post (it was late) but even though i have created the method in the Listener, when i use it in the main class to add the player, eclipse says i have to create the method :confused:

    Help?

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

    FirecatHD

    SkillSam
    It asks for this
    Code:java
    1. public static List<String> getFraggerKit() {
    2. return fraggerKit;
     
Thread Status:
Not open for further replies.

Share This Page