mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-11-25 03:55:10 +01:00
Create WorldSaveEvent listener that stores challenges, when event occur.
Partial fix of issue #21.
This commit is contained in:
parent
cb046894b5
commit
4edc1c5c62
@ -5,6 +5,7 @@ import org.bukkit.Bukkit;
|
|||||||
import bentobox.addon.challenges.commands.ChallengesCommand;
|
import bentobox.addon.challenges.commands.ChallengesCommand;
|
||||||
import bentobox.addon.challenges.commands.admin.Challenges;
|
import bentobox.addon.challenges.commands.admin.Challenges;
|
||||||
import bentobox.addon.challenges.listeners.ResetListener;
|
import bentobox.addon.challenges.listeners.ResetListener;
|
||||||
|
import bentobox.addon.challenges.listeners.SaveListener;
|
||||||
import world.bentobox.bentobox.api.addons.Addon;
|
import world.bentobox.bentobox.api.addons.Addon;
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
|
|
||||||
@ -73,6 +74,8 @@ public class ChallengesAddon extends Addon {
|
|||||||
}
|
}
|
||||||
// Register the reset listener
|
// Register the reset listener
|
||||||
this.registerListener(new ResetListener(this));
|
this.registerListener(new ResetListener(this));
|
||||||
|
// Register the autosave listener.
|
||||||
|
this.registerListener(new SaveListener(this));
|
||||||
// Done
|
// Done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
package bentobox.addon.challenges.listeners;
|
||||||
|
|
||||||
|
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.world.WorldSaveEvent;
|
||||||
|
|
||||||
|
import bentobox.addon.challenges.ChallengesAddon;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is Simple World Save event listener. On each world save, this method
|
||||||
|
* asks challenge manager to save its data.
|
||||||
|
*/
|
||||||
|
public class SaveListener implements Listener
|
||||||
|
{
|
||||||
|
public SaveListener(ChallengesAddon addon) {
|
||||||
|
this.addon = addon;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
|
public void onWorldSave(WorldSaveEvent e)
|
||||||
|
{
|
||||||
|
this.addon.getChallengesManager().save(e.isAsynchronous());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
// Section: Variables
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
private ChallengesAddon addon;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user