1
0
mirror of https://github.com/BentoBoxWorld/BentoBox.git synced 2024-12-31 21:47:58 +01:00

Added make leader (WIP)

This commit is contained in:
tastybento 2017-08-08 20:49:06 -07:00
parent 95c80a89f8
commit 389b9f52f4
3 changed files with 437 additions and 340 deletions
locales
plugin.yml
src/main/java/us/tastybento/bskyblock/commands

View File

@ -41,6 +41,7 @@ general:
no-island: "You do not have an island!"
not-leader: "You are not the leader of your island!"
offline-player: "That player is offline or doesn't exist."
unknown-player: "Unknown player!"
# TODO: These are legacy strings and should be converted to a better format but will do for now
acidBottle: "Acid Bottle"

View File

@ -2,7 +2,7 @@ name: BSkyBlock
main: us.tastybento.bskyblock.BSkyBlock
version: ${version}
authors: [Tastybento, Poslovitch]
authors: [tastybento, Poslovitch]
depend: [Vault]
softdepend: [Herochat, DeluxeChat, PlaceholderAPI, MVdWPlaceholderAPI]
@ -16,11 +16,11 @@ commands:
aliases: [is, island]
usage: |
/island help
asadmin:
bsadmin:
description: Admin commands
usage: |
/asadmin
asc:
/bsadmin
bsc:
description: Game challenges
aliases: [c, challenge, aschallenge, challenges]
usage: |

View File

@ -721,7 +721,7 @@ public class IslandCommand extends AbstractCommand {
leavingPlayers.remove(playerUUID);
// Remove from team
if (!plugin.getIslands().setLeaveTeam(playerUUID)) {
//Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).leaveerrorYouCannotLeaveIsland);
//Util.sendMessage(player, ChatColor.RED + plugin.getLocale(playerUUID).get("leaveerrorYouCannotLeaveIsland);
// If this is canceled, fail silently
return;
}
@ -870,7 +870,7 @@ public class IslandCommand extends AbstractCommand {
@Override
public CanUseResp canUse(CommandSender sender) {
if (VaultHelper.hasPerm(player, Settings.PERMPREFIX + "team.create")) {
if (VaultHelper.hasPerm(player, Settings.PERMPREFIX + "team.join")) {
return new CanUseResp(true);
}
return new CanUseResp(ChatColor.RED + plugin.getLocale(sender).get("general.errors.no-permission"));
@ -878,7 +878,21 @@ public class IslandCommand extends AbstractCommand {
@Override
public void execute(CommandSender sender, String[] args) {
// Reject /island reject
if (inviteList.containsKey(player.getUniqueId())) {
Util.sendMessage(player, ChatColor.YELLOW + plugin.getLocale(playerUUID).get("reject.youHaveRejectedInvitation"));
// If the player is online still then tell them directly
// about the rejection
if (Bukkit.getPlayer(inviteList.get(player.getUniqueId())) != null) {
Util.sendMessage(Bukkit.getPlayer(inviteList.get(playerUUID)),
ChatColor.RED + plugin.getLocale(playerUUID).get("reject.nameHasRejectedInvite").replace("[name]", player.getName()));
}
// Remove this player from the global invite list
inviteList.remove(player.getUniqueId());
} else {
// Someone typed /island reject and had not been invited
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(playerUUID).get("reject.youHaveNotBeenInvited"));
}
}
@Override
@ -905,7 +919,89 @@ public class IslandCommand extends AbstractCommand {
@Override
public void execute(CommandSender sender, String[] args) {
UUID targetPlayer = plugin.getPlayers().getUUID(args[0]);
if (targetPlayer == null) {
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(playerUUID).get("general.errors.unknown-player"));
return;
}
if (!plugin.getPlayers().inTeam(playerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(playerUUID).get("makeLeader.errorYouMustBeInTeam"));
return;
}
if (teamLeaderUUID.equals(playerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(playerUUID).get("makeLeader.errorNotYourIsland"));
return;
}
if (targetPlayer.equals(playerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(playerUUID).get("makeLeader.errorGeneralError"));
return;
}
if (!teamMembers.contains(targetPlayer)) {
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(playerUUID).get("makeLeader.errorThatPlayerIsNotInTeam"));
return;
}
// targetPlayer is the new leader
//plugin.getIslands().getIsland(playerUUID).makeLeader(targetPlayer);
Util.sendMessage(player, ChatColor.GREEN
+ plugin.getLocale(playerUUID).get("makeLeader.nameIsNowTheOwner").replace("[name]", plugin.getPlayers().getName(targetPlayer)));
// Check if online
Player target = plugin.getServer().getPlayer(targetPlayer);
if (target == null) {
// TODO offline messaging
//plugin.getMessages().setMessage(targetPlayer, plugin.getLocale(playerUUID).get("makeLeader.youAreNowTheOwner"));
} else {
// Online
Util.sendMessage(plugin.getServer().getPlayer(targetPlayer), ChatColor.GREEN + plugin.getLocale(targetPlayer).get("makeLeader.youAreNowTheOwner"));
// Check if new leader has a lower range permission than the island size
boolean hasARangePerm = false;
int range = Settings.islandProtectionRange;
// Check for zero protection range
Island islandByOwner = plugin.getIslands().getIsland(targetPlayer);
if (islandByOwner.getProtectionRange() == 0) {
plugin.getLogger().warning("Player " + player.getName() + "'s island had a protection range of 0. Setting to default " + range);
islandByOwner.setProtectionRange(range);
}
for (PermissionAttachmentInfo perms : target.getEffectivePermissions()) {
if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.range.")) {
if (perms.getPermission().contains(Settings.PERMPREFIX + "island.range.*")) {
// Ignore
break;
} else {
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.range.");
if (spl.length > 1) {
if (!NumberUtils.isDigits(spl[1])) {
plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
} else {
hasARangePerm = true;
range = Math.max(range, Integer.valueOf(spl[1]));
}
}
}
}
}
// Only set the island range if the player has a perm to override the default
if (hasARangePerm) {
// Do some sanity checking
if (range % 2 != 0) {
range--;
}
// Get island range
// Range can go up or down
if (range != islandByOwner.getProtectionRange()) {
Util.sendMessage(player, ChatColor.GOLD + plugin.getLocale(targetPlayer).get("admin.SetRangeUpdated").replace("[number]", String.valueOf(range)));
Util.sendMessage(target, ChatColor.GOLD + plugin.getLocale(targetPlayer).get("admin.SetRangeUpdated").replace("[number]", String.valueOf(range)));
plugin.getLogger().info(
"Makeleader: Island protection range changed from " + islandByOwner.getProtectionRange() + " to "
+ range + " for " + player.getName() + " due to permission.");
}
islandByOwner.setProtectionRange(range);
}
}
plugin.getIslands().save(true);
}
@Override