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.
This commit is contained in:
BONNe 2021-09-24 11:14:07 +03:00
parent 41d574a859
commit adf4e7c58b
1 changed files with 69 additions and 18 deletions

View File

@ -1,6 +1,3 @@
/**
*
*/
package world.bentobox.challenges.listeners;
import org.bukkit.event.EventHandler;
@ -10,22 +7,18 @@ 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
*
* @author tastybento
*/
public class ResetListener implements Listener {
private ChallengesAddon addon;
public ResetListener(ChallengesAddon addon) {
this.addon = addon;
}
public record ResetListener(ChallengesAddon addon) implements Listener
{
/**
* This method handles Island Created event.
*
@ -34,7 +27,13 @@ public class ResetListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onIslandCreated(IslandCreatedEvent e)
{
addon.getChallengesManager().resetAllChallenges(e.getOwner(), e.getLocation().getWorld(), e.getOwner());
// 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());
}
}
@ -44,9 +43,16 @@ public class ResetListener implements Listener {
* @param e Event that must be handled.
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onIslandCreated(IslandResettedEvent e)
public void onIslandResetted(IslandResettedEvent 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());
}
}
@ -56,8 +62,53 @@ public class ResetListener implements Listener {
* @param e Event that must be handled.
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onIslandCreated(IslandRegisteredEvent 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 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());
}
}
}