Added LevelRequestHandler (island-level)

This commit is contained in:
Florian CUNY 2018-12-23 21:20:15 +01:00
parent 456e278d11
commit b7aec5b0eb
2 changed files with 47 additions and 0 deletions

View File

@ -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
}

View File

@ -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<String, Object> 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"));
}
}