mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 22:16:34 +00:00
Add option to stack limit permissions, Close #108
This commit is contained in:
1 parent
8a1cc15d1d
commit
7239e7bdac
3 files changed
+68
-42
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user