Files
src
build.gradle
settings.gradle
Code
7 397
src/main/java/com/stonesmp/graceperiod/StoneSMPGracePeriod.java
package com.stonesmp.graceperiod;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
public final class StoneSMPGracePeriod extends JavaPlugin {
private GracePeriodManager gracePeriodManager;
@Override
public void onEnable() {
saveDefaultConfig();
gracePeriodManager = new GracePeriodManager(
this,
getConfig().getBoolean("grace.protect-from-hostile-mob-damage", false)
);
Bukkit.getPluginManager().registerEvents(gracePeriodManager, this);
long defaultDuration = getConfig().getLong("grace.duration-seconds", 600L);
if (defaultDuration <= 0) {
defaultDuration = 600L;
getLogger().warning("grace.duration-seconds must be positive; using 600 seconds.");
}
PluginCommand command = getCommand("graceperiod");
if (command == null) {
throw new IllegalStateException("The graceperiod command is missing from plugin.yml.");
}
GracePeriodCommand executor = new GracePeriodCommand(gracePeriodManager, defaultDuration);
command.setExecutor(executor);
command.setTabCompleter(executor);
if (getConfig().getBoolean("grace.enabled", true)
&& !gracePeriodManager.start(defaultDuration)) {
getLogger().warning("Could not start the configured grace period duration.");
}
}
@Override
public void onDisable() {
if (gracePeriodManager != null) {
gracePeriodManager.stop();
}
}
}