|
4 | 4 | import it.unimi.dsi.fastutil.objects.Object2IntMap; |
5 | 5 | import net.countercraft.movecraft.combat.MovecraftCombat; |
6 | 6 | import net.countercraft.movecraft.util.Tags; |
7 | | -import org.apache.commons.lang.reflect.FieldUtils; |
8 | 7 | import org.bukkit.Bukkit; |
9 | 8 | import org.bukkit.Material; |
10 | 9 | import org.bukkit.configuration.file.FileConfiguration; |
11 | 10 | import org.jetbrains.annotations.NotNull; |
12 | 11 | import org.jetbrains.annotations.Nullable; |
13 | 12 |
|
14 | 13 | import java.lang.reflect.Field; |
| 14 | +import java.lang.reflect.InaccessibleObjectException; |
15 | 15 | import java.lang.reflect.InvocationTargetException; |
16 | 16 | import java.lang.reflect.Method; |
17 | 17 | import java.util.*; |
@@ -340,36 +340,46 @@ protected boolean setIgniteOdds(Material m, int value, Object fireBlock) { |
340 | 340 | abstract Class<?> getCraftMagicNumbersClass() throws ClassNotFoundException; |
341 | 341 |
|
342 | 342 | protected Object getBlockClass(Material m) |
343 | | - throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, ClassNotFoundException { |
| 343 | + throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, |
| 344 | + ClassNotFoundException { |
344 | 345 | if (this.magicNumbers == null) { |
345 | 346 | this.magicNumbers = this.getCraftMagicNumbersClass(); |
346 | 347 | } |
347 | 348 | Method method = magicNumbers.getMethod("getBlock", Material.class); |
348 | 349 | return method.invoke(null, m); |
349 | 350 | } |
350 | 351 |
|
351 | | - protected static <T> void writeField(@NotNull Object block, @NotNull Consumer<T> whatToDoWithField, String fieldName) throws IllegalAccessException, NoSuchFieldException, ClassCastException { |
352 | | - Field field = FieldUtils.getField(block.getClass(), fieldName, true); |
353 | | - T obj = (T)field.get(block); |
| 352 | + protected static <T> void writeField(@NotNull Object block, @NotNull Consumer<T> whatToDoWithField, |
| 353 | + String fieldName) throws IllegalAccessException, NoSuchFieldException, ClassCastException, |
| 354 | + InaccessibleObjectException, SecurityException { |
| 355 | + Field field = block.getClass().getField(fieldName); |
| 356 | + field.setAccessible(true); |
| 357 | + T obj = (T) field.get(block); |
354 | 358 | whatToDoWithField.accept(obj); |
355 | 359 | } |
356 | 360 |
|
357 | | - protected static <T> void writeField(@NotNull Object block, T value, String fieldName) throws IllegalAccessException, NoSuchFieldException, ClassCastException { |
358 | | - Field field = FieldUtils.getField(block.getClass(), fieldName, true); |
359 | | - T obj = (T)field.get(block); |
| 361 | + protected static <T> void writeField(@NotNull Object block, T value, String fieldName) |
| 362 | + throws IllegalAccessException, NoSuchFieldException, ClassCastException, InaccessibleObjectException, |
| 363 | + SecurityException { |
| 364 | + Field field = block.getClass().getField(fieldName); |
| 365 | + field.setAccessible(true); |
360 | 366 | field.set(block, value); |
361 | 367 | } |
362 | 368 |
|
363 | 369 | protected static <T> Optional<T> getFieldValueSafe(@NotNull Object instance, String fieldName) { |
364 | 370 | try { |
365 | 371 | return Optional.ofNullable(getFieldValue(instance, fieldName)); |
366 | | - } catch(Exception ex) { |
| 372 | + } catch (Exception ex) { |
367 | 373 | return Optional.empty(); |
368 | 374 | } |
369 | 375 | } |
370 | | - protected static <T> T getFieldValue(@NotNull Object instance, String fieldName) throws IllegalAccessException, NoSuchFieldException, ClassCastException { |
371 | | - Field field = FieldUtils.getField(instance.getClass(), fieldName, true); |
372 | | - T obj = (T)field.get(instance); |
| 376 | + |
| 377 | + protected static <T> T getFieldValue(@NotNull Object instance, String fieldName) |
| 378 | + throws IllegalAccessException, NoSuchFieldException, ClassCastException, InaccessibleObjectException, |
| 379 | + SecurityException { |
| 380 | + Field field = instance.getClass().getField(fieldName); |
| 381 | + field.setAccessible(true); |
| 382 | + T obj = (T) field.get(instance); |
373 | 383 | return obj; |
374 | 384 | } |
375 | 385 | } |
|
0 commit comments