ChestShop-authors / ChestShop-3

ChestShop - the chest & sign shop plugin for Minecraft Servers running Bukkit/Spigot/Paper
https://dev.bukkit.org/projects/chestshop
GNU Lesser General Public License v2.1
276 stars 177 forks source link

TransactionEvent with Enchanted Books #418

Closed pijlwagen closed 3 years ago

pijlwagen commented 3 years ago

Plugin Version

3.11 (build 213)

Plugin Config

Not applicable

Server Version

1.16.5

Server Log

Not applicable

What other plugins are you running?

Vault, EssentialsX

What is happening?

When selling or buying enchanted books from a chestshop <ItemStack>.getItemMeta().hasEnchants() returns false in com.Acrobot.ChestShop.Events.TransactionEvent

What did you expect to happen?

Return a set of enchantment(s) on this item.

Additional context

What am I trying to achieve? I am saving transactions in a SQLite database, but I am unable to separate enchanted books from regular ENCHANTED_BOOK.

    @EventHandler
    public void chestShopTransaction(TransactionEvent e) {
        ItemStack[] stack = e.getStock();

        for (ItemStack item : stack) {
            item.getItemMeta().hasEnchants(); // false
        }
    }

With my current code I am trying to append the enchantment to the item name (ex: ENCHANTED_BOOK_MENDING)

pijlwagen commented 3 years ago

I guess that an alternative to this could be using the last line of the sign, for example Enchanted Book#1. Is there a list I can use so I can translate Enchanted Book#1 to the corresponding enchantment so I can still achieve ENCHANTED_BOOK_MENDING? I assume I will walk into the same issue with potions.

Phoenix616 commented 3 years ago

The item from the event should contain the full information, not sure why you are not getting that. Maybe try the latest ChestShop build?

pijlwagen commented 3 years ago

No luck.

Made a new server using Spigot 1.16.5 (directly created from BuildTools), downloaded the latest development build of chestshop also added updated pom.xml.

I also noticed that the Adminshop signs appeared to be broken, perhaps this is my PC acting up. This issue also occurs on my production server, we have temporarily switched back to essentials sell signs. My production server runs Paper 1.16.5

C:\Users\tfhdg>java -version
java version "15.0.2" 2021-01-19
Java(TM) SE Runtime Environment (build 15.0.2+7-27)
Java HotSpot(TM) 64-Bit Server VM (build 15.0.2+7-27, mixed mode, sharing)
        <repository>
            <id>chestshop-repo</id>
            <url>https://repo.minebench.de/</url>
        </repository>

        <dependency>
            <groupId>com.acrobot.chestshop</groupId>
            <artifactId>chestshop</artifactId>
            <version>3.12-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
    @EventHandler
    public void chestShopTransaction(TransactionEvent e) {
        String type = e.getTransactionType().toString();
        ItemStack[] i = e.getStock();
        Double price = Double.valueOf(e.getExactPrice().toString());
        Integer amount = 0;
        String name = null;

        for (ItemStack item : i) {
            if (name == null) {
                name = item.getType().toString();

                for (Enchantment ec : item.getItemMeta().getEnchants().keySet()) {
                    name += ec.getKey().getKey().toUpperCase();
                }
            }

            amount += item.getAmount();
        }

        saveTransaction(type, name, price, amount);
    }
Phoenix616 commented 3 years ago

I also noticed that the Adminshop signs appeared to be broken, perhaps this is my PC acting up. This issue also occurs on my production server, we have temporarily switched back to essentials sell signs. My production server runs Paper 1.16.5

The admin shop name can be set in the config, if you didn't do that then it will be Admin Shop, not Adminshop... If you actually changed it then please open a new ticket for unrelated issues.

pijlwagen commented 3 years ago

I also noticed that the Adminshop signs appeared to be broken, perhaps this is my PC acting up. This issue also occurs on my production server, we have temporarily switched back to essentials sell signs. My production server runs Paper 1.16.5

The admin shop name can be set in the config, if you didn't do that then it will be Admin Shop, not Adminshop... If you actually changed it then please open a new ticket for unrelated issues.

My bad, anyway back to the original issue

Phoenix616 commented 3 years ago

Enchanted Books don't have enchantments, they store enchantments which can be accessed via EnchantmentStorageMeta#hasStoredEnchants and EnchantmentStorageMeta#getStoredEnchants.