Skip to content

Commit

Permalink
Fixes #253
Browse files Browse the repository at this point in the history
Adds TeamKick and TeamLeave events to the reset check.
Do not reset challenges if data is stored per island. As in that case, they will already lose their data.
  • Loading branch information
BONNe committed Sep 24, 2021
1 parent 41d574a commit adf4e7c
Showing 1 changed file with 67 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
*
*/
package world.bentobox.challenges.listeners;

import org.bukkit.event.EventHandler;
Expand All @@ -10,43 +7,90 @@
import world.bentobox.bentobox.api.events.island.IslandCreatedEvent;
import world.bentobox.bentobox.api.events.island.IslandRegisteredEvent;
import world.bentobox.bentobox.api.events.island.IslandResettedEvent;
import world.bentobox.bentobox.api.events.team.TeamKickEvent;
import world.bentobox.bentobox.api.events.team.TeamLeaveEvent;
import world.bentobox.challenges.ChallengesAddon;


/**
* Resets challenges when the island is reset
* @author tastybento
*
* @author tastybento
*/
public class ResetListener implements Listener {
public record ResetListener(ChallengesAddon addon) implements Listener
{
/**
* This method handles Island Created event.
*
* @param e Event that must be handled.
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onIslandCreated(IslandCreatedEvent e)
{
// Reset any challenges that can be assigned to the island or its owner.
if (this.addon.getChallengesSettings().isResetChallenges())
{
this.addon.getChallengesManager().resetAllChallenges(e.getOwner(),
e.getLocation().getWorld(),
e.getOwner());
}
}

private ChallengesAddon addon;

public ResetListener(ChallengesAddon addon) {
this.addon = addon;
/**
* This method handles Island Resetted event.
*
* @param e Event that must be handled.
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onIslandResetted(IslandResettedEvent e)
{
// Reset owner challenges only if data is stored per player.
if (this.addon.getChallengesSettings().isResetChallenges() &&
!this.addon.getChallengesSettings().isStoreAsIslandData())
{
this.addon.getChallengesManager().resetAllChallenges(e.getOwner(),
e.getLocation().getWorld(),
e.getOwner());
}
}


/**
* This method handles Island Created event.
* This method handles Island Registered event.
*
* @param e Event that must be handled.
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onIslandCreated(IslandCreatedEvent e)
public void onIslandRegistered(IslandRegisteredEvent e)
{
addon.getChallengesManager().resetAllChallenges(e.getOwner(), e.getLocation().getWorld(), e.getOwner());
// Reset owner challenges only if data is stored per player.
if (this.addon.getChallengesSettings().isResetChallenges() &&
!this.addon.getChallengesSettings().isStoreAsIslandData())
{
this.addon.getChallengesManager().resetAllChallenges(e.getOwner(),
e.getLocation().getWorld(),
e.getOwner());
}
}


/**
* This method handles Island Resetted event.
* This method handles Island Registered event.
*
* @param e Event that must be handled.
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onIslandCreated(IslandResettedEvent e)
public void onTeamLeave(TeamLeaveEvent e)
{
addon.getChallengesManager().resetAllChallenges(e.getOwner(), e.getLocation().getWorld(), e.getOwner());
// Reset player challenges only if data is stored per player.
if (this.addon.getChallengesSettings().isResetChallenges() &&
!this.addon.getChallengesSettings().isStoreAsIslandData())
{
this.addon.getChallengesManager().resetAllChallenges(e.getPlayerUUID(),
e.getLocation().getWorld(),
e.getOwner());
}
}


Expand All @@ -56,8 +100,15 @@ public void onIslandCreated(IslandResettedEvent e)
* @param e Event that must be handled.
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onIslandCreated(IslandRegisteredEvent e)
public void onTeamKick(TeamKickEvent e)
{
addon.getChallengesManager().resetAllChallenges(e.getOwner(), e.getLocation().getWorld(), e.getOwner());
// Reset player challenges only if data is stored per player.
if (this.addon.getChallengesSettings().isResetChallenges() &&
!this.addon.getChallengesSettings().isStoreAsIslandData())
{
this.addon.getChallengesManager().resetAllChallenges(e.getPlayerUUID(),
e.getLocation().getWorld(),
e.getOwner());
}
}
}

0 comments on commit adf4e7c

Please sign in to comment.