Files
src
pom.xml
README.md
Code
8 757
src/main/java/com/worldhome/WorldHomePlugin.java
package com.worldhome;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
public final class WorldHomePlugin extends JavaPlugin {
private Set<String> enabledWorlds = Set.of();
private Set<String> configuredWorlds = Set.of();
private Map<String, Map<String, String>> dimensionWorlds = Map.of();
private HomeStorage homeStorage;
@Override
public void onEnable() {
saveDefaultConfig();
reloadWorldConfiguration();
homeStorage = new HomeStorage(this);
WorldHomeCommand commandHandler = new WorldHomeCommand(this);
registerCommand("sethome", commandHandler);
registerCommand("home", commandHandler);
registerCommand("delhome", commandHandler);
registerCommand("homes", commandHandler);
registerCommand("worldhome", commandHandler);
getServer().getPluginManager().registerEvents(new PortalListener(this), this);
}
public void reloadWorldConfiguration() {
reloadConfig();
Set<String> worlds = new LinkedHashSet<>();
for (String worldName : getConfig().getStringList("enabled-worlds")) {
if (worldName != null && !worldName.isBlank()) {
worlds.add(worldName.trim());
}
}
Set<String> configured = new LinkedHashSet<>(worlds);
Map<String, Map<String, String>> links = new LinkedHashMap<>();
var dimensions = getConfig().getConfigurationSection("dimension-worlds");
if (dimensions != null) {
for (String sourceWorld : dimensions.getKeys(false)) {
var sourceLinks = dimensions.getConfigurationSection(sourceWorld);
if (sourceLinks == null) {
continue;
}
Map<String, String> linksForWorld = new LinkedHashMap<>();
for (String dimension : Set.of("overworld", "nether", "end")) {
String targetWorld = sourceLinks.getString(dimension);
if (targetWorld != null && !targetWorld.isBlank()) {
targetWorld = targetWorld.trim();
linksForWorld.put(dimension, targetWorld);
configured.add(targetWorld);
}
}
links.put(sourceWorld, linksForWorld);
configured.add(sourceWorld);
}
}
enabledWorlds = Collections.unmodifiableSet(worlds);
configuredWorlds = Collections.unmodifiableSet(configured);
dimensionWorlds = Collections.unmodifiableMap(links);
for (String worldName : configuredWorlds) {
if (Bukkit.getWorld(worldName) == null) {
getLogger().warning("Configured world '" + worldName + "' is not loaded. WorldHome does not create or delete worlds; check Multiverse-Core's world registration and the world folder.");
}
}
}
private void registerCommand(String name, WorldHomeCommand commandHandler) {
PluginCommand command = getCommand(name);
if (command != null) {
command.setExecutor(commandHandler);
command.setTabCompleter(commandHandler);
}
}
public boolean isEnabledWorld(String worldName) {
return enabledWorlds.contains(worldName);
}
public String getLinkedWorld(String sourceWorld, String dimension) {
Map<String, String> links = dimensionWorlds.get(sourceWorld);
return links == null ? null : links.get(dimension.toLowerCase(Locale.ROOT));
}
public Set<String> getEnabledWorlds() {
return enabledWorlds;
}
public Set<String> getConfiguredWorlds() {
return configuredWorlds;
}
public HomeStorage getHomeStorage() {
return homeStorage;
}
}