Uses a trial generic event to expose add-on data as K,V pairs.

This commit is contained in:
tastybento 2018-11-25 22:29:45 -08:00
parent 413887d31f
commit 5eea419746
3 changed files with 25 additions and 4 deletions

View File

@ -86,7 +86,7 @@
<dependency> <dependency>
<groupId>world.bentobox</groupId> <groupId>world.bentobox</groupId>
<artifactId>bentobox</artifactId> <artifactId>bentobox</artifactId>
<version>0.12.0-SNAPSHOT</version> <version>0.15.0-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -19,10 +19,10 @@ import com.google.common.collect.Multiset;
import com.google.common.collect.Multiset.Entry; import com.google.common.collect.Multiset.Entry;
import com.google.common.collect.Multisets; import com.google.common.collect.Multisets;
import world.bentobox.level.Level;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.util.Pair; import world.bentobox.bentobox.util.Pair;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
import world.bentobox.level.Level;
public class CalcIslandLevel { public class CalcIslandLevel {
@ -345,5 +345,16 @@ public class CalcIslandLevel {
return pointsToNextLevel; 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 + "]";
}
} }
} }

View File

@ -1,15 +1,18 @@
package world.bentobox.level.calculators; package world.bentobox.level.calculators;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.bukkit.World; 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.Level;
import world.bentobox.level.calculators.CalcIslandLevel.Results; import world.bentobox.level.calculators.CalcIslandLevel.Results;
import world.bentobox.level.event.IslandLevelCalculatedEvent; import world.bentobox.level.event.IslandLevelCalculatedEvent;
import world.bentobox.level.event.IslandPreLevelEvent; 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 // Fire post calculation event
IslandLevelCalculatedEvent ilce = new IslandLevelCalculatedEvent(targetPlayer, island, calc.getResult()); IslandLevelCalculatedEvent ilce = new IslandLevelCalculatedEvent(targetPlayer, island, calc.getResult());
addon.getServer().getPluginManager().callEvent(ilce); addon.getServer().getPluginManager().callEvent(ilce);
Map<String, Object> 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(); Results results = ilce.getResults();
// Save the results // Save the results
island.getMemberSet().forEach(m -> addon.setIslandLevel(world, m, results.getLevel())); island.getMemberSet().forEach(m -> addon.setIslandLevel(world, m, results.getLevel()));