|
10 | 10 | * A collection of miscellaneous material-related utility methods. |
11 | 11 | */ |
12 | 12 | public final class MaterialConverter { |
13 | | - /** |
14 | | - * Turn log into sapling preserving tree type |
15 | | - * |
16 | | - * @param log log you want to turn into sapling |
17 | | - * @return sapling |
18 | | - */ |
19 | | - public static Optional<Material> getSaplingFromLog(@Nonnull Material log) { |
20 | | - if (!isLog(log)) |
21 | | - return Optional.empty(); |
22 | | - |
23 | | - String type = log.name().substring(0, log.name().lastIndexOf('_')); |
24 | | - type = type.replace("STRIPPED_", ""); |
25 | | - try { |
26 | | - return Optional.ofNullable(Material.valueOf(type + "_SAPLING")); |
27 | | - } catch (IllegalArgumentException ignored) { |
28 | | - return Optional.empty(); |
29 | | - } |
30 | | - } |
31 | | - |
32 | | - /** |
33 | | - * Turn log into planks preserving tree type |
34 | | - * |
35 | | - * @param log log you want to turn into planks |
36 | | - * @return planks |
37 | | - */ |
38 | | - public static Optional<Material> getPlanksFromLog(@Nonnull Material log) { |
39 | | - if (!isLog(log)) |
40 | | - return Optional.empty(); |
41 | | - |
42 | | - String type = log.name().substring(0, log.name().lastIndexOf('_')); |
43 | | - type = type.replace("STRIPPED_", ""); |
44 | | - try { |
45 | | - return Optional.ofNullable(Material.valueOf(type + "_PLANKS")); |
46 | | - } catch (IllegalArgumentException ignored) { |
47 | | - return Optional.empty(); |
48 | | - } |
49 | | - } |
50 | | - |
51 | | - /** |
52 | | - * Check if material is log (any type) |
53 | | - * |
54 | | - * @param log the material to check |
55 | | - * @return true if the stack is log; false otherwise |
56 | | - */ |
57 | | - public static boolean isLog(@Nonnull Material log) { |
58 | | - return log.name().endsWith("_LOG") || log.name().endsWith("_WOOD"); |
59 | | - } |
| 13 | + /** |
| 14 | + * Turn log into sapling preserving tree type |
| 15 | + * |
| 16 | + * @param log log you want to turn into sapling |
| 17 | + * @return sapling |
| 18 | + */ |
| 19 | + public static Optional<Material> getSaplingFromLog(@Nonnull Material log) { |
| 20 | + if (!isLog(log)) |
| 21 | + return Optional.empty(); |
| 22 | + |
| 23 | + String type = log.name().substring(0, log.name().lastIndexOf('_')); |
| 24 | + type = type.replace("STRIPPED_", ""); |
| 25 | + try { |
| 26 | + return Optional.ofNullable(Material.valueOf(type + "_SAPLING")); |
| 27 | + } catch (IllegalArgumentException ignored) { |
| 28 | + return Optional.empty(); |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Turn log into planks preserving tree type |
| 34 | + * |
| 35 | + * @param log log you want to turn into planks |
| 36 | + * @return planks |
| 37 | + */ |
| 38 | + public static Optional<Material> getPlanksFromLog(@Nonnull Material log) { |
| 39 | + if (!isLog(log)) |
| 40 | + return Optional.empty(); |
| 41 | + |
| 42 | + String type = log.name().substring(0, log.name().lastIndexOf('_')); |
| 43 | + type = type.replace("STRIPPED_", ""); |
| 44 | + try { |
| 45 | + return Optional.ofNullable(Material.valueOf(type + "_PLANKS")); |
| 46 | + } catch (IllegalArgumentException ignored) { |
| 47 | + return Optional.empty(); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Check if material is log (any type) |
| 53 | + * |
| 54 | + * @param log the material to check |
| 55 | + * @return true if the stack is log; false otherwise |
| 56 | + */ |
| 57 | + public static boolean isLog(@Nonnull Material log) { |
| 58 | + return log.name().endsWith("_LOG") || log.name().endsWith("_WOOD"); |
| 59 | + } |
60 | 60 | } |
0 commit comments