mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-08 19:51:05 +00:00
Use permission based shop limits
This also removes the permission "shopchest.limits" Closes #27
This commit is contained in:
parent
8452fad8a3
commit
b73ad05034
@ -120,17 +120,13 @@ class ShopCommand extends BukkitCommand {
|
||||
return true;
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("limits")) {
|
||||
if (perm.has(p, "shopchest.limits")) {
|
||||
plugin.debug(p.getName() + " is viewing his shop limits: " + shopUtils.getShopAmount(p) + "/" + shopUtils.getShopLimit(p));
|
||||
int limit = shopUtils.getShopLimit(p);
|
||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.OCCUPIED_SHOP_SLOTS,
|
||||
new LocalizedMessage.ReplacedRegex(Regex.LIMIT, (limit < 0 ? "∞" : String.valueOf(limit))),
|
||||
new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(shopUtils.getShopAmount(p)))));
|
||||
plugin.debug(p.getName() + " is viewing his shop limits: " + shopUtils.getShopAmount(p) + "/" + shopUtils.getShopLimit(p));
|
||||
int limit = shopUtils.getShopLimit(p);
|
||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.OCCUPIED_SHOP_SLOTS,
|
||||
new LocalizedMessage.ReplacedRegex(Regex.LIMIT, (limit < 0 ? "∞" : String.valueOf(limit))),
|
||||
new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(shopUtils.getShopAmount(p)))));
|
||||
|
||||
return true;
|
||||
} else {
|
||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_LIMITS));
|
||||
}
|
||||
return true;
|
||||
} else if (args[0].equalsIgnoreCase("config")) {
|
||||
if (perm.has(p, "shopchest.config")) {
|
||||
if (args.length >= 4) {
|
||||
@ -167,8 +163,6 @@ class ShopCommand extends BukkitCommand {
|
||||
sendBasicHelpMessage(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -914,7 +914,6 @@ public class LanguageUtils {
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_REMOVE_OTHERS, langConfig.getString("message.noPermission.remove-others", "&cYou don't have permission to remove this shop.")));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_RELOAD, langConfig.getString("message.noPermission.reload", "&cYou don't have permission to reload the shops.")));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_UPDATE, langConfig.getString("message.noPermission.update", "&cYou don't have permission to check for updates.")));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_LIMITS, langConfig.getString("message.noPermission.limits", "&cYou don't have permission to view the shop limits.")));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_CONFIG, langConfig.getString("message.noPermission.config", "&cYou don't have permission to change configuration values.")));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_CREATE, langConfig.getString("message.commandDescription.create", "Create a shop.")));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_REMOVE, langConfig.getString("message.commandDescription.remove", "Remove a shop.")));
|
||||
|
@ -111,7 +111,6 @@ public class LocalizedMessage {
|
||||
NO_PERMISSION_REMOVE_OTHERS,
|
||||
NO_PERMISSION_RELOAD,
|
||||
NO_PERMISSION_UPDATE,
|
||||
NO_PERMISSION_LIMITS,
|
||||
NO_PERMISSION_CONFIG,
|
||||
COMMAND_DESC_CREATE,
|
||||
COMMAND_DESC_REMOVE,
|
||||
|
@ -7,10 +7,9 @@ import de.epiceric.shopchest.sql.Database;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -124,53 +123,27 @@ public class ShopUtils {
|
||||
public int getShopLimit(Player p) {
|
||||
int limit = plugin.getShopChestConfig().default_limit;
|
||||
|
||||
if (plugin.getPermission().hasGroupSupport()) {
|
||||
List<String> groups = new ArrayList<String>();
|
||||
for (PermissionAttachmentInfo permInfo : p.getEffectivePermissions()) {
|
||||
if (permInfo.getPermission().startsWith("shopchest.limit.")) {
|
||||
if (permInfo.getPermission().contains("shopchest.limit.*")) {
|
||||
limit = -1;
|
||||
break;
|
||||
} else {
|
||||
String[] spl = permInfo.getPermission().split("shopchest.limit.");
|
||||
|
||||
for (String key : plugin.getShopChestConfig().shopLimits_group) {
|
||||
for (int i = 0; i < plugin.getPermission().getGroups().length; i++) {
|
||||
if (plugin.getPermission().getGroups()[i].equals(key)) {
|
||||
if (plugin.getPermission().playerInGroup(p, key)) {
|
||||
groups.add(key);
|
||||
if (spl.length > 1) {
|
||||
try {
|
||||
int newLimit = Integer.valueOf(spl[1]);
|
||||
limit = Math.max(limit, newLimit);
|
||||
} catch (NumberFormatException ignored) {
|
||||
/* Ignore and continue */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (groups.size() != 0) {
|
||||
List<Integer> limits = new ArrayList<>();
|
||||
for (String group : groups) {
|
||||
int gLimit = ShopChest.getInstance().getConfig().getInt("shop-limits.group." + group);
|
||||
limits.add(gLimit);
|
||||
}
|
||||
|
||||
int highestLimit = 0;
|
||||
for (int l : limits) {
|
||||
if (l > highestLimit) {
|
||||
highestLimit = l;
|
||||
} else if (l == -1) {
|
||||
highestLimit = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
limit = highestLimit;
|
||||
}
|
||||
}
|
||||
|
||||
for (String key : plugin.getShopChestConfig().shopLimits_player) {
|
||||
int pLimit = ShopChest.getInstance().getConfig().getInt("shop-limits.player." + key);
|
||||
if (Utils.isUUID(key)) {
|
||||
if (p.getUniqueId().equals(UUID.fromString(key))) {
|
||||
limit = pLimit;
|
||||
}
|
||||
} else {
|
||||
if (p.getName().equals(key)) {
|
||||
limit = pLimit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (limit < -1) limit = -1;
|
||||
return limit;
|
||||
}
|
||||
|
||||
|
@ -131,31 +131,4 @@ database:
|
||||
|
||||
# ...password you are going to login with
|
||||
# Be careful, as anyone who can read this file, can read the password!
|
||||
password: ""
|
||||
|
||||
# Priority: default < group < player
|
||||
shop-limits:
|
||||
|
||||
# Set whether admin shops should be excluded of the shop limits.
|
||||
# If set to true, admin shops won't be added to a player's shop count.
|
||||
exclude-admin-shops: true
|
||||
|
||||
# Set the amount of shops anyone who's not listed in the sections below can have.
|
||||
# If you don't want the players to have a limit, set the value to -1.
|
||||
default: 5
|
||||
|
||||
# Set the amount of shops a player in a specific permission group can have.
|
||||
# If you don't want the group to have a limit, set the value to -1.
|
||||
# To add an item DELETE THE '[]' after 'group:' and follow the format below.
|
||||
# Important: You must have exactly 4 spaces between the text and the edge.
|
||||
group: []
|
||||
# "VIP": 10
|
||||
|
||||
# Set the amount of shops a specific player can have.
|
||||
# You can add a player by its name or by its UUID, but please do NOT provide the name and the UUID.
|
||||
# If you don't want the player to have a limit, set the value to -1.
|
||||
# To add an item DELETE THE '[]' after 'player:' and follow the format below.
|
||||
# Important: You must have exactly 4 spaces between the text and the edge.
|
||||
player: []
|
||||
# "EpicEric": 50
|
||||
# "898afbbe-6566-4a0f-b0ac-145868b3cb12": 50
|
||||
password: ""
|
@ -67,7 +67,6 @@ message.noPermission.sell=&cDu hast keine Berechtigung etwas zu verkaufen.
|
||||
message.noPermission.remove-others=&cDu hast keine Berechtigung diesen Shop zu entfernen.
|
||||
message.noPermission.reload=&cDu hast keine Berechtigung die Shops neu zu laden.
|
||||
message.noPermission.update=&cDu hast keine Berechtigung nach Aktualisierungen zu suchen.
|
||||
message.noPermission.limits=&cDu hast keine Berechtigung die Shop Limits zu sehen.
|
||||
message.noPermission.config=&cDu hast keine Berechtigung Konfigurationswerte zu verändern.
|
||||
message.commandDescription.create=Erstelle einen Shop.
|
||||
message.commandDescription.remove=Entferne einen Shop.
|
||||
|
@ -235,9 +235,6 @@ message.noPermission.reload=&cYou don't have permission to reload the shops.
|
||||
# Set the message when a not permitted player tries to check for updates.
|
||||
message.noPermission.update=&cYou don't have permission to check for updates.
|
||||
|
||||
# Set the message when a not permitted player tries to view the shop limits.
|
||||
message.noPermission.limits=&cYou don't have permission to view the shop limits.
|
||||
|
||||
# Set the message when a not permitted player tries to change configuration values.
|
||||
message.noPermission.config=&cYou don't have permission to change configuration values.
|
||||
|
||||
|
@ -18,7 +18,7 @@ permissions:
|
||||
shopchest.notification.update: true
|
||||
shopchest.reload: true
|
||||
shopchest.update: true
|
||||
shopchest.limits: true
|
||||
shopchest.limit.*: true
|
||||
shopchest.config: true
|
||||
shopchest.create:
|
||||
description: Allows you to create a shop.
|
||||
@ -54,9 +54,8 @@ permissions:
|
||||
shopchest.update:
|
||||
description: Allows you to check for updates.
|
||||
default: op
|
||||
shopchest.limits:
|
||||
description: Allows you to view shop limits.
|
||||
default: true
|
||||
shopchest.limit.*:
|
||||
default: op
|
||||
shopchest.config:
|
||||
description: Allows you to change configuration values per command.
|
||||
default: op
|
||||
|
Loading…
Reference in New Issue
Block a user