From 3e77ce0f004b163de9d4913573908bb0bbbd0ed0 Mon Sep 17 00:00:00 2001 From: xXVevzZXx Date: Wed, 6 Jul 2016 14:03:41 +0200 Subject: [PATCH] make arrays parseable by variables --- .../mineplex/serverdata/data/ServerGroup.java | 1 + .../arcade/managers/GameCreationManager.java | 51 +++++++++++++------ 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/ServerGroup.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/ServerGroup.java index fd4c81dc0..cbf80c7b1 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/ServerGroup.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/ServerGroup.java @@ -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 + ""); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java index 2de25542c..94e0bc6c7 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java @@ -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 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 currentList = (ArrayList) 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 currentList = (ArrayList) 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)); + } } }