13 changed files with 699 additions and 2 deletions

No files matched your search

+4
View File
@@ -11,6 +11,7 @@ version '1.0-SNAPSHOT'
repositories { repositories {
mavenCentral() mavenCentral()
maven { url = 'https://mvn.everbuild.org/public' }
} }
java { java {
@@ -38,6 +39,9 @@ dependencies {
//PvP //PvP
implementation 'io.github.togar2:MinestomPvP:2026.05.30-26.1.1' implementation 'io.github.togar2:MinestomPvP:2026.05.30-26.1.1'
//Block placement
implementation 'org.everbuild.blocksandstuff:blocksandstuff-blocks:1.10.2-SNAPSHOT'
} }
tasks { tasks {
@@ -1,5 +1,6 @@
package eu.mhsl.minenet.minigames.handler.global; package eu.mhsl.minenet.minigames.handler.global;
import eu.mhsl.minenet.minigames.Main;
import eu.mhsl.minenet.minigames.message.Icon; import eu.mhsl.minenet.minigames.message.Icon;
import eu.mhsl.minenet.minigames.message.type.ChatMessage; import eu.mhsl.minenet.minigames.message.type.ChatMessage;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@@ -9,6 +10,9 @@ import net.minestom.server.event.player.PlayerChatEvent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class ChatFormatHandler implements EventListener<PlayerChatEvent> { public class ChatFormatHandler implements EventListener<PlayerChatEvent> {
// Verteilt der Proxy den Chat (chat-bridge bei CraftAttack), darf er hier nicht noch einmal erscheinen
private final boolean chatViaProxy = Main.globalConfig.node("velocity", "chat-via-proxy").getBoolean(false);
@Override @Override
public @NotNull Class<PlayerChatEvent> eventType() { public @NotNull Class<PlayerChatEvent> eventType() {
return PlayerChatEvent.class; return PlayerChatEvent.class;
@@ -16,6 +20,10 @@ public class ChatFormatHandler implements EventListener<PlayerChatEvent> {
@Override @Override
public @NotNull Result run(@NotNull PlayerChatEvent event) { public @NotNull Result run(@NotNull PlayerChatEvent event) {
if(this.chatViaProxy) {
event.setCancelled(true);
return Result.SUCCESS;
}
NamedTextColor color = event.getPlayer().getPermissionLevel() > 0 ? NamedTextColor.AQUA : NamedTextColor.GRAY; NamedTextColor color = event.getPlayer().getPermissionLevel() > 0 ? NamedTextColor.AQUA : NamedTextColor.GRAY;
event.setFormattedMessage( event.setFormattedMessage(
new ChatMessage(Icon.CHAT) new ChatMessage(Icon.CHAT)
@@ -9,6 +9,7 @@ import eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBattle.Block
import eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBreakRace.BlockBreakRaceFactory; import eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBreakRace.BlockBreakRaceFactory;
import eu.mhsl.minenet.minigames.instance.game.stateless.types.boatRace.BoatRaceFactory; import eu.mhsl.minenet.minigames.instance.game.stateless.types.boatRace.BoatRaceFactory;
import eu.mhsl.minenet.minigames.instance.game.stateless.types.bowSpleef.BowSpleefFactory; import eu.mhsl.minenet.minigames.instance.game.stateless.types.bowSpleef.BowSpleefFactory;
import eu.mhsl.minenet.minigames.instance.game.stateless.types.buildBattle.BuildBattleFactory;
import eu.mhsl.minenet.minigames.instance.game.stateless.types.colorJump.ColorJumpFactory; import eu.mhsl.minenet.minigames.instance.game.stateless.types.colorJump.ColorJumpFactory;
import eu.mhsl.minenet.minigames.instance.game.stateless.types.deathcube.DeathcubeFactory; import eu.mhsl.minenet.minigames.instance.game.stateless.types.deathcube.DeathcubeFactory;
import eu.mhsl.minenet.minigames.instance.game.stateless.types.elytraRace.ElytraRaceFactory; import eu.mhsl.minenet.minigames.instance.game.stateless.types.elytraRace.ElytraRaceFactory;
@@ -54,7 +55,8 @@ public enum GameList {
PILLARS(new PillarsFactory(), GameType.PROTOTYPE), PILLARS(new PillarsFactory(), GameType.PROTOTYPE),
BLOCKBATTLE(new BlockBattleFactory(), GameType.PVP), BLOCKBATTLE(new BlockBattleFactory(), GameType.PVP),
COLORJUMP(new ColorJumpFactory(), GameType.JUMPNRUN), COLORJUMP(new ColorJumpFactory(), GameType.JUMPNRUN),
PLAYERRACE(new PlayerRaceFactory(), GameType.JUMPNRUN); PLAYERRACE(new PlayerRaceFactory(), GameType.JUMPNRUN),
BUILDBATTLE(new BuildBattleFactory(), GameType.PROTOTYPE);
private final GameFactory factory; private final GameFactory factory;
private final GameType type; private final GameType type;
@@ -43,7 +43,7 @@ public class BlockBattle extends StatelessGame {
); );
this.eventNode().addListener(FinalAttackEvent.class, finalAttackEvent -> { this.eventNode().addListener(FinalAttackEvent.class, finalAttackEvent -> {
if(this.isBeforeBeginning) finalAttackEvent.setCancelled(true); if(!this.isRunning) finalAttackEvent.setCancelled(true);
finalAttackEvent.setBaseDamage(0); finalAttackEvent.setBaseDamage(0);
((Player) finalAttackEvent.getTarget()).setHealth(20); ((Player) finalAttackEvent.getTarget()).setHealth(20);
}); });
@@ -0,0 +1,226 @@
package eu.mhsl.minenet.minigames.instance.game.stateless.types.buildBattle;
import eu.mhsl.minenet.minigames.instance.Dimension;
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
import eu.mhsl.minenet.minigames.score.PointsWinScore;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.title.Title;
import net.minestom.server.coordinate.Point;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.entity.GameMode;
import net.minestom.server.entity.Player;
import net.minestom.server.event.player.PlayerBlockBreakEvent;
import net.minestom.server.event.player.PlayerBlockInteractEvent;
import net.minestom.server.event.player.PlayerBlockPlaceEvent;
import net.minestom.server.event.player.PlayerUseItemEvent;
import net.minestom.server.event.player.PlayerUseItemOnBlockEvent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import net.minestom.server.timer.TaskSchedule;
import org.jetbrains.annotations.NotNull;
import java.util.*;
import java.util.stream.IntStream;
public class BuildBattle extends StatelessGame {
private static final int height = 100;
private static final int plotHalf = BuildBattleChunkgenerator.inner / 2;
private static final int rowCount = 5;
private static final int ratingSeconds = 15;
private static final List<Material> ratingMaterials = List.of(
Material.RED_CONCRETE, Material.ORANGE_CONCRETE, Material.YELLOW_CONCRETE,
Material.LIME_CONCRETE, Material.GREEN_CONCRETE
);
private static final List<ItemStack> ratingItems = IntStream.range(0, ratingMaterials.size())
.mapToObj(i -> ItemStack.builder(ratingMaterials.get(i))
.customName(Component.text((i + 1) + " Punkte"))
.build())
.toList();
private static final List<String> themes = List.of(
"Burg", "Raumschiff", "Unterwasserwelt", "Pizzeria", "Spukhaus",
"Bauernhof", "Dschungel", "Zukunftsstadt", "Piratenschiff", "Vulkan",
"Freizeitpark", "Leuchtturm", "Wikingerdorf", "Weihnachtsmarkt",
"Schloss", "Strand", "Berghütte", "Bahnhof", "Zoo", "Schule",
"Zeitreise", "Ein Haus, das auf dem Kopf steht", "Eine Stadt auf dem Rücken eines Riesen",
"Wohnen in einer Schneekugel", "Alles ist aus Süßigkeiten", "Ein Schiff in der Luft",
"Das Museum der Zukunft", "Das letzte Haus vor dem Weltuntergang",
"Wenn Schweine fliegen könnten", "Das Gefängnis für Creeper", "Die Wohnung von Herobrine",
"Ein Dönerladen im Weltall", "Ein Spa für Enderman", "Der Käse-Palast",
"Mein Zimmer nach 3 Wochen ohne Aufräumen", "Die Hüpfburg des Todes"
);
private int spawnPosx = 0;
private int spawnPosz = 0;
private final Map<Player, Pos> spawnPositions = new WeakHashMap<>();
private final int seconds;
private final Map<Player, Integer> currentVotes = new HashMap<>();
private Player currentOwner = null;
public BuildBattle(int seconds) {
super(Dimension.THE_END.key, "BuildBattle", new PointsWinScore());
this.seconds = seconds;
this.setGenerator(new BuildBattleChunkgenerator(height));
BuildBattleBlockRules.register();
this.eventNode().addListener(PlayerUseItemEvent.class, this::onRatingItemUse);
this.eventNode().addListener(PlayerUseItemOnBlockEvent.class, e -> FluidFlowHelper.onBucketUse(e, p -> this.isInArea(p, e.getPlayer())));
this.eventNode().addListener(PlayerBlockInteractEvent.class, e -> {
if (this.isInArea(e.getBlockPosition(), e.getPlayer())) BuildBattleBlockRules.onInteract(e);
});
}
@Override
protected void onStart() {
String theme = themes.get(this.rnd.nextInt(themes.size()));
this.showTitle(Title.title(
Component.text("Thema", NamedTextColor.GOLD),
Component.text(theme, NamedTextColor.YELLOW)
));
this.sendMessage(Component.text("Euer Thema: ", NamedTextColor.GRAY)
.append(Component.text(theme, NamedTextColor.YELLOW)));
this.getPlayers().forEach(player -> player.setGameMode(GameMode.CREATIVE));
this.scheduler().scheduleTask(this::endBuildPhase, TaskSchedule.seconds(this.seconds), TaskSchedule.stop());
this.scheduleCountdown();
}
private void scheduleCountdown() {
int[] marks = {30, 10, 5, 4, 3, 2, 1};
for (int m : marks) {
if (this.seconds <= m) continue;
int remaining = m;
this.scheduler().scheduleTask(() -> {
NamedTextColor color = remaining <= 5 ? NamedTextColor.RED : (remaining <= 10 ? NamedTextColor.GOLD : NamedTextColor.YELLOW);
this.sendMessage(Component.text("Noch ", NamedTextColor.GRAY)
.append(Component.text(remaining, color))
.append(Component.text(" Sekunde" + (remaining == 1 ? "" : "n") + " Bauzeit!", NamedTextColor.GRAY)));
}, TaskSchedule.seconds(this.seconds - m), TaskSchedule.stop());
}
}
private void endBuildPhase() {
this.sendMessage(Component.text("Die Bauzeit ist beendet!"));
this.getPlayers().forEach(p -> {
p.setGameMode(GameMode.ADVENTURE);
p.setAllowFlying(true);
p.setFlying(true);
});
this.scheduler().scheduleTask(this::rating, TaskSchedule.seconds(3), TaskSchedule.stop());
}
@Override
protected boolean onPlayerJoin(Player player) {
Pos plotCenter = new Pos(
this.spawnPosx * BuildBattleChunkgenerator.period + plotHalf,
height,
this.spawnPosz * BuildBattleChunkgenerator.period + plotHalf
);
this.spawnPositions.put(player, plotCenter);
if(this.spawnPosx >= rowCount - 1) {
this.spawnPosx = 0;
this.spawnPosz++;
} else this.spawnPosx ++;
player.setGameMode(GameMode.ADVENTURE);
this.scheduler().scheduleNextTick(() -> player.teleport(plotCenter.add(0, 1.5, 0)));
return super.onPlayerJoin(player);
}
@Override
protected void onBlockBreak(@NotNull PlayerBlockBreakEvent event) {
if (!this.isInArea(event.getBlockPosition(), event.getPlayer())) {
event.setCancelled(true);
return;
}
FluidFlowHelper.onBreak(event);
}
@Override
protected void onBlockPlace(@NotNull PlayerBlockPlaceEvent event) {
if (!this.isInArea(event.getBlockPosition(), event.getPlayer())) {
event.setCancelled(true);
return;
}
FluidFlowHelper.onPlace(event);
}
private Pos safeSpawn(Player owner) {
Pos center = this.spawnPositions.get(owner);
int topY = center.blockY();
for (int y = 300; y >= center.blockY(); y--) {
if (!this.getBlock(center.blockX(), y, center.blockZ()).isAir()) {
topY = y;
break;
}
}
return new Pos(center.x(), topY + 3, center.z()).withView(center.yaw(), center.pitch());
}
private void rating() {
Queue<Player> owners = new ArrayDeque<>(this.getPlayers());
this.scheduler().submitTask(() -> {
if (this.currentOwner != null) this.finishRound();
Player next = owners.poll();
while (next != null && !(next.isOnline() && this.spawnPositions.containsKey(next))) next = owners.poll();
if (next == null) return TaskSchedule.stop();
this.startRound(next);
return TaskSchedule.seconds(ratingSeconds);
});
}
private void startRound(Player owner) {
this.currentOwner = owner;
this.currentVotes.clear();
Pos plot = this.safeSpawn(owner);
this.sendMessage(Component.text("Bewerte das Grundstück von " + owner.getUsername() + "!"));
this.getPlayers().forEach(p -> {
p.teleport(plot);
p.getInventory().clear();
if (p != owner) this.giveRatingItems(p);
});
}
private void giveRatingItems(Player player) {
for (int i = 0; i < ratingItems.size(); i++) {
player.getInventory().setItemStack(i, ratingItems.get(i));
}
}
private void onRatingItemUse(PlayerUseItemEvent event) {
Player voter = event.getPlayer();
if (this.currentOwner == null || voter == this.currentOwner) return;
int slot = voter.getHeldSlot();
if (slot >= ratingItems.size()) return;
event.setCancelled(true);
this.currentVotes.put(voter, slot + 1);
voter.sendMessage(Component.text("Du hast " + (slot + 1) + " Punkte vergeben."));
}
private void finishRound() {
int voteSum = this.currentVotes.values().stream()
.mapToInt(Integer::intValue)
.sum();
int score = (int) Math.round((double) voteSum / this.getPlayers().size());
this.getPlayers().forEach(p -> p.getInventory().clear());
this.getScore().insertResult(this.currentOwner, score);
this.currentOwner = null;
}
private boolean isInArea(Point block, Player player) {
Pos center = this.spawnPositions.get(player);
if (center == null) return false;
Pos min = new Pos(center.x() - plotHalf, center.y() + 1, center.z() - plotHalf);
Pos max = new Pos(center.x() + plotHalf - 1, 300, center.z() + plotHalf - 1);
return eu.mhsl.minenet.minigames.util.Position.isInArea(block, min, max);
}
}
@@ -0,0 +1,85 @@
package eu.mhsl.minenet.minigames.instance.game.stateless.types.buildBattle;
import net.minestom.server.MinecraftServer;
import net.minestom.server.event.player.PlayerBlockInteractEvent;
import net.minestom.server.instance.block.Block;
import net.minestom.server.instance.block.BlockHandler;
import net.minestom.server.instance.block.rule.BlockPlacementRule;
import org.everbuild.blocksandstuff.blocks.group.VanillaBlockBehaviour;
import org.everbuild.blocksandstuff.blocks.group.VanillaPlacementRules;
import org.everbuild.blocksandstuff.blocks.group.behaviour.BehaviourGroup;
import org.everbuild.blocksandstuff.blocks.group.placement.PlacementGroup;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
public final class BuildBattleBlockRules {
private BuildBattleBlockRules() {}
private static final ThreadLocal<Boolean> interactingInBuildBattle = ThreadLocal.withInitial(() -> false);
private static final Map<Integer, BlockHandler> behaviours = new HashMap<>();
private static boolean registered = false;
public static synchronized void register() {
if (registered) return;
registered = true;
var blockManager = MinecraftServer.getBlockManager();
for (PlacementGroup group : VanillaPlacementRules.INSTANCE.getALL()) {
for (Block block : group.getBlockGroup().allMatching()) {
blockManager.registerBlockPlacementRule(new BuildBattleOnlyRule(group.createRule(block)));
}
}
for (BehaviourGroup group : VanillaBlockBehaviour.INSTANCE.getALL()) {
for (Block block : group.getBlockGroup().allMatching()) {
behaviours.put(block.id(), group.createHandler(block));
}
}
MinecraftServer.getGlobalEventHandler().addListener(PlayerBlockInteractEvent.class,
e -> interactingInBuildBattle.set(e.getInstance() instanceof BuildBattle));
}
public static void onInteract(PlayerBlockInteractEvent event) {
BlockHandler handler = behaviours.get(event.getBlock().id());
if (handler == null) return;
boolean continueItemUse = handler.onInteract(new BlockHandler.Interaction(
event.getBlock(), event.getInstance(), event.getBlockFace(), event.getBlockPosition(),
event.getCursorPosition(), event.getPlayer(), event.getHand()
));
if (!continueItemUse) event.setBlockingItemUse(true);
}
private static final class BuildBattleOnlyRule extends BlockPlacementRule {
private final BlockPlacementRule delegate;
private BuildBattleOnlyRule(BlockPlacementRule delegate) {
super(delegate.getBlock());
this.delegate = delegate;
}
@Override
public @Nullable Block blockPlace(PlacementState placementState) {
if (!(placementState.instance() instanceof BuildBattle)) return placementState.block();
return this.delegate.blockPlace(placementState);
}
@Override
public Block blockUpdate(UpdateState updateState) {
if (!(updateState.instance() instanceof BuildBattle)) return updateState.currentBlock();
return this.delegate.blockUpdate(updateState);
}
@Override
public boolean isSelfReplaceable(Replacement replacement) {
return interactingInBuildBattle.get() && this.delegate.isSelfReplaceable(replacement);
}
@Override
public int maxUpdateDistance() {
return this.delegate.maxUpdateDistance();
}
}
}
@@ -0,0 +1,41 @@
package eu.mhsl.minenet.minigames.instance.game.stateless.types.buildBattle;
import eu.mhsl.minenet.minigames.util.GeneratorUtils;
import eu.mhsl.minenet.minigames.world.generator.terrain.BaseGenerator;
import net.minestom.server.instance.block.Block;
public class BuildBattleChunkgenerator extends BaseGenerator {
static final int inner = 32;
private static final int ring = 3;
private static final int wall = 1;
private static final int wallHeight = 200;
static final int period = wall + ring + inner + ring;
private static final int innerStart = wall + ring;
private static final int innerEnd = innerStart + inner;
private static final Block middleBlocks = Block.QUARTZ_BLOCK;
private static final Block outerBlocks = Block.STONE_BRICKS;
private static final Block wallBlocks = Block.POLISHED_DEEPSLATE;
public BuildBattleChunkgenerator(int height) {
this.addMixIn(unit -> GeneratorUtils.foreachXZ(unit, point -> {
int lx = Math.floorMod(point.blockX() + innerStart, period);
int lz = Math.floorMod(point.blockZ() + innerStart, period);
if (lx < wall || lz < wall) {
unit.modifier().fill(point.withY(height), point.add(1, 0, 1).withY(height + wallHeight + 1), wallBlocks);
} else {
unit.modifier().setBlock(point.withY(height), floorBlock(lx, lz));
}
}));
}
private static Block floorBlock(int lx, int lz) {
boolean inInner = lx >= innerStart && lx < innerEnd
&& lz >= innerStart && lz < innerEnd;
return inInner ? middleBlocks : outerBlocks;
}
}
@@ -0,0 +1,40 @@
package eu.mhsl.minenet.minigames.instance.game.stateless.types.buildBattle;
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;
import java.util.Map;
public class BuildBattleFactory implements GameFactory {
@Override
public TranslatedComponent name() {
return TranslatedComponent.byId("game_BuildBattle#name");
}
@Override
public ConfigManager configuration() {
return new ConfigManager()
.addOption(new NumericOption("seconds", Material.CLOCK, TranslatedComponent.byId("game_BuildBattle#seconds"), 60, 120, 300, 600));
}
@Override
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
return new BuildBattle(configuration.get("seconds").getAsInt()).setParent(parent);
}
@Override
public Material symbol() {
return Material.SANDSTONE;
}
@Override
public TranslatedComponent description() {
return TranslatedComponent.byId("game_BuildBattle#description");
}
}
@@ -0,0 +1,267 @@
package eu.mhsl.minenet.minigames.instance.game.stateless.types.buildBattle;
import net.minestom.server.coordinate.BlockVec;
import net.minestom.server.coordinate.Point;
import net.minestom.server.event.player.PlayerBlockBreakEvent;
import net.minestom.server.event.player.PlayerBlockPlaceEvent;
import net.minestom.server.event.player.PlayerUseItemOnBlockEvent;
import net.minestom.server.instance.Instance;
import net.minestom.server.instance.block.Block;
import net.minestom.server.item.Material;
import net.minestom.server.timer.TaskSchedule;
import net.minestom.server.utils.Direction;
import java.util.ArrayDeque;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Predicate;
public final class FluidFlowHelper {
private FluidFlowHelper() {}
private static final int WATER_TICK = 5;
private static final int LAVA_TICK = 30;
private static final int WATER_RANGE = 7;
private static final int LAVA_RANGE = 3;
private static final int FALLING = 8;
public static void onBucketUse(PlayerUseItemOnBlockEvent event, Predicate<Point> inArea) {
Material m = event.getItemStack().material();
Instance inst = event.getPlayer().getInstance();
if (inst == null) return;
Point hit = event.getPosition();
var face = event.getBlockFace();
BlockVec placePos = new BlockVec(
hit.blockX() + face.toDirection().normalX(),
hit.blockY() + face.toDirection().normalY(),
hit.blockZ() + face.toDirection().normalZ()
);
if (!inArea.test(placePos)) return;
if (m == Material.WATER_BUCKET) {
inst.setBlock(placePos, Block.WATER.withProperty("level", "0"));
scheduleFlow(inst, placePos, true);
} else if (m == Material.LAVA_BUCKET) {
inst.setBlock(placePos, Block.LAVA.withProperty("level", "0"));
scheduleFlow(inst, placePos, false);
} else if (m == Material.BUCKET) {
Block existing = inst.getBlock(placePos);
if (isWater(existing) || isLava(existing)) inst.setBlock(placePos, Block.AIR);
}
}
public static void onPlace(PlayerBlockPlaceEvent event) {
Block b = event.getBlock();
if (isWater(b) || isLava(b)) {
Instance inst = event.getInstance();
BlockVec pos = event.getBlockPosition();
scheduleFlow(inst, pos, isWater(b));
}
triggerNeighbors(event.getInstance(), event.getBlockPosition());
}
public static void onBreak(PlayerBlockBreakEvent event) {
triggerNeighbors(event.getInstance(), event.getBlockPosition());
}
private static void triggerNeighbors(Instance inst, BlockVec pos) {
for (Direction d : Direction.values()) {
BlockVec np = new BlockVec(pos.blockX() + d.normalX(), pos.blockY() + d.normalY(), pos.blockZ() + d.normalZ());
Block nb = inst.getBlock(np);
if (isWater(nb) || isLava(nb)) scheduleFlow(inst, np, isWater(nb));
}
}
private static void scheduleFlow(Instance inst, BlockVec pos, boolean water) {
int delay = water ? WATER_TICK : LAVA_TICK;
inst.scheduler().buildTask(() -> step(inst, pos, water)).delay(TaskSchedule.tick(delay)).schedule();
}
private static void step(Instance inst, BlockVec pos, boolean water) {
Block self = inst.getBlock(pos);
if (water ? !isWater(self) : !isLava(self)) return;
int level = parseLevel(self);
boolean source = level == 0;
boolean falling = level >= FALLING;
int flowLevel = source ? 1 : (falling ? 1 : level + 1);
int maxRange = water ? WATER_RANGE : LAVA_RANGE;
if (!source && !falling) {
int newLevel = computeIncomingLevel(inst, pos, water, maxRange);
if (newLevel == -1) {
inst.setBlock(pos, Block.AIR);
triggerNeighbors(inst, pos);
return;
}
if (newLevel != level) {
inst.setBlock(pos, (water ? Block.WATER : Block.LAVA).withProperty("level", String.valueOf(newLevel)));
level = newLevel;
flowLevel = level + 1;
}
}
if (water && !source && countAdjacentSources(inst, pos, true) >= 2
&& hasSolidBelow(inst, pos)) {
inst.setBlock(pos, Block.WATER.withProperty("level", "0"));
scheduleFlow(inst, pos, true);
triggerNeighbors(inst, pos);
return;
}
BlockVec below = new BlockVec(pos.blockX(), pos.blockY() - 1, pos.blockZ());
Block belowBlock = inst.getBlock(below);
if (isReplaceable(belowBlock) || (water ? isWater(belowBlock) : isLava(belowBlock))) {
if (handleFluidCollision(inst, below, water)) {
triggerNeighbors(inst, below);
return;
}
Block target = (water ? Block.WATER : Block.LAVA).withProperty("level", String.valueOf(FALLING));
if (!belowBlock.compare(target) || !target.getProperty("level").equals(belowBlock.getProperty("level"))) {
if (!(isWater(belowBlock) && parseLevel(belowBlock) == 0)
&& !(isLava(belowBlock) && parseLevel(belowBlock) == 0)) {
inst.setBlock(below, target);
scheduleFlow(inst, below, water);
triggerNeighbors(inst, below);
}
}
if (!hasSolidBelow(inst, pos) && !source) return;
}
if (flowLevel > maxRange) return;
Set<Direction> targets = findFlowTargets(inst, pos, water, maxRange - (source ? 0 : level));
for (Direction d : Direction.HORIZONTAL) {
if (!targets.contains(d)) continue;
BlockVec np = new BlockVec(pos.blockX() + d.normalX(), pos.blockY(), pos.blockZ() + d.normalZ());
Block nb = inst.getBlock(np);
if (handleFluidCollision(inst, np, water)) continue;
if (!isReplaceable(nb) && !(water ? isWater(nb) : isLava(nb))) continue;
int existingLevel = (water ? isWater(nb) : isLava(nb)) ? parseLevel(nb) : Integer.MAX_VALUE;
if (existingLevel == 0) continue;
if (flowLevel < existingLevel) {
inst.setBlock(np, (water ? Block.WATER : Block.LAVA).withProperty("level", String.valueOf(flowLevel)));
scheduleFlow(inst, np, water);
triggerNeighbors(inst, np);
}
}
}
private static int computeIncomingLevel(Instance inst, BlockVec pos, boolean water, int maxRange) {
int min = Integer.MAX_VALUE;
BlockVec above = new BlockVec(pos.blockX(), pos.blockY() + 1, pos.blockZ());
Block ab = inst.getBlock(above);
if ((water ? isWater(ab) : isLava(ab))) return FALLING;
for (Direction d : Direction.HORIZONTAL) {
BlockVec np = new BlockVec(pos.blockX() + d.normalX(), pos.blockY(), pos.blockZ() + d.normalZ());
Block nb = inst.getBlock(np);
if (water ? isWater(nb) : isLava(nb)) {
int nl = parseLevel(nb);
if (nl >= FALLING) nl = 0;
if (nl < min) min = nl;
}
}
if (min == Integer.MAX_VALUE) return -1;
int result = min + 1;
if (result > maxRange) return -1;
return result;
}
private static Set<Direction> findFlowTargets(Instance inst, BlockVec pos, boolean water, int remaining) {
Set<Direction> result = new HashSet<>();
if (remaining <= 0) return result;
int bestDist = Integer.MAX_VALUE;
int[] dist = new int[4];
Direction[] dirs = {Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST};
for (int i = 0; i < 4; i++) {
BlockVec np = new BlockVec(pos.blockX() + dirs[i].normalX(), pos.blockY(), pos.blockZ() + dirs[i].normalZ());
Block nb = inst.getBlock(np);
if (!isReplaceable(nb) && !(water ? isWater(nb) : isLava(nb))) { dist[i] = Integer.MAX_VALUE; continue; }
dist[i] = bfsDownhill(inst, np, water, remaining);
if (dist[i] < bestDist) bestDist = dist[i];
}
if (bestDist == Integer.MAX_VALUE) {
for (int i = 0; i < 4; i++) {
if (dist[i] < Integer.MAX_VALUE) result.add(dirs[i]);
}
} else {
for (int i = 0; i < 4; i++) {
if (dist[i] == bestDist) result.add(dirs[i]);
}
}
return result;
}
private static int bfsDownhill(Instance inst, BlockVec start, boolean water, int remaining) {
ArrayDeque<int[]> queue = new ArrayDeque<>();
Set<Long> visited = new HashSet<>();
queue.add(new int[]{start.blockX(), start.blockY(), start.blockZ(), 0});
visited.add(key(start.blockX(), start.blockY(), start.blockZ()));
while (!queue.isEmpty()) {
int[] c = queue.poll();
BlockVec cp = new BlockVec(c[0], c[1], c[2]);
Block below = inst.getBlock(new BlockVec(c[0], c[1] - 1, c[2]));
if (isReplaceable(below) && !(water ? isWater(below) : isLava(below))) return c[3];
if (c[3] >= remaining) continue;
for (Direction d : Direction.HORIZONTAL) {
int nx = c[0] + d.normalX(), nz = c[2] + d.normalZ();
long k = key(nx, c[1], nz);
if (visited.contains(k)) continue;
Block nb = inst.getBlock(new BlockVec(nx, c[1], nz));
if (!isReplaceable(nb) && !(water ? isWater(nb) : isLava(nb))) continue;
visited.add(k);
queue.add(new int[]{nx, c[1], nz, c[3] + 1});
}
}
return Integer.MAX_VALUE;
}
private static long key(int x, int y, int z) {
return ((long) x & 0x3FFFFFFL) | (((long) z & 0x3FFFFFFL) << 26) | (((long) y & 0xFFFL) << 52);
}
private static int countAdjacentSources(Instance inst, BlockVec pos, boolean water) {
int c = 0;
for (Direction d : Direction.HORIZONTAL) {
Block nb = inst.getBlock(new BlockVec(pos.blockX() + d.normalX(), pos.blockY(), pos.blockZ() + d.normalZ()));
if ((water ? isWater(nb) : isLava(nb)) && parseLevel(nb) == 0) c++;
}
return c;
}
private static boolean hasSolidBelow(Instance inst, BlockVec pos) {
Block below = inst.getBlock(new BlockVec(pos.blockX(), pos.blockY() - 1, pos.blockZ()));
return below.isSolid();
}
private static boolean handleFluidCollision(Instance inst, BlockVec pos, boolean incomingIsWater) {
Block target = inst.getBlock(pos);
if (incomingIsWater && isLava(target)) {
boolean lavaSource = parseLevel(target) == 0;
inst.setBlock(pos, lavaSource ? Block.OBSIDIAN : Block.COBBLESTONE);
return true;
}
if (!incomingIsWater && isWater(target)) {
inst.setBlock(pos, Block.STONE);
return true;
}
return false;
}
private static boolean isReplaceable(Block b) {
if (b.isAir()) return true;
String p = b.key().value();
return p.equals("short_grass") || p.equals("tall_grass") || p.equals("fern") || p.equals("large_fern")
|| p.equals("dead_bush") || p.equals("seagrass") || p.equals("tall_seagrass") || p.equals("vine")
|| p.equals("snow") || p.equals("fire") || p.equals("soul_fire");
}
private static boolean isWater(Block b) { return b.compare(Block.WATER); }
private static boolean isLava(Block b) { return b.compare(Block.LAVA); }
private static int parseLevel(Block b) {
String s = b.getProperty("level");
if (s == null) return 0;
try { return Integer.parseInt(s); } catch (NumberFormatException e) { return 0; }
}
}
@@ -172,5 +172,9 @@ public class ColorJump extends StatelessGame {
this.getScore().insertResult(player); this.getScore().insertResult(player);
player.setGameMode(GameMode.SPECTATOR); player.setGameMode(GameMode.SPECTATOR);
} }
if(!this.isBeforeBeginning && !this.isRunning) {
player.setGameMode(GameMode.SPECTATOR);
player.teleport(this.getSpawn());
}
} }
} }
@@ -44,4 +44,17 @@ public class Position {
public static boolean hasPositionChanged(Pos oldPos, Pos newPos) { public static boolean hasPositionChanged(Pos oldPos, Pos newPos) {
return !oldPos.withView(0, 0).equals(newPos.withView(0, 0)); return !oldPos.withView(0, 0).equals(newPos.withView(0, 0));
} }
public static boolean isInArea(Point point, Point pos1, Point pos2) {
double minX = Math.min(pos1.x(), pos2.x());
double maxX = Math.max(pos1.x(), pos2.x());
double minY = Math.min(pos1.y(), pos2.y());
double maxY = Math.max(pos1.y(), pos2.y());
double minZ = Math.min(pos1.z(), pos2.z());
double maxZ = Math.max(pos1.z(), pos2.z());
return point.x() >= minX && point.x() <= maxX
&& point.y() >= minY && point.y() <= maxY
&& point.z() >= minZ && point.z() <= maxZ;
}
} }
+2
View File
@@ -9,6 +9,8 @@ bungeecord:
velocity: velocity:
enabled: false enabled: false
# Chat nur über den Proxy verteilen, hier verwerfen (chat-bridge)
chat-via-proxy: false
secret: '' secret: ''
api: api:
+5
View File
@@ -191,3 +191,8 @@ description;Jump on the right color!;Springe auf die richtige Farbe!
ns:game_PlayerRace#;; ns:game_PlayerRace#;;
name;Player Race;Wettrennen name;Player Race;Wettrennen
description;Get to the other side as quickly as possible!;Komme so schnell wie möglich auf die andere Seite! description;Get to the other side as quickly as possible!;Komme so schnell wie möglich auf die andere Seite!
;;
ns:game_BuildBattle#;;
name;Build Battle;Bauwettbewerb
description;Build the best creation for the given theme before time runs out and win through the other players’ ratings.;Baue in der Zeit das beste Bauwerk zum Thema und gewinne durch die Bewertung der anderen Spieler.
seconds;Build Time;Bauzeit
1 map en_us de_de
191 ns:game_PlayerRace#
192 name Player Race Wettrennen
193 description Get to the other side as quickly as possible! Komme so schnell wie möglich auf die andere Seite!
194
195 ns:game_BuildBattle#
196 name Build Battle Bauwettbewerb
197 description Build the best creation for the given theme before time runs out and win through the other players’ ratings. Baue in der Zeit das beste Bauwerk zum Thema und gewinne durch die Bewertung der anderen Spieler.
198 seconds Build Time Bauzeit