Merge branch 'alex-ctf' of ssh://184.154.0.242:7999/min/Mineplex into alex-ctf
This commit is contained in:
commit
52a5c63166
@ -4,7 +4,10 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashSet;
|
||||
|
||||
import net.minecraft.server.v1_7_R4.Block;
|
||||
import net.minecraft.server.v1_7_R4.BlockSandStone;
|
||||
import net.minecraft.server.v1_7_R4.EnumProtocol;
|
||||
import net.minecraft.server.v1_7_R4.Item;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -22,6 +25,7 @@ public class PacketHandler extends MiniPlugin
|
||||
{
|
||||
private NautHashMap<Player, PacketVerifier> _playerVerifierMap = new NautHashMap<Player, PacketVerifier>();
|
||||
private HashSet<IPacketHandler> _packetHandlers = new HashSet<IPacketHandler>();
|
||||
public static Item BANNER = new Item().c("banner");
|
||||
|
||||
public PacketHandler(JavaPlugin plugin)
|
||||
{
|
||||
@ -47,15 +51,16 @@ public class PacketHandler extends MiniPlugin
|
||||
|
||||
EnumProtocol.PLAY.a().put(2, PacketPlayUseEntity.class);
|
||||
EnumProtocol.PLAY.a().put(PacketPlayUseEntity.class, 2);
|
||||
|
||||
Method method = ProtocolInjector.class.getDeclaredMethod("addPacket", EnumProtocol.class,boolean.class, int.class, Class.class);
|
||||
|
||||
Method method = ProtocolInjector.class.getDeclaredMethod("addPacket", EnumProtocol.class, boolean.class, int.class,
|
||||
Class.class);
|
||||
method.setAccessible(true);
|
||||
|
||||
method.invoke(null, EnumProtocol.PLAY, true, 67, PacketPlayOutCamera.class);
|
||||
method.invoke(null, EnumProtocol.PLAY, true, 68, PacketPlayOutWorldBorder.class);
|
||||
|
||||
// EnumProtocol.PLAY.b().put(68, PacketPlayOutWorldBorder.class);
|
||||
// EnumProtocol.PLAY.b().put(PacketPlayOutWorldBorder.class, 68);
|
||||
|
||||
Item.REGISTRY.a(425, "banner", BANNER);
|
||||
Block.REGISTRY.a(425, "banner", new BlockSandStone());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
package nautilus.game.arcade.game.games.common;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -18,6 +19,9 @@ import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.elo.EloPlayer;
|
||||
import mineplex.core.elo.EloTeam;
|
||||
import mineplex.core.elo.GameResult;
|
||||
import mineplex.core.packethandler.IPacketHandler;
|
||||
import mineplex.core.packethandler.PacketHandler;
|
||||
import mineplex.core.packethandler.PacketInfo;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.minecraft.game.core.combat.CombatComponent;
|
||||
@ -35,10 +39,15 @@ 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 net.minecraft.server.v1_7_R4.NBTTagCompound;
|
||||
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.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -75,6 +84,8 @@ public class CaptureTheFlag extends TeamGame
|
||||
|
||||
private ConcurrentHashMap<Player, List<ItemStack>> _hotbars = new ConcurrentHashMap<Player, List<ItemStack>>();
|
||||
private ConcurrentHashMap<Player, ItemStack> _helmets = new ConcurrentHashMap<Player, ItemStack>();
|
||||
private IPacketHandler _flagItemListener;
|
||||
private Field _itemField;
|
||||
|
||||
public CaptureTheFlag(ArcadeManager manager, GameType type, Kit[] kits)
|
||||
{
|
||||
@ -95,8 +106,149 @@ public class CaptureTheFlag extends TeamGame
|
||||
this.WorldTimeSet = 2000;
|
||||
|
||||
this.DeathSpectateSecs = 10;
|
||||
|
||||
try
|
||||
{
|
||||
_itemField = PacketPlayOutSetSlot.class.getDeclaredField("c");
|
||||
_itemField.setAccessible(true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
_flagItemListener = new IPacketHandler()
|
||||
{
|
||||
@Override
|
||||
public void handle(PacketInfo packetInfo)
|
||||
{
|
||||
if (packetInfo.getPacket() instanceof PacketPlayOutEntityEquipment)
|
||||
{
|
||||
PacketPlayOutEntityEquipment eqiup = (PacketPlayOutEntityEquipment) packetInfo
|
||||
.getPacket();
|
||||
|
||||
ItemStack item = CraftItemStack.asBukkitCopy(eqiup.c);
|
||||
|
||||
if (item != null && item.getType() != Material.AIR)
|
||||
{
|
||||
for (Flag flag : _flags)
|
||||
{
|
||||
if (flag.getRepresentation().isSimilar(item))
|
||||
{
|
||||
eqiup.c = getFlag(flag.getTeam().GetColorData());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (packetInfo.getPacket() instanceof PacketPlayOutWindowItems
|
||||
|| packetInfo.getPacket() instanceof PacketPlayOutSetSlot)
|
||||
{
|
||||
Player player = packetInfo.getPlayer();
|
||||
|
||||
if (_hotbars.containsKey(player))
|
||||
{
|
||||
ItemStack flagMaterial = null;
|
||||
net.minecraft.server.v1_7_R4.ItemStack flagItem = null;
|
||||
|
||||
for (Flag flag : _flags)
|
||||
{
|
||||
if (flag.getCarrier() == player)
|
||||
{
|
||||
flagMaterial = flag.getRepresentation();
|
||||
flagItem = getFlag(flag.getTeam()
|
||||
.GetColorData());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (flagItem == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (packetInfo.getPacket() instanceof PacketPlayOutWindowItems)
|
||||
{
|
||||
PacketPlayOutWindowItems packet = (PacketPlayOutWindowItems) packetInfo
|
||||
.getPacket();
|
||||
|
||||
for (int i = 0; i < packet.b.length; i++)
|
||||
{
|
||||
ItemStack item = CraftItemStack
|
||||
.asBukkitCopy(packet.b[i]);
|
||||
|
||||
if (item != null
|
||||
&& item.isSimilar(flagMaterial))
|
||||
{
|
||||
packet.b[i] = flagItem;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
PacketPlayOutSetSlot packet = (PacketPlayOutSetSlot) packetInfo
|
||||
.getPacket();
|
||||
|
||||
ItemStack item = null;
|
||||
|
||||
try
|
||||
{
|
||||
item = CraftItemStack
|
||||
.asBukkitCopy((net.minecraft.server.v1_7_R4.ItemStack) _itemField
|
||||
.get(packet));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
if (item != null && item.isSimilar(flagMaterial))
|
||||
{
|
||||
packetInfo.setCancelled(true);
|
||||
|
||||
packet = new PacketPlayOutSetSlot(packet.a,
|
||||
packet.b, flagItem);
|
||||
|
||||
packetInfo.getVerifier().bypassProcess(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private net.minecraft.server.v1_7_R4.ItemStack getFlag(byte b)
|
||||
{
|
||||
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();
|
||||
|
||||
nbt.setInt("Base", b);
|
||||
|
||||
nbtBase.set("BlockEntityTag", nbt);
|
||||
item.setTag(nbtBase);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void handleFlagItem(GameStateChangeEvent event)
|
||||
{
|
||||
if (event.GetState() == GameState.Live)
|
||||
{
|
||||
getArcadeManager().getPacketHandler().addPacketHandler(
|
||||
_flagItemListener);
|
||||
}
|
||||
else if (event.GetState() == GameState.Dead)
|
||||
{
|
||||
getArcadeManager().getPacketHandler().removePacketHandler(
|
||||
_flagItemListener);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void ParseData()
|
||||
{
|
||||
@ -569,7 +721,7 @@ public class CaptureTheFlag extends TeamGame
|
||||
public void DropFlag(PlayerDropItemEvent event)
|
||||
{
|
||||
for (Flag flag : _flags)
|
||||
if (flag.getRepresentation() == event.getItemDrop().getItemStack().getType())
|
||||
if (flag.getRepresentation().getType() == event.getItemDrop().getItemStack().getType())
|
||||
if (flag.getCarrier() != null)
|
||||
if (flag.getCarrier().getName().equals(event.getPlayer().getName()))
|
||||
{
|
||||
|
@ -90,9 +90,9 @@ public class Flag
|
||||
return _flagBlocks[0].getLocation();
|
||||
}
|
||||
|
||||
public Material getRepresentation()
|
||||
public ItemStack getRepresentation()
|
||||
{
|
||||
return _representation.getType();
|
||||
return _representation;
|
||||
}
|
||||
|
||||
private void AnnounceSteal(Player cap, boolean steal)
|
||||
|
Loading…
Reference in New Issue
Block a user