- Code Cleanup

- Transitioning to banners fully
- Preparation to remove banner bugs
This commit is contained in:
AlexTheCoder 2015-09-19 00:41:23 -04:00
parent 52a5c63166
commit 3a1acb9f37
2 changed files with 90 additions and 133 deletions

View File

@ -40,11 +40,13 @@ 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 net.minecraft.server.v1_7_R4.NBTTagCompound;
import net.minecraft.server.v1_7_R4.NBTTagString;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityEquipment;
import net.minecraft.server.v1_7_R4.PacketPlayOutSetSlot;
import net.minecraft.server.v1_7_R4.PacketPlayOutWindowItems;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
@ -135,7 +137,7 @@ public class CaptureTheFlag extends TeamGame
{
if (flag.getRepresentation().isSimilar(item))
{
eqiup.c = getFlag(flag.getTeam().GetColorData());
eqiup.c = getFlag(flag.getTeam().GetColor() == ChatColor.RED, flag.getDisplayName());
break;
}
}
@ -157,7 +159,7 @@ public class CaptureTheFlag extends TeamGame
{
flagMaterial = flag.getRepresentation();
flagItem = getFlag(flag.getTeam()
.GetColorData());
.GetColor() == ChatColor.RED, flag.getDisplayName());
break;
}
}
@ -219,17 +221,26 @@ public class CaptureTheFlag extends TeamGame
};
}
private net.minecraft.server.v1_7_R4.ItemStack getFlag(byte b)
@SuppressWarnings("deprecation")
private net.minecraft.server.v1_7_R4.ItemStack getFlag(boolean red, String displayName)
{
byte b;
if (red)
b = DyeColor.RED.getWoolData();
else
b = DyeColor.BLUE.getWoolData();
net.minecraft.server.v1_7_R4.ItemStack item = new net.minecraft.server.v1_7_R4.ItemStack(
PacketHandler.BANNER, 1, 32767);
NBTTagCompound nbtBase = new NBTTagCompound();
NBTTagCompound nbt = new NBTTagCompound();
NBTTagCompound display = new NBTTagCompound();
nbt.setInt("Base", b);
display.set("Name", new NBTTagString(displayName));
nbtBase.set("BlockEntityTag", nbt);
nbtBase.set("display", display);
item.setTag(nbtBase);
return item;
@ -335,6 +346,7 @@ public class CaptureTheFlag extends TeamGame
for (Player player : _hotbars.keySet())
if (!player.isOnline() || UtilPlayer.isSpectator(player) || !IsAlive(player))
_hotbars.remove(player);
for (Player player : _helmets.keySet())
if (!player.isOnline() || UtilPlayer.isSpectator(player) || !IsAlive(player))
_helmets.remove(player);
@ -343,8 +355,8 @@ public class CaptureTheFlag extends TeamGame
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());
if (UtilMath.offset(player.getLocation(), flag.getPlacedLocation()) < 1)
flag.Pickup(player);
else
ProgressTime();
}

View File

@ -1,15 +1,14 @@
package nautilus.game.arcade.game.games.common.ctf_data;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilEnt;
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.disguise.disguises.DisguiseArmorStand;
import mineplex.core.hologram.Hologram;
import mineplex.core.recharge.Recharge;
import nautilus.game.arcade.game.GameTeam;
@ -20,7 +19,8 @@ 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.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -31,8 +31,7 @@ public class Flag
{
private CaptureTheFlag Host;
private Location _spawn;
private Block[] _flagBlocks;
private Location _spawn, _current;
private GameTeam _team;
@ -46,11 +45,16 @@ public class Flag
private Hologram _name, _time;
private String _displayName;
private LivingEntity _flagEntity;
public Flag (CaptureTheFlag host, Location spawn, GameTeam team)
{
Host = host;
_spawn = spawn;
_team = team;
_displayName = team.GetColor() + team.GetName() + "'s Flag".replace("s's", "s'");
ItemStack i;
if (team.GetColor() == ChatColor.RED)
@ -59,7 +63,7 @@ public class Flag
i = new ItemStack(Material.LAPIS_BLOCK);
ItemMeta im = i.getItemMeta();
im.setDisplayName(team.GetColor() + team.GetName() + "'s Flag".replace("s's", "s'"));
im.setDisplayName(_displayName);
i.setItemMeta(im);
_representation = i;
@ -87,40 +91,31 @@ public class Flag
public Location getPlacedLocation()
{
return _flagBlocks[0].getLocation();
return _current;
}
public ItemStack getRepresentation()
{
return _representation;
}
public String getDisplayName()
{
return _displayName;
}
private void AnnounceSteal(Player cap, boolean steal)
{
if (steal)
UtilTextMiddle.display("", Host.GetTeam(cap).GetColor() + cap.getName() + C.cWhite + " stole " + _team.GetColor() + _team.GetName() + " Flag!", 0, 60, 10);
else
UtilTextMiddle.display("", Host.GetTeam(cap).GetColor() + cap.getName() + C.cWhite + " picked up " + _team.GetColor() + _team.GetName() + " Flag!", 0, 60, 10);
/*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 stolen the enemy flag!"));
}*/
}
private void AnnounceDrop(Player player)
{
UtilTextMiddle.display("", Host.GetTeam(player).GetColor() + player.getName() + C.cWhite + " dropped " + _team.GetColor() + _team.GetName() + " Flag!", 0, 60, 10);
/*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!"));
}*/
}
private void AnnounceCapture(Player player)
@ -135,15 +130,10 @@ 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));
Integer r = (int)(System.currentTimeMillis() - _dropTime) / 1000;
Integer re = 15 - r;
_time.setText(RemainColor(re) + re.toString());
@ -154,21 +144,13 @@ public class Flag
_name.stop();
_time.stop();
for (Block block : _flagBlocks)
{
block.setType(Material.AIR);
}
DeleteFlag();
_moved = false;
_dropped = false;
SpawnFlag(_spawn, _team.GetColor() == ChatColor.RED);
AnnounceReturn();
/*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());
return;
@ -194,23 +176,11 @@ public class Flag
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);
}
}
@ -224,16 +194,14 @@ public class Flag
public void SpawnFlag(Location loc, boolean red)
{
_flagBlocks = new Block[]
{
loc.getBlock(),
loc.clone().add(0, 1, 0).getBlock()
};
_current = loc;
_flagEntity = (LivingEntity) Host.getArcadeManager().GetCreature().SpawnEntity(loc, EntityType.CHICKEN);
UtilEnt.Vegetate(_flagEntity);
DisguiseArmorStand disguise = new DisguiseArmorStand(_flagEntity);
disguise.setInvisible(true);
disguise.setHelmet(_representation);
Host.getArcadeManager().GetDisguise().disguise(disguise, UtilServer.getPlayers());
for (Block block : _flagBlocks)
{
block.setType(_representation.getType());
}
if (!_moved)
{
_name.setLocation(loc.getBlock().getLocation().clone().add(0.5, 3, 0.5));
@ -241,17 +209,25 @@ public class Flag
}
else
{
_name.setLocation(_flagBlocks[0].getLocation().clone().add(0.5, 3, 0.5));
_name.setLocation(loc.getBlock().getLocation().clone().add(0.5, 3, 0.5));
_name.start();
Integer r = (int)(System.currentTimeMillis() - _dropTime) / 1000;
Integer re = 15 - r;
_time.setText(RemainColor(re) + re.toString());
_time.setLocation(_flagBlocks[0].getLocation().clone().add(0.5, 2.5, 0.5));
_time.setLocation(loc.getBlock().getLocation().clone().add(0.5, 2.5, 0.5));
_time.start();
}
}
public boolean Pickup(Player player, Block block)
private void DeleteFlag()
{
Host.getArcadeManager().GetDisguise().undisguise(_flagEntity);
_flagEntity.remove();
_current = null;
_flagEntity = null;
}
public boolean Pickup(Player player)
{
if (_holding == null)
{
@ -264,62 +240,40 @@ public class Flag
{
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);
}
_name.stop();
_time.stop();
Host.SaveInventory(player);
for (int i = 0; i < 9; i++)
{
player.getInventory().setItem(i, _representation);
}
ItemStack compass = new ItemStack(Material.COMPASS);
ItemMeta im = compass.getItemMeta();
im.setDisplayName(C.cDAqua + "Your Base");
compass.setItemMeta(im);
player.getInventory().setItem(4, compass);
player.getInventory().setHelmet(_representation);
player.updateInventory();
player.getInventory().setHeldItemSlot(4);
for (PotionEffect effect : player.getActivePotionEffects())
player.removePotionEffect(effect.getType());
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 1000000, 0));
if (_moved)
AnnounceSteal(player, false);
else
AnnounceSteal(player, true);
_holding = player;
_dropped = false;
_dropTime = 0;
_moved = true;
return true;
}
}
DeleteFlag();
_name.stop();
_time.stop();
Host.SaveInventory(player);
for (int i = 0; i < 9; i++)
player.getInventory().setItem(i, _representation);
ItemStack compass = new ItemStack(Material.COMPASS);
ItemMeta im = compass.getItemMeta();
im.setDisplayName(C.cDAqua + "Your Base");
compass.setItemMeta(im);
player.getInventory().setItem(4, compass);
player.getInventory().setHelmet(_representation);
player.updateInventory();
player.getInventory().setHeldItemSlot(4);
for (PotionEffect effect : player.getActivePotionEffects())
player.removePotionEffect(effect.getType());
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 1000000, 0));
if (_moved)
AnnounceSteal(player, false);
else
AnnounceSteal(player, true);
_holding = player;
_dropped = false;
_dropTime = 0;
_moved = true;
return true;
}
}
}
@ -356,9 +310,6 @@ public class Flag
{
if (_holding.getUniqueId() == player.getUniqueId())
{
// 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;
@ -368,18 +319,12 @@ public class Flag
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.ResetInventory(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'")));
}*/
AnnounceCapture(player);
Host.AddGems(player, 10, "Enemy Flag Captured", true, true);
Host.AddCapture(Host.GetTeam(player));