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


Java PacketEvent.getPlayer方法代码示例

本文整理汇总了Java中com.comphenix.protocol.events.PacketEvent.getPlayer方法的典型用法代码示例。如果您正苦于以下问题:Java PacketEvent.getPlayer方法的具体用法?Java PacketEvent.getPlayer怎么用?Java PacketEvent.getPlayer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.comphenix.protocol.events.PacketEvent的用法示例。


在下文中一共展示了PacketEvent.getPlayer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //导入方法依赖的package包/类
@Override
public void onPacketSending(PacketEvent event) {
    WrapperPlayServerResourcePackSend packet = new WrapperPlayServerResourcePackSend(event.getPacket());
    if (!packet.getUrl().equals(Config.getConfig().getString("resource-pack.url"))) {
        return;
    }

    final Player player = event.getPlayer();
    packet.setHash(Config.getConfig().getString("resource-pack.hash"));
    final LoadData loadData = new LoadData();
    loadList.put(player.getUniqueId(), loadData);

    new BukkitRunnable() {
        @Override
        public void run() {
            loadData.setPrepared();
        }
    }.runTaskLater(RPGInventory.getInstance(), Config.getConfig().getInt("resource-pack.delay") * 20);
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:20,代码来源:PlayerLoader.java

示例2: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //导入方法依赖的package包/类
@Override
public void onPacketSending(PacketEvent event) {
    Player player = event.getPlayer();
    //noinspection ConstantConditions
    if (event.isCancelled() || !InventoryManager.playerIsLoaded(player)
            || isNotNeededHere(player)) {
        return;
    }

    WrapperPlayServerWindowItems packet = new WrapperPlayServerWindowItems(event.getPacket());
    if (player.getOpenInventory().getType() == InventoryType.WORKBENCH) {
        List<ItemStack> contents = packet.getSlotData();

        List<CraftExtension> extensions = CraftManager.getExtensions(player);
        for (CraftExtension extension : extensions) {
            for (int slot : extension.getSlots()) {
                contents.set(slot, extension.getCapItem());
            }
        }

        packet.setSlotData(contents);
    }
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:24,代码来源:CraftListener.java

示例3: onPacketReceiving

import com.comphenix.protocol.events.PacketEvent; //导入方法依赖的package包/类
@Override
public void onPacketReceiving(PacketEvent packetEvent) {
    Player p = packetEvent.getPlayer();
    PacketContainer packet = packetEvent.getPacket();
    if (packet.getType().equals(PacketType.Play.Client.USE_ENTITY)) {
        UUID u = tagMap.get(packet.getIntegers().read(0));
        if (u == null) return;
        Entity e = p.getNearbyEntities(8, 8, 8).stream().filter(entity -> entity.getUniqueId().equals(u)).findAny
                ().orElse(null);
        if (e == null) return;
        if (!HitboxUtil.isLookingAt(p, e)) return;
        packet.getIntegers().write(0, e.getEntityId());
        if (e.getType() == EntityType.ARMOR_STAND)
            packet.getEntityUseActions().write(0, EnumWrappers.EntityUseAction.ATTACK);
    }
}
 
开发者ID:iso2013,项目名称:MultiLineAPI,代码行数:17,代码来源:PacketListener.java

示例4: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //导入方法依赖的package包/类
@Override
public void onPacketSending( PacketEvent event ) {
	final Player                  player = event.getPlayer();
	final PacketContainer packet = event.getPacket();
	
	String message     = this.restoreTextFromChatComponent( packet.getChatComponents().read( 0 ) );
	String translation = this.translateMessageIfAppropriate( this.i18n.getLocale( player.getUniqueId() ), message );
	
	if ( message != translation ) {
		// Yes, the test of instance equality is what I want to do here
		// as it saves me time determining whether the message was actually
		// translated or not:
		
		// Issue #4:
		//  https://github.com/BlackyPaw/I18N/issues/4
		//
		// Do this ugly conversion thing here in order to enforce usage of JSON color tags
		// over the legacy chat format. Invoking WrappedChatComponent.fromText( ... ) for
		// example, would result in a JSON such as {"text":"§cExample"} which can, if long enough
		// and automatically put onto a new line by Minecraft, lose its formatting on the addtional
		// line of chat. This issue does only arise for chat currently as it is the only place where
		// multiple lines are even supported. In case this issue should arise again somewhere else
		// one will simply have to do this conversion there, too:
		packet.getChatComponents().write( 0, ComponentConverter.fromBaseComponent( TextComponent.fromLegacyText( translation ) ) );
	}
}
 
开发者ID:BlackyPaw,项目名称:I18N,代码行数:27,代码来源:InterceptorChat.java

示例5: onMapChunk

import com.comphenix.protocol.events.PacketEvent; //导入方法依赖的package包/类
private void onMapChunk( PacketEvent event ) {
	final Player          player = event.getPlayer();
	final PacketContainer packet = event.getPacket();
	final Locale          locale = this.i18n.getLocale( player.getUniqueId() );
	
	List handleList = packet.getSpecificModifier( List.class ).read( 0 );
	for ( Object compoundHandle : handleList ) {
		NbtCompound compound = NbtFactory.fromNMSCompound( compoundHandle );
		String id = compound.getString( "id" );
		if ( id.equals( "minecraft:sign" ) || id.equals( "Sign" ) ) {
			for ( int i = 1; i <= 4; ++i ) {
				final String key = "Text" + i;
				String message    = this.gson.fromJson( compound.getString( key ), ChatComponent.class ).getUnformattedText();
				String translated = this.translateMessageIfAppropriate( locale, message );
				
				if ( message != translated ) {
					compound.put( key, WrappedChatComponent.fromText( translated ).getJson() );
				}
			}
		}
	}
}
 
开发者ID:BlackyPaw,项目名称:I18N,代码行数:23,代码来源:InterceptorSign.java

示例6: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //导入方法依赖的package包/类
@Override
public void onPacketSending( PacketEvent event ) {
	final Player          player = event.getPlayer();
	final PacketContainer packet = event.getPacket();
	
	// Translate all four lines if necessary:
	boolean                changed        = false;
	WrappedChatComponent[] chatComponents = packet.getChatComponentArrays().read( 0 );
	for ( int i = 0; i < chatComponents.length; ++i ) {
		WrappedChatComponent chat = chatComponents[i];
		if ( chat != null ) {
			String message    = this.restoreTextFromChatComponent( chat );
			String translated = this.translateMessageIfAppropriate( this.i18n.getLocale( player.getUniqueId() ), message );
			
			if ( message != translated ) {
				chatComponents[i] = WrappedChatComponent.fromText( translated );
				changed = true;
			}
		}
	}
	
	if ( changed ) {
		// Only write back when really needed:
		packet.getChatComponentArrays().write( 0, chatComponents );
	}
}
 
开发者ID:BlackyPaw,项目名称:I18N,代码行数:27,代码来源:InterceptorSign.java

示例7: onPacketReceiving

import com.comphenix.protocol.events.PacketEvent; //导入方法依赖的package包/类
@Override
public void onPacketReceiving(PacketEvent event) {
    Player player = event.getPlayer();
    int id = event.getPacketID();
    holder.holdIfPresent(event);
    if (id == Packets.Client.HANDSHAKE) {
        cacher.caching(player);
    }
    if (id == Packets.Client.TRANSACTION) {
        PacketContainer packet = event.getPacket();
        int pId = packet.getShorts().read(0);
        if (pId == Short.MIN_VALUE) {
            latch.countDown(player);
        }
    }
}
 
开发者ID:EntryPointKR,项目名称:K-Security,代码行数:17,代码来源:TransactionAntiBot.java

示例8: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //导入方法依赖的package包/类
@Override
public void onPacketSending(PacketEvent packetEvent) {
    Player player = packetEvent.getPlayer();
    if (packetEvent.isCancelled() || player instanceof Factory) {
        return;
    }

    PacketContainer packet = packetEvent.getPacket();
    if (packet.hasMetadata("ScoreboardStats")) {
        //it's our own packet
        return;
    }

    UUID playerUUID = player.getUniqueId();

    //handle async packets by other plugins
    if (Bukkit.isPrimaryThread()) {
        ensureMainThread(playerUUID, packet);
    } else {
        PacketContainer clone = packet.deepClone();
        Bukkit.getScheduler().runTask(plugin, () -> ensureMainThread(playerUUID, clone));
    }
}
 
开发者ID:games647,项目名称:ScoreboardStats,代码行数:24,代码来源:PacketListener.java

示例9: onSetSlot

import com.comphenix.protocol.events.PacketEvent; //导入方法依赖的package包/类
private void onSetSlot( PacketEvent event ) {
	final Player                  player   = event.getPlayer();
	final PacketContainer packet   = event.getPacket();
	final Locale          language = this.i18n.getLocale( player.getUniqueId() );
	
	ItemStack stack = packet.getItemModifier().read( 0 );
	if ( stack != null ) {
		ItemMeta meta = stack.getItemMeta();
		if ( meta == null ) {
			return;
		}
		String message = meta.getDisplayName();
		if ( message == null ) {
			return;
		}
		
		//self.getLogger().info( "#SetSlot: Message of Item = " + message );
		String translated = this.translateMessageIfAppropriate( language, message );
		
		if ( message != translated ) {
			// Only write back when really needed:
			
			// Got to clone here as otherwise we might be modifying an instance that
			// is actually also used by the inventory:
			stack = stack.clone();
			meta = stack.getItemMeta();
			meta.setDisplayName( translated );
			stack.setItemMeta( meta );
			packet.getItemModifier().write( 0, stack );
		}
	}
}
 
开发者ID:BlackyPaw,项目名称:I18N,代码行数:33,代码来源:InterceptorSlot.java

示例10: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //导入方法依赖的package包/类
@Override
public void onPacketSending( PacketEvent event ) {
	final Player          player = event.getPlayer();
	final PacketContainer packet = event.getPacket();
	
	EnumWrappers.TitleAction action = packet.getTitleActions().read( 0 );
	if ( action == EnumWrappers.TitleAction.TITLE || action == EnumWrappers.TitleAction.SUBTITLE ) {
		String message     = this.restoreTextFromChatComponent( packet.getChatComponents().read( 0 ) );
		String translation = this.translateMessageIfAppropriate( this.i18n.getLocale( player.getUniqueId() ), message );
		
		if ( message != translation ) {
			packet.getChatComponents().write( 0, WrappedChatComponent.fromText( translation ) );
		}
	}
}
 
开发者ID:BlackyPaw,项目名称:I18N,代码行数:16,代码来源:InterceptorTitle.java

示例11: onSetSlot

import com.comphenix.protocol.events.PacketEvent; //导入方法依赖的package包/类
private void onSetSlot( PacketEvent event ) {
	final Player          player   = event.getPlayer();
	final PacketContainer packet   = event.getPacket();
	final Locale          language = this.i18n.getLocale( player.getUniqueId() );
	
	ItemStack stack = packet.getItemModifier().read( 0 );
	if ( stack != null ) {
		ItemMeta meta = stack.getItemMeta();
		if ( meta == null ) {
			return;
		}
		String message = meta.getDisplayName();
		if ( message == null ) {
			return;
		}
		
		//self.getLogger().info( "#SetSlot: Message of Item = " + message );
		String translated = this.translateMessageIfAppropriate( language, message );
		
		if ( message != translated ) {
			// Only write back when really needed:
			
			// Got to clone here as otherwise we might be modifying an instance that
			// is actually also used by the inventory:
			stack = stack.clone();
			meta = stack.getItemMeta();
			meta.setDisplayName( translated );
			stack.setItemMeta( meta );
			packet.getItemModifier().write( 0, stack );
		}
	}
}
 
开发者ID:BlackyPaw,项目名称:I18N,代码行数:33,代码来源:InterceptorSlot.java

示例12: onScoreboardScore

import com.comphenix.protocol.events.PacketEvent; //导入方法依赖的package包/类
private void onScoreboardScore( PacketEvent event ) {
	final Player          player = event.getPlayer();
	final PacketContainer packet = event.getPacket();
	
	String message     = packet.getStrings().read( 0 );
	String translation = this.translateMessageIfAppropriate( this.i18n.getLocale( player.getUniqueId() ), message );
	
	if ( message != translation ) {
		packet.getStrings().write( 0, translation );
	}
}
 
开发者ID:BlackyPaw,项目名称:I18N,代码行数:12,代码来源:InterceptorScoreboard.java

示例13: listenForPackets

import com.comphenix.protocol.events.PacketEvent; //导入方法依赖的package包/类
private void listenForPackets()
{
	this.packetAdapter = new PacketAdapter(AnimulusLib.getInstance().getPlugin(), ListenerPriority.NORMAL,
			PacketType.Play.Client.USE_ENTITY)
	{
		@Override public void onPacketReceiving(PacketEvent packetEvent)
		{
			// taken from PacketWrapper
			EntityUseAction action = packetEvent.getPacket().getEntityUseActions().read(0);
			if(action == EntityUseAction.INTERACT_AT)
				return;

			Player player = packetEvent.getPlayer();
			int entityId = packetEvent.getPacket().getIntegers().read(0);
			StateNPC npc = AnimulusLib.getNPCManager().getNPC(entityId);

			// clicked actual player
			if(npc == null)
				return;

			if(action == EntityUseAction.INTERACT)
				npc.playerRightClick(player);
			else
				npc.playerLeftClick(player);
		}
	};

	ProtocolLibrary.getProtocolManager().addPacketListener(this.packetAdapter);
}
 
开发者ID:domisum,项目名称:AnimulusLib,代码行数:30,代码来源:NPCInteractPacketListener.java

示例14: onPacketReceiving

import com.comphenix.protocol.events.PacketEvent; //导入方法依赖的package包/类
@Override
public void onPacketReceiving( PacketEvent event ) {
	final Player         player   = event.getPlayer();
	final Locale language = new Locale( event.getPacket().getStrings().read( 0 ).substring( 0, 2 ) );
	
	PlayerLanguageSettingEvent call = new PlayerLanguageSettingEvent( player, language );
	Bukkit.getServer().getPluginManager().callEvent( call );
}
 
开发者ID:BlackyPaw,项目名称:I18N,代码行数:9,代码来源:InterceptorSettings.java

示例15: onScoreboardObjective

import com.comphenix.protocol.events.PacketEvent; //导入方法依赖的package包/类
private void onScoreboardObjective( PacketEvent event ) {
	final Player                  player = event.getPlayer();
	final PacketContainer packet = event.getPacket();
	
	int mode = packet.getIntegers().read( 0 );
	if ( mode == 0 || mode == 2 ) {
		String message     = packet.getStrings().read( 1 );
		String translation = this.translateMessageIfAppropriate( this.i18n.getLocale( player.getUniqueId() ), message );
		
		if ( message != translation ) {
			packet.getStrings().write( 1, translation );
		}
	}
}
 
开发者ID:BlackyPaw,项目名称:I18N,代码行数:15,代码来源:InterceptorScoreboard.java


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