Fix for arcade custom tags
This commit is contained in:
parent
01f311a3d6
commit
5cf3e6c3a1
@ -6,6 +6,7 @@ import java.util.List;
|
||||
|
||||
import mineplex.core.common.DummyEntity;
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.event.CustomTagEvent;
|
||||
import mineplex.core.packethandler.IPacketHandler;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.packethandler.PacketHandler;
|
||||
@ -334,8 +335,12 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler
|
||||
}
|
||||
}
|
||||
|
||||
private void sendProtocolPackets(final Player owner, final int entityId, final int newEntityId, final String entityName, final PacketVerifier packetList)
|
||||
private void sendProtocolPackets(final Player owner, final int entityId, final int newEntityId, String entityName, final PacketVerifier packetList)
|
||||
{
|
||||
CustomTagEvent event = new CustomTagEvent(owner, entityId, entityName);
|
||||
_plugin.getServer().getPluginManager().callEvent(event);
|
||||
final String finalEntityName = event.getCustomName();
|
||||
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(GetPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
@ -412,7 +417,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler
|
||||
|
||||
watcher.watch(10, Byte.valueOf(b1));
|
||||
|
||||
watcher.watch(2, entityName);
|
||||
watcher.watch(2, finalEntityName);
|
||||
watcher.watch(3, Byte.valueOf((byte)1));
|
||||
|
||||
packet.l = watcher;
|
||||
|
@ -0,0 +1,55 @@
|
||||
package mineplex.core.event;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Created by Shaun on 10/24/2014.
|
||||
*/
|
||||
public class CustomTagEvent extends Event
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private Player _player;
|
||||
private int _entityId;
|
||||
private String _customName;
|
||||
|
||||
public CustomTagEvent(Player player, int entityId, String customName)
|
||||
{
|
||||
_player = player;
|
||||
_entityId = entityId;
|
||||
_customName = customName;
|
||||
}
|
||||
|
||||
public Player getPlayer()
|
||||
{
|
||||
return _player;
|
||||
}
|
||||
|
||||
public String getCustomName()
|
||||
{
|
||||
return _customName;
|
||||
}
|
||||
|
||||
public void setCustomName(String customName)
|
||||
{
|
||||
_customName = customName;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public int getEntityId()
|
||||
{
|
||||
return _entityId;
|
||||
}
|
||||
}
|
@ -45,6 +45,7 @@ import mineplex.core.common.util.MapUtil;
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.common.util.UtilInv;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.common.util.UtilText;
|
||||
import mineplex.core.common.util.UtilText.TextAlign;
|
||||
@ -52,6 +53,7 @@ import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.common.util.UtilWorld;
|
||||
import mineplex.core.cosmetic.event.ActivateGemBoosterEvent;
|
||||
import mineplex.core.donation.Donor;
|
||||
import mineplex.core.event.CustomTagEvent;
|
||||
import mineplex.core.packethandler.IPacketHandler;
|
||||
import mineplex.core.packethandler.PacketHandler;
|
||||
import mineplex.core.packethandler.PacketVerifier;
|
||||
@ -69,7 +71,9 @@ import nautilus.game.arcade.kit.Kit;
|
||||
import nautilus.game.arcade.kit.KitAvailability;
|
||||
import nautilus.game.arcade.kit.KitSorter;
|
||||
import net.minecraft.server.v1_7_R4.Packet;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityMetadata;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving;
|
||||
import net.minecraft.server.v1_7_R4.WatchableObject;
|
||||
|
||||
public class GameLobbyManager implements Listener, IPacketHandler
|
||||
{
|
||||
@ -1087,21 +1091,47 @@ public class GameLobbyManager implements Listener, IPacketHandler
|
||||
return entityName;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void customEntityName(CustomTagEvent event)
|
||||
{
|
||||
// TODO: This needs to be changed when removing CustomTagFix
|
||||
|
||||
if (Manager.GetGame() != null)
|
||||
{
|
||||
String customName = null;
|
||||
|
||||
for (LobbyEnt ent : _kits.values())
|
||||
{
|
||||
if (ent.GetEnt().getEntityId() == event.getEntityId())
|
||||
{
|
||||
customName = GetKitCustomName(event.getPlayer(), Manager.GetGame(), ent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (customName != null)
|
||||
{
|
||||
event.setCustomName(customName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void handle(PacketInfo packetInfo)
|
||||
{
|
||||
if (_handlingPacket)
|
||||
// This only applies to 1.7 clients currently, 1.8 custom names are handled by customEntityName(CustomTagEvent event)
|
||||
if (_handlingPacket || UtilPlayer.is1_8(packetInfo.getPlayer()))
|
||||
return;
|
||||
|
||||
Packet packet = packetInfo.getPacket();
|
||||
Player owner = packetInfo.getPlayer();
|
||||
PacketVerifier packetVerifier = packetInfo.getVerifier();
|
||||
|
||||
|
||||
int entityId = -1;
|
||||
|
||||
if (packet instanceof PacketPlayOutSpawnEntityLiving)
|
||||
if (packet instanceof PacketPlayOutEntityMetadata)
|
||||
{
|
||||
entityId = ((PacketPlayOutSpawnEntityLiving)packet).a;
|
||||
entityId = ((PacketPlayOutEntityMetadata)packet).a;
|
||||
}
|
||||
|
||||
if (entityId != -1)
|
||||
@ -1122,16 +1152,37 @@ public class GameLobbyManager implements Listener, IPacketHandler
|
||||
{
|
||||
try
|
||||
{
|
||||
if (packet instanceof PacketPlayOutSpawnEntityLiving)
|
||||
if (packet instanceof PacketPlayOutEntityMetadata)
|
||||
{
|
||||
((PacketPlayOutSpawnEntityLiving)packet).l.watch(2, customName);
|
||||
((PacketPlayOutSpawnEntityLiving)packet).l.watch(10, customName);
|
||||
List<WatchableObject> watchables = new ArrayList<WatchableObject>();
|
||||
|
||||
for (WatchableObject watchableObject : (List<WatchableObject>)((PacketPlayOutEntityMetadata) packet).b)
|
||||
{
|
||||
WatchableObject newWatch = new WatchableObject(watchableObject.c(), watchableObject.a(), watchableObject.b());
|
||||
|
||||
if (newWatch.a() == 10)
|
||||
{
|
||||
newWatch.a(customName);
|
||||
}
|
||||
|
||||
watchables.add(newWatch);
|
||||
}
|
||||
|
||||
PacketPlayOutEntityMetadata newPacket = new PacketPlayOutEntityMetadata();
|
||||
newPacket.a = entityId;
|
||||
newPacket.b = watchables;
|
||||
|
||||
_handlingPacket = true;
|
||||
packetVerifier.process(newPacket);
|
||||
_handlingPacket = false;
|
||||
|
||||
packetInfo.setCancelled(true);
|
||||
}
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user