From 818e93ac95e322c7d8bb1bac34dd7515707ce8a8 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sat, 26 May 2018 10:58:42 +0300 Subject: [PATCH] Fixed ReactHook registration and a bug with data collection --- Plan/dependency-reduced-pom.xml | 28 +++++++++---------- .../djrapitops/pluginbridge/plan/Bridge.java | 3 +- ...CollectionTask.java => ReactDataTask.java} | 21 ++++++++++---- .../pluginbridge/plan/react/ReactHook.java | 2 +- 4 files changed, 32 insertions(+), 22 deletions(-) rename PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/{DataCollectionTask.java => ReactDataTask.java} (79%) diff --git a/Plan/dependency-reduced-pom.xml b/Plan/dependency-reduced-pom.xml index 2beea636f..454cd29ef 100644 --- a/Plan/dependency-reduced-pom.xml +++ b/Plan/dependency-reduced-pom.xml @@ -71,20 +71,20 @@ org.apache.logging.* - - com.maxmind - plan.com.maxmind - - org.apache.logging.* - - - - com.fasterxml - plan.com.fasterxml - - org.apache.logging.* - - + + com.maxmind + plan.com.maxmind + + org.apache.logging.* + + + + com.fasterxml + plan.com.fasterxml + + org.apache.logging.* + + 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 076bdbdb3..b244e5b05 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/Bridge.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/Bridge.java @@ -17,8 +17,8 @@ import com.djrapitops.pluginbridge.plan.jobs.JobsHook; import com.djrapitops.pluginbridge.plan.kingdoms.KingdomsHook; import com.djrapitops.pluginbridge.plan.litebans.LiteBansHook; import com.djrapitops.pluginbridge.plan.mcmmo.McmmoHook; -import com.djrapitops.pluginbridge.plan.placeholderapi.PlaceholderAPIHook; import com.djrapitops.pluginbridge.plan.protocolsupport.ProtocolSupportHook; +import com.djrapitops.pluginbridge.plan.react.ReactHook; import com.djrapitops.pluginbridge.plan.redprotect.RedProtectHook; import com.djrapitops.pluginbridge.plan.superbvote.SuperbVoteHook; import com.djrapitops.pluginbridge.plan.towny.TownyHook; @@ -85,6 +85,7 @@ public class Bridge { new McmmoHook(h), new SuperbVoteHook(h), new ProtocolSupportHook(h), + new ReactHook(h), new RedProtectHook(h), new TownyHook(h), new VaultHook(h), diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/DataCollectionTask.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ReactDataTask.java similarity index 79% rename from PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/DataCollectionTask.java rename to PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ReactDataTask.java index f85655e0a..7510e0c88 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/DataCollectionTask.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ReactDataTask.java @@ -2,6 +2,7 @@ package com.djrapitops.pluginbridge.plan.react; import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plugin.api.TimeAmount; +import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.task.AbsRunnable; import com.volmit.react.React; import com.volmit.react.api.GraphSampleLine; @@ -19,7 +20,7 @@ import java.util.Map; * * @author Rsl1122 */ -public class DataCollectionTask extends AbsRunnable { +public class ReactDataTask extends AbsRunnable { private static final SampledType[] STORED_TYPES = new SampledType[]{ SampledType.ENT, @@ -44,23 +45,31 @@ public class DataCollectionTask extends AbsRunnable { private final ReactDataTable table; private final Map> history; - public DataCollectionTask(ReactDataTable table) { - super(DataCollectionTask.class.getSimpleName()); + public ReactDataTask(ReactDataTable table) { + super(ReactDataTask.class.getSimpleName()); this.table = table; history = new EnumMap<>(SampledType.class); } @Override public void run() { - GMap samplers = React.instance.graphController.getG(); + try { + GMap samplers = React.instance.graphController.getG(); - for (SampledType type : STORED_TYPES) { - processType(samplers, type); + for (SampledType type : STORED_TYPES) { + processType(samplers, type); + } + } catch (Exception e) { + Log.toLog(this.getClass(), e); + cancel(); } } private void processType(GMap samplers, SampledType type) { GMap values = samplers.get(type).getPlotBoard().getBetween(M.ms() - 10000, M.ms()); + if (values.isEmpty()) { + return; + } List storedValues = history.getOrDefault(type, new ArrayList<>()); values.entrySet().stream() .map(entry -> new ReactValue(type, entry.getKey(), entry.getValue())) diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ReactHook.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ReactHook.java index 820c43141..46baa2f63 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ReactHook.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/react/ReactHook.java @@ -43,7 +43,7 @@ public class ReactHook extends Hook { table.createTable(); table.clean(); - ITask task = RunnableFactory.createNew(new DataCollectionTask(table)) + ITask task = RunnableFactory.createNew(new ReactDataTask(table)) .runTaskTimerAsynchronously(TimeAmount.SECOND.ticks() * 10L, TimeAmount.SECOND.ticks() * 10L); setTask(task); }