本文整理匯總了Java中com.comphenix.protocol.events.PacketEvent.getPacket方法的典型用法代碼示例。如果您正苦於以下問題:Java PacketEvent.getPacket方法的具體用法?Java PacketEvent.getPacket怎麽用?Java PacketEvent.getPacket使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.comphenix.protocol.events.PacketEvent
的用法示例。
在下文中一共展示了PacketEvent.getPacket方法的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);
}
示例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);
}
}
示例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);
}
}
示例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 ) ) );
}
}
示例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() );
}
}
}
}
}
示例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 );
}
}
示例7: onPacketSending
import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketSending( PacketEvent event ) {
PacketContainer packet = event.getPacket();
int entityID = packet.getIntegers().read( 0 );
ItemStack item = packet.getItemModifier().read( 0 );
//Run this check first to save on performance.
if( plugin.getGlintManager().isGlintDisabled( event.getPlayer().getUniqueId() ) ) {
Player player = GlintUtils.getPlayerByEntityID( entityID );
if ( player != null && item != null && !item.getType().equals( Material.AIR )) {
GlintUtils.removeGlint( item );
}
}
}
示例8: onPacketSending
import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketSending( PacketEvent event ) {
PacketContainer packet = event.getPacket();
int entityID = packet.getIntegers().read( 0 );
int type = packet.getIntegers().read( 9 );
/*
ItemStacks are ID'd as 2.
*/
if( type == 2 ) {
Entity entity = packet.getEntityModifier( event ).read( 0 );
//Lets just make sure
if( entity instanceof Item ) {
ItemStack item = ( (Item) entity ).getItemStack();
if( plugin.getGlintManager().isGlintDisabled( event.getPlayer().getUniqueId() ) ) {
GlintUtils.removeGlint( item );
}
}
}
}
示例9: 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));
}
}
示例10: 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 );
}
}
}
示例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 );
}
}
}
示例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 );
}
}
示例13: 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 ) );
}
}
}
示例14: ignore
import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
public void ignore(PacketEvent event) {
PacketContainer packet = event.getPacket();
Player player = event.getPlayer();
if (packet.getID() == def(ignorePacketMap.remove(player.getName()), -1)) {
event.setCancelled(true);
}
}
示例15: 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 );
}
}
}