geforkt von Mirrors/Paper
Updated to the new Configuration api
Dieser Commit ist enthalten in:
Ursprung
255778b388
Commit
c818414fd5
@ -1,9 +1,15 @@
|
||||
package org.bukkit.craftbukkit;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
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 CraftServer server;
|
||||
|
||||
@ -61,4 +67,22 @@ public class CraftOfflinePlayer implements OfflinePlayer {
|
||||
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.WorldSettings;
|
||||
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.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
@ -71,8 +74,6 @@ import org.bukkit.util.permissions.DefaultPermissions;
|
||||
import org.bukkit.event.world.WorldInitEvent;
|
||||
import org.bukkit.permissions.Permission;
|
||||
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.constructor.SafeConstructor;
|
||||
import org.yaml.snakeyaml.error.MarkedYAMLException;
|
||||
@ -88,10 +89,14 @@ public final class CraftServer implements Server {
|
||||
protected final MinecraftServer console;
|
||||
protected final ServerConfigurationManager server;
|
||||
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 Map<String, OfflinePlayer> offlinePlayers = new MapMaker().softValues().makeMap();
|
||||
|
||||
static {
|
||||
ConfigurationSerialization.registerClass(CraftOfflinePlayer.class);
|
||||
}
|
||||
|
||||
public CraftServer(MinecraftServer console, ServerConfigurationManager server) {
|
||||
this.console = console;
|
||||
this.server = server;
|
||||
@ -99,35 +104,27 @@ public final class CraftServer implements Server {
|
||||
|
||||
Bukkit.setServer(this);
|
||||
|
||||
configuration = new Configuration((File) console.options.valueOf("bukkit-settings"));
|
||||
loadConfig();
|
||||
configuration = YamlConfiguration.loadConfiguration(getConfigFile());
|
||||
configuration.options().copyDefaults(true);
|
||||
configuration.setDefaults(YamlConfiguration.loadConfiguration(getClass().getClassLoader().getResourceAsStream("configurations/bukkit.yml")));
|
||||
saveConfig();
|
||||
|
||||
loadPlugins();
|
||||
enablePlugins(PluginLoadOrder.STARTUP);
|
||||
|
||||
ChunkCompressionThread.startThread();
|
||||
}
|
||||
|
||||
private void loadConfig() {
|
||||
configuration.load();
|
||||
configuration.getString("database.url", "jdbc:sqlite:{DIR}{NAME}.db");
|
||||
configuration.getString("database.username", "bukkit");
|
||||
configuration.getString("database.password", "walrus");
|
||||
configuration.getString("database.driver", "org.sqlite.JDBC");
|
||||
configuration.getString("database.isolation", "SERIALIZABLE");
|
||||
|
||||
configuration.getString("settings.update-folder", "update");
|
||||
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);
|
||||
private File getConfigFile() {
|
||||
return (File)console.options.valueOf("bukkit-settings");
|
||||
}
|
||||
|
||||
private void saveConfig() {
|
||||
try {
|
||||
configuration.save(getConfigFile());
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(CraftServer.class.getName()).log(Level.SEVERE, "Could not save " + getConfigFile(), ex);
|
||||
}
|
||||
configuration.save();
|
||||
}
|
||||
|
||||
public void loadPlugins() {
|
||||
@ -365,7 +362,7 @@ public final class CraftServer implements Server {
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
loadConfig();
|
||||
configuration = YamlConfiguration.loadConfiguration(getConfigFile());
|
||||
PropertyManager config = new PropertyManager(console.options);
|
||||
|
||||
console.propertyManager = config;
|
||||
@ -692,17 +689,18 @@ public final class CraftServer implements Server {
|
||||
}
|
||||
|
||||
public Map<String, String[]> getCommandAliases() {
|
||||
ConfigurationNode node = configuration.getNode("aliases");
|
||||
ConfigurationSection section = configuration.getConfigurationSection("aliases");
|
||||
Map<String, String[]> result = new LinkedHashMap<String, String[]>();
|
||||
|
||||
if (node != null) {
|
||||
for (String key : node.getKeys()) {
|
||||
List<String> commands = new ArrayList<String>();
|
||||
if (section != null) {
|
||||
for (String key : section.getKeys(false)) {
|
||||
List<String> commands = null;
|
||||
|
||||
if (node.getProperty(key) instanceof List) {
|
||||
commands = node.getStringList(key, null);
|
||||
if (section.isList(key)) {
|
||||
commands = section.getList(key);
|
||||
} else {
|
||||
commands.add(node.getString(key));
|
||||
commands = new ArrayList<String>();
|
||||
commands.add(section.getString(key));
|
||||
}
|
||||
|
||||
result.put(key, commands.toArray(new String[0]));
|
||||
@ -717,8 +715,8 @@ public final class CraftServer implements Server {
|
||||
}
|
||||
|
||||
public void setSpawnRadius(int value) {
|
||||
configuration.setProperty("settings.spawn-radius", value);
|
||||
configuration.save();
|
||||
configuration.set("settings.spawn-radius", value);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
public boolean getOnlineMode() {
|
||||
@ -730,14 +728,14 @@ public final class CraftServer implements Server {
|
||||
}
|
||||
|
||||
public ChunkGenerator getGenerator(String world) {
|
||||
ConfigurationNode node = configuration.getNode("worlds");
|
||||
ConfigurationSection section = configuration.getConfigurationSection("worlds");
|
||||
ChunkGenerator result = null;
|
||||
|
||||
if (node != null) {
|
||||
node = node.getNode(world);
|
||||
if (section != null) {
|
||||
section = section.getConfigurationSection(world);
|
||||
|
||||
if (node != null) {
|
||||
String name = node.getString("generator");
|
||||
if (section != null) {
|
||||
String name = section.getString("generator");
|
||||
|
||||
if ((name != null) && (!name.equals(""))) {
|
||||
String[] split = name.split(":", 2);
|
||||
|
@ -2,6 +2,8 @@ package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import net.minecraft.server.EntityHuman;
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.Packet131;
|
||||
@ -24,6 +26,8 @@ import org.bukkit.Material;
|
||||
import org.bukkit.Note;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
||||
import org.bukkit.craftbukkit.CraftOfflinePlayer;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
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.map.MapView;
|
||||
|
||||
@DelegateDeserialization(CraftOfflinePlayer.class)
|
||||
public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
public CraftPlayer(CraftServer server, EntityPlayer entity) {
|
||||
super(server, entity);
|
||||
@ -535,4 +540,12 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
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.Material;
|
||||
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
||||
|
||||
@DelegateDeserialization(ItemStack.class)
|
||||
public class CraftItemStack extends ItemStack {
|
||||
protected net.minecraft.server.ItemStack item;
|
||||
|
||||
|
14
src/main/resources/configurations/bukkit.yml
Normale Datei
14
src/main/resources/configurations/bukkit.yml
Normale Datei
@ -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
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren