Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,25 @@ public class CommonAddonManager implements AddonManager {
private final SerializableHashMap addonMD5s = new SerializableHashMap();
private final Addon internal;

private Field gameField;
private Field descriptionField;
private Field loggerField;
private Field dataPathField;

public CommonAddonManager(Game game) {
this.game = game;
this.internal = new InternalAddon(game);
addons.add(internal);

Class<Addon> clazz = Addon.class;
try {
gameField = clazz.getDeclaredField("game");
descriptionField = clazz.getDeclaredField("description");
loggerField = clazz.getDeclaredField("logger");
dataPathField = clazz.getDeclaredField("dataPath");
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
}

@Override
Expand Down Expand Up @@ -103,22 +118,18 @@ public Addon loadAddon(Path path) throws InvalidAddonException, InvalidDescripti
final Constructor<? extends Addon> constructor = addonClass.getConstructor();
final Addon addon = constructor.newInstance();

final Field gameField = addonClass.getSuperclass().getDeclaredField("game");
gameField.setAccessible(true);
gameField.set(addon, game);
gameField.setAccessible(false);

final Field descriptionField = addonClass.getSuperclass().getDeclaredField("description");
descriptionField.setAccessible(true);
descriptionField.set(addon, description);
descriptionField.setAccessible(false);

final Field loggerField = addonClass.getSuperclass().getDeclaredField("logger");
loggerField.setAccessible(true);
loggerField.set(addon, LogManager.getLogger(description.getName()));
loggerField.setAccessible(false);

final Field dataPathField = addonClass.getSuperclass().getDeclaredField("dataPath");
dataPathField.setAccessible(true);
dataPathField.set(addon, dataPath);
dataPathField.setAccessible(false);
Expand Down