Compare commits
3 Commits
develop-ja
...
73ab137ae4
| Author | SHA1 | Date | |
|---|---|---|---|
| 73ab137ae4 | |||
| 9a9e646288 | |||
| 728dc92fc8 |
@@ -28,8 +28,7 @@ public class StickFightFactory implements GameFactory {
|
||||
@Override
|
||||
public ConfigManager configuration() {
|
||||
return new ConfigManager()
|
||||
.addOption(new NumericOption("length", Material.SANDSTONE, TranslatedComponent.byId("optionCommon#length"), 7, 10, 13, 16, 19))
|
||||
.addOption(new NumericOption("seconds", Material.CLOCK, TranslatedComponent.byId("optionCommon#seconds"), 30, 60, 90, 120));
|
||||
.addOption(new NumericOption("length", Material.SANDSTONE, TranslatedComponent.byId("optionCommon#length"), 7, 10, 13, 16, 19));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,7 +40,7 @@ public class StickFightFactory implements GameFactory {
|
||||
|
||||
@Override
|
||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) {
|
||||
return new Stickfight(configuration.get("length").getAsInt(), configuration.get("seconds").getAsInt()).setParent(parent);
|
||||
return new Stickfight(configuration.get("length").getAsInt()).setParent(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,12 +24,10 @@ public class Stickfight extends StatelessGame {
|
||||
private final WeakHashMap<Player, Pos> spawnPoints = new WeakHashMap<>();
|
||||
private final Map<Player, Integer> scoreMap = new WeakHashMap<>();
|
||||
private boolean countdownStarted = false;
|
||||
private final int seconds;
|
||||
|
||||
public Stickfight(int length, int seconds) {
|
||||
public Stickfight(int length) {
|
||||
super(Dimension.OVERWORLD.key, "Stickfight", new LowestPointsWinScore());
|
||||
this.radius = length;
|
||||
this.seconds = seconds;
|
||||
|
||||
this.eventNode().addChild(
|
||||
CombatFeatures.empty()
|
||||
@@ -90,11 +88,6 @@ public class Stickfight extends StatelessGame {
|
||||
super.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
this.setTimeLimit(this.seconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
this.scoreMap.forEach((player, score) -> this.getScore().insertResult(player, score));
|
||||
|
||||
@@ -6,18 +6,20 @@ import eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.game.Tetri
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.game.Tetromino;
|
||||
import eu.mhsl.minenet.minigames.score.PointsWinScore;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.entity.metadata.display.BlockDisplayMeta;
|
||||
import net.minestom.server.event.player.PlayerHandAnimationEvent;
|
||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||
import net.minestom.server.event.player.PlayerTickEvent;
|
||||
import net.minestom.server.event.player.PlayerUseItemEvent;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import net.minestom.server.potion.Potion;
|
||||
import net.minestom.server.potion.PotionEffect;
|
||||
import net.minestom.server.timer.TaskSchedule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -78,18 +80,24 @@ class Tetris extends StatelessGame {
|
||||
p.setGameMode(GameMode.SURVIVAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent event) {
|
||||
private void onPlayerInteract(@NotNull PlayerUseItemEvent event) {
|
||||
event.setItemUseTime(0);
|
||||
this.tetrisGames.get(event.getPlayer()).pressedButton(TetrisGame.Button.mouseRight);
|
||||
}
|
||||
|
||||
private void onPlayerAttack(@NotNull PlayerHandAnimationEvent event) {
|
||||
this.tetrisGames.get(event.getPlayer()).pressedButton(TetrisGame.Button.mouseLeft);
|
||||
}
|
||||
|
||||
private void onPlayerTick(PlayerTickEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Pos currentPosition = event.getNewPosition();
|
||||
|
||||
TetrisGame tetrisGame = this.tetrisGames.get(player);
|
||||
|
||||
if(tetrisGame == null) {
|
||||
event.setCancelled(true);
|
||||
if(tetrisGame == null) return;
|
||||
if(tetrisGame.lost) {
|
||||
this.letPlayerLoose(player);
|
||||
return;
|
||||
}
|
||||
if(tetrisGame.lost) return;
|
||||
|
||||
if(player.getGameMode() == GameMode.SPECTATOR) return;
|
||||
|
||||
if(player.inputs().forward()) tetrisGame.pressedButton(TetrisGame.Button.W);
|
||||
@@ -97,26 +105,6 @@ class Tetris extends StatelessGame {
|
||||
if(player.inputs().right()) tetrisGame.pressedButton(TetrisGame.Button.D);
|
||||
if(player.inputs().left()) tetrisGame.pressedButton(TetrisGame.Button.A);
|
||||
if(player.inputs().jump()) tetrisGame.pressedButton(TetrisGame.Button.space);
|
||||
|
||||
event.setNewPosition(tetrisGame.getPlayerSpawnPosition().withView(currentPosition));
|
||||
player.setSprinting(false);
|
||||
}
|
||||
|
||||
protected void onPlayerInteract(@NotNull PlayerUseItemEvent event) {
|
||||
this.tetrisGames.get(event.getPlayer()).pressedButton(TetrisGame.Button.mouseRight);
|
||||
}
|
||||
|
||||
protected void onPlayerAttack(@NotNull PlayerHandAnimationEvent event) {
|
||||
this.tetrisGames.get(event.getPlayer()).pressedButton(TetrisGame.Button.mouseLeft);
|
||||
}
|
||||
|
||||
protected void onPlayerTick(PlayerTickEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
TetrisGame tetrisGame = this.tetrisGames.get(player);
|
||||
if(tetrisGame == null) return;
|
||||
if(tetrisGame.lost && player.getGameMode() != GameMode.SPECTATOR) {
|
||||
this.letPlayerLoose(player);
|
||||
}
|
||||
}
|
||||
|
||||
private void letPlayerLoose(Player player) {
|
||||
@@ -124,6 +112,7 @@ class Tetris extends StatelessGame {
|
||||
if(!this.getScore().hasResult(player)) {
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
player.setInvisible(true);
|
||||
if(player.getVehicle() != null) player.getVehicle().removePassenger(player);
|
||||
this.getScore().insertResult(player, tetrisGame.getScore());
|
||||
}
|
||||
|
||||
@@ -160,7 +149,16 @@ class Tetris extends StatelessGame {
|
||||
|
||||
p.teleport(tetrisGame.getPlayerSpawnPosition());
|
||||
tetrisGame.sidebar.addViewer(p);
|
||||
p.addEffect(new Potion(PotionEffect.SLOWNESS, 4, Potion.INFINITE_DURATION));
|
||||
|
||||
MinecraftServer.getSchedulerManager().scheduleTask(() -> {
|
||||
Entity ghostBlock = new Entity(EntityType.BLOCK_DISPLAY);
|
||||
((BlockDisplayMeta) ghostBlock.getEntityMeta()).setBlockState(Block.AIR);
|
||||
ghostBlock.setNoGravity(true);
|
||||
ghostBlock.setInstance(this, tetrisGame.getPlayerSpawnPosition());
|
||||
ghostBlock.addPassenger(p);
|
||||
return TaskSchedule.stop();
|
||||
}, TaskSchedule.nextTick());
|
||||
|
||||
|
||||
return super.onPlayerJoin(p);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user