From 5eea419746b201847c7c7816a8a9c4f7d99dcd54 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 25 Nov 2018 22:29:45 -0800 Subject: [PATCH] Uses a trial generic event to expose add-on data as K,V pairs. --- pom.xml | 2 +- .../level/calculators/CalcIslandLevel.java | 13 ++++++++++++- .../bentobox/level/calculators/PlayerLevel.java | 14 ++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 947ea8a..f6b9331 100644 --- a/pom.xml +++ b/pom.xml @@ -86,7 +86,7 @@ world.bentobox bentobox - 0.12.0-SNAPSHOT + 0.15.0-SNAPSHOT provided diff --git a/src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java b/src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java index 179e0e1..b6bc97e 100644 --- a/src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java +++ b/src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java @@ -19,10 +19,10 @@ import com.google.common.collect.Multiset; import com.google.common.collect.Multiset.Entry; import com.google.common.collect.Multisets; -import world.bentobox.level.Level; import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.util.Pair; import world.bentobox.bentobox.util.Util; +import world.bentobox.level.Level; public class CalcIslandLevel { @@ -345,5 +345,16 @@ public class CalcIslandLevel { return pointsToNextLevel; } + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "Results [report=" + report + ", mdCount=" + mdCount + ", uwCount=" + uwCount + ", ncCount=" + + ncCount + ", ofCount=" + ofCount + ", rawBlockCount=" + rawBlockCount + ", underWaterBlockCount=" + + underWaterBlockCount + ", level=" + level + ", deathHandicap=" + deathHandicap + + ", pointsToNextLevel=" + pointsToNextLevel + "]"; + } + } } diff --git a/src/main/java/world/bentobox/level/calculators/PlayerLevel.java b/src/main/java/world/bentobox/level/calculators/PlayerLevel.java index a874e8a..f86d13c 100644 --- a/src/main/java/world/bentobox/level/calculators/PlayerLevel.java +++ b/src/main/java/world/bentobox/level/calculators/PlayerLevel.java @@ -1,15 +1,18 @@ package world.bentobox.level.calculators; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; import org.bukkit.World; +import world.bentobox.bentobox.api.events.addon.AddonEvent; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.bentobox.database.objects.Island; import world.bentobox.level.Level; import world.bentobox.level.calculators.CalcIslandLevel.Results; import world.bentobox.level.event.IslandLevelCalculatedEvent; import world.bentobox.level.event.IslandPreLevelEvent; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.database.objects.Island; /** @@ -53,6 +56,13 @@ public class PlayerLevel { // Fire post calculation event IslandLevelCalculatedEvent ilce = new IslandLevelCalculatedEvent(targetPlayer, island, calc.getResult()); addon.getServer().getPluginManager().callEvent(ilce); + Map keyValues = new HashMap<>(); + keyValues.put("targetPlayer", targetPlayer); + keyValues.put("islandUUID", island.getUniqueId()); + keyValues.put("level", calc.getResult().getLevel()); + keyValues.put("pointsToNextLevel", calc.getResult().getPointsToNextLevel()); + keyValues.put("deathHandicap", calc.getResult().getDeathHandicap()); + addon.getServer().getPluginManager().callEvent(new AddonEvent().builder().addon(addon).keyValues(keyValues).build()); Results results = ilce.getResults(); // Save the results island.getMemberSet().forEach(m -> addon.setIslandLevel(world, m, results.getLevel()));