Skip to content

Commit 6b986b8

Browse files
authored
Merge pull request #400 from BentoBoxWorld/391_custom_block_placeholders
Fix custom block count/value/limit placeholders for Oraxen, Nexo, ItemsAdder #391
2 parents 3179732 + 3537573 commit 6b986b8

File tree

1 file changed

+59
-16
lines changed

1 file changed

+59
-16
lines changed

src/main/java/world/bentobox/level/PlaceholderManager.java

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@
2323
import org.bukkit.persistence.PersistentDataType;
2424
import org.eclipse.jdt.annotation.Nullable;
2525

26+
import com.nexomc.nexo.api.NexoBlocks;
27+
import com.nexomc.nexo.api.NexoItems;
28+
import com.nexomc.nexo.mechanics.custom_block.CustomBlockMechanic;
29+
2630
import world.bentobox.bentobox.BentoBox;
2731
import world.bentobox.bentobox.api.addons.GameModeAddon;
2832
import world.bentobox.bentobox.api.user.User;
2933
import world.bentobox.bentobox.database.objects.Island;
3034
import world.bentobox.bentobox.hooks.ItemsAdderHook;
35+
import world.bentobox.bentobox.hooks.OraxenHook;
3136
import world.bentobox.bentobox.managers.PlaceholdersManager;
3237
import world.bentobox.bentobox.managers.RanksManager;
3338
import world.bentobox.level.objects.IslandLevels;
@@ -394,6 +399,30 @@ private Object getBlockIdentifier(@Nullable Block block) {
394399
return Material.SPAWNER; // Return generic spawner material if state invalid
395400
}
396401

402+
// Check Oraxen custom blocks (noteblock/stringblock/chorusblock mechanics)
403+
if (BentoBox.getInstance().getHooks().getHook("Oraxen").isPresent()) {
404+
String oraxenId = OraxenHook.getOraxenBlockID(block.getLocation());
405+
if (oraxenId != null) {
406+
return "oraxen:" + oraxenId;
407+
}
408+
}
409+
410+
// Check Nexo custom blocks
411+
if (addon.isNexo()) {
412+
CustomBlockMechanic nexoMechanic = NexoBlocks.customBlockMechanic(block.getLocation());
413+
if (nexoMechanic != null) {
414+
return "nexo:" + nexoMechanic.getItemID();
415+
}
416+
}
417+
418+
// Check ItemsAdder custom blocks
419+
if (addon.isItemsAdder()) {
420+
String iaId = ItemsAdderHook.getInCustomRegion(block.getLocation());
421+
if (iaId != null) {
422+
return iaId;
423+
}
424+
}
425+
397426
// Fallback to the Material for regular blocks
398427
return type;
399428
}
@@ -474,15 +503,31 @@ private Object getItemIdentifier(@Nullable ItemStack itemStack) {
474503
} // End of Spawner handling
475504

476505
// 2. Handle potential custom items (e.g., ItemsAdder)
477-
if (addon.isItemsAdder()) {
478-
Optional<String> customId = ItemsAdderHook.getNamespacedId(itemStack);
479-
if (customId.isPresent()) {
480-
return customId.get(); // Return the String ID from ItemsAdder
481-
}
482-
}
483-
484-
// 3. Fallback to Material for regular items that represent blocks
485-
return type.isBlock() ? type : null;
506+
if (addon.isItemsAdder()) {
507+
Optional<String> customId = ItemsAdderHook.getNamespacedId(itemStack);
508+
if (customId.isPresent()) {
509+
return customId.get(); // Return the String ID from ItemsAdder
510+
}
511+
}
512+
513+
// 3. Handle Oraxen custom items
514+
if (BentoBox.getInstance().getHooks().getHook("Oraxen").isPresent()) {
515+
Optional<String> oraxenId = OraxenHook.getNamespacedId(itemStack);
516+
if (oraxenId.isPresent()) {
517+
return "oraxen:" + oraxenId.get();
518+
}
519+
}
520+
521+
// 4. Handle Nexo custom items
522+
if (addon.isNexo()) {
523+
String nexoId = NexoItems.idFromItem(itemStack);
524+
if (nexoId != null) {
525+
return "nexo:" + nexoId;
526+
}
527+
}
528+
529+
// 5. Fallback to Material for regular items that represent blocks
530+
return type.isBlock() ? type : null;
486531
}
487532

488533
/**
@@ -538,16 +583,14 @@ private Object getObjectFromConfigKey(String configKey) {
538583
return material;
539584
}
540585

541-
// Assume it's a custom String key (e.g., ItemsAdder) if not resolved yet
542-
if (addon.isItemsAdder() && ItemsAdderHook.isInRegistry(configKey)) { // Use original case key for lookup?
543-
return configKey;
544-
}
545-
546586
// Final check: maybe it's the generic "spawner" key from config?
547-
if(lowerCaseKey.equals("spawner")) {
587+
if (lowerCaseKey.equals("spawner")) {
548588
return Material.SPAWNER;
549589
}
550-
return null;
590+
591+
// Return the key as-is for custom blocks (ItemsAdder, Oraxen, Nexo).
592+
// These are stored as String keys in mdCount/uwCount.
593+
return configKey;
551594
}
552595

553596
/**

0 commit comments

Comments
 (0)