mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2024-11-30 14:03:27 +01:00
Added LevelRequestHandler (island-level)
This commit is contained in:
parent
456e278d11
commit
b7aec5b0eb
@ -19,6 +19,7 @@ import world.bentobox.bentobox.api.commands.CompositeCommand;
|
|||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.Database;
|
import world.bentobox.bentobox.database.Database;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
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
|
* 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
|
// Register new island listener
|
||||||
registerListener(new NewIslandListener(this));
|
registerListener(new NewIslandListener(this));
|
||||||
registerListener(new JoinLeaveListener(this));
|
registerListener(new JoinLeaveListener(this));
|
||||||
|
|
||||||
|
// Register request handlers
|
||||||
|
registerRequestHandler(new LevelRequestHandler(this));
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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"));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user