Skip to content

Commit 148f121

Browse files
committed
Update BlockBehaviorOverride.java
1 parent 8e1ba3e commit 148f121

1 file changed

Lines changed: 22 additions & 12 deletions

File tree

src/main/java/net/countercraft/movecraft/combat/features/BlockBehaviorOverride.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
import it.unimi.dsi.fastutil.objects.Object2IntMap;
55
import net.countercraft.movecraft.combat.MovecraftCombat;
66
import net.countercraft.movecraft.util.Tags;
7-
import org.apache.commons.lang.reflect.FieldUtils;
87
import org.bukkit.Bukkit;
98
import org.bukkit.Material;
109
import org.bukkit.configuration.file.FileConfiguration;
1110
import org.jetbrains.annotations.NotNull;
1211
import org.jetbrains.annotations.Nullable;
1312

1413
import java.lang.reflect.Field;
14+
import java.lang.reflect.InaccessibleObjectException;
1515
import java.lang.reflect.InvocationTargetException;
1616
import java.lang.reflect.Method;
1717
import java.util.*;
@@ -340,36 +340,46 @@ protected boolean setIgniteOdds(Material m, int value, Object fireBlock) {
340340
abstract Class<?> getCraftMagicNumbersClass() throws ClassNotFoundException;
341341

342342
protected Object getBlockClass(Material m)
343-
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, ClassNotFoundException {
343+
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException,
344+
ClassNotFoundException {
344345
if (this.magicNumbers == null) {
345346
this.magicNumbers = this.getCraftMagicNumbersClass();
346347
}
347348
Method method = magicNumbers.getMethod("getBlock", Material.class);
348349
return method.invoke(null, m);
349350
}
350351

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);
354358
whatToDoWithField.accept(obj);
355359
}
356360

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);
360366
field.set(block, value);
361367
}
362368

363369
protected static <T> Optional<T> getFieldValueSafe(@NotNull Object instance, String fieldName) {
364370
try {
365371
return Optional.ofNullable(getFieldValue(instance, fieldName));
366-
} catch(Exception ex) {
372+
} catch (Exception ex) {
367373
return Optional.empty();
368374
}
369375
}
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);
373383
return obj;
374384
}
375385
}

0 commit comments

Comments
 (0)