Skip to content
This repository has been archived by the owner on Jul 13, 2024. It is now read-only.

Commit

Permalink
Start with block handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
TonimatasDEV committed Nov 9, 2023
1 parent ba49540 commit fcce7f9
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/main/java/net/tonimatasdev/mossy/Mossy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit fcce7f9

Please sign in to comment.