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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.