3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-20 06:50:08 +01:00

Basic Config API for sponge, need to do comments

Dieser Commit ist enthalten in:
Myles 2016-09-26 20:12:34 +01:00
Ursprung 3411c3d144
Commit 8b9a1750de
8 geänderte Dateien mit 173 neuen und 54 gelöschten Zeilen

Datei anzeigen

@ -1,8 +1,7 @@
PORT STUFF TO GUAVA :D (so we dont need to include commons) PORT STUFF TO GUAVA :D (so we dont need to include commons)
Test on SpongeForge, only tested SpongeVanilla
Stop using new Gson() everywhere Stop using new Gson() everywhere
Java docs (for platforms etc) Java docs (for platforms etc)
Config implementation for sponge Add comments to sponge api
Port bukkit listeners to sponge maybe Port bukkit listeners to sponge maybe
Fix task ids, methods for sponge Fix task ids, methods for sponge
Find all the TODO's and check they're done. Find all the TODO's and check they're done.

Datei anzeigen

@ -13,7 +13,7 @@ public class ViaConfig implements ViaVersionConfig, ConfigurationProvider {
public ViaConfig(ViaVersionPlugin plugin) { public ViaConfig(ViaVersionPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
generateConfig(); reloadConfig();
} }
public void generateConfig() { public void generateConfig() {
@ -198,6 +198,11 @@ public class ViaConfig implements ViaVersionConfig, ConfigurationProvider {
plugin.saveConfig(); plugin.saveConfig();
} }
@Override
public void reloadConfig() {
generateConfig();
}
@Override @Override
public Map<String, Object> getValues() { public Map<String, Object> getValues() {
return plugin.getConfig().getValues(false); return plugin.getConfig().getValues(false);

Datei anzeigen

@ -17,7 +17,7 @@ import us.myles.ViaVersion.bungee.BungeeViaAPI;
import us.myles.ViaVersion.bungee.BungeeViaInjector; import us.myles.ViaVersion.bungee.BungeeViaInjector;
import us.myles.ViaVersion.bungee.BungeeViaLoader; import us.myles.ViaVersion.bungee.BungeeViaLoader;
import us.myles.ViaVersion.bungee.command.BungeeCommandSender; import us.myles.ViaVersion.bungee.command.BungeeCommandSender;
import us.myles.ViaVersion.bungee.config.BungeeConfigProvider; import us.myles.ViaVersion.bungee.config.BungeeConfigAPI;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -25,13 +25,13 @@ import java.util.concurrent.TimeUnit;
public class Bungee extends Plugin implements ViaPlatform { public class Bungee extends Plugin implements ViaPlatform {
private BungeeViaAPI api; private BungeeViaAPI api;
private BungeeConfigProvider config; private BungeeConfigAPI config;
private BungeeCommandHandler commandHandler; private BungeeCommandHandler commandHandler;
@Override @Override
public void onLoad() { public void onLoad() {
api = new BungeeViaAPI(); api = new BungeeViaAPI();
config = new BungeeConfigProvider(); config = new BungeeConfigAPI();
commandHandler = new BungeeCommandHandler(); commandHandler = new BungeeCommandHandler();
ProxyServer.getInstance().getPluginManager().registerCommand(this, new BungeeCommand(commandHandler)); ProxyServer.getInstance().getPluginManager().registerCommand(this, new BungeeCommand(commandHandler));
// Init platform // Init platform

Datei anzeigen

@ -8,7 +8,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
// TODO implement // TODO implement
public class BungeeConfigProvider implements ViaVersionConfig, ConfigurationProvider { public class BungeeConfigAPI implements ViaVersionConfig, ConfigurationProvider {
@Override @Override
public boolean isCheckForUpdates() { public boolean isCheckForUpdates() {
return false; return false;
@ -169,6 +169,11 @@ public class BungeeConfigProvider implements ViaVersionConfig, ConfigurationProv
} }
@Override
public void reloadConfig() {
}
@Override @Override
public Map<String, Object> getValues() { public Map<String, Object> getValues() {
return null; return null;

Datei anzeigen

@ -17,6 +17,11 @@ public interface ConfigurationProvider {
*/ */
void saveConfig(); void saveConfig();
/**
* Reloads the config
*/
void reloadConfig();
/** /**
* Get all the configuration values * Get all the configuration values
* *

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.getPlatform().getConfigurationProvider().saveConfig(); Via.getPlatform().getConfigurationProvider().reloadConfig();
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

@ -3,7 +3,11 @@ package us.myles.ViaVersion;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.inject.Inject; import com.google.inject.Inject;
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.loader.ConfigurationLoader;
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
import org.spongepowered.api.Game; import org.spongepowered.api.Game;
import org.spongepowered.api.config.DefaultConfig;
import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent; import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent;
@ -21,6 +25,7 @@ import us.myles.ViaVersion.api.platform.ViaPlatform;
import us.myles.ViaVersion.dump.PluginInfo; import us.myles.ViaVersion.dump.PluginInfo;
import us.myles.ViaVersion.sponge.*; import us.myles.ViaVersion.sponge.*;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -37,13 +42,18 @@ import java.util.logging.Logger;
public class SpongePlugin implements ViaPlatform { public class SpongePlugin implements ViaPlatform {
@Inject @Inject
private Game game; private Game game;
@Inject @Inject
private PluginContainer container; private PluginContainer container;
@Inject
@DefaultConfig(sharedRoot = false)
private File defaultConfig;
private SpongeViaAPI api = new SpongeViaAPI();
private SpongeExecutorService asyncExecutor; private SpongeExecutorService asyncExecutor;
private SpongeExecutorService syncExecutor; private SpongeExecutorService syncExecutor;
private SpongeConfigAPI conf = new SpongeConfigAPI(this); private SpongeConfigAPI conf;
private SpongeViaAPI api = new SpongeViaAPI();
private Logger logger; private Logger logger;
@Listener @Listener
@ -51,6 +61,7 @@ public class SpongePlugin implements ViaPlatform {
// Setup Logger // Setup Logger
logger = new LoggerWrapper(container.getLogger()); logger = new LoggerWrapper(container.getLogger());
// Setup Plugin // Setup Plugin
conf = new SpongeConfigAPI(defaultConfig.getParentFile());
syncExecutor = game.getScheduler().createSyncExecutor(this); syncExecutor = game.getScheduler().createSyncExecutor(this);
asyncExecutor = game.getScheduler().createAsyncExecutor(this); asyncExecutor = game.getScheduler().createAsyncExecutor(this);
SpongeCommandHandler commandHandler = new SpongeCommandHandler(); SpongeCommandHandler commandHandler = new SpongeCommandHandler();

Datei anzeigen

@ -1,64 +1,70 @@
package us.myles.ViaVersion.sponge; package us.myles.ViaVersion.sponge;
import us.myles.ViaVersion.SpongePlugin; import org.yaml.snakeyaml.Yaml;
import us.myles.ViaVersion.api.ViaVersionConfig; import us.myles.ViaVersion.api.ViaVersionConfig;
import us.myles.ViaVersion.api.configuration.ConfigurationProvider; import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
import java.util.Arrays; import java.io.*;
import java.util.HashMap; import java.net.URL;
import java.util.List; import java.util.*;
import java.util.Map;
public class SpongeConfigAPI implements ViaVersionConfig, ConfigurationProvider{ public class SpongeConfigAPI implements ViaVersionConfig, ConfigurationProvider {
private final SpongePlugin spongePlugin; private final File defaultConfig;
private Map<Object, Object> config;
private ThreadLocal<Yaml> yaml = new ThreadLocal<Yaml>() {
@Override
protected Yaml initialValue() {
return new Yaml();
}
};
public SpongeConfigAPI(SpongePlugin spongePlugin) { public SpongeConfigAPI(File defaultConfig) {
this.spongePlugin = spongePlugin; this.defaultConfig = defaultConfig;
reloadConfig();
} }
@Override
public boolean isCheckForUpdates() { public boolean isCheckForUpdates() {
return false; return getBoolean("checkforupdates", true);
} }
@Override @Override
public boolean isPreventCollision() { public boolean isPreventCollision() {
return false; return getBoolean("prevent-collision", true);
} }
@Override @Override
public boolean isNewEffectIndicator() { public boolean isNewEffectIndicator() {
return false; return getBoolean("use-new-effect-indicator", true);
} }
@Override @Override
public boolean isShowNewDeathMessages() { public boolean isShowNewDeathMessages() {
return false; return getBoolean("use-new-deathmessages", false);
} }
@Override @Override
public boolean isSuppressMetadataErrors() { public boolean isSuppressMetadataErrors() {
return false; return getBoolean("suppress-metadata-errors", false);
} }
@Override @Override
public boolean isShieldBlocking() { public boolean isShieldBlocking() {
return false; return getBoolean("shield-blocking", true);
} }
@Override @Override
public boolean isHologramPatch() { public boolean isHologramPatch() {
return false; return getBoolean("hologram-patch", false);
} }
@Override @Override
public boolean isBossbarPatch() { public boolean isBossbarPatch() {
return false; return getBoolean("bossbar-patch", true);
} }
@Override @Override
public boolean isBossbarAntiflicker() { public boolean isBossbarAntiflicker() {
return false; return getBoolean("bossbar-anti-flicker", false);
} }
@Override @Override
@ -68,12 +74,7 @@ public class SpongeConfigAPI implements ViaVersionConfig, ConfigurationProvider{
@Override @Override
public double getHologramYOffset() { public double getHologramYOffset() {
return 0; return getDouble("hologram-y", -0.96D);
}
@Override
public boolean isAutoTeam() {
return false;
} }
@Override @Override
@ -83,101 +84,194 @@ public class SpongeConfigAPI implements ViaVersionConfig, ConfigurationProvider{
@Override @Override
public int getMaxPPS() { public int getMaxPPS() {
return 0; return getInt("max-pps", 140);
} }
@Override @Override
public String getMaxPPSKickMessage() { public String getMaxPPSKickMessage() {
return null; return getString("max-pps-kick-msg", "Sending packets too fast? lag?");
} }
@Override @Override
public int getTrackingPeriod() { public int getTrackingPeriod() {
return 0; return getInt("tracking-period", 6);
} }
@Override @Override
public int getWarningPPS() { public int getWarningPPS() {
return 0; return getInt("tracking-warning-pps", 120);
} }
@Override @Override
public int getMaxWarnings() { public int getMaxWarnings() {
return 0; return getInt("tracking-max-warnings", 3);
} }
@Override @Override
public String getMaxWarningsKickMessage() { public String getMaxWarningsKickMessage() {
return null; return getString("tracking-max-kick-msg", "You are sending too many packets, :(");
} }
@Override @Override
public boolean isAntiXRay() { public boolean isAntiXRay() {
return false; return getBoolean("anti-xray-patch", true);
} }
@Override @Override
public boolean isSendSupportedVersions() { public boolean isSendSupportedVersions() {
return false; return getBoolean("send-supported-versions", false);
} }
@Override @Override
public boolean isStimulatePlayerTick() { public boolean isStimulatePlayerTick() {
return false; return getBoolean("simulate-pt", true);
} }
@Override @Override
public boolean isItemCache() { public boolean isItemCache() {
return false; return getBoolean("item-cache", true);
} }
@Override @Override
public boolean isNMSPlayerTicking() { public boolean isNMSPlayerTicking() {
return false; return getBoolean("nms-player-ticking", true);
} }
@Override @Override
public boolean isReplacePistons() { public boolean isReplacePistons() {
return false; return getBoolean("replace-pistons", false);
} }
@Override @Override
public int getPistonReplacementId() { public int getPistonReplacementId() {
return 0; return getInt("replacement-piston-id", 0);
}
public boolean isAutoTeam() {
// Collision has to be enabled first
return isPreventCollision() && getBoolean("auto-team", true);
} }
@Override @Override
public boolean isForceJsonTransform() { public boolean isForceJsonTransform() {
return false; return getBoolean("force-json-transform", false);
} }
@Override @Override
public List<Integer> getBlockedProtocols() { public List<Integer> getBlockedProtocols() {
return Arrays.asList(0); return getIntegerList("block-protocols");
} }
@Override @Override
public String getBlockedDisconnectMsg() { public String getBlockedDisconnectMsg() {
return "Boop"; return getString("block-disconnect-msg", "You are using an unsupported Minecraft version!");
} }
@Override @Override
public String getReloadDisconnectMsg() { public String getReloadDisconnectMsg() {
return "Beep"; return getString("reload-disconnect-msg", "Server reload, please rejoin!");
} }
@Override @Override
public void set(String path, Object value) { public void set(String path, Object value) {
config.put(path, value);
} }
@Override @Override
public void saveConfig() { public void saveConfig() {
if (!defaultConfig.isDirectory()) {
defaultConfig.mkdir();
}
File config = new File(defaultConfig, "config.yml");
try (FileWriter fw = new FileWriter(config)) {
yaml.get().dump(this.config, fw);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void reloadConfig() {
if (!defaultConfig.isDirectory()) {
defaultConfig.mkdir();
}
File config = new File(defaultConfig, "config.yml");
URL jarConfigFile = this.getClass().getClassLoader().getResource("config.yml");
this.config = null;
if (config.exists()) {
try (FileInputStream input = new FileInputStream(config)) {
this.config = (Map<Object, Object>) yaml.get().load(input);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
if (this.config == null) {
this.config = new HashMap<>();
}
Map<Object, Object> defaults;
try (InputStream stream = jarConfigFile.openStream()) {
defaults = (Map<Object, Object>) yaml.get().load(stream);
} catch (IOException e) {
e.printStackTrace();
return;
}
// Merge with defaultLoader
for (Object key : this.config.keySet()) {
// Set option in new conf if exists
if (defaults.containsKey(key)) {
defaults.put(key, this.config.get(key));
}
}
this.config = defaults;
// Save
saveConfig();
}
public boolean getBoolean(String key, boolean def) {
if (this.config.containsKey(key)) {
return (boolean) this.config.get(key);
} else {
return def;
}
}
public String getString(String key, String def) {
if (this.config.containsKey(key)) {
return (String) this.config.get(key);
} else {
return def;
}
}
public int getInt(String key, int def) {
if (this.config.containsKey(key)) {
return (int) this.config.get(key);
} else {
return def;
}
}
public double getDouble(String key, double def) {
if (this.config.containsKey(key)) {
return (double) this.config.get(key);
} else {
return def;
}
}
public List<Integer> getIntegerList(String key) {
if (this.config.containsKey(key)) {
return (List<Integer>) this.config.get(key);
} else {
return new ArrayList<>();
}
} }
@Override @Override
public Map<String, Object> getValues() { public Map<String, Object> getValues() {
return new HashMap<>(); return (Map<String, Object>) ((Map) this.config);
} }
} }