mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-13 22:21:06 +00:00
Added way to retrieve shop info by clicking it with a specific item
Closes #104
This commit is contained in:
parent
c4e7e5a8ab
commit
f653355cc2
@ -4,7 +4,9 @@ import de.epiceric.shopchest.ShopChest;
|
|||||||
import de.epiceric.shopchest.event.ShopUpdateEvent;
|
import de.epiceric.shopchest.event.ShopUpdateEvent;
|
||||||
import de.epiceric.shopchest.language.LanguageUtils;
|
import de.epiceric.shopchest.language.LanguageUtils;
|
||||||
import de.epiceric.shopchest.sql.Database;
|
import de.epiceric.shopchest.sql.Database;
|
||||||
|
import de.epiceric.shopchest.utils.ItemUtils;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -25,6 +27,9 @@ public class Config {
|
|||||||
/** The quality of hologram and item updating (performance saving, or better quality) **/
|
/** The quality of hologram and item updating (performance saving, or better quality) **/
|
||||||
public ShopUpdateEvent.UpdateQuality update_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' **/
|
/** The default value for the custom WorldGuard flag 'create-shop' **/
|
||||||
public boolean wg_allow_create_shop_default;
|
public boolean wg_allow_create_shop_default;
|
||||||
|
|
||||||
@ -334,6 +339,7 @@ public class Config {
|
|||||||
plugin.reloadConfig();
|
plugin.reloadConfig();
|
||||||
|
|
||||||
update_quality = ShopUpdateEvent.UpdateQuality.valueOf(plugin.getConfig().getString("update-quality"));
|
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_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_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");
|
wg_allow_use_shop_default = plugin.getConfig().getBoolean("worldguard-default-flag-values.use-shop");
|
||||||
|
@ -394,12 +394,29 @@ public class ShopInteractListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (shopUtils.isShop(b.getLocation())) {
|
|
||||||
Shop shop = shopUtils.getShop(b.getLocation());
|
Shop shop = shopUtils.getShop(b.getLocation());
|
||||||
|
if (shop != null) {
|
||||||
if (e.getAction() == Action.LEFT_CLICK_BLOCK && p.isSneaking() && Utils.hasAxeInHand(p)) {
|
if (e.getAction() == Action.LEFT_CLICK_BLOCK && p.isSneaking() && Utils.hasAxeInHand(p)) {
|
||||||
return;
|
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) {
|
if (e.getAction() == Action.RIGHT_CLICK_BLOCK && p.getUniqueId().equals(shop.getVendor().getUniqueId()) && shop.getShopType() != ShopType.ADMIN) {
|
||||||
return;
|
return;
|
||||||
|
@ -74,6 +74,8 @@ public class ItemUtils {
|
|||||||
* @return The de-serialized ItemStack or {@code null} if the serialized item is invalid
|
* @return The de-serialized ItemStack or {@code null} if the serialized item is invalid
|
||||||
*/
|
*/
|
||||||
public static ItemStack getItemStack(String item) {
|
public static ItemStack getItemStack(String item) {
|
||||||
|
if (item.trim().isEmpty()) return null;
|
||||||
|
|
||||||
if (item.contains(":")) {
|
if (item.contains(":")) {
|
||||||
Material mat = Material.getMaterial(item.split(":")[0]);
|
Material mat = Material.getMaterial(item.split(":")[0]);
|
||||||
if (mat == null) return null;
|
if (mat == null) return null;
|
||||||
|
@ -23,6 +23,10 @@ show-shop-items: true
|
|||||||
# may lead to TPS loss.
|
# may lead to TPS loss.
|
||||||
update-quality: NORMAL
|
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.
|
# Set whether interaction with the hologram should be enabled.
|
||||||
# If set to true, a player can do the exact same thing with the
|
# 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
|
# hologram, as with the chest. You can even open the chest if you
|
||||||
|
Loading…
Reference in New Issue
Block a user