Made CTF follow Chiss' specifications and also added more advanced features
This commit is contained in:
parent
6fefcbd953
commit
474f1bd0b8
@ -3,9 +3,11 @@ package nautilus.game.arcade.game.games.common;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.elo.EloPlayer;
|
||||
@ -32,7 +34,6 @@ 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;
|
||||
@ -40,15 +41,15 @@ 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.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
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
|
||||
@ -61,9 +62,10 @@ public class CaptureTheFlag extends TeamGame
|
||||
|
||||
//Times
|
||||
private long _gameTime = 300000;
|
||||
//private long _gameEndAnnounce = 0;
|
||||
|
||||
protected String[] _blockedItems = new String[] {"SWORD", "AXE", "BOW"};
|
||||
//protected String[] _blockedItems = new String[] {"SWORD", "AXE", "BOW"};
|
||||
|
||||
private ConcurrentHashMap<Player, List<ItemStack>> _hotbars = new ConcurrentHashMap<Player, List<ItemStack>>();
|
||||
|
||||
public CaptureTheFlag(ArcadeManager manager, GameType type, Kit[] kits)
|
||||
{
|
||||
@ -92,6 +94,9 @@ public class CaptureTheFlag extends TeamGame
|
||||
_redFlag = WorldData.GetDataLocs("RED").get(0);
|
||||
_blueFlag = WorldData.GetDataLocs("BLUE").get(0);
|
||||
|
||||
/*ItemDropAllow.add(Material.REDSTONE_BLOCK.getId());
|
||||
ItemDropAllow.add(Material.LAPIS_BLOCK.getId());*/
|
||||
|
||||
for (GameTeam team : GetTeamList())
|
||||
{
|
||||
if (team.GetColor() == ChatColor.RED || team.GetColor() == ChatColor.BLUE || team.GetColor() == ChatColor.AQUA)
|
||||
@ -119,23 +124,6 @@ public class CaptureTheFlag extends TeamGame
|
||||
}
|
||||
|
||||
//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
|
||||
@ -179,8 +167,20 @@ public class CaptureTheFlag extends TeamGame
|
||||
return;
|
||||
|
||||
if (event.getType() == UpdateType.FASTEST)
|
||||
{
|
||||
for (Flag flag : _flags)
|
||||
flag.Update();
|
||||
|
||||
for (Player player : _hotbars.keySet())
|
||||
if (!player.isOnline() || UtilPlayer.isSpectator(player) || !IsAlive(player))
|
||||
_hotbars.remove(player);
|
||||
}
|
||||
else if (event.getType() == UpdateType.TICK)
|
||||
for (Flag flag : _flags)
|
||||
if (flag.getCarrier() == null)
|
||||
for (Player player : GetPlayers(true))
|
||||
if (UtilMath.offset(player.getLocation(), flag.getPlacedLocation()) < 4)
|
||||
flag.Pickup(player, flag.getPlacedLocation().getBlock());
|
||||
else
|
||||
ProgressTime();
|
||||
}
|
||||
@ -216,6 +216,36 @@ public class CaptureTheFlag extends TeamGame
|
||||
EndCheckScore();
|
||||
}
|
||||
|
||||
public void SaveHotbar(Player player)
|
||||
{
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
if (player.getInventory().getItem(i) != null)
|
||||
items.add(i, player.getInventory().getItem(i));
|
||||
else
|
||||
items.add(i, new ItemStack(Material.AIR));
|
||||
}
|
||||
_hotbars.put(player, items);
|
||||
}
|
||||
|
||||
public void ResetItems(Player player)
|
||||
{
|
||||
if (_hotbars.containsKey(player))
|
||||
{
|
||||
List<ItemStack> items = _hotbars.get(player);
|
||||
for (int i = 0; i < items.size(); i++)
|
||||
{
|
||||
if (items.get(i).getType() != Material.AIR)
|
||||
player.getInventory().setItem(i, items.get(i));
|
||||
else
|
||||
player.getInventory().setItem(i, new ItemStack(Material.AIR));
|
||||
}
|
||||
player.updateInventory();
|
||||
_hotbars.remove(player);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAtHome(ChatColor team)
|
||||
{
|
||||
for (Flag flag : _flags)
|
||||
@ -226,20 +256,30 @@ public class CaptureTheFlag extends TeamGame
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<Block> getZoneBlocks(ChatColor color)
|
||||
public Location getRedFlag()
|
||||
{
|
||||
return getZoneBlocks(GetTeam(color));
|
||||
return _redFlag;
|
||||
}
|
||||
|
||||
public List<Block> getZoneBlocks(GameTeam team)
|
||||
public Location getBlueFlag()
|
||||
{
|
||||
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>();
|
||||
return _blueFlag;
|
||||
}
|
||||
|
||||
public boolean isInZone(Location location, boolean red)
|
||||
{
|
||||
if (red)
|
||||
{
|
||||
if (UtilMath.offset(location, _redFlag) < 4)
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (UtilMath.offset(location, _blueFlag) < 4)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -441,7 +481,7 @@ public class CaptureTheFlag extends TeamGame
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
/*@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void GrabFlag(PlayerInteractEvent event)
|
||||
{
|
||||
if (!IsLive())
|
||||
@ -462,10 +502,10 @@ public class CaptureTheFlag extends TeamGame
|
||||
for (Flag flag : _flags)
|
||||
if (flag.Pickup(event.getPlayer(), event.getClickedBlock()))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}*/
|
||||
|
||||
@EventHandler
|
||||
public void selectKit(PlayerKitApplyEvent event)
|
||||
public void SelectKit(PlayerKitApplyEvent event)
|
||||
{
|
||||
if (this instanceof ChampionsCTF)
|
||||
{
|
||||
@ -478,4 +518,19 @@ public class CaptureTheFlag extends TeamGame
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void DropFlag(PlayerDropItemEvent event)
|
||||
{
|
||||
for (Flag flag : _flags)
|
||||
if (flag.getRepresentation() == event.getItemDrop().getItemStack().getType())
|
||||
if (flag.getCarrier() != null)
|
||||
if (flag.getCarrier().getName().equals(event.getPlayer().getName()))
|
||||
{
|
||||
event.setCancelled(false);
|
||||
event.getItemDrop().remove();
|
||||
flag.Drop(event.getPlayer());
|
||||
ResetItems(event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,15 @@ 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.UtilParticle;
|
||||
import mineplex.core.common.util.UtilParticle.ParticleType;
|
||||
import mineplex.core.common.util.UtilParticle.ViewDist;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.common.util.UtilTextBottom;
|
||||
import mineplex.core.common.util.UtilTextMiddle;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.hologram.Hologram;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import nautilus.game.arcade.game.GameTeam;
|
||||
import nautilus.game.arcade.game.games.common.CaptureTheFlag;
|
||||
@ -38,6 +43,8 @@ public class Flag
|
||||
private boolean _dropped = false;
|
||||
private long _dropTime = 0;
|
||||
|
||||
private Hologram _name, _time;
|
||||
|
||||
public Flag (CaptureTheFlag host, Location spawn, GameTeam team)
|
||||
{
|
||||
Host = host;
|
||||
@ -56,6 +63,9 @@ public class Flag
|
||||
|
||||
_representation = i;
|
||||
|
||||
_name = new Hologram(Host.getArcadeManager().getHologramManager(), spawn, team.GetColor() + team.GetName() + "'s Flag".replace("s's", "s'"));
|
||||
_time = new Hologram(Host.getArcadeManager().getHologramManager(), spawn, "");
|
||||
|
||||
SpawnFlag(spawn, team.GetColor() == ChatColor.RED);
|
||||
}
|
||||
|
||||
@ -74,18 +84,33 @@ public class Flag
|
||||
return _holding;
|
||||
}
|
||||
|
||||
private void AnnounceCapture()
|
||||
public Location getPlacedLocation()
|
||||
{
|
||||
UtilTextMiddle.display("Your flag has", "been stolen! Retrieve it!", _team.GetPlayers(true).toArray(new Player[0]));
|
||||
return _flagBlocks[0].getLocation();
|
||||
}
|
||||
|
||||
public Material getRepresentation()
|
||||
{
|
||||
return _representation.getType();
|
||||
}
|
||||
|
||||
private void AnnounceCapture(Player cap)
|
||||
{
|
||||
UtilTextMiddle.display("", "Your flag has been stolen! Retrieve it!", _team.GetPlayers(true).toArray(new Player[0]));
|
||||
UtilTextMiddle.display("", cap.getName() + " has stolen the enemy flag!", Host.GetTeam(cap).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!"));
|
||||
}
|
||||
for (Player player : Host.GetTeam(cap).GetPlayers(true))
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Game", cap.getName() + " has captured the enemy flag!"));
|
||||
}
|
||||
}
|
||||
|
||||
private void AnnounceDrop()
|
||||
{
|
||||
UtilTextMiddle.display("Your flag has", "been dropped! Defend it!", _team.GetPlayers(true).toArray(new Player[0]));
|
||||
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!"));
|
||||
@ -94,30 +119,41 @@ public class Flag
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (!_moved || _dropped)
|
||||
for (Block block : _flagBlocks)
|
||||
block.setType(_representation.getType());
|
||||
|
||||
if (_moved)
|
||||
{
|
||||
if (_dropped)
|
||||
{
|
||||
//Bukkit.broadcastMessage(System.currentTimeMillis() + ":" + _dropTime + (10 * 60 * 1000));
|
||||
if (!UtilTime.elapsed(_dropTime, 200 * 60))
|
||||
Integer r = (int)(System.currentTimeMillis() - _dropTime) / 1000;
|
||||
Integer re = 10 - r;
|
||||
_time.setText(RemainColor(re) + re.toString());
|
||||
|
||||
if (!UtilTime.elapsed(_dropTime, 10000))
|
||||
return;
|
||||
|
||||
_name.stop();
|
||||
_time.stop();
|
||||
|
||||
for (Block block : _flagBlocks)
|
||||
{
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
|
||||
_moved = false;
|
||||
_dropped = false;
|
||||
SpawnFlag(_spawn, _team.GetColor() == ChatColor.RED);
|
||||
|
||||
UtilTextMiddle.display("Your flag has", "returned to safety!", _team.GetPlayers(true).toArray(new Player[0]));
|
||||
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;
|
||||
}
|
||||
|
||||
@ -139,10 +175,36 @@ public class Flag
|
||||
return;
|
||||
}
|
||||
|
||||
UtilTextBottom.display("Return the Flag to your Capture Zone!", _holding);
|
||||
|
||||
if (_team.GetColor() == ChatColor.RED)
|
||||
{
|
||||
for (int i = 0 ; i < 2 ; i++)
|
||||
UtilParticle.PlayParticle(ParticleType.RED_DUST, _holding.getEyeLocation().clone().add(0.0, 0.5, 0.0), 0, 0, 0, 0, 1,
|
||||
ViewDist.MAX, UtilServer.getPlayers());
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0 ; i < 2 ; i++)
|
||||
UtilParticle.PlayParticle(ParticleType.RED_DUST, _holding.getEyeLocation().clone().add(0.0, 0.5, 0.0), -1, 1, 1, 1, 0,
|
||||
ViewDist.MAX, UtilServer.getPlayers());
|
||||
}
|
||||
|
||||
if (Host.GetTeam(_holding).GetColor() == ChatColor.RED)
|
||||
_holding.setCompassTarget(Host.getRedFlag());
|
||||
else
|
||||
_holding.setCompassTarget(Host.getBlueFlag());
|
||||
Score(_holding);
|
||||
}
|
||||
}
|
||||
|
||||
private ChatColor RemainColor(int remain)
|
||||
{
|
||||
if (remain >= 7) return ChatColor.GREEN;
|
||||
if ((remain < 7) && (remain >= 4)) return ChatColor.YELLOW;
|
||||
return ChatColor.RED;
|
||||
}
|
||||
|
||||
public void SpawnFlag(Location loc, boolean red)
|
||||
{
|
||||
_flagBlocks = new Block[]
|
||||
@ -155,6 +217,21 @@ public class Flag
|
||||
{
|
||||
block.setType(_representation.getType());
|
||||
}
|
||||
if (!_moved)
|
||||
{
|
||||
_name.setLocation(loc.getBlock().getLocation().clone().add(0.5, 3, 0.5));
|
||||
_name.start();
|
||||
}
|
||||
else
|
||||
{
|
||||
_name.setLocation(_flagBlocks[0].getLocation().clone().add(0.5, 3, 0.5));
|
||||
_name.start();
|
||||
Integer r = (int)(System.currentTimeMillis() - _dropTime) / 1000;
|
||||
Integer re = 10 - r;
|
||||
_time.setText(RemainColor(re) + re.toString());
|
||||
_time.setLocation(_flagBlocks[0].getLocation().clone().add(0.5, 2, 0.5));
|
||||
_time.start();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean Pickup(Player player, Block block)
|
||||
@ -163,6 +240,9 @@ public class Flag
|
||||
{
|
||||
if (!UtilPlayer.isSpectator(player))
|
||||
{
|
||||
if (!Recharge.Instance.use(player, "Flag Pickup", 3000, false, false))
|
||||
return false;
|
||||
|
||||
if (Host.IsAlive(player))
|
||||
{
|
||||
if (Host.GetTeam(player) != _team)
|
||||
@ -188,14 +268,19 @@ public class Flag
|
||||
{
|
||||
flagBlock.setType(Material.AIR);
|
||||
}
|
||||
_name.stop();
|
||||
_time.stop();
|
||||
|
||||
Host.SaveHotbar(player);
|
||||
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
player.getInventory().setItem(i, _representation);
|
||||
}
|
||||
player.getInventory().setItem(4, new ItemStack(Material.COMPASS));
|
||||
player.updateInventory();
|
||||
|
||||
AnnounceCapture();
|
||||
AnnounceCapture(player);
|
||||
_holding = player;
|
||||
_dropped = false;
|
||||
_dropTime = 0;
|
||||
@ -220,6 +305,8 @@ public class Flag
|
||||
{
|
||||
if (_holding.getUniqueId() == player.getUniqueId())
|
||||
{
|
||||
Recharge.Instance.recharge(player, "Flag Pickup");
|
||||
Recharge.Instance.use(player, "Flag Pickup", 3000, false, false);
|
||||
SpawnFlag(player.getLocation(), _team.GetColor() == ChatColor.RED);
|
||||
AnnounceDrop();
|
||||
_holding = null;
|
||||
@ -241,9 +328,12 @@ public class Flag
|
||||
// List<Block> zone = null;
|
||||
// if (Host.GetTeam(player).GetColor() == ChatColor.RED) zone = Host.RedZone;
|
||||
// else zone = Host.BlueZone;
|
||||
if (_team.GetColor() == ChatColor.RED)
|
||||
if (!Host.isInZone(player.getLocation(), false)) return;
|
||||
|
||||
if (_team.GetColor() == ChatColor.BLUE)
|
||||
if (!Host.isInZone(player.getLocation(), true)) return;
|
||||
|
||||
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))
|
||||
@ -253,8 +343,8 @@ public class Flag
|
||||
return;
|
||||
}
|
||||
|
||||
Host.Manager.getClassManager().Get(player).ResetItems();
|
||||
UtilTextMiddle.display(player.getName(), "has captured " + _team.GetName() + "'s flag!".replace("s's", "s'"));
|
||||
Host.ResetItems(player);
|
||||
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'")));
|
||||
@ -262,12 +352,11 @@ public class Flag
|
||||
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;
|
||||
}
|
||||
SpawnFlag(_spawn, _team.GetColor() == ChatColor.RED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user