当前位置: 首页>>代码示例>>Java>>正文


Java ReceivedPacket类代码示例

本文整理汇总了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);
}
 
开发者ID:InventivetalentDev,项目名称:CompactNPCLib,代码行数:56,代码来源:NPCLib.java


注:本文中的org.inventivetalent.packetlistener.handler.ReceivedPacket类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。