From 4a735345700a2a66152bd84ef687b57b129e18d3 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Wed, 2 Jan 2019 11:11:31 +0200 Subject: [PATCH] Implement TeamJoinDeathReset. Add TeamJoinEvent listener that checks if TeamJoinDeathReset is enabled and resets player death count. --- .../level/listeners/NewIslandListener.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/world/bentobox/level/listeners/NewIslandListener.java b/src/main/java/world/bentobox/level/listeners/NewIslandListener.java index 10b69f2..0ded09c 100644 --- a/src/main/java/world/bentobox/level/listeners/NewIslandListener.java +++ b/src/main/java/world/bentobox/level/listeners/NewIslandListener.java @@ -9,6 +9,7 @@ import org.bukkit.event.Listener; import world.bentobox.bentobox.api.events.island.IslandEvent.IslandCreatedEvent; import world.bentobox.bentobox.api.events.island.IslandEvent.IslandResettedEvent; +import world.bentobox.bentobox.api.events.team.TeamEvent.TeamJoinEvent; import world.bentobox.bentobox.database.objects.Island; import world.bentobox.level.Level; import world.bentobox.level.calculators.CalcIslandLevel; @@ -47,6 +48,24 @@ public class NewIslandListener implements Listener { } } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onTeamJoin(TeamJoinEvent event) + { + if (this.addon.getSettings().isTeamJoinDeathReset()) + { + this.cil.putIfAbsent(event.getIsland(), + new CalcIslandLevel(this.addon, + event.getIsland(), + () -> zeroLevel(event.getIsland()))); + + this.addon.getPlayers().setDeaths(event.getIsland().getWorld(), + event.getOwner(), + 0); + } + } + + private void zeroLevel(Island island) { if (cil.containsKey(island)) { addon.setInitialIslandLevel(island, cil.get(island).getResult().getLevel());