From 54625a0bf05970b7378228f6ecfb47c92a565532 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Sat, 11 Jun 2022 09:26:53 +0000 Subject: [PATCH] p2 --- .../pl/minecon724/realweather/ConfigUtils.java | 14 ++++++++++++++ .../pl/minecon724/realweather/GetStateTask.java | 11 ++++++++++- src/main/java/pl/minecon724/realweather/RW.java | 9 ++++++--- src/main/resources/config.yml | 9 ++++++++- 4 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 src/main/java/pl/minecon724/realweather/ConfigUtils.java diff --git a/src/main/java/pl/minecon724/realweather/ConfigUtils.java b/src/main/java/pl/minecon724/realweather/ConfigUtils.java new file mode 100644 index 0000000..571e206 --- /dev/null +++ b/src/main/java/pl/minecon724/realweather/ConfigUtils.java @@ -0,0 +1,14 @@ +package pl.minecon724.realweather; + +public class ConfigUtils { + public static String parsePlaceholders(String key, String value, Object[] data) { + if (key.equals("messages.actionbarInfo")) { + value = value.replaceAll('%weather_full%', data[0]).replaceAll('%weather%', data[1]); + } + return value; + } + + public static String color(String str) { + return ChatColor.translateAlternateColorCodes('&', str); + } +} \ No newline at end of file diff --git a/src/main/java/pl/minecon724/realweather/GetStateTask.java b/src/main/java/pl/minecon724/realweather/GetStateTask.java index 06a69b2..b81d1fe 100644 --- a/src/main/java/pl/minecon724/realweather/GetStateTask.java +++ b/src/main/java/pl/minecon724/realweather/GetStateTask.java @@ -31,6 +31,7 @@ public class GetStateTask extends BukkitRunnable { boolean debug, debugDox; double scaleLat, scaleLon; int onExceed; + boolean actionbar; MapUtils mapUtils = new MapUtils(); @@ -41,7 +42,7 @@ public class GetStateTask extends BukkitRunnable { WebServiceClient client, boolean broadcast, boolean debug, boolean debugDox, double scaleLat, double scaleLon, - int onExceed + int onExceed, boolean actionbar ) { this.provider = provider; this.source = source; @@ -56,8 +57,11 @@ public class GetStateTask extends BukkitRunnable { this.scaleLat = scaleLat; this.scaleLon = scaleLon; this.onExceed = onExceed; + this.actionbar = actionbar; } + // That's a lot of variables + @Override public void run() { if (debug) logger.info("Refreshing weather by " + source); @@ -70,6 +74,11 @@ public class GetStateTask extends BukkitRunnable { world.setThundering(state.simple == ConditionSimple.THUNDER ? true : false); world.setStorm(state.simple == ConditionSimple.CLEAR ? false : true); } + if (actionbar) { + for (Player p : Bukkit.getOnlinePlayers()) { + + } + } } else if (source.equals("player")) { InetAddress playerIp = null; Player curr = null; diff --git a/src/main/java/pl/minecon724/realweather/RW.java b/src/main/java/pl/minecon724/realweather/RW.java index 36b8184..f28b6d3 100644 --- a/src/main/java/pl/minecon724/realweather/RW.java +++ b/src/main/java/pl/minecon724/realweather/RW.java @@ -10,7 +10,7 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; import pl.minecon724.realweather.provider.OpenWeatherMapProvider; -import pl.minecon724.thirdparty.Metrics; +import pl.minecon724.realweather.thirdparty.Metrics; public class RW extends JavaPlugin { FileConfiguration config; @@ -54,7 +54,7 @@ public class RW extends JavaPlugin { provider.init(); if (source.equals("player")) { - this.getLogger().info("Initializing GeoLite2 by MaxMind because we need it for retrieving players locations."); + this.getLogger().info("Initializing GeoLite2 by MaxMind because we need it for retrieving players real world locations."); int accId = player.getInt("geolite2_accountId"); String license = player.getString("geolite2_apiKey"); client = new WebServiceClient.Builder(accId, license).host("geolite.info").build(); @@ -76,7 +76,10 @@ public class RW extends JavaPlugin { settingsSec.getLong("timeBetweenRecheck") ); - new Metrics(this, 15020); + Metrics metrics = new Metrics(this, 15020); + metrics.addCustomChart(new SimplePie("source_type", () -> { + return source; + })); long end = System.currentTimeMillis(); this.getLogger().info( String.format( this.getName() + " enabled! (%s ms)", Long.toString( end-start ) ) ); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 4530867..e04329d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -49,8 +49,15 @@ settings: timeBetweenRecheck: 600 # Whether to broadcast messages about weather updates broadcast: false + # Whether to display an actionbar containing info + actionbar: true # Advanced options timeBeforeInitialRun: 0 debug: false - debugAllowDox: false \ No newline at end of file + debugAllowDox: false + +messages: + # %weather_full% - full state description, such as "extreme thunder" + # %weather% - short state description, such as "rain" + actionbarInfo: "&b%weather_full%" \ No newline at end of file