mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-24 11:38:29 +01:00
Updated to the new Configuration api
This commit is contained in:
parent
255778b388
commit
c818414fd5
@ -1,9 +1,15 @@
|
|||||||
package org.bukkit.craftbukkit;
|
package org.bukkit.craftbukkit;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
|
import org.bukkit.configuration.serialization.SerializableAs;
|
||||||
|
|
||||||
public class CraftOfflinePlayer implements OfflinePlayer {
|
@SerializableAs("Player")
|
||||||
|
public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializable {
|
||||||
private final String name;
|
private final String name;
|
||||||
private final CraftServer server;
|
private final CraftServer server;
|
||||||
|
|
||||||
@ -61,4 +67,22 @@ public class CraftOfflinePlayer implements OfflinePlayer {
|
|||||||
server.getHandle().removeWhitelist(name.toLowerCase());
|
server.getHandle().removeWhitelist(name.toLowerCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> serialize() {
|
||||||
|
Map<String, Object> result = new LinkedHashMap<String, Object>();
|
||||||
|
|
||||||
|
result.put("name", name);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OfflinePlayer deserialize(Map<String, Object> args) {
|
||||||
|
System.out.println("Deserializing CraftOfflinePlayer with args " + args);
|
||||||
|
return Bukkit.getServer().getOfflinePlayer((String)args.get("name"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getClass().getSimpleName() + "[name=" + name + "]";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,9 @@ import net.minecraft.server.WorldMap;
|
|||||||
import net.minecraft.server.WorldMapCollection;
|
import net.minecraft.server.WorldMapCollection;
|
||||||
import net.minecraft.server.WorldSettings;
|
import net.minecraft.server.WorldSettings;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||||
import org.bukkit.permissions.Permissible;
|
import org.bukkit.permissions.Permissible;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
@ -71,8 +74,6 @@ import org.bukkit.util.permissions.DefaultPermissions;
|
|||||||
import org.bukkit.event.world.WorldInitEvent;
|
import org.bukkit.event.world.WorldInitEvent;
|
||||||
import org.bukkit.permissions.Permission;
|
import org.bukkit.permissions.Permission;
|
||||||
import org.bukkit.plugin.PluginLoadOrder;
|
import org.bukkit.plugin.PluginLoadOrder;
|
||||||
import org.bukkit.util.config.Configuration;
|
|
||||||
import org.bukkit.util.config.ConfigurationNode;
|
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
import org.yaml.snakeyaml.constructor.SafeConstructor;
|
import org.yaml.snakeyaml.constructor.SafeConstructor;
|
||||||
import org.yaml.snakeyaml.error.MarkedYAMLException;
|
import org.yaml.snakeyaml.error.MarkedYAMLException;
|
||||||
@ -88,10 +89,14 @@ public final class CraftServer implements Server {
|
|||||||
protected final MinecraftServer console;
|
protected final MinecraftServer console;
|
||||||
protected final ServerConfigurationManager server;
|
protected final ServerConfigurationManager server;
|
||||||
private final Map<String, World> worlds = new LinkedHashMap<String, World>();
|
private final Map<String, World> worlds = new LinkedHashMap<String, World>();
|
||||||
private final Configuration configuration;
|
private YamlConfiguration configuration;
|
||||||
private final Yaml yaml = new Yaml(new SafeConstructor());
|
private final Yaml yaml = new Yaml(new SafeConstructor());
|
||||||
private final Map<String, OfflinePlayer> offlinePlayers = new MapMaker().softValues().makeMap();
|
private final Map<String, OfflinePlayer> offlinePlayers = new MapMaker().softValues().makeMap();
|
||||||
|
|
||||||
|
static {
|
||||||
|
ConfigurationSerialization.registerClass(CraftOfflinePlayer.class);
|
||||||
|
}
|
||||||
|
|
||||||
public CraftServer(MinecraftServer console, ServerConfigurationManager server) {
|
public CraftServer(MinecraftServer console, ServerConfigurationManager server) {
|
||||||
this.console = console;
|
this.console = console;
|
||||||
this.server = server;
|
this.server = server;
|
||||||
@ -99,35 +104,27 @@ public final class CraftServer implements Server {
|
|||||||
|
|
||||||
Bukkit.setServer(this);
|
Bukkit.setServer(this);
|
||||||
|
|
||||||
configuration = new Configuration((File) console.options.valueOf("bukkit-settings"));
|
configuration = YamlConfiguration.loadConfiguration(getConfigFile());
|
||||||
loadConfig();
|
configuration.options().copyDefaults(true);
|
||||||
|
configuration.setDefaults(YamlConfiguration.loadConfiguration(getClass().getClassLoader().getResourceAsStream("configurations/bukkit.yml")));
|
||||||
|
saveConfig();
|
||||||
|
|
||||||
loadPlugins();
|
loadPlugins();
|
||||||
enablePlugins(PluginLoadOrder.STARTUP);
|
enablePlugins(PluginLoadOrder.STARTUP);
|
||||||
|
|
||||||
ChunkCompressionThread.startThread();
|
ChunkCompressionThread.startThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadConfig() {
|
private File getConfigFile() {
|
||||||
configuration.load();
|
return (File)console.options.valueOf("bukkit-settings");
|
||||||
configuration.getString("database.url", "jdbc:sqlite:{DIR}{NAME}.db");
|
}
|
||||||
configuration.getString("database.username", "bukkit");
|
|
||||||
configuration.getString("database.password", "walrus");
|
private void saveConfig() {
|
||||||
configuration.getString("database.driver", "org.sqlite.JDBC");
|
try {
|
||||||
configuration.getString("database.isolation", "SERIALIZABLE");
|
configuration.save(getConfigFile());
|
||||||
|
} catch (IOException ex) {
|
||||||
configuration.getString("settings.update-folder", "update");
|
Logger.getLogger(CraftServer.class.getName()).log(Level.SEVERE, "Could not save " + getConfigFile(), ex);
|
||||||
configuration.getInt("settings.spawn-radius", 16);
|
|
||||||
|
|
||||||
configuration.getString("settings.permissions-file", "permissions.yml");
|
|
||||||
|
|
||||||
configuration.getInt("settings.ping-packet-limit", 100);
|
|
||||||
|
|
||||||
if (configuration.getNode("aliases") == null) {
|
|
||||||
List<String> icanhasbukkit = new ArrayList<String>();
|
|
||||||
icanhasbukkit.add("version");
|
|
||||||
configuration.setProperty("aliases.icanhasbukkit", icanhasbukkit);
|
|
||||||
}
|
}
|
||||||
configuration.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadPlugins() {
|
public void loadPlugins() {
|
||||||
@ -365,7 +362,7 @@ public final class CraftServer implements Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void reload() {
|
public void reload() {
|
||||||
loadConfig();
|
configuration = YamlConfiguration.loadConfiguration(getConfigFile());
|
||||||
PropertyManager config = new PropertyManager(console.options);
|
PropertyManager config = new PropertyManager(console.options);
|
||||||
|
|
||||||
console.propertyManager = config;
|
console.propertyManager = config;
|
||||||
@ -692,17 +689,18 @@ public final class CraftServer implements Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String[]> getCommandAliases() {
|
public Map<String, String[]> getCommandAliases() {
|
||||||
ConfigurationNode node = configuration.getNode("aliases");
|
ConfigurationSection section = configuration.getConfigurationSection("aliases");
|
||||||
Map<String, String[]> result = new LinkedHashMap<String, String[]>();
|
Map<String, String[]> result = new LinkedHashMap<String, String[]>();
|
||||||
|
|
||||||
if (node != null) {
|
if (section != null) {
|
||||||
for (String key : node.getKeys()) {
|
for (String key : section.getKeys(false)) {
|
||||||
List<String> commands = new ArrayList<String>();
|
List<String> commands = null;
|
||||||
|
|
||||||
if (node.getProperty(key) instanceof List) {
|
if (section.isList(key)) {
|
||||||
commands = node.getStringList(key, null);
|
commands = section.getList(key);
|
||||||
} else {
|
} else {
|
||||||
commands.add(node.getString(key));
|
commands = new ArrayList<String>();
|
||||||
|
commands.add(section.getString(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
result.put(key, commands.toArray(new String[0]));
|
result.put(key, commands.toArray(new String[0]));
|
||||||
@ -717,8 +715,8 @@ public final class CraftServer implements Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setSpawnRadius(int value) {
|
public void setSpawnRadius(int value) {
|
||||||
configuration.setProperty("settings.spawn-radius", value);
|
configuration.set("settings.spawn-radius", value);
|
||||||
configuration.save();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getOnlineMode() {
|
public boolean getOnlineMode() {
|
||||||
@ -730,14 +728,14 @@ public final class CraftServer implements Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ChunkGenerator getGenerator(String world) {
|
public ChunkGenerator getGenerator(String world) {
|
||||||
ConfigurationNode node = configuration.getNode("worlds");
|
ConfigurationSection section = configuration.getConfigurationSection("worlds");
|
||||||
ChunkGenerator result = null;
|
ChunkGenerator result = null;
|
||||||
|
|
||||||
if (node != null) {
|
if (section != null) {
|
||||||
node = node.getNode(world);
|
section = section.getConfigurationSection(world);
|
||||||
|
|
||||||
if (node != null) {
|
if (section != null) {
|
||||||
String name = node.getString("generator");
|
String name = section.getString("generator");
|
||||||
|
|
||||||
if ((name != null) && (!name.equals(""))) {
|
if ((name != null) && (!name.equals(""))) {
|
||||||
String[] split = name.split(":", 2);
|
String[] split = name.split(":", 2);
|
||||||
|
@ -2,6 +2,8 @@ package org.bukkit.craftbukkit.entity;
|
|||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
import net.minecraft.server.EntityHuman;
|
import net.minecraft.server.EntityHuman;
|
||||||
import net.minecraft.server.EntityPlayer;
|
import net.minecraft.server.EntityPlayer;
|
||||||
import net.minecraft.server.Packet131;
|
import net.minecraft.server.Packet131;
|
||||||
@ -24,6 +26,8 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.Note;
|
import org.bukkit.Note;
|
||||||
import org.bukkit.Statistic;
|
import org.bukkit.Statistic;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
||||||
|
import org.bukkit.craftbukkit.CraftOfflinePlayer;
|
||||||
import org.bukkit.craftbukkit.CraftServer;
|
import org.bukkit.craftbukkit.CraftServer;
|
||||||
import org.bukkit.craftbukkit.CraftWorld;
|
import org.bukkit.craftbukkit.CraftWorld;
|
||||||
import org.bukkit.craftbukkit.map.CraftMapView;
|
import org.bukkit.craftbukkit.map.CraftMapView;
|
||||||
@ -33,6 +37,7 @@ import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
|||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import org.bukkit.map.MapView;
|
import org.bukkit.map.MapView;
|
||||||
|
|
||||||
|
@DelegateDeserialization(CraftOfflinePlayer.class)
|
||||||
public class CraftPlayer extends CraftHumanEntity implements Player {
|
public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||||
public CraftPlayer(CraftServer server, EntityPlayer entity) {
|
public CraftPlayer(CraftServer server, EntityPlayer entity) {
|
||||||
super(server, entity);
|
super(server, entity);
|
||||||
@ -535,4 +540,12 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> serialize() {
|
||||||
|
Map<String, Object> result = new LinkedHashMap<String, Object>();
|
||||||
|
|
||||||
|
result.put("name", getName());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,9 @@ package org.bukkit.craftbukkit.inventory;
|
|||||||
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
||||||
|
|
||||||
|
@DelegateDeserialization(ItemStack.class)
|
||||||
public class CraftItemStack extends ItemStack {
|
public class CraftItemStack extends ItemStack {
|
||||||
protected net.minecraft.server.ItemStack item;
|
protected net.minecraft.server.ItemStack item;
|
||||||
|
|
||||||
|
14
src/main/resources/configurations/bukkit.yml
Normal file
14
src/main/resources/configurations/bukkit.yml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
settings:
|
||||||
|
spawn-radius: 16
|
||||||
|
permissions-file: permissions.yml
|
||||||
|
update-folder: update
|
||||||
|
ping-packet-limit: 100
|
||||||
|
aliases:
|
||||||
|
icanhasbukkit:
|
||||||
|
- version
|
||||||
|
database:
|
||||||
|
username: bukkit
|
||||||
|
isolation: SERIALIZABLE
|
||||||
|
driver: org.sqlite.JDBC
|
||||||
|
password: walrus
|
||||||
|
url: jdbc:sqlite:{DIR}{NAME}.db
|
Loading…
Reference in New Issue
Block a user