make arrays parseable by variables

This commit is contained in:
xXVevzZXx 2016-07-06 14:03:41 +02:00
parent a430f7e94d
commit 3e77ce0f00
2 changed files with 36 additions and 16 deletions

View File

@ -363,6 +363,7 @@ public class ServerGroup
_dataMap.put("tournament", _tournament + ""); _dataMap.put("tournament", _tournament + "");
_dataMap.put("tournamentPoints", _tournamentPoints + ""); _dataMap.put("tournamentPoints", _tournamentPoints + "");
_dataMap.put("games", _games); _dataMap.put("games", _games);
_dataMap.put("modes", _modes);
_dataMap.put("serverType", _serverType); _dataMap.put("serverType", _serverType);
_dataMap.put("addNoCheat", _addNoCheat + ""); _dataMap.put("addNoCheat", _addNoCheat + "");
_dataMap.put("teamRejoin", _teamRejoin + ""); _dataMap.put("teamRejoin", _teamRejoin + "");

View File

@ -1,5 +1,6 @@
package nautilus.game.arcade.managers; package nautilus.game.arcade.managers;
import java.lang.reflect.Array;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
@ -7,6 +8,7 @@ import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -345,9 +347,14 @@ public class GameCreationManager implements Listener
value = value.split("\\(")[1]; value = value.split("\\(")[1];
value = value.replace(")", ""); value = value.replace(")", "");
processList(clazz, game, var,
value.contains(":") ? value.split("\\:") : new String[] Field f = getField(clazz, var);
{ value }, add, remove);
processList(clazz, game, var, value.contains(":") ? value.split("\\:") : new String[]
{
value
},
add, remove, List.class.isAssignableFrom(f.getType()));
} }
else if (value.contains("[")) else if (value.contains("["))
{ {
@ -413,7 +420,7 @@ public class GameCreationManager implements Listener
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void processList(Class<? extends Game> clazz, Game game, String var, String[] value, private void processList(Class<? extends Game> clazz, Game game, String var, String[] value,
boolean add, boolean remove) boolean add, boolean remove, boolean array)
{ {
Field f = getField(clazz, var); Field f = getField(clazz, var);
if (f == null) if (f == null)
@ -427,6 +434,17 @@ public class GameCreationManager implements Listener
Type generic = type.getActualTypeArguments()[0]; Type generic = type.getActualTypeArguments()[0];
Class<?> genericClazz = Class.forName(generic.getTypeName()); Class<?> genericClazz = Class.forName(generic.getTypeName());
if (array)
{
Object[] objectArray = new Object[value.length];
for (int i = 0; i < value.length; i++)
{
objectArray[i] = parseValue(genericClazz, value[i], game);
}
f.set(game, objectArray);
}
else
{
ArrayList<Object> currentList = (ArrayList<Object>) f.get(game); ArrayList<Object> currentList = (ArrayList<Object>) f.get(game);
if (!add && !remove) if (!add && !remove)
{ {
@ -445,6 +463,7 @@ public class GameCreationManager implements Listener
currentList.remove(parseValue(genericClazz, finalValue, game)); currentList.remove(parseValue(genericClazz, finalValue, game));
} }
} }
}
f.setAccessible(false); f.setAccessible(false);
} }