Skip to content

Commit 1b552e6

Browse files
committed
Added value support #385
1 parent a972a2f commit 1b552e6

File tree

3 files changed

+86
-11
lines changed

3 files changed

+86
-11
lines changed

src/main/java/world/bentobox/level/commands/IslandValueCommand.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
import org.bukkit.inventory.PlayerInventory;
1212
import org.eclipse.jdt.annotation.NonNull;
1313

14+
import world.bentobox.bentobox.BentoBox;
1415
import world.bentobox.bentobox.api.commands.CompositeCommand;
1516
import world.bentobox.bentobox.api.localization.TextVariables;
1617
import world.bentobox.bentobox.api.user.User;
1718
import world.bentobox.bentobox.hooks.ItemsAdderHook;
19+
import world.bentobox.bentobox.hooks.OraxenHook;
1820
import world.bentobox.bentobox.util.Util;
1921
import world.bentobox.level.Level;
2022
import world.bentobox.level.objects.IslandLevels;
@@ -77,6 +79,15 @@ private void executeHandCommand(User user) {
7779
return;
7880
}
7981

82+
// Oraxen
83+
if (BentoBox.getInstance().getHooks().getHook("Oraxen").isPresent()) {
84+
String id = OraxenHook.getIdByItem(mainHandItem);
85+
if (id != null) {
86+
printValue(user, "oraxen:" + id);
87+
return;
88+
}
89+
}
90+
// ItemsAdder
8091
if (addon.isItemsAdder()) {
8192
Optional<String> id = ItemsAdderHook.getNamespacedId(mainHandItem);
8293
if (id.isPresent()) {
@@ -145,7 +156,7 @@ public Optional<List<String>> tabComplete(User user, String alias, List<String>
145156
}
146157

147158
List<String> options = new ArrayList<>(
148-
Arrays.stream(Material.values()).filter(Material::isBlock).map(Material::name).toList());
159+
Arrays.stream(Material.values()).filter(Material::isBlock).map(Material::name).map(String::toLowerCase).toList());
149160

150161
options.add("HAND");
151162

src/main/java/world/bentobox/level/panels/ValuePanel.java

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
import org.bukkit.Material;
1414
import org.bukkit.NamespacedKey;
1515
import org.bukkit.Registry;
16+
import org.bukkit.Tag;
1617
import org.bukkit.World;
1718
import org.bukkit.event.inventory.ClickType;
1819
import org.bukkit.inventory.ItemStack;
1920

2021
import com.google.common.base.Enums;
2122

23+
import world.bentobox.bentobox.BentoBox;
2224
import world.bentobox.bentobox.api.localization.TextVariables;
2325
import world.bentobox.bentobox.api.panels.PanelItem;
2426
import world.bentobox.bentobox.api.panels.TemplatedPanel;
@@ -134,11 +136,12 @@ private ValuePanel(Level addon,
134136

135137
this.activeFilter = Filter.NAME_ASC;
136138

137-
addon.getBlockConfig().getBlockValues().entrySet().stream().filter(en -> this.getIcon(en.getKey()) != null)
138-
.filter(en -> addon.getBlockConfig().isNotHiddenBlock(en.getKey()))
139-
.forEach(en -> blockRecordList
140-
.add(new BlockRecord(en.getKey(), Objects.requireNonNullElse(en.getValue(), 0),
141-
Objects.requireNonNullElse(addon.getBlockConfig().getLimit(en.getKey()), 0))));
139+
addon.getBlockConfig().getBlockValues().entrySet().stream()
140+
.filter(en -> this.getIcon(en.getKey()) != null)
141+
.filter(en -> addon.getBlockConfig().isNotHiddenBlock(en.getKey()))
142+
.forEach(en -> blockRecordList
143+
.add(new BlockRecord(en.getKey(), Objects.requireNonNullElse(en.getValue(), 0),
144+
Objects.requireNonNullElse(addon.getBlockConfig().getLimit(en.getKey()), 0))));
142145

143146
this.elementList = new ArrayList<>();
144147
this.searchText = "";
@@ -649,7 +652,7 @@ private PanelItem createMaterialButton(ItemTemplateRecord template, TemplatedPan
649652
{
650653
if (this.elementList.isEmpty())
651654
{
652-
// Does not contain any generators.
655+
// Does not contain any.
653656
return null;
654657
}
655658

@@ -665,16 +668,71 @@ private PanelItem createMaterialButton(ItemTemplateRecord template, TemplatedPan
665668
}
666669

667670
private Material getIcon(String key) {
671+
// Filter out some names
672+
key = key.replaceAll("wall_", "");
673+
key = key.replaceAll("_hanging", "");
668674
Material icon = Registry.MATERIAL.get(NamespacedKey.fromString(key));
669675
if (icon == null && key.endsWith("_spawner")) {
670676
icon = Registry.MATERIAL.get(NamespacedKey.fromString(key.substring(0, key.length() - 2) + "_egg"));
671677
}
678+
// ItemsAdder
672679
if (icon == null && addon.isItemsAdder() && ItemsAdderHook.isInRegistry(key)) {
673680
icon = ItemsAdderHook.getItemStack(key).map(ItemStack::getType).orElse(null);
674681
}
675682
if (icon != null && icon.isItem()) {
676683
return icon;
677684
}
685+
// Not an item, but maybe still something
686+
if (icon != null) {
687+
switch (icon) {
688+
case BUBBLE_COLUMN: return Material.WATER_BUCKET;
689+
case NETHER_PORTAL: return Material.PURPLE_STAINED_GLASS_PANE;
690+
case END_GATEWAY: return Material.BLACK_STAINED_GLASS_PANE;
691+
case END_PORTAL: return Material.BLACK_STAINED_GLASS_PANE;
692+
case SOUL_FIRE: return Material.SOUL_TORCH;
693+
case WALL_TORCH: return Material.TORCH;
694+
case TWISTING_VINES_PLANT: return Material.VINE;
695+
case CAVE_VINES_PLANT: return Material.VINE;
696+
case BAMBOO_SAPLING: return Material.BAMBOO;
697+
case KELP_PLANT: return Material.KELP;
698+
case SWEET_BERRY_BUSH: return Material.SWEET_BERRIES;
699+
case LAVA, FIRE: return Material.LAVA_BUCKET;
700+
case PISTON_HEAD: return Material.PISTON;
701+
case REDSTONE_WIRE: return Material.REDSTONE;
702+
case TORCHFLOWER_CROP: return Material.TORCHFLOWER_SEEDS;
703+
case TALL_SEAGRASS: return Material.SEAGRASS;
704+
case WATER: return Material.WATER_BUCKET;
705+
case VOID_AIR: return Material.BARRIER;
706+
case COCOA: return Material.COCOA_BEANS;
707+
case TRIPWIRE: return Material.TRIPWIRE_HOOK;
708+
case BEETROOTS: return Material.BEETROOT_SEEDS;
709+
case POTATOES: return Material.POTATO;
710+
case CARROTS: return Material.CARROT;
711+
case PITCHER_CROP: return Material.PITCHER_POD;
712+
case BIG_DRIPLEAF_STEM: return Material.BIG_DRIPLEAF;
713+
default: {}
714+
}
715+
if (Tag.FLOWER_POTS.isTagged(icon)) {
716+
return Material.FLOWER_POT;
717+
}
718+
if (Tag.WALL_SIGNS.isTagged(icon) || Tag.ALL_HANGING_SIGNS.isTagged(icon)) {
719+
return Material.OAK_SIGN;
720+
}
721+
if (Tag.CANDLE_CAKES.isTagged(icon)) {
722+
return Material.CAKE;
723+
}
724+
if (Tag.CAULDRONS.isTagged(icon)) {
725+
return Material.CAULDRON;
726+
}
727+
if (Tag.ICE.isTagged(icon)) {
728+
return Material.ICE;
729+
}
730+
731+
}
732+
// Try Oraxen
733+
if (key.startsWith("oraxen:") && BentoBox.getInstance().getHooks().getHook("Oraxen").isPresent()) {
734+
return Material.PAPER;
735+
}
678736
return null;
679737
}
680738

@@ -702,13 +760,15 @@ private PanelItem createMaterialButton(ItemTemplateRecord template, BlockRecord
702760
String.valueOf(blockValue));
703761
String limitTranslation = blockLimit > 0
704762
? this.user.getTranslationOrNothing(baseKey + "limit", TextVariables.NUMBER, String.valueOf(blockLimit))
705-
: "";
763+
: "";
706764

707765
// Determine icon and display material text
708766
Material icon = getIcon(key);
709767
builder.icon((icon == null || icon == Material.AIR) ? Material.PAPER : icon);
710-
711-
String displayMaterial = (icon == null) ? Util.prettifyText(key) : Utils.prettifyObject(icon, user);
768+
if (key.startsWith("oraxen:")) {
769+
key = key.substring(7);
770+
}
771+
String displayMaterial = (icon == null) ? Util.prettifyText(key) : Utils.prettifyObject(key, user);
712772
// Special handling for spawn eggs
713773
if (icon != null && icon.name().endsWith("_SPAWN_EGG")) {
714774
displayMaterial = Util.prettifyText(key);

src/main/java/world/bentobox/level/util/Utils.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ public static String prettifyObject(Object object, User user) {
158158
key = ((Enum<?>) object).name().toLowerCase();
159159
} else {
160160
key = (String) object;
161+
// Remove prefix
162+
if (key.startsWith("oraxen:")) {
163+
key = key.substring(7);
164+
}
161165
}
162166

163167
// Try our translations for Material.
@@ -177,7 +181,7 @@ public static String prettifyObject(Object object, User user) {
177181
// Fallback to our hook for Material.
178182
return LangUtilsHook.getMaterialName((Material) object, user);
179183
} else {
180-
return key;
184+
return world.bentobox.bentobox.util.Util.prettifyText(key);
181185
}
182186
} else if (object instanceof EntityType) {
183187
String key = ((Enum<?>) object).name().toLowerCase();

0 commit comments

Comments
 (0)