Files
src
build.gradle
settings.gradle
Code
29 2,414
src/main/java/com/kodari/smpcore/SmpCoreLite.java
package com.kodari.smpcore;
import com.kodari.smpcore.core.DataStore;
import com.kodari.smpcore.core.MessageService;
import com.kodari.smpcore.core.Module;
import com.kodari.smpcore.core.ModuleManager;
import com.kodari.smpcore.core.TeleportService;
import com.kodari.smpcore.modules.BackModule;
import com.kodari.smpcore.modules.ChatPauseModule;
import com.kodari.smpcore.modules.CombatTagModule;
import com.kodari.smpcore.modules.HomeModule;
import com.kodari.smpcore.modules.NicknameModule;
import com.kodari.smpcore.modules.QualityOfLifeModule;
import com.kodari.smpcore.modules.RtpModule;
import com.kodari.smpcore.modules.SkinModule;
import com.kodari.smpcore.modules.SpawnModule;
import com.kodari.smpcore.modules.SpawnProtectionModule;
import com.kodari.smpcore.modules.TpaModule;
import com.kodari.smpcore.modules.UtilityModule;
import java.io.File;
import java.util.Arrays;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabCompleter;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
public final class SmpCoreLite extends JavaPlugin {
private FileConfiguration messages;
private DataStore dataStore;
private MessageService messageService;
private TeleportService teleportService;
private ModuleManager moduleManager;
@Override
public void onEnable() {
saveDefaultConfig();
saveResource("messages.yml", false);
this.messages = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "messages.yml"));
this.dataStore = new DataStore(this);
this.messageService = new MessageService(this);
this.teleportService = new TeleportService(this);
Bukkit.getPluginManager().registerEvents(teleportService, this);
this.moduleManager = new ModuleManager(this);
Arrays.asList(
new SpawnModule(this),
new RtpModule(this),
new HomeModule(this),
new BackModule(this),
new TpaModule(this),
new UtilityModule(this),
new SpawnProtectionModule(this),
new CombatTagModule(this),
new QualityOfLifeModule(this),
new ChatPauseModule(this),
new NicknameModule(this),
new SkinModule(this)
).forEach(moduleManager::register);
moduleManager.enableAll();
getLogger().info("SmpCoreLite enabled with " + moduleManager.enabledCount() + " modules.");
}
@Override
public void onDisable() {
if (moduleManager != null) {
moduleManager.disableAll();
}
if (dataStore != null) {
dataStore.saveNow();
}
}
public FileConfiguration getMessages() {
return messages;
}
public DataStore data() {
return dataStore;
}
public MessageService messages() {
return messageService;
}
public TeleportService teleports() {
return teleportService;
}
public boolean enabled(String module) {
return getConfig().getBoolean("modules." + module, true);
}
public void registerCommand(String name, CommandExecutor executor) {
PluginCommand command = getCommand(name);
if (command != null) {
command.setExecutor(executor);
if (executor instanceof TabCompleter completer) {
command.setTabCompleter(completer);
}
} else {
getLogger().warning("Command " + name + " is missing from plugin.yml.");
}
}
}