Damage Help! :)

Discussion in 'Plugin Development' started by MunchMallow, Jan 1, 2014.

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

    MunchMallow

    Hello all amazing people out there!
    I have been working on a plugin in a good amount of time​
    but i encountered this really annoying problem.​
    It has destroyed my day, lol xD​
    I wanted to know if there was a method to check if the player​
    is touching the particle effect, or something simillar.​
    I appreciate any possible help.​
    I havn't typed much in this thread, compared to my other threads.​
    The reason for that, is simply because I am lazy.​
    I apologize if you somehow get offended by this thread, hehe. ​
    By the way, this is not the whole code of course​
    -----------​
    Class
    Code:java
    1. @EventHandler
    2. public void onWandUse(PlayerInteractEvent event) {
    3. final Player p = event.getPlayer();
    4. if(event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
    5. if(event.getPlayer().getItemInHand().getType() == Material.STICK) {
    6. if (!delay.contains(p.getName())) {
    7. delay.add(p.getName());
    8.  
    9. Location elocation = p.getEyeLocation();
    10. BlockIterator blocksToAdd = new BlockIterator(elocation, 0.0D, 15);
    11. Location blockToAdd;
    12.  
    13. while(blocksToAdd.hasNext()) {
    14. blockToAdd = blocksToAdd.next().getLocation();
    15. p.getWorld().playEffect(blockToAdd, Effect.SMOKE, 0);
    16. p.getWorld().playEffect(blockToAdd, Effect.SMOKE, 0);
    17.  
    18. if ( ! blocksToAdd.hasNext()) {
    19. p.getWorld().playEffect(blockToAdd, Effect.POTION_BREAK, 1);
    20. p.getWorld().playSound(p.getLocation(), Sound.BAT_TAKEOFF, 1, 100);
    21.  
    22. } else if (delay.contains(p.getName())) {
    23. Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    24. @Override
    25. public void run() {
    26. delay.remove(p.getName());
    27. }
    28. }, 20);
    29. }
    30. }
    31. }
    32. }
    33. }
    34. }
    35. }
     
  2. Offline

    Windy Day

    As far as I know you can't. The best you can do is check if they are at or near the location where the particle effect is being played.
     
  3. Offline

    MunchMallow

    How would I do that? An example would be absolutely brilliant!
     
  4. Offline

    GyllieGyllie

    Just loop through all the online players and check their distance to the location to see if they touch it or not.

    Code:java
    1. for (Player p : Bukkit.getOnlinePlayers()){
    2. if (p.distance(location) <=3){
    3. //do what you need to do if in this case they are closer then 3 meters to that location
    4. }
    5. }
     
  5. Offline

    MunchMallow

    What if it were to be a zombie?
     
  6. Offline

    AoH_Ruthless

  7. Offline

    GyllieGyllie

    then you just loop through the living entities doing
    Code:java
    1. for (Entity entity : where.getWorld().getEntities()) {
    2.  
    3. }

    Then you need to check what kind of entity it is.
    Code:java
    1. if (entity.getType() == EntityType.Player || entity.getType() == EntityType.Zombie){
    2. }

    Then you just check the distance again doing
    Code:java
    1. if (entity.distance(location) <= 3){
    2. }
     
Thread Status:
Not open for further replies.

Share This Page