-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add new data Request Handler for Level add-on, which requires world-name in input and returns: - empty map, if input is invalid - LinkedHashMap from TopTenData object for given world.
- Loading branch information
1 parent
ddbe806
commit e011c2e
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/world/bentobox/level/requests/TopTenRequestHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package world.bentobox.level.requests; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import org.bukkit.Bukkit; | ||
|
||
import world.bentobox.bentobox.api.addons.request.AddonRequestHandler; | ||
import world.bentobox.level.Level; | ||
import world.bentobox.level.objects.TopTenData; | ||
|
||
|
||
/** | ||
* This Request Handler allows other plugins to get access to top 10 player list per particular world. | ||
* Handler returns linked hashmap from TopTenData for particular world. | ||
*/ | ||
public class TopTenRequestHandler extends AddonRequestHandler { | ||
|
||
/** | ||
* The level addon field. | ||
*/ | ||
private Level addon; | ||
|
||
/** | ||
* This constructor creates a new TopTenRequestHandler instance. | ||
* | ||
* @param addon of type Level | ||
*/ | ||
public TopTenRequestHandler(Level addon) { | ||
super("top-ten-level"); | ||
this.addon = addon; | ||
} | ||
|
||
/** | ||
* @see AddonRequestHandler#handle(Map<String, Object>) | ||
*/ | ||
@Override | ||
public Object handle(Map<String, Object> map) { | ||
/* | ||
What we need in the map: | ||
"world-name" -> String | ||
What we will return: | ||
- Empty map if invalid input | ||
- the map of top ten player UUIDs and their island levels. Can be less then 10. | ||
*/ | ||
|
||
if (map == null || map.isEmpty() | ||
|| map.get("world-name") == null || !(map.get("world-name") instanceof String) | ||
|| Bukkit.getWorld((String) map.get("world-name")) == null) { | ||
return Collections.emptyMap(); | ||
} | ||
|
||
// Null-point check. | ||
TopTenData data = addon.getTopTen().getTopTenList(Bukkit.getWorld((String) map.get("world-name"))); | ||
return data != null ? data.getTopTen() : Collections.emptyMap(); | ||
} | ||
} |