Added spleef gamemode
This commit is contained in:
		| @@ -5,6 +5,7 @@ import eu.mhsl.minenet.minigames.instance.game.stateless.types.backrooms.Backroo | ||||
| import eu.mhsl.minenet.minigames.instance.game.stateless.types.bedwars.BedwarsFactory; | ||||
| import eu.mhsl.minenet.minigames.instance.game.stateless.types.deathcube.DeathcubeFactory; | ||||
| import eu.mhsl.minenet.minigames.instance.game.stateless.types.minerun.MinerunFactory; | ||||
| import eu.mhsl.minenet.minigames.instance.game.stateless.types.spleef.SpleefFactory; | ||||
| import eu.mhsl.minenet.minigames.instance.game.stateless.types.stickfight.StickFightFactory; | ||||
| import eu.mhsl.minenet.minigames.instance.game.stateless.types.towerdefense.TowerdefenseFactory; | ||||
| import eu.mhsl.minenet.minigames.instance.game.stateless.types.trafficlightrace.TrafficLightRaceFactory; | ||||
| @@ -16,7 +17,8 @@ public enum GameList { | ||||
|     TRAFFICLIGHTRACE(new TrafficLightRaceFactory(), GameType.OTHER), | ||||
|     TOWERDEFENSE(new TowerdefenseFactory(), GameType.PVE), | ||||
|     BEDWARS(new BedwarsFactory(), GameType.PVP), | ||||
|     BACKROOMS(new BackroomsFactory(), GameType.PVE); | ||||
|     BACKROOMS(new BackroomsFactory(), GameType.PVE), | ||||
|     SPLEEF(new SpleefFactory(), GameType.PVP); | ||||
|  | ||||
|     private final GameFactory factory; | ||||
|     private final GameType type; | ||||
|   | ||||
| @@ -0,0 +1,88 @@ | ||||
| package eu.mhsl.minenet.minigames.instance.game.stateless.types.spleef; | ||||
|  | ||||
| import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame; | ||||
| import eu.mhsl.minenet.minigames.message.component.TranslatedComponent; | ||||
| import eu.mhsl.minenet.minigames.score.LastWinsScore; | ||||
| import eu.mhsl.minenet.minigames.util.BatchUtil; | ||||
| import net.minestom.server.coordinate.Pos; | ||||
| import net.minestom.server.entity.GameMode; | ||||
| import net.minestom.server.event.player.PlayerMoveEvent; | ||||
| import net.minestom.server.event.player.PlayerStartDiggingEvent; | ||||
| import net.minestom.server.instance.batch.AbsoluteBlockBatch; | ||||
| import net.minestom.server.instance.block.Block; | ||||
| import net.minestom.server.item.*; | ||||
| import net.minestom.server.world.DimensionType; | ||||
| import org.jetbrains.annotations.NotNull; | ||||
|  | ||||
| import java.util.concurrent.CompletableFuture; | ||||
|  | ||||
| public class Spleef extends StatelessGame { | ||||
|     public Spleef() { | ||||
|         super(DimensionType.OVERWORLD, "Spleef", new LastWinsScore()); | ||||
|  | ||||
|         eventNode().addListener(PlayerStartDiggingEvent.class, this::destroyBlock); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void onLoad(@NotNull CompletableFuture<Void> callback) { | ||||
|         AbsoluteBlockBatch circle = new AbsoluteBlockBatch(); | ||||
|  | ||||
|         for(int x = -20; x <= 20; x++) { | ||||
|             for(int z = -20; z <= 20; z++) { | ||||
|                 circle.setBlock(x, 10, z, Block.SNOW_BLOCK); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         for(int x = -20; x <= 20; x++) { | ||||
|             for(int z = -20; z <= 20; z++) { | ||||
|                 circle.setBlock(x, 20, z, Block.SNOW_BLOCK); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         for(int x = -20; x <= 20; x++) { | ||||
|             for(int z = -20; z <= 20; z++) { | ||||
|                 circle.setBlock(x, 30, z, Block.SNOW_BLOCK); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         BatchUtil.loadAndApplyBatch(circle, this, () -> callback.complete(null)); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void onStart() { | ||||
|         getPlayers().forEach(player -> { | ||||
|             player.setGameMode(GameMode.SURVIVAL); | ||||
|             player.getInventory().addItemStack( | ||||
|                     ItemStack | ||||
|                             .builder(Material.DIAMOND_SHOVEL) | ||||
|                             .displayName(TranslatedComponent.byId("game_Spleef#shovelName").getAssembled(player)) | ||||
|                             .meta( | ||||
|                                 builder -> builder | ||||
|                                     .enchantment(Enchantment.EFFICIENCY, (short) 99) | ||||
|                                     .hideFlag(ItemHideFlag.HIDE_ENCHANTS) | ||||
|                                     .build() | ||||
|                             ) | ||||
|                             .build() | ||||
|             ); | ||||
|             player.setHeldItemSlot((byte) 0); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) { | ||||
|         if(playerMoveEvent.getNewPosition().y() < 9) { | ||||
|             playerMoveEvent.getPlayer().setGameMode(GameMode.SPECTATOR); | ||||
|             playerMoveEvent.getPlayer().getInventory().clear(); | ||||
|             getScore().addResult(playerMoveEvent.getPlayer()); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void destroyBlock(PlayerStartDiggingEvent event) { | ||||
|         setBlock(event.getBlockPosition(), Block.AIR); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Pos getSpawn() { | ||||
|         return new Pos(0, 33, 0); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,41 @@ | ||||
| package eu.mhsl.minenet.minigames.instance.game.stateless.types.spleef; | ||||
|  | ||||
| import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame; | ||||
| 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.restriction.RestrictionHandler; | ||||
| import eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.common.MinimalPlayeramountGameRestriction; | ||||
| import eu.mhsl.minenet.minigames.message.component.TranslatedComponent; | ||||
| import net.minestom.server.item.Material; | ||||
|  | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
|  | ||||
| public class SpleefFactory implements GameFactory { | ||||
|     @Override | ||||
|     public TranslatedComponent name() { | ||||
|         return TranslatedComponent.byId("game_Spleef#name"); | ||||
|     } | ||||
|  | ||||
| //    @Override | ||||
| //    public RestrictionHandler globalRestrictions() { | ||||
| //        return new RestrictionHandler() | ||||
| //                .addRestriction(new MinimalPlayeramountGameRestriction(2)); | ||||
| //    } | ||||
|  | ||||
|     @Override | ||||
|     public Material symbol() { | ||||
|         return Material.DIAMOND_SHOVEL; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public TranslatedComponent description() { | ||||
|         return TranslatedComponent.byId("game_Spleef#description"); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public StatelessGame manufacture(Map<String, Option<?>> configuration) throws Exception { | ||||
|         return new Spleef(); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user