From d7f54048ff6bf03f88912ce8a990afade2900282 Mon Sep 17 00:00:00 2001 From: fillefilip8 Date: Sun, 6 Mar 2016 10:39:58 +0100 Subject: [PATCH] Made the config use the default bukkit config methods insteed. --- .../us/myles/ViaVersion/ViaVersionPlugin.java | 61 +++++++++---------- src/main/resources/config.yml | 2 + 2 files changed, 31 insertions(+), 32 deletions(-) create mode 100644 src/main/resources/config.yml diff --git a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java index 52933b5c4..ea5dcfe3e 100644 --- a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java +++ b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java @@ -28,9 +28,7 @@ import us.myles.ViaVersion.util.ReflectionUtil; import java.io.File; import java.io.IOException; import java.lang.reflect.Field; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; @@ -39,12 +37,11 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI { private final Map portedPlayers = new ConcurrentHashMap(); private boolean debug = false; - private FileConfiguration config; - private File configFile; @Override public void onEnable() { ViaVersion.setInstance(this); + saveDefaultConfig(); if (System.getProperty("ViaVersion") != null) { getLogger().severe("ViaVersion is already loaded, we don't support reloads. Please reboot if you wish to update."); getLogger().severe("Some features may not work."); @@ -59,18 +56,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI { getLogger().severe("Unable to inject handlers, are you on 1.8? "); e.printStackTrace(); } - - this.config = getFileConfiguration(); - if (!config.contains("checkforupdates")) { - config.set("checkforupdates", true); - try { - config.save(configFile); - } catch (IOException e1) { - this.getLogger().info("Unabled to write config.yml!"); - e1.printStackTrace(); - } - } - if (config.getBoolean("checkforupdates")) { + if (getConfig().getBoolean("checkforupdates")) { Bukkit.getPluginManager().registerEvents(new UpdateListener(this), this); UpdateUtil.sendUpdateMessage(this); } @@ -139,6 +125,31 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI { return this.debug; } + @Override + public Map getPortedPlayers() { + return Collections.unmodifiableMap(portedPlayers); + } + + @Override + public List getNonPortedPlayers() { + List nonPortedPlayers = new ArrayList(); + for(Player p : Bukkit.getOnlinePlayers()){ + if(!isPorted(p)){ + nonPortedPlayers.add(p.getUniqueId()); + } + } + return Collections.unmodifiableList(nonPortedPlayers); + } + + @Override + public List getPortedPlayersList() { + List players = new ArrayList(); + for(UUID uuid : portedPlayers.keySet()){ + players.add(uuid); + } + return Collections.unmodifiableList(players); + } + public void setDebug(boolean value) { this.debug = value; } @@ -151,20 +162,6 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI { portedPlayers.remove(clientID); } - private FileConfiguration getFileConfiguration() { - if (!this.getDataFolder().exists()) - this.getDataFolder().mkdirs(); - this.configFile = new File(this.getDataFolder(), "config.yml"); - if (!this.configFile.exists()) - try { - this.configFile.createNewFile(); - } catch (IOException e) { - this.getLogger().info("Unable to create config.yml!"); - e.printStackTrace(); - } - return YamlConfiguration.loadConfiguration(this.configFile); - } - public static ItemStack getHandItem(final ConnectionInfo info) { try { return Bukkit.getScheduler().callSyncMethod(Bukkit.getPluginManager().getPlugin("ViaVersion"), new Callable() { @@ -182,4 +179,4 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI { return null; } } -} \ No newline at end of file +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 000000000..5f02e58e1 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,2 @@ +#Should ViaVersion check for updates? +checkforupdates: true \ No newline at end of file