diff --git a/src/main/java/net/tonimatasdev/mossy/Mossy.java b/src/main/java/net/tonimatasdev/mossy/Mossy.java index 72a23e5..b2d11bc 100644 --- a/src/main/java/net/tonimatasdev/mossy/Mossy.java +++ b/src/main/java/net/tonimatasdev/mossy/Mossy.java @@ -9,8 +9,9 @@ import net.minestom.server.instance.block.Block; import net.tonimatasdev.mossy.api.MossyDimensionType; import net.tonimatasdev.mossy.logger.Logger; -import net.tonimatasdev.mossy.manager.CommandManager; -import net.tonimatasdev.mossy.manager.EventManager; +import net.tonimatasdev.mossy.manager.MossyCommandManager; +import net.tonimatasdev.mossy.manager.MossyEventManager; +import net.tonimatasdev.mossy.manager.MossyBlockManager; import net.tonimatasdev.mossy.util.ConsoleThread; public class Mossy { @@ -39,8 +40,9 @@ public static void main(String[] args) { end.setChunkLoader(new AnvilLoader("end")); Logger.info("World \"end\" loaded."); - CommandManager.register(); - EventManager.register(); + MossyBlockManager.init(); + MossyCommandManager.init(); + MossyEventManager.init(); MojangAuth.init(); // Premium diff --git a/src/main/java/net/tonimatasdev/mossy/api/blocks/ChestBlockHandler.java b/src/main/java/net/tonimatasdev/mossy/api/blocks/ChestBlockHandler.java new file mode 100644 index 0000000..1d928aa --- /dev/null +++ b/src/main/java/net/tonimatasdev/mossy/api/blocks/ChestBlockHandler.java @@ -0,0 +1,18 @@ +package net.tonimatasdev.mossy.api.blocks; + +import net.minestom.server.instance.block.BlockHandler; +import net.minestom.server.utils.NamespaceID; +import org.jetbrains.annotations.NotNull; + +public class ChestBlockHandler implements BlockHandler { + @Override + public boolean onInteract(@NotNull Interaction interaction) { + System.out.println("Chest opened."); + return BlockHandler.super.onInteract(interaction); + } + + @Override + public @NotNull NamespaceID getNamespaceId() { + return NamespaceID.from("minecraft:chest"); + } +} diff --git a/src/main/java/net/tonimatasdev/mossy/manager/MossyBlockManager.java b/src/main/java/net/tonimatasdev/mossy/manager/MossyBlockManager.java new file mode 100644 index 0000000..6722448 --- /dev/null +++ b/src/main/java/net/tonimatasdev/mossy/manager/MossyBlockManager.java @@ -0,0 +1,24 @@ +package net.tonimatasdev.mossy.manager; + +import net.minestom.server.MinecraftServer; +import net.minestom.server.instance.block.Block; +import net.minestom.server.instance.block.BlockHandler; +import net.minestom.server.instance.block.BlockManager; +import net.minestom.server.utils.NamespaceID; +import net.tonimatasdev.mossy.api.blocks.ChestBlockHandler; +import net.tonimatasdev.mossy.logger.Logger; + +import java.util.Objects; + +public class MossyBlockManager { + private static BlockManager blockManager = MinecraftServer.getBlockManager(); + + public static void init() { + registerHandler(Block.CHEST, new ChestBlockHandler()); + Logger.info("All blocks registered."); + } + + private static void registerHandler(Block block, BlockHandler blockHandler) { + blockManager.registerHandler(NamespaceID.from("minecraft:" + block.name().toLowerCase()), () -> Objects.requireNonNull(block.withHandler(new ChestBlockHandler()).handler())); + } +} diff --git a/src/main/java/net/tonimatasdev/mossy/manager/CommandManager.java b/src/main/java/net/tonimatasdev/mossy/manager/MossyCommandManager.java similarity index 79% rename from src/main/java/net/tonimatasdev/mossy/manager/CommandManager.java rename to src/main/java/net/tonimatasdev/mossy/manager/MossyCommandManager.java index 2f53aee..0644bc0 100644 --- a/src/main/java/net/tonimatasdev/mossy/manager/CommandManager.java +++ b/src/main/java/net/tonimatasdev/mossy/manager/MossyCommandManager.java @@ -3,12 +3,13 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.minestom.server.MinecraftServer; +import net.minestom.server.command.CommandManager; import net.tonimatasdev.mossy.commands.*; import net.tonimatasdev.mossy.logger.Logger; -public class CommandManager { - public static void register() { - net.minestom.server.command.CommandManager commandManager = MinecraftServer.getCommandManager(); +public class MossyCommandManager { + public static void init() { + CommandManager commandManager = MinecraftServer.getCommandManager(); commandManager.register(new GameModeCommand()); commandManager.register(new DifficultyCommand()); diff --git a/src/main/java/net/tonimatasdev/mossy/manager/EventManager.java b/src/main/java/net/tonimatasdev/mossy/manager/MossyEventManager.java similarity index 89% rename from src/main/java/net/tonimatasdev/mossy/manager/EventManager.java rename to src/main/java/net/tonimatasdev/mossy/manager/MossyEventManager.java index ef2a65a..1fb0f72 100644 --- a/src/main/java/net/tonimatasdev/mossy/manager/EventManager.java +++ b/src/main/java/net/tonimatasdev/mossy/manager/MossyEventManager.java @@ -5,8 +5,8 @@ import net.tonimatasdev.mossy.events.*; import net.tonimatasdev.mossy.logger.Logger; -public class EventManager { - public static void register() { +public class MossyEventManager { + public static void init() { GlobalEventHandler eventHandler = MinecraftServer.getGlobalEventHandler(); BlockEvents.init(eventHandler); InstanceEvents.init(eventHandler); diff --git a/src/main/java/net/tonimatasdev/mossy/util/ConsoleThread.java b/src/main/java/net/tonimatasdev/mossy/util/ConsoleThread.java index 52437fb..e7d4854 100644 --- a/src/main/java/net/tonimatasdev/mossy/util/ConsoleThread.java +++ b/src/main/java/net/tonimatasdev/mossy/util/ConsoleThread.java @@ -15,7 +15,6 @@ public static void stopConsole() { public void run() { while (!isStop) { Scanner scanner = new Scanner(System.in); - System.out.print("> "); String command = scanner.nextLine(); MinecraftServer.getCommandManager().executeServerCommand(command); }