added playerrace and updated to version 26.2 #14
+43
-3
@@ -19,7 +19,9 @@ import net.minestom.server.item.Material;
|
|||||||
import net.minestom.server.timer.TaskSchedule;
|
import net.minestom.server.timer.TaskSchedule;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
class Pillars extends StatelessGame {
|
class Pillars extends StatelessGame {
|
||||||
@@ -27,6 +29,43 @@ class Pillars extends StatelessGame {
|
|||||||
private int spawnPosz = 0;
|
private int spawnPosz = 0;
|
||||||
private final int pillarSpacing = 10;
|
private final int pillarSpacing = 10;
|
||||||
private final int pillarRowCount = 5;
|
private final int pillarRowCount = 5;
|
||||||
|
private final int timeToNextItem = 5;
|
||||||
|
|
||||||
|
private static final Set<String> IGNORED_SUFFIXES = Set.of(
|
||||||
|
"_SWORD", "_PICKAXE", "_AXE", "_SHOVEL", "_HOE",
|
||||||
|
"_HELMET", "_CHESTPLATE", "_LEGGINGS", "_BOOTS",
|
||||||
|
"_BOAT", "_MINECART", "_BUCKET", "_SPAWN_EGG",
|
||||||
|
"_BANNER", "_CANDLE", "_PRESSURE_PLATE", "_TEMPLATE",
|
||||||
|
"_BUTTON", "_HARNESS"
|
||||||
|
);
|
||||||
|
|
||||||
|
private static final Set<Material> IGNORED_EXACT = Set.of(
|
||||||
|
Material.BOW, Material.CROSSBOW, Material.TRIDENT, Material.MACE, Material.SHIELD,
|
||||||
|
Material.SHEARS, Material.FLINT_AND_STEEL, Material.FISHING_ROD, Material.SADDLE,
|
||||||
|
Material.TURTLE_HELMET, Material.ELYTRA,
|
||||||
|
Material.LADDER, Material.VINE, Material.SCAFFOLDING, Material.TWISTING_VINES, Material.WEEPING_VINES,
|
||||||
|
Material.BAMBOO_RAFT,
|
||||||
|
Material.TNT, Material.SPAWNER, Material.END_PORTAL_FRAME,
|
||||||
|
Material.COMMAND_BLOCK, Material.CHAIN_COMMAND_BLOCK, Material.REPEATING_COMMAND_BLOCK,
|
||||||
|
Material.STRUCTURE_BLOCK, Material.STRUCTURE_VOID, Material.JIGSAW,
|
||||||
|
Material.BARRIER, Material.LIGHT, Material.DEBUG_STICK, Material.KNOWLEDGE_BOOK,
|
||||||
|
Material.BEDROCK, Material.AIR
|
||||||
|
);
|
||||||
|
|
||||||
|
private static final Set<Material> IGNORED_MATERIALS = new HashSet<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
for (Material material : Material.values()) {
|
||||||
|
String id = material.key().asString();
|
||||||
|
|
||||||
|
for (String suffix : IGNORED_SUFFIXES) {
|
||||||
|
if (id.endsWith(suffix.toLowerCase())) {
|
||||||
|
IGNORED_MATERIALS.add(material);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Pillars() {
|
public Pillars() {
|
||||||
super(Dimension.THE_END.key, "Pillars", new LastWinsScore());
|
super(Dimension.THE_END.key, "Pillars", new LastWinsScore());
|
||||||
@@ -90,14 +129,15 @@ class Pillars extends StatelessGame {
|
|||||||
|
|
||||||
MinecraftServer.getSchedulerManager().submitTask(() -> {
|
MinecraftServer.getSchedulerManager().submitTask(() -> {
|
||||||
List<Material> materials = Material.values().stream()
|
List<Material> materials = Material.values().stream()
|
||||||
.filter(material -> !material.equals(Material.AIR))
|
.filter(material -> !IGNORED_EXACT.contains(material))
|
||||||
|
.filter(material -> !IGNORED_MATERIALS.contains(material))
|
||||||
.toList();
|
.toList();
|
||||||
this.getPlayers().forEach(player -> {
|
this.getPlayers().forEach(player -> {
|
||||||
ItemStack item = ItemStack.of(materials.get(ThreadLocalRandom.current().nextInt(Material.values().toArray().length)));
|
ItemStack item = ItemStack.of(materials.get(ThreadLocalRandom.current().nextInt(materials.size())));
|
||||||
player.getInventory().addItemStack(item);
|
player.getInventory().addItemStack(item);
|
||||||
});
|
});
|
||||||
|
|
||||||
return TaskSchedule.seconds(5);
|
return TaskSchedule.seconds(this.timeToNextItem);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-10
@@ -2,7 +2,7 @@ package eu.mhsl.minenet.minigames.instance.game.stateless.types.playerRace;
|
|||||||
|
|
||||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||||
import eu.mhsl.minenet.minigames.score.LastWinsScore;
|
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
|
||||||
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
||||||
import eu.mhsl.minenet.minigames.util.CommonProperties;
|
import eu.mhsl.minenet.minigames.util.CommonProperties;
|
||||||
import net.minestom.server.coordinate.Pos;
|
import net.minestom.server.coordinate.Pos;
|
||||||
@@ -13,16 +13,18 @@ import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
|||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.WeakHashMap;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class PlayerRace extends StatelessGame {
|
public class PlayerRace extends StatelessGame {
|
||||||
|
Pupsi marked this conversation as resolved
Outdated
|
|||||||
private final int height = 64;
|
private final int height = 64;
|
||||||
private double zLine = 32;
|
private final Map<Player, Double> zLine = new WeakHashMap<>();
|
||||||
private double zSpawnPoint = 14.5;
|
private final Map<Player, Double> zSpawnPoint = new WeakHashMap<>();
|
||||||
private final int obstacleCount;
|
private final int obstacleCount;
|
||||||
|
|
||||||
|
Pupsi marked this conversation as resolved
Outdated
Pupsi
commented
Bei LastWinsScore gewinnt derjenige, der als letztes ins Ziel kommt... Bei LastWinsScore gewinnt derjenige, der als letztes ins Ziel kommt...
|
|||||||
public PlayerRace(int obstacleCount) {
|
public PlayerRace(int obstacleCount) {
|
||||||
super(Dimension.THE_END.key, "PlayerRace", new LastWinsScore());
|
super(Dimension.THE_END.key, "PlayerRace", new FirstWinsScore());
|
||||||
this.setGenerator(new PlayerRaceChunkgenerator(this.height, obstacleCount));
|
this.setGenerator(new PlayerRaceChunkgenerator(this.height, obstacleCount));
|
||||||
this.obstacleCount = obstacleCount;
|
this.obstacleCount = obstacleCount;
|
||||||
}
|
}
|
||||||
@@ -30,6 +32,8 @@ public class PlayerRace extends StatelessGame {
|
|||||||
@Override
|
@Override
|
||||||
protected boolean onPlayerJoin(Player p) {
|
protected boolean onPlayerJoin(Player p) {
|
||||||
p.setGameMode(GameMode.ADVENTURE);
|
p.setGameMode(GameMode.ADVENTURE);
|
||||||
|
this.zLine.put(p, 32.0);
|
||||||
|
this.zSpawnPoint.put(p, 14.5);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,19 +58,19 @@ public class PlayerRace extends StatelessGame {
|
|||||||
return new Pos(8, this.height + 1.5, 8);
|
return new Pos(8, this.height + 1.5, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pos getNewSpawn() {
|
public Pos getNewSpawn(Player player) {
|
||||||
return new Pos(8, this.height + 1.5, this.zSpawnPoint);
|
return new Pos(8, this.height + 1.5, this.zSpawnPoint.get(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||||
var player = playerMoveEvent.getPlayer();
|
var player = playerMoveEvent.getPlayer();
|
||||||
if(playerMoveEvent.getNewPosition().y() < this.height - 5)
|
if(playerMoveEvent.getNewPosition().y() < this.height - 5)
|
||||||
player.teleport(this.isBeforeBeginning ? this.getSpawn() : this.getNewSpawn());
|
player.teleport(this.isBeforeBeginning ? this.getSpawn() : this.getNewSpawn(player));
|
||||||
|
|
||||||
if(playerMoveEvent.getNewPosition().z() >= this.zLine && this.isRunning) {
|
if(playerMoveEvent.getNewPosition().z() >= this.zLine.get(player) && this.isRunning) {
|
||||||
this.zLine += 19;
|
this.zLine.merge(player, 19.0, Double::sum);
|
||||||
this.zSpawnPoint += 19;
|
this.zSpawnPoint.merge(player, 19.0, Double::sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(playerMoveEvent.getNewPosition().z() >= 16 + this.obstacleCount * 19 && this.isRunning) {
|
if(playerMoveEvent.getNewPosition().z() >= 16 + this.obstacleCount * 19 && this.isRunning) {
|
||||||
|
|||||||
Reference in New Issue
Block a user
Checkpoints sollten nicht global für alle Spieler gleich sein, sonst werden langsamere Spieler beim herunterfallen nach vorne teleportiert.