3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 00:22:51 +01:00

Basic configuration api and add platform specific dump info

Dieser Commit ist enthalten in:
Matsv 2016-09-25 20:41:34 +02:00
Ursprung 30d477c6d2
Commit 79d353d458
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 97CEC2A2EA31350F
11 geänderte Dateien mit 132 neuen und 52 gelöschten Zeilen

Datei anzeigen

@ -1,12 +1,14 @@
package us.myles.ViaVersion; package us.myles.ViaVersion;
import us.myles.ViaVersion.api.ViaVersionConfig; import us.myles.ViaVersion.api.ViaVersionConfig;
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
import us.myles.ViaVersion.util.Configuration; import us.myles.ViaVersion.util.Configuration;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import java.util.Map;
public class ViaConfig implements ViaVersionConfig { public class ViaConfig implements ViaVersionConfig, ConfigurationProvider {
private final ViaVersionPlugin plugin; private final ViaVersionPlugin plugin;
public ViaConfig(ViaVersionPlugin plugin) { public ViaConfig(ViaVersionPlugin plugin) {
@ -185,4 +187,19 @@ public class ViaConfig implements ViaVersionConfig {
public String getReloadDisconnectMsg() { public String getReloadDisconnectMsg() {
return plugin.getConfig().getString("reload-disconnect-msg", "Server reload, please rejoin!"); return plugin.getConfig().getString("reload-disconnect-msg", "Server reload, please rejoin!");
} }
@Override
public void set(String path, Object value) {
plugin.getConfig().set(path, value);
}
@Override
public void saveConfig() {
plugin.saveConfig();
}
@Override
public Map<String, Object> getValues() {
return plugin.getConfig().getValues(false);
}
} }

Datei anzeigen

@ -1,14 +1,18 @@
package us.myles.ViaVersion; package us.myles.ViaVersion;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.ViaAPI; import us.myles.ViaVersion.api.ViaAPI;
import us.myles.ViaVersion.api.ViaVersion; import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.platform.ViaPlatform; import us.myles.ViaVersion.api.platform.ViaPlatform;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry; import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
@ -17,8 +21,11 @@ import us.myles.ViaVersion.bukkit.BukkitCommandSender;
import us.myles.ViaVersion.bukkit.BukkitViaAPI; import us.myles.ViaVersion.bukkit.BukkitViaAPI;
import us.myles.ViaVersion.bukkit.BukkitViaInjector; import us.myles.ViaVersion.bukkit.BukkitViaInjector;
import us.myles.ViaVersion.classgenerator.ClassGenerator; import us.myles.ViaVersion.classgenerator.ClassGenerator;
import us.myles.ViaVersion.dump.PluginInfo;
import us.myles.ViaVersion.util.ReflectionUtil; import us.myles.ViaVersion.util.ReflectionUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.Future; import java.util.concurrent.Future;
@ -89,7 +96,6 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
Via.getManager().init(); Via.getManager().init();
} }
getCommand("viaversion").setExecutor(commandHandler = new BukkitCommandHandler()); getCommand("viaversion").setExecutor(commandHandler = new BukkitCommandHandler());
getCommand("viaversion").setTabCompleter(commandHandler); getCommand("viaversion").setTabCompleter(commandHandler);
@ -177,13 +183,23 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
} }
@Override @Override
public void runAsync(Runnable runnable) { public int runAsync(Runnable runnable) {
getServer().getScheduler().runTaskAsynchronously(this, runnable); return getServer().getScheduler().runTaskAsynchronously(this, runnable).getTaskId();
} }
@Override @Override
public void runSync(Runnable runnable) { public int runSync(Runnable runnable) {
getServer().getScheduler().runTask(this, runnable); return getServer().getScheduler().runTask(this, runnable).getTaskId();
}
@Override
public int runRepeatingSync(Runnable runnable, Long ticks) {
return getServer().getScheduler().runTaskTimer(this, runnable, ticks, 0).getTaskId(); // TODO or the other way around?
}
@Override
public void cancelTask(int taskId) {
getServer().getScheduler().cancelTask(taskId);
} }
@Override @Override
@ -220,6 +236,11 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
return Bukkit.getPluginManager().getPlugin("ViaVersion").isEnabled(); return Bukkit.getPluginManager().getPlugin("ViaVersion").isEnabled();
} }
@Override
public ConfigurationProvider getConfigurationProvider() {
return conf;
}
@Override @Override
public void onReload() { public void onReload() {
if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null) { if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null) {
@ -232,4 +253,18 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
getLogger().severe("ViaVersion is already loaded, this should work fine. If you get any console errors, try rebooting."); getLogger().severe("ViaVersion is already loaded, this should work fine. If you get any console errors, try rebooting.");
} }
} }
@Override
public JsonObject getDump() {
JsonObject platformSpecific = new JsonObject();
List<PluginInfo> plugins = new ArrayList<>();
for (Plugin p : Bukkit.getPluginManager().getPlugins())
plugins.add(new PluginInfo(p.isEnabled(), p.getDescription().getName(), p.getDescription().getVersion(), p.getDescription().getMain(), p.getDescription().getAuthors()));
platformSpecific.add("plugins", new Gson().toJsonTree(plugins));
// TODO more? ProtocolLib things etc?
return platformSpecific;
}
} }

Datei anzeigen

@ -217,9 +217,4 @@ public interface ViaVersionConfig {
* @return Disconnect message * @return Disconnect message
*/ */
String getReloadDisconnectMsg(); String getReloadDisconnectMsg();
/**
* Reloads the config from disk
*/
void reloadConfig();
} }

Datei anzeigen

@ -0,0 +1,26 @@
package us.myles.ViaVersion.api.configuration;
import java.util.Map;
public interface ConfigurationProvider {
/**
* Sets the specified path to the given value.
*
* @param path Path of the object to set.
* @param value New value to set the path to
*/
void set(String path, Object value);
/**
* Saves the config
*/
void saveConfig();
/**
* Get all the configuration values
*
* @return Map with key->values
*/
Map<String,Object> getValues();
}

Datei anzeigen

@ -1,8 +1,11 @@
package us.myles.ViaVersion.api.platform; package us.myles.ViaVersion.api.platform;
import com.google.gson.JsonObject;
import jdk.nashorn.internal.runtime.regexp.joni.Config;
import us.myles.ViaVersion.api.ViaAPI; import us.myles.ViaVersion.api.ViaAPI;
import us.myles.ViaVersion.api.ViaVersionConfig; import us.myles.ViaVersion.api.ViaVersionConfig;
import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -13,29 +16,35 @@ import java.util.logging.Logger;
* @param <T> - The player type for the platform, used for API related methods * @param <T> - The player type for the platform, used for API related methods
*/ */
public interface ViaPlatform<T> { public interface ViaPlatform<T> {
public Logger getLogger(); Logger getLogger();
public String getPlatformName(); String getPlatformName();
public String getPluginVersion(); String getPluginVersion();
public void runAsync(Runnable runnable); int runAsync(Runnable runnable);
public void runSync(Runnable runnable); int runSync(Runnable runnable);
public void runRepeatingSync(Runnable runnable, Long ticks); int runRepeatingSync(Runnable runnable, Long ticks);
public ViaCommandSender[] getOnlinePlayers(); void cancelTask(int taskId);
public void sendMessage(UUID uuid, String message); ViaCommandSender[] getOnlinePlayers();
public boolean kickPlayer(UUID uuid, String message); void sendMessage(UUID uuid, String message);
public boolean isPluginEnabled(); boolean kickPlayer(UUID uuid, String message);
public ViaAPI<T> getApi(); boolean isPluginEnabled();
public ViaVersionConfig getConf(); ViaAPI<T> getApi();
public void onReload(); ViaVersionConfig getConf();
ConfigurationProvider getConfigurationProvider();
void onReload();
JsonObject getDump();
} }

Datei anzeigen

@ -1,10 +1,9 @@
package us.myles.ViaVersion.commands.defaultsubs; package us.myles.ViaVersion.commands.defaultsubs;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.ViaVersion.api.command.ViaSubCommand; import us.myles.ViaVersion.api.command.ViaSubCommand;
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
public class AutoTeamSubCmd extends ViaSubCommand { public class AutoTeamSubCmd extends ViaSubCommand {
@Override @Override
@ -19,11 +18,11 @@ public class AutoTeamSubCmd extends ViaSubCommand {
@Override @Override
public boolean execute(ViaCommandSender sender, String[] args) { public boolean execute(ViaCommandSender sender, String[] args) {
ViaVersionPlugin plugin = (ViaVersionPlugin) ViaVersion.getInstance(); ConfigurationProvider provider = Via.getPlatform().getConfigurationProvider();
boolean newValue = !Via.getConfig().isAutoTeam(); boolean newValue = !Via.getConfig().isAutoTeam();
plugin.getConfig().set("auto-team", newValue);
plugin.saveConfig(); provider.set("auto-team", newValue);
provider.saveConfig();
sendMessage(sender, "&6We will %s", (newValue ? "&aautomatically team players" : "&cno longer auto team players")); sendMessage(sender, "&6We will %s", (newValue ? "&aautomatically team players" : "&cno longer auto team players"));
sendMessage(sender, "&6All players will need to re-login for the change to take place."); sendMessage(sender, "&6All players will need to re-login for the change to take place.");

Datei anzeigen

@ -1,10 +1,9 @@
package us.myles.ViaVersion.commands.defaultsubs; package us.myles.ViaVersion.commands.defaultsubs;
import org.bukkit.command.CommandSender; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.ViaVersion.api.command.ViaSubCommand; import us.myles.ViaVersion.api.command.ViaSubCommand;
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
public class DontBugMeSubCmd extends ViaSubCommand { public class DontBugMeSubCmd extends ViaSubCommand {
@Override @Override
@ -19,11 +18,11 @@ public class DontBugMeSubCmd extends ViaSubCommand {
@Override @Override
public boolean execute(ViaCommandSender sender, String[] args) { public boolean execute(ViaCommandSender sender, String[] args) {
ViaVersionPlugin plugin = (ViaVersionPlugin) ViaVersion.getInstance(); ConfigurationProvider provider = Via.getPlatform().getConfigurationProvider();
boolean newValue = !Via.getConfig().isCheckForUpdates();
boolean newValue = !ViaVersion.getConfig().isCheckForUpdates(); provider.set("checkforupdates", newValue);
plugin.getConfig().set("checkforupdates", newValue); provider.saveConfig();
plugin.saveConfig();
sendMessage(sender, "&6We will %snotify you about updates.", (newValue ? "&a" : "&cnot ")); sendMessage(sender, "&6We will %snotify you about updates.", (newValue ? "&a" : "&cnot "));
return true; return true;

Datei anzeigen

@ -3,6 +3,8 @@ package us.myles.ViaVersion.commands.defaultsubs;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.md_5.bungee.api.ChatColor;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.ViaVersion.api.command.ViaSubCommand; import us.myles.ViaVersion.api.command.ViaSubCommand;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry; import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
@ -37,22 +39,19 @@ public class DumpSubCmd extends ViaSubCommand {
@Override @Override
public boolean execute(final ViaCommandSender sender, String[] args) { public boolean execute(final ViaCommandSender sender, String[] args) {
VersionInfo version = new VersionInfo( VersionInfo version = new VersionInfo(
Bukkit.getServer().getVersion(),
Bukkit.getServer().getBukkitVersion(),
System.getProperty("java.version"), System.getProperty("java.version"),
System.getProperty("os.name"), System.getProperty("os.name"),
ProtocolRegistry.SERVER_PROTOCOL, ProtocolRegistry.SERVER_PROTOCOL,
ProtocolRegistry.getSupportedVersions()); ProtocolRegistry.getSupportedVersions(),
Via.getPlatform().getPlatformName(),
Via.getPlatform().getPluginVersion()
);
List<PluginInfo> plugins = new ArrayList<>(); Map<String, Object> configuration = Via.getPlatform().getConfigurationProvider().getValues();
for (Plugin p : Bukkit.getPluginManager().getPlugins())
plugins.add(new PluginInfo(p.isEnabled(), p.getDescription().getName(), p.getDescription().getVersion(), p.getDescription().getMain(), p.getDescription().getAuthors()));
Map<String, Object> configuration = ((ViaVersionPlugin) ViaVersion.getInstance()).getConfig().getValues(false); final DumpTemplate template = new DumpTemplate(version, configuration, Via.getPlatform().getDump());
final DumpTemplate template = new DumpTemplate(version, configuration, plugins); Via.getPlatform().runAsync(new Runnable() {
Bukkit.getScheduler().runTaskAsynchronously((ViaVersionPlugin) ViaVersion.getInstance(), new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
@ -75,7 +74,7 @@ public class DumpSubCmd extends ViaSubCommand {
sender.sendMessage(ChatColor.GREEN + "We've made a dump with useful information, report your issue and provide this url: " + getUrl(output.get("key").getAsString())); sender.sendMessage(ChatColor.GREEN + "We've made a dump with useful information, report your issue and provide this url: " + getUrl(output.get("key").getAsString()));
} catch (Exception e) { } catch (Exception e) {
sender.sendMessage(ChatColor.RED + "Failed to dump, please check the console for more information"); sender.sendMessage(ChatColor.RED + "Failed to dump, please check the console for more information");
((ViaVersionPlugin) ViaVersion.getInstance()).getLogger().log(Level.WARNING, "Could not paste ViaVersion dump to Hastebin", e); Via.getPlatform().getLogger().log(Level.WARNING, "Could not paste ViaVersion dump to Hastebin", e);
} }
} }
}); });

Datei anzeigen

@ -17,7 +17,7 @@ public class ReloadSubCmd extends ViaSubCommand {
@Override @Override
public boolean execute(ViaCommandSender sender, String[] args) { public boolean execute(ViaCommandSender sender, String[] args) {
Via.getConfig().reloadConfig(); Via.getPlatform().getConfigurationProvider().saveConfig();
sendMessage(sender, "&6Configuration successfully reloaded! Some features may need a restart."); sendMessage(sender, "&6Configuration successfully reloaded! Some features may need a restart.");
return true; return true;
} }

Datei anzeigen

@ -1,5 +1,6 @@
package us.myles.ViaVersion.dump; package us.myles.ViaVersion.dump;
import com.google.gson.JsonObject;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@ -11,5 +12,5 @@ import java.util.Map;
public class DumpTemplate { public class DumpTemplate {
private VersionInfo versionInfo; private VersionInfo versionInfo;
private Map<String, Object> configuration; private Map<String, Object> configuration;
private List<PluginInfo> plugins; private JsonObject platformDump;
} }

Datei anzeigen

@ -8,11 +8,11 @@ import java.util.Set;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
public class VersionInfo { public class VersionInfo {
private String version;
private String bukkitVersion;
private String javaVersion; private String javaVersion;
private String operatingSystem; private String operatingSystem;
private int serverProtocol; private int serverProtocol;
private Set<Integer> enabledPipelines; private Set<Integer> enabledPipelines;
private String platformName;
private String platformVersion;
} }