Game api additions, Refactoring, Translation api edits
This commit is contained in:
		| @@ -0,0 +1,72 @@ | ||||
| package eu.mhsl.minenet.minigames.instance; | ||||
|  | ||||
| import eu.mhsl.minenet.minigames.message.component.TranslatedComponent; | ||||
| import net.minestom.server.MinecraftServer; | ||||
| import net.minestom.server.entity.Player; | ||||
| import net.minestom.server.event.instance.AddEntityToInstanceEvent; | ||||
| import net.minestom.server.event.instance.RemoveEntityFromInstanceEvent; | ||||
| import net.minestom.server.instance.Instance; | ||||
| import net.minestom.server.instance.InstanceContainer; | ||||
| import net.minestom.server.timer.TaskSchedule; | ||||
| import net.minestom.server.world.DimensionType; | ||||
|  | ||||
| import java.util.UUID; | ||||
|  | ||||
| public class MineNetInstance extends InstanceContainer { | ||||
|     public MineNetInstance(DimensionType type) { | ||||
|         super(UUID.randomUUID(), type); | ||||
|         MinecraftServer.getInstanceManager().registerInstance(this); | ||||
|  | ||||
|         eventNode() | ||||
|                 .addListener(AddEntityToInstanceEvent.class, this::onEntityAdd) | ||||
|                 .addListener(RemoveEntityFromInstanceEvent.class, this::onEntityRemove); | ||||
|     } | ||||
|  | ||||
|     private void onEntityRemove(RemoveEntityFromInstanceEvent removeEntityFromInstanceEvent) { | ||||
|         if(removeEntityFromInstanceEvent.getEntity() instanceof Player p) { | ||||
|             this.onPlayerLeave(p); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void onEntityAdd(AddEntityToInstanceEvent addEntityToInstanceEvent) { | ||||
|         if(addEntityToInstanceEvent.getEntity() instanceof Player p) { | ||||
|             addEntityToInstanceEvent.setCancelled(this.onPlayerJoin(p)); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Called when Player joins this instance | ||||
|      * @param p player who is joining | ||||
|      * @return setCanceled | ||||
|      */ | ||||
|     protected boolean onPlayerJoin(Player p) { | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Called when Player leaves this instance | ||||
|      * @param p player who is leaving | ||||
|      */ | ||||
|     protected void onPlayerLeave(Player p) { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @param target | ||||
|      */ | ||||
|     public void destroy(Instance target) { | ||||
|         getPlayers().forEach(player -> { | ||||
|             if(target != null) | ||||
|                 player.setInstance(target); | ||||
|             else | ||||
|                 player.kick(TranslatedComponent.raw("sample").getAssembled(player)); | ||||
|         }); | ||||
|  | ||||
|         MinecraftServer.getSchedulerManager().scheduleTask( | ||||
|                 () -> MinecraftServer.getInstanceManager().unregisterInstance(this), | ||||
|                 TaskSchedule.seconds(10), | ||||
|                 TaskSchedule.stop() | ||||
|         ); | ||||
|     } | ||||
| } | ||||
| @@ -1,11 +1,13 @@ | ||||
| package eu.mhsl.minenet.minigames.instance.game; | ||||
|  | ||||
| import eu.mhsl.minenet.minigames.instance.MineNetInstance; | ||||
| import eu.mhsl.minenet.minigames.util.CommonEventHandles; | ||||
| import eu.mhsl.minenet.minigames.instance.Spawnable; | ||||
| import eu.mhsl.minenet.minigames.instance.room.Room; | ||||
| import io.github.bloepiloepi.pvp.config.PvPConfig; | ||||
| import net.minestom.server.MinecraftServer; | ||||
| import net.minestom.server.coordinate.Pos; | ||||
| import net.minestom.server.entity.Player; | ||||
| import net.minestom.server.event.EventNode; | ||||
| import net.minestom.server.event.instance.AddEntityToInstanceEvent; | ||||
| import net.minestom.server.event.instance.RemoveEntityFromInstanceEvent; | ||||
| @@ -23,33 +25,31 @@ import org.jetbrains.annotations.NotNull; | ||||
| import java.util.Random; | ||||
| import java.util.UUID; | ||||
| import java.util.concurrent.CompletableFuture; | ||||
| import java.util.logging.Logger; | ||||
|  | ||||
| public abstract class Game extends InstanceContainer implements Spawnable { | ||||
| public abstract class Game extends MineNetInstance implements Spawnable { | ||||
|  | ||||
|     protected boolean isRunning = false; | ||||
|     protected boolean isBeforeBeginning = true; | ||||
|  | ||||
|     protected final Random rnd = new Random(); //TODO better way than ths? | ||||
|  | ||||
|     protected final Logger logger; | ||||
|  | ||||
|     public Game(DimensionType dimensionType) { | ||||
|         super(UUID.randomUUID(), dimensionType); | ||||
|         super(dimensionType); | ||||
|  | ||||
|         MinecraftServer.getInstanceManager().registerInstance(this); | ||||
|  | ||||
|         logger = Logger.getLogger("Game:" + getUniqueId()); | ||||
|  | ||||
|         eventNode() | ||||
|                 .addListener(PlayerMoveEvent.class, this::onPlayerMove) | ||||
|                 .addListener(PlayerBlockBreakEvent.class, this::onBlockBreak) | ||||
|                 .addListener(PlayerBlockPlaceEvent.class, this::onBlockPlace) | ||||
|                 .addListener(AddEntityToInstanceEvent.class, this::onJoin) | ||||
|                 .addListener(RemoveEntityFromInstanceEvent.class, this::onLeave) | ||||
|                 .addListener(ItemDropEvent.class, this::onItemDrop); | ||||
|     } | ||||
|  | ||||
|     public void enablePvpConfig(PvPConfig config) { | ||||
|         //eventNode().addChild((EventNode<? extends InstanceEvent>) config.createNode()); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * Load and start countdown | ||||
|      */ | ||||
| @@ -82,7 +82,7 @@ public abstract class Game extends InstanceContainer implements Spawnable { | ||||
|  | ||||
|         scheduler().scheduleTask(() -> { | ||||
|  | ||||
|             System.out.println("stopping game instance " + this.uniqueId); | ||||
|             logger.info("stopping game instance " + this.uniqueId); | ||||
|             getPlayers().forEach(player -> player.kick("timeout")); | ||||
|  | ||||
|             MinecraftServer.getInstanceManager().unregisterInstance(this); | ||||
| @@ -108,15 +108,8 @@ public abstract class Game extends InstanceContainer implements Spawnable { | ||||
|         playerBlockPlaceEvent.setCancelled(true); | ||||
|     } | ||||
|  | ||||
|     protected void onJoin(@NotNull AddEntityToInstanceEvent addEntityToInstanceEvent) { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Make sure when overriding to call checkAbandoned to insure no garbage instances | ||||
|      * @param removeEntityFromInstanceEvent | ||||
|      */ | ||||
|     protected void onLeave(@NotNull RemoveEntityFromInstanceEvent removeEntityFromInstanceEvent) { | ||||
|     @Override | ||||
|     protected void onPlayerLeave(Player p) { | ||||
|         this.checkAbandoned(); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| package eu.mhsl.minenet.minigames.instance.game.minigame; | ||||
| package eu.mhsl.minenet.minigames.instance.game; | ||||
| 
 | ||||
| import eu.mhsl.minenet.minigames.instance.game.minigame.config.GameFactory; | ||||
| import eu.mhsl.minenet.minigames.instance.game.minigame.types.deathcube.DeathcubeFactory; | ||||
| @@ -6,17 +6,23 @@ import eu.mhsl.minenet.minigames.instance.game.minigame.types.minerun.MinerunFac | ||||
| import eu.mhsl.minenet.minigames.instance.game.minigame.types.stickfight.StickFightFactory; | ||||
| import eu.mhsl.minenet.minigames.instance.game.minigame.types.trafficlightrace.TrafficLightRaceFactory; | ||||
| 
 | ||||
| public enum MinigameType { | ||||
|     DEATHCUBE(new DeathcubeFactory()), | ||||
|     STICKFIGHT(new StickFightFactory()), | ||||
|     MINERUN(new MinerunFactory()), | ||||
|     TRAFFICLIGHTRACE(new TrafficLightRaceFactory()); | ||||
| public enum GameList { | ||||
|     DEATHCUBE(new DeathcubeFactory(), GameType.OTHER), | ||||
|     STICKFIGHT(new StickFightFactory(), GameType.PVP), | ||||
|     MINERUN(new MinerunFactory(), GameType.PVE), | ||||
|     TRAFFICLIGHTRACE(new TrafficLightRaceFactory(), GameType.OTHER); | ||||
| 
 | ||||
|     private GameFactory factory; | ||||
|     MinigameType(GameFactory factory) { | ||||
|     private GameType type; | ||||
|     GameList(GameFactory factory, GameType type) { | ||||
|         this.factory = factory; | ||||
|         this.type = type; | ||||
|     } | ||||
|     public GameFactory getFactory() { | ||||
|         return this.factory; | ||||
|     } | ||||
| 
 | ||||
|     public GameType getType() { | ||||
|         return type; | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,36 @@ | ||||
| package eu.mhsl.minenet.minigames.instance.game; | ||||
|  | ||||
| import eu.mhsl.minenet.minigames.message.component.NamespacedTranslatable; | ||||
| import eu.mhsl.minenet.minigames.message.component.TranslatedComponent; | ||||
| import net.minestom.server.item.Material; | ||||
|  | ||||
| public enum GameType { | ||||
|     OTHER(Material.GRASS_BLOCK, TranslatedComponent.raw("GameType#other"), TranslatedComponent.raw("GameType#other_description")), | ||||
|     PVP(Material.DIAMOND_SWORD, TranslatedComponent.raw("GameType#pvp"), TranslatedComponent.raw("GameType#pvp_description")), | ||||
|     PVE(Material.DIAMOND_PICKAXE, TranslatedComponent.raw("GameType#pve"), TranslatedComponent.raw("GameType#pve_description")); | ||||
|  | ||||
|  | ||||
|     Material icon; | ||||
|     TranslatedComponent title; | ||||
|     TranslatedComponent description; | ||||
|  | ||||
|     GameType(Material icon, TranslatedComponent title, TranslatedComponent description) { | ||||
|         this.title = title; | ||||
|         this.description = description; | ||||
|         this.icon = icon; | ||||
|     } | ||||
|  | ||||
|     public Material getIcon() { | ||||
|         return icon; | ||||
|     } | ||||
|  | ||||
|     public TranslatedComponent getTitle() { | ||||
|         return title; | ||||
|     } | ||||
|  | ||||
|     public TranslatedComponent getDescription() { | ||||
|         return description; | ||||
|     } | ||||
|  | ||||
|  | ||||
| } | ||||
| @@ -72,7 +72,6 @@ public class Minigame extends Game { | ||||
|  | ||||
|             if(timeLimit > 0) { | ||||
|                 scheduler().submitTask(() -> { | ||||
|                     System.out.println("Countdown running..."); | ||||
|                     if(!isRunning || timeLimit == 0) return TaskSchedule.stop(); | ||||
|                     if(timeLimit <= timePlayed) { | ||||
|                         stop(); | ||||
|   | ||||
| @@ -40,9 +40,6 @@ class Minerun extends Minigame { | ||||
|         this.width = width; | ||||
|         this.length = length; | ||||
|         this.minePercentage = minePercentage; | ||||
|  | ||||
|         System.out.println(width + " " + length + " " + minePercentage); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
| @@ -26,7 +26,6 @@ public class MinerunFactory implements GameFactory { | ||||
|  | ||||
|     @Override | ||||
|     public Minigame manufacture(Map<String, Option<?>> configuration) { | ||||
|         System.out.println("Manufacture" + configuration.get("width").getAsInt()); | ||||
|         return new Minerun(configuration.get("width").getAsInt(), configuration.get("length").getAsInt(), configuration.get("percentage").getAsInt()); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -59,11 +59,6 @@ public class Stickfight extends Minigame { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void onJoin(@NotNull AddEntityToInstanceEvent addEntityToInstanceEvent) { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Pos getSpawn() { | ||||
|         return new Pos(0.5, 51, 0.5); | ||||
|   | ||||
| @@ -1,12 +1,14 @@ | ||||
| package eu.mhsl.minenet.minigames.instance.hub; | ||||
| 
 | ||||
| import eu.mhsl.minenet.minigames.Resource; | ||||
| import eu.mhsl.minenet.minigames.instance.MineNetInstance; | ||||
| import eu.mhsl.minenet.minigames.instance.hub.entity.RoomSelector; | ||||
| import eu.mhsl.minenet.minigames.util.CommonEventHandles; | ||||
| import eu.mhsl.minenet.minigames.instance.Spawnable; | ||||
| import eu.mhsl.minenet.minigames.instance.Dimension; | ||||
| import net.minestom.server.MinecraftServer; | ||||
| import net.minestom.server.coordinate.Pos; | ||||
| import net.minestom.server.event.instance.AddEntityToInstanceEvent; | ||||
| import net.minestom.server.event.player.*; | ||||
| import net.minestom.server.instance.AnvilLoader; | ||||
| import net.minestom.server.instance.InstanceContainer; | ||||
| @@ -14,8 +16,8 @@ import net.minestom.server.instance.InstanceContainer; | ||||
| import java.nio.file.Path; | ||||
| import java.util.UUID; | ||||
| 
 | ||||
| public class HubInstance extends InstanceContainer implements Spawnable { | ||||
|     public static final HubInstance INSTANCE = new HubInstance(); | ||||
| public class Hub extends MineNetInstance implements Spawnable { | ||||
|     public static final Hub INSTANCE = new Hub(); | ||||
| 
 | ||||
|     static { | ||||
|         MinecraftServer.getInstanceManager().registerInstance(INSTANCE); | ||||
| @@ -30,14 +32,15 @@ public class HubInstance extends InstanceContainer implements Spawnable { | ||||
|         new RoomSelector().setInstance(INSTANCE, new Pos(0.5, 11, 4.5)); | ||||
|     } | ||||
| 
 | ||||
|     private HubInstance() { | ||||
|         super(UUID.randomUUID(), Dimension.THE_END.DIMENSION); | ||||
|     private Hub() { | ||||
|         super(Dimension.THE_END.DIMENSION); | ||||
|         setChunkLoader(new AnvilLoader(Path.of("maps/hub"))); | ||||
| 
 | ||||
|         setTime(18000); | ||||
|         setTimeRate(0); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     @Override | ||||
|     public Pos getSpawn() { | ||||
|         return new Pos(0.5, 11, 0.5); | ||||
| @@ -4,7 +4,7 @@ import eu.mhsl.minenet.minigames.instance.room.Room; | ||||
| import eu.mhsl.minenet.minigames.message.Icon; | ||||
| import eu.mhsl.minenet.minigames.message.type.ChatMessage; | ||||
| import eu.mhsl.minenet.minigames.shared.inventory.InteractableInventory; | ||||
| import eu.mhsl.minenet.minigames.instance.hub.HubInstance; | ||||
| import eu.mhsl.minenet.minigames.instance.hub.Hub; | ||||
| import net.kyori.adventure.text.Component; | ||||
| import net.minestom.server.MinecraftServer; | ||||
| import net.minestom.server.entity.Player; | ||||
| @@ -37,7 +37,7 @@ public class JoinInventory extends InteractableInventory { | ||||
|                 itemClick -> {} | ||||
|         ); | ||||
|  | ||||
|         HubInstance.INSTANCE.eventNode().addListener(PlayerPacketEvent.class, event -> { | ||||
|         Hub.INSTANCE.eventNode().addListener(PlayerPacketEvent.class, event -> { | ||||
|             if (event.getPacket() instanceof ClientNameItemPacket packet) { | ||||
|                 typedText = packet.itemName(); | ||||
|             } | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package eu.mhsl.minenet.minigames.instance.room; | ||||
|  | ||||
| import eu.mhsl.minenet.minigames.Resource; | ||||
| import eu.mhsl.minenet.minigames.instance.MineNetInstance; | ||||
| import eu.mhsl.minenet.minigames.instance.game.Game; | ||||
| import eu.mhsl.minenet.minigames.message.Icon; | ||||
| import eu.mhsl.minenet.minigames.message.type.ChatMessage; | ||||
| @@ -8,7 +9,7 @@ import eu.mhsl.minenet.minigames.util.CommonEventHandles; | ||||
| import eu.mhsl.minenet.minigames.util.MoveInstance; | ||||
| import eu.mhsl.minenet.minigames.instance.Spawnable; | ||||
| import eu.mhsl.minenet.minigames.instance.Dimension; | ||||
| import eu.mhsl.minenet.minigames.instance.hub.HubInstance; | ||||
| import eu.mhsl.minenet.minigames.instance.hub.Hub; | ||||
| import eu.mhsl.minenet.minigames.instance.room.entity.GameSelector; | ||||
| import net.minestom.server.MinecraftServer; | ||||
| import net.minestom.server.coordinate.Pos; | ||||
| @@ -19,21 +20,23 @@ import net.minestom.server.instance.AnvilLoader; | ||||
| import net.minestom.server.instance.InstanceContainer; | ||||
|  | ||||
| import java.util.*; | ||||
| import java.util.logging.Logger; | ||||
| import java.util.stream.Collectors; | ||||
|  | ||||
| public class Room extends InstanceContainer implements Spawnable { | ||||
| public class Room extends MineNetInstance implements Spawnable { | ||||
|     private static final Map<Player, Room> rooms = new WeakHashMap<>(); | ||||
|     private static final Logger logger = Logger.getLogger("room"); | ||||
|  | ||||
|     public static Room createRoom(Player owner) { | ||||
|         System.out.println("Room created by " + owner.getUsername()); | ||||
|         logger.info("Creating room with owner " + owner.getUsername()); | ||||
|         setRoom(owner, new Room(owner)); | ||||
|         return getRoom(owner); | ||||
|     } | ||||
|  | ||||
|     public static void deleteRoom(Room room) { | ||||
|         System.out.println("Room deleted"); | ||||
|         logger.info("Deleting room with owner " + room.owner.getUsername()); | ||||
|         rooms.values().removeAll(Collections.singleton(room)); // remove(room) would only remove the first one | ||||
|         room.getAllMembers().forEach(player -> MoveInstance.move(player, HubInstance.INSTANCE)); | ||||
|         room.getAllMembers().forEach(player -> MoveInstance.move(player, Hub.INSTANCE)); | ||||
|         MoveInstance.forceCloseInstance(room); | ||||
|     } | ||||
|  | ||||
| @@ -46,6 +49,7 @@ public class Room extends InstanceContainer implements Spawnable { | ||||
|     } | ||||
|  | ||||
|     public static void setRoom(Player p, Room room) { | ||||
|         logger.info("Set room for player " + p.getUsername() + " to room by " + room.owner.getUsername()); | ||||
|         p.clearEffects(); | ||||
|         p.clearTitle(); | ||||
|         p.getInventory().clear(); | ||||
| @@ -54,6 +58,7 @@ public class Room extends InstanceContainer implements Spawnable { | ||||
|     } | ||||
|  | ||||
|     public static void unsetRoom(Player p) { | ||||
|         logger.info("Unset room for " + p.getUsername()); | ||||
|         rooms.remove(p); | ||||
|     } | ||||
|  | ||||
| @@ -63,7 +68,7 @@ public class Room extends InstanceContainer implements Spawnable { | ||||
|  | ||||
|     private Player owner; | ||||
|     private Room(Player owner) { | ||||
|         super(UUID.randomUUID(), Dimension.THE_END.DIMENSION); | ||||
|         super(Dimension.THE_END.DIMENSION); | ||||
|         MinecraftServer.getInstanceManager().registerInstance(this); | ||||
|         setChunkLoader(new AnvilLoader(Resource.LOBBY_MAP.getPath())); | ||||
|  | ||||
| @@ -82,7 +87,6 @@ public class Room extends InstanceContainer implements Spawnable { | ||||
|         this.owner = newOwner; | ||||
|  | ||||
|         this.owner.eventNode().addListener(PlayerDisconnectEvent.class, playerDisconnectEvent -> { | ||||
|             System.out.println("Room Leader left room"); | ||||
|             Player p = playerDisconnectEvent.getPlayer(); | ||||
|  | ||||
|             if(p != this.owner) return; // return if the current handling player is really the current owner | ||||
| @@ -100,11 +104,14 @@ public class Room extends InstanceContainer implements Spawnable { | ||||
|             new ChatMessage(Icon.ERROR).appendStatic("The room leader left!").send(getAllMembers()); | ||||
|             new ChatMessage(Icon.SCIENCE).appendStatic(this.owner.getUsername()).appendStatic(" is the new Leader!").send(getAllMembers().stream().filter(player -> player != this.owner).collect(Collectors.toSet())); | ||||
|             new ChatMessage(Icon.SUCCESS).appendStatic("You are now the leader.").send(this.owner); | ||||
|  | ||||
|             logger.info("Room owner changed from " + p.getUsername() + " to " + owner.getUsername()); | ||||
|         }); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public void moveMembersToGame(Game game) { | ||||
|         logger.info("Move room group with " + this.getAllMembers().size() + " players to Game " + game.getUniqueId()); | ||||
|         this.getAllMembers().forEach(player -> { | ||||
|             MoveInstance.move(player, game); | ||||
|         }); | ||||
|   | ||||
| @@ -1,11 +0,0 @@ | ||||
| package eu.mhsl.minenet.minigames.instance.room.inventory; | ||||
|  | ||||
| import eu.mhsl.minenet.minigames.shared.inventory.InteractableInventory; | ||||
| import net.kyori.adventure.text.Component; | ||||
| import net.minestom.server.inventory.InventoryType; | ||||
|  | ||||
| public class BoardInventory extends InteractableInventory { | ||||
|     public BoardInventory() { | ||||
|         super(InventoryType.CHEST_3_ROW, Component.text("Brettspiele")); | ||||
|     } | ||||
| } | ||||
| @@ -1,6 +1,7 @@ | ||||
| package eu.mhsl.minenet.minigames.instance.room.inventory; | ||||
|  | ||||
| import eu.mhsl.minenet.minigames.instance.game.minigame.MinigameType; | ||||
| import eu.mhsl.minenet.minigames.instance.game.GameList; | ||||
| import eu.mhsl.minenet.minigames.instance.game.GameType; | ||||
| import eu.mhsl.minenet.minigames.instance.game.minigame.config.GameConfigurationInventory; | ||||
| import eu.mhsl.minenet.minigames.instance.game.minigame.config.GameFactory; | ||||
| import eu.mhsl.minenet.minigames.shared.inventory.InteractableInventory; | ||||
| @@ -12,11 +13,39 @@ import net.minestom.server.item.Material; | ||||
|  | ||||
| public class MinigameTypeSelectInventory extends InteractableInventory { | ||||
|     public MinigameTypeSelectInventory() { | ||||
|         super(InventoryType.CHEST_3_ROW, Component.text("MineNet Servernetzwerk")); | ||||
|         super(InventoryType.CHEST_6_ROW, Component.text("MineNet Servernetzwerk")); | ||||
|  | ||||
|         int i = 0; | ||||
|         for (MinigameType minigameType : MinigameType.values()) { | ||||
|             GameFactory gameFactory = minigameType.getFactory(); | ||||
|         int typeCount = 0; | ||||
|         for (GameType type : GameType.values()) { | ||||
|             setClickableItem( | ||||
|                     ItemStack.builder(type.getIcon()) | ||||
|                             .displayName(type.getTitle().asComponent()) | ||||
|                             .lore(type.getDescription().asComponent()) | ||||
|                             .build(), | ||||
|                     typeCount, | ||||
|                     itemClick -> { | ||||
|                         drawGames(type); | ||||
|                     } | ||||
|             ); | ||||
|             typeCount++; | ||||
|         } | ||||
|  | ||||
|         for(int i = 9; i <= 17; i++) { | ||||
|             setDummyItem(Material.CYAN_STAINED_GLASS_PANE, i); | ||||
|         } | ||||
|  | ||||
|  | ||||
|     } | ||||
|  | ||||
|     private void drawGames(GameType type) { | ||||
|         for(int i = 18; i <= 53; i++) { | ||||
|             setDummyItem(Material.AIR, i); | ||||
|         } | ||||
|         int gameCount = 18; | ||||
|         for (GameList gameList : GameList.values()) { | ||||
|             if(!gameList.getType().equals(type)) continue; | ||||
|  | ||||
|             GameFactory gameFactory = gameList.getFactory(); | ||||
|  | ||||
|             setClickableItem( | ||||
|                     ItemStack.builder(gameFactory.symbol()) | ||||
| @@ -24,41 +53,10 @@ public class MinigameTypeSelectInventory extends InteractableInventory { | ||||
|                             .lore(gameFactory.description()) | ||||
|                             .meta(metaBuilder -> metaBuilder.hideFlag(ItemHideFlag.HIDE_ATTRIBUTES)) | ||||
|                             .build(), | ||||
|                     i, | ||||
|                     gameCount, | ||||
|                     itemClick -> itemClick.getPlayer().openInventory(new GameConfigurationInventory(gameFactory)) | ||||
|             ); | ||||
|             i++; | ||||
|             gameCount++; | ||||
|         } | ||||
|  | ||||
| //        setClickableItem( | ||||
| //                ItemStack | ||||
| //                        .builder(Material.IRON_SWORD) | ||||
| //                        .displayName(Component.text("PVP Spiele")) | ||||
| //                        .lore(Component.text("Player versus Player")) | ||||
| //                        .meta(metaBuilder -> metaBuilder.hideFlag(ItemHideFlag.HIDE_ATTRIBUTES)) | ||||
| //                        .build(), | ||||
| //                11, | ||||
| //                itemClick -> itemClick.getPlayer().openInventory(new PvpInventory()) | ||||
| //        ); | ||||
| // | ||||
| //        setClickableItem( | ||||
| //                ItemStack | ||||
| //                        .builder(Material.ZOMBIE_HEAD) | ||||
| //                        .displayName(Component.text("PVE Arenen")) | ||||
| //                        .lore(Component.text("Player versus Entity")) | ||||
| //                        .build(), | ||||
| //                13, | ||||
| //                itemClick -> itemClick.getPlayer().openInventory(new PveInventory()) | ||||
| //        ); | ||||
| // | ||||
| //        setClickableItem( | ||||
| //                ItemStack | ||||
| //                        .builder(Material.BRICK_SLAB) | ||||
| //                        .displayName(Component.text("Brettspiele")) | ||||
| //                        .lore(Component.text("Bekannte Brettspieler aller Art")) | ||||
| //                        .build(), | ||||
| //                15, | ||||
| //                itemClick -> itemClick.getPlayer().openInventory(new BoardInventory()) | ||||
| //        ); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,41 +0,0 @@ | ||||
| package eu.mhsl.minenet.minigames.instance.room.inventory; | ||||
|  | ||||
| import eu.mhsl.minenet.minigames.instance.game.minigame.config.GameConfigurationInventory; | ||||
| import eu.mhsl.minenet.minigames.instance.game.minigame.types.minerun.MinerunFactory; | ||||
| import eu.mhsl.minenet.minigames.shared.inventory.InteractableInventory; | ||||
| import eu.mhsl.minenet.minigames.instance.game.minigame.types.deathcube.DeathcubeFactory; | ||||
| import eu.mhsl.minenet.minigames.instance.game.minigame.types.trafficlightrace.TrafficLightRaceFactory; | ||||
| import net.kyori.adventure.text.Component; | ||||
| import net.minestom.server.inventory.InventoryType; | ||||
| import net.minestom.server.item.ItemStack; | ||||
| import net.minestom.server.item.Material; | ||||
|  | ||||
| public class PveInventory extends InteractableInventory { | ||||
|     public PveInventory() { | ||||
|         super(InventoryType.CHEST_3_ROW, Component.text("PVE")); | ||||
|  | ||||
|         setClickableItem( | ||||
|                 ItemStack.builder(Material.LIGHT_WEIGHTED_PRESSURE_PLATE).displayName(Component.text("Minerun")).lore(Component.text("Jump between ground mines to the finish")).build(), | ||||
|                 0, | ||||
|                 itemClick -> { | ||||
|                     itemClick.getPlayer().openInventory(new GameConfigurationInventory(new MinerunFactory())); | ||||
|                 } | ||||
|         ); | ||||
|  | ||||
|         setClickableItem( | ||||
|                 ItemStack.builder(Material.YELLOW_WOOL).displayName(Component.text("Ampelrennen")).build(), | ||||
|                 1, | ||||
|                 itemClick -> { | ||||
|                     itemClick.getPlayer().openInventory(new GameConfigurationInventory(new TrafficLightRaceFactory())); | ||||
|                 } | ||||
|         ); | ||||
|  | ||||
|         setClickableItem( | ||||
|                 ItemStack.builder(Material.RED_WOOL).displayName(Component.text("Deathcube")).build(), | ||||
|                 2, | ||||
|                 itemClick -> { | ||||
|                     itemClick.getPlayer().openInventory(new GameConfigurationInventory(new DeathcubeFactory())); | ||||
|                 } | ||||
|         ); | ||||
|     } | ||||
| } | ||||
| @@ -1,27 +0,0 @@ | ||||
| package eu.mhsl.minenet.minigames.instance.room.inventory; | ||||
|  | ||||
| import eu.mhsl.minenet.minigames.instance.game.minigame.config.GameConfigurationInventory; | ||||
| import eu.mhsl.minenet.minigames.instance.game.minigame.types.stickfight.StickFightFactory; | ||||
| import eu.mhsl.minenet.minigames.shared.inventory.InteractableInventory; | ||||
| import net.kyori.adventure.text.Component; | ||||
| import net.minestom.server.entity.Player; | ||||
| import net.minestom.server.inventory.InventoryType; | ||||
| import net.minestom.server.inventory.click.ClickType; | ||||
| import net.minestom.server.inventory.condition.InventoryConditionResult; | ||||
| import net.minestom.server.item.ItemStack; | ||||
| import net.minestom.server.item.Material; | ||||
|  | ||||
| public class PvpInventory extends InteractableInventory { | ||||
|     public PvpInventory() { | ||||
|         super(InventoryType.CHEST_6_ROW, Component.text("PVP")); | ||||
|  | ||||
|         setClickableItem(ItemStack.of(Material.GOLD_INGOT), 4, itemClick -> { | ||||
|             itemClick.getPlayer().openInventory(new GameConfigurationInventory(new StickFightFactory())); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void onClick(Player player, int slot, ClickType clickType, InventoryConditionResult inventoryConditionResult) { | ||||
|         super.onClick(player, slot, clickType, inventoryConditionResult); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user