本文整理汇总了Java中org.inventivetalent.packetlistener.handler.ReceivedPacket类的典型用法代码示例。如果您正苦于以下问题:Java ReceivedPacket类的具体用法?Java ReceivedPacket怎么用?Java ReceivedPacket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReceivedPacket类属于org.inventivetalent.packetlistener.handler包,在下文中一共展示了ReceivedPacket类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.inventivetalent.packetlistener.handler.ReceivedPacket; //导入依赖的package包/类
@Override
public void init(final Plugin plugin) {
PacketHandler.addHandler(new PacketHandler(plugin) {
@PacketOptions(forcePlayer = true)
@Override
public void onSend(final SentPacket sentPacket) {
if (sentPacket.hasPlayer()) {
if ("PacketPlayOutNamedEntitySpawn".equals(sentPacket.getPacketName())) {
final Player player = sentPacket.getPlayer();
final UUID uuid = Minecraft.VERSION.newerThan(Minecraft.Version.v1_8_R1) ?
((UUID) sentPacket.getPacketValue("b")) :
(((GameProfile) sentPacket.getPacketValue("b")).getId());
Player npcPlayer = null;
//TODO: check if this doesn't cause any ConcurrentModExceptions / make this synchronous somehow
for (Player worldPlayer : player.getWorld().getPlayers()) {// We can't use Bukkit#getOnlinePlayers, since the server doesn't know about the player NPCs
if (worldPlayer.getUniqueId().equals(uuid)) {
npcPlayer = worldPlayer;
break;
}
}
if (npcPlayer != null) {
NPCAbstract<?, ?> npcAbstract = NPCLib.getNPC(npcPlayer);
if (npcAbstract != null && npcAbstract instanceof NPCPlayer) {
((NPCPlayer) npcAbstract).updateToPlayer(player);
}
}
}
}
}
@PacketOptions(forcePlayer = true)
@Override
public void onReceive(ReceivedPacket receivedPacket) {
if (receivedPacket.hasPlayer()) {
if ("PacketPlayInUseEntity".equals(receivedPacket.getPacketName())) {
int a = (int) receivedPacket.getPacketValue(0);
Entity entity = Reflection.getEntityById(receivedPacket.getPlayer().getWorld(), a);
if (entity == null || !NPCLib.isNPC(entity)) {
return;
}
Enum<?> action = (Enum<?>) receivedPacket.getPacketValue(1);
NPCInteractEvent event = new NPCInteractEvent(NPCLib.getNPC(entity), a, action == null ? -1 : action.ordinal(), receivedPacket.getPlayer());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
receivedPacket.setCancelled(true);
}
}
}
}
});
String version = getVersion();
logger.info("Version is " + version);
}