Challenges/src/main/java/world/bentobox/challenges/listeners/ResetListener.java
BONNe adf4e7c58b Fixes #253
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.
2021-09-24 11:14:07 +03:00

115 lines
3.8 KiB
Java

package world.bentobox.challenges.listeners;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
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
*/
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());
}
}
/**
* 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 Registered event.
*
* @param e Event that must be handled.
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onIslandRegistered(IslandRegisteredEvent 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 Registered event.
*
* @param e Event that must be handled.
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onTeamLeave(TeamLeaveEvent e)
{
// 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());
}
}
/**
* This method handles Island Registered event.
*
* @param e Event that must be handled.
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onTeamKick(TeamKickEvent e)
{
// 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());
}
}
}