Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-26 00:00:28 +01:00
Basic configuration api and add platform specific dump info
Dieser Commit ist enthalten in:
Ursprung
30d477c6d2
Commit
79d353d458
@ -1,12 +1,14 @@
|
||||
package us.myles.ViaVersion;
|
||||
|
||||
import us.myles.ViaVersion.api.ViaVersionConfig;
|
||||
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
||||
import us.myles.ViaVersion.util.Configuration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ViaConfig implements ViaVersionConfig {
|
||||
public class ViaConfig implements ViaVersionConfig, ConfigurationProvider {
|
||||
private final ViaVersionPlugin plugin;
|
||||
|
||||
public ViaConfig(ViaVersionPlugin plugin) {
|
||||
@ -185,4 +187,19 @@ public class ViaConfig implements ViaVersionConfig {
|
||||
public String getReloadDisconnectMsg() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,18 @@
|
||||
package us.myles.ViaVersion;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.ViaAPI;
|
||||
import us.myles.ViaVersion.api.ViaVersion;
|
||||
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.platform.ViaPlatform;
|
||||
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.BukkitViaInjector;
|
||||
import us.myles.ViaVersion.classgenerator.ClassGenerator;
|
||||
import us.myles.ViaVersion.dump.PluginInfo;
|
||||
import us.myles.ViaVersion.util.ReflectionUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
@ -89,7 +96,6 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
|
||||
Via.getManager().init();
|
||||
}
|
||||
|
||||
|
||||
getCommand("viaversion").setExecutor(commandHandler = new BukkitCommandHandler());
|
||||
getCommand("viaversion").setTabCompleter(commandHandler);
|
||||
|
||||
@ -177,13 +183,23 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAsync(Runnable runnable) {
|
||||
getServer().getScheduler().runTaskAsynchronously(this, runnable);
|
||||
public int runAsync(Runnable runnable) {
|
||||
return getServer().getScheduler().runTaskAsynchronously(this, runnable).getTaskId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runSync(Runnable runnable) {
|
||||
getServer().getScheduler().runTask(this, runnable);
|
||||
public int runSync(Runnable 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
|
||||
@ -220,6 +236,11 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
|
||||
return Bukkit.getPluginManager().getPlugin("ViaVersion").isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationProvider getConfigurationProvider() {
|
||||
return conf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReload() {
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
@ -217,9 +217,4 @@ public interface ViaVersionConfig {
|
||||
* @return Disconnect message
|
||||
*/
|
||||
String getReloadDisconnectMsg();
|
||||
|
||||
/**
|
||||
* Reloads the config from disk
|
||||
*/
|
||||
void reloadConfig();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
@ -1,8 +1,11 @@
|
||||
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.ViaVersionConfig;
|
||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
||||
|
||||
import java.util.UUID;
|
||||
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
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
package us.myles.ViaVersion.commands.defaultsubs;
|
||||
|
||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||
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.ViaSubCommand;
|
||||
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
||||
|
||||
public class AutoTeamSubCmd extends ViaSubCommand {
|
||||
@Override
|
||||
@ -19,11 +18,11 @@ public class AutoTeamSubCmd extends ViaSubCommand {
|
||||
|
||||
@Override
|
||||
public boolean execute(ViaCommandSender sender, String[] args) {
|
||||
ViaVersionPlugin plugin = (ViaVersionPlugin) ViaVersion.getInstance();
|
||||
|
||||
ConfigurationProvider provider = Via.getPlatform().getConfigurationProvider();
|
||||
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, "&6All players will need to re-login for the change to take place.");
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
package us.myles.ViaVersion.commands.defaultsubs;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||
import us.myles.ViaVersion.api.ViaVersion;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||
import us.myles.ViaVersion.api.command.ViaSubCommand;
|
||||
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
||||
|
||||
public class DontBugMeSubCmd extends ViaSubCommand {
|
||||
@Override
|
||||
@ -19,11 +18,11 @@ public class DontBugMeSubCmd extends ViaSubCommand {
|
||||
|
||||
@Override
|
||||
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();
|
||||
plugin.getConfig().set("checkforupdates", newValue);
|
||||
plugin.saveConfig();
|
||||
provider.set("checkforupdates", newValue);
|
||||
provider.saveConfig();
|
||||
sendMessage(sender, "&6We will %snotify you about updates.", (newValue ? "&a" : "&cnot "));
|
||||
|
||||
return true;
|
||||
|
@ -3,6 +3,8 @@ package us.myles.ViaVersion.commands.defaultsubs;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
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.ViaSubCommand;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||
@ -37,22 +39,19 @@ public class DumpSubCmd extends ViaSubCommand {
|
||||
@Override
|
||||
public boolean execute(final ViaCommandSender sender, String[] args) {
|
||||
VersionInfo version = new VersionInfo(
|
||||
Bukkit.getServer().getVersion(),
|
||||
Bukkit.getServer().getBukkitVersion(),
|
||||
System.getProperty("java.version"),
|
||||
System.getProperty("os.name"),
|
||||
ProtocolRegistry.SERVER_PROTOCOL,
|
||||
ProtocolRegistry.getSupportedVersions());
|
||||
ProtocolRegistry.getSupportedVersions(),
|
||||
Via.getPlatform().getPlatformName(),
|
||||
Via.getPlatform().getPluginVersion()
|
||||
);
|
||||
|
||||
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()));
|
||||
Map<String, Object> configuration = Via.getPlatform().getConfigurationProvider().getValues();
|
||||
|
||||
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);
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously((ViaVersionPlugin) ViaVersion.getInstance(), new Runnable() {
|
||||
Via.getPlatform().runAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
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()));
|
||||
} catch (Exception e) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -17,7 +17,7 @@ public class ReloadSubCmd extends ViaSubCommand {
|
||||
|
||||
@Override
|
||||
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.");
|
||||
return true;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package us.myles.ViaVersion.dump;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@ -11,5 +12,5 @@ import java.util.Map;
|
||||
public class DumpTemplate {
|
||||
private VersionInfo versionInfo;
|
||||
private Map<String, Object> configuration;
|
||||
private List<PluginInfo> plugins;
|
||||
private JsonObject platformDump;
|
||||
}
|
||||
|
@ -8,11 +8,11 @@ import java.util.Set;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class VersionInfo {
|
||||
private String version;
|
||||
private String bukkitVersion;
|
||||
private String javaVersion;
|
||||
private String operatingSystem;
|
||||
private int serverProtocol;
|
||||
private Set<Integer> enabledPipelines;
|
||||
private String platformName;
|
||||
private String platformVersion;
|
||||
}
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren