-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added fieldValue parameter to the CustomFieldLoader deserialize Metho…
…d and a default ListAdapter
- Loading branch information
Showing
14 changed files
with
296 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/me/ignpurple/ignlib/configuration/adapter/DefaultFieldLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package me.ignpurple.ignlib.configuration.adapter; | ||
|
||
import me.ignpurple.ignlib.configuration.manager.ConfigurationManager; | ||
|
||
public class DefaultFieldLoader implements CustomFieldLoader { | ||
|
||
@Override | ||
public Object deserialize(ConfigurationManager configurationManager, Object fieldValue, Object object) { | ||
return object; | ||
} | ||
|
||
@Override | ||
public Object serialize(ConfigurationManager configurationManager, Object object) { | ||
return object; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/me/ignpurple/ignlib/configuration/adapter/defaults/ListAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package me.ignpurple.ignlib.configuration.adapter.defaults; | ||
|
||
import me.ignpurple.ignlib.configuration.adapter.CustomFieldLoader; | ||
import me.ignpurple.ignlib.configuration.manager.ConfigurationManager; | ||
|
||
import java.lang.reflect.ParameterizedType; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ListAdapter implements CustomFieldLoader { | ||
|
||
@Override | ||
public Object serialize(ConfigurationManager configurationManager, Object object) { | ||
final List<Object> objects = (List<Object>) object; | ||
final List<Object> serializedObjects = new ArrayList<>(); | ||
for (final Object obj : objects) { | ||
serializedObjects.add(configurationManager.getLoader(obj.getClass()).serialize(configurationManager, obj)); | ||
} | ||
return serializedObjects; | ||
} | ||
|
||
@Override | ||
public Object deserialize(ConfigurationManager configurationManager, Object fieldValue, Object object) { | ||
final List<Object> fieldList = (List<Object>) fieldValue; | ||
final ParameterizedType parameterizedType = (ParameterizedType) fieldList; | ||
final List<Object> objects = (List<Object>) object; | ||
final List<Object> deserializedObjects = new ArrayList<>(); | ||
for (final Object obj : objects) { | ||
deserializedObjects.add(configurationManager.getLoader((Class<?>) parameterizedType.getActualTypeArguments()[0]).deserialize(configurationManager, null, obj)); | ||
} | ||
return deserializedObjects; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/me/ignpurple/ignlib/configuration/adapter/defaults/WorldAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package me.ignpurple.ignlib.configuration.adapter.defaults; | ||
|
||
import me.ignpurple.ignlib.configuration.adapter.CustomFieldLoader; | ||
import me.ignpurple.ignlib.configuration.manager.ConfigurationManager; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.World; | ||
|
||
public class WorldAdapter implements CustomFieldLoader { | ||
|
||
@Override | ||
public Object serialize(ConfigurationManager configurationManager, Object object) { | ||
final World world = (World) object; | ||
return world.getName(); | ||
} | ||
|
||
@Override | ||
public Object deserialize(ConfigurationManager configurationManager, Object fieldValue, Object object) { | ||
final String worldName = (String) object; | ||
try { | ||
final World world = Bukkit.getWorld(worldName); | ||
if (world == null) { | ||
throw new IllegalStateException("Invalid World Specified! Consider adding Multiverse-Core as a soft-depend if you have it installed!"); | ||
} | ||
|
||
return Bukkit.getWorld(worldName); | ||
} catch (Exception exception) { | ||
exception.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
src/main/java/me/ignpurple/ignlib/configuration/loader/DefaultFieldLoader.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/me/ignpurple/ignlib/configuration/type/ConfigLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.