Add example of config as well
This commit is contained in:
@@ -3,20 +3,32 @@ package dev.hytalemodding;
|
||||
import com.hypixel.hytale.server.core.event.events.player.PlayerReadyEvent;
|
||||
import com.hypixel.hytale.server.core.plugin.JavaPlugin;
|
||||
import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
|
||||
import com.hypixel.hytale.server.core.util.Config;
|
||||
import dev.hytalemodding.commands.ExampleCommand;
|
||||
import dev.hytalemodding.config.ExampleConfig;
|
||||
import dev.hytalemodding.events.ExampleEvent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ExamplePlugin extends JavaPlugin {
|
||||
|
||||
private static Config<ExampleConfig> config = null;
|
||||
|
||||
public ExamplePlugin(@Nonnull JavaPluginInit init) {
|
||||
super(init);
|
||||
config = this.withConfig("example_config", ExampleConfig.CODEC);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
config.save();
|
||||
this.getCommandRegistry().registerCommand(new ExampleCommand("example", "An example command"));
|
||||
if (getConfig().get().isEnabledWelcomeMessage()) {
|
||||
this.getEventRegistry().registerGlobal(PlayerReadyEvent.class, ExampleEvent::onPlayerReady);
|
||||
}
|
||||
}
|
||||
|
||||
public static Config<ExampleConfig> getConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
25
src/main/java/dev/hytalemodding/config/ExampleConfig.java
Normal file
25
src/main/java/dev/hytalemodding/config/ExampleConfig.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package dev.hytalemodding.config;
|
||||
|
||||
import com.hypixel.hytale.codec.Codec;
|
||||
import com.hypixel.hytale.codec.KeyedCodec;
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
|
||||
public class ExampleConfig {
|
||||
|
||||
public static final BuilderCodec<ExampleConfig> CODEC = BuilderCodec.builder(ExampleConfig.class, ExampleConfig::new)
|
||||
.append(
|
||||
new KeyedCodec<>("EnableWelcomeMessage", Codec.BOOLEAN),
|
||||
(exConfig, aBoolean, extraInfo) -> exConfig.enabledWelcomeMessage = aBoolean,
|
||||
(exConfig, extraInfo) -> exConfig.enabledWelcomeMessage
|
||||
)
|
||||
.add()
|
||||
.build();
|
||||
|
||||
private boolean enabledWelcomeMessage;
|
||||
|
||||
private ExampleConfig() {}
|
||||
|
||||
public boolean isEnabledWelcomeMessage() {
|
||||
return enabledWelcomeMessage;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user