pull requestest changes
This commit is contained in:
@@ -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.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.FirstWinsScore;
|
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.events.FinalAttackEvent;
|
||||||
import io.github.togar2.pvp.feature.CombatFeatures;
|
import io.github.togar2.pvp.feature.CombatFeatures;
|
||||||
import net.minestom.server.coordinate.Pos;
|
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.PlayerBlockBreakEvent;
|
||||||
import net.minestom.server.event.player.PlayerBlockPlaceEvent;
|
import net.minestom.server.event.player.PlayerBlockPlaceEvent;
|
||||||
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.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
import net.minestom.server.item.Material;
|
import net.minestom.server.item.Material;
|
||||||
@@ -21,7 +23,7 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
import java.util.stream.Collectors;
|
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).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 Team teamRed = new Team(new Pos(0, 101, -20).add(0.5), Team.Color.RED);
|
||||||
private final int itemCount;
|
private final int itemCount;
|
||||||
|
|
||||||
@@ -49,7 +51,42 @@ public class BlockBattle extends StatelessGame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
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
|
@Override
|
||||||
@@ -89,7 +126,7 @@ public class BlockBattle extends StatelessGame {
|
|||||||
if(!validBlue && !validRed) return;
|
if(!validBlue && !validRed) return;
|
||||||
var winningTeam = validBlue ? Team.Color.BLUE : Team.Color.RED;
|
var winningTeam = validBlue ? Team.Color.BLUE : Team.Color.RED;
|
||||||
var winningPlayers = this.teams.entrySet().stream()
|
var winningPlayers = this.teams.entrySet().stream()
|
||||||
.filter(entry -> entry.getValue().getColor().equals(winningTeam))
|
.filter(entry -> entry.getValue().color().equals(winningTeam))
|
||||||
.map(Map.Entry::getKey)
|
.map(Map.Entry::getKey)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
@@ -116,7 +153,7 @@ public class BlockBattle extends StatelessGame {
|
|||||||
player.teleport(
|
player.teleport(
|
||||||
this.isBeforeBeginning
|
this.isBeforeBeginning
|
||||||
? this.getSpawn()
|
? this.getSpawn()
|
||||||
: this.teams.get(player).getSpawnPosition()
|
: this.teams.get(player).spawnPosition()
|
||||||
);
|
);
|
||||||
|
|
||||||
this.giveItems(player);
|
this.giveItems(player);
|
||||||
@@ -126,12 +163,10 @@ public class BlockBattle extends StatelessGame {
|
|||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
this.setTeams();
|
this.setTeams();
|
||||||
this.getPlayers().forEach(player -> {
|
this.getPlayers().forEach(player -> player.teleport(this.teams.get(player).spawnPosition()).thenRun(() -> {
|
||||||
player.teleport(this.teams.get(player).getSpawnPosition()).thenRun(() -> {
|
|
||||||
this.giveItems(player);
|
this.giveItems(player);
|
||||||
player.setGameMode(GameMode.SURVIVAL);
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
});
|
}));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generatePlatform(Pos center, Block inner, Block outer) {
|
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() {
|
private void setTeams() {
|
||||||
List<Player> players = new ArrayList<>(this.getPlayers());
|
List<Player> players = new ArrayList<>(this.getPlayers());
|
||||||
Collections.shuffle(players);
|
Collections.shuffle(players);
|
||||||
@@ -189,7 +199,7 @@ public class BlockBattle extends StatelessGame {
|
|||||||
private void giveItems(Player player) {
|
private void giveItems(Player player) {
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
ItemStack item = ItemStack.of(
|
ItemStack item = ItemStack.of(
|
||||||
this.teams.get(player).getColor().getMaterial(),
|
this.teams.get(player).color().getMaterial(),
|
||||||
this.itemCount
|
this.itemCount
|
||||||
);
|
);
|
||||||
player.getInventory().addItemStack(item);
|
player.getInventory().addItemStack(item);
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ 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;
|
import net.minestom.server.item.Material;
|
||||||
|
|
||||||
public class Team {
|
public record Team(Pos spawnPosition, Color color) {
|
||||||
public enum Color {
|
public enum Color {
|
||||||
RED(Material.RED_WOOL),
|
RED(Material.RED_WOOL),
|
||||||
BLUE(Material.BLUE_WOOL);
|
BLUE(Material.BLUE_WOOL);
|
||||||
|
|
||||||
private final Material block;
|
private final Material block;
|
||||||
|
|
||||||
Color(Material block) {
|
Color(Material block) {
|
||||||
this.block = block;
|
this.block = block;
|
||||||
}
|
}
|
||||||
@@ -17,19 +18,4 @@ public class Team {
|
|||||||
return this.block;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,13 +20,14 @@ import net.minestom.server.timer.TaskSchedule;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
class Pillars extends StatelessGame {
|
class Pillars extends StatelessGame {
|
||||||
private int spawnPosx = 0;
|
private int spawnPosx = 0;
|
||||||
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;
|
||||||
|
|
||||||
public Pillars() {
|
public Pillars() {
|
||||||
super(Dimension.THE_END.key, "Pillars", new LastWinsScore());
|
super(Dimension.THE_END.key, "Pillars", new LastWinsScore());
|
||||||
this.getScore().setIgnoreLastPlayers(1);
|
this.getScore().setIgnoreLastPlayers(1);
|
||||||
@@ -71,13 +72,15 @@ class Pillars extends StatelessGame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||||
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);
|
playerMoveEvent.setCancelled(true);
|
||||||
|
|
||||||
if(playerMoveEvent.getNewPosition().y() < 80) {
|
if(playerMoveEvent.getNewPosition().y() < 80) {
|
||||||
this.getScore().insertResult(playerMoveEvent.getPlayer());
|
this.getScore().insertResult(playerMoveEvent.getPlayer());
|
||||||
playerMoveEvent.getPlayer().teleport(this.getSpawn());
|
player.teleport(this.getSpawn());
|
||||||
playerMoveEvent.getPlayer().setGameMode(GameMode.SPECTATOR);
|
player.setGameMode(GameMode.SPECTATOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +93,7 @@ class Pillars extends StatelessGame {
|
|||||||
.filter(material -> !material.equals(Material.AIR))
|
.filter(material -> !material.equals(Material.AIR))
|
||||||
.toList();
|
.toList();
|
||||||
this.getPlayers().forEach(player -> {
|
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);
|
player.getInventory().addItemStack(item);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -182,3 +182,4 @@ description;Build yourself up with your random blocks to reach your opponents an
|
|||||||
ns:game_BlockBattle#;;
|
ns:game_BlockBattle#;;
|
||||||
name;Block Battle;Block Kampf
|
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!
|
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
|
||||||
|
Reference in New Issue
Block a user