Skip to content

Commit

Permalink
Uses a trial generic event to expose add-on data as K,V pairs.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Nov 26, 2018
1 parent 413887d commit 5eea419
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<dependency>
<groupId>world.bentobox</groupId>
<artifactId>bentobox</artifactId>
<version>0.12.0-SNAPSHOT</version>
<version>0.15.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
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 {
Expand Down Expand Up @@ -345,5 +345,16 @@ public long getPointsToNextLevel() {
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 + "]";
}

}
}
14 changes: 12 additions & 2 deletions src/main/java/world/bentobox/level/calculators/PlayerLevel.java
Original file line number Diff line number Diff line change
@@ -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;


/**
Expand Down Expand Up @@ -53,6 +56,13 @@ private void fireIslandLevelCalcEvent() {
// Fire post calculation event
IslandLevelCalculatedEvent ilce = new IslandLevelCalculatedEvent(targetPlayer, island, calc.getResult());
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();
// Save the results
island.getMemberSet().forEach(m -> addon.setIslandLevel(world, m, results.getLevel()));
Expand Down

0 comments on commit 5eea419

Please sign in to comment.