Files
src
build.gradle
README.md
settings.gradle
Code
26 1,780
src/main/java/com/ebicep/perworldinventory/PerWorldInventory.java
package com.ebicep.perworldinventory;
import com.ebicep.perworldinventory.command.PWICommand;
import com.ebicep.perworldinventory.config.ConfigManager;
import com.ebicep.perworldinventory.listener.PlayerDeathListener;
import com.ebicep.perworldinventory.listener.PlayerJoinListener;
import com.ebicep.perworldinventory.listener.PlayerQuitListener;
import com.ebicep.perworldinventory.listener.PlayerWorldChangeListener;
import com.ebicep.perworldinventory.manager.CacheManager;
import com.ebicep.perworldinventory.manager.DataManager;
import com.ebicep.perworldinventory.manager.EconomyManager;
import com.ebicep.perworldinventory.manager.WorldManager;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
@Getter
public class PerWorldInventory extends JavaPlugin {
private ConfigManager configManager;
private WorldManager worldManager;
private DataManager dataManager;
private CacheManager cacheManager;
private EconomyManager economyManager;
@Override
public void onEnable() {
long startTime = System.currentTimeMillis();
initializeDataFolder();
this.configManager = new ConfigManager(this);
this.worldManager = new WorldManager(this);
this.cacheManager = new CacheManager(this);
this.dataManager = new DataManager(this);
this.economyManager = new EconomyManager(this);
registerCommands();
registerListeners();
long loadTime = System.currentTimeMillis() - startTime;
log(LogLevel.INFO, "PerWorldInventory v" + getDescription().getVersion() + " enabled in " + loadTime + "ms");
log(LogLevel.INFO, "Loaded " + worldManager.getGroups().size() + " world groups");
if (economyManager.isEnabled()) {
log(LogLevel.INFO, "Economy support enabled via Vault");
}
}
@Override
public void onDisable() {
if (dataManager != null) {
dataManager.saveAllOnlinePlayers();
}
if (cacheManager != null) {
cacheManager.shutdown();
}
log(LogLevel.INFO, "PerWorldInventory disabled");
}
private void initializeDataFolder() {
File dataFolder = new File(getDataFolder(), "data");
if (!dataFolder.exists()) {
dataFolder.mkdirs();
}
}
private void registerCommands() {
getCommand("pwi").setExecutor(new PWICommand(this));
}
private void registerListeners() {
Bukkit.getPluginManager().registerEvents(new PlayerWorldChangeListener(this), this);
Bukkit.getPluginManager().registerEvents(new PlayerJoinListener(this), this);
Bukkit.getPluginManager().registerEvents(new PlayerQuitListener(this), this);
Bukkit.getPluginManager().registerEvents(new PlayerDeathListener(this), this);
}
public void reload() {
configManager.reload();
worldManager.reload();
cacheManager.clear();
log(LogLevel.INFO, "Configuration reloaded");
}
public void log(LogLevel level, String message) {
LogLevel configLevel = configManager != null ? configManager.getLoggingLevel() : LogLevel.INFO;
if (level.ordinal() >= configLevel.ordinal()) {
getLogger().info("[" + level + "] " + message);
}
}
public enum LogLevel {
DEBUG,
FINE,
INFO
}
}