Made new branch up to date and including previous branch's code

This commit is contained in:
AlexTheCoder 2015-08-30 03:58:58 -04:00
parent 47331658ac
commit eca69a8ae2
4 changed files with 734 additions and 0 deletions

View File

@ -66,6 +66,8 @@ public enum GameDisplay
Lobbers("Bomb Lobbers", Material.FIREBALL, (byte) 0, GameCategory.ARCADE, 54), Lobbers("Bomb Lobbers", Material.FIREBALL, (byte) 0, GameCategory.ARCADE, 54),
ChampionsCTF("Champions Capture the Flag", "Champions", Material.REDSTONE_BLOCK, (byte)0, GameCategory.CHAMPIONS, 55),
Event("Mineplex Event", Material.CAKE, (byte)0, GameCategory.EVENT, 999); Event("Mineplex Event", Material.CAKE, (byte)0, GameCategory.EVENT, 999);
String _name; String _name;

View File

@ -9,6 +9,7 @@ import nautilus.game.arcade.game.games.bridge.Bridge;
import nautilus.game.arcade.game.games.build.Build; import nautilus.game.arcade.game.games.build.Build;
import nautilus.game.arcade.game.games.cards.Cards; import nautilus.game.arcade.game.games.cards.Cards;
import nautilus.game.arcade.game.games.castlesiege.CastleSiege; import nautilus.game.arcade.game.games.castlesiege.CastleSiege;
import nautilus.game.arcade.game.games.champions.ChampionsCTF;
import nautilus.game.arcade.game.games.champions.ChampionsDominate; import nautilus.game.arcade.game.games.champions.ChampionsDominate;
import nautilus.game.arcade.game.games.champions.ChampionsTDM; import nautilus.game.arcade.game.games.champions.ChampionsTDM;
import nautilus.game.arcade.game.games.christmas.Christmas; import nautilus.game.arcade.game.games.christmas.Christmas;
@ -68,6 +69,7 @@ public enum GameType
Barbarians(Barbarians.class, GameDisplay.Barbarians), Barbarians(Barbarians.class, GameDisplay.Barbarians),
Bridge(Bridge.class, GameDisplay.Bridge), Bridge(Bridge.class, GameDisplay.Bridge),
CastleSiege(CastleSiege.class, GameDisplay.CastleSiege), CastleSiege(CastleSiege.class, GameDisplay.CastleSiege),
ChampionsCTF(ChampionsCTF.class, GameDisplay.ChampionsCTF),
ChampionsDominate(ChampionsDominate.class, GameDisplay.ChampionsDominate), ChampionsDominate(ChampionsDominate.class, GameDisplay.ChampionsDominate),
//ChampionsMOBA(ChampionsMOBA.class, "Champions MOBA", "Champions", Material.SKULL_ITEM, (byte)0, GameCategory.CHAMPIONS, 7), //ChampionsMOBA(ChampionsMOBA.class, "Champions MOBA", "Champions", Material.SKULL_ITEM, (byte)0, GameCategory.CHAMPIONS, 7),
ChampionsTDM(ChampionsTDM.class, GameDisplay.ChampionsTDM), ChampionsTDM(ChampionsTDM.class, GameDisplay.ChampionsTDM),

View File

@ -0,0 +1,465 @@
package nautilus.game.arcade.game.games.common;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.elo.EloPlayer;
import mineplex.core.elo.EloTeam;
import mineplex.core.elo.GameResult;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.combat.CombatComponent;
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.events.PlayerGameRespawnEvent;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.TeamGame;
import nautilus.game.arcade.game.games.champions.ChampionsCTF;
import nautilus.game.arcade.game.games.common.ctf_data.Flag;
import nautilus.game.arcade.game.games.common.dominate_data.PlayerData;
import nautilus.game.arcade.kit.Kit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
public class CaptureTheFlag extends TeamGame
{
//Map Data
private Location _redFlag;
private Location _blueFlag;
public ArrayList<Block> RedZone = new ArrayList<Block>();
public ArrayList<Block> BlueZone = new ArrayList<Block>();
private ArrayList<Flag> _flags = new ArrayList<Flag>();
//Stats
private HashMap<String, PlayerData> _stats = new HashMap<String, PlayerData>();
//Captures
private int _victoryCaps = 3;
private int _redScore = 0;
private int _blueScore = 0;
//Times
private long _gameTime = 300000;
//private long _gameEndAnnounce = 0;
protected String[] _blockedItems = new String[] {"SWORD", "AXE", "BOW"};
public CaptureTheFlag(ArcadeManager manager, GameType type, Kit[] kits)
{
super(manager, type, kits,
new String[]
{
"Capture The Opponent's Flag",
"First team to 3 Captures",
"Or with the most Captures after 5 minutes wins"
});
this.DeathOut = false;
this.PrepareFreeze = true;
this.VersionRequire1_8 = true;
this.HungerSet = 20;
this.WorldTimeSet = 2000;
this.DeathSpectateSecs = 10;
}
@Override
public void ParseData()
{
_redFlag = WorldData.GetDataLocs("RED").get(0);
_blueFlag = WorldData.GetDataLocs("BLUE").get(0);
for (GameTeam team : GetTeamList())
{
if (team.GetColor() == ChatColor.RED || team.GetColor() == ChatColor.BLUE || team.GetColor() == ChatColor.AQUA)
{
_flags.add(new Flag(this, team.GetColor() == ChatColor.RED ? _redFlag : _blueFlag, team));
}
}
//Kit spawning
if (this instanceof ChampionsCTF)
{
CreatureAllowOverride = true;
for (int i = 0; i < GetKits().length && i < WorldData.GetDataLocs("PURPLE").size() && i < WorldData.GetDataLocs("ORANGE").size(); i++)
{
Entity ent = GetKits()[i].SpawnEntity(WorldData.GetDataLocs("ORANGE").get(i));
Manager.GetLobby().AddKitLocation(ent, GetKits()[i], WorldData.GetDataLocs("ORANGE").get(i));
ent = GetKits()[i].SpawnEntity(WorldData.GetDataLocs("PURPLE").get(i));
Manager.GetLobby().AddKitLocation(ent, GetKits()[i], WorldData.GetDataLocs("PURPLE").get(i));
}
CreatureAllowOverride = false;
}
//End kit spawning
for (Location red : WorldData.GetDataLocs("PINK"))
{
//Get 3 blocks above = exact cap zone.
for (int i = 0 ; i < 3 ; i++)
{
RedZone.add(red.clone().add(0, i, 0).getBlock());
}
}
for (Location blue : WorldData.GetDataLocs("LIGHT_BLUE"))
{
//Get 3 blocks above = exact cap zone.
for (int i = 0 ; i < 3 ; i++)
{
BlueZone.add(blue.clone().add(0, i, 0).getBlock());
}
}
}
@EventHandler
public void CustomTeamGeneration(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Recruit)
return;
for (GameTeam team : GetTeamList())
if (team.GetColor() == ChatColor.AQUA)
team.SetColor(ChatColor.BLUE);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void blockliquidFlow(BlockPhysicsEvent event)
{
Material matOfBlock = event.getBlock().getType();
if (matOfBlock == Material.STATIONARY_WATER || matOfBlock == Material.SAND || matOfBlock == Material.GRAVEL || matOfBlock == Material.STATIONARY_LAVA)
{
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onTNTExplode(EntityExplodeEvent event)
{
if (!IsLive())
return;
if (event.getEntityType() == EntityType.PRIMED_TNT)
{
event.setCancelled(true);
}
}
@EventHandler
public void Updates(UpdateEvent event)
{
if (!IsLive())
return;
if (event.getType() == UpdateType.FASTEST)
for (Flag flag : _flags)
flag.Update();
else
ProgressTime();
}
public void ProgressTime()
{
long remain = _gameTime - (System.currentTimeMillis() - GetStateTime());
if (remain <= 0)
{
if (_redScore > _blueScore)
AnnounceEnd(GetTeam(ChatColor.RED));
else if(_redScore < _blueScore)
AnnounceEnd(GetTeam(ChatColor.BLUE));
else
AnnounceEnd((GameTeam) null);
SetState(GameState.End);
}
}
public void AddCapture(GameTeam team)
{
if (team.GetColor() == ChatColor.RED)
{
_redScore = Math.min(_victoryCaps, _redScore + 1);
}
else
{
_blueScore = Math.min(_victoryCaps, _blueScore + 1);
}
EndCheckScore();
}
public boolean isAtHome(ChatColor team)
{
for (Flag flag : _flags)
{
if (flag.getTeam().GetColor() == team)
return flag.isAtHome();
}
return false;
}
public List<Block> getZoneBlocks(ChatColor color)
{
return getZoneBlocks(GetTeam(color));
}
public List<Block> getZoneBlocks(GameTeam team)
{
if (team == null)
return new ArrayList<Block>();
if (team.GetColor() == ChatColor.RED)
return RedZone;
else if (team.GetColor() == ChatColor.BLUE)
return BlueZone;
return new ArrayList<Block>();
}
@Override
@EventHandler
public void ScoreboardUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
ScoreboardWrite();
}
private void ScoreboardWrite()
{
if (!InProgress())
return;
//Wipe Last
Scoreboard.Reset();
//Scores
Scoreboard.WriteBlank();
Scoreboard.Write("First to " + _victoryCaps);
Scoreboard.WriteBlank();
Scoreboard.Write(C.cRed + "Red Team");
Scoreboard.Write(_redScore + C.cRed);
Scoreboard.WriteBlank();
Scoreboard.Write(C.cAqua + "Blue Team");
Scoreboard.Write(_blueScore + C.cAqua);
Scoreboard.WriteBlank();
Scoreboard.Write("Time Remaining:");
Scoreboard.Write(UtilTime.MakeStr(Math.max(_gameTime - (System.currentTimeMillis() - GetStateTime()), 0)) + C.cWhite);
Scoreboard.Draw();
}
public void EndCheckScore()
{
if (!IsLive())
return;
GameTeam winner = null;
if (_redScore >= _victoryCaps)
winner = GetTeam(ChatColor.RED);
else if (_blueScore >= _victoryCaps)
winner = GetTeam(ChatColor.BLUE);
if (winner == null)
return;
ScoreboardWrite();
//Announce
AnnounceEnd(winner);
for (GameTeam team : GetTeamList())
{
if (WinnerTeam != null && team.equals(WinnerTeam))
{
for (Player player : team.GetPlayers(false))
AddGems(player, 10, "Winning Team", false, false);
}
for (Player player : team.GetPlayers(false))
if (player.isOnline())
AddGems(player, 10, "Participation", false, false);
}
if (EloRanking)
{
EloTeam teamWinner = new EloTeam();
EloTeam teamLoser = new EloTeam();
for (GameTeam team : GetTeamList())
{
if (WinnerTeam != null && team.equals(WinnerTeam))
{
for (Player player : WinnerTeam.GetPlayers(false))
{
EloPlayer eloPlayer = new EloPlayer();
eloPlayer.UniqueId = player.getUniqueId().toString();
eloPlayer.Rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName());
teamWinner.addPlayer(eloPlayer);
}
}
else
{
for (Player player : team.GetPlayers(false))
{
EloPlayer eloPlayer = new EloPlayer();
eloPlayer.UniqueId = player.getUniqueId().toString();
eloPlayer.Rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName());
teamLoser.addPlayer(eloPlayer);
}
}
}
for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamWinner, teamLoser, GameResult.Win).getPlayers())
{
Manager.getEloManager().saveElo(eloPlayer.UniqueId, GetName(), eloPlayer.Rating);
}
for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamLoser, teamWinner, GameResult.Loss).getPlayers())
{
Manager.getEloManager().saveElo(eloPlayer.UniqueId, GetName(), eloPlayer.Rating);
}
}
//End
SetState(GameState.End);
}
@Override
public double GetKillsGems(Player killer, Player killed, boolean assist)
{
return 1;
}
public String GetMode()
{
return "Capture the Flag";
}
@EventHandler
public void RespawnRegen(PlayerGameRespawnEvent event)
{
Manager.GetCondition().Factory().Regen("Respawn", event.GetPlayer(), event.GetPlayer(), 8, 3, false, false, false);
Manager.GetCondition().Factory().Protection("Respawn", event.GetPlayer(), event.GetPlayer(), 8, 3, false, false, false);
}
public PlayerData GetStats(Player player)
{
if (!_stats.containsKey(player.getName()))
_stats.put(player.getName(), new PlayerData(player.getName()));
return _stats.get(player.getName());
}
@EventHandler
public void StatsKillAssistDeath(CombatDeathEvent event)
{
Game game = Manager.GetGame();
if (game == null) return;
if (!(event.GetEvent().getEntity() instanceof Player))
return;
Player killed = (Player)event.GetEvent().getEntity();
GetStats(killed).Deaths++;
if (event.GetLog().GetKiller() != null)
{
Player killer = UtilPlayer.searchExact(event.GetLog().GetKiller().GetName());
if (killer != null && !killer.equals(killed))
GetStats(killer).Kills++;
}
for (CombatComponent log : event.GetLog().GetAttackers())
{
if (event.GetLog().GetKiller() != null && log.equals(event.GetLog().GetKiller()))
continue;
Player assist = UtilPlayer.searchExact(log.GetName());
//Assist
if (assist != null)
GetStats(assist).Assists++;
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void StatsKillAssistDeath(CustomDamageEvent event)
{
Player damager = event.GetDamagerPlayer(true);
if (damager != null)
{
GetStats(damager).DamageDealt += event.GetDamage();
}
Player damagee = event.GetDamageePlayer();
if (damagee != null)
{
GetStats(damagee).DamageTaken += event.GetDamage();
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void UsableInteract(PlayerInteractEvent event)
{
if (UtilBlock.usable(event.getClickedBlock()))
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.LOWEST)
public void GrabFlag(PlayerInteractEvent event)
{
if (!IsLive())
return;
if (event.isCancelled())
return;
if (!IsAlive(event.getPlayer()))
return;
for (String blocked : _blockedItems)
{
if (event.getPlayer().getItemInHand().getType().toString().contains(blocked))
return;
}
for (Flag flag : _flags)
if (flag.Pickup(event.getPlayer(), event.getClickedBlock()))
event.setCancelled(true);
}
}

View File

@ -0,0 +1,265 @@
package nautilus.game.arcade.game.games.common.ctf_data;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilTime;
import mineplex.core.recharge.Recharge;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.common.CaptureTheFlag;
import org.bukkit.ChatColor;
import org.bukkit.FireworkEffect;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class Flag
{
private CaptureTheFlag Host;
private Location _spawn;
private Block[] _flagBlocks;
private GameTeam _team;
private ItemStack _representation;
private Player _holding = null;
private boolean _moved = false;
private boolean _dropped = false;
private long _dropTime = 0;
public Flag (CaptureTheFlag host, Location spawn, GameTeam team)
{
Host = host;
_spawn = spawn;
_team = team;
ItemStack i;
if (team.GetColor() == ChatColor.RED)
i = new ItemStack(Material.REDSTONE_BLOCK);
else
i = new ItemStack(Material.LAPIS_BLOCK);
ItemMeta im = i.getItemMeta();
im.setDisplayName(team.GetColor() + team.GetName() + "'s Flag".replace("s's", "s'"));
i.setItemMeta(im);
_representation = i;
SpawnFlag(spawn, team.GetColor() == ChatColor.RED);
}
public GameTeam getTeam()
{
return _team;
}
public boolean isAtHome()
{
return !_moved;
}
private void AnnounceCapture()
{
UtilTextMiddle.display("Your flag has", "been stolen! Retrieve it!", _team.GetPlayers(true).toArray(new Player[0]));
for (Player player : _team.GetPlayers(true))
{
UtilPlayer.message(player, F.main("Game", "Your flag has been stolen! Retrieve it!"));
}
}
private void AnnounceDrop()
{
UtilTextMiddle.display("Your flag has", "been dropped! Defend it!", _team.GetPlayers(true).toArray(new Player[0]));
for (Player player : _team.GetPlayers(true))
{
UtilPlayer.message(player, F.main("Game", "Your flag has been dropped! Defend it!"));
}
}
public void Update()
{
if (_moved)
{
if (_dropped)
{
//Bukkit.broadcastMessage(System.currentTimeMillis() + ":" + _dropTime + (10 * 60 * 1000));
if (!UtilTime.elapsed(_dropTime, 200 * 60))
return;
for (Block block : _flagBlocks)
{
block.setType(Material.AIR);
}
SpawnFlag(_spawn, _team.GetColor() == ChatColor.RED);
UtilTextMiddle.display("Your flag has", "returned to safety!", _team.GetPlayers(true).toArray(new Player[0]));
for (Player player : _team.GetPlayers(true))
{
UtilPlayer.message(player, F.main("Game", "Your flag has returned to safety!"));
}
UtilFirework.playFirework(_spawn.clone().add(0, 1, 0), FireworkEffect.builder().flicker(false).withColor(_team.GetColorBase()).with(Type.BURST).trail(true).build());
_moved = false;
_dropped = false;
return;
}
if (!_holding.isOnline())
{
Drop(_holding);
return;
}
if (UtilPlayer.isSpectator(_holding))
{
Drop(_holding);
return;
}
if (!Host.IsAlive(_holding))
{
Drop(_holding);
return;
}
Score(_holding);
}
}
public void SpawnFlag(Location loc, boolean red)
{
_flagBlocks = new Block[]
{
loc.getBlock(),
loc.clone().add(0, 1, 0).getBlock()
};
for (Block block : _flagBlocks)
{
block.setType(_representation.getType());
}
}
public boolean Pickup(Player player, Block block)
{
if (_holding == null)
{
if (Host.GetTeam(player) != _team)
{
if (block != null)
{
if (block.getType() == _representation.getType())
{
boolean isFlag = false;
for (Block flagBlock : _flagBlocks)
{
if (block.getLocation().equals(flagBlock.getLocation()))
{
isFlag = true;
break;
}
}
if (!isFlag)
return false;
for (Block flagBlock : _flagBlocks)
{
flagBlock.setType(Material.AIR);
}
for (int i = 0; i < 9; i++)
{
player.getInventory().setItem(i, _representation);
}
player.updateInventory();
AnnounceCapture();
_holding = player;
_dropped = false;
_dropTime = 0;
_moved = true;
return true;
}
}
}
}
return false;
}
public void Drop(Player player)
{
if (_moved)
{
if (_holding != null)
{
if (_holding.getUniqueId() == player.getUniqueId())
{
SpawnFlag(player.getLocation(), _team.GetColor() == ChatColor.RED);
AnnounceDrop();
_holding = null;
_dropped = true;
_dropTime = System.currentTimeMillis();
}
}
}
}
public void Score(Player player)
{
if (_moved)
{
if (_holding != null)
{
if (_holding.getUniqueId() == player.getUniqueId())
{
// List<Block> zone = null;
// if (Host.GetTeam(player).GetColor() == ChatColor.RED) zone = Host.RedZone;
// else zone = Host.BlueZone;
if (Host.getZoneBlocks(_team.GetColor() == ChatColor.RED ? ChatColor.BLUE : ChatColor.RED).contains(player.getLocation().getBlock()))
{
if (!Host.isAtHome(_team.GetColor() == ChatColor.RED ? ChatColor.BLUE : ChatColor.RED))
{
if (Recharge.Instance.use(player, "No Cap Message", 1000, false, false))
{
UtilTextMiddle.display("", C.cRed + "Your flag must be at home to capture!", player);
}
return;
}
Host.Manager.getClassManager().Get(player).ResetItems();
UtilTextMiddle.display(player.getName(), "has captured " + _team.GetName() + "'s flag!".replace("s's", "s'"));
for (Player p : UtilServer.getPlayers())
{
UtilPlayer.message(p, F.main("Game", player.getName() + " has captured " + _team.GetName() + "'s flag!".replace("s's", "s'")));
}
Host.AddGems(player, 10, "Enemy Flag Captured", true, true);
Host.AddCapture(Host.GetTeam(player));
SpawnFlag(_spawn, _team.GetColor() == ChatColor.RED);
_moved = false;
_dropped = false;
_dropTime = 0;
_holding = null;
}
}
}
}
}
}