implemented fastbridge gameplay
This commit is contained in:
		| @@ -2,18 +2,63 @@ package eu.mhsl.minenet.minigames.instance.game.stateless.types.fastbridge; | ||||
|  | ||||
| import eu.mhsl.minenet.minigames.instance.Dimension; | ||||
| import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame; | ||||
| import eu.mhsl.minenet.minigames.score.PointsWinScore; | ||||
| import eu.mhsl.minenet.minigames.score.FirstWinsScore; | ||||
| import net.minestom.server.coordinate.Pos; | ||||
| import net.minestom.server.entity.GameMode; | ||||
| import net.minestom.server.entity.Player; | ||||
| import net.minestom.server.event.player.PlayerBlockPlaceEvent; | ||||
| import net.minestom.server.event.player.PlayerMoveEvent; | ||||
| import net.minestom.server.instance.Chunk; | ||||
| import net.minestom.server.inventory.PlayerInventory; | ||||
| import net.minestom.server.item.ItemStack; | ||||
| import net.minestom.server.item.Material; | ||||
| import org.jetbrains.annotations.NotNull; | ||||
|  | ||||
| public class Fastbridge extends StatelessGame { | ||||
|     private int currentSpawn = 0; | ||||
|  | ||||
|     public Fastbridge() { | ||||
|         super(Dimension.OVERWORLD.key, "Fastbridge", new PointsWinScore()); | ||||
|         super(Dimension.OVERWORLD.key, "Fastbridge", new FirstWinsScore()); | ||||
|         this.setGenerator(new FastbridgeChunkgenerator()); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Pos getSpawn() { | ||||
|         return new Pos(0, 3, 0); | ||||
|     protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) { | ||||
|         Player player = playerMoveEvent.getPlayer(); | ||||
|         Pos newPos = playerMoveEvent.getNewPosition(); | ||||
|         if(this.getScore().hasResult(player)) return; | ||||
|         if(newPos.y() < -65) { | ||||
|             player.teleport(getSpawn()); | ||||
|             if(!isBeforeBeginning) this.resetPlayer(player); | ||||
|         } | ||||
|         if(newPos.x() > 53) { | ||||
|             this.getScore().insertResult(player); | ||||
|             player.setGameMode(GameMode.SPECTATOR); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void onStart() { | ||||
|         getPlayers().forEach(player -> { | ||||
|             player.setGameMode(GameMode.SURVIVAL); | ||||
|             resetPlayer(player); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void onBlockPlace(@NotNull PlayerBlockPlaceEvent playerBlockPlaceEvent) { | ||||
|         if(isBeforeBeginning) playerBlockPlaceEvent.setCancelled(true); | ||||
|     } | ||||
|  | ||||
|     private void resetPlayer(Player player) { | ||||
|         if(isBeforeBeginning) return; | ||||
|         PlayerInventory inventory = player.getInventory(); | ||||
|         inventory.clear(); | ||||
|         inventory.addItemStack(ItemStack.of(Material.WHITE_WOOL, 64)); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public synchronized Pos getSpawn() { | ||||
|         return new Pos(24, -60, currentSpawn++*Chunk.CHUNK_SIZE_Z*2-8, -90, 0); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -8,15 +8,15 @@ import org.jetbrains.annotations.NotNull; | ||||
| public class FastbridgeChunkgenerator implements Generator { | ||||
|     @Override | ||||
|     public void generate(@NotNull GenerationUnit unit) { | ||||
|         //unit.modifier().fill(unit.absoluteStart(), unit.absoluteEnd().withY(2), Block.GRASS_BLOCK); | ||||
|         if (unit.absoluteStart().chunkX() != 1 && unit.absoluteStart().chunkX() != 3) return; | ||||
|         if (unit.absoluteStart().chunkZ() % 2 == 0) { | ||||
|             unit.modifier().fill(Block.BARRIER); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         if (unit.absoluteStart().chunkX() != 1 && unit.absoluteStart().chunkX() != 3) return; | ||||
|         for (int x = 5; x <= 10; x++){ | ||||
|             for (int z = 5; z <= 10; z++){ | ||||
|                 unit.modifier().setRelative(x, 2, z,Block.GRASS_BLOCK); | ||||
|                 unit.modifier().setRelative(x, 2, z, unit.absoluteStart().chunkX() == 3 ? Block.GOLD_BLOCK : Block.GRASS_BLOCK); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -17,6 +17,6 @@ public class FastbridgeFactory implements GameFactory { | ||||
|  | ||||
|     @Override | ||||
|     public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception { | ||||
|         return new Fastbridge(); | ||||
|         return new Fastbridge().setParent(parent); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user