If NO block == 18

Discussion in 'Plugin Development' started by PauleFaule, Jan 8, 2014.

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

    PauleFaule

    Dear Community,

    today I created a plugin that hides players near leaves. But I don't know how to remove the invisibility when the leaves get out of the players radius. I tried:
    Code:java
    1. new BukkitRunnable() {
    2.  
    3. @Override
    4. public void run() {
    5. for (Player p : getServer().getOnlinePlayers()) {
    6. if (p.hasPermission("aresion.ranger")){
    7. Location location = p.getLocation();
    8. int r = 3;
    9.  
    10. int X = location.getBlockX();
    11. int Y = location.getBlockY();
    12. int Z = location.getBlockZ();
    13.  
    14. int x = (int) (X -r);
    15. int y = (int) (Y -r);
    16. int z = (int) (Z -r);
    17.  
    18. int bx = x;
    19. int bz = z;
    20.  
    21. for (int i = 0; i< r * 2+1; i++) {
    22. for (int j = 0; j< r * 2+1; j++) {
    23. for (int k = 0; k< r * 2+1; k++) {
    24.  
    25. Block block = p.getWorld().getBlockAt(x, y, z);
    26. if (block.getTypeId() == 18) {
    27. p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 15));
    28. [COLOR=#000000]} else if (!(block.getTypeId() == 18)){[/COLOR]
    29. if(p.hasPotionEffect(PotionEffectType.INVISIBILITY)){
    30. p.removePotionEffect(PotionEffectType.INVISIBILITY);
    31. }
    32. }
    33. x++;
    34. }
    35. z++;
    36. x = bx;
    37. }
    38. z = bz;
    39. x = bx;
    40. y++;
    41. }
    42.  
    43. }
    44.  
    45. }
    46. }
    47.  
    48. }.runTaskTimer(this, 1, 1);


    But the if(!(block.getTypeId() == 18)) doesn't mean that the action will get done if there is no Block == 18, but that the action will get done if any Block is != 18.

    What do I need to write to check if NO BLOCK == 18?

    Thanks in advance,

    PauleFaule
     
  2. Offline

    werter318

    I'm sorry but I don't understand what you mean, also doing these kind of calculations every tick, would lag your server I think.
     
  3. Offline

    Ytry

    So I am a little confused myself but I am assuming you want to remove their invisibility if they are not near leaves? My solution is to make a set of player names. Now what you will do with this is add players name to this set when they "hide in the leaves" then remove it when they have no leaves near them. You could check if they have no leaves nearby by making a for loop to loop through all the blocks around the player adding them to an array of locations. Then you could check if that array contains any leaves. This for loop could fire on events like player move event provided the players name is in the set of player names. I can help explain it a bit better if this is actually what you need.
     
  4. Offline

    Desle

    Pretty sure this will work fine;

    Every 2 sec or so, run a method that will check if the player is near leaves.. if so.. don't remove the potioneffect, if not, remove it?
     
    PauleFaule likes this.
  5. Offline

    Ytry

    That would work just fine but having a set of players that are hidden could be beneficial in the future. If he ever wanted to do more with those players like make them walk slower when hidden or something.
     
  6. Offline

    PauleFaule

    I'm just going to add the potion effect for 1 second or less... that will solve my problem
     
Thread Status:
Not open for further replies.

Share This Page