Added Group- and Player limits for Shops

This commit is contained in:
Eric 2015-09-04 20:16:33 +02:00
parent fa9f3e59fc
commit 477b6a4701
9 changed files with 170 additions and 9 deletions

View File

@ -49,13 +49,36 @@ buy-greater-or-equal-sell: true
# Set the minimum prices for each individual Item. Not per Stack, per single Item!
# To add an item DELETE THE '[]' after 'minimum-prices:' and follow the format below.
# Important: You must have exactly 2 spaces between the text and the edge (Just like the other properties)
# Important: You must have exactly 2 spaces between the text and the edge.
# You can find the item names in the 'item_names.txt' file.
minimum-prices: []
# "STONE:1": 0.5
# "DIAMOND_SWORD": 100
# Priority: default < group < player
shop-limits:
# 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
messages:
# Set the message when a shop is created at the clicked chest.
@ -174,6 +197,14 @@ messages:
# Usable regex: %AMOUNT% (Amount of shops)
reloaded-shops: "&aSuccessfully reloaded %AMOUNT% shop/s."
# Set the message when the players' shop limit is reached.
# Usable regex: %LIMIT%
shop-limit-reached: "&cYou reached your limit of &6%LIMIT% &cshop/s."
# Set the message that shows the player how many shop slots of his shop limit he has occupied.
# Usable regex: %LIMIT%, %AMOUNT% (Amount of shops)
occupied-shop-slots: "&6You have &c%AMOUNT%/%LIMIT% &6shop slot/s occupied."
update:
# Set the message when an update is available.
@ -230,6 +261,9 @@ messages:
# Set the message when a not permitted player tries to check for updates.
update: "&cYou don't have permission to check for updates."
# Set the message when a not permitted player tries to view the shop limits.
limits: "&cYou don't have permission to view the shop limits."
command-description:
# Set the command description message for '/<main-command> create' when you type '/<main-command>'.
@ -247,4 +281,7 @@ messages:
# Set the command description message for '/<main-command> update' when you type '/<main-command>'.
update: "Check for Updates."
# Set the command description message for '/<main-command> limits' when you type '/<main-command>'.
limits: "View shop limits."
# End of file.

View File

@ -2,7 +2,7 @@
name: ShopChest
main: de.epiceric.shopchest.ShopChest
version: 1.4.11.1
version: 1.5.0
author: EpicEric
website: https://www.spigotmc.org/resources/shopchest.11431/
depend: [Vault]
@ -20,6 +20,7 @@ permissions:
shopchest.notification.update: true
shopchest.reload: true
shopchest.update: true
shopchest.limits: true
shopchest.create:
description: Allows you to create a shop.
default: true
@ -54,3 +55,6 @@ permissions:
shopchest.update:
description: Allows you to check for updates.
default: op
shopchest.limits:
description: Allows you to view shop limits.
default: true

View File

@ -1,10 +1,13 @@
package de.epiceric.shopchest;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
@ -13,13 +16,17 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.utils.ClickType;
import de.epiceric.shopchest.interfaces.JsonBuilder;
import de.epiceric.shopchest.utils.ClickType.EnumClickType;
import de.epiceric.shopchest.interfaces.JsonBuilder.ClickAction;
import de.epiceric.shopchest.interfaces.JsonBuilder.HoverAction;
import de.epiceric.shopchest.interfaces.Utils;
import de.epiceric.shopchest.interfaces.jsonbuilder.*;
import de.epiceric.shopchest.interfaces.jsonbuilder.JsonBuilder_R1;
import de.epiceric.shopchest.interfaces.jsonbuilder.JsonBuilder_R2;
import de.epiceric.shopchest.interfaces.jsonbuilder.JsonBuilder_R3;
import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.utils.ClickType;
import de.epiceric.shopchest.utils.ClickType.EnumClickType;
import de.epiceric.shopchest.utils.ShopUtils;
import de.epiceric.shopchest.utils.UpdateChecker;
import net.md_5.bungee.api.ChatColor;
import net.milkbowl.vault.permission.Permission;
@ -140,6 +147,18 @@ public class Commands extends BukkitCommand {
return true;
}
} else if (args[0].equalsIgnoreCase("limits")) {
if (perm.has(p, "shopchest.limits")) {
p.sendMessage(Config.occupied_shop_slots(ShopUtils.getShopLimit(p), ShopUtils.getShopAmount(p)));
return true;
} else {
p.sendMessage(Config.noPermission_limits());
}
} else {
sendBasicHelpMessage(p);
return true;
}
return true;
@ -195,6 +214,14 @@ public class Commands extends BukkitCommand {
int amount;
double buyPrice, sellPrice;
int limit = ShopUtils.getShopLimit(p);
if (limit != -1) {
if (ShopUtils.getShopAmount(p) >= limit) {
p.sendMessage(Config.limit_reached(limit));
return;
}
}
try {
amount = Integer.parseInt(args[1]);
@ -287,6 +314,7 @@ public class Commands extends BukkitCommand {
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " info - " + Config.cmdDesc_info());
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " reload - " + Config.cmdDesc_reload());
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " update - " + Config.cmdDesc_update());
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " limits - " + Config.cmdDesc_limits());
}

View File

@ -182,7 +182,7 @@ public class ShopChest extends JavaPlugin{
if (!itemNamesFile.exists())
try {itemNamesFile.createNewFile();} catch (IOException e) {e.printStackTrace();}
copy(getResource("item_names"), itemNamesFile);
copy(getResource("item_names.txt"), itemNamesFile);
shopChests = YamlConfiguration.loadConfiguration(shopChestsFile);

View File

@ -10,8 +10,12 @@ public class Config {
private static ShopChest plugin = ShopChest.getInstance();
public static Set<String> minimum_prices() {return (plugin.getConfig().getConfigurationSection("minimum-prices") == null) ? new HashSet<String>() : plugin.getConfig().getConfigurationSection("minimum-prices").getKeys(true);}
public static Set<String> shopLimits_group() {return (plugin.getConfig().getConfigurationSection("shop-limits.group") == null) ? new HashSet<String>() : plugin.getConfig().getConfigurationSection("shop-limits.group").getKeys(true);}
public static Set<String> shopLimits_player() {return (plugin.getConfig().getConfigurationSection("shop-limits.player") == null) ? new HashSet<String>() : plugin.getConfig().getConfigurationSection("shop-limits.player").getKeys(true);}
public static boolean buy_greater_or_equal_sell() {return plugin.getConfig().getBoolean("buy-greater-or-equal-sell");}
public static double maximal_distance() {return plugin.getConfig().getDouble("maximal-distance");}
public static int default_limit() {return plugin.getConfig().getInt("shop-limits.default");}
public static String main_command_name() { return plugin.getConfig().getString("main-command-name");}
public static String currency_symbol() { return plugin.getConfig().getString("currency-symbol").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
@ -36,6 +40,7 @@ public class Config {
public static String cmdDesc_info() { return plugin.getConfig().getString("messages.command-description.info").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String cmdDesc_reload() { return plugin.getConfig().getString("messages.command-description.reload").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String cmdDesc_update() { return plugin.getConfig().getString("messages.command-description.update").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String cmdDesc_limits() { return plugin.getConfig().getString("messages.command-description.limits").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String shopInfo_isInfinite() { return plugin.getConfig().getString("messages.shop-info.is-infinite").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");};
public static String shopInfo_isNormal() { return plugin.getConfig().getString("messages.shop-info.is-not-infinite").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");};
public static String noPermission_create() { return plugin.getConfig().getString("messages.no-permission.create").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
@ -46,6 +51,7 @@ public class Config {
public static String noPermission_sell() { return plugin.getConfig().getString("messages.no-permission.sell").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String noPermission_reload() { return plugin.getConfig().getString("messages.no-permission.reload").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String noPermission_update() { return plugin.getConfig().getString("messages.no-permission.update").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String noPermission_limits() { return plugin.getConfig().getString("messages.no-permission.limits").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String cannot_break_shop() { return plugin.getConfig().getString("messages.cannot-break-shop").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String cannot_sell_broken_item() { return plugin.getConfig().getString("messages.cannot-sell-broken-item").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String disabled() {return plugin.getConfig().getString("messages.shop-info.disabled").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
@ -56,6 +62,10 @@ public class Config {
public static String no_new_update() {return plugin.getConfig().getString("messages.update.no-update").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String click_to_download() {return plugin.getConfig().getString("messages.update.click-to-download").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String limit_reached(int limit) {
return plugin.getConfig().getString("messages.shop-limit-reached").replace(Regex.limit, String.valueOf(limit)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String reloaded_shops(int amount) {
return plugin.getConfig().getString("messages.reloaded-shops").replace(Regex.amount, String.valueOf(amount)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
@ -123,4 +133,8 @@ public class Config {
public static String sell_success(int amount, String itemName, double sellPrice, String vendor) {
return plugin.getConfig().getString("messages.sell-success").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.amount, String.valueOf(amount)).replace(Regex.itemName, itemName).replace(Regex.sellPrice, String.valueOf(sellPrice)).replace(Regex.vendor, vendor).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String occupied_shop_slots(int limit, int amount) {
return plugin.getConfig().getString("messages.occupied-shop-slots").replace(Regex.limit, String.valueOf(limit)).replace(Regex.amount, String.valueOf(amount)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
}

View File

@ -13,5 +13,6 @@ public class Regex {
public static String version = "%VERSION%";
public static String buyPrice = "%BUY-PRICE%";
public static String sellPrice = "%SELL-PRICE%";
public static String limit = "%LIMIT%";
}

View File

@ -29,4 +29,8 @@ public abstract class Utils {
return packageName.substring(packageName.lastIndexOf('.') + 1);
}
public static boolean isUUID(String string) {
return string.matches("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[34][0-9a-fA-F]{3}-[89ab][0-9a-fA-F]{3}-[0-9a-fA-F]{12}");
}
}

View File

@ -2,15 +2,22 @@ package de.epiceric.shopchest.utils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.block.DoubleChest;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.interfaces.Utils;
import de.epiceric.shopchest.shop.Shop;
public class ShopUtils {
@ -104,4 +111,70 @@ public class ShopUtils {
return w.getName() + "_" + String.valueOf(x) + "_" + String.valueOf(y) + "_" + String.valueOf(z);
}
public static int getShopLimit(Player p) {
int limit = Config.default_limit();
if (ShopChest.perm.hasGroupSupport()) {
List<String> groups = new ArrayList<String>();
for (String key : Config.shopLimits_group()) {
for (int i = 0; i < ShopChest.perm.getGroups().length; i++) {
if (ShopChest.perm.getGroups()[i].equals(key)) {
if (ShopChest.perm.playerInGroup(p, key)) {
groups.add(key);
}
}
}
}
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 : Config.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;
}
}
}
return limit;
}
public static int getShopAmount(OfflinePlayer p) {
int shopCount = 0;
for (Shop shop : ShopUtils.getShops()) {
if (shop.getVendor().equals(p)) shopCount++;
}
return shopCount;
}
}