Files
src
pom.xml
Code
10 612
src/main/java/com/niloy/netherlinker/NetherLinker.java
package com.niloy.netherlinker;
import com.niloy.netherlinker.commands.NetherLinkerCommand;
import com.niloy.netherlinker.listeners.PortalListener;
import com.niloy.netherlinker.managers.ConfigManager;
import com.niloy.netherlinker.managers.MessageManager;
import com.niloy.netherlinker.placeholders.NetherLinkerExpansion;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level;
public final class NetherLinker extends JavaPlugin {
private final Map<UUID, NamespacedKey> sourceWorlds = new HashMap<>();
private ConfigManager configManager;
private MessageManager messageManager;
private NetherLinkerExpansion placeholderExpansion;
@Override
public void onEnable() {
saveDefaultConfig();
saveResource("messages.yml", false);
this.configManager = new ConfigManager(this);
this.messageManager = new MessageManager(this);
this.configManager.load();
this.messageManager.load();
validateWorlds();
Bukkit.getPluginManager().registerEvents(new PortalListener(this), this);
NetherLinkerCommand commandHandler = new NetherLinkerCommand(this);
getCommand("netherlinker").setExecutor(commandHandler);
getCommand("netherlinker").setTabCompleter(commandHandler);
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
this.placeholderExpansion = new NetherLinkerExpansion(this);
this.placeholderExpansion.register();
getLogger().info("PlaceholderAPI integration enabled");
}
getLogger().info("NetherLinker enabled - Nether world: " + configManager.getNetherWorld().asString());
getLogger().info("Tracked overworlds: " + configManager.getOverworlds().size());
}
@Override
public void onDisable() {
if (this.placeholderExpansion != null) {
this.placeholderExpansion.unregister();
}
this.sourceWorlds.clear();
}
public void reload() {
reloadConfig();
this.configManager.load();
this.messageManager.load();
validateWorlds();
}
private void validateWorlds() {
NamespacedKey netherKey = configManager.getNetherWorld();
World netherWorld = Bukkit.getWorld(netherKey);
if (netherWorld == null) {
getLogger().log(Level.WARNING, "Configured nether world '" + netherKey.asString() + "' does not exist!");
}
NamespacedKey fallbackKey = configManager.getFallbackWorld();
World fallbackWorld = Bukkit.getWorld(fallbackKey);
if (fallbackWorld == null) {
getLogger().log(Level.WARNING, "Configured fallback world '" + fallbackKey.asString() + "' does not exist!");
}
for (NamespacedKey overworldKey : configManager.getOverworlds()) {
World overworld = Bukkit.getWorld(overworldKey);
if (overworld == null) {
getLogger().log(Level.WARNING, "Configured overworld '" + overworldKey.asString() + "' does not exist!");
}
}
}
public Map<UUID, NamespacedKey> getSourceWorlds() {
return sourceWorlds;
}
public ConfigManager getConfigManager() {
return configManager;
}
public MessageManager getMessageManager() {
return messageManager;
}
}