make arrays parseable by variables
This commit is contained in:
parent
a430f7e94d
commit
3e77ce0f00
|
@ -363,6 +363,7 @@ public class ServerGroup
|
|||
_dataMap.put("tournament", _tournament + "");
|
||||
_dataMap.put("tournamentPoints", _tournamentPoints + "");
|
||||
_dataMap.put("games", _games);
|
||||
_dataMap.put("modes", _modes);
|
||||
_dataMap.put("serverType", _serverType);
|
||||
_dataMap.put("addNoCheat", _addNoCheat + "");
|
||||
_dataMap.put("teamRejoin", _teamRejoin + "");
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package nautilus.game.arcade.managers;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
|
@ -7,6 +8,7 @@ import java.lang.reflect.Type;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
@ -345,9 +347,14 @@ public class GameCreationManager implements Listener
|
|||
value = value.split("\\(")[1];
|
||||
value = value.replace(")", "");
|
||||
|
||||
processList(clazz, game, var,
|
||||
value.contains(":") ? value.split("\\:") : new String[]
|
||||
{ value }, add, remove);
|
||||
|
||||
Field f = getField(clazz, var);
|
||||
|
||||
processList(clazz, game, var, value.contains(":") ? value.split("\\:") : new String[]
|
||||
{
|
||||
value
|
||||
},
|
||||
add, remove, List.class.isAssignableFrom(f.getType()));
|
||||
}
|
||||
else if (value.contains("["))
|
||||
{
|
||||
|
@ -413,7 +420,7 @@ public class GameCreationManager implements Listener
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
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);
|
||||
if (f == null)
|
||||
|
@ -427,22 +434,34 @@ public class GameCreationManager implements Listener
|
|||
Type generic = type.getActualTypeArguments()[0];
|
||||
Class<?> genericClazz = Class.forName(generic.getTypeName());
|
||||
|
||||
ArrayList<Object> currentList = (ArrayList<Object>) f.get(game);
|
||||
if (!add && !remove)
|
||||
if (array)
|
||||
{
|
||||
add = true;
|
||||
currentList.clear();
|
||||
}
|
||||
|
||||
for (String finalValue : value)
|
||||
{
|
||||
if (add)
|
||||
Object[] objectArray = new Object[value.length];
|
||||
for (int i = 0; i < value.length; i++)
|
||||
{
|
||||
currentList.add(parseValue(genericClazz, finalValue, game));
|
||||
objectArray[i] = parseValue(genericClazz, value[i], game);
|
||||
}
|
||||
else if (remove)
|
||||
f.set(game, objectArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
ArrayList<Object> currentList = (ArrayList<Object>) f.get(game);
|
||||
if (!add && !remove)
|
||||
{
|
||||
currentList.remove(parseValue(genericClazz, finalValue, game));
|
||||
add = true;
|
||||
currentList.clear();
|
||||
}
|
||||
|
||||
for (String finalValue : value)
|
||||
{
|
||||
if (add)
|
||||
{
|
||||
currentList.add(parseValue(genericClazz, finalValue, game));
|
||||
}
|
||||
else if (remove)
|
||||
{
|
||||
currentList.remove(parseValue(genericClazz, finalValue, game));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue