mirror of
https://github.com/2006-Scape/Parabot-Randoms.git
synced 2026-07-06 16:51:36 +00:00
[BUGFIX] Fixed issue with accessibility
This commit is contained in:
@@ -6,6 +6,9 @@ import org.parabot.core.reflect.RefClass;
|
|||||||
import org.parabot.core.reflect.RefField;
|
import org.parabot.core.reflect.RefField;
|
||||||
import org.parabot.environment.scripts.randoms.Random;
|
import org.parabot.environment.scripts.randoms.Random;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author JKetelaar
|
* @author JKetelaar
|
||||||
*/
|
*/
|
||||||
@@ -23,17 +26,24 @@ public class SerialBanAvoider implements Random {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
RefClass client = new RefClass(Context.getInstance().getClient());
|
try {
|
||||||
RefField serial = client.getField(serialAddressField);
|
workAroundStaticValues(Context.getInstance().getClient().getClass(), serialAddressField, serialAddressValue);
|
||||||
if (serial != null) {
|
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||||
serial.set(serialAddressValue);
|
e.printStackTrace();
|
||||||
} else {
|
|
||||||
Core.verbose(String.format("Oh oh... Couldn't find field: %s", serialAddressField));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void workAroundStaticValues(Class clazz, String fieldName, Object newValue) throws NoSuchFieldException, IllegalAccessException {
|
||||||
|
Field field = clazz.getDeclaredField(fieldName);
|
||||||
|
field.setAccessible(true);
|
||||||
|
Field modifiers = field.getClass().getDeclaredField("modifiers");
|
||||||
|
modifiers.setAccessible(true);
|
||||||
|
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||||
|
field.set(null, newValue);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Serial ban avoider";
|
return "Serial ban avoider";
|
||||||
|
|||||||
Reference in New Issue
Block a user