mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-22 00:58:04 +01:00
Revert "Removed /is and /bsbadmin commands"
This reverts commit c6e2ba6418
.
This commit is contained in:
parent
399a5c1518
commit
422fd7b0e8
@ -0,0 +1,40 @@
|
||||
package world.bentobox.bentobox.commands.admin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
public class AdminClearResetsAllCommand extends CompositeCommand {
|
||||
|
||||
public AdminClearResetsAllCommand(CompositeCommand parent) {
|
||||
super(parent, "clearresetsall");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("admin.clearresetsall");
|
||||
setDescription("commands.admin.clearresetsall.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// If args are not right, show help
|
||||
if (!args.isEmpty()) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
this.askConfirmation(user, () -> {
|
||||
// Set the reset epoch to now
|
||||
getIWM().setResetEpoch(getWorld());
|
||||
// Reset all current players
|
||||
Bukkit.getOnlinePlayers().stream().map(Player::getUniqueId).filter(getPlayers()::isKnown).forEach(u -> getPlayers().setResets(getWorld(), u, 0));
|
||||
user.sendMessage("general.success");
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package world.bentobox.bentobox.commands.admin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
public class AdminClearResetsCommand extends CompositeCommand {
|
||||
|
||||
public AdminClearResetsCommand(CompositeCommand parent) {
|
||||
super(parent, "clearresets");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("admin.clearreset");
|
||||
setParameters("commands.admin.clearresets.parameters");
|
||||
setDescription("commands.admin.clearresets.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// If args are not right, show help
|
||||
if (args.size() != 1) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
// Get target
|
||||
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player");
|
||||
return false;
|
||||
}
|
||||
if (!getIslands().hasIsland(getWorld(), targetUUID)) {
|
||||
user.sendMessage("general.errors.player-has-no-island");
|
||||
return false;
|
||||
}
|
||||
// Clear resets
|
||||
user.sendMessage("commands.admin.clearresets.cleared");
|
||||
getPlayers().setResets(getWorld(), targetUUID, 0);
|
||||
user.sendMessage("general.success");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||
if (args.isEmpty()) {
|
||||
// Don't show every player on the server. Require at least the first letter
|
||||
return Optional.empty();
|
||||
}
|
||||
List<String> options = new ArrayList<>(Util.getOnlinePlayerList(user));
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package world.bentobox.bentobox.commands.admin;
|
||||
|
||||
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 world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class AdminGetRankCommand extends CompositeCommand {
|
||||
|
||||
public AdminGetRankCommand(CompositeCommand adminCommand) {
|
||||
super(adminCommand, "getrank");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("admin.setrank");
|
||||
setOnlyPlayer(false);
|
||||
setParameters("commands.admin.getrank.parameters");
|
||||
setDescription("commands.admin.getrank.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, 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 (!getIslands().hasIsland(getWorld(), targetUUID)) {
|
||||
user.sendMessage("general.errors.player-has-no-island");
|
||||
return false;
|
||||
}
|
||||
// Get rank
|
||||
RanksManager rm = getPlugin().getRanksManager();
|
||||
User target = User.getInstance(targetUUID);
|
||||
Island island = getIslands().getIsland(getWorld(), targetUUID);
|
||||
int currentRank = island.getRank(target);
|
||||
user.sendMessage("commands.admin.getrank.rank-is", TextVariables.RANK, user.getTranslation(rm.getRank(currentRank)));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
return Optional.of(Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package world.bentobox.bentobox.commands.admin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
public class AdminInfoCommand extends CompositeCommand {
|
||||
|
||||
public AdminInfoCommand(CompositeCommand parent) {
|
||||
super(parent, "info");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("admin.info");
|
||||
setOnlyPlayer(false);
|
||||
setParameters("commands.admin.info.parameters");
|
||||
setDescription("commands.admin.info.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (args.size() > 1 || (args.isEmpty() && !user.isPlayer())) {
|
||||
// Show help
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
// If there are no args, then the player wants info on the island at this location
|
||||
if (args.isEmpty()) {
|
||||
if (!getIslands().getIslandAt(user.getLocation()).map(i -> i.showInfo(getPlugin(), user, getWorld())).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 (!getIslands().hasIsland(getWorld(), targetUUID)) {
|
||||
user.sendMessage("general.errors.player-has-no-island");
|
||||
return false;
|
||||
}
|
||||
// Show info for this player
|
||||
getIslands().getIsland(getWorld(), targetUUID).showInfo(getPlugin(), user, getWorld());
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
package world.bentobox.bentobox.commands.admin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
public class AdminRegisterCommand extends CompositeCommand {
|
||||
|
||||
public AdminRegisterCommand(CompositeCommand parent) {
|
||||
super(parent, "register");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("admin.register");
|
||||
setOnlyPlayer(true);
|
||||
setParameters("commands.admin.register.parameters");
|
||||
setDescription("commands.admin.register.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// If args are not right, show help
|
||||
if (args.size() != 1) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
// Get target
|
||||
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player");
|
||||
return false;
|
||||
}
|
||||
if (getIslands().hasIsland(getWorld(), targetUUID)) {
|
||||
user.sendMessage("general.errors.player-has-island");
|
||||
return false;
|
||||
}
|
||||
if (getIslands().inTeam(getWorld(), targetUUID)) {
|
||||
user.sendMessage("commands.admin.register.cannot-register-team-player");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if island is owned
|
||||
Optional<Island> island = getIslands().getIslandAt(user.getLocation());
|
||||
if (island.map(i -> i.getOwner() != null).orElse(false)) {
|
||||
user.sendMessage("commands.admin.register.already-owned");
|
||||
return false;
|
||||
}
|
||||
// Register island if it exists
|
||||
if (!island.map(i -> {
|
||||
// Island exists
|
||||
getIslands().makeLeader(user, targetUUID, i, getPermissionPrefix());
|
||||
user.sendMessage("commands.admin.register.registered-island", "[xyz]", Util.xyz(i.getCenter().toVector()));
|
||||
user.sendMessage("general.success");
|
||||
return true;
|
||||
}).orElse(false)) {
|
||||
// Island does not exist
|
||||
user.sendMessage("commands.admin.register.no-island-here");
|
||||
this.askConfirmation(user, () -> {
|
||||
// Make island here
|
||||
Island i = getIslands().createIsland(getClosestIsland(user.getLocation()), targetUUID);
|
||||
getIslands().makeLeader(user, targetUUID, i, getPermissionPrefix());
|
||||
getWorld().getBlockAt(i.getCenter()).setType(Material.BEDROCK);
|
||||
user.sendMessage("commands.admin.register.registered-island", "[xyz]", Util.xyz(i.getCenter().toVector()));
|
||||
user.sendMessage("general.success");
|
||||
});
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||
if (args.isEmpty()) {
|
||||
// Don't show every player on the server. Require at least the first letter
|
||||
return Optional.empty();
|
||||
}
|
||||
List<String> options = new ArrayList<>(Util.getOnlinePlayerList(user));
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns the coordinate of where an island should be on the grid.
|
||||
*
|
||||
* @param location - location to check
|
||||
* @return Location of where an island should be on a grid in this world
|
||||
*/
|
||||
public Location getClosestIsland(Location location) {
|
||||
int dist = getIWM().getIslandDistance(getWorld()) * 2;
|
||||
long x = Math.round((double) location.getBlockX() / dist) * dist + getIWM().getIslandXOffset(getWorld());
|
||||
long z = Math.round((double) location.getBlockZ() / dist) * dist + getIWM().getIslandZOffset(getWorld());
|
||||
long y = getIWM().getIslandHeight(getWorld());
|
||||
return new Location(location.getWorld(), x, y, z);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package world.bentobox.bentobox.commands.admin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class AdminReloadCommand extends CompositeCommand {
|
||||
|
||||
/**
|
||||
* @param parent - parent command
|
||||
*/
|
||||
public AdminReloadCommand(CompositeCommand parent) {
|
||||
super(parent, "reload", "rl");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setDescription("commands.admin.reload.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,141 @@
|
||||
package world.bentobox.bentobox.commands.admin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.island.builders.Clipboard;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
public class AdminSchemCommand extends CompositeCommand {
|
||||
private Map<UUID, Clipboard> clipboards;
|
||||
|
||||
public AdminSchemCommand(CompositeCommand parent) {
|
||||
super(parent, "schem");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("admin.schem");
|
||||
setParameters("commands.admin.schem.parameters");
|
||||
setDescription("commands.admin.schem.description");
|
||||
setOnlyPlayer(true);
|
||||
clipboards = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
File schemFolder = new File(getIWM().getDataFolder(getWorld()), "schems");
|
||||
Clipboard cb = clipboards.getOrDefault(user.getUniqueId(), new Clipboard(getPlugin(), schemFolder));
|
||||
|
||||
if (args.get(0).equalsIgnoreCase("paste")) {
|
||||
if (cb.isFull()) {
|
||||
cb.paste(user.getLocation());
|
||||
user.sendMessage("general.success");
|
||||
return true;
|
||||
} else {
|
||||
user.sendMessage("commands.admin.schem.copy-first");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.get(0).equalsIgnoreCase("load")) {
|
||||
if (args.size() == 2) {
|
||||
if (cb.load(user, args.get(1))) {
|
||||
clipboards.put(user.getUniqueId(), cb);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.get(0).equalsIgnoreCase("origin")) {
|
||||
if (cb.getPos1() == null || cb.getPos2() == null) {
|
||||
user.sendMessage("commands.admin.schem.need-pos1-pos2");
|
||||
return false;
|
||||
}
|
||||
// Get the block player is looking at
|
||||
Block b = user.getPlayer().getLineOfSight(null, 20).stream().filter(x -> !x.getType().equals(Material.AIR)).findFirst().orElse(null);
|
||||
if (b != null) {
|
||||
cb.setOrigin(b.getLocation());
|
||||
user.getPlayer().sendBlockChange(b.getLocation(), Material.STAINED_GLASS,(byte)14);
|
||||
Bukkit.getScheduler().runTaskLater(getPlugin(),
|
||||
() -> user.getPlayer().sendBlockChange(b.getLocation(), b.getType(), b.getData()), 20L);
|
||||
|
||||
user.sendMessage("general.success");
|
||||
return true;
|
||||
} else {
|
||||
user.sendMessage("commands.admin.schem.look-at-a-block");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.get(0).equalsIgnoreCase("copy")) {
|
||||
boolean copyAir = (args.size() == 2 && args.get(1).equalsIgnoreCase("air"));
|
||||
return cb.copy(user, copyAir);
|
||||
}
|
||||
|
||||
if (args.get(0).equalsIgnoreCase("save")) {
|
||||
if (cb.isFull()) {
|
||||
if (args.size() == 2) {
|
||||
// Check if file exists
|
||||
File newFile = new File(schemFolder, args.get(1) + ".schem");
|
||||
if (newFile.exists()) {
|
||||
user.sendMessage("commands.admin.schem.file-exists");
|
||||
this.askConfirmation(user, () -> cb.save(user, args.get(1)));
|
||||
return false;
|
||||
} else {
|
||||
return cb.save(user, args.get(1));
|
||||
}
|
||||
} else {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
user.sendMessage("commands.admin.schem.copy-first");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.get(0).equalsIgnoreCase("pos1")) {
|
||||
if (user.getLocation().equals(cb.getPos2())) {
|
||||
user.sendMessage("commands.admin.schem.set-different-pos");
|
||||
return false;
|
||||
}
|
||||
cb.setPos1(user.getLocation());
|
||||
user.sendMessage("commands.admin.schem.set-pos1", "[vector]", Util.xyz(user.getLocation().toVector()));
|
||||
clipboards.put(user.getUniqueId(), cb);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.get(0).equalsIgnoreCase("pos2")) {
|
||||
if (user.getLocation().equals(cb.getPos1())) {
|
||||
user.sendMessage("commands.admin.schem.set-different-pos");
|
||||
return false;
|
||||
}
|
||||
cb.setPos2(user.getLocation());
|
||||
user.sendMessage("commands.admin.schem.set-pos2", "[vector]", Util.xyz(user.getLocation().toVector()));
|
||||
clipboards.put(user.getUniqueId(), cb);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package world.bentobox.bentobox.commands.admin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class AdminSetRankCommand extends CompositeCommand {
|
||||
|
||||
public AdminSetRankCommand(CompositeCommand adminCommand) {
|
||||
super(adminCommand, "setrank");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("admin.setrank");
|
||||
setOnlyPlayer(false);
|
||||
setParameters("commands.admin.setrank.parameters");
|
||||
setDescription("commands.admin.setrank.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, 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(getWorld(), 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(Map.Entry::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(getWorld(), 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(User user, String alias, List<String> args) {
|
||||
return Optional.of(getPlugin().getRanksManager().getRanks().keySet().stream().map(user::getTranslation).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package world.bentobox.bentobox.commands.admin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
import world.bentobox.bentobox.util.teleport.SafeTeleportBuilder;
|
||||
|
||||
public class AdminTeleportCommand extends CompositeCommand {
|
||||
|
||||
public AdminTeleportCommand(CompositeCommand parent, String tpCommand) {
|
||||
super(parent, tpCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
// Permission
|
||||
setPermission(getPermissionPrefix() + "admin.tp");
|
||||
setOnlyPlayer(true);
|
||||
setParameters("commands.admin.tp.parameters");
|
||||
setDescription("commands.admin.tp.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
this.showHelp(this, user);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Convert name to a UUID
|
||||
final UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player");
|
||||
return false;
|
||||
} else {
|
||||
if (getIslands().hasIsland(getWorld(), targetUUID) || getIslands().inTeam(getWorld(), targetUUID)) {
|
||||
Location warpSpot = getIslands().getIslandLocation(getWorld(), targetUUID).toVector().toLocation(getWorld());
|
||||
if (getLabel().equals("tpnether")) {
|
||||
warpSpot = getIslands().getIslandLocation(getWorld(), targetUUID).toVector().toLocation(getPlugin().getIWM().getNetherWorld(getWorld()));
|
||||
} else if (getLabel().equals("tpend")) {
|
||||
warpSpot = getIslands().getIslandLocation(getWorld(), targetUUID).toVector().toLocation(getPlugin().getIWM().getEndWorld(getWorld()));
|
||||
}
|
||||
// Other wise, go to a safe spot
|
||||
String failureMessage = user.getTranslation("commands.admin.tp.manual", "[location]", warpSpot.getBlockX() + " " + warpSpot.getBlockY() + " "
|
||||
+ warpSpot.getBlockZ());
|
||||
new SafeTeleportBuilder(getPlugin()).entity(user.getPlayer())
|
||||
.location(warpSpot)
|
||||
.failureMessage(failureMessage)
|
||||
.build();
|
||||
return true;
|
||||
}
|
||||
user.sendMessage("general.errors.player-has-no-island");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||
if (args.isEmpty()) {
|
||||
// Don't show every player on the server. Require at least the first letter
|
||||
return Optional.empty();
|
||||
}
|
||||
List<String> options = new ArrayList<>(Util.getOnlinePlayerList(user));
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package world.bentobox.bentobox.commands.admin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
public class AdminUnregisterCommand extends CompositeCommand {
|
||||
|
||||
public AdminUnregisterCommand(CompositeCommand parent) {
|
||||
super(parent, "unregister");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("admin.unregister");
|
||||
setParameters("commands.admin.unregister.parameters");
|
||||
setDescription("commands.admin.unregister.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// If args are not right, show help
|
||||
if (args.size() != 1) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
// Get target
|
||||
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player");
|
||||
return false;
|
||||
}
|
||||
if (!getIslands().hasIsland(getWorld(), targetUUID)) {
|
||||
user.sendMessage("general.errors.player-has-no-island");
|
||||
return false;
|
||||
}
|
||||
if (getIslands().inTeam(getWorld(), targetUUID)) {
|
||||
user.sendMessage("commands.admin.unregister.cannot-unregister-team-player");
|
||||
return false;
|
||||
}
|
||||
// Unregister island
|
||||
user.sendMessage("commands.admin.unregister.unregistered-island", "[xyz]", Util.xyz(getIslands().getIsland(getWorld(), targetUUID).getCenter().toVector()));
|
||||
getIslands().removePlayer(getWorld(), targetUUID);
|
||||
getPlayers().clearHomeLocations(getWorld(), targetUUID);
|
||||
user.sendMessage("general.success");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||
if (args.isEmpty()) {
|
||||
// Don't show every player on the server. Require at least the first letter
|
||||
return Optional.empty();
|
||||
}
|
||||
List<String> options = new ArrayList<>(Util.getOnlinePlayerList(user));
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package world.bentobox.bentobox.commands.admin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
public class AdminVersionCommand extends CompositeCommand {
|
||||
|
||||
public AdminVersionCommand(CompositeCommand adminCommand) {
|
||||
super(adminCommand, "version", "v");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
// Permission
|
||||
setPermission("admin.version");
|
||||
setDescription("commands.admin.version.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package world.bentobox.bentobox.commands.admin.range;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
/**
|
||||
* @author Poslovitch
|
||||
*/
|
||||
public class AdminRangeCommand extends CompositeCommand {
|
||||
|
||||
public AdminRangeCommand(CompositeCommand parent) {
|
||||
super (parent, "range");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("admin.range");
|
||||
setDescription("commands.admin.range.description");
|
||||
|
||||
new AdminRangeDisplayCommand(this);
|
||||
new AdminRangeSetCommand(this);
|
||||
new AdminRangeResetCommand(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
showHelp(this, user);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
package world.bentobox.bentobox.commands.admin.range;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
/**
|
||||
* @author Poslovitch
|
||||
*/
|
||||
public class AdminRangeDisplayCommand extends CompositeCommand {
|
||||
|
||||
private Map<User, Integer> display = new HashMap<>();
|
||||
|
||||
public AdminRangeDisplayCommand(CompositeCommand parent) {
|
||||
super(parent, "display", "show", "hide");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("admin.range.display");
|
||||
setDescription("commands.admin.range.display.description");
|
||||
setOnlyPlayer(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// According to the label used to execute the command, there is a different behaviour
|
||||
// - display : toggle on/off
|
||||
// - show : only set on - and send "error" if already on
|
||||
// - hide : only set off - same if already off
|
||||
|
||||
if (!display.containsKey(user)) {
|
||||
switch (label) {
|
||||
case "display":
|
||||
case "show":
|
||||
showZones(user);
|
||||
break;
|
||||
case "hide":
|
||||
user.sendMessage("commands.admin.range.display.already-off");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (label) {
|
||||
case "display":
|
||||
case "hide":
|
||||
hideZones(user);
|
||||
break;
|
||||
case "show":
|
||||
user.sendMessage("commands.admin.range.display.already-on");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void showZones(User user) {
|
||||
user.sendMessage("commands.admin.range.display.showing");
|
||||
user.sendMessage("commands.admin.range.display.hint");
|
||||
display.put(user, Bukkit.getScheduler().scheduleSyncRepeatingTask(getPlugin(), () -> {
|
||||
if (!user.getPlayer().isOnline()) {
|
||||
hideZones(user);
|
||||
}
|
||||
|
||||
getIslands().getIslandAt(user.getLocation()).ifPresent(island -> {
|
||||
// Draw the island protected area
|
||||
drawZone(user.getPlayer(), Particle.BARRIER, island.getCenter(), island.getProtectionRange());
|
||||
|
||||
// Draw the default protected area if island protected zone is different
|
||||
if (island.getProtectionRange() != getPlugin().getIWM().getIslandProtectionRange(getWorld())) {
|
||||
drawZone(user.getPlayer(), Particle.VILLAGER_HAPPY, island.getCenter(), getPlugin().getIWM().getIslandProtectionRange(getWorld()));
|
||||
}
|
||||
|
||||
// Draw the island area
|
||||
drawZone(user.getPlayer(), Particle.TOWN_AURA, island.getCenter(), island.getRange());
|
||||
});
|
||||
}, 20, 30));
|
||||
}
|
||||
|
||||
private void hideZones(User user) {
|
||||
user.sendMessage("commands.admin.range.display.hiding");
|
||||
Bukkit.getScheduler().cancelTask(display.get(user));
|
||||
display.remove(user);
|
||||
}
|
||||
|
||||
private void drawZone(Player player, Particle particle, Location center, int range) {
|
||||
// Get player Y coordinate
|
||||
int playerY = player.getLocation().getBlockY() + 1;
|
||||
|
||||
// Draw 3 "stages" (one line below, at and above player's y coordinate)
|
||||
for (int stage = -1 ; stage <= 1 ; stage++) {
|
||||
for (int i = -range ; i <= range ; i++) {
|
||||
spawnParticle(player, particle, center.getBlockX() + i, playerY + stage, center.getBlockZ() + range);
|
||||
spawnParticle(player, particle, center.getBlockX() + i, playerY + stage, center.getBlockZ() - range);
|
||||
spawnParticle(player, particle, center.getBlockX() + range, playerY + stage, center.getBlockZ() + i);
|
||||
spawnParticle(player, particle, center.getBlockX() - range, playerY + stage, center.getBlockZ() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void spawnParticle(Player player, Particle particle, int x, int y, int z) {
|
||||
// Check if this particle is beyond the viewing distance of the server
|
||||
if (player.getLocation().toVector().distanceSquared(new Vector(x,y,z)) < (Bukkit.getServer().getViewDistance()*256*Bukkit.getServer().getViewDistance())) {
|
||||
player.spawnParticle(particle, x, y, z, 1);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package world.bentobox.bentobox.commands.admin.range;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
|
||||
public class AdminRangeResetCommand extends CompositeCommand {
|
||||
|
||||
public AdminRangeResetCommand(CompositeCommand parent) {
|
||||
super(parent, "reset");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("admin.range.reset");
|
||||
setParameters("commands.admin.range.reset.parameters");
|
||||
setDescription("commands.admin.range.reset.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, 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(getWorld(), targetUUID)) {
|
||||
user.sendMessage("general.errors.player-has-no-island");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get island
|
||||
Island island = getIslands().getIsland(getWorld(), targetUUID);
|
||||
|
||||
// Reset the protection range
|
||||
int range = getIWM().getIslandProtectionRange(getWorld());
|
||||
island.setProtectionRange(range);
|
||||
user.sendMessage("commands.admin.range.reset.success", TextVariables.NUMBER, String.valueOf(range));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package world.bentobox.bentobox.commands.admin.range;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
|
||||
public class AdminRangeSetCommand extends CompositeCommand {
|
||||
|
||||
public AdminRangeSetCommand(CompositeCommand parent) {
|
||||
super(parent, "set");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("admin.range.set");
|
||||
setParameters("commands.admin.range.set.parameters");
|
||||
setDescription("commands.admin.range.set.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, 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(getWorld(), targetUUID)) {
|
||||
user.sendMessage("general.errors.player-has-no-island");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get new range
|
||||
if (!StringUtils.isNumeric(args.get(1))) {
|
||||
user.sendMessage("commands.admin.range.set.invalid-value.not-numeric", TextVariables.NUMBER, args.get(1));
|
||||
return false;
|
||||
}
|
||||
int range = Integer.valueOf(args.get(1));
|
||||
|
||||
// Get island
|
||||
Island island = getIslands().getIsland(getWorld(), targetUUID);
|
||||
|
||||
// Do some sanity checks to make sure the new protection range won't cause problems
|
||||
if (range <= 1) {
|
||||
user.sendMessage("commands.admin.range.set.invalid-value.too-low", TextVariables.NUMBER, args.get(1));
|
||||
return false;
|
||||
}
|
||||
if (range > island.getRange()) {
|
||||
user.sendMessage("commands.admin.range.set.invalid-value.too-high", TextVariables.NUMBER, String.valueOf(island.getRange()));
|
||||
return false;
|
||||
}
|
||||
if (range == island.getProtectionRange()) {
|
||||
user.sendMessage("commands.admin.range.set.invalid-value.same-as-before", TextVariables.NUMBER, args.get(1));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Well, now it can be applied without taking any risks !
|
||||
island.setProtectionRange(range);
|
||||
user.sendMessage("commands.admin.range.set.success", TextVariables.NUMBER, String.valueOf(range));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package world.bentobox.bentobox.commands.admin.team;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
public class AdminTeamAddCommand extends CompositeCommand {
|
||||
|
||||
public AdminTeamAddCommand(CompositeCommand parent) {
|
||||
super(parent, "add");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("admin.team");
|
||||
setParameters("commands.admin.team.add.parameters");
|
||||
setDescription("commands.admin.team.add.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// If args are not right, show help
|
||||
if (args.size() != 2) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
// Get leader and target
|
||||
UUID leaderUUID = getPlayers().getUUID(args.get(0));
|
||||
if (leaderUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player-name", TextVariables.NAME, args.get(0));
|
||||
return false;
|
||||
}
|
||||
UUID targetUUID = getPlayers().getUUID(args.get(1));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player-name", TextVariables.NAME, args.get(1));
|
||||
return false;
|
||||
}
|
||||
if (!getIslands().hasIsland(getWorld(), leaderUUID)) {
|
||||
user.sendMessage("general.errors.player-has-no-island");
|
||||
return false;
|
||||
}
|
||||
if (getIslands().inTeam(getWorld(), leaderUUID) && !getIslands().getTeamLeader(getWorld(), leaderUUID).equals(leaderUUID)) {
|
||||
user.sendMessage("commands.admin.team.add.name-not-leader", TextVariables.NAME, args.get(0));
|
||||
getIslands().getIsland(getWorld(), leaderUUID).showMembers(getPlugin(), user, getWorld());
|
||||
return false;
|
||||
}
|
||||
if (getIslands().inTeam(getWorld(), targetUUID)) {
|
||||
user.sendMessage("commands.island.team.invite.errors.already-on-team");
|
||||
return false;
|
||||
}
|
||||
if (getIslands().hasIsland(getWorld(), targetUUID)) {
|
||||
user.sendMessage("commands.admin.team.add.name-has-island", TextVariables.NAME, args.get(1));
|
||||
return false;
|
||||
}
|
||||
// Success
|
||||
User target = User.getInstance(targetUUID);
|
||||
User leader = User.getInstance(leaderUUID);
|
||||
leader.sendMessage("commands.island.team.invite.accept.name-joined-your-island", TextVariables.NAME, getPlugin().getPlayers().getName(targetUUID));
|
||||
target.sendMessage("commands.island.team.invite.accept.you-joined-island", TextVariables.LABEL, getTopLabel());
|
||||
getIslands().getIsland(getWorld(), leaderUUID).addMember(targetUUID);
|
||||
user.sendMessage("general.success");
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package world.bentobox.bentobox.commands.admin.team;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
public class AdminTeamDisbandCommand extends CompositeCommand {
|
||||
|
||||
public AdminTeamDisbandCommand(CompositeCommand parent) {
|
||||
super(parent, "disband");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("admin.team");
|
||||
setParameters("commands.admin.team.disband.parameters");
|
||||
setDescription("commands.admin.team.disband.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// If args are not right, show help
|
||||
if (args.size() != 1) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
// Get target
|
||||
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player");
|
||||
return false;
|
||||
}
|
||||
if (!getIslands().hasIsland(getWorld(), targetUUID)) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
if (!getIslands().inTeam(getWorld(), targetUUID)) {
|
||||
user.sendMessage("general.errors.not-in-team");
|
||||
return false;
|
||||
}
|
||||
if (!getIslands().getTeamLeader(getWorld(), targetUUID).equals(targetUUID)) {
|
||||
user.sendMessage("commands.admin.team.disband.use-disband-leader", "[leader]", getPlayers().getName(getIslands().getTeamLeader(getWorld(), targetUUID)));
|
||||
return false;
|
||||
}
|
||||
// Disband team
|
||||
getIslands().getMembers(getWorld(), targetUUID).forEach(m -> {
|
||||
User.getInstance(m).sendMessage("commands.admin.team.disband.disbanded");
|
||||
// The leader gets to keep the island
|
||||
if (!m.equals(targetUUID)) {
|
||||
getIslands().setLeaveTeam(getWorld(), m);
|
||||
}
|
||||
});
|
||||
user.sendMessage("general.success");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package world.bentobox.bentobox.commands.admin.team;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
public class AdminTeamKickCommand extends CompositeCommand {
|
||||
|
||||
public AdminTeamKickCommand(CompositeCommand parent) {
|
||||
super(parent, "kick");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("admin.team");
|
||||
setParameters("commands.admin.team.kick.parameters");
|
||||
setDescription("commands.admin.team.kick.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// If args are not right, show help
|
||||
if (args.size() != 1) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
// Get target
|
||||
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player");
|
||||
return false;
|
||||
}
|
||||
if (!getIslands().hasIsland(getWorld(), targetUUID)) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
if (!getIslands().inTeam(getWorld(), targetUUID)) {
|
||||
user.sendMessage("general.errors.not-in-team");
|
||||
return false;
|
||||
}
|
||||
if (getIslands().getTeamLeader(getWorld(), targetUUID).equals(targetUUID)) {
|
||||
user.sendMessage("commands.admin.team.kick.cannot-kick-leader");
|
||||
getIslands().getIsland(getWorld(), targetUUID).showMembers(getPlugin(), user, getWorld());
|
||||
return false;
|
||||
}
|
||||
User.getInstance(targetUUID).sendMessage("commands.admin.team.kick.admin-kicked");
|
||||
getIslands().removePlayer(getWorld(), targetUUID);
|
||||
user.sendMessage("general.success");
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package world.bentobox.bentobox.commands.admin.team;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
public class AdminTeamMakeLeaderCommand extends CompositeCommand {
|
||||
|
||||
public AdminTeamMakeLeaderCommand(CompositeCommand parent) {
|
||||
super(parent, "makeleader");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("admin.team");
|
||||
setParameters("commands.admin.team.makeleader.parameters");
|
||||
setDescription("commands.admin.team.makeleader.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// If args are not right, show help
|
||||
if (args.size() != 1) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
// Get target
|
||||
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player");
|
||||
return false;
|
||||
}
|
||||
if (!getIslands().hasIsland(getWorld(), targetUUID)) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
if (!getIslands().inTeam(getWorld(), targetUUID)) {
|
||||
user.sendMessage("general.errors.not-in-team");
|
||||
return false;
|
||||
}
|
||||
if (getIslands().getTeamLeader(getWorld(), targetUUID).equals(targetUUID)) {
|
||||
user.sendMessage("commands.admin.team.makeleader.already-leader");
|
||||
return false;
|
||||
}
|
||||
// Make new leader
|
||||
getIslands().makeLeader(getWorld(), user, targetUUID, getPermissionPrefix());
|
||||
user.sendMessage("general.success");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package world.bentobox.bentobox.commands.island;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
* This is a custom help for the /island go and /island sethome commands. It overrides the default help sub command.
|
||||
* The number of homes can change depending on the player's permissions and config.yml settings.
|
||||
* This is an example of a custom help as much as anything.
|
||||
*
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class CustomIslandMultiHomeHelp extends CompositeCommand {
|
||||
|
||||
public CustomIslandMultiHomeHelp(CompositeCommand parent) {
|
||||
super(parent, "help");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setOnlyPlayer(true);
|
||||
// Inherit parameters from the respective parent class - in this case, only /island go and /island sethome
|
||||
setParameters(parent.getParameters());
|
||||
setDescription(parent.getDescription());
|
||||
inheritPermission();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// This will only be shown if it is for a player
|
||||
if (user.isPlayer()) {
|
||||
// Get elements
|
||||
String usage = parent.getUsage().isEmpty() ? "" : user.getTranslation(parent.getUsage());
|
||||
String params = "";
|
||||
String desc = getDescription().isEmpty() ? "" : user.getTranslation(getDescription());
|
||||
|
||||
showPrettyHelp(user, usage, params, desc);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void showPrettyHelp(User user, String usage, String params, String desc) {
|
||||
// Player. Check perms
|
||||
if (user.hasPermission(getPermission())) {
|
||||
int maxHomes = Util.getPermValue(user.getPlayer(), getPermissionPrefix() + "island.maxhomes", getIWM().getMaxHomes(getWorld()));
|
||||
if (maxHomes > 1) {
|
||||
params = getParameters().isEmpty() ? "" : user.getTranslation(getParameters());
|
||||
}
|
||||
user.sendMessage("commands.help.syntax", "[usage]", usage, "[parameters]", params, "[description]", desc);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,50 @@
|
||||
package world.bentobox.bentobox.commands.island;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
public class IslandAboutCommand extends CompositeCommand {
|
||||
|
||||
/**
|
||||
* About
|
||||
* @param islandCommand - parent command
|
||||
*/
|
||||
public IslandAboutCommand(CompositeCommand islandCommand) {
|
||||
super(islandCommand, "about", "ab");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setDescription("commands.island.about.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
user.sendRawMessage("About " + BentoBox.getInstance().getDescription().getName() + " v" + BentoBox.getInstance().getDescription().getVersion() + ":");
|
||||
user.sendRawMessage("Copyright (c) 2017 - 2018 Tastybento, Poslovitch");
|
||||
user.sendRawMessage("All rights reserved.");
|
||||
user.sendRawMessage("");
|
||||
user.sendRawMessage("Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:");
|
||||
|
||||
user.sendRawMessage(" * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.");
|
||||
user.sendRawMessage(" * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.");
|
||||
user.sendRawMessage(" * Neither the name of the development team nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.");
|
||||
|
||||
user.sendRawMessage("THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" "
|
||||
+ "AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE "
|
||||
+ "IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE "
|
||||
+ "ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE "
|
||||
+ "LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR "
|
||||
+ "CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF "
|
||||
+ "SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS "
|
||||
+ "INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN "
|
||||
+ "CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) "
|
||||
+ "ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE "
|
||||
+ "POSSIBILITY OF SUCH DAMAGE.");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
package world.bentobox.bentobox.commands.island;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
public class IslandBanCommand extends CompositeCommand {
|
||||
|
||||
public IslandBanCommand(CompositeCommand islandCommand) {
|
||||
super(islandCommand, "ban");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.ban");
|
||||
setOnlyPlayer(true);
|
||||
setParameters("commands.island.ban.parameters");
|
||||
setDescription("commands.island.ban.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (args.size() != 1) {
|
||||
// Show help
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
// Player issuing the command must have an island
|
||||
if (!getIslands().hasIsland(getWorld(), playerUUID)) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
if (!getIslands().isOwner(getWorld(), playerUUID)) {
|
||||
user.sendMessage("general.errors.not-leader");
|
||||
return false;
|
||||
}
|
||||
// Get target player
|
||||
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player");
|
||||
return false;
|
||||
}
|
||||
// Player cannot ban themselves
|
||||
if (playerUUID.equals(targetUUID)) {
|
||||
user.sendMessage("commands.island.ban.cannot-ban-yourself");
|
||||
return false;
|
||||
}
|
||||
if (getIslands().getMembers(getWorld(), user.getUniqueId()).contains(targetUUID)) {
|
||||
user.sendMessage("commands.island.ban.cannot-ban-member");
|
||||
return false;
|
||||
}
|
||||
if (getIslands().getIsland(getWorld(), playerUUID).isBanned(targetUUID)) {
|
||||
user.sendMessage("commands.island.ban.player-already-banned");
|
||||
return false;
|
||||
}
|
||||
User target = User.getInstance(targetUUID);
|
||||
// Cannot ban ops
|
||||
if (target.isOp()) {
|
||||
user.sendMessage("commands.island.ban.cannot-ban");
|
||||
return false;
|
||||
}
|
||||
// Finished error checking - start the banning
|
||||
return ban(user, target);
|
||||
}
|
||||
|
||||
private boolean ban(User user, User targetUser) {
|
||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||
if (island.addToBanList(targetUser.getUniqueId())) {
|
||||
user.sendMessage("general.success");
|
||||
targetUser.sendMessage("commands.island.ban.owner-banned-you", TextVariables.NAME, user.getName());
|
||||
// If the player is online, has an island and on the banned island, move them home immediately
|
||||
if (targetUser.isOnline() && getIslands().hasIsland(getWorld(), targetUser.getUniqueId()) && island.onIsland(targetUser.getLocation())) {
|
||||
getIslands().homeTeleport(getWorld(), targetUser.getPlayer());
|
||||
island.getWorld().playSound(targetUser.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// Banning was blocked, maybe due to an event cancellation. Fail silently.
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
// Don't show every player on the server. Require at least the first letter
|
||||
return Optional.empty();
|
||||
}
|
||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||
List<String> options = Bukkit.getOnlinePlayers().stream()
|
||||
.filter(p -> !p.getUniqueId().equals(user.getUniqueId()))
|
||||
.filter(p -> !island.isBanned(p.getUniqueId()))
|
||||
.filter(p -> user.getPlayer().canSee(p))
|
||||
.map(Player::getName).collect(Collectors.toList());
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package world.bentobox.bentobox.commands.island;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
|
||||
public class IslandBanlistCommand extends CompositeCommand {
|
||||
|
||||
public IslandBanlistCommand(CompositeCommand islandCommand) {
|
||||
super(islandCommand, "banlist");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.ban");
|
||||
setOnlyPlayer(true);
|
||||
setDescription("commands.island.banlist.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (!args.isEmpty()) {
|
||||
// Show help
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
// Player issuing the command must have an island
|
||||
if (!getIslands().hasIsland(getWorld(), user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||
// Show all the players banned on the island
|
||||
if (island.getBanned().isEmpty()) {
|
||||
user.sendMessage("commands.island.banlist.noone");
|
||||
return true;
|
||||
}
|
||||
// Title
|
||||
user.sendMessage("commands.island.banlist.the-following");
|
||||
// Create a nicely formatted list
|
||||
List<String> names = island.getBanned().stream().map(u -> getPlayers().getName(u)).sorted().collect(Collectors.toList());
|
||||
List<String> lines = new ArrayList<>();
|
||||
StringBuilder line = new StringBuilder();
|
||||
// Put the names into lines of no more than 40 characters long, separated by commas
|
||||
names.forEach(n -> {
|
||||
if (line.length() + n.length() < 41) {
|
||||
line.append(n);
|
||||
} else {
|
||||
lines.add(line.toString().trim());
|
||||
line.setLength(0);
|
||||
line.append(n);
|
||||
}
|
||||
line.append(", ");
|
||||
});
|
||||
// Remove trailing comma
|
||||
line.setLength(line.length() - 2);
|
||||
// Add the final line if it is not empty
|
||||
if (line.length() > 0) {
|
||||
lines.add(line.toString());
|
||||
}
|
||||
// Send the strings
|
||||
lines.forEach(l -> user.sendMessage("commands.island.banlist.names", "[line]", l));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package world.bentobox.bentobox.commands.island;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.events.island.IslandEvent.Reason;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.managers.island.NewIsland;
|
||||
|
||||
/**
|
||||
* /island create - Create an island.
|
||||
*
|
||||
* @author Tastybento
|
||||
*/
|
||||
public class IslandCreateCommand extends CompositeCommand {
|
||||
|
||||
/**
|
||||
* Command to create an island
|
||||
* @param islandCommand - parent command
|
||||
*/
|
||||
public IslandCreateCommand(CompositeCommand islandCommand) {
|
||||
super(islandCommand, "create");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.create");
|
||||
setOnlyPlayer(true);
|
||||
setDescription("commands.island.create.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (getIslands().hasIsland(getWorld(), user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.already-have-island");
|
||||
return false;
|
||||
}
|
||||
if (getIslands().inTeam(getWorld(), user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.already-have-island");
|
||||
return false;
|
||||
}
|
||||
user.sendMessage("commands.island.create.creating-island");
|
||||
try {
|
||||
NewIsland.builder()
|
||||
.player(user)
|
||||
.world(getWorld())
|
||||
.reason(Reason.CREATE)
|
||||
.build();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
getPlugin().logError("Could not create island for player. " + e.getMessage());
|
||||
user.sendMessage("commands.island.create.unable-create-island");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package world.bentobox.bentobox.commands.island;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*/
|
||||
public class IslandGoCommand extends CompositeCommand {
|
||||
|
||||
public IslandGoCommand(CompositeCommand islandCommand) {
|
||||
super(islandCommand, "go", "home", "h");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.home");
|
||||
setOnlyPlayer(true);
|
||||
setDescription("commands.island.go.description");
|
||||
new CustomIslandMultiHomeHelp(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (getIslands().getIsland(getWorld(), user.getUniqueId()) == null) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
if (!args.isEmpty() && NumberUtils.isDigits(args.get(0))) {
|
||||
int homeValue = Integer.valueOf(args.get(0));
|
||||
int maxHomes = Util.getPermValue(user.getPlayer(), "island.maxhomes", getIWM().getMaxHomes(getWorld()));
|
||||
if (homeValue > 1 && homeValue <= maxHomes) {
|
||||
getIslands().homeTeleport(getWorld(), user.getPlayer(), homeValue);
|
||||
user.sendMessage("commands.island.go.tip", TextVariables.LABEL, getTopLabel());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
getIslands().homeTeleport(getWorld(), user.getPlayer());
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package world.bentobox.bentobox.commands.island;
|
||||
|
||||
public class IslandInfoCommand {
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package world.bentobox.bentobox.commands.island;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.panels.LanguagePanel;
|
||||
|
||||
/**
|
||||
* @author Poslovitch
|
||||
*/
|
||||
public class IslandLanguageCommand extends CompositeCommand {
|
||||
|
||||
public IslandLanguageCommand(CompositeCommand islandCommand) {
|
||||
super(islandCommand, "language", "lang");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.language");
|
||||
setOnlyPlayer(true);
|
||||
setDescription("commands.island.language.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
LanguagePanel.openPanel(user);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
package world.bentobox.bentobox.commands.island;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.events.island.IslandEvent.Reason;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.island.NewIsland;
|
||||
|
||||
public class IslandResetCommand extends CompositeCommand {
|
||||
|
||||
private Map<UUID, Long> cooldown;
|
||||
|
||||
public IslandResetCommand(CompositeCommand islandCommand) {
|
||||
super(islandCommand, "reset", "restart");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
cooldown = new HashMap<>();
|
||||
setPermission("island.create");
|
||||
setOnlyPlayer(true);
|
||||
setDescription("commands.island.reset.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// Check cooldown
|
||||
if (getSettings().getResetWait() > 0 && onRestartWaitTime(user) > 0 && !user.isOp()) {
|
||||
user.sendMessage("general.errors.you-must-wait", TextVariables.NUMBER, String.valueOf(onRestartWaitTime(user)));
|
||||
return false;
|
||||
}
|
||||
if (!getIslands().hasIsland(getWorld(), user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
if (!getIslands().isOwner(getWorld(), user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.not-leader");
|
||||
return false;
|
||||
}
|
||||
if (getIslands().inTeam(getWorld(), user.getUniqueId())) {
|
||||
user.sendMessage("commands.island.reset.must-remove-members");
|
||||
return false;
|
||||
}
|
||||
if (getIWM().getResetLimit(getWorld()) >= 0 ) {
|
||||
int resetsLeft = getIWM().getResetLimit(getWorld()) - getPlayers().getResets(getWorld(), user.getUniqueId());
|
||||
if (resetsLeft <= 0) {
|
||||
user.sendMessage("commands.island.reset.none-left");
|
||||
return false;
|
||||
} else {
|
||||
// Notify how many resets are left
|
||||
user.sendMessage("commands.island.reset.resets-left", TextVariables.NUMBER, String.valueOf(resetsLeft));
|
||||
}
|
||||
}
|
||||
// Request confirmation
|
||||
if (getSettings().isResetConfirmation()) {
|
||||
this.askConfirmation(user, () -> resetIsland(user));
|
||||
return true;
|
||||
} else {
|
||||
return resetIsland(user);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean resetIsland(User user) {
|
||||
// Reset the island
|
||||
Player player = user.getPlayer();
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
// Get the player's old island
|
||||
Island oldIsland = getIslands().getIsland(getWorld(), player.getUniqueId());
|
||||
// Remove them from this island (it still exists and will be deleted later)
|
||||
getIslands().removePlayer(getWorld(), player.getUniqueId());
|
||||
// Remove money inventory etc.
|
||||
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
|
||||
user.getPlayer().getEnderChest().clear();
|
||||
}
|
||||
if (getIWM().isOnLeaveResetInventory(getWorld())) {
|
||||
user.getPlayer().getInventory().clear();
|
||||
}
|
||||
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
||||
// TODO: needs Vault
|
||||
}
|
||||
// Add a reset
|
||||
getPlayers().addReset(getWorld(), user.getUniqueId());
|
||||
// Create new island and then delete the old one
|
||||
try {
|
||||
NewIsland.builder()
|
||||
.player(user)
|
||||
.reason(Reason.RESET)
|
||||
.oldIsland(oldIsland)
|
||||
.build();
|
||||
} catch (IOException e) {
|
||||
getPlugin().logError("Could not create island for player. " + e.getMessage());
|
||||
user.sendMessage("commands.island.create.unable-create-island");
|
||||
return false;
|
||||
}
|
||||
setCooldown(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
private int onRestartWaitTime(User user) {
|
||||
if (!cooldown.containsKey(user.getUniqueId())) {
|
||||
return 0;
|
||||
}
|
||||
return (int) (System.currentTimeMillis() - cooldown.get(user.getUniqueId()) / 1000);
|
||||
}
|
||||
|
||||
private void setCooldown(User user) {
|
||||
cooldown.put(user.getUniqueId(), System.currentTimeMillis() + (getIWM().getResetLimit(getWorld()) * 1000L));
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package world.bentobox.bentobox.commands.island;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class IslandResetnameCommand extends CompositeCommand {
|
||||
|
||||
public IslandResetnameCommand(CompositeCommand islandCommand) {
|
||||
super(islandCommand, "resetname");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.name");
|
||||
setOnlyPlayer(true);
|
||||
setDescription("commands.island.resetname.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
|
||||
if (!getIslands().hasIsland(getWorld(), playerUUID)) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!getIslands().isOwner(getWorld(), playerUUID)) {
|
||||
user.sendMessage("general.errors.not-leader");
|
||||
return false;
|
||||
}
|
||||
// Resets the island name
|
||||
getIslands().getIsland(getWorld(), playerUUID).setName(null);
|
||||
|
||||
user.sendMessage("general.success");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package world.bentobox.bentobox.commands.island;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
public class IslandSethomeCommand extends CompositeCommand {
|
||||
|
||||
public IslandSethomeCommand(CompositeCommand islandCommand) {
|
||||
super(islandCommand, "sethome");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.sethome");
|
||||
setOnlyPlayer(true);
|
||||
setDescription("commands.island.sethome.description");
|
||||
new CustomIslandMultiHomeHelp(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
// Check island
|
||||
if (getPlugin().getIslands().getIsland(getWorld(), user.getUniqueId()) == null) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
if (!getPlugin().getIslands().userIsOnIsland(getWorld(), user)) {
|
||||
user.sendMessage("commands.island.sethome.must-be-on-your-island");
|
||||
return false;
|
||||
}
|
||||
if (args.isEmpty()) {
|
||||
// island sethome
|
||||
getPlugin().getPlayers().setHomeLocation(playerUUID, user.getLocation());
|
||||
user.sendMessage("commands.island.sethome.home-set");
|
||||
} else {
|
||||
// Dynamic home sizes with permissions
|
||||
int maxHomes = Util.getPermValue(user.getPlayer(), "island.maxhomes", getIWM().getMaxHomes(getWorld()));
|
||||
if (maxHomes > 1) {
|
||||
// Check the number given is a number
|
||||
int number;
|
||||
try {
|
||||
number = Integer.valueOf(args.get(0));
|
||||
if (number < 1 || number > maxHomes) {
|
||||
user.sendMessage("commands.island.sethome.num-homes", TextVariables.NUMBER, String.valueOf(maxHomes));
|
||||
return false;
|
||||
} else {
|
||||
getPlugin().getPlayers().setHomeLocation(user, user.getLocation(), number);
|
||||
user.sendMessage("commands.island.sethome.home-set");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
user.sendMessage("commands.island.sethome.num-homes", TextVariables.NUMBER, String.valueOf(maxHomes));
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package world.bentobox.bentobox.commands.island;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class IslandSetnameCommand extends CompositeCommand {
|
||||
|
||||
public IslandSetnameCommand(CompositeCommand islandCommand) {
|
||||
super(islandCommand, "setname");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.name");
|
||||
setOnlyPlayer(true);
|
||||
setParameters("commands.island.setname.parameters");
|
||||
setDescription("commands.island.setname.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
|
||||
if (!getIslands().hasIsland(getWorld(), playerUUID)) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!getIslands().isOwner(getWorld(), playerUUID)) {
|
||||
user.sendMessage("general.errors.not-leader");
|
||||
return false;
|
||||
}
|
||||
// Explain command
|
||||
if (args.isEmpty()) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Naming the island - join all the arguments with spaces.
|
||||
String name = args.stream().collect(Collectors.joining( " " ));
|
||||
|
||||
// Check if the name isn't too short or too long
|
||||
if (name.length() < getSettings().getNameMinLength()) {
|
||||
user.sendMessage("commands.island.setname.too-short", TextVariables.NUMBER, String.valueOf(getSettings().getNameMinLength()));
|
||||
return false;
|
||||
}
|
||||
if (name.length() > getSettings().getNameMaxLength()) {
|
||||
user.sendMessage("commands.island.setname.too-long", TextVariables.NUMBER, String.valueOf(getSettings().getNameMaxLength()));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the name
|
||||
if (user.isOp() || user.hasPermission(this.getPermissionPrefix() + ".island.name.format")) {
|
||||
getIslands().getIsland(getWorld(), playerUUID).setName(ChatColor.translateAlternateColorCodes('&', name));
|
||||
} else {
|
||||
getIslands().getIsland(getWorld(), playerUUID).setName(name);
|
||||
}
|
||||
|
||||
user.sendMessage("general.success");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package world.bentobox.bentobox.commands.island;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.flags.Flag;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.panels.SettingsPanel;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
* @author Poslovitch
|
||||
*/
|
||||
public class IslandSettingsCommand extends CompositeCommand {
|
||||
|
||||
public IslandSettingsCommand(CompositeCommand islandCommand) {
|
||||
super(islandCommand, "settings", "flags");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.settings");
|
||||
setOnlyPlayer(true);
|
||||
setDescription("commands.island.settings.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// Settings are only shown if you are in the right world
|
||||
if (Util.getWorld(user.getWorld()).equals(getWorld())) {
|
||||
SettingsPanel.openPanel(getPlugin(), user, Flag.Type.PROTECTION, getWorld()); //TODO keep track of history?
|
||||
return true;
|
||||
} else {
|
||||
user.sendMessage("general.errors.wrong-world");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package world.bentobox.bentobox.commands.island;
|
||||
|
||||
public class IslandSpawnCommand {
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package world.bentobox.bentobox.commands.island;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
public class IslandUnbanCommand extends CompositeCommand {
|
||||
|
||||
public IslandUnbanCommand(CompositeCommand islandCommand) {
|
||||
super(islandCommand, "unban");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.ban");
|
||||
setOnlyPlayer(true);
|
||||
setParameters("commands.island.unban.parameters");
|
||||
setDescription("commands.island.unban.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (args.size() != 1) {
|
||||
// Show help
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
// Player issuing the command must have an island
|
||||
if (!getIslands().hasIsland(getWorld(), playerUUID)) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
if (!getIslands().isOwner(getWorld(), playerUUID)) {
|
||||
user.sendMessage("general.errors.not-leader");
|
||||
return false;
|
||||
}
|
||||
// Get target player
|
||||
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player");
|
||||
return false;
|
||||
}
|
||||
// Player cannot unban themselves
|
||||
if (playerUUID.equals(targetUUID)) {
|
||||
user.sendMessage("commands.island.unban.cannot-unban-yourself");
|
||||
return false;
|
||||
}
|
||||
if (!getIslands().getIsland(getWorld(), playerUUID).isBanned(targetUUID)) {
|
||||
user.sendMessage("commands.island.unban.player-not-banned");
|
||||
return false;
|
||||
}
|
||||
// Finished error checking - start the unbanning
|
||||
User targetUser = User.getInstance(targetUUID);
|
||||
return unban(user, targetUser);
|
||||
}
|
||||
|
||||
private boolean unban(User user, User targetUser) {
|
||||
if (getIslands().getIsland(getWorld(), user.getUniqueId()).removeFromBanList(targetUser.getUniqueId())) {
|
||||
user.sendMessage("general.success");
|
||||
targetUser.sendMessage("commands.island.unban.you-are-unbanned", TextVariables.NAME, user.getName());
|
||||
return true;
|
||||
}
|
||||
// Unbanning was blocked, maybe due to an event cancellation. Fail silently.
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||
List<String> options = island.getBanned().stream().map(getPlayers()::getName).collect(Collectors.toList());
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package world.bentobox.bentobox.commands.island.team;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
public class IslandTeamCommand extends CompositeCommand {
|
||||
|
||||
private IslandTeamInviteCommand inviteCommand;
|
||||
|
||||
public IslandTeamCommand(CompositeCommand parent) {
|
||||
super(parent, "team");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.team");
|
||||
setOnlyPlayer(true);
|
||||
setDescription("commands.island.team.description");
|
||||
// Register commands
|
||||
inviteCommand = new IslandTeamInviteCommand(this);
|
||||
new IslandTeamLeaveCommand(this);
|
||||
new IslandTeamSetownerCommand(this);
|
||||
new IslandTeamKickCommand(this);
|
||||
new IslandTeamInviteAcceptCommand(this);
|
||||
new IslandTeamInviteRejectCommand(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// Player issuing the command must have an island
|
||||
UUID teamLeaderUUID = getTeamLeader(getWorld(), user);
|
||||
if (teamLeaderUUID == null) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
// Fire event so add-ons can run commands, etc.
|
||||
if (fireEvent(user)) {
|
||||
// Cancelled
|
||||
return false;
|
||||
}
|
||||
Set<UUID> teamMembers = getMembers(getWorld(), user);
|
||||
if (teamLeaderUUID.equals(playerUUID)) {
|
||||
int maxSize = inviteCommand.getMaxTeamSize(user);
|
||||
if (teamMembers.size() < maxSize) {
|
||||
user.sendMessage("commands.island.team.invite.you-can-invite", TextVariables.NUMBER, String.valueOf(maxSize - teamMembers.size()));
|
||||
} else {
|
||||
user.sendMessage("commands.island.team.invite.errors.island-is-full");
|
||||
}
|
||||
}
|
||||
// Show members of island
|
||||
getIslands().getIsland(getWorld(), playerUUID).showMembers(getPlugin(), user, getWorld());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private boolean fireEvent(User user) {
|
||||
IslandBaseEvent event = TeamEvent.builder()
|
||||
.island(getIslands()
|
||||
.getIsland(getWorld(), user.getUniqueId()))
|
||||
.reason(TeamEvent.Reason.INFO)
|
||||
.involvedPlayer(user.getUniqueId())
|
||||
.build();
|
||||
getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
return event.isCancelled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the inviteCommand
|
||||
*/
|
||||
public IslandTeamInviteCommand getInviteCommand() {
|
||||
return inviteCommand;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
package world.bentobox.bentobox.commands.island.team;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
|
||||
public class IslandTeamInviteAcceptCommand extends CompositeCommand {
|
||||
|
||||
private IslandTeamCommand itc;
|
||||
|
||||
public IslandTeamInviteAcceptCommand(IslandTeamCommand islandTeamCommand) {
|
||||
super(islandTeamCommand, "accept");
|
||||
this.itc = islandTeamCommand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.team");
|
||||
setOnlyPlayer(true);
|
||||
setDescription("commands.island.team.invite.accept.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
// Check if player has been invited
|
||||
if (!itc.getInviteCommand().getInviteList().containsKey(playerUUID)) {
|
||||
user.sendMessage("commands.island.team.invite.errors.none-invited-you");
|
||||
return false;
|
||||
}
|
||||
// Check if player is already in a team
|
||||
if (getIslands().inTeam(getWorld(), playerUUID)) {
|
||||
user.sendMessage("commands.island.team.invite.errors.you-already-are-in-team");
|
||||
return false;
|
||||
}
|
||||
// Get the team leader
|
||||
UUID prospectiveTeamLeaderUUID = itc.getInviteCommand().getInviteList().get(playerUUID);
|
||||
if (!getIslands().hasIsland(getWorld(), prospectiveTeamLeaderUUID)) {
|
||||
user.sendMessage("commands.island.team.invite.errors.invalid-invite");
|
||||
itc.getInviteCommand().getInviteList().remove(playerUUID);
|
||||
return false;
|
||||
}
|
||||
// Fire event so add-ons can run commands, etc.
|
||||
IslandBaseEvent event = TeamEvent.builder()
|
||||
.island(getIslands()
|
||||
.getIsland(getWorld(), prospectiveTeamLeaderUUID))
|
||||
.reason(TeamEvent.Reason.JOIN)
|
||||
.involvedPlayer(playerUUID)
|
||||
.build();
|
||||
getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
// Remove the invite
|
||||
itc.getInviteCommand().getInviteList().remove(playerUUID);
|
||||
// Put player into Spectator mode
|
||||
user.setGameMode(GameMode.SPECTATOR);
|
||||
// Get the player's island - may be null if the player has no island
|
||||
Island island = getIslands().getIsland(getWorld(), playerUUID);
|
||||
// Get the team's island
|
||||
Island teamIsland = getIslands().getIsland(getWorld(), prospectiveTeamLeaderUUID);
|
||||
// Clear the player's inventory
|
||||
user.getInventory().clear();
|
||||
// Move player to team's island
|
||||
User prospectiveTeamLeader = User.getInstance(prospectiveTeamLeaderUUID);
|
||||
Location newHome = getIslands().getSafeHomeLocation(getWorld(), prospectiveTeamLeader, 1);
|
||||
user.teleport(newHome);
|
||||
// Remove player as owner of the old island
|
||||
getIslands().removePlayer(getWorld(), playerUUID);
|
||||
// Remove money inventory etc. for leaving
|
||||
if (getIWM().isOnLeaveResetEnderChest(getWorld()) || getIWM().isOnJoinResetEnderChest(getWorld())) {
|
||||
user.getPlayer().getEnderChest().clear();
|
||||
}
|
||||
if (getIWM().isOnLeaveResetInventory(getWorld()) || getIWM().isOnJoinResetInventory(getWorld())) {
|
||||
user.getPlayer().getInventory().clear();
|
||||
}
|
||||
if (getSettings().isUseEconomy() && (getIWM().isOnLeaveResetMoney(getWorld()) || getIWM().isOnJoinResetMoney(getWorld()))) {
|
||||
// TODO: needs Vault
|
||||
}
|
||||
// Add the player as a team member of the new island
|
||||
getIslands().setJoinTeam(teamIsland, playerUUID);
|
||||
// Set the player's home
|
||||
getPlayers().setHomeLocation(playerUUID, user.getLocation());
|
||||
// Delete the old island
|
||||
getIslands().deleteIsland(island, true);
|
||||
// TODO Set the cooldown
|
||||
// Reset deaths
|
||||
if (getIWM().isTeamJoinDeathReset(getWorld())) {
|
||||
getPlayers().setDeaths(getWorld(), playerUUID, 0);
|
||||
}
|
||||
// Put player back into normal mode
|
||||
user.setGameMode(getIWM().getDefaultGameMode(getWorld()));
|
||||
|
||||
user.sendMessage("commands.island.team.invite.accept.you-joined-island", TextVariables.LABEL, getTopLabel());
|
||||
User inviter = User.getInstance(itc.getInviteCommand().getInviteList().get(playerUUID));
|
||||
if (inviter != null) {
|
||||
inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", TextVariables.NAME, user.getName());
|
||||
}
|
||||
getIslands().save(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,159 @@
|
||||
package world.bentobox.bentobox.commands.island.team;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
public class IslandTeamInviteCommand extends CompositeCommand {
|
||||
|
||||
private BiMap<UUID, UUID> inviteList;
|
||||
|
||||
public IslandTeamInviteCommand(CompositeCommand islandCommand) {
|
||||
super(islandCommand, "invite");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.team");
|
||||
setOnlyPlayer(true);
|
||||
setDescription("commands.island.team.invite.description");
|
||||
inviteList = HashBiMap.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
// Player issuing the command must have an island
|
||||
if (!getIslands().hasIsland(getWorld(), user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
UUID teamLeaderUUID = getTeamLeader(getWorld(), user);
|
||||
if (!(teamLeaderUUID.equals(playerUUID))) {
|
||||
user.sendMessage("general.errors.not-leader");
|
||||
return false;
|
||||
}
|
||||
if (args.isEmpty() || args.size() > 1) {
|
||||
// Invite label with no name, i.e., /island invite - tells the player who has invited them so far
|
||||
if (inviteList.containsKey(playerUUID)) {
|
||||
OfflinePlayer inviter = getPlugin().getServer().getOfflinePlayer(inviteList.get(playerUUID));
|
||||
user.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, inviter.getName());
|
||||
return true;
|
||||
}
|
||||
// Show help
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
} else {
|
||||
// Only online players can be invited
|
||||
UUID invitedPlayerUUID = getPlayers().getUUID(args.get(0));
|
||||
if (invitedPlayerUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player");
|
||||
return false;
|
||||
}
|
||||
User invitedPlayer = User.getInstance(invitedPlayerUUID);
|
||||
if (!invitedPlayer.isOnline()) {
|
||||
user.sendMessage("general.errors.offline-player");
|
||||
return false;
|
||||
}
|
||||
// Player cannot invite themselves
|
||||
if (playerUUID.equals(invitedPlayerUUID)) {
|
||||
user.sendMessage("commands.island.team.invite.errors.cannot-invite-self");
|
||||
return false;
|
||||
}
|
||||
// Check if this player can be invited to this island, or
|
||||
// whether they are still on cooldown
|
||||
long time = getPlayers().getInviteCoolDownTime(invitedPlayerUUID, getIslands().getIslandLocation(getWorld(), playerUUID));
|
||||
if (time > 0 && !user.isOp()) {
|
||||
user.sendMessage("commands.island.team.invite.errors.cooldown", TextVariables.NUMBER, String.valueOf(time));
|
||||
return false;
|
||||
}
|
||||
// Player cannot invite someone already on a team
|
||||
if (getIslands().inTeam(getWorld(), invitedPlayerUUID)) {
|
||||
user.sendMessage("commands.island.team.invite.errors.already-on-team");
|
||||
return false;
|
||||
}
|
||||
return invite(user,invitedPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean invite(User user, User invitedPlayer) {
|
||||
Set<UUID> teamMembers = getMembers(getWorld(), user);
|
||||
// Check if player has space on their team
|
||||
int maxSize = getMaxTeamSize(user);
|
||||
if (teamMembers.size() < maxSize) {
|
||||
// If that player already has an invite out then retract it.
|
||||
// Players can only have one invite one at a time - interesting
|
||||
if (inviteList.containsValue(user.getUniqueId())) {
|
||||
inviteList.inverse().remove(user.getUniqueId());
|
||||
user.sendMessage("commands.island.team.invite.removing-invite");
|
||||
}
|
||||
// Fire event so add-ons can run commands, etc.
|
||||
IslandBaseEvent event = TeamEvent.builder()
|
||||
.island(getIslands().getIsland(getWorld(), user.getUniqueId()))
|
||||
.reason(TeamEvent.Reason.INVITE)
|
||||
.involvedPlayer(invitedPlayer.getUniqueId())
|
||||
.build();
|
||||
getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
// Put the invited player (key) onto the list with inviter (value)
|
||||
// If someone else has invited a player, then this invite will overwrite the previous invite!
|
||||
inviteList.put(invitedPlayer.getUniqueId(), user.getUniqueId());
|
||||
user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, invitedPlayer.getName());
|
||||
// Send message to online player
|
||||
invitedPlayer.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, user.getName());
|
||||
invitedPlayer.sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, getLabel());
|
||||
if (getIslands().hasIsland(getWorld(), invitedPlayer.getUniqueId())) {
|
||||
invitedPlayer.sendMessage("commands.island.team.invite.you-will-lose-your-island");
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
user.sendMessage("commands.island.team.invite.errors.island-is-full");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||
if (args.isEmpty()) {
|
||||
// Don't show every player on the server. Require at least the first letter
|
||||
return Optional.empty();
|
||||
}
|
||||
List<String> options = new ArrayList<>(Util.getOnlinePlayerList(user));
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
|
||||
/**
|
||||
* Order is Invited, Inviter
|
||||
* @return the inviteList
|
||||
*/
|
||||
public BiMap<UUID, UUID> getInviteList() {
|
||||
return inviteList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum team size for this player in this game based on the permission or the world's setting
|
||||
* @param user - user
|
||||
* @return max team size of user
|
||||
*/
|
||||
public int getMaxTeamSize(User user) {
|
||||
return Util.getPermValue(user.getPlayer(), getPermissionPrefix() + "team.maxsize.", getIWM().getMaxTeamSize(getWorld()));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package world.bentobox.bentobox.commands.island.team;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
public class IslandTeamInviteRejectCommand extends CompositeCommand {
|
||||
|
||||
private IslandTeamCommand itc;
|
||||
|
||||
public IslandTeamInviteRejectCommand(IslandTeamCommand islandTeamCommand) {
|
||||
super(islandTeamCommand, "reject");
|
||||
this.itc = islandTeamCommand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.team");
|
||||
setOnlyPlayer(true);
|
||||
setDescription("commands.island.team.invite.reject.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
// Reject /island reject
|
||||
if (itc.getInviteCommand().getInviteList().containsKey(playerUUID)) {
|
||||
// Fire event so add-ons can run commands, etc.
|
||||
IslandBaseEvent event = TeamEvent.builder()
|
||||
.island(getIslands()
|
||||
.getIsland(getWorld(), itc.getInviteCommand().getInviteList().get(playerUUID)))
|
||||
.reason(TeamEvent.Reason.REJECT)
|
||||
.involvedPlayer(playerUUID)
|
||||
.build();
|
||||
getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove this player from the global invite list
|
||||
itc.getInviteCommand().getInviteList().remove(user.getUniqueId());
|
||||
user.sendMessage("commands.island.team.invite.reject.you-rejected-invite");
|
||||
|
||||
User inviter = User.getInstance(itc.getInviteCommand().getInviteList().get(playerUUID));
|
||||
inviter.sendMessage("commands.island.team.invite.reject.name-rejected-your-invite", TextVariables.NAME, user.getName());
|
||||
} else {
|
||||
// Someone typed /island reject and had not been invited
|
||||
// TODO: make the error nicer if there are invites in other worlds
|
||||
user.sendMessage("commands.island.team.invite.errors.none-invited-you");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
package world.bentobox.bentobox.commands.island.team;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
public class IslandTeamKickCommand extends CompositeCommand {
|
||||
|
||||
Set<UUID> kickSet;
|
||||
|
||||
public IslandTeamKickCommand(CompositeCommand islandTeamCommand) {
|
||||
super(islandTeamCommand, "kick");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.team");
|
||||
setOnlyPlayer(true);
|
||||
setParameters("commands.island.team.kick.parameters");
|
||||
setDescription("commands.island.team.kick.description");
|
||||
kickSet = new HashSet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (!getIslands().inTeam(getWorld(), user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-team");
|
||||
return false;
|
||||
}
|
||||
if (!getTeamLeader(getWorld(), user).equals(user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.not-leader");
|
||||
return false;
|
||||
}
|
||||
// If args are not right, show help
|
||||
if (args.size() != 1) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
// Get target
|
||||
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player");
|
||||
return false;
|
||||
}
|
||||
if (targetUUID.equals(user.getUniqueId())) {
|
||||
user.sendMessage("commands.island.kick.cannot-kick");
|
||||
return false;
|
||||
}
|
||||
if (!getIslands().getMembers(getWorld(), user.getUniqueId()).contains(targetUUID)) {
|
||||
user.sendMessage("general.errors.not-in-team");
|
||||
return false;
|
||||
}
|
||||
if (!getSettings().isKickConfirmation() || kickSet.contains(targetUUID)) {
|
||||
kickSet.remove(targetUUID);
|
||||
User.getInstance(targetUUID).sendMessage("commands.island.team.kick.leader-kicked");
|
||||
getIslands().removePlayer(getWorld(), targetUUID);
|
||||
// Remove money inventory etc.
|
||||
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
|
||||
user.getPlayer().getEnderChest().clear();
|
||||
}
|
||||
if (getIWM().isOnLeaveResetInventory(getWorld())) {
|
||||
user.getPlayer().getInventory().clear();
|
||||
}
|
||||
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
||||
// TODO: needs Vault
|
||||
}
|
||||
user.sendMessage("general.success");
|
||||
return true;
|
||||
} else {
|
||||
user.sendMessage("commands.island.team.kick.type-again");
|
||||
kickSet.add(targetUUID);
|
||||
new BukkitRunnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (kickSet.contains(targetUUID)) {
|
||||
kickSet.remove(targetUUID);
|
||||
user.sendMessage("general.errors.command-cancelled");
|
||||
}
|
||||
}}.runTaskLater(getPlugin(), getSettings().getKickWait() * 20);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package world.bentobox.bentobox.commands.island.team;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
public class IslandTeamLeaveCommand extends CompositeCommand {
|
||||
|
||||
public IslandTeamLeaveCommand(CompositeCommand islandTeamCommand) {
|
||||
super(islandTeamCommand, "leave");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.team");
|
||||
setOnlyPlayer(true);
|
||||
setDescription("commands.island.team.leave.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (!getIslands().inTeam(getWorld(), user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-team");
|
||||
return false;
|
||||
}
|
||||
if (getIslands().hasIsland(getWorld(), user.getUniqueId())) {
|
||||
user.sendMessage("commands.island.team.leave.cannot-leave");
|
||||
return false;
|
||||
}
|
||||
if (!getSettings().isLeaveConfirmation()) {
|
||||
leave(user);
|
||||
return true;
|
||||
} else {
|
||||
this.askConfirmation(user, () -> leave(user));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void leave(User user) {
|
||||
UUID leaderUUID = getIslands().getTeamLeader(getWorld(), user.getUniqueId());
|
||||
if (leaderUUID != null) {
|
||||
User.getInstance(leaderUUID).sendMessage("commands.island.team.leave.left-your-island", TextVariables.NAME, user.getName());
|
||||
}
|
||||
getIslands().setLeaveTeam(getWorld(), user.getUniqueId());
|
||||
// Remove money inventory etc.
|
||||
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
|
||||
user.getPlayer().getEnderChest().clear();
|
||||
}
|
||||
if (getIWM().isOnLeaveResetInventory(getWorld())) {
|
||||
user.getPlayer().getInventory().clear();
|
||||
}
|
||||
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
||||
// TODO: needs Vault
|
||||
}
|
||||
user.sendMessage("general.success");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package world.bentobox.bentobox.commands.island.team;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
public class IslandTeamPromoteCommand extends CompositeCommand {
|
||||
|
||||
public IslandTeamPromoteCommand(CompositeCommand islandTeamCommand, String string) {
|
||||
super(islandTeamCommand, string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.team");
|
||||
setOnlyPlayer(true);
|
||||
if (this.getLabel().equals("promote")) {
|
||||
setParameters("commands.island.team.promote.parameters");
|
||||
setDescription("commands.island.team.promote.description");
|
||||
} else {
|
||||
setParameters("commands.island.team.demote.parameters");
|
||||
setDescription("commands.island.team.demote.description");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (!getIslands().inTeam(getWorld(), user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-team");
|
||||
return true;
|
||||
}
|
||||
if (!getTeamLeader(getWorld(), user).equals(user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.not-leader");
|
||||
return true;
|
||||
}
|
||||
// If args are not right, show help
|
||||
if (args.size() != 1) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
// Get target
|
||||
User target = getPlayers().getUser(args.get(0));
|
||||
if (target == null) {
|
||||
user.sendMessage("general.errors.unknown-player");
|
||||
return true;
|
||||
}
|
||||
if (!inTeam(getWorld(), target) || !getTeamLeader(getWorld(), user).equals(getTeamLeader(getWorld(), target))) {
|
||||
user.sendMessage("general.errors.not-in-team");
|
||||
return true;
|
||||
}
|
||||
|
||||
return change(user, target);
|
||||
}
|
||||
|
||||
private boolean change(User user, User target) {
|
||||
int currentRank = getIslands().getIsland(getWorld(), user.getUniqueId()).getRank(target);
|
||||
if (this.getLabel().equals("promote")) {
|
||||
int nextRank = getPlugin().getRanksManager().getRankUpValue(currentRank);
|
||||
if (nextRank > currentRank) {
|
||||
getIslands().getIsland(getWorld(), user.getUniqueId()).setRank(target, nextRank);
|
||||
String rankName = user.getTranslation(getPlugin().getRanksManager().getRank(nextRank));
|
||||
user.sendMessage("commands.island.team.promote.success", TextVariables.NAME, target.getName(), TextVariables.RANK, rankName);
|
||||
return true;
|
||||
} else {
|
||||
user.sendMessage("commands.island.team.promote.failure");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Demote
|
||||
int prevRank = getPlugin().getRanksManager().getRankDownValue(currentRank);
|
||||
if (prevRank < currentRank) {
|
||||
getIslands().getIsland(getWorld(), user.getUniqueId()).setRank(target, prevRank);
|
||||
String rankName = user.getTranslation(getPlugin().getRanksManager().getRank(prevRank));
|
||||
user.sendMessage("commands.island.team.demote.success", TextVariables.NAME, target.getName(), TextVariables.RANK, rankName);
|
||||
return true;
|
||||
} else {
|
||||
user.sendMessage("commands.island.team.demote.failure");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package world.bentobox.bentobox.commands.island.team;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
public class IslandTeamSetownerCommand extends CompositeCommand {
|
||||
|
||||
public IslandTeamSetownerCommand(CompositeCommand islandTeamCommand) {
|
||||
super(islandTeamCommand, "setleader");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.team");
|
||||
setOnlyPlayer(true);
|
||||
setParameters("commands.island.team.setowner.parameters");
|
||||
setDescription("commands.island.team.setowner.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
// Can use if in a team
|
||||
boolean inTeam = getPlugin().getIslands().inTeam(getWorld(), playerUUID);
|
||||
UUID teamLeaderUUID = getTeamLeader(getWorld(), user);
|
||||
if (!(inTeam && teamLeaderUUID.equals(playerUUID))) {
|
||||
user.sendMessage("general.errors.not-leader");
|
||||
return false;
|
||||
}
|
||||
// If args are not right, show help
|
||||
if (args.size() != 1) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player");
|
||||
return false;
|
||||
}
|
||||
if (!getIslands().inTeam(getWorld(), playerUUID)) {
|
||||
user.sendMessage("general.errors.no-team");
|
||||
return false;
|
||||
}
|
||||
if (targetUUID.equals(playerUUID)) {
|
||||
user.sendMessage("commands.island.team.setowner.errors.cant-transfer-to-yourself");
|
||||
return false;
|
||||
}
|
||||
if (!getPlugin().getIslands().getMembers(getWorld(), playerUUID).contains(targetUUID)) {
|
||||
user.sendMessage("commands.island.team.setowner.errors.target-is-not-member");
|
||||
return false;
|
||||
}
|
||||
// Fire event so add-ons can run commands, etc.
|
||||
IslandBaseEvent event = TeamEvent.builder()
|
||||
.island(getIslands()
|
||||
.getIsland(getWorld(), playerUUID))
|
||||
.reason(TeamEvent.Reason.MAKELEADER)
|
||||
.involvedPlayer(targetUUID)
|
||||
.build();
|
||||
getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
getIslands().makeLeader(getWorld(), user, targetUUID, getPermissionPrefix());
|
||||
getIslands().save(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
List<String> options = new ArrayList<>();
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||
for (UUID member : getPlugin().getIslands().getMembers(getWorld(), user.getUniqueId())) {
|
||||
options.add(getPlugin().getServer().getOfflinePlayer(member).getName());
|
||||
}
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user