perfectet colorjump timer, cancelled inventory movement
This commit is contained in:
@@ -8,6 +8,7 @@ import eu.mhsl.minenet.minigames.world.generator.terrain.CircularPlateTerrainGen
|
|||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.coordinate.Pos;
|
import net.minestom.server.coordinate.Pos;
|
||||||
import net.minestom.server.entity.GameMode;
|
import net.minestom.server.entity.GameMode;
|
||||||
|
import net.minestom.server.event.inventory.InventoryPreClickEvent;
|
||||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||||
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
@@ -41,6 +42,11 @@ public class ColorJump extends StatelessGame {
|
|||||||
this.getScore().setIgnoreLastPlayers(1);
|
this.getScore().setIgnoreLastPlayers(1);
|
||||||
|
|
||||||
this.setGenerator(new CircularPlateTerrainGenerator(100));
|
this.setGenerator(new CircularPlateTerrainGenerator(100));
|
||||||
|
|
||||||
|
this.eventNode().addListener(
|
||||||
|
InventoryPreClickEvent.class,
|
||||||
|
inventoryPreClickEvent -> inventoryPreClickEvent.setCancelled(true)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -55,10 +61,11 @@ public class ColorJump extends StatelessGame {
|
|||||||
|
|
||||||
private void nextRound() {
|
private void nextRound() {
|
||||||
this.generate();
|
this.generate();
|
||||||
|
do {
|
||||||
this.currentBlock = this.blocks.get(ThreadLocalRandom.current().nextInt(this.blocks.size()));
|
this.currentBlock = this.blocks.get(ThreadLocalRandom.current().nextInt(this.blocks.size()));
|
||||||
if(this.currentBlock == this.blockLastRound) this.nextRound();
|
} while(this.currentBlock == this.blockLastRound);
|
||||||
this.blockLastRound = this.currentBlock;
|
this.blockLastRound = this.currentBlock;
|
||||||
|
|
||||||
ItemStack item = ItemStack.of(Objects.requireNonNull(this.currentBlock.registry().material()));
|
ItemStack item = ItemStack.of(Objects.requireNonNull(this.currentBlock.registry().material()));
|
||||||
this.getPlayers().forEach(player -> {
|
this.getPlayers().forEach(player -> {
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
@@ -80,19 +87,18 @@ public class ColorJump extends StatelessGame {
|
|||||||
}, TaskSchedule.seconds(3));
|
}, TaskSchedule.seconds(3));
|
||||||
return stop;
|
return stop;
|
||||||
}, TaskSchedule.seconds((long) this.roundTime));
|
}, TaskSchedule.seconds((long) this.roundTime));
|
||||||
if(this.roundTime > 0.5)
|
|
||||||
this.roundTime = this.roundTime * this.multiplierNextRoundTime;
|
this.roundTime = this.roundTime * this.multiplierNextRoundTime;
|
||||||
|
if(this.roundTime <= 1) this.roundTime = 1;
|
||||||
|
|
||||||
long totalMillis = (long) (this.roundTime * 1000);
|
long totalTicks = (long) (this.roundTime * 20);
|
||||||
long startTime = System.currentTimeMillis();
|
final long[] remainingTicks = { totalTicks };
|
||||||
|
|
||||||
scheduler.scheduleTask(() -> {
|
scheduler.scheduleTask(() -> {
|
||||||
if (!this.isRunning) return stop;
|
|
||||||
|
|
||||||
long elapsed = System.currentTimeMillis() - startTime;
|
if (!this.isRunning)
|
||||||
long remaining = totalMillis - elapsed;
|
return stop;
|
||||||
|
|
||||||
if (remaining <= 0) {
|
if (remainingTicks[0] <= 0) {
|
||||||
this.getPlayers().forEach(player -> {
|
this.getPlayers().forEach(player -> {
|
||||||
player.setExp(0f);
|
player.setExp(0f);
|
||||||
player.setLevel(0);
|
player.setLevel(0);
|
||||||
@@ -100,14 +106,16 @@ public class ColorJump extends StatelessGame {
|
|||||||
return stop;
|
return stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
float progress = (float) remaining / totalMillis;
|
float progress = (float) remainingTicks[0] / totalTicks;
|
||||||
|
|
||||||
this.getPlayers().forEach(player -> {
|
this.getPlayers().forEach(player -> {
|
||||||
player.setExp(progress);
|
player.setExp(progress);
|
||||||
player.setLevel((int) Math.ceil(remaining / 1000.0));
|
player.setLevel((int) Math.ceil(remainingTicks[0] / 20.0));
|
||||||
});
|
});
|
||||||
return TaskSchedule.millis(50); // 1 Tick (20 TPS)
|
|
||||||
}, TaskSchedule.millis(0));
|
remainingTicks[0]--;
|
||||||
|
return TaskSchedule.tick(1);
|
||||||
|
}, TaskSchedule.tick(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generate() {
|
private void generate() {
|
||||||
|
|||||||
Reference in New Issue
Block a user