Added way to retrieve shop info by clicking it with a specific item

Closes #104
This commit is contained in:
Eric 2017-06-05 15:02:49 +02:00
parent c4e7e5a8ab
commit f653355cc2
4 changed files with 32 additions and 3 deletions

View File

@ -4,7 +4,9 @@ import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.event.ShopUpdateEvent;
import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.sql.Database;
import de.epiceric.shopchest.utils.ItemUtils;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.inventory.ItemStack;
import java.io.BufferedReader;
import java.io.File;
@ -25,6 +27,9 @@ public class Config {
/** The quality of hologram and item updating (performance saving, or better quality) **/
public ShopUpdateEvent.UpdateQuality update_quality;
/** The item with which a player can click a shop to retrieve information **/
public ItemStack shop_info_item;
/** The default value for the custom WorldGuard flag 'create-shop' **/
public boolean wg_allow_create_shop_default;
@ -334,6 +339,7 @@ public class Config {
plugin.reloadConfig();
update_quality = ShopUpdateEvent.UpdateQuality.valueOf(plugin.getConfig().getString("update-quality"));
shop_info_item = ItemUtils.getItemStack(plugin.getConfig().getString("shop-info-item"));
wg_allow_create_shop_default = plugin.getConfig().getBoolean("worldguard-default-flag-values.create-shop");
wg_allow_use_admin_shop_default = plugin.getConfig().getBoolean("worldguard-default-flag-values.use-admin-shop");
wg_allow_use_shop_default = plugin.getConfig().getBoolean("worldguard-default-flag-values.use-shop");

View File

@ -394,12 +394,29 @@ public class ShopInteractListener implements Listener {
}
}
} else {
if (shopUtils.isShop(b.getLocation())) {
Shop shop = shopUtils.getShop(b.getLocation());
if (shop != null) {
if (e.getAction() == Action.LEFT_CLICK_BLOCK && p.isSneaking() && Utils.hasAxeInHand(p)) {
return;
}
ItemStack infoItem = config.shop_info_item;
if (infoItem != null) {
if (e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_BLOCK) {
ItemStack item = Utils.getItemInMainHand(p);
if (item == null || !(infoItem.getType() == item.getType() && infoItem.getDurability() == item.getDurability())) {
item = Utils.getItemInMainHand(p);
if (item != null && infoItem.getType() == item.getType() && infoItem.getDurability() == item.getDurability()) {
e.setCancelled(true);
info(p, shop);
return;
}
} else {
e.setCancelled(true);
info(p, shop);
return;
}
}
}
if (e.getAction() == Action.RIGHT_CLICK_BLOCK && p.getUniqueId().equals(shop.getVendor().getUniqueId()) && shop.getShopType() != ShopType.ADMIN) {
return;

View File

@ -74,6 +74,8 @@ public class ItemUtils {
* @return The de-serialized ItemStack or {@code null} if the serialized item is invalid
*/
public static ItemStack getItemStack(String item) {
if (item.trim().isEmpty()) return null;
if (item.contains(":")) {
Material mat = Material.getMaterial(item.split(":")[0]);
if (mat == null) return null;

View File

@ -23,6 +23,10 @@ show-shop-items: true
# may lead to TPS loss.
update-quality: NORMAL
# Set the item with which a player can click a shop to retrieve information.
# You can set this to an empty string to disable this feature.
shop-info-item: "STICK"
# Set whether interaction with the hologram should be enabled.
# If set to true, a player can do the exact same thing with the
# hologram, as with the chest. You can even open the chest if you