Finalized ColorJump #13
+19
-19
@@ -14,6 +14,7 @@ import net.minestom.server.event.player.PlayerSwapItemEvent;
|
||||
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.timer.Scheduler;
|
||||
import net.minestom.server.timer.TaskSchedule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -97,30 +98,29 @@ public class ColorJump extends StatelessGame {
|
||||
if(this.roundTime <= 1) this.roundTime = 1;
|
||||
|
||||
long totalTicks = (long) (this.roundTime * 20);
|
||||
|
MineTec marked this conversation as resolved
|
||||
final long[] remainingTicks = { totalTicks };
|
||||
this.scheduleExpUpdate(scheduler, totalTicks, totalTicks);
|
||||
}
|
||||
|
||||
scheduler.scheduleTask(() -> {
|
||||
|
||||
if (!this.isRunning)
|
||||
return stop;
|
||||
|
||||
if (remainingTicks[0] <= 0) {
|
||||
this.getPlayers().forEach(player -> {
|
||||
player.setExp(0f);
|
||||
player.setLevel(0);
|
||||
});
|
||||
return stop;
|
||||
}
|
||||
|
||||
float progress = (float) remainingTicks[0] / totalTicks;
|
||||
private void scheduleExpUpdate(Scheduler scheduler, long remainingTicks, long totalTicks) {
|
||||
if (!this.isRunning) return;
|
||||
|
||||
if (remainingTicks <= 0) {
|
||||
this.getPlayers().forEach(player -> {
|
||||
player.setExp(progress);
|
||||
player.setLevel((int) Math.ceil(remainingTicks[0] / 20.0));
|
||||
player.setExp(0f);
|
||||
player.setLevel(0);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
remainingTicks[0]--;
|
||||
return TaskSchedule.tick(1);
|
||||
float progress = (float) remainingTicks / totalTicks;
|
||||
|
||||
this.getPlayers().forEach(player -> {
|
||||
player.setExp(progress);
|
||||
player.setLevel((int) Math.ceil(remainingTicks / 20.0));
|
||||
});
|
||||
scheduler.scheduleTask(() -> {
|
||||
this.scheduleExpUpdate(scheduler, remainingTicks -1, totalTicks);
|
||||
return TaskSchedule.stop();
|
||||
}, TaskSchedule.tick(1));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user
andere Lösung für das effective-final wär schön
passt so?