Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6 from haq/develop
Browse files Browse the repository at this point in the history
fixed bug where loading would not work
  • Loading branch information
Affan Haq authored Dec 2, 2020
2 parents 48f159d + c8797c0 commit 7d8dab7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 61 deletions.
57 changes: 26 additions & 31 deletions bungee/src/main/java/me/affanhaq/keeper/Keeper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Keeper {
/**
* @param plugin instance of your plugin
*/
public Keeper(Plugin plugin) {
public Keeper(@NotNull Plugin plugin) {
this.plugin = plugin;
}

Expand Down Expand Up @@ -52,36 +52,31 @@ public Keeper register(@NotNull Object... objects) {
* @return instance of this class so you can build
*/
public Keeper load() {
OBJECTS.entrySet().forEach(this::load);
return this;
}

public Keeper load(@NotNull Object object) {
ConfigurationFile file = OBJECTS.get(object);
Arrays.stream(object.getClass().getDeclaredFields())
.filter(field -> field.isAnnotationPresent(ConfigValue.class))
.forEach(field -> {

Object value = file.getConfiguration().get(
field.getAnnotation(ConfigValue.class).value()
);

if (value == null) {
return;
}

if (value instanceof String) {
value = ChatColor.translateAlternateColorCodes('&', value.toString());
}

try {
field.setAccessible(true);
field.set(object, value);
} catch (IllegalAccessException e) {
e.printStackTrace();
}

});
OBJECTS.forEach((object, configFile) ->
Arrays.stream(object.getClass().getDeclaredFields())
.filter(field -> field.isAnnotationPresent(ConfigValue.class))
.forEach(field -> {

Object value = configFile.getConfiguration().get(
field.getAnnotation(ConfigValue.class).value()
);

if (value == null) {
return;
}

if (value instanceof String) {
value = ChatColor.translateAlternateColorCodes('&', value.toString());
}

try {
field.setAccessible(true);
field.set(object, value);
} catch (IllegalAccessException e) {
e.printStackTrace();
}

}));
return this;
}

Expand Down
55 changes: 25 additions & 30 deletions spigot/src/main/java/me/affanhaq/keeper/Keeper.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,36 +52,31 @@ public Keeper register(@NotNull Object... objects) {
* @return instance of this class so you can build
*/
public Keeper load() {
OBJECTS.entrySet().forEach(this::load);
return this;
}

public Keeper load(@NotNull Object object) {
ConfigurationFile file = OBJECTS.get(object);
Arrays.stream(object.getClass().getDeclaredFields())
.filter(field -> field.isAnnotationPresent(ConfigValue.class))
.forEach(field -> {

Object value = file.getConfiguration().get(
field.getAnnotation(ConfigValue.class).value()
);

if (value == null) {
return;
}

if (value instanceof String) {
value = ChatColor.translateAlternateColorCodes('&', value.toString());
}

try {
field.setAccessible(true);
field.set(object, value);
} catch (IllegalAccessException e) {
e.printStackTrace();
}

});
OBJECTS.forEach((object, configFile) ->
Arrays.stream(object.getClass().getDeclaredFields())
.filter(field -> field.isAnnotationPresent(ConfigValue.class))
.forEach(field -> {

Object value = configFile.getConfiguration().get(
field.getAnnotation(ConfigValue.class).value()
);

if (value == null) {
return;
}

if (value instanceof String) {
value = ChatColor.translateAlternateColorCodes('&', value.toString());
}

try {
field.setAccessible(true);
field.set(object, value);
} catch (IllegalAccessException e) {
e.printStackTrace();
}

}));
return this;
}

Expand Down

0 comments on commit 7d8dab7

Please sign in to comment.