added pillars and block battle #10

Merged
jannis merged 7 commits from develop-pillars into develop 2026-02-02 19:09:44 +00:00
4 changed files with 58 additions and 58 deletions
Showing only changes of commit 11ddd01470 - Show all commits

View File

@@ -3,6 +3,7 @@ package eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBattle;
import eu.mhsl.minenet.minigames.instance.Dimension;
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
import eu.mhsl.minenet.minigames.util.BatchUtil;
import io.github.togar2.pvp.events.FinalAttackEvent;
import io.github.togar2.pvp.feature.CombatFeatures;
import net.minestom.server.coordinate.Pos;
@@ -11,6 +12,7 @@ import net.minestom.server.entity.Player;
import net.minestom.server.event.player.PlayerBlockBreakEvent;
import net.minestom.server.event.player.PlayerBlockPlaceEvent;
import net.minestom.server.event.player.PlayerMoveEvent;
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
import net.minestom.server.instance.block.Block;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
@@ -21,7 +23,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
public class BlockBattle extends StatelessGame {
private final Team teamBlue = new Team(new Pos(0,101,20).add(0.5), Team.Color.BLUE);
private final Team teamBlue = new Team(new Pos(0,101,20).add(0.5).withView(180, 0), Team.Color.BLUE);
private final Team teamRed = new Team(new Pos(0, 101, -20).add(0.5), Team.Color.RED);
private final int itemCount;
@@ -49,7 +51,42 @@ public class BlockBattle extends StatelessGame {
@Override
jannis marked this conversation as resolved
Review

generateWorld wird nur hier aufgerufen, der code von generateWorld kann also direkt hier in onLoad, ohne extra Methode.

generateWorld wird nur hier aufgerufen, der code von generateWorld kann also direkt hier in onLoad, ohne extra Methode.
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
this.generateWorld();
this.generatePlatform(new Pos(0, 100, 0), Block.GOLD_BLOCK, Block.YELLOW_CONCRETE_POWDER);
this.generatePlatform(new Pos(0, 101, 0), Block.AIR, Block.SANDSTONE_SLAB);
this.generatePlatform(new Pos(0, 100, 20), Block.BLUE_CONCRETE, Block.BLUE_CONCRETE_POWDER);
this.generatePlatform(new Pos(0, 100, -20), Block.RED_CONCRETE, Block.RED_CONCRETE_POWDER);
this.generatePlatform(new Pos(-5, 101, -14), Block.RED_STAINED_GLASS, Block.AIR);
this.generatePlatform(new Pos(5, 101, 14), Block.BLUE_STAINED_GLASS, Block.AIR);
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
Pos[] positionsRedGlass = {
new Pos(2, 102, -9),
new Pos(-1, 103, -9),
new Pos(-2, 104, -6),
new Pos(-5, 103, -7),
new Pos(-7, 102, -10),
new Pos(3, 102, -12),
new Pos(5, 101, -15)
};
Pos[] positionsBlueGlass = {
new Pos(-5, 101, 15),
new Pos(-3, 102, 12),
new Pos(-2, 102, 9),
new Pos(1, 103, 9),
new Pos(2, 104, 6),
new Pos(5, 103, 7),
new Pos(7, 102, 10)
};
for(Pos pos : positionsRedGlass)
batch.setBlock(pos, Block.RED_STAINED_GLASS);
for(Pos pos : positionsBlueGlass)
batch.setBlock(pos, Block.BLUE_STAINED_GLASS);
BatchUtil.loadAndApplyBatch(batch, this, () -> {});
}
@Override
@@ -89,7 +126,7 @@ public class BlockBattle extends StatelessGame {
if(!validBlue && !validRed) return;
var winningTeam = validBlue ? Team.Color.BLUE : Team.Color.RED;
var winningPlayers = this.teams.entrySet().stream()
.filter(entry -> entry.getValue().getColor().equals(winningTeam))
.filter(entry -> entry.getValue().color().equals(winningTeam))
.map(Map.Entry::getKey)
.collect(Collectors.toSet());
@@ -116,7 +153,7 @@ public class BlockBattle extends StatelessGame {
player.teleport(
this.isBeforeBeginning
? this.getSpawn()
: this.teams.get(player).getSpawnPosition()
: this.teams.get(player).spawnPosition()
);
this.giveItems(player);
@@ -126,12 +163,10 @@ public class BlockBattle extends StatelessGame {
@Override
protected void onStart() {
this.setTeams();
this.getPlayers().forEach(player -> {
player.teleport(this.teams.get(player).getSpawnPosition()).thenRun(() -> {
this.giveItems(player);
player.setGameMode(GameMode.SURVIVAL);
});
});
this.getPlayers().forEach(player -> player.teleport(this.teams.get(player).spawnPosition()).thenRun(() -> {
this.giveItems(player);
player.setGameMode(GameMode.SURVIVAL);
}));
}
private void generatePlatform(Pos center, Block inner, Block outer) {
@@ -148,31 +183,6 @@ public class BlockBattle extends StatelessGame {
}
}
private void generateWorld() {
this.generatePlatform(new Pos(0, 100, 0), Block.GOLD_BLOCK, Block.YELLOW_CONCRETE_POWDER);
this.generatePlatform(new Pos(0, 101, 0), Block.AIR, Block.YELLOW_CONCRETE_POWDER);
this.generatePlatform(new Pos(0, 100, 20), Block.BLUE_CONCRETE, Block.BLUE_CONCRETE_POWDER);
this.generatePlatform(new Pos(0, 100, -20), Block.RED_CONCRETE, Block.RED_CONCRETE_POWDER);
this.generatePlatform(new Pos(-5, 101, -14), Block.RED_STAINED_GLASS, Block.AIR);
this.generatePlatform(new Pos(5, 101, 14), Block.BLUE_STAINED_GLASS, Block.AIR);
this.setBlock(new Pos(2, 102, -9), Block.RED_STAINED_GLASS);
this.setBlock(new Pos(-1, 103, -9), Block.RED_STAINED_GLASS);
this.setBlock(new Pos(-2, 104, -6), Block.RED_STAINED_GLASS);
this.setBlock(new Pos(-5, 103, -7), Block.RED_STAINED_GLASS);
this.setBlock(new Pos(-7, 102, -10), Block.RED_STAINED_GLASS);
this.setBlock(new Pos(3, 102, -12), Block.RED_STAINED_GLASS);
this.setBlock(new Pos(5, 101, -15), Block.RED_STAINED_GLASS);
this.setBlock(new Pos(-5, 101, 15), Block.BLUE_STAINED_GLASS);
this.setBlock(new Pos(-3, 102, 12), Block.BLUE_STAINED_GLASS);
this.setBlock(new Pos(-2, 102, 9), Block.BLUE_STAINED_GLASS);
this.setBlock(new Pos(1, 103, 9), Block.BLUE_STAINED_GLASS);
this.setBlock(new Pos(2, 104, 6), Block.BLUE_STAINED_GLASS);
this.setBlock(new Pos(5, 103, 7), Block.BLUE_STAINED_GLASS);
this.setBlock(new Pos(7, 102, 10), Block.BLUE_STAINED_GLASS);
}
private void setTeams() {
List<Player> players = new ArrayList<>(this.getPlayers());
Collections.shuffle(players);
@@ -189,7 +199,7 @@ public class BlockBattle extends StatelessGame {
private void giveItems(Player player) {
player.getInventory().clear();
ItemStack item = ItemStack.of(
this.teams.get(player).getColor().getMaterial(),
this.teams.get(player).color().getMaterial(),
this.itemCount
);
player.getInventory().addItemStack(item);

View File

@@ -3,12 +3,13 @@ package eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBattle;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.item.Material;
public class Team {
public record Team(Pos spawnPosition, Color color) {
public enum Color {
RED(Material.RED_WOOL),
BLUE(Material.BLUE_WOOL);
private final Material block;
Color(Material block) {
this.block = block;
}
@@ -17,19 +18,4 @@ public class Team {
return this.block;
}
}
private final Pos spawnPosition;
private final Color color;
public Team(Pos spawnPosition, Color color) {
this.spawnPosition = spawnPosition;
this.color = color;
}
public Pos getSpawnPosition() {
return this.spawnPosition;
}
public Color getColor() {
return this.color;
}
}

View File

@@ -20,13 +20,14 @@ import net.minestom.server.timer.TaskSchedule;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
class Pillars extends StatelessGame {
private int spawnPosx = 0;
private int spawnPosz = 0;
private final int pillarSpacing = 10;
private final int pillarRowCount = 5;
public Pillars() {
super(Dimension.THE_END.key, "Pillars", new LastWinsScore());
this.getScore().setIgnoreLastPlayers(1);
@@ -71,13 +72,15 @@ class Pillars extends StatelessGame {
@Override
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
jannis marked this conversation as resolved
Review

Eigene Variable für playerMoveEvent.getPlayer(), das wiederholt sich sonst.

Eigene Variable für playerMoveEvent.getPlayer(), das wiederholt sich sonst.
if(this.isBeforeBeginning && Position.hasPositionChanged(playerMoveEvent.getPlayer().getPosition(), playerMoveEvent.getNewPosition()))
var player = playerMoveEvent.getPlayer();
if(this.isBeforeBeginning && Position.hasPositionChanged(player.getPosition(), playerMoveEvent.getNewPosition()))
playerMoveEvent.setCancelled(true);
if(playerMoveEvent.getNewPosition().y() < 80) {
this.getScore().insertResult(playerMoveEvent.getPlayer());
playerMoveEvent.getPlayer().teleport(this.getSpawn());
playerMoveEvent.getPlayer().setGameMode(GameMode.SPECTATOR);
player.teleport(this.getSpawn());
player.setGameMode(GameMode.SPECTATOR);
}
}
@@ -90,7 +93,7 @@ class Pillars extends StatelessGame {
.filter(material -> !material.equals(Material.AIR))
jannis marked this conversation as resolved
Review

new Random() als eigene Variable in Pillars, damit nicht immer ein neues Objekt erstellt wird.
Alternativ geht ThreadLocalRandom.current()

new Random() als eigene Variable in Pillars, damit nicht immer ein neues Objekt erstellt wird. Alternativ geht ThreadLocalRandom.current()
Review

nimm ThreadLocalRandom.current()

nimm ThreadLocalRandom.current()
.toList();
this.getPlayers().forEach(player -> {
ItemStack item = ItemStack.of(materials.get(new Random().nextInt(Material.values().toArray().length)));
ItemStack item = ItemStack.of(materials.get(ThreadLocalRandom.current().nextInt(Material.values().toArray().length)));
player.getInventory().addItemStack(item);
});

View File

@@ -182,3 +182,4 @@ description;Build yourself up with your random blocks to reach your opponents an
ns:game_BlockBattle#;;
name;Block Battle;Block Kampf
description;The team that fills the center with their color first wins!;Das Team, welches als erstes die Mitte mit ihrer Farbe gefüllt hat, hat gewonnen!
itemCount;Block Count;Block Anzahl
1 map en_us de_de
182 ns:game_BlockBattle#
183 name Block Battle Block Kampf
184 description The team that fills the center with their color first wins! Das Team, welches als erstes die Mitte mit ihrer Farbe gefüllt hat, hat gewonnen!
185 itemCount Block Count Block Anzahl