added setting, refactored code
This commit is contained in:
@@ -23,12 +23,15 @@ import java.util.stream.Collectors;
|
|||||||
public class BlockBattle extends StatelessGame {
|
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), Team.Color.BLUE);
|
||||||
private final Team teamRed = new Team(new Pos(0, 101, -20).add(0.5), Team.Color.RED);
|
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<>();
|
private final Map<Player, Team> teams = new WeakHashMap<>();
|
||||||
|
|
||||||
public BlockBattle() {
|
public BlockBattle(int itemCount) {
|
||||||
super(Dimension.THE_END.key, "Block Battle", new FirstWinsScore());
|
super(Dimension.THE_END.key, "Block Battle", new FirstWinsScore());
|
||||||
|
|
||||||
|
this.itemCount = itemCount;
|
||||||
|
|
||||||
this.eventNode().addChild(
|
this.eventNode().addChild(
|
||||||
CombatFeatures.empty()
|
CombatFeatures.empty()
|
||||||
.add(CombatFeatures.VANILLA_ATTACK)
|
.add(CombatFeatures.VANILLA_ATTACK)
|
||||||
@@ -97,42 +100,26 @@ public class BlockBattle extends StatelessGame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onBlockBreak(@NotNull PlayerBlockBreakEvent playerBlockBreakEvent) {
|
protected void onBlockBreak(@NotNull PlayerBlockBreakEvent playerBlockBreakEvent) {
|
||||||
final Block[] blockCantBreakList = new Block[] {
|
boolean isAllowed = Arrays.stream(Team.Color.values())
|
||||||
Block.YELLOW_CONCRETE_POWDER,
|
.map(Team.Color::getMaterial)
|
||||||
Block.GOLD_BLOCK,
|
.map(Material::block)
|
||||||
Block.BLUE_CONCRETE_POWDER,
|
.toList()
|
||||||
Block.BLUE_CONCRETE,
|
.contains(playerBlockBreakEvent.getBlock());
|
||||||
Block.BLUE_STAINED_GLASS,
|
if(!isAllowed) playerBlockBreakEvent.setCancelled(true);
|
||||||
Block.RED_CONCRETE_POWDER,
|
|
||||||
Block.RED_CONCRETE,
|
|
||||||
Block.RED_STAINED_GLASS
|
|
||||||
};
|
|
||||||
for(Block block : blockCantBreakList) {
|
|
||||||
if(playerBlockBreakEvent.getBlock().equals(block))
|
|
||||||
playerBlockBreakEvent.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||||
if(playerMoveEvent.getNewPosition().y() < 75) {
|
if(playerMoveEvent.getNewPosition().y() < 95) {
|
||||||
var player = playerMoveEvent.getPlayer();
|
var player = playerMoveEvent.getPlayer();
|
||||||
|
|
||||||
if(this.isBeforeBeginning) {
|
player.teleport(
|
||||||
player.teleport(this.getSpawn());
|
this.isBeforeBeginning
|
||||||
} else {
|
? this.getSpawn()
|
||||||
player.teleport(this.teams.get(player).getSpawnPosition());
|
: this.teams.get(player).getSpawnPosition()
|
||||||
}
|
);
|
||||||
|
|
||||||
player.getInventory().clear();
|
this.giveItems(player);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,17 +127,10 @@ public class BlockBattle extends StatelessGame {
|
|||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
this.setTeams();
|
this.setTeams();
|
||||||
this.getPlayers().forEach(player -> {
|
this.getPlayers().forEach(player -> {
|
||||||
player.setGameMode(GameMode.SURVIVAL);
|
player.teleport(this.teams.get(player).getSpawnPosition()).thenRun(() -> {
|
||||||
player.teleport(this.teams.get(player).getSpawnPosition());
|
this.giveItems(player);
|
||||||
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
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() {
|
public Pos getSpawn() {
|
||||||
return new Pos(0, 101, 0).add(0.5);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBattle;
|
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.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.GameFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
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.instance.room.Room;
|
||||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||||
import net.minestom.server.item.Material;
|
import net.minestom.server.item.Material;
|
||||||
@@ -20,6 +22,12 @@ public class BlockBattleFactory implements GameFactory {
|
|||||||
return TranslatedComponent.byId("game_BlockBattle#description");
|
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
|
@Override
|
||||||
public Material symbol() {
|
public Material symbol() {
|
||||||
return Material.GREEN_CONCRETE;
|
return Material.GREEN_CONCRETE;
|
||||||
@@ -27,6 +35,6 @@ public class BlockBattleFactory implements GameFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,21 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBattle;
|
package eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBattle;
|
||||||
|
|
||||||
import net.minestom.server.coordinate.Pos;
|
import net.minestom.server.coordinate.Pos;
|
||||||
|
import net.minestom.server.item.Material;
|
||||||
|
|
||||||
public class Team {
|
public class Team {
|
||||||
public enum Color {
|
public enum Color {
|
||||||
RED,
|
RED(Material.RED_WOOL),
|
||||||
BLUE
|
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 Pos spawnPosition;
|
||||||
private final Color color;
|
private final Color color;
|
||||||
|
|||||||
Reference in New Issue
Block a user