Bug Verified Critical priority

MythicCrucible reformatting non-crucible recipe results

#3600 opened by Unknown 3 years ago

Unknownreported this bug

I'm using Denizen to create custom crafting recipes, and have noticed that occasionally my Denizen items cannot be used in the crafting recipes of other Denizen items. I have narrowed the issue down to MythicCrucible, by only using a clean install of Denizen, MythicMobs, and MythicCrucible on a test server. This issue does not occur if I am using Denizen alone.

It turns out MythicCrucible is doing some reformatting of non-crucible items in the craft item event. Specifically, the things I've found is that it converts every hex color code in lore lines to be all-uppercase, and it converts unicode \uXXXX codes into their respective characters.

This means if I have hex color codes in my Denizen items' lore, or use characters such as single quotes, MythicCrucible reformats the item in the craft event and prevents it from matching any subsequent Denizen recipes. It also prevents stacking the items together if they can be obtained through non-crafting means.

An example listening to CraftItemEvent before and after MythicCrucible alters items:

EventPriority.LOWEST:
{"extra":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"#abc123","text":"It\u0027s a test"}],"text":""}
EventPriority.HIGHEST:
{"extra":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"#ABC123","text":"It's a test"}],"text":""}

There may be other ways it changes the item. Ideally it would not alter non-crucible recipe items at all.

Unknowncommented

Crucible recipes are currently registered in the Bukkit API and use the regular crafting stuff, it doesn't intercept recipes at all, so not sure why this is happening. Will require some more investigation.

Unknowncommented

I cracked the jar open, it is definitely messing with the lore.

    @EventHandler(priority=EventPriority.HIGHEST)
    public void eventCraft(CraftItemEvent event) {
        try {
            ItemMeta im;
            if (event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR) {
                return;
            }
            ItemStack item = event.getCurrentItem();
            if (item.hasItemMeta() && (im = item.getItemMeta()).hasLore()) {
                ArrayList<String> parsedLore = new ArrayList<String>();
                int num = 0;
                for (String str : im.getLore()) {
                    if (str.contains("{")) {
                        Matcher pMatcher = LoreRanges.matcher(str);
                        while (pMatcher.find()) {
                            int min = Integer.parseInt(pMatcher.group(1));
                            int max = Integer.parseInt(pMatcher.group(2));
                            num = MythicCrucible.r.nextInt(max - min) + min;
                            str = str.replace(pMatcher.group(0), "" + num);
                            MythicCrucible.debug("-- Replacing number range " + pMatcher.group(0) + " with " + num);
                        }
                        str = str.replace("{lastrandom}", String.valueOf(num));
                    }
                    parsedLore.add(str);
                }
                im.setLore(parsedLore);
                item.setItemMeta(im);
                event.setCurrentItem(item);
            }
        }
        catch (Exception exception) {
            // empty catch block
        }
    }

I would imagine this is the culprit.

Unknowncommented

ItemManager line 410. Hasn't been touched in a long time, but the code does modify item lore.

Unknowncommented

Should be fixed in the latest builds

Sign in to join the discussion.