added pillars and block battle #10

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

View File

@@ -23,12 +23,15 @@ 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 teamRed = new Team(new Pos(0, 101, -20).add(0.5), Team.Color.RED);
private final int itemCount;
private final Map<Player, Team> teams = new WeakHashMap<>();
public BlockBattle() {
public BlockBattle(int itemCount) {
super(Dimension.THE_END.key, "Block Battle", new FirstWinsScore());
this.itemCount = itemCount;
this.eventNode().addChild(
CombatFeatures.empty()
.add(CombatFeatures.VANILLA_ATTACK)
@@ -97,42 +100,26 @@ public class BlockBattle extends StatelessGame {
@Override
protected void onBlockBreak(@NotNull PlayerBlockBreakEvent playerBlockBreakEvent) {
final Block[] blockCantBreakList = new Block[] {
Block.YELLOW_CONCRETE_POWDER,
Block.GOLD_BLOCK,
Block.BLUE_CONCRETE_POWDER,
Block.BLUE_CONCRETE,
Block.BLUE_STAINED_GLASS,
Block.RED_CONCRETE_POWDER,
Block.RED_CONCRETE,
Block.RED_STAINED_GLASS
};
for(Block block : blockCantBreakList) {
if(playerBlockBreakEvent.getBlock().equals(block))
playerBlockBreakEvent.setCancelled(true);
}
boolean isAllowed = Arrays.stream(Team.Color.values())
.map(Team.Color::getMaterial)
.map(Material::block)
.toList()
.contains(playerBlockBreakEvent.getBlock());
if(!isAllowed) playerBlockBreakEvent.setCancelled(true);
}
@Override
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
if(playerMoveEvent.getNewPosition().y() < 75) {
if(playerMoveEvent.getNewPosition().y() < 95) {
var player = playerMoveEvent.getPlayer();
if(this.isBeforeBeginning) {
player.teleport(this.getSpawn());
} else {
player.teleport(this.teams.get(player).getSpawnPosition());
}
player.teleport(
this.isBeforeBeginning
? this.getSpawn()
: this.teams.get(player).getSpawnPosition()
);
player.getInventory().clear();
if(this.teams.get(player).getColor() == Team.Color.RED) {
ItemStack item = ItemStack.of(Material.RED_WOOL);
player.getInventory().addItemStack(item);
}
if(this.teams.get(player).getColor() == Team.Color.BLUE) {
ItemStack item = ItemStack.of(Material.BLUE_WOOL);
player.getInventory().addItemStack(item);
}
this.giveItems(player);
}
}
@@ -140,17 +127,10 @@ public class BlockBattle extends StatelessGame {
protected void onStart() {
this.setTeams();
this.getPlayers().forEach(player -> {
jannis marked this conversation as resolved Outdated
Outdated
Review

Kann als lambda expression geschrieben werden. Schlägt IntelliJ meistens schon vor.

Kann als lambda expression geschrieben werden. Schlägt IntelliJ meistens schon vor.
player.teleport(this.teams.get(player).getSpawnPosition()).thenRun(() -> {
this.giveItems(player);
player.setGameMode(GameMode.SURVIVAL);
player.teleport(this.teams.get(player).getSpawnPosition());
if(this.teams.get(player).getColor() == Team.Color.RED) {
ItemStack item = ItemStack.of(Material.RED_WOOL);
player.getInventory().addItemStack(item);
}
if(this.teams.get(player).getColor() == Team.Color.BLUE) {
ItemStack item = ItemStack.of(Material.BLUE_WOOL);
player.getInventory().addItemStack(item);
}
});
});
}
@@ -205,4 +185,13 @@ public class BlockBattle extends StatelessGame {
public Pos getSpawn() {
return new Pos(0, 101, 0).add(0.5);
}
private void giveItems(Player player) {
player.getInventory().clear();
ItemStack item = ItemStack.of(
this.teams.get(player).getColor().getMaterial(),
this.itemCount
);
player.getInventory().addItemStack(item);
}
}

View File

@@ -1,8 +1,10 @@
package eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBattle;
import eu.mhsl.minenet.minigames.instance.game.Game;
import eu.mhsl.minenet.minigames.instance.game.stateless.config.ConfigManager;
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
import eu.mhsl.minenet.minigames.instance.game.stateless.config.common.NumericOption;
import eu.mhsl.minenet.minigames.instance.room.Room;
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
import net.minestom.server.item.Material;
@@ -20,6 +22,12 @@ public class BlockBattleFactory implements GameFactory {
return TranslatedComponent.byId("game_BlockBattle#description");
}
@Override
public ConfigManager configuration() {
return new ConfigManager()
.addOption(new NumericOption("itemCount", Material.WHITE_WOOL, TranslatedComponent.byId("game_BlockBattle#itemCount"), 1, 2, 3));
}
@Override
public Material symbol() {
return Material.GREEN_CONCRETE;
@@ -27,6 +35,6 @@ public class BlockBattleFactory implements GameFactory {
@Override
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
return new BlockBattle().setParent(parent);
return new BlockBattle(configuration.get("itemCount").getAsInt()).setParent(parent);
}
}

View File

@@ -1,11 +1,21 @@
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 {
jannis marked this conversation as resolved Outdated
Outdated
Review

Könnte ein record sein. IntelliJ schlägt das vermutlich schon vor.

Könnte ein record sein. IntelliJ schlägt das vermutlich schon vor.
public enum Color {
RED,
BLUE
RED(Material.RED_WOOL),
BLUE(Material.BLUE_WOOL);
private final Material block;
Color(Material block) {
this.block = block;
}
public Material getMaterial() {
return this.block;
}
}
private final Pos spawnPosition;
private final Color color;