Skip to content

Commit

Permalink
Reordered convertOption if statements
Browse files Browse the repository at this point in the history
  • Loading branch information
fulminazzo committed Apr 7, 2024
1 parent 5c83ba4 commit 081eb1b
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,11 @@ public static void spawnEffect(final @NotNull Player player, final @NotNull Part

@SuppressWarnings("unchecked")
static @Nullable Object convertOption(@NotNull Class<?> dataType, @NotNull Object option) {
// Check options
if (option instanceof AbstractItem) return itemToItemStack((AbstractItem) option);
else if (option instanceof Potion) return wPotionToPotion((Potion) option);
else if (option instanceof Color) return wColorToColor((Color) option);
// Check data types
else if (dataType.isEnum()) return EnumUtils.valueOf(dataType, option.toString());
else if (dataType.equals(MaterialData.class)) {
if (!(option instanceof Tuple))
Expand All @@ -292,18 +295,17 @@ else if (dataType.equals(MaterialData.class)) {
Material material = EnumUtils.valueOf(Material.class, tuple.getKey());
Integer data = tuple.getValue();
return material.getNewData((byte) (data == null ? 0 : data));
} else if (dataType.getCanonicalName().equalsIgnoreCase("org.bukkit.Vibration")) return option;
else if (dataType.getSimpleName().equals("BlockData")) {
} else if (dataType.getCanonicalName().equals("org.bukkit.Vibration")) return option;
else if (dataType.getCanonicalName().equals("org.bukkit.block.data.BlockData")) {
String raw = option.toString();
BlockDataOption blockDataOption = new BlockDataOption(raw);
Material material = EnumUtils.valueOf(Material.class, blockDataOption.getMaterial());
if (!material.isBlock())
throw new IllegalArgumentException(String.format("Cannot use non-block material '%s' as block data", material));
String nbt = blockDataOption.getNBT().trim();
return nbt.isEmpty() ? material.createBlockData() : material.createBlockData(String.format("[%s]", nbt));
}
else if (option instanceof Color) return wColorToColor((Color) option);
else {
} else {
// Try creation from data type
final Object finalOption;
Constructor<?> constructor = dataType.getDeclaredConstructors()[0];
int size = constructor.getParameterCount();
Expand Down

0 comments on commit 081eb1b

Please sign in to comment.