mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-09 12:11:08 +00:00
Fixed Bugs & Added Hologram Format Configuration
This commit is contained in:
parent
1e5a6f3731
commit
66750cd570
13
config.yml
13
config.yml
@ -155,6 +155,9 @@ messages:
|
||||
# Set the message when the player doesn't have enough items to sell.
|
||||
not-enough-items: "&cNot enough items."
|
||||
|
||||
# Set the message when the vendor doesn't have enough money to buy something from the player
|
||||
vendor-not-enough-money: "&cVendor has not enough money."
|
||||
|
||||
# Set the message when the shop is out of stock.
|
||||
out-of-stock: "&cShop out of stock."
|
||||
|
||||
@ -231,15 +234,19 @@ messages:
|
||||
|
||||
hologram:
|
||||
|
||||
# Set the message in the second row of the shops' hologram when the player can buy and sell an item.
|
||||
# Set the text in the first row of the shops' hologram
|
||||
# Usable regex: %ITEMNAME%, %AMOUNT%
|
||||
format: "%AMOUNT% * %ITEMNAME%"
|
||||
|
||||
# Set the text in the second row of the shops' hologram when the player can buy and sell an item.
|
||||
# Usable regex: %BUY-PRICE%, %SELL-PRICE%, %CURRENCY-SYMBOL%
|
||||
buy-and-sell: "Buy %BUY-PRICE%%CURRENCY-SYMBOL% | %SELL-PRICE%%CURRENCY-SYMBOL% Sell"
|
||||
|
||||
# Set the message in the second row of the shops' hologram when the player can only buy an item.
|
||||
# Set the text in the second row of the shops' hologram when the player can only buy an item.
|
||||
# Usable regex: %BUY-PRICE%, %CURRENCY-SYMBOL%
|
||||
only-buy: "Buy %BUY-PRICE%%CURRENCY-SYMBOL%"
|
||||
|
||||
# Set the message in the second row of the shops' hologram when the player can only sell an item.
|
||||
# Set the text in the second row of the shops' hologram when the player can only sell an item.
|
||||
# Usable regex: %SELL-PRICE%, %CURRENCY-SYMBOL%
|
||||
only-sell: "Sell %SELL-PRICE%%CURRENCY-SYMBOL%"
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
name: ShopChest
|
||||
main: de.epiceric.shopchest.ShopChest
|
||||
version: 1.5.6
|
||||
version: 1.5.7
|
||||
author: EpicEric
|
||||
website: https://www.spigotmc.org/resources/shopchest.11431/
|
||||
depend: [Vault]
|
||||
|
@ -86,6 +86,10 @@ public class Config {
|
||||
return plugin.getConfig().getString("messages.update.update-available").replace(Regex.version, version);
|
||||
}
|
||||
|
||||
public static String hologram_format(int amount, String itemName) {
|
||||
return plugin.getConfig().getString("messages.hologram.format").replace(Regex.amount, String.valueOf(amount)).replace(Regex.itemName, itemName).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
|
||||
}
|
||||
|
||||
public static String hologram_buy_sell(double buyPrice, double sellPrice) {
|
||||
return plugin.getConfig().getString("messages.hologram.buy-and-sell").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.buyPrice, String.valueOf(buyPrice)).replace(Regex.sellPrice, String.valueOf(sellPrice)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.yi.acru.bukkit.Lockette.Lockette;
|
||||
|
||||
import com.griefcraft.model.Protection;
|
||||
@ -123,7 +124,7 @@ public class InteractShop implements Listener{
|
||||
|
||||
Shop shop = ShopUtils.getShop(b.getLocation());
|
||||
|
||||
if (shop.getVendor().equals(p) || perm.has(p, "shopchest.removeOther")) {
|
||||
if (shop.getVendor().getUniqueId().equals(p.getUniqueId()) || perm.has(p, "shopchest.removeOther")) {
|
||||
remove(p, shop);
|
||||
} else {
|
||||
p.sendMessage(Config.noPermission_removeOthers());
|
||||
@ -144,7 +145,7 @@ public class InteractShop implements Listener{
|
||||
e.setCancelled(true);
|
||||
Shop shop = ShopUtils.getShop(b.getLocation());
|
||||
|
||||
if (p.equals(shop.getVendor())) {
|
||||
if (p.getUniqueId().equals(shop.getVendor().getUniqueId())) {
|
||||
e.setCancelled(false);
|
||||
return;
|
||||
} else {
|
||||
@ -195,7 +196,7 @@ public class InteractShop implements Listener{
|
||||
if (ShopUtils.isShop(b.getLocation())) {
|
||||
Shop shop = ShopUtils.getShop(b.getLocation());
|
||||
|
||||
if (!p.equals(shop.getVendor())) {
|
||||
if (!p.getUniqueId().equals(shop.getVendor().getUniqueId())) {
|
||||
if (shop.getSellPrice() > 0) {
|
||||
if (perm.has(p, "shopchest.sell")) {
|
||||
if (Utils.getAmount(p.getInventory(), shop.getProduct().getType(), shop.getProduct().getDurability(), shop.getProduct().getItemMeta()) >= shop.getProduct().getAmount()) {
|
||||
@ -262,8 +263,15 @@ public class InteractShop implements Listener{
|
||||
String price = Config.shopInfo_price(shop.getBuyPrice(), shop.getSellPrice());
|
||||
String infinite = (shop.isInfinite() ? Config.shopInfo_isInfinite() : Config.shopInfo_isNormal());
|
||||
|
||||
Map<Enchantment, Integer> enchantmentMap;
|
||||
|
||||
if (shop.getProduct().getItemMeta() instanceof EnchantmentStorageMeta) {
|
||||
EnchantmentStorageMeta esm = (EnchantmentStorageMeta) shop.getProduct().getItemMeta();
|
||||
enchantmentMap = esm.getStoredEnchants();
|
||||
} else {
|
||||
enchantmentMap = shop.getProduct().getEnchantments();
|
||||
}
|
||||
|
||||
Map<Enchantment, Integer> enchantmentMap = shop.getProduct().getItemMeta().getEnchants();
|
||||
Enchantment[] enchantments = enchantmentMap.keySet().toArray(new Enchantment[enchantmentMap.size()]);
|
||||
|
||||
for (int i = 0; i < enchantments.length; i++) {
|
||||
|
@ -7,7 +7,7 @@ import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
|
||||
public class ItemCustomNameListener implements Listener {
|
||||
|
||||
@EventHandler(priority=EventPriority.HIGH)
|
||||
@EventHandler(priority=EventPriority.MONITOR)
|
||||
public void onItemSpawn(ItemSpawnEvent e) {
|
||||
if (e.getEntity().hasMetadata("shopItem")) {
|
||||
e.getEntity().setCustomNameVisible(false);
|
||||
|
@ -20,27 +20,30 @@ public class UpdateHolograms implements Listener{
|
||||
Player p = e.getPlayer();
|
||||
Location playerLocation = p.getLocation();
|
||||
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
|
||||
Location shopLocation = shop.getLocation();
|
||||
|
||||
if (playerLocation.getWorld().equals(shopLocation.getWorld())) {
|
||||
if (shop.getHologram() != null) {
|
||||
|
||||
if (playerLocation.distance(shop.getHologram().getLocation()) <= Config.maximal_distance()) {
|
||||
Location shopLocation = shop.getLocation();
|
||||
|
||||
if (playerLocation.getWorld().equals(shopLocation.getWorld())) {
|
||||
|
||||
if (!shop.getHologram().isVisible(p)) {
|
||||
shop.getHologram().showPlayer(p);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (shop.getHologram().isVisible(p)) {
|
||||
shop.getHologram().hidePlayer(p);
|
||||
if (playerLocation.distance(shop.getHologram().getLocation()) <= Config.maximal_distance()) {
|
||||
|
||||
if (!shop.getHologram().isVisible(p)) {
|
||||
shop.getHologram().showPlayer(p);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (shop.getHologram().isVisible(p)) {
|
||||
shop.getHologram().hidePlayer(p);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -64,9 +64,9 @@ public class Shop {
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
|
||||
item = location.getWorld().dropItem(itemLocation, itemStack);
|
||||
item.getItemStack().getItemMeta().setDisplayName(UUID.randomUUID().toString());
|
||||
item.setVelocity(new Vector(0, 0, 0));
|
||||
item.setMetadata("shopItem", new FixedMetadataValue(plugin, true));
|
||||
item.setCustomNameVisible(false);
|
||||
|
||||
this.item = item;
|
||||
}
|
||||
@ -131,10 +131,9 @@ public class Shop {
|
||||
|
||||
}
|
||||
|
||||
} else holoLocation = new Location(b.getWorld(), b.getX() + 0.5, b.getY() - 0.6, b.getZ() + 0.5);
|
||||
} else holoLocation = new Location(b.getWorld(), b.getX() + 0.5, b.getY() - 0.6, b.getZ() + 0.5);
|
||||
|
||||
|
||||
holoText[0] = String.valueOf(product.getAmount()) + " x " + ItemNames.lookup(product);
|
||||
holoText[0] = Config.hologram_format(product.getAmount(), ItemNames.lookup(product));
|
||||
|
||||
if ((buyPrice <= 0) && (sellPrice > 0)) holoText[1] = Config.hologram_sell(sellPrice);
|
||||
else if ((buyPrice > 0) && (sellPrice <= 0)) holoText[1] = Config.hologram_buy(buyPrice);
|
||||
|
@ -182,7 +182,6 @@ public abstract class Database {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public OfflinePlayer getVendor(int id) {
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
@ -194,7 +193,7 @@ public abstract class Database {
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()){
|
||||
if(rs.getInt("id") == id){
|
||||
return (Utils.isUUID(rs.getString("vendor"))) ? Bukkit.getOfflinePlayer(UUID.fromString(rs.getString("vendor"))) : Bukkit.getOfflinePlayer(rs.getString("vendor"));
|
||||
return Bukkit.getOfflinePlayer(UUID.fromString(rs.getString("vendor")));
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
|
Loading…
Reference in New Issue
Block a user