2018-08-03 04:26:46 +02:00
|
|
|
package world.bentobox.bentobox.api.commands.admin.team;
|
2018-08-01 17:29:09 +02:00
|
|
|
|
2019-07-05 01:54:05 +02:00
|
|
|
import java.util.List;
|
2021-09-19 02:59:32 +02:00
|
|
|
import java.util.Objects;
|
2019-07-05 01:54:05 +02:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2018-08-01 17:29:09 +02:00
|
|
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
2020-04-04 18:58:13 +02:00
|
|
|
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
2019-02-03 05:40:44 +01:00
|
|
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
2018-09-15 10:39:16 +02:00
|
|
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
2018-08-01 17:29:09 +02:00
|
|
|
import world.bentobox.bentobox.api.user.User;
|
2019-02-03 05:40:44 +01:00
|
|
|
import world.bentobox.bentobox.database.objects.Island;
|
2020-04-04 18:58:13 +02:00
|
|
|
import world.bentobox.bentobox.managers.RanksManager;
|
2020-04-23 21:16:09 +02:00
|
|
|
import world.bentobox.bentobox.util.Util;
|
2018-10-28 10:19:14 +01:00
|
|
|
|
2019-04-28 11:21:58 +02:00
|
|
|
/**
|
|
|
|
* Sets the owner of an island.
|
|
|
|
* @author tastybento
|
|
|
|
*/
|
2018-10-28 10:27:01 +01:00
|
|
|
public class AdminTeamSetownerCommand extends CompositeCommand {
|
2018-08-01 17:29:09 +02:00
|
|
|
|
2018-10-28 10:27:01 +01:00
|
|
|
public AdminTeamSetownerCommand(CompositeCommand parent) {
|
2018-10-28 10:19:14 +01:00
|
|
|
super(parent, "setowner");
|
2020-04-07 22:38:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setup() {
|
2023-06-18 22:55:21 +02:00
|
|
|
setPermission("mod.team.setowner");
|
2018-10-28 10:19:14 +01:00
|
|
|
setParametersHelp("commands.admin.team.setowner.parameters");
|
|
|
|
setDescription("commands.admin.team.setowner.description");
|
2018-08-01 17:29:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
2020-04-23 21:16:09 +02:00
|
|
|
UUID targetUUID = Util.getUUID(args.get(0));
|
2018-08-01 17:29:09 +02:00
|
|
|
if (targetUUID == null) {
|
2018-09-15 10:39:16 +02:00
|
|
|
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
2018-08-01 17:29:09 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!getIslands().inTeam(getWorld(), targetUUID)) {
|
|
|
|
user.sendMessage("general.errors.not-in-team");
|
|
|
|
return false;
|
|
|
|
}
|
2020-05-09 11:39:17 +02:00
|
|
|
|
|
|
|
UUID previousOwnerUUID = getIslands().getOwner(getWorld(), targetUUID);
|
|
|
|
if (targetUUID.equals(previousOwnerUUID)) {
|
2019-04-28 11:15:26 +02:00
|
|
|
user.sendMessage("commands.admin.team.setowner.already-owner", TextVariables.NAME, args.get(0));
|
2018-08-01 17:29:09 +02:00
|
|
|
return false;
|
|
|
|
}
|
2020-05-09 11:39:17 +02:00
|
|
|
|
|
|
|
// Get the User corresponding to the current owner
|
2020-04-04 18:58:13 +02:00
|
|
|
User target = User.getInstance(targetUUID);
|
2020-05-09 11:39:17 +02:00
|
|
|
|
2019-02-03 05:40:44 +01:00
|
|
|
// Fire event so add-ons know
|
2021-09-19 02:59:32 +02:00
|
|
|
Island island = Objects.requireNonNull(getIslands().getIsland(getWorld(), targetUUID));
|
2020-05-09 11:39:17 +02:00
|
|
|
// Call the setowner event
|
2020-01-07 19:15:12 +01:00
|
|
|
TeamEvent.builder()
|
|
|
|
.island(island)
|
|
|
|
.reason(TeamEvent.Reason.SETOWNER)
|
|
|
|
.involvedPlayer(targetUUID)
|
|
|
|
.admin(true)
|
|
|
|
.build();
|
2020-05-09 11:39:17 +02:00
|
|
|
|
|
|
|
// Call the rank change event for the new island owner
|
2020-05-13 16:17:06 +02:00
|
|
|
// We need to call it BEFORE the actual change, in order to retain the player's previous rank.
|
2020-04-04 18:58:13 +02:00
|
|
|
IslandEvent.builder()
|
2020-04-23 21:16:09 +02:00
|
|
|
.island(island)
|
|
|
|
.involvedPlayer(targetUUID)
|
|
|
|
.admin(true)
|
|
|
|
.reason(IslandEvent.Reason.RANK_CHANGE)
|
|
|
|
.rankChange(island.getRank(target), RanksManager.OWNER_RANK)
|
|
|
|
.build();
|
2020-05-09 11:39:17 +02:00
|
|
|
|
2020-05-13 16:17:06 +02:00
|
|
|
// Make new owner
|
|
|
|
getIslands().setOwner(getWorld(), user, targetUUID);
|
|
|
|
user.sendMessage("commands.admin.team.setowner.success", TextVariables.NAME, args.get(0));
|
|
|
|
|
2020-05-09 11:39:17 +02:00
|
|
|
// Call the rank change event for the old island owner
|
2021-09-19 02:59:32 +02:00
|
|
|
if (previousOwnerUUID != null) {
|
|
|
|
// We need to call it AFTER the actual change.
|
|
|
|
IslandEvent.builder()
|
|
|
|
.island(island)
|
|
|
|
.involvedPlayer(previousOwnerUUID)
|
|
|
|
.admin(true)
|
|
|
|
.reason(IslandEvent.Reason.RANK_CHANGE)
|
|
|
|
.rankChange(RanksManager.OWNER_RANK, island.getRank(previousOwnerUUID))
|
|
|
|
.build();
|
|
|
|
}
|
2018-08-01 17:29:09 +02:00
|
|
|
return true;
|
|
|
|
}
|
2018-10-28 10:19:14 +01:00
|
|
|
}
|