0

I have a DataHolders class. It contains:

public static boolean hit;

In my other class theres:

public void onHit(ProjectileHitEvent event) {
    if (event.getHitEntity() != null || event.getHitBlock() != null) {
        DataHolders.hit = true;
    }
}

ProjectileHitEvent gets triggered when a Player hits something with a Projectile (Arrow)

In my last class:

public void onLaunch(ProjectileLaunchEvent event) {
    while (!DataHolders.hit) {
        //..............
    }
}

ProjectileLaunchEvent gets triggered when a Player launches the Projectile (Arrow)

I want to do something while the Projectile (Arrow) is in the air (ProjectileLaunchEvent triggered but ProjectileHitEvent not). But when the Arrow hits something (ProjectileHitEvent gets triggered and boolean hit becomes true) the loop should stop but the while loop goes on. I've already tested if ProjectileHitEvent really gets triggered, it works but the loop doesn't.

Hulk
  • 6,399
  • 1
  • 30
  • 52
zSxmpt
  • 9
  • 2

1 Answers1

0

check if DataHolders.hit is true/false.

public void onLaunch(ProjectileLaunchEvent event) {
    while (!DataHolders.hit) {
        System.out.println(DataHolders.hit);
        //..............
    }
}

If true

You should focus on setting DataHolders.hit properly

If false

Print the value before/after setting the value

public void onHit(ProjectileHitEvent event) {
    if (event.getHitEntity() != null || event.getHitBlock() != null) {
        System.out.println(DataHolders.hit);
        DataHolders.hit = true;
        System.out.println(DataHolders.hit);
    }
}

If the latter output is true then there is a problem with the class where public static boolean hit; exists.