Skip to content

Commit

Permalink
Fix NBT placeholder parsing on BossShopPro integration by delaying it…
Browse files Browse the repository at this point in the history
…s application
  • Loading branch information
EverNife committed Apr 9, 2024
1 parent fad1e73 commit f807c25
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package br.com.finalcraft.evernifecore.integration.bossshop.customizer;

import br.com.finalcraft.evernifecore.integration.bossshop.datapart.BSItemDataPartNBT;
import br.com.finalcraft.evernifecore.integration.bossshop.shops.IECShop;
import br.com.finalcraft.evernifecore.itemstack.FCItemFactory;
import br.com.finalcraft.evernifecore.util.FCNBTUtil;
import de.tr7zw.changeme.nbtapi.NBTContainer;
import de.tr7zw.changeme.nbtapi.NBTItem;
import org.black_ixx.bossshop.core.BSBuy;
import org.black_ixx.bossshop.core.BSShop;
import org.black_ixx.bossshop.core.BSShopHolder;
import org.black_ixx.bossshop.managers.ClassManager;
import org.black_ixx.bossshop.managers.item.ItemStackTranslator;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
Expand All @@ -14,6 +20,20 @@ public class ECItemStackTranslator extends ItemStackTranslator {
public ItemStack translateItemStack(BSBuy buy, BSShop shop, BSShopHolder holder, ItemStack item, Player target, boolean final_version) {
ItemStack itemStack = super.translateItemStack(buy, shop, holder, item, target, final_version); //Do Default Tranlation

NBTItem itemNBT = FCNBTUtil.getFrom(itemStack);

if (!itemNBT.isEmpty() && itemNBT.hasTag(BSItemDataPartNBT.NBT_TAG)){
String nbtString = itemNBT.getString(BSItemDataPartNBT.NBT_TAG);
String parsedNbtString = ClassManager.manager.getStringManager().transform(nbtString, buy, shop, holder, target);
NBTContainer nbtContent = FCNBTUtil.getFrom(parsedNbtString);

itemStack = FCItemFactory.from(itemStack)
.setNbt(nbtCompound -> {
nbtCompound.removeKey(BSItemDataPartNBT.NBT_TAG);
nbtCompound.mergeCompound(nbtContent);
}).build();
}

if (shop instanceof IECShop){ //IF ECshop, fire last customization!
itemStack = ((IECShop) shop).finalizeTranslateItemStack(buy, shop, holder, item, target, final_version);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
package br.com.finalcraft.evernifecore.integration.bossshop.datapart;

import br.com.finalcraft.evernifecore.util.FCNBTUtil;
import de.tr7zw.changeme.nbtapi.NBTContainer;
import org.black_ixx.bossshop.core.BSBuy;
import org.black_ixx.bossshop.managers.item.ItemDataPart;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ItemDataPartNBT extends ItemDataPart {
public class BSItemDataPartNBT extends ItemDataPart {

public static final String NBT_TAG = "ec_temporary_tag_to_be_removed_later";

final Pattern pattern = Pattern.compile("%\\w+%");

@Override
public ItemStack transform(ItemStack item, String used_name, String argument) {
// Use Matcher to find the pattern in the input string
Matcher matcher = pattern.matcher(argument);

if (matcher.find()) {
//We have at least one placeholder here, lets delay the apply of the NBT for later, only apply on
NBTContainer nbtContainer = FCNBTUtil.getFrom("{}");
nbtContainer.setString(NBT_TAG, argument);
argument = nbtContainer.toString();
}

return br.com.finalcraft.evernifecore.itemdatapart.ItemDataPart.NBT.transform(item, used_name, argument);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import br.com.finalcraft.evernifecore.EverNifeCore;
import br.com.finalcraft.evernifecore.integration.BossShopIntegration;
import br.com.finalcraft.evernifecore.integration.bossshop.customizer.ECItemStackTranslator;
import br.com.finalcraft.evernifecore.integration.bossshop.datapart.ItemDataPartNBT;
import br.com.finalcraft.evernifecore.integration.bossshop.datapart.BSItemDataPartNBT;
import br.com.finalcraft.evernifecore.listeners.base.ECListener;
import br.com.finalcraft.evernifecore.reflection.FieldAccessor;
import br.com.finalcraft.evernifecore.util.FCReflectionUtil;
Expand All @@ -25,7 +25,7 @@

public class BossShopListener implements ECListener {

private final ItemDataPartNBT DATAPART_NBT = new ItemDataPartNBT();
private final BSItemDataPartNBT DATAPART_NBT = new BSItemDataPartNBT();
private ECItemStackTranslator EC_ITEM_STACK_TRANSLATOR = new ECItemStackTranslator();

@EventHandler
Expand Down

0 comments on commit f807c25

Please sign in to comment.