WIP added some admin commands. Still not finished.

Get rank, set rank, info.
This commit is contained in:
Tastybento 2018-05-02 21:23:02 -07:00
parent 0eae384b97
commit 0a17639529
8 changed files with 281 additions and 7 deletions

View File

@ -49,6 +49,26 @@ commands:
admin:
help:
description: "admin command"
info:
parameters: "<player>"
description: "get info on where you are or player's island"
no-island: "&cYou are not in an island right now..."
title: "========== Island Info ============"
owner: "Owner: [owner] ([uuid])"
last-login: "Last login: [date]"
deaths: "Deaths: [number]"
resets-left: "Resets left: [number]/[total]"
team-members-title: "Team members:"
owner-suffix: "(Owner)"
player-prefix: "&b"
island-location: "Island location: [xyz]"
island-coords: "Island coordinates: [xz1] to [xz2]"
protection-range: "Protection range: [range]"
protection-coords: "Protection coordinates: [xz1] to [xz2]"
is-spawn: "Island is a spawn island"
is-locked: "Island is locked"
is-unlocked: "Island is unlocked"
banned-players: "Banned players:"
version:
description: "display %bsb_plugin_name% and addons versions"
setrange:
@ -61,6 +81,15 @@ commands:
parameters: "[player]"
description: "teleport to a player's island"
manual: "&cNo safe warp found! Manually tp near to &b[location] &cand check it out"
getrank:
parameters: "[player]"
description: "get a player's rank on their island"
rank-is: "&aRank is [rank] on their island."
setrank:
parameters: "[player] [rank]"
description: "set a player's rank on their island"
unknown-rank: "&cUnknown rank!"
rank-set: "&aRank set from [from] to [to]."
island:
about:
description: "display info about %bsb_plugin_name%"
@ -188,6 +217,8 @@ ranks:
coop: "Coop"
visitor: "Visitor"
banned: "Banned"
admin: "Admin"
mod: "Mod"
protection:
protected: "&cIsland protected!"

View File

@ -5,7 +5,10 @@ import java.util.List;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.commands.admin.AdminGetRankCommand;
import us.tastybento.bskyblock.commands.admin.AdminInfoCommand;
import us.tastybento.bskyblock.commands.admin.AdminReloadCommand;
import us.tastybento.bskyblock.commands.admin.AdminSetRankCommand;
import us.tastybento.bskyblock.commands.admin.AdminTeleportCommand;
import us.tastybento.bskyblock.commands.admin.AdminVersionCommand;
@ -26,6 +29,9 @@ public class AdminCommand extends CompositeCommand {
new AdminTeleportCommand(this, "tp");
new AdminTeleportCommand(this, "tpnether");
new AdminTeleportCommand(this, "tpend");
new AdminGetRankCommand(this);
new AdminSetRankCommand(this);
new AdminInfoCommand(this);
}
@Override

View File

@ -0,0 +1,75 @@
/**
*
*/
package us.tastybento.bskyblock.commands.admin;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.managers.RanksManager;
/**
* @author tastybento
*
*/
public class AdminGetRankCommand extends CompositeCommand {
public AdminGetRankCommand(CompositeCommand adminCommand) {
super(adminCommand, "getrank");
}
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.BSBCommand#setup()
*/
@Override
public void setup() {
setPermission(Constants.PERMPREFIX + "admin.setrank");
setOnlyPlayer(false);
setParameters("commands.admin.getrank.parameters");
setDescription("commands.admin.getrank.description");
}
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.BSBCommand#execute(us.tastybento.bskyblock.api.user.User, java.util.List)
*/
@Override
public boolean execute(User user, List<String> args) {
if (args.size() != 1) {
// Show help
showHelp(this, user);
return false;
}
// Get target player
UUID targetUUID = getPlayers().getUUID(args.get(0));
if (targetUUID == null) {
user.sendMessage("general.errors.unknown-player");
return false;
}
if (!getPlugin().getIslands().hasIsland(targetUUID)) {
user.sendMessage("general.errors.player-has-no-island");
return false;
}
// Get rank
RanksManager rm = getPlugin().getRanksManager();
User target = User.getInstance(targetUUID);
Island island = getPlugin().getIslands().getIsland(targetUUID);
int currentRank = island.getRank(target);
user.sendMessage("commands.admin.getrank.rank-is", "[rank]", user.getTranslation(rm.getRank(currentRank)));
return true;
}
@Override
public Optional<List<String>> tabComplete(final User user, final String alias, final LinkedList<String> args) {
return Optional.of(Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()));
}
}

View File

@ -1,4 +1,52 @@
package us.tastybento.bskyblock.commands.admin;
public class AdminInfoCommand {
import java.util.List;
import java.util.UUID;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User;
public class AdminInfoCommand extends CompositeCommand {
public AdminInfoCommand(CompositeCommand parent) {
super(parent, "info");
}
@Override
public void setup() {
setPermission(Constants.PERMPREFIX + "admin.info");
setOnlyPlayer(false);
setParameters("commands.admin.info.parameters");
setDescription("commands.admin.info.description");
}
@Override
public boolean execute(User user, List<String> args) {
if (args.size() > 1 || (args.isEmpty() && !user.isPlayer())) {
// Show help
showHelp(this, user);
return false;
}
if (args.isEmpty()) {
if (!getIslands().getIslandAt(user.getLocation()).map(i -> i.showInfo(getPlugin(), user)).orElse(false)) {
user.sendMessage("commands.admin.info.no-island");
return false;
}
return true;
}
// Get target player
UUID targetUUID = getPlayers().getUUID(args.get(0));
if (targetUUID == null) {
user.sendMessage("general.errors.unknown-player");
return false;
}
if (!getPlugin().getIslands().hasIsland(targetUUID)) {
user.sendMessage("general.errors.player-has-no-island");
return false;
}
// Get rank
getPlugin().getIslands().getIsland(targetUUID).showInfo(getPlugin(), user);
return true;
}
}

View File

@ -0,0 +1,81 @@
/**
*
*/
package us.tastybento.bskyblock.commands.admin;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.managers.RanksManager;
/**
* @author tastybento
*
*/
public class AdminSetRankCommand extends CompositeCommand {
public AdminSetRankCommand(CompositeCommand adminCommand) {
super(adminCommand, "setrank");
}
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.BSBCommand#setup()
*/
@Override
public void setup() {
setPermission(Constants.PERMPREFIX + "admin.setrank");
setOnlyPlayer(false);
setParameters("commands.admin.setrank.parameters");
setDescription("commands.admin.setrank.description");
}
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.BSBCommand#execute(us.tastybento.bskyblock.api.user.User, java.util.List)
*/
@Override
public boolean execute(User user, List<String> args) {
if (args.size() != 2) {
// Show help
showHelp(this, user);
return false;
}
// Get target player
UUID targetUUID = getPlayers().getUUID(args.get(0));
if (targetUUID == null) {
user.sendMessage("general.errors.unknown-player");
return false;
}
if (!getPlugin().getIslands().hasIsland(targetUUID)) {
user.sendMessage("general.errors.player-has-no-island");
return false;
}
// Get rank
RanksManager rm = getPlugin().getRanksManager();
int rankValue = rm.getRanks().entrySet().stream()
.filter(r -> user.getTranslation(r.getKey()).equalsIgnoreCase(args.get(1))).findFirst()
.map(r -> r.getValue()).orElse(-999);
if (rankValue < RanksManager.BANNED_RANK) {
user.sendMessage("commands.admin.setrank.unknown-rank");
return false;
}
User target = User.getInstance(targetUUID);
Island island = getPlugin().getIslands().getIsland(targetUUID);
int currentRank = island.getRank(target);
island.setRank(target, rankValue);
user.sendMessage("commands.admin.setrank.rank-set", "[from]", user.getTranslation(rm.getRank(currentRank)), "[to]", user.getTranslation(rm.getRank(rankValue)));
return true;
}
@Override
public Optional<List<String>> tabComplete(final User user, final String alias, final LinkedList<String> args) {
return Optional.of(getPlugin().getRanksManager().getRanks().keySet().stream().map(user::getTranslation).collect(Collectors.toList()));
}
}

View File

@ -36,7 +36,7 @@ public class IslandBanCommand extends CompositeCommand {
// Show help
showHelp(this, user);
return false;
}
}
UUID playerUUID = user.getUniqueId();
// Player issuing the command must have an island
if (!getIslands().hasIsland(playerUUID)) {

View File

@ -1,4 +0,0 @@
package us.tastybento.bskyblock.commands.island;
public class IslandLockCommand {
}

View File

@ -1,5 +1,6 @@
package us.tastybento.bskyblock.database.objects;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@ -12,6 +13,7 @@ import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.util.Vector;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
@ -376,7 +378,7 @@ public class Island implements DataObject {
* @return true if in the island space
*/
public boolean inIslandSpace(int x, int z) {
return x >= minX && x < minX + range*2 && z >= minZ && z < minZ + range*2;
return x >= minX && x < minX + range*2 && z >= minZ && z < minZ + range*2;
}
public boolean inIslandSpace(Location location) {
@ -641,4 +643,39 @@ public class Island implements DataObject {
public void setWorld(World world) {
this.world = world;
}
/**
* Show info on the island
* @param plugin
* @param user - the user who is receiving the info
* @return true always
*/
public boolean showInfo(BSkyBlock plugin, User user) {
// TODO show ranks
user.sendMessage("commands.admin.info.title");
user.sendMessage("commands.admin.info.owner", "[owner]", plugin.getPlayers().getName(owner), "[uuid]", owner.toString());
Date d = new Date(plugin.getServer().getOfflinePlayer(owner).getLastPlayed());
user.sendMessage("commands.admin.info.last-login","[date]", d.toString());
user.sendMessage("commands.admin.info.deaths", "[number]", String.valueOf(plugin.getPlayers().getDeaths(owner)));
String resets = String.valueOf(plugin.getPlayers().getResetsLeft(owner));
String total = plugin.getSettings().getResetLimit() < 0 ? "Unlimited" : String.valueOf(plugin.getSettings().getResetLimit());
user.sendMessage("commands.admin.info.resets-left", "[number]", resets, "[total]", total);
user.sendMessage("commands.admin.info.team-members-title");
user.sendMessage("commands.admin.info.owner-suffix");
user.sendMessage("commands.admin.info.player-prefix");
String location = center.toVector().toString();
user.sendMessage("commands.admin.info.island-location", "[xyz]", location);
String from = center.toVector().subtract(new Vector(range, 0, range)).toString();
String to = center.toVector().add(new Vector(range, 0, range)).toString();
user.sendMessage("commands.admin.info.island-coords", "[xz1]", from, "[xz2]", to);
user.sendMessage("commands.admin.info.protection-range", "[range]", String.valueOf(range));
String pfrom = center.toVector().subtract(new Vector(protectionRange, 0, protectionRange)).toString();
String pto = center.toVector().add(new Vector(protectionRange, 0, protectionRange)).toString();
user.sendMessage("commands.admin.info.protection-coords", "[xz1]", pfrom, "[xz2]", pto);
user.sendMessage("commands.admin.info.is-spawn");
user.sendMessage("commands.admin.info.is-locked");
user.sendMessage("commands.admin.info.is-unlocked");
user.sendMessage("commands.admin.info.banned-players");
return true;
}
}