Implement Lists and Maps into the variable system and finish more gamemodes

This commit is contained in:
xXVevzZXx 2016-05-01 18:48:07 +02:00
parent 1b5b18c9b2
commit 7bd6cdb93c
12 changed files with 735 additions and 100 deletions

View File

@ -1,7 +1,7 @@
package nautilus.game.arcade;
import java.io.File;
import java.util.HashMap ;
import java.util.HashMap;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -233,21 +233,25 @@ public class Arcade extends JavaPlugin
try
{
if(_serverConfiguration.getServerGroup().getModes().contains(","))
if(_serverConfiguration.getServerGroup().getModes() != null)
{
for (String modeName : _serverConfiguration.getServerGroup().getModes().split(","))
if(_serverConfiguration.getServerGroup().getModes().contains(","))
{
addGamemode(modeName, config);
for (String modeName : _serverConfiguration.getServerGroup().getModes().split(","))
{
addGamemode(modeName, config);
}
}
else
{
addGamemode(_serverConfiguration.getServerGroup().getModes(), config);
}
}
else
{
addGamemode(_serverConfiguration.getServerGroup().getModes(), config);
}
}
catch (Exception ex)
{
System.out.println("Error reading Gamemode variable values : " + ex.getMessage());
System.out.println("Error reading Gamemode variable values : ");
ex.printStackTrace();
}
}
@ -298,11 +302,11 @@ public class Arcade extends JavaPlugin
private void addGamemode(String gamemode, GameServerConfig config)
{
String mode = gamemode.split("{")[0];
String mode = gamemode.split("\\{")[0];
System.out.println(mode);
config.GameModeList.add(mode);
String mods = gamemode.split("{")[1];
String mods = gamemode.split("\\{")[1];
mods = mods.replace("}", "");
config.GameModeMods.put(mode, new HashMap<>());

View File

@ -12,9 +12,10 @@ import nautilus.game.arcade.game.games.barbarians.Barbarians;
import nautilus.game.arcade.game.games.bossbattles.BossBattles;
import nautilus.game.arcade.game.games.bouncyballs.BouncyBalls;
import nautilus.game.arcade.game.games.bridge.Bridge;
import nautilus.game.arcade.game.games.bridge.modes.OverpoweredBridge ;
import nautilus.game.arcade.game.games.bridge.modes.OverpoweredBridge;
import nautilus.game.arcade.game.games.bridge.modes.SpeedBridges ;
import nautilus.game.arcade.game.games.build.Build;
import nautilus.game.arcade.game.games.build.modes.TeamBuild ;
import nautilus.game.arcade.game.games.build.modes.TeamBuild;
import nautilus.game.arcade.game.games.cards.Cards;
import nautilus.game.arcade.game.games.castlesiege.CastleSiege;
import nautilus.game.arcade.game.games.champions.ChampionsCTF;
@ -47,9 +48,11 @@ import nautilus.game.arcade.game.games.oldmineware.OldMineWare;
import nautilus.game.arcade.game.games.paintball.Paintball;
import nautilus.game.arcade.game.games.quiver.Quiver;
import nautilus.game.arcade.game.games.quiver.QuiverTeams;
import nautilus.game.arcade.game.games.quiver.modes.BunnyHop ;
import nautilus.game.arcade.game.games.quiver.modes.TwoQuiver ;
import nautilus.game.arcade.game.games.rings.ElytraRings;
import nautilus.game.arcade.game.games.runner.Runner;
import nautilus.game.arcade.game.games.runner.modes.FasterThanLight ;
import nautilus.game.arcade.game.games.runner.modes.FasterThanLight;
import nautilus.game.arcade.game.games.searchanddestroy.SearchAndDestroy;
import nautilus.game.arcade.game.games.sheep.SheepGame;
import nautilus.game.arcade.game.games.skywars.SoloSkywars;
@ -67,11 +70,12 @@ import nautilus.game.arcade.game.games.squidshooter.SquidShooter;
import nautilus.game.arcade.game.games.stacker.Stacker;
import nautilus.game.arcade.game.games.survivalgames.SoloSurvivalGames;
import nautilus.game.arcade.game.games.survivalgames.TeamSurvivalGames;
import nautilus.game.arcade.game.games.survivalgames.modes.OverpoweredSurvival ;
import nautilus.game.arcade.game.games.survivalgames.modes.OverpoweredSurvival;
import nautilus.game.arcade.game.games.tug.Tug;
import nautilus.game.arcade.game.games.turfforts.TurfForts;
import nautilus.game.arcade.game.games.typewars.TypeWars;
import nautilus.game.arcade.game.games.uhc.UHC;
import nautilus.game.arcade.game.games.uhc.modes.CutClean ;
import nautilus.game.arcade.game.games.valentines.Valentines;
import nautilus.game.arcade.game.games.wither.WitherGame;
import nautilus.game.arcade.game.games.wizards.Wizards;
@ -83,7 +87,7 @@ public enum GameType
BaconBrawl(BaconBrawl.class, GameDisplay.BaconBrawl),
Barbarians(Barbarians.class, GameDisplay.Barbarians),
BossBattles(BossBattles.class, GameDisplay.BossBattles),
Bridge(Bridge.class, new GameMode[]{new GameMode(OverpoweredBridge.class, "OP Bridges")}, GameDisplay.Bridge),
Bridge(Bridge.class, new GameMode[]{new GameMode(OverpoweredBridge.class, "OP Bridges"), new GameMode(SpeedBridges.class, "Speed Bridges")}, GameDisplay.Bridge),
CastleSiege(CastleSiege.class, GameDisplay.CastleSiege),
ChampionsCTF(ChampionsCTF.class, GameDisplay.ChampionsCTF),
ChampionsDominate(ChampionsDominate.class, GameDisplay.ChampionsDominate),
@ -123,7 +127,7 @@ public enum GameType
MineWare(MineWare.class, GameDisplay.MineWare),
OldMineWare(OldMineWare.class, GameDisplay.OldMineWare),
Paintball(Paintball.class, GameDisplay.Paintball),
Quiver(Quiver.class, GameDisplay.Quiver),
Quiver(Quiver.class, new GameMode[]{new GameMode(BunnyHop.class, "Bunny Hop"), new GameMode(TwoQuiver.class, "Two In The Quiver")}, GameDisplay.Quiver),
QuiverTeams(QuiverTeams.class, GameDisplay.QuiverTeams),
Runner(Runner.class, new GameMode[]{new GameMode(FasterThanLight.class, "Gotta Go Fast")}, GameDisplay.Runner),
SearchAndDestroy(SearchAndDestroy.class, GameDisplay.SearchAndDestroy),
@ -145,7 +149,7 @@ public enum GameType
SurvivalGamesTeams(TeamSurvivalGames.class, GameDisplay.SurvivalGamesTeams, new GameType[]{GameType.SurvivalGames}, false),
Tug(Tug.class, GameDisplay.Tug),
TurfWars(TurfForts.class, GameDisplay.TurfWars),
UHC(UHC.class, GameDisplay.UHC),
UHC(UHC.class, new GameMode[]{new GameMode(CutClean.class, "Cut Clean")}, GameDisplay.UHC),
WitherAssault(WitherGame.class, GameDisplay.WitherAssault),
Wizards(Wizards.class, GameDisplay.Wizards, new Pair[]
{

View File

@ -35,8 +35,8 @@ import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent ;
import org.bukkit.event.player.PlayerInteractEntityEvent ;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.world.WorldLoadEvent;
@ -60,7 +60,7 @@ import mineplex.core.disguise.disguises.DisguisePlayer;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.packethandler.IPacketHandler;
import mineplex.core.packethandler.PacketInfo;
import mineplex.core.recharge.Recharge ;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.classcombat.event.ClassCombatCreatureAllowSpawnEvent;
@ -72,7 +72,6 @@ import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.events.PlayerGameRespawnEvent;
import nautilus.game.arcade.events.PlayerStateChangeEvent;
import nautilus.game.arcade.game.Game.GameState ;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;

View File

@ -0,0 +1,41 @@
package nautilus.game.arcade.game.games.bridge.modes;
import org.bukkit.event.EventHandler;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.games.bridge.Bridge;
/**
* SpeedBridges
*
* @author xXVevzZXx
*/
public class SpeedBridges extends Bridge
{
private int _untilBridges;
public SpeedBridges(ArcadeManager manager)
{
super(manager);
_untilBridges = 20000;
}
@EventHandler
public void fallBridges(GameStateChangeEvent event)
{
if(event.GetState() != GameState.Live)
return;
setBridgeTime(_untilBridges);
}
@Override
public String GetMode()
{
return "Speed Bridges";
}
}

View File

@ -49,7 +49,7 @@ public class TeamBuild extends Build
@Override
@EventHandler
public void prepare(GameStateChangeEvent event)
{
{
if (event.GetState() == GameState.Live)
{
for (GameTeam team : GetTeamList())

View File

@ -51,19 +51,22 @@ public class Quiver extends SoloGame
private Objective _scoreObj;
public Quiver(ArcadeManager manager)
{
super(manager, GameType.Quiver,
new Kit[]
{
new KitLeaper(manager),
new KitBrawler(manager),
new KitEnchanter(manager),
new KitSlamShot(manager),
new KitNinja(manager)
},
this(manager, new Kit[]
{
new KitLeaper(manager),
new KitBrawler(manager),
new KitEnchanter(manager),
new KitSlamShot(manager),
new KitNinja(manager)
});
}
public Quiver(ArcadeManager manager, Kit[] kits)
{
super(manager, GameType.Quiver, kits,
new String[]
{
"Bow and Arrow insta-kills.",
@ -384,4 +387,9 @@ public class Quiver extends SoloGame
else
return null;
}
public HashMap<Player, Long> getDeathTime()
{
return _deathTime;
}
}

View File

@ -0,0 +1,30 @@
package nautilus.game.arcade.game.games.quiver.modes;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.quiver.Quiver;
import nautilus.game.arcade.game.games.quiver.modes.kits.KitModedLeaper ;
import nautilus.game.arcade.kit.Kit;
/**
* BunnyHop
*
* @author xXVevzZXx
*/
public class BunnyHop extends Quiver
{
public BunnyHop(ArcadeManager manager)
{
super(manager, new Kit[]
{
new KitModedLeaper(manager)
});
}
@Override
public String GetMode()
{
return "Bunny Hop";
}
}

View File

@ -0,0 +1,75 @@
package nautilus.game.arcade.game.games.quiver.modes;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
import mineplex.minecraft.game.core.condition.Condition.ConditionType;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.quiver.Quiver;
import nautilus.game.arcade.game.games.quiver.kits.KitSlamShot;
/**
* TwoQuiver
*
* @author xXVevzZXx
*/
public class TwoQuiver extends Quiver
{
private int _arrowAmount;
public TwoQuiver(ArcadeManager manager)
{
super(manager);
_arrowAmount = 2;
}
@Override
@EventHandler
public void Death(CombatDeathEvent event)
{
if (event.GetEvent().getEntity() instanceof Player)
{
getDeathTime().put((Player)event.GetEvent().getEntity(), System.currentTimeMillis());
}
if (event.GetLog().GetKiller() == null)
return;
if (!event.GetLog().GetKiller().IsPlayer())
return;
Player player = UtilPlayer.searchExact(event.GetLog().GetKiller().GetName());
if (player == null) return;
int amount = _arrowAmount;
if (GetKit(player) instanceof KitSlamShot)
{
if (Manager.GetCondition().HasCondition(event.GetEvent().getEntity(), ConditionType.FALLING, null))
{
amount++;
}
}
//New Arrow
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(262, (byte)0, amount, F.item("Super Arrow")));
player.playSound(player.getLocation(), Sound.PISTON_EXTEND, 3f, 2f);
//Score
AddKill(player);
}
@Override
public String GetMode()
{
return "Two In The Quiver";
}
}

View File

@ -0,0 +1,60 @@
package nautilus.game.arcade.game.games.quiver.modes.kits;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilServer;
import mineplex.core.itemstack.ItemStackFactory;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.PerkTripleJump;
public class KitModedLeaper extends Kit
{
public KitModedLeaper(ArcadeManager manager)
{
super(manager, "Jumper", KitAvailability.Free,
new String[]
{
"Evade and kill using your triple jump!"
},
new Perk[]
{
new PerkTripleJump("Triple Jump", 0.9, 0.9, true, 0, false)
},
EntityType.ZOMBIE,
new ItemStack(Material.IRON_AXE));
}
@Override
public void GiveItems(Player player)
{
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.IRON_AXE));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.BOW));
if (Manager.GetGame().GetState() == GameState.Live)
{
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(262, (byte)0, 1, F.item("Super Arrow")));
final Player fPlayer = player;
UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable()
{
public void run()
{
UtilInv.Update(fPlayer);
}
}, 10);
}
}
}

View File

@ -0,0 +1,112 @@
package nautilus.game.arcade.game.games.uhc.modes;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.itemstack.ItemStackFactory;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.games.uhc.UHC;
/**
* CutClean
*
* @author xXVevzZXx
*/
public class CutClean extends UHC
{
private int _steakAmount;
private HashMap<Material, Material> _ores;
private HashMap<Material, Material> _drops;
public CutClean(ArcadeManager manager)
{
super(manager);
_steakAmount = 15;
_ores = new HashMap<>();
_ores.put(Material.GOLD_ORE, Material.GOLD_INGOT);
_ores.put(Material.IRON_ORE, Material.IRON_INGOT);
_drops = new HashMap<>();
_drops.put(Material.RAW_BEEF, Material.COOKED_BEEF);
_drops.put(Material.RAW_CHICKEN, Material.COOKED_CHICKEN);
_drops.put(Material.RAW_FISH, Material.COOKED_FISH);
_drops.put(Material.PORK, Material.GRILLED_PORK);
_drops.put(Material.RABBIT, Material.COOKED_RABBIT);
}
@EventHandler
public void giveSteak(GameStateChangeEvent event)
{
if(event.GetState() != GameState.Live)
return;
for(Player player : GetPlayers(true))
{
UtilInv.insert(player, ItemStackFactory.Instance.CreateStack(Material.COOKED_BEEF, _steakAmount));
}
}
@EventHandler
public void smeltOres(BlockBreakEvent event)
{
for(Material mat : _ores.keySet())
{
if (event.getBlock().getType() == mat)
{
event.setCancelled(true);
event.getBlock().setType(Material.AIR);
Bukkit.getScheduler().runTaskLater(Manager.getPlugin(), new Runnable()
{
@Override
public void run()
{
event.getBlock().getWorld().dropItem(event.getBlock().getLocation().add(0.5, 0.2, 0.5), new ItemStack(_ores.get(mat)));
}}, 1);
}
}
}
@EventHandler
public void smeltFood(EntityDeathEvent event)
{
List<ItemStack> drops = event.getDrops();
for(Material mat : _drops.keySet())
{
Iterator<ItemStack> itemIterator = drops.iterator();
while(itemIterator.hasNext())
{
ItemStack item = itemIterator.next();
if(item.getType() == mat)
{
itemIterator.remove();
drops.add(ItemStackFactory.Instance.CreateStack(_drops.get(mat), 1 + UtilMath.r(3)));
}
}
}
}
@Override
public String GetMode()
{
return "Cut Clean";
}
}

View File

@ -0,0 +1,147 @@
package nautilus.game.arcade.kit.perks;
import java.util.HashSet;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerToggleFlightEvent;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilServer;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.kit.Perk;
public class PerkTripleJump extends Perk
{
private double _power;
private double _heightMax;
private boolean _control;
private long _recharge;
private boolean _displayForce;
private HashSet<Player> _disabled = new HashSet<Player>();
public PerkTripleJump(String name, double power, double heightLimit, boolean control)
{
super(name, new String[]
{
C.cYellow + "Tap Jump Twice" + C.cGray + " to " + C.cGreen + name
});
_power = power;
_heightMax = heightLimit;
_control = control;
_recharge = 0;
_displayForce = false;
}
public PerkTripleJump(String name, double power, double heightLimit, boolean control, long recharge, boolean displayForce)
{
super(name, new String[]
{
C.cYellow + "Tap Jump Twice" + C.cGray + " to " + C.cGreen + name
});
_power = power;
_heightMax = heightLimit;
_control = control;
_recharge = recharge;
_displayForce = displayForce;
}
@EventHandler
public void FlightHop(PlayerToggleFlightEvent event)
{
Player player = event.getPlayer();
if (!Kit.HasKit(player))
return;
if (Manager.isSpectator(player))
return;
if (player.getGameMode() == GameMode.CREATIVE)
return;
event.setCancelled(true);
player.setFlying(false);
//Disable Flight
if(!Recharge.Instance.usable(player, GetName()))
{
player.setAllowFlight(false);
}
//Velocity
if (_control)
{
UtilAction.velocity(player, _power, 0.2, _heightMax, true);
}
else
{
UtilAction.velocity(player, player.getLocation().getDirection(), _power, true, _power, 0, _heightMax, true);
}
//Sound
player.getWorld().playEffect(player.getLocation(), Effect.BLAZE_SHOOT, 0);
//Recharge
if (_recharge > 0)
{
if(Recharge.Instance.usable(player, GetName()))
{
Recharge.Instance.useForce(player, GetName(), _recharge);
}
else
{
Recharge.Instance.useForce(player, GetName() + " 2", 500);
}
if (_displayForce)
{
Recharge.Instance.setDisplayForce(player, GetName(), true);
}
}
Recharge.Instance.useForce(player, GetName(), 500);
}
@EventHandler
public void FlightUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
for (Player player : UtilServer.getPlayers())
{
if (Manager.isSpectator(player))
continue;
if (!Kit.HasKit(player))
continue;
if (_recharge > 0 && !Recharge.Instance.usable(player, GetName()))
continue;
if (player.isOnGround() || (UtilBlock.solid(player.getLocation().getBlock().getRelative(BlockFace.DOWN)) && UtilBlock.solid(player.getLocation().getBlock())))
player.setAllowFlight(true);
}
}
public void disableForPlayer(Player player)
{
_disabled.add(player);
}
public void enableForPlayer(Player player)
{
_disabled.remove(player);
}
}

View File

@ -2,9 +2,19 @@ package nautilus.game.arcade.managers;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilServer;
@ -21,12 +31,6 @@ import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.stats.StatTracker;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
public class GameCreationManager implements Listener
{
ArcadeManager Manager;
@ -211,11 +215,11 @@ public class GameCreationManager implements Listener
GameMode mode = null;
Class<? extends Game> gameClass = gameType.getGameClass();
if(ModePref != null)
if (ModePref != null)
{
for(GameMode modes : gameType.getGameModes())
for (GameMode modes : gameType.getGameModes())
{
if(modes.getName().replaceAll(" ", "").equalsIgnoreCase(ModePref))
if (modes.getName().replaceAll(" ", "").equalsIgnoreCase(ModePref))
{
_lastMode = ModePref;
mode = modes;
@ -230,7 +234,7 @@ public class GameCreationManager implements Listener
Game game = gameClass.getConstructor(ArcadeManager.class).newInstance(Manager);
if(setVars && mode != null)
if (setVars && mode != null)
{
modifyGameConfiguration(gameClass, mode, game);
}
@ -271,7 +275,7 @@ public class GameCreationManager implements Listener
private String randomGameMode(GameType type)
{
ArrayList<String> modes = Manager.GetServerConfig().GameModeList;
if(modes.size() == 0)
if (modes.size() == 0)
return null;
GameMode[] gameModes = type.getGameModes();
@ -279,20 +283,20 @@ public class GameCreationManager implements Listener
String mode = modes.get(UtilMath.r(modes.size()));
int i = 0;
while(mode.equalsIgnoreCase(_lastMode) && !containsMode(gameModes, mode) && i != 25)
while (mode.equalsIgnoreCase(_lastMode) && !containsMode(gameModes, mode) && i != 25)
{
mode = modes.get(UtilMath.r(modes.size()));
i++;
}
return mode;
return mode.replace(" ", "");
}
private boolean containsMode(GameMode[] modes, String mode)
{
for(GameMode otherMode : modes)
for (GameMode otherMode : modes)
{
if(otherMode.getName().equalsIgnoreCase(mode))
if (otherMode.getName().equalsIgnoreCase(mode))
{
return true;
}
@ -311,7 +315,8 @@ public class GameCreationManager implements Listener
ArrayList<Class<? extends Game>> classes = new ArrayList<>();
classes.add(gameClass);
classes.add((Class<? extends Game>) gameClass.getSuperclass());
if(gameClass.getSuperclass() != Game.class)
if (gameClass.getSuperclass() != Game.class)
{
Class<? extends Game> gameType = (Class<? extends Game>) gameClass.getSuperclass();
classes.add((Class<? extends Game>) gameType.getSuperclass());
@ -319,66 +324,216 @@ public class GameCreationManager implements Listener
HashMap<String, String> varSet = Manager.GetServerConfig().GameModeMods.get(mode.getName());
for(Class<? extends Game> clazz : classes)
if(varSet == null)
return;
for (Class<? extends Game> clazz : classes)
{
for(String var : varSet.keySet())
for (String var : varSet.keySet())
{
Field f = null;
try
String value = varSet.get(var);
if (value.contains("("))
{
f = clazz.getDeclaredField(var);
boolean add = value.contains("+");
boolean remove = value.contains("-");
value = value.split("\\(")[1];
value = value.replace(")", "");
processList(clazz, game, var, value.contains(":") ? value.split("\\:") : new String[]{value}, add, remove);
}
catch (Exception e)
{
try
else if (value.contains("["))
{
value = value.split("\\[")[1];
value = value.replace("]", "");
Map<String, String> varMap = new HashMap<>();
String[] values = value.contains(":") ? value.split(":") : new String[]{value};
for (String keyValueSet : values)
{
f = clazz.getDeclaredField("_" + var);
String key = keyValueSet.split("\\$")[0];
String val = keyValueSet.split("\\$")[1];
varMap.put(key, val);
}
catch (Exception ex) {}
processMap(clazz, game, var, varMap);
}
try
else
{
f.setAccessible(true);
String value = varSet.get(var);
if(f.getType() == boolean.class)
{
f.set(game, Boolean.parseBoolean(value));
}
else if(f.getType() == String.class)
{
f.set(game, value);
}
else if(f.getType() == int.class)
{
f.set(game, Integer.parseInt(value));
}
else if(f.getType() == float.class)
{
f.set(game, Float.parseFloat(value));
}
else if(f.getType() == double.class)
{
f.set(game, Double.parseDouble(value));
}
else if(f.getType() == long.class)
{
f.set(game, Long.parseLong(value));
}
else if(f.getType() == byte.class)
{
f.set(game, Byte.parseByte(value));
}
else if(f.getType() == short.class)
{
f.set(game, Short.parseShort(value));
}
f.setAccessible(false);
}
catch (Exception ex)
{
System.out.println("Error while setting variable");
processVariable(clazz, game, var, value);
}
}
}
}
@SuppressWarnings("unchecked")
private void processMap(Class<? extends Game> clazz, Game game, String var, Map<String, String> map)
{
Field f = getField(clazz, var);
if(f == null)
return;
try
{
f.setAccessible(true);
ParameterizedType type = (ParameterizedType) f.getGenericType();
Type keyGeneric = type.getActualTypeArguments()[0];
Class<?> keyGenericClazz = Class.forName(keyGeneric.getTypeName());
Type valueGeneric = type.getActualTypeArguments()[1];
Class<?> valueGenericClazz = Class.forName(valueGeneric.getTypeName());
Map<Object, Object> currentMap = (Map<Object, Object>) f.get(game);
for (String key : map.keySet())
{
currentMap.put(parseValue(keyGenericClazz, key, game), parseValue(valueGenericClazz, map.get(key), game));
}
f.setAccessible(false);
}
catch (Exception ex)
{
System.out.println("Error while editing map");
}
}
@SuppressWarnings("unchecked")
private void processList(Class<? extends Game> clazz, Game game, String var, String[] value, boolean add, boolean remove)
{
Field f = getField(clazz, var);
if(f == null)
return;
try
{
f.setAccessible(true);
ParameterizedType type = (ParameterizedType) f.getGenericType();
Type generic = type.getActualTypeArguments()[0];
Class<?> genericClazz = Class.forName(generic.getTypeName());
ArrayList<Object> currentList = (ArrayList<Object>) f.get(game);
if (!add && !remove)
{
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));
}
}
f.setAccessible(false);
}
catch (Exception ex)
{
System.out.println("Error while editing list");
}
}
private void processVariable(Class<? extends Game> clazz, Game game, String var, String value)
{
Field f = getField(clazz, var);
if(f == null)
return;
try
{
f.setAccessible(true);
Object finalValue = parseValue(f.getType(), value, game);
if (value != null)
{
f.set(game, finalValue);
}
f.setAccessible(false);
}
catch (Exception ex)
{
ex.printStackTrace();
System.out.println("Error while setting variable");
}
}
private Object parseValue(Class<?> clazz, String value, Game game)
{
try
{
if (clazz == boolean.class)
{
return Boolean.parseBoolean(value);
}
else if (clazz == String.class)
{
return value;
}
else if (clazz == int.class)
{
return Integer.parseInt(value);
}
else if (clazz == float.class)
{
return Float.parseFloat(value);
}
else if (clazz == double.class)
{
return Double.parseDouble(value);
}
else if (clazz == long.class)
{
return Long.parseLong(value);
}
else if (clazz == byte.class)
{
return Byte.parseByte(value);
}
else if (clazz == short.class)
{
return Short.parseShort(value);
}
else if (clazz == Material.class)
{
return Material.getMaterial(value);
}
else if (clazz == ChatColor.class)
{
return ChatColor.getByChar(value);
}
return null;
}
catch(Exception ex)
{
System.out.println("Error while parsing value");
return null;
}
}
private Field getField(Class<? extends Game> clazz, String var)
{
Field f = null;
try
{
f = clazz.getDeclaredField(var);
}
catch (Exception e)
{
try
{
f = clazz.getDeclaredField("_" + var);
}
catch (Exception ex) {}
}
return f;
}
}