mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-22 17:18:47 +01:00
Added sethome, sethome #, go # commands.
Fixed perms for other commands.
This commit is contained in:
parent
44f1e296b0
commit
d09889e31b
@ -71,6 +71,12 @@ help:
|
|||||||
settings: "display island settings"
|
settings: "display island settings"
|
||||||
language: "select language"
|
language: "select language"
|
||||||
|
|
||||||
|
sethome:
|
||||||
|
error:
|
||||||
|
NumHomes: "Homes can be 1 to [max]"
|
||||||
|
NotOnIsland: "You must be within your island boundaries to set home!"
|
||||||
|
homeSet: "Your island home has been set to your current location."
|
||||||
|
|
||||||
# TODO: These are legacy strings and should be converted to a better format but will do for now
|
# TODO: These are legacy strings and should be converted to a better format but will do for now
|
||||||
acidBottle: "Acid Bottle"
|
acidBottle: "Acid Bottle"
|
||||||
acidBucket: "Acid Bucket"
|
acidBucket: "Acid Bucket"
|
||||||
@ -404,6 +410,7 @@ island:
|
|||||||
subtitle: "by tastybento"
|
subtitle: "by tastybento"
|
||||||
subtitlecolor: "blue"
|
subtitlecolor: "blue"
|
||||||
teleport: "Teleporting you to your island. (/[label] help for more info)"
|
teleport: "Teleporting you to your island. (/[label] help for more info)"
|
||||||
|
teleported: "Teleported to home #[number]"
|
||||||
title: "BSkyBlock"
|
title: "BSkyBlock"
|
||||||
titlecolor: "gold"
|
titlecolor: "gold"
|
||||||
unlimited: "Unlimited"
|
unlimited: "Unlimited"
|
||||||
@ -570,11 +577,7 @@ resetchallenge:
|
|||||||
errorChallengeDoesNotExist: "Challenge doesn't exist or isn't yet completed"
|
errorChallengeDoesNotExist: "Challenge doesn't exist or isn't yet completed"
|
||||||
schematics:
|
schematics:
|
||||||
title: "Select island..."
|
title: "Select island..."
|
||||||
sethome:
|
|
||||||
errorNoIsland: "You are not part of an island. Returning you the spawn area!"
|
|
||||||
errorNotOnIsland: "You must be within your island boundaries to set home!"
|
|
||||||
errorNumHomes: "Homes can be 1 to [max]"
|
|
||||||
homeSet: "Your island home has been set to your current location."
|
|
||||||
settingsReset:
|
settingsReset:
|
||||||
done: "Done."
|
done: "Done."
|
||||||
inprogress: "Protection settings being reset, please wait..."
|
inprogress: "Protection settings being reset, please wait..."
|
||||||
|
10
plugin.yml
10
plugin.yml
@ -31,11 +31,17 @@ permissions:
|
|||||||
children:
|
children:
|
||||||
bskyblock.island.*:
|
bskyblock.island.*:
|
||||||
children:
|
children:
|
||||||
|
bskyblock.island.create:
|
||||||
|
description: Allow island command usage
|
||||||
|
default: true
|
||||||
bskyblock.island.home:
|
bskyblock.island.home:
|
||||||
description: Allow teleporting to player island
|
description: Allow teleporting to player island
|
||||||
default: true
|
default: true
|
||||||
bskyblock.island.create:
|
bskyblock.island.reset:
|
||||||
description: Let the player use the /island command
|
description: Player can use the island reset or restart command
|
||||||
|
default: true
|
||||||
|
bskyblock.island.sethome:
|
||||||
|
description: Let the player use the sethome command
|
||||||
default: true
|
default: true
|
||||||
bskyblock.island.info:
|
bskyblock.island.info:
|
||||||
description: Let the player check their island level
|
description: Let the player check their island level
|
||||||
|
@ -153,7 +153,17 @@ public class IslandCommand extends AbstractCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
getIslands().homeTeleport(player);
|
if (isPlayer) {
|
||||||
|
if (args.length == 1 && NumberUtils.isDigits(args[0])) {
|
||||||
|
int homeValue = Integer.valueOf(args[0]);
|
||||||
|
int maxHomes = Util.getPermValue(player, Settings.PERMPREFIX + "island.maxhomes", Settings.maxHomes);
|
||||||
|
if (homeValue > 1 && homeValue <= maxHomes) {
|
||||||
|
getIslands().homeTeleport(player, homeValue);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getIslands().homeTeleport(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -163,9 +173,10 @@ public class IslandCommand extends AbstractCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] usage(CommandSender sender) {
|
public String[] usage(CommandSender sender) {
|
||||||
// TODO check if multiple homes
|
int maxHomes = Util.getPermValue((Player)sender, Settings.PERMPREFIX + "island.maxhomes", Settings.maxHomes);
|
||||||
if (VaultHelper.hasPerm((Player) sender, "todo"))
|
if (isPlayer && maxHomes > 1) {
|
||||||
return new String[]{"[1-x]", getLocale(sender).get("help.island.go-homes")};
|
return new String[]{"[1 - " + maxHomes + "]", getLocale(player).get("help.island.go-homes")};
|
||||||
|
}
|
||||||
return new String[]{null, getLocale(sender).get("help.island.go")};
|
return new String[]{null, getLocale(sender).get("help.island.go")};
|
||||||
}
|
}
|
||||||
}.alias("go").alias("home").alias("h"));
|
}.alias("go").alias("home").alias("h"));
|
||||||
@ -340,12 +351,46 @@ public class IslandCommand extends AbstractCommand {
|
|||||||
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.sethome")) {
|
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.sethome")) {
|
||||||
return new CanUseResp(getLocale(sender).get("general.errors.no-permission"));
|
return new CanUseResp(getLocale(sender).get("general.errors.no-permission"));
|
||||||
}
|
}
|
||||||
return new CanUseResp(false);
|
return new CanUseResp(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
|
// Check island
|
||||||
|
if (plugin.getIslands().getIsland(player.getUniqueId()) == null) {
|
||||||
|
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(playerUUID).get("general.errors.no-island"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!plugin.getIslands().playerIsOnIsland(player)) {
|
||||||
|
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(playerUUID).get("sethome.error.NotOnIsland"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (args.length == 0) {
|
||||||
|
// island sethome
|
||||||
|
plugin.getPlayers().setHomeLocation(playerUUID, player.getLocation());
|
||||||
|
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(playerUUID).get("sethome.homeSet"));
|
||||||
|
return;
|
||||||
|
} else if (args.length == 1) {
|
||||||
|
// Dynamic home sizes with permissions
|
||||||
|
int maxHomes = Util.getPermValue(player, Settings.PERMPREFIX + "island.maxhomes", Settings.maxHomes);
|
||||||
|
if (maxHomes > 1) {
|
||||||
|
// Check the number given is a number
|
||||||
|
int number = 0;
|
||||||
|
try {
|
||||||
|
number = Integer.valueOf(args[0]);
|
||||||
|
if (number < 1 || number > maxHomes) {
|
||||||
|
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(playerUUID).get("sethome.error.NumHomes").replace("[max]",String.valueOf(maxHomes)));
|
||||||
|
} else {
|
||||||
|
plugin.getPlayers().setHomeLocation(playerUUID, player.getLocation(), number);
|
||||||
|
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(playerUUID).get("sethome.homeSet"));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(playerUUID).get("sethome.error.NumHomes").replace("[max]",String.valueOf(maxHomes)));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(playerUUID).get("general.errors.no-permission"));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -355,6 +400,10 @@ public class IslandCommand extends AbstractCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] usage(CommandSender sender) {
|
public String[] usage(CommandSender sender) {
|
||||||
|
int maxHomes = Util.getPermValue((Player)sender, Settings.PERMPREFIX + "island.maxhomes", Settings.maxHomes);
|
||||||
|
if (isPlayer && maxHomes > 1) {
|
||||||
|
return new String[]{"[1 - " + maxHomes + "]", getLocale(sender).get("help.island.sethome")};
|
||||||
|
}
|
||||||
return new String[]{null, getLocale(sender).get("help.island.sethome")};
|
return new String[]{null, getLocale(sender).get("help.island.sethome")};
|
||||||
}
|
}
|
||||||
}.alias("sethome"));
|
}.alias("sethome"));
|
||||||
|
@ -529,7 +529,7 @@ public class IslandsManager {
|
|||||||
if (number ==1 ) {
|
if (number ==1 ) {
|
||||||
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(player.getUniqueId()).get("island.teleport").replace("[label]", Settings.ISLANDCOMMAND));
|
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(player.getUniqueId()).get("island.teleport").replace("[label]", Settings.ISLANDCOMMAND));
|
||||||
} else {
|
} else {
|
||||||
Util.sendMessage(player, ChatColor.GREEN + "teleported to #" + number);
|
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(player.getUniqueId()).get("island.teleported").replace("[number]", String.valueOf(number)));
|
||||||
}
|
}
|
||||||
// Exit spectator mode if in it
|
// Exit spectator mode if in it
|
||||||
if (player.getGameMode().equals(GameMode.SPECTATOR)) {
|
if (player.getGameMode().equals(GameMode.SPECTATOR)) {
|
||||||
@ -558,9 +558,8 @@ public class IslandsManager {
|
|||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG: Home location " + l);
|
plugin.getLogger().info("DEBUG: Home location " + l);
|
||||||
if (l != null) {
|
if (l != null) {
|
||||||
// Homes are stored as integers and need correcting to be more central
|
|
||||||
if (isSafeLocation(l)) {
|
if (isSafeLocation(l)) {
|
||||||
return l.clone().add(new Vector(0.5D,0,0.5D));
|
return l;
|
||||||
}
|
}
|
||||||
// To cover slabs, stairs and other half blocks, try one block above
|
// To cover slabs, stairs and other half blocks, try one block above
|
||||||
Location lPlusOne = l.clone();
|
Location lPlusOne = l.clone();
|
||||||
@ -569,7 +568,7 @@ public class IslandsManager {
|
|||||||
if (isSafeLocation(lPlusOne)) {
|
if (isSafeLocation(lPlusOne)) {
|
||||||
// Adjust the home location accordingly
|
// Adjust the home location accordingly
|
||||||
plugin.getPlayers().setHomeLocation(playerUUID, lPlusOne, number);
|
plugin.getPlayers().setHomeLocation(playerUUID, lPlusOne, number);
|
||||||
return lPlusOne.clone().add(new Vector(0.5D,0,0.5D));
|
return lPlusOne;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -585,7 +584,7 @@ public class IslandsManager {
|
|||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG:island loc is safe");
|
plugin.getLogger().info("DEBUG:island loc is safe");
|
||||||
plugin.getPlayers().setHomeLocation(playerUUID, l, number);
|
plugin.getPlayers().setHomeLocation(playerUUID, l, number);
|
||||||
return l.clone().add(new Vector(0.5D,0,0.5D));
|
return l;
|
||||||
} else {
|
} else {
|
||||||
// try team leader's home
|
// try team leader's home
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
@ -598,7 +597,7 @@ public class IslandsManager {
|
|||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG: team leader's home is safe");
|
plugin.getLogger().info("DEBUG: team leader's home is safe");
|
||||||
plugin.getPlayers().setHomeLocation(playerUUID, tlh, number);
|
plugin.getPlayers().setHomeLocation(playerUUID, tlh, number);
|
||||||
return tlh.clone().add(new Vector(0.5D,0,0.5D));
|
return tlh;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -252,6 +252,7 @@ public class PlayersManager{
|
|||||||
public void setHomeLocation(UUID playerUUID, Location location, int number) {
|
public void setHomeLocation(UUID playerUUID, Location location, int number) {
|
||||||
addPlayer(playerUUID);
|
addPlayer(playerUUID);
|
||||||
playerCache.get(playerUUID).setHomeLocation(location,number);
|
playerCache.get(playerUUID).setHomeLocation(location,number);
|
||||||
|
this.save(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -262,6 +263,7 @@ public class PlayersManager{
|
|||||||
public void setHomeLocation(UUID playerUUID, Location location) {
|
public void setHomeLocation(UUID playerUUID, Location location) {
|
||||||
addPlayer(playerUUID);
|
addPlayer(playerUUID);
|
||||||
playerCache.get(playerUUID).setHomeLocation(location,1);
|
playerCache.get(playerUUID).setHomeLocation(location,1);
|
||||||
|
this.save(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,7 +62,7 @@ public class Players extends DataObject {
|
|||||||
*/
|
*/
|
||||||
public Location getHomeLocation(int number) {
|
public Location getHomeLocation(int number) {
|
||||||
/*
|
/*
|
||||||
* Bukkit.getLogger().info("DEBUG: getting home location " + number);
|
Bukkit.getLogger().info("DEBUG: getting home location " + number);
|
||||||
|
|
||||||
Bukkit.getLogger().info("DEBUG: " + homeLocations.toString());
|
Bukkit.getLogger().info("DEBUG: " + homeLocations.toString());
|
||||||
for (Entry<Integer, Location> en : homeLocations.entrySet()) {
|
for (Entry<Integer, Location> en : homeLocations.entrySet()) {
|
||||||
@ -169,8 +169,7 @@ public class Players extends DataObject {
|
|||||||
if (location == null) {
|
if (location == null) {
|
||||||
homeLocations.clear();
|
homeLocations.clear();
|
||||||
} else {
|
} else {
|
||||||
// Make the location x,y,z integer, but keep the yaw and pitch
|
homeLocations.put(number, location);
|
||||||
homeLocations.put(number, new Location(location.getWorld(),location.getBlockX(),location.getBlockY(),location.getBlockZ(),location.getYaw(), location.getPitch()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.math.NumberUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -24,6 +25,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.material.MaterialData;
|
import org.bukkit.material.MaterialData;
|
||||||
import org.bukkit.material.SimpleAttachableMaterialData;
|
import org.bukkit.material.SimpleAttachableMaterialData;
|
||||||
import org.bukkit.material.TrapDoor;
|
import org.bukkit.material.TrapDoor;
|
||||||
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
@ -463,4 +465,37 @@ public class Util {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the maximum value of a numerical perm setting
|
||||||
|
* @param player - the player to check
|
||||||
|
* @param perm - the start of the perm, e.g., bskyblock.maxhomes
|
||||||
|
* @param permValue - the default value - the result may be higher or lower than this
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int getPermValue(Player player, String perm, int permValue) {
|
||||||
|
for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
|
||||||
|
if (perms.getPermission().startsWith(perm + ".")) {
|
||||||
|
// Get the max value should there be more than one
|
||||||
|
if (perms.getPermission().contains(perm + ".*")) {
|
||||||
|
return permValue;
|
||||||
|
} else {
|
||||||
|
String[] spl = perms.getPermission().split(perm + ".");
|
||||||
|
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 {
|
||||||
|
permValue = Math.max(permValue, Integer.valueOf(spl[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Do some sanity checking
|
||||||
|
if (permValue < 1) {
|
||||||
|
permValue = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return permValue;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user