Use Bukkit YAML for home configuration

This commit is contained in:
2026-09-26 22:43:41 -07:00
parent 6df83fbee9
commit 509df1b452
3 changed files with 56 additions and 33 deletions

View File

@@ -13,7 +13,7 @@
| MET-009 | Done | Review custom scripts and resources for required updates to the Gradle build and modern Paper server workflow. | | MET-009 | Done | Review custom scripts and resources for required updates to the Gradle build and modern Paper server workflow. |
| MET-010 | Done | Refactor plugin logging to use JavaPlugin.getLogger(). | | MET-010 | Done | Refactor plugin logging to use JavaPlugin.getLogger(). |
| MET-011 | Done | Refactor event listeners and registration to use Listener, @EventHandler, and the modern plugin manager API. | | MET-011 | Done | Refactor event listeners and registration to use Listener, @EventHandler, and the modern plugin manager API. |
| MET-012 | Ready | Replace deprecated configuration APIs with the modern Bukkit/Paper configuration API, including load, save, and reload behavior. | | MET-012 | Done | Replace deprecated configuration APIs with the modern Bukkit/Paper configuration API, including load, save, and reload behavior. |
| MET-013 | Ready | Replace Player-keyed storage with UUID-based storage wherever player identity is persisted or tracked. | | MET-013 | Ready | Replace Player-keyed storage with UUID-based storage wherever player identity is persisted or tracked. |
| MET-014 | Ready | Review player lookup logic and use exact or otherwise explicit name-matching behavior where appropriate. | | MET-014 | Ready | Review player lookup logic and use exact or otherwise explicit name-matching behavior where appropriate. |
| MET-015 | Ready | Refactor remaining code that uses deprecated or removed Bukkit, Spigot, or Paper APIs so it is compatible with the target Paper API. | | MET-015 | Ready | Refactor remaining code that uses deprecated or removed Bukkit, Spigot, or Paper APIs so it is compatible with the target Paper API. |

View File

@@ -20,6 +20,8 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.Configuration; import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
@@ -38,7 +40,6 @@ import com.majinnaibu.bukkitplugins.metropolis.commands.MetropolisHomeMoveComman
import com.majinnaibu.bukkitplugins.metropolis.commands.MetropolisPlotGoCommand; import com.majinnaibu.bukkitplugins.metropolis.commands.MetropolisPlotGoCommand;
import com.majinnaibu.bukkitplugins.metropolis.commands.MetropolisPlotReserveCommand; import com.majinnaibu.bukkitplugins.metropolis.commands.MetropolisPlotReserveCommand;
import com.majinnaibu.bukkitplugins.metropolis.eventlisteners.PlayerJoinListener; import com.majinnaibu.bukkitplugins.metropolis.eventlisteners.PlayerJoinListener;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
@@ -87,7 +88,7 @@ public class MetropolisPlugin extends JavaPlugin {
private Material roadSupportMaterial = Material.STONE; private Material roadSupportMaterial = Material.STONE;
private String worldName = "world"; private String worldName = "world";
private boolean generateFloor = false; private boolean generateFloor = false;
private Material floorMaterial = Material.GRASS; private Material floorMaterial = Material.GRASS_BLOCK;
private int spaceAboveFloor = 2; private int spaceAboveFloor = 2;
private boolean generateSign = false; private boolean generateSign = false;
private boolean generateSpawn = true; private boolean generateSpawn = true;
@@ -164,7 +165,7 @@ public class MetropolisPlugin extends JavaPlugin {
spawnFloorMaterial = safeGetMaterialFromConfig(config, "spawn.material"); spawnFloorMaterial = safeGetMaterialFromConfig(config, "spawn.material");
generateWall = safeGetBooleanFromConfig(config, "wall.generate"); generateWall = safeGetBooleanFromConfig(config, "wall.generate");
wallMaterial = safeGetMaterialFromConfig(config, "wall.material"); wallMaterial = safeGetMaterialFromConfig(config, "wall.material");
wallHeight = safeGetIntFromConfig(config, "wall.material"); wallHeight = safeGetIntFromConfig(config, "wall.height");
worldName = safeGetStringFromConfig(config, "worldname"); worldName = safeGetStringFromConfig(config, "worldname");
_maxPlots = safeGetIntFromConfig(config, "plot.multiplier"); _maxPlots = safeGetIntFromConfig(config, "plot.multiplier");
_plotMultiplier = safeGetIntFromConfig(config, "plot.maxPerPlayer"); _plotMultiplier = safeGetIntFromConfig(config, "plot.maxPerPlayer");
@@ -297,19 +298,24 @@ public class MetropolisPlugin extends JavaPlugin {
} }
private void loadCurrentHomes() { private void loadCurrentHomes() {
YAMLProcessor processor = new YAMLProcessor(new File(getDataFolder(), "currentHomes.yml"), true); File homesFile = new File(getDataFolder(), "currentHomes.yml");
if (!homesFile.exists()) {
return;
}
YamlConfiguration homes = new YamlConfiguration();
try { try {
processor.load(); homes.load(homesFile);
} catch (IOException e) { } catch (IOException | InvalidConfigurationException e) {
getLogger().info(e.toString()); getLogger().log(java.util.logging.Level.SEVERE, "Unable to load currentHomes.yml", e);
return; return;
} }
Set<String> keys = processor.getMap().keySet();
_currentHomes.clear(); _currentHomes.clear();
for(String username : keys){ for(String username : homes.getKeys(false)){
_currentHomes.put(username, processor.getInt(username, 0)); int homeNumber = homes.getInt(username, 0);
if (homeNumber > 0) {
_currentHomes.put(username, homeNumber);
}
} }
} }
@@ -397,14 +403,20 @@ public class MetropolisPlugin extends JavaPlugin {
private Material safeGetMaterialFromConfig(Configuration config, String name){ private Material safeGetMaterialFromConfig(Configuration config, String name){
Material material = null; Material material = null;
if(config.isInt(name)){ if(config.isInt(name)){
material = Material.getMaterial(config.getInt(name)); material = switch (config.getInt(name)) {
case 1 -> Material.STONE;
case 2 -> Material.GRASS_BLOCK;
case 4 -> Material.COBBLESTONE;
case 7 -> Material.BEDROCK;
default -> null;
};
}else if(config.isString(name)){ }else if(config.isString(name)){
material = Material.getMaterial(config.getString(name)); material = Material.matchMaterial(config.getString(name));
if(material== null){ }
material = Material.matchMaterial(config.getString(name)); if (material == null) {
} getLogger().severe("Invalid material configured at " + name);
throwInvalidConfigException();
} }
return material; return material;
} }
@@ -1077,11 +1089,14 @@ public class MetropolisPlugin extends JavaPlugin {
} }
private void saveCurrentHomes() { private void saveCurrentHomes() {
File outFile = new File(getDataFolder(), "currentHomes.yml"); File homesFile = new File(getDataFolder(), "currentHomes.yml");
YamlConfiguration homes = new YamlConfiguration();
// TODO Auto-generated method stub _currentHomes.forEach(homes::set);
try {
//YAMLProcessor processor = new YAMLProcessor(new File(getDataFolder(), "currentHomes.yml"), true); getDataFolder().mkdirs();
//processor.save(); homes.save(homesFile);
} catch (IOException e) {
getLogger().log(java.util.logging.Level.SEVERE, "Unable to save currentHomes.yml", e);
}
} }
} }

View File

@@ -1,29 +1,37 @@
plot: plot:
sizeX: 32 sizeX: 32
sizeY: 256 sizeY: 256
sizeZ: 32
offsetX: 0
offsetY: 0
offsetZ: 0
multiplier: 1
maxPerPlayer: 1
initial: 1
floor: floor:
generate: true generate: true
clearSpaceAbove: 66 clearSpaceAbove: 66
offsetZ: 0 material: GRASS_BLOCK
supports: supports:
generate: true generate: true
initial: 1 material: STONE
sign: sign:
generate: true generate: true
road:
width: 4 width: 4
clearSpaceAbove: 66 clearSpaceAbove: 66
level: 62 level: 62
generate: true material: COBBLESTONE
supports: supports:
generate: true generate: true
generate: true material: STONE
spawn: spawn:
generate: true generate: true
setAsWorldSpawn: true setAsWorldSpawn: true
level: 62 material: GRASS_BLOCK
wall: wall:
generate: true generate: true
generate: true material: BEDROCK
height: 66 height: 66
worldname: world worldname: world
userOverrides: userOverrides: