fix some format issues and implement God battles

This commit is contained in:
xXVevzZXx 2016-05-01 19:43:42 +02:00
parent 7bd6cdb93c
commit 6c2caac800
10 changed files with 315 additions and 190 deletions

View File

@ -311,9 +311,9 @@ public class Arcade extends JavaPlugin
config.GameModeMods.put(mode, new HashMap<>()); config.GameModeMods.put(mode, new HashMap<>());
if(mods.contains(";")) if (mods.contains(";"))
{ {
for(String varSet : mods.split(";")) for (String varSet : mods.split(";"))
{ {
String var = varSet.split("=")[0]; String var = varSet.split("=")[0];
String value = varSet.split("=")[1]; String value = varSet.split("=")[1];

View File

@ -1790,18 +1790,20 @@ public abstract class Game implements Listener
itel.remove(); itel.remove();
} }
} }
}@EventHandler(priority = EventPriority.HIGH) }
@EventHandler(priority = EventPriority.HIGH)
public void teamSelectInteract(PlayerInteractEntityEvent event) public void teamSelectInteract(PlayerInteractEntityEvent event)
{ {
if(!PlayerTeamSelection) if (!PlayerTeamSelection)
return; return;
if (GetState() != GameState.Recruit) if (GetState() != GameState.Recruit)
return; return;
if (event.getRightClicked() == null) if (event.getRightClicked() == null)
return; return;
if (!(event.getRightClicked() instanceof Player)) if (!(event.getRightClicked() instanceof Player))
return; return;
@ -1814,37 +1816,39 @@ public abstract class Game implements Listener
return; return;
} }
selectTeamMate(player, (Player)event.getRightClicked()); selectTeamMate(player, (Player) event.getRightClicked());
} }
@EventHandler @EventHandler
public void teamSelectCommand(PlayerCommandPreprocessEvent event) public void teamSelectCommand(PlayerCommandPreprocessEvent event)
{ {
if(!PlayerTeamSelection) if (!PlayerTeamSelection)
return; return;
if (GetState() != GameState.Recruit) if (GetState() != GameState.Recruit)
return; return;
if (!event.getMessage().toLowerCase().startsWith("/team ")) if (!event.getMessage().toLowerCase().startsWith("/team "))
return; return;
event.setCancelled(true); event.setCancelled(true);
Player target = UtilPlayer.searchOnline(event.getPlayer(), event.getMessage().split(" ")[1], true); Player target = UtilPlayer.searchOnline(event.getPlayer(), event.getMessage().split(" ")[1],
true);
if (target == null) if (target == null)
return; return;
//Observer //Observer
if (Manager.IsObserver(event.getPlayer())) if (Manager.IsObserver(event.getPlayer()))
{ {
UtilPlayer.message(event.getPlayer(), F.main("Game", "Spectators cannot partake in games.")); UtilPlayer.message(event.getPlayer(),
F.main("Game", "Spectators cannot partake in games."));
return; return;
} }
if (event.getPlayer().equals(target)) if (event.getPlayer().equals(target))
return; return;
selectTeamMate(event.getPlayer(), target); selectTeamMate(event.getPlayer(), target);
} }
@ -1856,26 +1860,28 @@ public abstract class Game implements Listener
//Remove Prefs //Remove Prefs
_teamReqs.remove(player); _teamReqs.remove(player);
_teamReqs.remove(ally); _teamReqs.remove(ally);
//Inform //Inform
UtilPlayer.message(player, F.main("Game", "You accepted " + ally.getName() + "'s Team Request!")); UtilPlayer.message(player,
UtilPlayer.message(ally, F.main("Game", player.getName() + " accepted your Team Request!")); F.main("Game", "You accepted " + ally.getName() + "'s Team Request!"));
UtilPlayer.message(ally,
F.main("Game", player.getName() + " accepted your Team Request!"));
//Leave Old Teams //Leave Old Teams
if (GetTeam(player) != null) if (GetTeam(player) != null)
GetTeam(player).DisbandTeam(); GetTeam(player).DisbandTeam();
if (GetTeam(ally) != null) if (GetTeam(ally) != null)
GetTeam(ally).DisbandTeam(); GetTeam(ally).DisbandTeam();
//Get Team //Get Team
GameTeam team = getEmptyTeam(); GameTeam team = getEmptyTeam();
if (team == null) if (team == null)
return; return;
//Join Team //Join Team
SetPlayerTeam(player, team, true); SetPlayerTeam(player, team, true);
SetPlayerTeam(ally, team, true); SetPlayerTeam(ally, team, true);
} }
//Send Invite //Send Invite
else else
@ -1884,36 +1890,39 @@ public abstract class Game implements Listener
if (GetTeam(player) != null) if (GetTeam(player) != null)
if (GetTeam(player).HasPlayer(ally)) if (GetTeam(player).HasPlayer(ally))
return; return;
//Inform Player //Inform Player
UtilPlayer.message(player, F.main("Game", "You sent a Team Request to " + ally.getName() + "!")); UtilPlayer.message(player,
F.main("Game", "You sent a Team Request to " + ally.getName() + "!"));
//Inform Target //Inform Target
if (Recharge.Instance.use(player, "Team Req " + ally.getName(), 2000, false, false)) if (Recharge.Instance.use(player, "Team Req " + ally.getName(), 2000, false, false))
{ {
UtilPlayer.message(ally, F.main("Game", player.getName() + " sent you a Team Request!")); UtilPlayer.message(ally,
UtilPlayer.message(ally, F.main("Game", "Type " + F.elem("/team " + player.getName()) + " to accept!")); F.main("Game", player.getName() + " sent you a Team Request!"));
UtilPlayer.message(ally, F.main("Game",
"Type " + F.elem("/team " + player.getName()) + " to accept!"));
} }
//Add Pref //Add Pref
_teamReqs.put(player, ally); _teamReqs.put(player, ally);
} }
} }
@EventHandler @EventHandler
public void teamQuit(PlayerQuitEvent event) public void teamQuit(PlayerQuitEvent event)
{ {
if(!PlayerTeamSelection) if (!PlayerTeamSelection)
return; return;
if (GetState() != GameState.Recruit) if (GetState() != GameState.Recruit)
return; return;
Player player = event.getPlayer(); Player player = event.getPlayer();
if (GetTeam(player) != null) if (GetTeam(player) != null)
GetTeam(player).DisbandTeam(); GetTeam(player).DisbandTeam();
Iterator<Player> teamIter = _teamReqs.keySet().iterator(); Iterator<Player> teamIter = _teamReqs.keySet().iterator();
while (teamIter.hasNext()) while (teamIter.hasNext())
{ {
@ -1922,7 +1931,7 @@ public abstract class Game implements Listener
teamIter.remove(); teamIter.remove();
} }
} }
public GameTeam getEmptyTeam() public GameTeam getEmptyTeam()
{ {
for (GameTeam team : GetTeamList()) for (GameTeam team : GetTeamList())
@ -1930,64 +1939,65 @@ public abstract class Game implements Listener
if (team.GetPlayers(false).isEmpty()) if (team.GetPlayers(false).isEmpty())
return team; return team;
} }
return null; return null;
} }
@EventHandler @EventHandler
public void CustomTeamGeneration(GameStateChangeEvent event) public void CustomTeamGeneration(GameStateChangeEvent event)
{ {
if(!TeamMode) if (!TeamMode)
return; return;
if (event.GetState() != GameState.Recruit) if (event.GetState() != GameState.Recruit)
return; return;
ArrayList<Location> initialSpawns = this.GetTeamList().get(0).GetSpawns(); ArrayList<Location> initialSpawns = this.GetTeamList().get(0).GetSpawns();
ArrayList<Location> spawns = this.GetTeamList().get(0).GetSpawns(); ArrayList<Location> spawns = this.GetTeamList().get(0).GetSpawns();
this.GetTeamList().clear(); this.GetTeamList().clear();
TeamColors color = TeamColors.DARK_AQUA; TeamColors color = TeamColors.DARK_AQUA;
if(TeamPerSpawn) if (TeamPerSpawn)
{ {
int i = 0; int i = 0;
for(Location location : initialSpawns) for (Location location : initialSpawns)
{ {
i++; i++;
spawns = new ArrayList<>(); spawns = new ArrayList<>();
spawns.add(location); spawns.add(location);
addRelativeSpawns(spawns, location); addRelativeSpawns(spawns, location);
//Got Spawns //Got Spawns
color = getNextColor(color); color = getNextColor(color);
int e = 0; int e = 0;
for(GameTeam teams : GetTeamList()) for (GameTeam teams : GetTeamList())
{ {
if(teams.GetColor() == color.getColor()) if (teams.GetColor() == color.getColor())
{ {
e++; e++;
if(getColorName(color.getColor()).length <= e) if (getColorName(color.getColor()).length <= e)
{ {
e = 0; e = 0;
} }
} }
} }
GameTeam team = new GameTeam(this, getColorName(color.getColor())[e], color.getColor(), spawns, true); GameTeam team = new GameTeam(this, getColorName(color.getColor())[e],
color.getColor(), spawns, true);
team.SetVisible(true); team.SetVisible(true);
GetTeamList().add(team); GetTeamList().add(team);
} }
} }
else else
{ {
if(!this.ForceTeamSize) if (!this.ForceTeamSize)
{ {
for(int i = 1; i <= this.TeamCount; i++) for (int i = 1; i <= this.TeamCount; i++)
{ {
color = getNextColor(color); color = getNextColor(color);
GameTeam team = new GameTeam(this, String.valueOf(i), color.getColor(), spawns); GameTeam team = new GameTeam(this, String.valueOf(i), color.getColor(), spawns);
@ -1995,60 +2005,64 @@ public abstract class Game implements Listener
GetTeamList().add(team); GetTeamList().add(team);
} }
} }
else else
{ {
for(int i = 1; i <= Manager.GetPlayerFull() / this.PlayersPerTeam; i++) for (int i = 1; i <= Manager.GetPlayerFull() / this.PlayersPerTeam; i++)
{ {
//Got Spawns //Got Spawns
color = getNextColor(color); color = getNextColor(color);
int e = 0; int e = 0;
for(GameTeam teams : GetTeamList()) for (GameTeam teams : GetTeamList())
{ {
if(teams.GetColor() == color.getColor()) if (teams.GetColor() == color.getColor())
{ {
e++; e++;
if(getColorName(color.getColor()).length <= e) if (getColorName(color.getColor()).length <= e)
{ {
e = 0; e = 0;
} }
} }
} }
GameTeam team = new GameTeam(this, getColorName(color.getColor())[e], color.getColor(), spawns, true); GameTeam team = new GameTeam(this, getColorName(color.getColor())[e],
color.getColor(), spawns, true);
team.SetVisible(true); team.SetVisible(true);
GetTeamList().add(team); GetTeamList().add(team);
} }
} }
} }
} }
private void addRelativeSpawns(ArrayList<Location> spawns, Location location) private void addRelativeSpawns(ArrayList<Location> spawns, Location location)
{ {
//Gather Extra Spawns //Gather Extra Spawns
for(int x = -1; x <= 1; x++) for (int x = -1; x <= 1; x++)
{ {
for(int z = -1; z <= 1; z++) for (int z = -1; z <= 1; z++)
{ {
if(x != 0 && z != 0) if (x != 0 && z != 0)
{ {
Location newSpawn = location.clone().add(x, 0, z); Location newSpawn = location.clone().add(x, 0, z);
//Search Downward for Solid //Search Downward for Solid
while (UtilBlock.airFoliage(newSpawn.getBlock().getRelative(BlockFace.DOWN)) && newSpawn.getY() > location.getY()-5) while (UtilBlock.airFoliage(newSpawn.getBlock().getRelative(BlockFace.DOWN))
&& newSpawn.getY() > location.getY() - 5)
{ {
newSpawn.subtract(0, 1, 0); newSpawn.subtract(0, 1, 0);
} }
//Move Up out of Solid //Move Up out of Solid
while (!UtilBlock.airFoliage(newSpawn.getBlock()) && newSpawn.getY() < location.getY()+5) while (!UtilBlock.airFoliage(newSpawn.getBlock())
&& newSpawn.getY() < location.getY() + 5)
{ {
newSpawn.add(0, 1, 0); newSpawn.add(0, 1, 0);
} }
//On Solid, with 2 Air Above //On Solid, with 2 Air Above
if (UtilBlock.airFoliage(newSpawn.getBlock()) && if (UtilBlock.airFoliage(newSpawn.getBlock())
UtilBlock.airFoliage(newSpawn.getBlock().getRelative(BlockFace.UP)) && && UtilBlock.airFoliage(newSpawn.getBlock().getRelative(BlockFace.UP))
!UtilBlock.airFoliage(newSpawn.getBlock().getRelative(BlockFace.DOWN))) && !UtilBlock
.airFoliage(newSpawn.getBlock().getRelative(BlockFace.DOWN)))
{ {
spawns.add(newSpawn); spawns.add(newSpawn);
} }
@ -2094,32 +2108,37 @@ public abstract class Game implements Listener
} }
} }
private String[] getColorName(ChatColor color) private String[] getColorName(ChatColor color)
{ {
for(TeamColors colors : TeamColors.values()) for (TeamColors colors : TeamColors.values())
{ {
if(colors.getColor() == color) if (colors.getColor() == color)
{ {
return colors.getNames(); return colors.getNames();
} }
} }
return null; return null;
} }
private TeamColors getNextColor(TeamColors color) private TeamColors getNextColor(TeamColors color)
{ {
for(TeamColors colors : TeamColors.values()) { for (TeamColors colors : TeamColors.values())
if(colors.ordinal() == color.ordinal() + 1) {
{ if (colors.ordinal() == color.ordinal() + 1)
{
return colors; return colors;
} }
} }
return TeamColors.YELLOW; return TeamColors.YELLOW;
} }
public void addTutorials(){} public void addTutorials()
{
}
public void disable(){} public void disable()
{
}
} }

View File

@ -15,23 +15,23 @@ public class SpeedBridges extends Bridge
{ {
private int _untilBridges; private int _untilBridges;
public SpeedBridges(ArcadeManager manager) public SpeedBridges(ArcadeManager manager)
{ {
super(manager); super(manager);
_untilBridges = 20000; _untilBridges = 20000;
} }
@EventHandler @EventHandler
public void fallBridges(GameStateChangeEvent event) public void fallBridges(GameStateChangeEvent event)
{ {
if(event.GetState() != GameState.Live) if (event.GetState() != GameState.Live)
return; return;
setBridgeTime(_untilBridges); setBridgeTime(_untilBridges);
} }
@Override @Override
public String GetMode() public String GetMode()
{ {

View File

@ -58,7 +58,7 @@ public class TeamBuild extends Build
BuildData data = new BuildData(team, spawn, WorldData.GetDataLocs("YELLOW")); BuildData data = new BuildData(team, spawn, WorldData.GetDataLocs("YELLOW"));
for(Player player : team.GetPlayers(true)) for (Player player : team.GetPlayers(true))
{ {
getData().put(player, data); getData().put(player, data);
player.setFlySpeed(0.1f); player.setFlySpeed(0.1f);
@ -90,7 +90,7 @@ public class TeamBuild extends Build
{ {
getViewData().setAbusive(); getViewData().setAbusive();
for(Player player : getViewData().Team.GetPlayers(true)) for (Player player : getViewData().Team.GetPlayers(true))
{ {
//Record Abuse //Record Abuse
AddStat(player, "Build Draw Abuse", 1, false, true); AddStat(player, "Build Draw Abuse", 1, false, true);
@ -168,7 +168,7 @@ public class TeamBuild extends Build
BuildData data = null; BuildData data = null;
//Average points per player is 1000, so divided by 50 = 20 gems //Average points per player is 1000, so divided by 50 = 20 gems
for(Player player : bestTeam.GetPlayers(true)) for (Player player : bestTeam.GetPlayers(true))
{ {
AddGems(player, bestPoints / 50, "Build Votes", false, false); AddGems(player, bestPoints / 50, "Build Votes", false, false);
@ -192,7 +192,7 @@ public class TeamBuild extends Build
//Gems //Gems
if (places.size() >= 1) if (places.size() >= 1)
{ {
for(Player player : places.get(0).GetPlayers(true)) for (Player player : places.get(0).GetPlayers(true))
{ {
_winners.add(player); _winners.add(player);
AddGems(player, 20, "1st Place", false, false); AddGems(player, 20, "1st Place", false, false);

View File

@ -2,7 +2,7 @@ package nautilus.game.arcade.game.games.quiver.modes;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.quiver.Quiver; import nautilus.game.arcade.game.games.quiver.Quiver;
import nautilus.game.arcade.game.games.quiver.modes.kits.KitModedLeaper ; import nautilus.game.arcade.game.games.quiver.modes.kits.KitModedLeaper;
import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.Kit;
/** /**
@ -16,11 +16,11 @@ public class BunnyHop extends Quiver
public BunnyHop(ArcadeManager manager) public BunnyHop(ArcadeManager manager)
{ {
super(manager, new Kit[] super(manager, new Kit[]
{ {
new KitModedLeaper(manager) new KitModedLeaper(manager)
}); });
} }
@Override @Override
public String GetMode() public String GetMode()
{ {

View File

@ -22,23 +22,23 @@ public class TwoQuiver extends Quiver
{ {
private int _arrowAmount; private int _arrowAmount;
public TwoQuiver(ArcadeManager manager) public TwoQuiver(ArcadeManager manager)
{ {
super(manager); super(manager);
_arrowAmount = 2; _arrowAmount = 2;
} }
@Override @Override
@EventHandler @EventHandler
public void Death(CombatDeathEvent event) public void Death(CombatDeathEvent event)
{ {
if (event.GetEvent().getEntity() instanceof Player) if (event.GetEvent().getEntity() instanceof Player)
{ {
getDeathTime().put((Player)event.GetEvent().getEntity(), System.currentTimeMillis()); getDeathTime().put((Player) event.GetEvent().getEntity(), System.currentTimeMillis());
} }
if (event.GetLog().GetKiller() == null) if (event.GetLog().GetKiller() == null)
return; return;
@ -46,26 +46,29 @@ public class TwoQuiver extends Quiver
return; return;
Player player = UtilPlayer.searchExact(event.GetLog().GetKiller().GetName()); Player player = UtilPlayer.searchExact(event.GetLog().GetKiller().GetName());
if (player == null) return; if (player == null)
return;
int amount = _arrowAmount; int amount = _arrowAmount;
if (GetKit(player) instanceof KitSlamShot) if (GetKit(player) instanceof KitSlamShot)
{ {
if (Manager.GetCondition().HasCondition(event.GetEvent().getEntity(), ConditionType.FALLING, null)) if (Manager.GetCondition().HasCondition(event.GetEvent().getEntity(),
ConditionType.FALLING, null))
{ {
amount++; amount++;
} }
} }
//New Arrow //New Arrow
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(262, (byte)0, amount, F.item("Super Arrow"))); player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(262, (byte) 0, amount,
F.item("Super Arrow")));
player.playSound(player.getLocation(), Sound.PISTON_EXTEND, 3f, 2f); player.playSound(player.getLocation(), Sound.PISTON_EXTEND, 3f, 2f);
//Score //Score
AddKill(player); AddKill(player);
} }
@Override @Override
public String GetMode() public String GetMode()
{ {

View File

@ -1599,6 +1599,9 @@ public class UHC extends TeamGame
if (visible) if (visible)
break; break;
} }
if(visible)
setOreType(vein);
// Remove Vein // Remove Vein
if (!visible) if (!visible)
@ -1621,6 +1624,11 @@ public class UHC extends TeamGame
} }
} }
} }
public void setOreType(ArrayList<Block> blocks)
{
}
public boolean isMapLoaded() public boolean isMapLoaded()
{ {

View File

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

View File

@ -0,0 +1,82 @@
package nautilus.game.arcade.game.games.uhc.modes;
import java.util.ArrayList;
import java.util.HashMap;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilMath;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.uhc.UHC;
/**
* GodBattles
*
* @author xXVevzZXx
*/
public class GodBattles extends UHC
{
private ArrayList<Material> _ores;
private HashMap<Material, Material> _oreDrops;
public GodBattles(ArcadeManager manager)
{
super(manager);
_ores = new ArrayList<>();
_ores.add(Material.GOLD_ORE);
_ores.add(Material.DIAMOND_ORE);
_oreDrops = new HashMap<>();
_oreDrops.put(Material.GOLD_ORE, Material.GOLD_BLOCK);
}
@EventHandler
public void smeltOres(BlockBreakEvent event)
{
for (Material mat : _oreDrops.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(_oreDrops.get(mat)));
}
}, 1);
}
}
}
@Override
public void setOreType(ArrayList<Block> blocks)
{
Material ore = _ores.get(UtilMath.r(_ores.size()));
for (Block block : blocks)
{
block.setType(ore);
}
}
@Override
public String GetMode()
{
return "God Battles";
}
}

View File

@ -308,25 +308,25 @@ public class GameCreationManager implements Listener
{ {
_nextGame = type; _nextGame = type;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void modifyGameConfiguration(Class<? extends Game> gameClass, GameMode mode, Game game) private void modifyGameConfiguration(Class<? extends Game> gameClass, GameMode mode, Game game)
{ {
ArrayList<Class<? extends Game>> classes = new ArrayList<>(); ArrayList<Class<? extends Game>> classes = new ArrayList<>();
classes.add(gameClass); classes.add(gameClass);
classes.add((Class<? extends Game>) gameClass.getSuperclass()); 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(); Class<? extends Game> gameType = (Class<? extends Game>) gameClass.getSuperclass();
classes.add((Class<? extends Game>) gameType.getSuperclass()); classes.add((Class<? extends Game>) gameType.getSuperclass());
} }
HashMap<String, String> varSet = Manager.GetServerConfig().GameModeMods.get(mode.getName()); HashMap<String, String> varSet = Manager.GetServerConfig().GameModeMods.get(mode.getName());
if(varSet == null) if (varSet == null)
return; return;
for (Class<? extends Game> clazz : classes) for (Class<? extends Game> clazz : classes)
{ {
for (String var : varSet.keySet()) for (String var : varSet.keySet())
@ -336,28 +336,31 @@ public class GameCreationManager implements Listener
{ {
boolean add = value.contains("+"); boolean add = value.contains("+");
boolean remove = value.contains("-"); boolean remove = value.contains("-");
value = value.split("\\(")[1]; value = value.split("\\(")[1];
value = value.replace(")", ""); value = value.replace(")", "");
processList(clazz, game, var, value.contains(":") ? value.split("\\:") : new String[]{value}, add, remove); processList(clazz, game, var,
value.contains(":") ? value.split("\\:") : new String[]
{ value }, add, remove);
} }
else if (value.contains("[")) else if (value.contains("["))
{ {
value = value.split("\\[")[1]; value = value.split("\\[")[1];
value = value.replace("]", ""); value = value.replace("]", "");
Map<String, String> varMap = new HashMap<>(); Map<String, String> varMap = new HashMap<>();
String[] values = value.contains(":") ? value.split(":") : new String[]{value}; String[] values = value.contains(":") ? value.split(":") : new String[]
{ value };
for (String keyValueSet : values) for (String keyValueSet : values)
{ {
String key = keyValueSet.split("\\$")[0]; String key = keyValueSet.split("\\$")[0];
String val = keyValueSet.split("\\$")[1]; String val = keyValueSet.split("\\$")[1];
varMap.put(key, val); varMap.put(key, val);
} }
processMap(clazz, game, var, varMap); processMap(clazz, game, var, varMap);
} }
else else
@ -367,31 +370,33 @@ public class GameCreationManager implements Listener
} }
} }
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void processMap(Class<? extends Game> clazz, Game game, String var, Map<String, String> map) private void processMap(Class<? extends Game> clazz, Game game, String var,
Map<String, String> map)
{ {
Field f = getField(clazz, var); Field f = getField(clazz, var);
if(f == null) if (f == null)
return; return;
try try
{ {
f.setAccessible(true); f.setAccessible(true);
ParameterizedType type = (ParameterizedType) f.getGenericType(); ParameterizedType type = (ParameterizedType) f.getGenericType();
Type keyGeneric = type.getActualTypeArguments()[0]; Type keyGeneric = type.getActualTypeArguments()[0];
Class<?> keyGenericClazz = Class.forName(keyGeneric.getTypeName()); Class<?> keyGenericClazz = Class.forName(keyGeneric.getTypeName());
Type valueGeneric = type.getActualTypeArguments()[1]; Type valueGeneric = type.getActualTypeArguments()[1];
Class<?> valueGenericClazz = Class.forName(valueGeneric.getTypeName()); Class<?> valueGenericClazz = Class.forName(valueGeneric.getTypeName());
Map<Object, Object> currentMap = (Map<Object, Object>) f.get(game); Map<Object, Object> currentMap = (Map<Object, Object>) f.get(game);
for (String key : map.keySet()) for (String key : map.keySet())
{ {
currentMap.put(parseValue(keyGenericClazz, key, game), parseValue(valueGenericClazz, map.get(key), game)); currentMap.put(parseValue(keyGenericClazz, key, game),
parseValue(valueGenericClazz, map.get(key), game));
} }
f.setAccessible(false); f.setAccessible(false);
} }
@ -400,30 +405,31 @@ public class GameCreationManager implements Listener
System.out.println("Error while editing map"); System.out.println("Error while editing map");
} }
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void processList(Class<? extends Game> clazz, Game game, String var, String[] value, boolean add, boolean remove) private void processList(Class<? extends Game> clazz, Game game, String var, String[] value,
boolean add, boolean remove)
{ {
Field f = getField(clazz, var); Field f = getField(clazz, var);
if(f == null) if (f == null)
return; return;
try try
{ {
f.setAccessible(true); f.setAccessible(true);
ParameterizedType type = (ParameterizedType) f.getGenericType(); ParameterizedType type = (ParameterizedType) f.getGenericType();
Type generic = type.getActualTypeArguments()[0]; Type generic = type.getActualTypeArguments()[0];
Class<?> genericClazz = Class.forName(generic.getTypeName()); Class<?> genericClazz = Class.forName(generic.getTypeName());
ArrayList<Object> currentList = (ArrayList<Object>) f.get(game); ArrayList<Object> currentList = (ArrayList<Object>) f.get(game);
if (!add && !remove) if (!add && !remove)
{ {
add = true; add = true;
currentList.clear(); currentList.clear();
} }
for(String finalValue : value) for (String finalValue : value)
{ {
if (add) if (add)
{ {
@ -434,7 +440,7 @@ public class GameCreationManager implements Listener
currentList.remove(parseValue(genericClazz, finalValue, game)); currentList.remove(parseValue(genericClazz, finalValue, game));
} }
} }
f.setAccessible(false); f.setAccessible(false);
} }
catch (Exception ex) catch (Exception ex)
@ -442,13 +448,13 @@ public class GameCreationManager implements Listener
System.out.println("Error while editing list"); System.out.println("Error while editing list");
} }
} }
private void processVariable(Class<? extends Game> clazz, Game game, String var, String value) private void processVariable(Class<? extends Game> clazz, Game game, String var, String value)
{ {
Field f = getField(clazz, var); Field f = getField(clazz, var);
if(f == null) if (f == null)
return; return;
try try
{ {
f.setAccessible(true); f.setAccessible(true);
@ -465,7 +471,7 @@ public class GameCreationManager implements Listener
System.out.println("Error while setting variable"); System.out.println("Error while setting variable");
} }
} }
private Object parseValue(Class<?> clazz, String value, Game game) private Object parseValue(Class<?> clazz, String value, Game game)
{ {
try try
@ -512,13 +518,13 @@ public class GameCreationManager implements Listener
} }
return null; return null;
} }
catch(Exception ex) catch (Exception ex)
{ {
System.out.println("Error while parsing value"); System.out.println("Error while parsing value");
return null; return null;
} }
} }
private Field getField(Class<? extends Game> clazz, String var) private Field getField(Class<? extends Game> clazz, String var)
{ {
Field f = null; Field f = null;
@ -526,13 +532,15 @@ public class GameCreationManager implements Listener
{ {
f = clazz.getDeclaredField(var); f = clazz.getDeclaredField(var);
} }
catch (Exception e) catch (Exception e)
{ {
try try
{ {
f = clazz.getDeclaredField("_" + var); f = clazz.getDeclaredField("_" + var);
} }
catch (Exception ex) {} catch (Exception ex)
{
}
} }
return f; return f;
} }