From 497b37aa3b493548a37b6bdb89c8a53800aabdef Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Wed, 15 Aug 2018 10:17:16 +0300 Subject: [PATCH 01/21] Removed DataContainerCache due to its memory impact vs cpu gain being too high --- .../plan/system/cache/CacheSystem.java | 16 ----- .../plan/system/cache/DataContainerCache.java | 67 ------------------- .../request/GenerateAnalysisPageRequest.java | 4 +- .../response/pages/RawPlayerDataResponse.java | 4 +- .../response/pages/RawServerDataResponse.java | 4 +- .../plan/utilities/html/pages/DebugPage.java | 35 ---------- .../utilities/html/pages/InspectPage.java | 3 +- 7 files changed, 7 insertions(+), 126 deletions(-) delete mode 100644 Plan/src/main/java/com/djrapitops/plan/system/cache/DataContainerCache.java diff --git a/Plan/src/main/java/com/djrapitops/plan/system/cache/CacheSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/cache/CacheSystem.java index 7c8467631..7e1e160cd 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/cache/CacheSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/cache/CacheSystem.java @@ -7,9 +7,6 @@ package com.djrapitops.plan.system.cache; import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.system.PlanSystem; import com.djrapitops.plan.system.SubSystem; -import com.djrapitops.plugin.api.TimeAmount; -import com.djrapitops.plugin.task.AbsRunnable; -import com.djrapitops.plugin.task.RunnableFactory; import com.djrapitops.plugin.utilities.Verify; /** @@ -21,7 +18,6 @@ public class CacheSystem implements SubSystem { private final DataCache dataCache; private final GeolocationCache geolocationCache; - private final DataContainerCache dataContainerCache; public CacheSystem(PlanSystem system) { this(new DataCache(system), system); @@ -30,7 +26,6 @@ public class CacheSystem implements SubSystem { protected CacheSystem(DataCache dataCache, PlanSystem system) { this.dataCache = dataCache; geolocationCache = new GeolocationCache(() -> system.getLocaleSystem().getLocale()); - dataContainerCache = new DataContainerCache(); } public static CacheSystem getInstance() { @@ -43,19 +38,11 @@ public class CacheSystem implements SubSystem { public void enable() throws EnableException { dataCache.enable(); geolocationCache.enable(); - - RunnableFactory.createNew("DataContainer cache clean task", new AbsRunnable() { - @Override - public void run() { - dataContainerCache.clear(); - } - }).runTaskTimerAsynchronously(TimeAmount.MINUTE.ticks(), TimeAmount.MINUTE.ms()); } @Override public void disable() { geolocationCache.clearCache(); - dataContainerCache.clear(); } public DataCache getDataCache() { @@ -66,7 +53,4 @@ public class CacheSystem implements SubSystem { return geolocationCache; } - public DataContainerCache getDataContainerCache() { - return dataContainerCache; - } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/cache/DataContainerCache.java b/Plan/src/main/java/com/djrapitops/plan/system/cache/DataContainerCache.java deleted file mode 100644 index 07170130a..000000000 --- a/Plan/src/main/java/com/djrapitops/plan/system/cache/DataContainerCache.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.djrapitops.plan.system.cache; - -import com.djrapitops.plan.data.store.Key; -import com.djrapitops.plan.data.store.containers.AnalysisContainer; -import com.djrapitops.plan.data.store.containers.DataContainer; -import com.djrapitops.plan.data.store.containers.PlayerContainer; -import com.djrapitops.plan.system.database.databases.Database; -import com.djrapitops.plugin.api.TimeAmount; - -import java.util.UUID; -import java.util.function.Supplier; - -/** - * Cache to aid Bungee in case SQL is causing cpu thread starvation, leading to mysql connection drops. - * - * @author Rsl1122 - */ -public class DataContainerCache extends DataContainer { - - public DataContainerCache() { - super(TimeAmount.SECOND.ms() * 10L); - } - - public PlayerContainer getPlayerContainer(UUID uuid) { - return getAndCacheSupplier(Keys.playerContainer(uuid), Suppliers.playerContainer(uuid)); - } - - public AnalysisContainer getAnalysisContainer(UUID serverUUID) { - return getAndCacheSupplier(Keys.analysisContainer(serverUUID), Suppliers.analysisContainer(serverUUID)); - } - - private T getAndCacheSupplier(Key key, Supplier ifNotPresent) { - if (!supports(key)) { - putSupplier(key, ifNotPresent); - } - return getUnsafe(key); - } - - private static class Keys { - static Key analysisContainer(UUID serverUUID) { - return new Key<>(AnalysisContainer.class, "ANALYSIS_CONTAINER:" + serverUUID); - } - - static Key playerContainer(UUID uuid) { - return new Key<>(PlayerContainer.class, "PLAYER_CONTAINER:" + uuid); - } - - private Keys() { - // Static utility class - } - } - - private static class Suppliers { - static Supplier analysisContainer(UUID serverUUID) { - return () -> new AnalysisContainer(Database.getActive().fetch().getServerContainer(serverUUID)); - } - - static Supplier playerContainer(UUID uuid) { - return () -> Database.getActive().fetch().getPlayerContainer(uuid); - } - - private Suppliers() { - // Static utility class - } - } - -} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/request/GenerateAnalysisPageRequest.java b/Plan/src/main/java/com/djrapitops/plan/system/info/request/GenerateAnalysisPageRequest.java index e421b5797..e5e47dae1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/request/GenerateAnalysisPageRequest.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/request/GenerateAnalysisPageRequest.java @@ -9,7 +9,7 @@ import com.djrapitops.plan.api.exceptions.connection.InternalErrorException; import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.data.store.containers.AnalysisContainer; -import com.djrapitops.plan.system.cache.CacheSystem; +import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.info.InfoSystem; import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.webserver.response.DefaultResponses; @@ -79,7 +79,7 @@ public class GenerateAnalysisPageRequest extends InfoRequestWithVariables implem try { runningAnalysis = true; UUID serverUUID = ServerInfo.getServerUUID(); - AnalysisContainer analysisContainer = CacheSystem.getInstance().getDataContainerCache().getAnalysisContainer(serverUUID); + AnalysisContainer analysisContainer = new AnalysisContainer(Database.getActive().fetch().getServerContainer(serverUUID)); return new AnalysisPage(analysisContainer).toHtml(); } catch (DBOpException e) { if (!e.getCause().getMessage().contains("Connection is closed")) { diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/RawPlayerDataResponse.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/RawPlayerDataResponse.java index 5e5970c71..6a9ee2391 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/RawPlayerDataResponse.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/RawPlayerDataResponse.java @@ -1,6 +1,6 @@ package com.djrapitops.plan.system.webserver.response.pages; -import com.djrapitops.plan.system.cache.CacheSystem; +import com.djrapitops.plan.system.database.databases.Database; import java.util.UUID; @@ -12,6 +12,6 @@ import java.util.UUID; public class RawPlayerDataResponse extends RawDataResponse { public RawPlayerDataResponse(UUID uuid) { - super(CacheSystem.getInstance().getDataContainerCache().getPlayerContainer(uuid)); + super(Database.getActive().fetch().getPlayerContainer(uuid)); } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/RawServerDataResponse.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/RawServerDataResponse.java index 814198d15..acb61ba99 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/RawServerDataResponse.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/RawServerDataResponse.java @@ -1,6 +1,6 @@ package com.djrapitops.plan.system.webserver.response.pages; -import com.djrapitops.plan.system.cache.CacheSystem; +import com.djrapitops.plan.system.database.databases.Database; import java.util.UUID; @@ -12,6 +12,6 @@ import java.util.UUID; public class RawServerDataResponse extends RawDataResponse { public RawServerDataResponse(UUID serverUUID) { - super(CacheSystem.getInstance().getDataContainerCache().getAnalysisContainer(serverUUID).getServerContainer()); + super(Database.getActive().fetch().getServerContainer(serverUUID)); } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/pages/DebugPage.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/pages/DebugPage.java index 4da7cdffc..ad8af1497 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/pages/DebugPage.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/pages/DebugPage.java @@ -2,13 +2,10 @@ package com.djrapitops.plan.utilities.html.pages; import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.data.container.Session; -import com.djrapitops.plan.data.store.CachingSupplier; -import com.djrapitops.plan.data.store.Key; import com.djrapitops.plan.data.store.keys.SessionKeys; import com.djrapitops.plan.data.store.mutators.formatting.Formatter; import com.djrapitops.plan.data.store.mutators.formatting.Formatters; import com.djrapitops.plan.data.store.objects.DateHolder; -import com.djrapitops.plan.system.cache.CacheSystem; import com.djrapitops.plan.system.cache.SessionCache; import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.info.connection.ConnectionLog; @@ -32,7 +29,6 @@ import java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; import java.nio.charset.Charset; import java.util.*; -import java.util.function.Supplier; /** * Html parsing for the Debug page. @@ -68,7 +64,6 @@ public class DebugPage implements Page { StringBuilder content = new StringBuilder(); appendResponseCache(content); appendSessionCache(content); - appendDataContainerCache(content); return content.toString(); } @@ -110,36 +105,6 @@ public class DebugPage implements Page { } } - private void appendDataContainerCache(StringBuilder content) { - try { - content.append("
### DataContainer Cache:

"); - - content.append("Key | Is Cached | Cache Time
") - .append("-- | -- | --
"); - Formatter timeStamp = Formatters.yearLongValue(); - Set> dataContainers = CacheSystem.getInstance().getDataContainerCache().getMap().entrySet(); - if (dataContainers.isEmpty()) { - content.append("Empty"); - } - for (Map.Entry entry : dataContainers) { - String keyName = entry.getKey().getKeyName(); - Supplier supplier = entry.getValue(); - if (supplier instanceof CachingSupplier) { - CachingSupplier cachingSupplier = (CachingSupplier) supplier; - boolean isCached = cachingSupplier.isCached(); - String cacheText = isCached ? "Yes" : "No"; - String cacheTime = isCached ? timeStamp.apply(cachingSupplier.getCacheTime()) : "-"; - content.append(keyName).append(" | ").append(cacheText).append(" | ").append(cacheTime).append("
"); - } else { - content.append(keyName).append(" | ").append("Non-caching Supplier").append(" | ").append("-").append("
"); - } - } - content.append("
"); - } catch (Exception e) { - Log.toLog(this.getClass(), e); - } - } - private String createConfigContent() { StringBuilder content = new StringBuilder(); appendConfig(content); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/pages/InspectPage.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/pages/InspectPage.java index 6312d31f4..506626182 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/pages/InspectPage.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/pages/InspectPage.java @@ -14,7 +14,6 @@ import com.djrapitops.plan.data.store.mutators.formatting.Formatter; import com.djrapitops.plan.data.store.mutators.formatting.Formatters; import com.djrapitops.plan.data.store.mutators.formatting.PlaceholderReplacer; import com.djrapitops.plan.data.time.WorldTimes; -import com.djrapitops.plan.system.cache.CacheSystem; import com.djrapitops.plan.system.cache.SessionCache; import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.info.server.ServerInfo; @@ -60,7 +59,7 @@ public class InspectPage implements Page { } Benchmark.start("Inspect Parse, Fetch"); Database db = Database.getActive(); - PlayerContainer container = CacheSystem.getInstance().getDataContainerCache().getPlayerContainer(uuid); + PlayerContainer container = Database.getActive().fetch().getPlayerContainer(uuid); if (!container.getValue(PlayerKeys.REGISTERED).isPresent()) { throw new IllegalStateException("Player is not registered"); } From 12073e9732808bfe736aa3371a10e4838f9e63f0 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Thu, 16 Aug 2018 12:16:28 +0300 Subject: [PATCH 02/21] Fixed ConcurrentModificationException #683 --- .../plan/utilities/html/structure/SessionAccordion.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/SessionAccordion.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/SessionAccordion.java index 00cbc8ee9..b50ebd4e4 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/SessionAccordion.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/SessionAccordion.java @@ -160,7 +160,7 @@ public class SessionAccordion extends AbstractAccordion { sessions.sort(new DateHolderRecentComparator()); int i = 0; - for (Session session : sessions) { + for (Session session : new ArrayList<>(sessions)) { if (i >= maxSessions) { break; } From 23929d73ca8440fcd2a28a8e5b45ba005e50a524 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Thu, 16 Aug 2018 12:19:36 +0300 Subject: [PATCH 03/21] Filtered out ping under 0 and over 4000ms, increased ping data gather delay to 15s #684 --- .../djrapitops/plan/data/store/mutators/PingMutator.java | 6 +++--- .../processing/processors/player/PingInsertProcessor.java | 6 +++--- .../djrapitops/plan/system/tasks/server/PingCountTimer.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/PingMutator.java b/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/PingMutator.java index 3a7af4a38..7c2be8749 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/PingMutator.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/PingMutator.java @@ -52,7 +52,7 @@ public class PingMutator { int max = -1; for (Ping ping : pings) { Integer value = ping.getMax(); - if (value < 0 || 8000 < value) { + if (value <= 0 || 4000 < value) { continue; } if (value > max) { @@ -67,7 +67,7 @@ public class PingMutator { int min = -1; for (Ping ping : pings) { Integer value = ping.getMin(); - if (value < 0 || 8000 < value) { + if (value <= 0 || 4000 < value) { continue; } if (value < min || min == -1) { @@ -80,7 +80,7 @@ public class PingMutator { public double average() { return pings.stream().mapToDouble(Ping::getAverage) - .filter(value -> value >= 0 && value <= 8000) + .filter(value -> value > 0 && value <= 4000) .average().orElse(-1); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/PingInsertProcessor.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/PingInsertProcessor.java index c2da9b280..0f068bfcf 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/PingInsertProcessor.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/PingInsertProcessor.java @@ -37,7 +37,7 @@ public class PingInsertProcessor implements CriticalRunnable { long lastDate = history.get(history.size() - 1).getDate(); OptionalInt max = history.stream() .mapToInt(DateObj::getValue) - .filter(i -> i >= 0) + .filter(i -> i > 0 && i < 4000) .max(); if (!max.isPresent()) { @@ -46,12 +46,12 @@ public class PingInsertProcessor implements CriticalRunnable { int minValue = history.stream() .mapToInt(DateObj::getValue) - .filter(i -> i >= 0) + .filter(i -> i > 0 && i < 4000) .min().orElse(-1); double avgValue = history.stream() .mapToInt(DateObj::getValue) - .filter(i -> i >= 0) + .filter(i -> i > 0 && i < 4000) .average().orElse(-1); int maxValue = max.getAsInt(); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PingCountTimer.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PingCountTimer.java index 0e00df941..8e1e360c0 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PingCountTimer.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PingCountTimer.java @@ -160,7 +160,7 @@ public class PingCountTimer extends AbsRunnable implements Listener { addPlayer(player); } } - }).runTaskLater(TimeAmount.SECOND.ticks() * 10L); + }).runTaskLater(TimeAmount.SECOND.ticks() * 15L); } @EventHandler From 5ad7f3f591224eff8cdfb0ec6dcf85ab7c64337f Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Thu, 16 Aug 2018 12:21:55 +0300 Subject: [PATCH 04/21] Fixed sponge metrics --- Plan/src/main/java/com/djrapitops/plan/PlanSponge.java | 6 +++++- .../plan/utilities/metrics/BStatsSponge.java | 10 +++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/PlanSponge.java b/Plan/src/main/java/com/djrapitops/plan/PlanSponge.java index f13ddc60b..a88e42f62 100644 --- a/Plan/src/main/java/com/djrapitops/plan/PlanSponge.java +++ b/Plan/src/main/java/com/djrapitops/plan/PlanSponge.java @@ -14,6 +14,7 @@ import com.djrapitops.plugin.api.utility.log.DebugLog; import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.settings.ColorScheme; import com.google.inject.Inject; +import org.bstats.sponge.Metrics; import org.slf4j.Logger; import org.spongepowered.api.config.ConfigDir; import org.spongepowered.api.event.Listener; @@ -27,6 +28,9 @@ import java.io.InputStream; @Plugin(id = "plan", name = "Plan", version = "4.4.3", description = "Player Analytics Plugin by Rsl1122", authors = {"Rsl1122"}) public class PlanSponge extends SpongePlugin implements PlanPlugin { + @Inject + private Metrics metrics; + @Inject private Logger logger; @@ -58,7 +62,7 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin { locale = system.getLocaleSystem().getLocale(); system.enable(); - new BStatsSponge().registerMetrics(); + new BStatsSponge(metrics).registerMetrics(); Log.info(locale.getString(PluginLang.ENABLED)); } catch (AbstractMethodError e) { diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/metrics/BStatsSponge.java b/Plan/src/main/java/com/djrapitops/plan/utilities/metrics/BStatsSponge.java index 327048f5a..15c2cd6c3 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/metrics/BStatsSponge.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/metrics/BStatsSponge.java @@ -5,18 +5,22 @@ import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plugin.api.utility.log.Log; import org.bstats.sponge.Metrics; -import javax.inject.Inject; import java.io.Serializable; public class BStatsSponge { - @Inject - private Metrics metrics; + private final Metrics metrics; + + public BStatsSponge(Metrics metrics) { + this.metrics = metrics; + } public void registerMetrics() { Log.logDebug("Enable", "Enabling bStats Metrics."); if (metrics != null) { registerConfigSettingGraphs(); + } else { + Log.debug("Metrics not injected properly."); } } From 9d45fa1c400ef05ece153f8095b48056af7040ed Mon Sep 17 00:00:00 2001 From: Vankka Date: Thu, 16 Aug 2018 16:59:54 +0300 Subject: [PATCH 05/21] AdvancedBan support (#688) + Make Hook not check if the class extends JavaPlugin --- Plan/src/main/resources/plugin.yml | 1 + PlanPluginBridge/pom.xml | 10 +- .../djrapitops/pluginbridge/plan/Bridge.java | 6 +- .../djrapitops/pluginbridge/plan/Hook.java | 11 +- .../plan/advancedban/AdvancedBanData.java | 105 ++++++++++++++++++ .../plan/advancedban/AdvancedBanHook.java | 26 +++++ 6 files changed, 148 insertions(+), 11 deletions(-) create mode 100644 PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedban/AdvancedBanData.java create mode 100644 PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedban/AdvancedBanHook.java diff --git a/Plan/src/main/resources/plugin.yml b/Plan/src/main/resources/plugin.yml index a13aacbab..196fb25b3 100644 --- a/Plan/src/main/resources/plugin.yml +++ b/Plan/src/main/resources/plugin.yml @@ -19,6 +19,7 @@ softdepend: - ProtocolSupport - Kingdoms - RedProtect +- AdvancedBan commands: plan: diff --git a/PlanPluginBridge/pom.xml b/PlanPluginBridge/pom.xml index e588a00d0..cc4e6edba 100644 --- a/PlanPluginBridge/pom.xml +++ b/PlanPluginBridge/pom.xml @@ -129,7 +129,7 @@ com.gmail.nossr50 - mcmmo + mcMMO 1.5.07 provided @@ -161,7 +161,7 @@ net.kaikk.mc GriefPreventionPlus - RELEASE + 13.3 provided @@ -230,6 +230,12 @@ 6.549 provided + + me.leoko + advancedban + 2.1.5 + provided + ${project.artifactId} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/Bridge.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/Bridge.java index a29c66bea..809783300 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/Bridge.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/Bridge.java @@ -6,6 +6,7 @@ import com.djrapitops.plugin.api.Check; import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.pluginbridge.plan.aac.AdvancedAntiCheatHook; import com.djrapitops.pluginbridge.plan.advancedachievements.AdvancedAchievementsHook; +import com.djrapitops.pluginbridge.plan.advancedban.AdvancedBanHook; import com.djrapitops.pluginbridge.plan.askyblock.ASkyBlockHook; import com.djrapitops.pluginbridge.plan.banmanager.BanManagerHook; import com.djrapitops.pluginbridge.plan.buycraft.BuyCraftHook; @@ -64,13 +65,16 @@ public class Bridge { } private static Hook[] getBungeeHooks(HookHandler h) { - return new Hook[0]; + return new Hook[]{ + new AdvancedBanHook(h) + }; } private static Hook[] getBukkitHooks(HookHandler h) { return new Hook[]{ new AdvancedAntiCheatHook(h), new AdvancedAchievementsHook(h), + new AdvancedBanHook(h), new ASkyBlockHook(h), new BanManagerHook(h), new BuyCraftHook(h), diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/Hook.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/Hook.java index 8abe4ff9b..16f600f53 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/Hook.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/Hook.java @@ -2,9 +2,6 @@ package com.djrapitops.pluginbridge.plan; import com.djrapitops.plan.data.plugin.HookHandler; import com.djrapitops.plan.data.plugin.PluginData; -import org.bukkit.plugin.java.JavaPlugin; - -import static org.bukkit.plugin.java.JavaPlugin.getPlugin; /** * Abstract class for easy hooking of plugins. @@ -35,11 +32,9 @@ public abstract class Hook { public Hook(String plugin, HookHandler hookHandler) { this.hookHandler = hookHandler; try { - Class givenClass = Class.forName(plugin); - Class pluginClass = (Class) givenClass; - JavaPlugin hookedPlugin = getPlugin(pluginClass); - enabled = hookedPlugin.isEnabled(); - } catch (NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError | Exception e) { + Class.forName(plugin); + enabled = true; + } catch (Exception e) { enabled = false; } } diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedban/AdvancedBanData.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedban/AdvancedBanData.java new file mode 100644 index 000000000..31f4bfae2 --- /dev/null +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedban/AdvancedBanData.java @@ -0,0 +1,105 @@ +/* + * Licence is provided in the jar as license.yml also here: + * https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml + */ +package com.djrapitops.pluginbridge.plan.advancedban; + +import com.djrapitops.plan.api.PlanAPI; +import com.djrapitops.plan.data.element.AnalysisContainer; +import com.djrapitops.plan.data.element.InspectContainer; +import com.djrapitops.plan.data.plugin.ContainerSize; +import com.djrapitops.plan.data.plugin.PluginData; +import com.djrapitops.plan.data.store.keys.AnalysisKeys; +import com.djrapitops.plan.utilities.FormatUtils; +import com.djrapitops.plan.utilities.html.Html; +import com.djrapitops.plan.utilities.html.HtmlUtils; +import com.djrapitops.plan.utilities.html.icon.Color; +import com.djrapitops.plan.utilities.html.icon.Family; +import com.djrapitops.plan.utilities.html.icon.Icon; +import com.djrapitops.plan.utilities.html.icon.Icons; +import com.djrapitops.plugin.api.utility.log.Log; +import java.util.Collection; +import java.util.HashMap; +import java.util.UUID; +import me.leoko.advancedban.manager.PunishmentManager; +import me.leoko.advancedban.manager.UUIDManager; +import me.leoko.advancedban.utils.Punishment; +import me.leoko.advancedban.utils.PunishmentType; + +/** + * PluginData for AdvancedBan plugin. + * + * @author Vankka + */ +public class AdvancedBanData extends PluginData { + public AdvancedBanData() { + super(ContainerSize.THIRD, "AdvancedBan"); + setPluginIcon(Icons.BANNED); + } + + @Override + public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) { + String abUuid = uuid.toString().replace("-", ""); + + if (uuid.version() == 3) { // Cracked / Offline UUID + return inspectContainer; + } + + Punishment ban = PunishmentManager.get().getBan(abUuid); + Punishment mute = PunishmentManager.get().getMute(abUuid); + long warnings = PunishmentManager.get().getWarns(abUuid).stream().filter(warning -> !warning.isExpired()).count(); + + inspectContainer.addValue(getWithIcon("Banned", Icons.BANNED), ban != null ? "Yes" : "No"); + inspectContainer.addValue(getWithIcon("Muted", Icon.called("bell-slash").of(Color.DEEP_ORANGE)), mute != null ? "Yes" : "No"); + inspectContainer.addValue(getWithIcon("Warnings", Icon.called("flag").of(Color.YELLOW)), warnings); + + if (ban != null) { + String operator = ban.getOperator(); + String link = Html.LINK.parse(PlanAPI.getInstance().getPlayerInspectPageLink(operator), operator); + String reason = HtmlUtils.swapColorsToSpan(ban.getReason()); + long start = ban.getStart(); + String end = FormatUtils.formatTimeStampYear(ban.getEnd()); + + if (ban.getType() == PunishmentType.BAN || ban.getType() == PunishmentType.IP_BAN) { // Permanent + end = "Permanent ban"; + } + + if (operator.equals("CONSOLE")) { + link = "CONSOLE"; + } + + inspectContainer.addValue(" " + getWithIcon("Operator", Icon.called("user").of(Color.RED)), link); + inspectContainer.addValue(" " + getWithIcon("Date", Icon.called("calendar").of(Color.RED).of(Family.REGULAR)), FormatUtils.formatTimeStampYear(start)); + inspectContainer.addValue(" " + getWithIcon("Ends", Icon.called("calendar-check").of(Color.RED).of(Family.REGULAR)), end); + inspectContainer.addValue(" " + getWithIcon("Reason", Icon.called("comment").of(Color.RED).of(Family.REGULAR)), reason); + } + + if (mute != null) { + String operator = mute.getOperator(); + String link = Html.LINK.parse(PlanAPI.getInstance().getPlayerInspectPageLink(operator), operator); + String reason = HtmlUtils.swapColorsToSpan(mute.getReason()); + long start = mute.getStart(); + String end = FormatUtils.formatTimeStampYear(mute.getEnd()); + + if (mute.getType() == PunishmentType.MUTE) { // Permanent + end = "Permanent mute"; + } + + if (operator.equals("CONSOLE")) { + link = "CONSOLE"; + } + + inspectContainer.addValue(" " + getWithIcon("Operator", Icon.called("user").of(Color.DEEP_ORANGE)), link); + inspectContainer.addValue(" " + getWithIcon("Date", Icon.called("calendar").of(Color.DEEP_ORANGE).of(Family.REGULAR)), FormatUtils.formatTimeStampYear(start)); + inspectContainer.addValue(" " + getWithIcon("Ends", Icon.called("calendar-check").of(Color.DEEP_ORANGE).of(Family.REGULAR)), end); + inspectContainer.addValue(" " + getWithIcon("Reason", Icon.called("comment").of(Color.DEEP_ORANGE).of(Family.REGULAR)), reason); + } + + return inspectContainer; + } + + @Override + public AnalysisContainer getServerData(Collection uuids, AnalysisContainer analysisContainer) { + return analysisContainer; + } +} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedban/AdvancedBanHook.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedban/AdvancedBanHook.java new file mode 100644 index 000000000..b118ce1f4 --- /dev/null +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/advancedban/AdvancedBanHook.java @@ -0,0 +1,26 @@ +/* + * Licence is provided in the jar as license.yml also here: + * https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml + */ +package com.djrapitops.pluginbridge.plan.advancedban; + +import com.djrapitops.pluginbridge.plan.Hook; +import com.djrapitops.plan.data.plugin.HookHandler; + +/** + * Hook for AdvancedBan plugin. + * + * @author Vankka + */ +public class AdvancedBanHook extends Hook { + public AdvancedBanHook(HookHandler hookHandler) { + super("me.leoko.advancedban.Universal", hookHandler); + } + + @Override + public void hook() throws NoClassDefFoundError { + if (enabled) { + addPluginDataSource(new AdvancedBanData()); + } + } +} From 53851bb6da274db0150252bcae307e9b4461e0c1 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 20 Aug 2018 10:36:32 +0300 Subject: [PATCH 06/21] Updated hikaricp to 3.2.0 --- Plan/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plan/pom.xml b/Plan/pom.xml index 0c307b7e6..baf436b60 100644 --- a/Plan/pom.xml +++ b/Plan/pom.xml @@ -112,7 +112,7 @@ com.zaxxer HikariCP - 3.1.0 + 3.2.0 From 151d09f284b2357821c67b2ff6ac2ddb3a3e0874 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 20 Aug 2018 10:59:14 +0300 Subject: [PATCH 07/21] Fixes longest world time calculation #690 --- .../com/djrapitops/plan/data/container/Session.java | 10 +++++++--- .../java/com/djrapitops/plan/data/time/WorldTimes.java | 7 +++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java b/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java index 4b0ce2ce0..4a6fb62c4 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java @@ -154,11 +154,11 @@ public class Session extends DataContainer implements DateHolder { } public void setWorldTimes(WorldTimes worldTimes) { - putRawData(SessionKeys.WORLD_TIMES, worldTimes); + this.worldTimes = worldTimes; } public void setPlayerKills(List playerKills) { - putRawData(SessionKeys.PLAYER_KILLS, playerKills); + this.playerKills = playerKills; } public boolean isFetchedFromDB() { @@ -231,7 +231,6 @@ public class Session extends DataContainer implements DateHolder { } Map playtimePerAlias = worldTimes.getPlaytimePerAlias(); - long total = worldTimes.getTotal(); long longest = 0; String theWorld = "-"; @@ -244,6 +243,11 @@ public class Session extends DataContainer implements DateHolder { } } + long total = worldTimes.getTotal(); + // Prevent arithmetic error if 0 + if (total <= 0) { + total = -1; + } double quotient = longest * 1.0 / total; return theWorld + " (" + Formatters.percentage().apply(quotient) + ")"; diff --git a/Plan/src/main/java/com/djrapitops/plan/data/time/WorldTimes.java b/Plan/src/main/java/com/djrapitops/plan/data/time/WorldTimes.java index 1554528bb..24ec27938 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/time/WorldTimes.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/time/WorldTimes.java @@ -170,8 +170,11 @@ public class WorldTimes { } public Map getPlaytimePerAlias() { - Map playtimePerWorld = getWorldTimes() // WorldTimes Map - .entrySet().stream() + if (times.isEmpty()) { + return new HashMap<>(); + } + + Map playtimePerWorld = times.entrySet().stream() // WorldTimes Map .collect(Collectors.toMap( Map.Entry::getKey, entry -> entry.getValue().getTotal() // GMTimes.getTotal From e165164a7f80686dabfc9c696e50ac3f43b0a34b Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 20 Aug 2018 11:04:28 +0300 Subject: [PATCH 08/21] Fixes wrong relative link on server page #689 --- Plan/src/main/resources/web/server.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Plan/src/main/resources/web/server.html b/Plan/src/main/resources/web/server.html index 17a79e9e8..5438fa41a 100644 --- a/Plan/src/main/resources/web/server.html +++ b/Plan/src/main/resources/web/server.html @@ -1148,9 +1148,9 @@ - - - + + + From 5e2c540522ecd391c37ea677c56723e248732a2d Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 20 Aug 2018 11:35:26 +0300 Subject: [PATCH 09/21] Fixed player online status on server switch, reduced delay 20 -> 5s #646 --- .../listeners/bungee/PlayerOnlineListener.java | 4 ++-- .../processors/info/PlayerPageUpdateProcessor.java | 2 +- .../plan/system/cache/SessionCacheTest.java | 12 ++++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bungee/PlayerOnlineListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bungee/PlayerOnlineListener.java index efb286640..1ab692619 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bungee/PlayerOnlineListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bungee/PlayerOnlineListener.java @@ -15,8 +15,8 @@ import com.djrapitops.plan.system.webserver.cache.PageId; import com.djrapitops.plan.system.webserver.cache.ResponseCache; import com.djrapitops.plugin.api.utility.log.Log; import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.PlayerDisconnectEvent; import net.md_5.bungee.api.event.PostLoginEvent; -import net.md_5.bungee.api.event.ServerDisconnectEvent; import net.md_5.bungee.api.event.ServerSwitchEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.event.EventHandler; @@ -53,7 +53,7 @@ public class PlayerOnlineListener implements Listener { } @EventHandler - public void onLogout(ServerDisconnectEvent event) { + public void onLogout(PlayerDisconnectEvent event) { try { ProxiedPlayer player = event.getPlayer(); UUID uuid = player.getUniqueId(); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/info/PlayerPageUpdateProcessor.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/info/PlayerPageUpdateProcessor.java index 98d0cfaa7..e6cbe7cf7 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/info/PlayerPageUpdateProcessor.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/info/PlayerPageUpdateProcessor.java @@ -32,7 +32,7 @@ public class PlayerPageUpdateProcessor implements Runnable { cancel(); } } - }).runTaskLaterAsynchronously(TimeAmount.SECOND.ticks() * 20); + }).runTaskLaterAsynchronously(TimeAmount.SECOND.ticks() * 5); } } } diff --git a/Plan/src/test/java/com/djrapitops/plan/system/cache/SessionCacheTest.java b/Plan/src/test/java/com/djrapitops/plan/system/cache/SessionCacheTest.java index 50e45a227..65eda615b 100644 --- a/Plan/src/test/java/com/djrapitops/plan/system/cache/SessionCacheTest.java +++ b/Plan/src/test/java/com/djrapitops/plan/system/cache/SessionCacheTest.java @@ -43,4 +43,16 @@ public class SessionCacheTest { assertTrue(cachedSession.isPresent()); assertEquals(session, cachedSession.get()); } + + @Test + public void testBungeeReCaching() { + SessionCache cache = new BungeeDataCache(null); + cache.cacheSession(uuid, session); + Session expected = new Session(uuid, 0, "", ""); + cache.cacheSession(uuid, expected); + + Optional result = SessionCache.getCachedSession(uuid); + assertTrue(result.isPresent()); + assertEquals(expected, result.get()); + } } \ No newline at end of file From d587892df2d260522b0f188e92e2ef9bf724bf21 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 20 Aug 2018 11:44:21 +0300 Subject: [PATCH 10/21] Fixed tests --- .../plan/data/container/Session.java | 22 ++++++++++++------- .../plan/system/cache/SessionCacheTest.java | 10 +++++---- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java b/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java index 4a6fb62c4..7a83447c0 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java @@ -182,14 +182,8 @@ public class Session extends DataContainer implements DateHolder { getValue(SessionKeys.END).orElse(-1L).equals(session.getValue(SessionKeys.END).orElse(-1L)) && mobKills == session.mobKills && deaths == session.deaths && - Objects.equals( - getValue(SessionKeys.WORLD_TIMES).orElse(null), - session.getValue(SessionKeys.WORLD_TIMES).orElse(null) - ) && - Objects.equals( - getValue(SessionKeys.PLAYER_KILLS).orElse(new ArrayList<>()), - session.getValue(SessionKeys.PLAYER_KILLS).orElse(new ArrayList<>()) - ); + Objects.equals(playerKills, session.playerKills) && + Objects.equals(worldTimes, session.worldTimes); } @Override @@ -252,4 +246,16 @@ public class Session extends DataContainer implements DateHolder { return theWorld + " (" + Formatters.percentage().apply(quotient) + ")"; } + + @Override + public String toString() { + return "Session{" + + "sessionStart=" + sessionStart + + ", worldTimes=" + worldTimes + + ", playerKills=" + playerKills + + ", mobKills=" + mobKills + + ", deaths=" + deaths + + ", afkTime=" + afkTime + + '}'; + } } diff --git a/Plan/src/test/java/com/djrapitops/plan/system/cache/SessionCacheTest.java b/Plan/src/test/java/com/djrapitops/plan/system/cache/SessionCacheTest.java index 65eda615b..7316387ab 100644 --- a/Plan/src/test/java/com/djrapitops/plan/system/cache/SessionCacheTest.java +++ b/Plan/src/test/java/com/djrapitops/plan/system/cache/SessionCacheTest.java @@ -1,10 +1,7 @@ package com.djrapitops.plan.system.cache; import com.djrapitops.plan.data.container.Session; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; +import org.junit.*; import org.junit.rules.TemporaryFolder; import utilities.TestConstants; import utilities.mocks.SystemMockUtil; @@ -36,6 +33,11 @@ public class SessionCacheTest { sessionCache.cacheSession(uuid, session); } + @After + public void tearDown() { + SessionCache.clear(); + } + @Test public void testAtomity() { SessionCache reloaded = new SessionCache(null); From 268474d5caf6271681000a4286d485059c91c01d Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Tue, 21 Aug 2018 09:46:43 +0300 Subject: [PATCH 11/21] Added config settings for ping delays #691 --- .../java/com/djrapitops/plan/system/settings/Settings.java | 2 ++ .../plan/system/settings/network/NetworkSettings.java | 4 +++- .../com/djrapitops/plan/system/tasks/BukkitTaskSystem.java | 5 ++++- .../djrapitops/plan/system/tasks/server/PingCountTimer.java | 3 ++- Plan/src/main/resources/bungeeconfig.yml | 3 +++ Plan/src/main/resources/config.yml | 3 +++ 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/system/settings/Settings.java b/Plan/src/main/java/com/djrapitops/plan/system/settings/Settings.java index 3a8d7e63f..0b283d009 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/settings/Settings.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/settings/Settings.java @@ -52,6 +52,8 @@ public enum Settings { AFK_THRESHOLD_MINUTES("Data.AFKThresholdMinutes"), KEEP_LOGS_DAYS("Plugin.KeepLogsForXDays"), KEEP_INACTIVE_PLAYERS_DAYS("Data.KeepInactivePlayerDataForDays"), + PING_SERVER_ENABLE_DELAY("Data.Ping.ServerEnableDelaySeconds"), + PING_PLAYER_LOGIN_DELAY("Data.Ping.PlayerLoginDelaySeconds"), // String DEBUG("Plugin.Debug"), diff --git a/Plan/src/main/java/com/djrapitops/plan/system/settings/network/NetworkSettings.java b/Plan/src/main/java/com/djrapitops/plan/system/settings/network/NetworkSettings.java index 7bc6990ad..985df52c5 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/settings/network/NetworkSettings.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/settings/network/NetworkSettings.java @@ -174,7 +174,9 @@ public class NetworkSettings { AFK_THRESHOLD_MINUTES, DATA_GEOLOCATIONS, KEEP_LOGS_DAYS, - KEEP_INACTIVE_PLAYERS_DAYS + KEEP_INACTIVE_PLAYERS_DAYS, + PING_SERVER_ENABLE_DELAY, + PING_PLAYER_LOGIN_DELAY }; Log.debug("NetworkSettings: Adding Config Values.."); for (Settings setting : sameStrings) { diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/BukkitTaskSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/BukkitTaskSystem.java index dfe9bd493..508efa0d4 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/BukkitTaskSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/BukkitTaskSystem.java @@ -5,10 +5,12 @@ package com.djrapitops.plan.system.tasks; import com.djrapitops.plan.Plan; +import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.tasks.server.BukkitTPSCountTimer; import com.djrapitops.plan.system.tasks.server.PaperTPSCountTimer; import com.djrapitops.plan.system.tasks.server.PingCountTimer; import com.djrapitops.plugin.api.Check; +import com.djrapitops.plugin.api.TimeAmount; import com.djrapitops.plugin.task.RunnableFactory; import org.bukkit.Bukkit; @@ -33,8 +35,9 @@ public class BukkitTaskSystem extends ServerTaskSystem { try { PingCountTimer pingCountTimer = new PingCountTimer(); ((Plan) plugin).registerListener(pingCountTimer); + long startDelay = TimeAmount.SECOND.ms() * (long) Settings.PING_SERVER_ENABLE_DELAY.getNumber(); RunnableFactory.createNew("PingCountTimer", pingCountTimer) - .runTaskTimer(20L, PingCountTimer.PING_INTERVAL); + .runTaskTimer(startDelay, PingCountTimer.PING_INTERVAL); } catch (ExceptionInInitializerError | NoClassDefFoundError ignore) { // Running CraftBukkit } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PingCountTimer.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PingCountTimer.java index 8e1e360c0..37c0b728b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PingCountTimer.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PingCountTimer.java @@ -26,6 +26,7 @@ package com.djrapitops.plan.system.tasks.server; import com.djrapitops.plan.data.store.objects.DateObj; import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.processors.player.PingInsertProcessor; +import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.utilities.java.Reflection; import com.djrapitops.plugin.api.TimeAmount; import com.djrapitops.plugin.api.utility.log.Log; @@ -160,7 +161,7 @@ public class PingCountTimer extends AbsRunnable implements Listener { addPlayer(player); } } - }).runTaskLater(TimeAmount.SECOND.ticks() * 15L); + }).runTaskLater(TimeAmount.SECOND.ticks() * (long) Settings.PING_PLAYER_LOGIN_DELAY.getNumber()); } @EventHandler diff --git a/Plan/src/main/resources/bungeeconfig.yml b/Plan/src/main/resources/bungeeconfig.yml index 0e4be559d..02d582993 100644 --- a/Plan/src/main/resources/bungeeconfig.yml +++ b/Plan/src/main/resources/bungeeconfig.yml @@ -67,6 +67,9 @@ Data: LogUnknownCommands: false CombineCommandAliases: true Geolocations: true + Ping: + ServerEnableDelaySeconds: 300 + PlayerLoginDelaySeconds: 30 KeepInactivePlayerDataForDays: 180 # ----------------------------------------------------- Customization: diff --git a/Plan/src/main/resources/config.yml b/Plan/src/main/resources/config.yml index be15fa519..266672566 100644 --- a/Plan/src/main/resources/config.yml +++ b/Plan/src/main/resources/config.yml @@ -81,6 +81,9 @@ Data: LogUnknownCommands: false CombineCommandAliases: true Geolocations: true + Ping: + ServerEnableDelaySeconds: 300 + PlayerLoginDelaySeconds: 30 KeepInactivePlayerDataForDays: 180 # ----------------------------------------------------- Customization: From 3afaad973124dda2365e9e98b4cbca39fe9af12f Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Tue, 21 Aug 2018 10:23:13 +0300 Subject: [PATCH 12/21] Changed gathered ping average to be median instead #691 (For each datapoint a median is calculated, which is then used in calculation for mean values, averages) --- .../player/PingInsertProcessor.java | 25 ++++-- .../plan/utilities/analysis/Median.java | 58 ++++++++++++ .../player/PingInsertProcessorTest.java | 66 ++++++++++++++ .../plan/utilities/analysis/MedianTest.java | 90 +++++++++++++++++++ 4 files changed, 230 insertions(+), 9 deletions(-) create mode 100644 Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Median.java create mode 100644 Plan/src/test/java/com/djrapitops/plan/system/processing/processors/player/PingInsertProcessorTest.java create mode 100644 Plan/src/test/java/com/djrapitops/plan/utilities/analysis/MedianTest.java diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/PingInsertProcessor.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/PingInsertProcessor.java index 0f068bfcf..abc1d6702 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/PingInsertProcessor.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/PingInsertProcessor.java @@ -9,10 +9,12 @@ import com.djrapitops.plan.data.store.objects.DateObj; import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.processing.CriticalRunnable; +import com.djrapitops.plan.utilities.analysis.Median; import java.util.List; import java.util.OptionalInt; import java.util.UUID; +import java.util.stream.Collectors; /** * Processes 60s values of a Ping list. @@ -44,23 +46,28 @@ public class PingInsertProcessor implements CriticalRunnable { return; } - int minValue = history.stream() - .mapToInt(DateObj::getValue) - .filter(i -> i > 0 && i < 4000) - .min().orElse(-1); + int minValue = getMinValue(history); - double avgValue = history.stream() - .mapToInt(DateObj::getValue) - .filter(i -> i > 0 && i < 4000) - .average().orElse(-1); + int meanValue = getMeanValue(history); int maxValue = max.getAsInt(); Ping ping = new Ping(lastDate, ServerInfo.getServerUUID(), minValue, maxValue, - avgValue); + meanValue); Database.getActive().save().ping(uuid, ping); } + + int getMinValue(List> history) { + return history.stream() + .mapToInt(DateObj::getValue) + .filter(i -> i > 0 && i < 4000) + .min().orElse(-1); + } + + int getMeanValue(List> history) { + return (int) Median.forInt(history.stream().map(DateObj::getValue).collect(Collectors.toList())).calculate(); + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Median.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Median.java new file mode 100644 index 000000000..92abc49cc --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Median.java @@ -0,0 +1,58 @@ +package com.djrapitops.plan.utilities.analysis; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Math utility for calculating the median from Integer values. + * + * @author Rsl1122 + */ +public class Median { + + private final List values; + private int size; + + private Median(Collection values, int b) { + this(values.stream().map(i -> (long) i).collect(Collectors.toList())); + } + + private Median(List values) { + this.values = values; + Collections.sort(values); + size = values.size(); + } + + public static Median forInt(Collection integers) { + return new Median(integers, 0); + } + + public static Median forLong(List longs) { + return new Median(longs); + } + + public double calculate() { + if (values.isEmpty()) { + return -1; + } + if (size % 2 == 0) { + return calculateEven(); + } else { + return calculateOdd(); + } + } + + private double calculateEven() { + int half = size / 2; + double x1 = values.get(half); + double x2 = values.get(half - 1); + return (x1 + x2) / 2; + } + + private double calculateOdd() { + int half = size / 2; + return (double) values.get(half); + } +} \ No newline at end of file diff --git a/Plan/src/test/java/com/djrapitops/plan/system/processing/processors/player/PingInsertProcessorTest.java b/Plan/src/test/java/com/djrapitops/plan/system/processing/processors/player/PingInsertProcessorTest.java new file mode 100644 index 000000000..ba7c40523 --- /dev/null +++ b/Plan/src/test/java/com/djrapitops/plan/system/processing/processors/player/PingInsertProcessorTest.java @@ -0,0 +1,66 @@ +package com.djrapitops.plan.system.processing.processors.player; + +import com.djrapitops.plan.data.store.objects.DateObj; +import com.djrapitops.plan.utilities.analysis.Median; +import com.djrapitops.plugin.api.TimeAmount; +import org.junit.Before; +import org.junit.Test; +import utilities.RandomData; +import utilities.TestConstants; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import static org.junit.Assert.assertEquals; + +/** + * Test for {@link PingInsertProcessor}. + * + * @author Rsl1122 + */ +public class PingInsertProcessorTest { + + private List> testPing; + + @Before + public void setUp() { + testPing = new ArrayList<>(); + + for (int i = 0; i < TimeAmount.MINUTE.ms(); i += TimeAmount.SECOND.ms() * 2L) { + testPing.add(new DateObj<>(i, RandomData.randomInt(1, 4000))); + } + } + + @Test + public void testMedian() { + List collect = testPing.stream().map(DateObj::getValue).sorted().collect(Collectors.toList()); + System.out.println(collect); + int expected = (int) Median.forInt(collect).calculate(); + int result = new PingInsertProcessor(TestConstants.PLAYER_ONE_UUID, new ArrayList<>()).getMeanValue(testPing); + System.out.println(result); + + assertEquals(expected, result); + } + + @Test + public void testMedianSingleEntry() { + int expected = 50; + int result = new PingInsertProcessor(TestConstants.PLAYER_ONE_UUID, new ArrayList<>()).getMeanValue( + Collections.singletonList(new DateObj<>(0, expected)) + ); + + assertEquals(expected, result); + } + + @Test + public void testMedianEmpty() { + int expected = -1; + int result = new PingInsertProcessor(TestConstants.PLAYER_ONE_UUID, new ArrayList<>()).getMeanValue( + Collections.emptyList() + ); + + assertEquals(expected, result); + } +} \ No newline at end of file diff --git a/Plan/src/test/java/com/djrapitops/plan/utilities/analysis/MedianTest.java b/Plan/src/test/java/com/djrapitops/plan/utilities/analysis/MedianTest.java new file mode 100644 index 000000000..50a0a3656 --- /dev/null +++ b/Plan/src/test/java/com/djrapitops/plan/utilities/analysis/MedianTest.java @@ -0,0 +1,90 @@ +package com.djrapitops.plan.utilities.analysis; + +import org.junit.Test; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +/** + * Tests for {@link Median}. + * + * @author Rsl1122 + */ +public class MedianTest { + + @Test + public void simpleOdd() { + List testValues = Arrays.asList(1, 3, 3, 6, 7, 8, 9); + Collections.shuffle(testValues); + double expected = 6; + double result = Median.forInt(testValues).calculate(); + + assertEquals(expected, result, 0.01); + } + + @Test + public void simpleEven() { + List testValues = Arrays.asList(1, 2, 3, 4, 5, 6, 8, 9); + Collections.shuffle(testValues); + double expected = 4.5; + double result = Median.forInt(testValues).calculate(); + + assertEquals(expected, result, 0.01); + } + + @Test + public void empty() { + double expected = -1; + double result = Median.forInt(Collections.emptyList()).calculate(); + + assertEquals(expected, result, 0.01); + } + + @Test + public void singleValue() { + double expected = 50; + double result = Median.forInt(Collections.singletonList((int) expected)).calculate(); + + assertEquals(expected, result, 0.01); + } + + @Test + public void twoValues() { + List testValues = Arrays.asList(1, 2); + double expected = 1.5; + double result = Median.forInt(testValues).calculate(); + + assertEquals(expected, result, 0.01); + } + + @Test + public void overflowOdd() { + List testValues = Arrays.asList(Integer.MIN_VALUE, 2, Integer.MAX_VALUE); + double expected = 2; + double result = Median.forInt(testValues).calculate(); + + assertEquals(expected, result, 0.01); + } + + @Test + public void overflowEven() { + List testValues = Arrays.asList(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); + double expected = -0.5; + double result = Median.forInt(testValues).calculate(); + + assertEquals(expected, result, 0.01); + } + + @Test + public void overflowEven2() { + List testValues = Arrays.asList(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); + double expected = Integer.MAX_VALUE; + double result = Median.forInt(testValues).calculate(); + + assertEquals(expected, result, 0.01); + } + +} \ No newline at end of file From bae8708e87b29739ce39b3bbeee00a1f3052e3d9 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Tue, 21 Aug 2018 10:24:38 +0300 Subject: [PATCH 13/21] Improved Session Length Median calculation on even number of sessions --- .../plan/data/store/mutators/SessionsMutator.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/SessionsMutator.java b/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/SessionsMutator.java index 10be83942..203d1c91a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/SessionsMutator.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/SessionsMutator.java @@ -7,6 +7,7 @@ import com.djrapitops.plan.data.store.containers.DataContainer; import com.djrapitops.plan.data.store.keys.CommonKeys; import com.djrapitops.plan.data.store.keys.SessionKeys; import com.djrapitops.plan.data.time.WorldTimes; +import com.djrapitops.plan.utilities.analysis.Median; import java.util.*; import java.util.function.Predicate; @@ -142,13 +143,8 @@ public class SessionsMutator { } public long toMedianSessionLength() { - List sessionLengths = sessions.stream().map(Session::getLength) - .sorted() - .collect(Collectors.toList()); - if (sessionLengths.isEmpty()) { - return 0; - } - return sessionLengths.get(sessionLengths.size() / 2); + List sessionLengths = sessions.stream().map(Session::getLength).collect(Collectors.toList()); + return (long) Median.forLong(sessionLengths).calculate(); } public int toAverageUniqueJoinsPerDay() { @@ -200,5 +196,4 @@ public class SessionsMutator { return toPlayerDeathList().size(); } - } \ No newline at end of file From f5cc33a7173ce2bcde0150a15c19114507647f78 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Tue, 21 Aug 2018 15:17:59 +0300 Subject: [PATCH 14/21] Add /planbungee uninstalled --- .../java/com/djrapitops/plan/command/PlanBungeeCommand.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Plan/src/main/java/com/djrapitops/plan/command/PlanBungeeCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/PlanBungeeCommand.java index f7daef2ea..7e37fd8f3 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/PlanBungeeCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/PlanBungeeCommand.java @@ -4,6 +4,7 @@ import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.command.commands.*; import com.djrapitops.plan.command.commands.manage.ManageConDebugCommand; import com.djrapitops.plan.command.commands.manage.ManageRawDataCommand; +import com.djrapitops.plan.command.commands.manage.ManageUninstalledCommand; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.lang.DeepHelpLang; import com.djrapitops.plan.system.settings.Permissions; @@ -44,6 +45,7 @@ public class PlanBungeeCommand extends TreeCmdNode { new ManageConDebugCommand(plugin), new ManageRawDataCommand(plugin), new BungeeSetupToggleCommand(plugin), + new ManageUninstalledCommand(plugin), new ReloadCommand(plugin), new DisableCommand(plugin), new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme()), From 8fb54ed905a725aac419419fe8f90c572503c958 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Tue, 21 Aug 2018 16:56:34 +0300 Subject: [PATCH 15/21] Added Connection: close header to HttpClient in ConnectionOut --- .../djrapitops/plan/system/info/connection/ConnectionOut.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionOut.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionOut.java index ca2b9fbe3..15881c207 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionOut.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionOut.java @@ -144,6 +144,7 @@ public class ConnectionOut { post.setHeader("Content-Type", "application/x-www-form-urlencoded"); post.setHeader("charset", "UTF-8"); + post.setHeader("Connection", "close"); byte[] toSend = parameters.getBytes(); post.setEntity(new ByteArrayEntity(toSend)); From 8ca16a1aa99737a36f6b3aa477996d94c4681f56 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Wed, 22 Aug 2018 10:38:44 +0300 Subject: [PATCH 16/21] Fixed Patch Task causing issues on disable #695 --- .../database/databases/sql/PatchTask.java | 56 +++++++++++++++++++ .../system/database/databases/sql/SQLDB.java | 32 ++--------- 2 files changed, 62 insertions(+), 26 deletions(-) create mode 100644 Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/PatchTask.java diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/PatchTask.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/PatchTask.java new file mode 100644 index 000000000..3a5f79711 --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/PatchTask.java @@ -0,0 +1,56 @@ +package com.djrapitops.plan.system.database.databases.sql; + +import com.djrapitops.plan.PlanPlugin; +import com.djrapitops.plan.system.database.databases.sql.patches.Patch; +import com.djrapitops.plan.system.locale.Locale; +import com.djrapitops.plan.system.locale.lang.PluginLang; +import com.djrapitops.plugin.api.utility.log.Log; +import com.djrapitops.plugin.task.AbsRunnable; + +import java.util.function.Supplier; + +/** + * Task that is in charge on patching the database when the database enables. + * + * @author Rsl1122 + */ +public class PatchTask extends AbsRunnable { + + private final Patch[] patches; + private final Supplier locale; + + public PatchTask(Patch[] patches, Supplier locale) { + this.patches = patches; + this.locale = locale; + } + + @Override + public void run() { + try { + boolean didApply = applyPatches(); + Log.info(locale.get().getString( + didApply ? PluginLang.DB_APPLIED_PATCHES : PluginLang.DB_APPLIED_PATCHES_ALREADY + )); + } catch (Exception e) { + Log.error("----------------------------------------------------"); + Log.error(locale.get().getString(PluginLang.ENABLE_FAIL_DB_PATCH)); + Log.error("----------------------------------------------------"); + Log.toLog(this.getClass(), e); + PlanPlugin.getInstance().onDisable(); + } + } + + private boolean applyPatches() { + boolean didApply = false; + for (Patch patch : patches) { + if (!patch.hasBeenApplied()) { + String patchName = patch.getClass().getSimpleName(); + Log.info(locale.get().getString(PluginLang.DB_APPLY_PATCH, patchName)); + patch.apply(); + didApply = true; + } + } + return didApply; + } + +} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLDB.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLDB.java index 2e1656591..46b376125 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLDB.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLDB.java @@ -1,6 +1,5 @@ package com.djrapitops.plan.system.database.databases.sql; -import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.api.exceptions.database.DBInitException; import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.system.database.databases.Database; @@ -157,31 +156,12 @@ public abstract class SQLDB extends Database { new VersionTableRemovalPatch(this) }; - RunnableFactory.createNew("Database Patch", new AbsRunnable() { - @Override - public void run() { - try { - boolean applied = false; - for (Patch patch : patches) { - if (!patch.hasBeenApplied()) { - String patchName = patch.getClass().getSimpleName(); - Log.info(locale.get().getString(PluginLang.DB_APPLY_PATCH, patchName)); - patch.apply(); - applied = true; - } - } - Log.info(locale.get().getString( - applied ? PluginLang.DB_APPLIED_PATCHES : PluginLang.DB_APPLIED_PATCHES_ALREADY - )); - } catch (Exception e) { - Log.error("----------------------------------------------------"); - Log.error(locale.get().getString(PluginLang.ENABLE_FAIL_DB_PATCH)); - Log.error("----------------------------------------------------"); - Log.toLog(this.getClass(), e); - PlanPlugin.getInstance().onDisable(); - } - } - }).runTaskLaterAsynchronously(TimeAmount.SECOND.ticks() * 5L); + try { + RunnableFactory.createNew("Database Patch", new PatchTask(patches, locale)) + .runTaskLaterAsynchronously(TimeAmount.SECOND.ticks() * 5L); + } catch (Exception ignore) { + // Task failed to register because plugin is being disabled + } } catch (DBOpException e) { throw new DBInitException("Failed to set-up Database", e); } From 710779e7b08d194fd693cfeaebc0e9bd91f46503 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Wed, 22 Aug 2018 10:39:32 +0300 Subject: [PATCH 17/21] Fixed Ping Enable delay #694 --- .../java/com/djrapitops/plan/system/tasks/BukkitTaskSystem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/BukkitTaskSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/BukkitTaskSystem.java index 508efa0d4..b99dde0c8 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/BukkitTaskSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/BukkitTaskSystem.java @@ -35,7 +35,7 @@ public class BukkitTaskSystem extends ServerTaskSystem { try { PingCountTimer pingCountTimer = new PingCountTimer(); ((Plan) plugin).registerListener(pingCountTimer); - long startDelay = TimeAmount.SECOND.ms() * (long) Settings.PING_SERVER_ENABLE_DELAY.getNumber(); + long startDelay = TimeAmount.SECOND.ticks() * (long) Settings.PING_SERVER_ENABLE_DELAY.getNumber(); RunnableFactory.createNew("PingCountTimer", pingCountTimer) .runTaskTimer(startDelay, PingCountTimer.PING_INTERVAL); } catch (ExceptionInInitializerError | NoClassDefFoundError ignore) { From 5143e0fd7fd0ae4a0d5b0e7746e06ba19ac924af Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Wed, 22 Aug 2018 10:45:15 +0300 Subject: [PATCH 18/21] Reduced AFK perm check to a single check until next reload #693 --- .../plan/system/listeners/bukkit/AFKListener.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/AFKListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/AFKListener.java index 2b7f51409..6f1246cc6 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/AFKListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/AFKListener.java @@ -12,6 +12,8 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerMoveEvent; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; /** @@ -27,14 +29,24 @@ public class AFKListener implements Listener { // Static so that /reload does not cause afk tracking to fail. public static final AFKTracker AFK_TRACKER = new AFKTracker(); + private final Map ignorePermissionInfo; + + public AFKListener() { + ignorePermissionInfo = new HashMap<>(); + } + private void event(PlayerEvent event) { try { Player player = event.getPlayer(); UUID uuid = player.getUniqueId(); long time = System.currentTimeMillis(); - if (player.hasPermission(Permissions.IGNORE_AFK.getPermission())) { + boolean ignored = ignorePermissionInfo.getOrDefault(uuid, player.hasPermission(Permissions.IGNORE_AFK.getPermission())); + if (ignored) { AFK_TRACKER.hasIgnorePermission(uuid); + ignorePermissionInfo.put(uuid, true); + } else { + ignorePermissionInfo.put(uuid, false); } AFK_TRACKER.performedAction(uuid, time); From 6585fa18a147682dffb79ba189dce26be3e1fb36 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Thu, 23 Aug 2018 18:56:25 +0300 Subject: [PATCH 19/21] Fixed current session not being displayed on Analysis page #697 --- .../database/databases/sql/operation/SQLFetchOps.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java index e73dd6de5..30e957451 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java @@ -9,9 +9,11 @@ import com.djrapitops.plan.data.store.mutators.PlayersMutator; import com.djrapitops.plan.data.store.mutators.SessionsMutator; import com.djrapitops.plan.data.store.objects.DateObj; import com.djrapitops.plan.data.time.WorldTimes; +import com.djrapitops.plan.system.cache.SessionCache; import com.djrapitops.plan.system.database.databases.operation.FetchOperations; import com.djrapitops.plan.system.database.databases.sql.SQLDB; import com.djrapitops.plan.system.info.server.Server; +import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plugin.api.TimeAmount; import java.util.*; @@ -84,7 +86,13 @@ public class SQLFetchOps extends SQLOps implements FetchOperations { // Calculating getters container.putSupplier(ServerKeys.OPERATORS, () -> PlayersMutator.forContainer(container).operators()); - container.putSupplier(ServerKeys.SESSIONS, () -> PlayersMutator.forContainer(container).getSessions()); + container.putSupplier(ServerKeys.SESSIONS, () -> { + List sessions = PlayersMutator.forContainer(container).getSessions(); + if (serverUUID.equals(ServerInfo.getServerUUID())) { + sessions.addAll(SessionCache.getActiveSessions().values()); + } + return sessions; + }); container.putSupplier(ServerKeys.PLAYER_KILLS, () -> SessionsMutator.forContainer(container).toPlayerKillList()); container.putSupplier(ServerKeys.PLAYER_KILL_COUNT, () -> container.getUnsafe(ServerKeys.PLAYER_KILLS).size()); container.putSupplier(ServerKeys.MOB_KILL_COUNT, () -> SessionsMutator.forContainer(container).toMobKillCount()); From e75f9a1027f328a06bbef781da3ca32c64de0725 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Thu, 23 Aug 2018 18:59:05 +0300 Subject: [PATCH 20/21] Version bump to 4.4.4 --- Plan/src/main/java/com/djrapitops/plan/PlanSponge.java | 2 +- Plan/src/main/resources/bungee.yml | 2 +- Plan/src/main/resources/plugin.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/PlanSponge.java b/Plan/src/main/java/com/djrapitops/plan/PlanSponge.java index a88e42f62..60ece7eba 100644 --- a/Plan/src/main/java/com/djrapitops/plan/PlanSponge.java +++ b/Plan/src/main/java/com/djrapitops/plan/PlanSponge.java @@ -25,7 +25,7 @@ import org.spongepowered.api.plugin.Plugin; import java.io.File; import java.io.InputStream; -@Plugin(id = "plan", name = "Plan", version = "4.4.3", description = "Player Analytics Plugin by Rsl1122", authors = {"Rsl1122"}) +@Plugin(id = "plan", name = "Plan", version = "4.4.4", description = "Player Analytics Plugin by Rsl1122", authors = {"Rsl1122"}) public class PlanSponge extends SpongePlugin implements PlanPlugin { @Inject diff --git a/Plan/src/main/resources/bungee.yml b/Plan/src/main/resources/bungee.yml index 3d5049815..365f2b64d 100644 --- a/Plan/src/main/resources/bungee.yml +++ b/Plan/src/main/resources/bungee.yml @@ -1,4 +1,4 @@ name: Plan author: Rsl1122 main: com.djrapitops.plan.PlanBungee -version: 4.4.3 \ No newline at end of file +version: 4.4.4 \ No newline at end of file diff --git a/Plan/src/main/resources/plugin.yml b/Plan/src/main/resources/plugin.yml index 196fb25b3..8583e4134 100644 --- a/Plan/src/main/resources/plugin.yml +++ b/Plan/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: Plan author: Rsl1122 main: com.djrapitops.plan.Plan -version: 4.4.3 +version: 4.4.4 softdepend: - EssentialsX - Towny From a130ce97ad72c5b1ae6c95c40b9e32ebac538d64 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Thu, 23 Aug 2018 19:07:46 +0300 Subject: [PATCH 21/21] Fixed Session PlayerKills not being saved --- .../main/java/com/djrapitops/plan/data/container/Session.java | 2 +- .../plan/system/database/databases/sql/tables/KillsTable.java | 4 ++-- .../system/database/databases/sql/tables/SessionsTable.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java b/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java index 7a83447c0..704ad2346 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java @@ -199,7 +199,7 @@ public class Session extends DataContainer implements DateHolder { return worldTimes; } - private List getPlayerKills() { + public List getPlayerKills() { return playerKills; } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/KillsTable.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/KillsTable.java index f7ee98ee6..a48ed9e62 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/KillsTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/KillsTable.java @@ -117,7 +117,7 @@ public class KillsTable extends UserIDTable { UUID victim = UUID.fromString(uuidS); long date = set.getLong(Col.DATE.get()); String weapon = set.getString(Col.WEAPON.get()); - session.getUnsafe(SessionKeys.PLAYER_KILLS).add(new PlayerKill(victim, weapon, date)); + session.getPlayerKills().add(new PlayerKill(victim, weapon, date)); } return null; } @@ -286,7 +286,7 @@ public class KillsTable extends UserIDTable { for (Session session : sessions) { int sessionID = session.getUnsafe(SessionKeys.DB_ID); // Every kill - for (PlayerKill kill : session.getUnsafe(SessionKeys.PLAYER_KILLS)) { + for (PlayerKill kill : session.getPlayerKills()) { UUID victim = kill.getVictim(); long date = kill.getDate(); String weapon = kill.getWeapon(); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/SessionsTable.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/SessionsTable.java index 7aae3de6a..5730b55e7 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/SessionsTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/SessionsTable.java @@ -113,7 +113,7 @@ public class SessionsTable extends UserIDTable { } db.getWorldTimesTable().saveWorldTimes(uuid, sessionID, session.getUnsafe(SessionKeys.WORLD_TIMES)); - db.getKillsTable().savePlayerKills(uuid, sessionID, session.getUnsafe(SessionKeys.PLAYER_KILLS)); + db.getKillsTable().savePlayerKills(uuid, sessionID, session.getPlayerKills()); } /**