Add option to stack limit permissions, Close #108

This commit is contained in:
William committed 2021-11-23 00:37:41 +00:00
1 parent 8a1cc15d1d
commit 7239e7bdac
3 files changed
+68 -42

No files matched your search

@@ -96,6 +96,9 @@ public class Settings {
// Whether to autocomplete player names for tpa (e.g /tpa William will assume you mean /tpa William278)
private boolean autoCompletePlayerNames;
// Whether to stack limit permissions (add them) if a user has multiple. By default, the highest one will be returned
private boolean homeLimitPermissionStacking;
// RTP command settings
private boolean doRtpCommand;
private int rtpRange;
@@ -242,7 +245,9 @@ public class Settings {
this.warpRestrictionPermissionFormat = config.getString("warp_command.permission_restrictions.format", "huskhomes.warp.");
this.hideRestrictedWarps = config.getBoolean("warp_command.permission_restrictions.hide_restricted_warps", true);
this.autoCompletePlayerNames = config.getBoolean("general.auto_complete_player_names", false);
this.autoCompletePlayerNames = config.getBoolean("general.auto_complete_player_names", true);
this.homeLimitPermissionStacking = config.getBoolean("general.home_limit_permission_stacking", false);
this.doRtpCommand = config.getBoolean("random_teleport_command.enabled", true);
this.rtpRange = config.getInt("random_teleport_command.range", 5000);
@@ -520,4 +525,8 @@ public class Settings {
public boolean doAutoCompletePlayerNames() {
return autoCompletePlayerNames;
}
public boolean doHomeLimitPermissionStacking() {
return homeLimitPermissionStacking;
}
}
@@ -8,9 +8,11 @@ import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachmentInfo;
import java.util.UUID;
import java.util.regex.PatternSyntaxException;
/**
* An object representing a Player's home in-game
*
* @author William
*/
public class Home extends SetPoint {
@@ -21,11 +23,12 @@ public class Home extends SetPoint {
/**
* An object representing a Player's home in-game
* @param location The Bukkit {@link Location} of the home
* @param server The Bungee server ID of the home
*
* @param location The Bukkit {@link Location} of the home
* @param server The Bungee server ID of the home
* @param homeOwner The Player who owns the home
* @param name The name of the home
* @param isPublic Whether the home is public
* @param name The name of the home
* @param isPublic Whether the home is public
*/
public Home(Location location, String server, Player homeOwner, String name, boolean isPublic) {
super(location, server, name, MessageManager.getRawMessage("home_default_description", homeOwner.getName()));
@@ -36,13 +39,14 @@ public class Home extends SetPoint {
/**
* An object representing a Player's home in-game
* @deprecated Use other method that accepts UUID instead of UUID-string
*
* @param teleportationPoint The {@link TeleportationPoint} position of the home
* @param ownerUsername The username of the owner
* @param ownerUUID The UUID string of the owner
* @param name The name of the home
* @param description The description of the home
* @param isPublic Whether the home is public
* @param ownerUsername The username of the owner
* @param ownerUUID The UUID string of the owner
* @param name The name of the home
* @param description The description of the home
* @param isPublic Whether the home is public
* @deprecated Use other method that accepts UUID instead of UUID-string
*/
public Home(TeleportationPoint teleportationPoint, String ownerUsername, String ownerUUID, String name, String description, boolean isPublic, long creationTime) throws IllegalArgumentException {
super(teleportationPoint.worldName, teleportationPoint.x, teleportationPoint.y, teleportationPoint.z, teleportationPoint.yaw, teleportationPoint.pitch, teleportationPoint.server, name, description, creationTime);
@@ -53,12 +57,13 @@ public class Home extends SetPoint {
/**
* An object representing a Player's home in-game
*
* @param teleportationPoint The {@link TeleportationPoint} position of the home
* @param ownerUsername The username of the owner
* @param ownerUUID The {@link UUID} of the owner
* @param name The name of the home
* @param description The description of the home
* @param isPublic Whether the home is public
* @param ownerUsername The username of the owner
* @param ownerUUID The {@link UUID} of the owner
* @param name The name of the home
* @param description The description of the home
* @param isPublic Whether the home is public
*/
public Home(TeleportationPoint teleportationPoint, String ownerUsername, UUID ownerUUID, String name, String description, boolean isPublic, long creationTime) {
super(teleportationPoint.worldName, teleportationPoint.x, teleportationPoint.y, teleportationPoint.z, teleportationPoint.yaw, teleportationPoint.pitch, teleportationPoint.server, name, description, creationTime);
@@ -69,6 +74,7 @@ public class Home extends SetPoint {
/**
* Returns whether the Home is public
*
* @return if the Home is public
*/
public boolean isPublic() {
@@ -77,6 +83,7 @@ public class Home extends SetPoint {
/**
* Set the privacy of the home
*
* @param isPublic should the home be public?
*/
public void setPublic(boolean isPublic) {
@@ -85,6 +92,7 @@ public class Home extends SetPoint {
/**
* Returns the UUID of the Home's owner
*
* @return the owner's UUID
*/
public UUID getOwnerUUID() {
@@ -93,6 +101,7 @@ public class Home extends SetPoint {
/**
* Returns the username of the Home's owner
*
* @return the owner's username
*/
public String getOwnerUsername() {
@@ -101,6 +110,7 @@ public class Home extends SetPoint {
/**
* Returns the Player who owns the home
*
* @return the Player owner of the home
*/
public Player getOwner() {
@@ -114,6 +124,7 @@ public class Home extends SetPoint {
/**
* Set the owner of the home
*
* @param player The new owner of the home
*/
public void setOwner(Player player) {
@@ -121,20 +132,13 @@ public class Home extends SetPoint {
this.ownerUsername = player.getName();
}
/*
* Static methods for fetching player set home limits
*/
// Returns the maximum number of set homes a player can make
public static int getSetHomeLimit(Player p) {
p.recalculatePermissions();
int maxSetHomes = -1;
for (PermissionAttachmentInfo permissionAI : p.getEffectivePermissions()) {
String permission = permissionAI.getPermission();
if (permission.contains("huskhomes.max_sethomes.")) {
try {
if (Integer.parseInt(permission.split("\\.")[2]) > maxSetHomes) {
maxSetHomes = Integer.parseInt(permission.split("\\.")[2]);
}
} catch (Exception ignored) { }
}
}
public static int getSetHomeLimit(Player player) {
int maxSetHomes = getCountFromPermissions(player, "huskhomes.max_sethomes.");
if (maxSetHomes != -1) {
return maxSetHomes;
}
@@ -142,21 +146,33 @@ public class Home extends SetPoint {
}
// Returns the number of set homes a player can set for free
public static int getFreeHomes(Player p) {
int freeSetHomes = -1;
for (PermissionAttachmentInfo permissionAI : p.getEffectivePermissions()) {
String permission = permissionAI.getPermission();
if (permission.contains("huskhomes.free_sethomes.")) {
try {
if (Integer.parseInt(permission.split("\\.")[2]) > freeSetHomes) {
freeSetHomes = Integer.parseInt(permission.split("\\.")[2]);
}
} catch(Exception ignored) { }
}
}
public static int getFreeHomes(Player player) {
int freeSetHomes = getCountFromPermissions(player, "huskhomes.free_sethomes.");
if (freeSetHomes != -1) {
return freeSetHomes;
}
return HuskHomes.getSettings().getFreeHomeSlots();
}
// Return the value from the player's permissions
private static int getCountFromPermissions(Player player, String permissionPrefix) {
player.recalculatePermissions();
int count = -1 + (HuskHomes.getSettings().doHomeLimitPermissionStacking() ? 1 : 0);
for (PermissionAttachmentInfo permissionAI : player.getEffectivePermissions()) {
String permission = permissionAI.getPermission();
if (permission.contains(permissionPrefix)) {
try {
int value = Integer.parseInt(permission.split("\\.")[2]);
if (HuskHomes.getSettings().doHomeLimitPermissionStacking()) {
count += value;
} else {
if (value > count) {
count = value;
}
}
} catch (NumberFormatException | PatternSyntaxException ignored) {}
}
}
return count;
}
}
+2 -1
View File
@@ -28,7 +28,8 @@ data_storage_options:
warps_data: 'huskhomes_warp_data'
general:
max_sethomes: 10
auto_complete_player_names: false
auto_complete_player_names: true
home_limit_permission_stacking: false
teleport_warmup_time: 5
teleport_request_expiry_time: 60
allow_unicode_descriptions: true