WIP - testing register/unregister admim commands

JUnit tests do not pass, so bypass for now.
This commit is contained in:
tastybento 2018-06-21 22:30:09 -07:00
parent 12a1700848
commit 97cf9b4132
8 changed files with 54 additions and 21 deletions

View File

@ -50,6 +50,7 @@ commands:
description: "help command"
admin:
help:
parameters: ""
description: "admin command"
team:
add:
@ -71,15 +72,15 @@ commands:
parameters: "<player>"
description: "make player the team's leader"
already-leader: "&cPlayer is already the leader!"
register:
parameters: "<player>"
description: "register player to unowned island you are on"
registered-island: "&aRegistered player to island at [xyz]."
already-owned: "&cIsland is already owned by another player!"
unregister:
parameters: "<owner>"
description: "unregister owner from island, but keep island blocks"
unregistered-island: "&aUnregistered player from island at [xyz]."
register:
parameters: "<player>"
description: "register player to unowned island you are on"
registered-island: "&aRegistered player to island at [xyz]."
already-owned: "&cIsland is already owned by another player!"
unregister:
parameters: "<owner>"
description: "unregister owner from island, but keep island blocks"
unregistered-island: "&aUnregistered player from island at [xyz]."
info:
parameters: "<player>"
description: "get info on where you are or player's island"

View File

@ -7,10 +7,12 @@ import us.tastybento.bskyblock.api.localization.TextVariables;
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.AdminRegisterCommand;
import us.tastybento.bskyblock.commands.admin.AdminReloadCommand;
import us.tastybento.bskyblock.commands.admin.AdminSchemCommand;
import us.tastybento.bskyblock.commands.admin.AdminSetRankCommand;
import us.tastybento.bskyblock.commands.admin.AdminTeleportCommand;
import us.tastybento.bskyblock.commands.admin.AdminUnregisterCommand;
import us.tastybento.bskyblock.commands.admin.AdminVersionCommand;
import us.tastybento.bskyblock.commands.admin.teams.AdminTeamAddCommand;
import us.tastybento.bskyblock.commands.admin.teams.AdminTeamDisbandCommand;
@ -46,6 +48,9 @@ public class AdminCommand extends CompositeCommand {
new AdminTeamMakeLeaderCommand(this);
// Schems
new AdminSchemCommand(this);
// Register/unregister islands
new AdminRegisterCommand(this);
new AdminUnregisterCommand(this);
}
@Override

View File

@ -29,6 +29,7 @@ public class AdminInfoCommand extends CompositeCommand {
}
// If there are no args, then the player wants info on the island at this location
if (args.isEmpty()) {
getPlugin().log("DEBUG: getting info - no args");
if (!getIslands().getIslandAt(user.getLocation()).map(i -> i.showInfo(getPlugin(), user)).orElse(false)) {
user.sendMessage("commands.admin.info.no-island");
return false;

View File

@ -44,6 +44,9 @@ public class AdminRegisterCommand extends CompositeCommand {
user.sendMessage("commands.admin.register.cannot-register-team-player");
return false;
}
getIslands().getIslandAt(user.getLocation()).ifPresent(i -> getPlugin().log("DEBUG: island at this location is " + i.getCenter()));
// Check if island is owned
Optional<Island> island = getIslands().getIslandAt(user.getLocation());
if (island.map(i -> i.getOwner() != null).orElse(false)) {
@ -58,5 +61,6 @@ public class AdminRegisterCommand extends CompositeCommand {
user.sendMessage("general.success");
return true;
}).orElse(false); // Island does not exist
}
}

View File

@ -8,6 +8,7 @@ import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
@ -377,6 +378,7 @@ public class Island implements DataObject {
* @return true if in the island space
*/
public boolean inIslandSpace(int x, int z) {
Bukkit.getLogger().info("DEBUG: minX = " + minX + " range = " + range + " minZ = " + minZ);
return x >= minX && x < minX + range*2 && z >= minZ && z < minZ + range*2;
}
@ -651,15 +653,20 @@ public class Island implements DataObject {
*/
public boolean showInfo(BSkyBlock plugin, User user) {
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);
// Show team members
showMembers(plugin, user);
if (owner == null) {
user.sendMessage("commands.admin.info.unowned");
} else {
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);
// Show team members
showMembers(plugin, user);
}
Vector location = center.toVector();
user.sendMessage("commands.admin.info.island-location", "[xyz]", Util.xyz(location));
Vector from = center.toVector().subtract(new Vector(range, 0, range)).setY(0);

View File

@ -653,6 +653,7 @@ public class IslandsManager {
*/
public void removePlayer(World world, User user) {
islandCache.removePlayer(world, user.getUniqueId());
save(true);
}
/**
@ -662,6 +663,7 @@ public class IslandsManager {
*/
public void removePlayer(World world, UUID uuid) {
islandCache.removePlayer(world, uuid);
save(true);
}
/**

View File

@ -8,6 +8,7 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
@ -167,19 +168,24 @@ public class IslandCache {
* @param uuid - player's UUID
*/
public void removePlayer(World world, UUID uuid) {
islandsByUUID.putIfAbsent(Util.getWorld(world), new HashMap<>());
Island island = islandsByUUID.get(Util.getWorld(world)).get(uuid);
Bukkit.getLogger().info("DEBUG: removing " + uuid + " in " + world.getName());
world = Util.getWorld(world);
islandsByUUID.putIfAbsent(world, new HashMap<>());
Island island = islandsByUUID.get(world).get(uuid);
if (island != null) {
Bukkit.getLogger().info("DEBUG: island found");
if (island.getOwner() != null && island.getOwner().equals(uuid)) {
Bukkit.getLogger().info("DEBUG: owner is not null and uuid is owner");
// Clear ownership and members
island.getMembers().clear();
island.setOwner(null);
} else {
Bukkit.getLogger().info("DEBUG: owner is not uuid - just remove member");
// Remove player from the island membership
island.removeMember(uuid);
}
}
islandsByUUID.get(Util.getWorld(world)).remove(uuid);
islandsByUUID.get(world).remove(uuid);
}
/**

View File

@ -1,6 +1,9 @@
package us.tastybento.bskyblock.managers.island;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import java.util.TreeMap;
import us.tastybento.bskyblock.database.objects.Island;
@ -69,13 +72,17 @@ public class IslandGrid {
* @return Island or null
*/
public Island getIslandAt(int x, int z) {
Bukkit.getLogger().info("DEBUG: x and z = " + x + " " + z);
Entry<Integer, TreeMap<Integer, Island>> en = grid.floorEntry(x);
if (en != null) {
Entry<Integer, Island> ent = en.getValue().floorEntry(z);
if (ent != null) {
Bukkit.getLogger().info("DEBUG: found island");
// Check if in the island range
Island island = ent.getValue();
Bukkit.getLogger().info("DEBUG: island center = " + island.getCenter());
if (island.inIslandSpace(x, z)) {
Bukkit.getLogger().info("DEBUG: in island space");
return island;
}
}