9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-28 19:39:06 +00:00

Added vanilla id support

This commit is contained in:
XiaoMoMi
2024-09-15 23:00:19 +08:00
parent 7ea4dab01e
commit a214217cf9
2 changed files with 19 additions and 2 deletions

View File

@@ -74,7 +74,16 @@ public class BukkitBlockManager implements BlockManager, Listener {
}
@Override
public BlockData blockData(@NotNull Context<Player> context, @NotNull String id, List<BlockDataModifier> modifiers) {
BlockData blockData = Material.valueOf(id.toUpperCase(Locale.ENGLISH)).createBlockData();
Material material;
try {
material = Material.valueOf(id.toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException e) {
material = Registry.MATERIAL.get(new NamespacedKey("minecraft", id.toLowerCase(Locale.ENGLISH)));
}
if (material == null) {
throw new IllegalArgumentException("Material " + id + " is not a valid material");
}
BlockData blockData = material.createBlockData();
for (BlockDataModifier modifier : modifiers)
modifier.apply(context, blockData);
return blockData;

View File

@@ -84,7 +84,11 @@ public class BukkitItemManager implements ItemManager, Listener {
@NotNull
@Override
public ItemStack buildItem(@NotNull Player player, @NotNull String id) {
return new ItemStack(Material.valueOf(id.toUpperCase(Locale.ENGLISH)));
try {
return new ItemStack(Material.valueOf(id.toUpperCase(Locale.ENGLISH)));
} catch (IllegalArgumentException e) {
return new ItemStack(requireNonNull(Registry.MATERIAL.get(new NamespacedKey("minecraft", id.toLowerCase(Locale.ENGLISH)))));
}
}
@NotNull
@Override
@@ -222,6 +226,10 @@ public class BukkitItemManager implements ItemManager, Listener {
try {
return new ItemStack(Material.valueOf(material.toUpperCase(Locale.ENGLISH)));
} catch (IllegalArgumentException e) {
Material another = Registry.MATERIAL.get(new NamespacedKey("minecraft", material.toLowerCase(Locale.ENGLISH)));
if (another != null) {
return new ItemStack(another);
}
plugin.getPluginLogger().severe("material " + material + " not exists", e);
return new ItemStack(Material.PAPER);
}