From b7aec5b0eb9b224482492aadbe6232b02f15aa2d Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Sun, 23 Dec 2018 21:20:15 +0100 Subject: [PATCH] Added LevelRequestHandler (island-level) --- src/main/java/world/bentobox/level/Level.java | 5 +++ .../level/requests/LevelRequestHandler.java | 42 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/main/java/world/bentobox/level/requests/LevelRequestHandler.java diff --git a/src/main/java/world/bentobox/level/Level.java b/src/main/java/world/bentobox/level/Level.java index 50103b7..b8e3240 100644 --- a/src/main/java/world/bentobox/level/Level.java +++ b/src/main/java/world/bentobox/level/Level.java @@ -19,6 +19,7 @@ import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.database.Database; import world.bentobox.bentobox.database.objects.Island; +import world.bentobox.level.requests.LevelRequestHandler; /** * Addon to BSkyBlock/AcidIsland that enables island level scoring and top ten functionality @@ -140,6 +141,10 @@ public class Level extends Addon { // Register new island listener registerListener(new NewIslandListener(this)); registerListener(new JoinLeaveListener(this)); + + // Register request handlers + registerRequestHandler(new LevelRequestHandler(this)); + // Done } diff --git a/src/main/java/world/bentobox/level/requests/LevelRequestHandler.java b/src/main/java/world/bentobox/level/requests/LevelRequestHandler.java new file mode 100644 index 0000000..7626050 --- /dev/null +++ b/src/main/java/world/bentobox/level/requests/LevelRequestHandler.java @@ -0,0 +1,42 @@ +package world.bentobox.level.requests; + +import org.bukkit.Bukkit; +import world.bentobox.bentobox.api.addons.request.AddonRequestHandler; +import world.bentobox.level.Level; + +import java.util.Map; +import java.util.UUID; + +public class LevelRequestHandler extends AddonRequestHandler { + + private Level addon; + + public LevelRequestHandler(Level addon) { + super("island-level"); + this.addon = addon; + } + + @Override + public Object handle(Map map) { + /* + What we need in the map: + + 0. "world-name" -> String + 1. "player" -> UUID + + What we will return: + + - 0L if invalid input/player has no island + - the island level otherwise (which may be 0) + */ + + if (map == null || map.isEmpty() + || map.get("world-name") == null || !(map.get("world-name") instanceof String) + || map.get("player") == null || !(map.get("player") instanceof UUID) + || Bukkit.getWorld((String) map.get("world-name")) == null) { + return 0L; + } + + return addon.getIslandLevel(Bukkit.getWorld((String) map.get("world-name")), (UUID) map.get("player")); + } +}