mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-09-25 13:12:57 +02:00
7fbffbb6d2
Most of the errors are just sanity checks, as the most of null-pointers were already checked in other ways.
75 lines
1.9 KiB
Java
75 lines
1.9 KiB
Java
package world.bentobox.challenges.handlers;
|
|
|
|
|
|
import java.util.Collections;
|
|
import java.util.Map;
|
|
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.World;
|
|
|
|
import world.bentobox.bentobox.api.addons.request.AddonRequestHandler;
|
|
import world.bentobox.challenges.ChallengesAddon;
|
|
|
|
|
|
/**
|
|
* This handler returns all challenges that is operating in given world.
|
|
*/
|
|
public class ChallengeListRequestHandler extends AddonRequestHandler
|
|
{
|
|
/**
|
|
* Constructor creates a new CompletedChallengesRequestHandler instance.
|
|
*
|
|
* @param addon of type ChallengesAddon
|
|
*/
|
|
public ChallengeListRequestHandler(ChallengesAddon addon)
|
|
{
|
|
super("challenge-list");
|
|
this.addon = addon;
|
|
}
|
|
|
|
|
|
/* (non-Javadoc)
|
|
* @see world.bentobox.bentobox.api.addons.request.AddonRequestHandler#handle(java.util.Map)
|
|
* @param metaData Required meta data.
|
|
* @return Set of strings that contains completed challenges.
|
|
*/
|
|
@Override
|
|
public Object handle(Map<String, Object> metaData)
|
|
{
|
|
/*
|
|
What we need in the metaData:
|
|
0. "world-name" -> String
|
|
What we will return:
|
|
- List of challenges in given world.
|
|
*/
|
|
|
|
if (metaData == null ||
|
|
metaData.isEmpty() ||
|
|
metaData.get("world-name") == null ||
|
|
!(metaData.get("world-name") instanceof String))
|
|
{
|
|
return Collections.emptyList();
|
|
}
|
|
|
|
World world = Bukkit.getWorld((String) metaData.get("world-name"));
|
|
|
|
if (world == null)
|
|
{
|
|
return Collections.emptyList();
|
|
}
|
|
|
|
return this.addon.getChallengesManager().getAllChallengesNames(world);
|
|
}
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
// Section: Variables
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
/**
|
|
* Variable stores challenges addon.
|
|
*/
|
|
private final ChallengesAddon addon;
|
|
}
|