-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSourceMovement.java
68 lines (54 loc) · 2.89 KB
/
SourceMovement.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLPaths;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.event.config.ModConfigEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.nio.file.Path;
@Mod("sourcemovement")
public class SourceMovement {
private static final Logger LOGGER = LogManager.getLogger();
private PlayerMovementManager playerMovementManager;
private CommandHandler commandHandler;
public SourceMovement() {
// register the configuration
Path configPath = FMLPaths.CONFIGDIR.get().resolve("sourcemovement.toml");
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, SourceMovementConfig.SPEC, configPath.toString());
// register event listeners
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onServerStarting);
// register the config change listener
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onConfigChanged);
}
private void setup(final FMLCommonSetupEvent event) {
LOGGER.info("Setting up SourceMovement mod...");
// create instances of PlayerMovementManager and CommandHandler
playerMovementManager = new PlayerMovementManager();
commandHandler = new CommandHandler(playerMovementManager);
// register the PlayerMovementManager with the Forge event bus
MinecraftForge.EVENT_BUS.register(playerMovementManager);
// perform initial validation and loading of config values
SourceMovementConfig.validateConfig();
LOGGER.info("SourceMovement mod setup complete.");
}
private void onServerStarting(final FMLServerStartingEvent event) {
LOGGER.info("Registering SourceMovement commands...");
// register the command handler with the server's command dispatcher
commandHandler.registerCommands(event.getServer().getCommandManager().getDispatcher());
LOGGER.info("SourceMovement commands registered.");
}
@SubscribeEvent
public void onConfigChanged(final ModConfigEvent.Reloading event) {
// ensure we are responding to our mod's configuration changes
if (event.getConfig().getModId().equals("sourcemovement")) {
SourceMovementConfig.refreshConfig();
LOGGER.info("Configuration reloaded, values updated.");
}
}
}