mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-28 11:29:15 +00:00
Added vanilla id support
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user