mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-03-19 01:59:13 +01:00
WIP
This commit is contained in:
parent
4ddb204fcf
commit
bb9ed87175
@ -1,9 +1,14 @@
|
|||||||
package world.bentobox.bentobox.api.commands.admin.team;
|
package world.bentobox.bentobox.api.commands.admin.team;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
|
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
||||||
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
@ -17,7 +22,11 @@ import world.bentobox.bentobox.util.Util;
|
|||||||
*
|
*
|
||||||
* @author tastybento
|
* @author tastybento
|
||||||
*/
|
*/
|
||||||
public class AdminTeamSetownerCommand extends CompositeCommand {
|
public class AdminTeamSetownerCommand extends ConfirmableCommand {
|
||||||
|
|
||||||
|
private @Nullable UUID targetUUID;
|
||||||
|
private Island island;
|
||||||
|
private @Nullable UUID previousOwnerUUID;
|
||||||
|
|
||||||
public AdminTeamSetownerCommand(CompositeCommand parent) {
|
public AdminTeamSetownerCommand(CompositeCommand parent) {
|
||||||
super(parent, "setowner");
|
super(parent, "setowner");
|
||||||
@ -28,17 +37,19 @@ public class AdminTeamSetownerCommand extends CompositeCommand {
|
|||||||
setPermission("mod.team.setowner");
|
setPermission("mod.team.setowner");
|
||||||
setParametersHelp("commands.admin.team.setowner.parameters");
|
setParametersHelp("commands.admin.team.setowner.parameters");
|
||||||
setDescription("commands.admin.team.setowner.description");
|
setDescription("commands.admin.team.setowner.description");
|
||||||
|
this.setOnlyPlayer(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(User user, String label, List<String> args) {
|
public boolean canExecute(User user, String label, List<String> args) {
|
||||||
// If args are not right, show help
|
// If args are not right, show help
|
||||||
if (args.size() != 1) {
|
if (args.size() != 1) {
|
||||||
showHelp(this, user);
|
showHelp(this, user);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get target
|
// Get target
|
||||||
UUID targetUUID = Util.getUUID(args.get(0));
|
targetUUID = Util.getUUID(args.get(0));
|
||||||
if (targetUUID == null) {
|
if (targetUUID == null) {
|
||||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||||
return false;
|
return false;
|
||||||
@ -47,16 +58,33 @@ public class AdminTeamSetownerCommand extends CompositeCommand {
|
|||||||
user.sendMessage("general.errors.not-in-team");
|
user.sendMessage("general.errors.not-in-team");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Island island = getIslands().getPrimaryIsland(getWorld(), targetUUID);
|
// Check that user is on an island
|
||||||
UUID previousOwnerUUID = island.getOwner();
|
Optional<Island> opIsland = getIslands().getIslandAt(user.getLocation());
|
||||||
|
if (opIsland.isEmpty()) {
|
||||||
|
user.sendMessage("commands.admin.team.setowner.must-be-on-island");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
island = opIsland.get();
|
||||||
|
previousOwnerUUID = island.getOwner();
|
||||||
if (targetUUID.equals(previousOwnerUUID)) {
|
if (targetUUID.equals(previousOwnerUUID)) {
|
||||||
user.sendMessage("commands.admin.team.setowner.already-owner", TextVariables.NAME, args.get(0));
|
user.sendMessage("commands.admin.team.setowner.already-owner", TextVariables.NAME, args.get(0));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Get the User corresponding to the current owner
|
public boolean execute(User user, String label, List<String> args) {
|
||||||
|
Objects.requireNonNull(island);
|
||||||
|
Objects.requireNonNull(targetUUID);
|
||||||
|
|
||||||
|
this.askConfirmation(user, user.getTranslation("commands.admin.team.setowner.confirmation", TextVariables.NAME,
|
||||||
|
args.get(0), TextVariables.XYZ, Util.xyz(island.getCenter().toVector())), () -> changeOwner(user));
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void changeOwner(User user) {
|
||||||
User target = User.getInstance(targetUUID);
|
User target = User.getInstance(targetUUID);
|
||||||
|
|
||||||
// Fire event so add-ons know
|
// Fire event so add-ons know
|
||||||
// Call the setowner event
|
// Call the setowner event
|
||||||
TeamEvent.builder().island(island).reason(TeamEvent.Reason.SETOWNER).involvedPlayer(targetUUID).admin(true)
|
TeamEvent.builder().island(island).reason(TeamEvent.Reason.SETOWNER).involvedPlayer(targetUUID).admin(true)
|
||||||
@ -70,8 +98,8 @@ public class AdminTeamSetownerCommand extends CompositeCommand {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Make new owner
|
// Make new owner
|
||||||
getIslands().setOwner(getWorld(), user, targetUUID);
|
getIslands().setOwner(user, targetUUID, island, RanksManager.MEMBER_RANK);
|
||||||
user.sendMessage("commands.admin.team.setowner.success", TextVariables.NAME, args.get(0));
|
user.sendMessage("commands.admin.team.setowner.success", TextVariables.NAME, target.getName());
|
||||||
|
|
||||||
// Call the rank change event for the old island owner
|
// Call the rank change event for the old island owner
|
||||||
if (previousOwnerUUID != null) {
|
if (previousOwnerUUID != null) {
|
||||||
@ -80,6 +108,6 @@ public class AdminTeamSetownerCommand extends CompositeCommand {
|
|||||||
.reason(IslandEvent.Reason.RANK_CHANGE)
|
.reason(IslandEvent.Reason.RANK_CHANGE)
|
||||||
.rankChange(RanksManager.OWNER_RANK, island.getRank(previousOwnerUUID)).build();
|
.rankChange(RanksManager.OWNER_RANK, island.getRank(previousOwnerUUID)).build();
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1520,7 +1520,7 @@ public class IslandsManager {
|
|||||||
/**
|
/**
|
||||||
* Sets this target as the owner for this island
|
* Sets this target as the owner for this island
|
||||||
*
|
*
|
||||||
* @param user previous owner
|
* @param user user making the change
|
||||||
* @param targetUUID new owner
|
* @param targetUUID new owner
|
||||||
* @param island island to register
|
* @param island island to register
|
||||||
* @param rank rank to which to set old owner.
|
* @param rank rank to which to set old owner.
|
||||||
@ -1528,8 +1528,8 @@ public class IslandsManager {
|
|||||||
public void setOwner(User user, UUID targetUUID, Island island, int rank) {
|
public void setOwner(User user, UUID targetUUID, Island island, int rank) {
|
||||||
islandCache.setOwner(island, targetUUID);
|
islandCache.setOwner(island, targetUUID);
|
||||||
// Set old owner as sub-owner on island.
|
// Set old owner as sub-owner on island.
|
||||||
if (rank > RanksManager.VISITOR_RANK) {
|
if (rank > RanksManager.VISITOR_RANK && island.getOwner() != null) {
|
||||||
island.setRank(user, rank);
|
island.setRank(island.getOwner(), rank);
|
||||||
}
|
}
|
||||||
|
|
||||||
user.sendMessage("commands.island.team.setowner.name-is-the-owner", "[name]",
|
user.sendMessage("commands.island.team.setowner.name-is-the-owner", "[name]",
|
||||||
|
@ -144,6 +144,8 @@ commands:
|
|||||||
parameters: <player>
|
parameters: <player>
|
||||||
description: transfers island ownership to the player
|
description: transfers island ownership to the player
|
||||||
already-owner: '&c [name] is already the owner of this island!'
|
already-owner: '&c [name] is already the owner of this island!'
|
||||||
|
must-be-on-island: '&c You must be on the island to set the owner'
|
||||||
|
confirmation: '&a Are you sure you want to set [name] to be the owner of the island at [xyz]?'
|
||||||
success: '&b [name]&a is now the owner of this island.'
|
success: '&b [name]&a is now the owner of this island.'
|
||||||
range:
|
range:
|
||||||
description: admin island range command
|
description: admin island range command
|
||||||
|
Loading…
Reference in New Issue
Block a user