當前位置: 首頁>>代碼示例>>Java>>正文


Java PacketEvent類代碼示例

本文整理匯總了Java中com.comphenix.protocol.events.PacketEvent的典型用法代碼示例。如果您正苦於以下問題:Java PacketEvent類的具體用法?Java PacketEvent怎麽用?Java PacketEvent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PacketEvent類屬於com.comphenix.protocol.events包,在下文中一共展示了PacketEvent類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: listenPackets

import com.comphenix.protocol.events.PacketEvent; //導入依賴的package包/類
public static void listenPackets() {
    ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(DynamicAC.instance, ListenerPriority.NORMAL, PacketType.Play.Client.POSITION, PacketType.Play.Client.POSITION_LOOK) {
        @Override
        public void onPacketReceiving(PacketEvent e) {
            Player p = e.getPlayer();
            Location cur = e.getPlayer().getLocation();
            if(!MOVE_COUNT.containsKey(p)) {
                MOVE_COUNT.put(p, 1);
            } else {
                MOVE_COUNT.put(p, MOVE_COUNT.get(p) + 1);
                if(MOVE_COUNT.get(p) > MagicNumbers.BLINK_PACKET)  {
                    for(Player player : DynamicAC.instance.onlinestaff) {
                        player.sendMessage(DynamicAC.prefix + p.getName() + " failed Blink test, sent too many " +
                                "packets in one place!");
                    }
                    MOVE_COUNT.remove(p);
                    e.setCancelled(true);
                    e.getPlayer().teleport(cur);
                }
            }
        }
    });
}
 
開發者ID:Notoh,項目名稱:DynamicAC,代碼行數:24,代碼來源:MovementListener.java

示例2: onSetCreativeSlotPacket

import com.comphenix.protocol.events.PacketEvent; //導入依賴的package包/類
private static void onSetCreativeSlotPacket(PacketEvent e) {
	if (!e.getPlayer().isOp()) {
		try {
			StructureModifier<ItemStack> structureModifier = e.getPacket().getItemModifier();
			if (structureModifier != null) {
				ItemStack item = structureModifier.read(0);
				if (item != null) {
					Object craftItem = method_asNMSCopy.invoke(null, item);
					if (craftItem != null) {
						Object hasTag = method_hasTag.invoke(craftItem);
						if (hasTag != null && (Boolean) hasTag) {
							e.setCancelled(true);
						}
					}
				}
			}
		} catch (Exception ex) {
			// ignore
		}
	}
}
 
開發者ID:jiongjionger,項目名稱:NeverLag,代碼行數:22,代碼來源:AntiAUWMod.java

示例3: 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

示例4: 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

示例5: 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

示例6: constructProtocol

import com.comphenix.protocol.events.PacketEvent; //導入依賴的package包/類
/**
 * Construct the packet listener that will be used to intercept every entity-related packet.
 *
 * @param plugin - the parent plugin.
 *
 * @return The packet listener.
 */
private PacketAdapter constructProtocol(Plugin plugin)
{
    return new PacketAdapter(plugin, ENTITY_PACKETS)
    {
        @Override
        public void onPacketSending(PacketEvent event)
        {
            int entityID = event.getPacket().getIntegers().read(0);

            // See if this packet should be cancelled
            if (!isVisible(event.getPlayer(), entityID))
            {
                event.setCancelled(true);
            }
        }
    };
}
 
開發者ID:WoutDev,項目名稱:Mega-Walls,代碼行數:25,代碼來源:EntityHider.java

示例7: onEnable

import com.comphenix.protocol.events.PacketEvent; //導入依賴的package包/類
/**
 * @see org.bukkit.plugin.java.JavaPlugin#onEnable()
 */
@Override
public void onEnable() {
    saveDefaultConfig();
    CONFIG = new Configuration(this);
    CONFIG.reload();

    _protocolManager = ProtocolLibrary.getProtocolManager();
    _protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.UPDATE_TIME) {
        @Override
        public void onPacketSending(PacketEvent event) {
            if (event.getPacketType() == PacketType.Play.Server.UPDATE_TIME &&
                _ignoringTime.contains(event.getPlayer()) &&
                event.getPacket().getLongs().read(1) >= 0) {
                event.setCancelled(true);
            }
        }
    });
}
 
開發者ID:NerdNu,項目名稱:NerdMoods,代碼行數:22,代碼來源:NerdMoods.java

示例8: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //導入依賴的package包/類
@Override
public void onPacketSending(PacketEvent event) {
    String verifyCode = verifyCodeSupplier.get();
    if (verifyCode != null) {
        try {
            WrappedServerPing ping = event.getPacket().getServerPings().read(0);

            Object motd = jsonParser.parse(ping.getMotD().getJson());
            if (motd instanceof JSONObject) {
                JSONObject component = (JSONObject) motd;
                component.put("text", verifyCode + ChatColor.RESET + component.get("text"));
                ping.setMotD(WrappedChatComponent.fromJson(component.toJSONString()));
            } else {
                // Legacy String format
                ping.setMotD(verifyCode + ChatColor.RESET + motd);
            }
        } catch (ParseException e) {
            ac.getLogger().log(Level.WARNING, "Failed to parse MOTD for verify request", e);
        }
    }
}
 
開發者ID:DeadmanDungeons,項目名稱:AudioConnect,代碼行數:22,代碼來源:VerifyRequestPacketListener.java

示例9: register

import com.comphenix.protocol.events.PacketEvent; //導入依賴的package包/類
public void register() {
    ProtocolLibrary.getProtocolManager().addPacketListener(
            new PacketAdapter(this, WrapperPlayClientUseEntity.TYPE) {
                @Override
                public void onPacketReceiving(PacketEvent event) {
                    if (event.getPacketType() == WrapperPlayClientUseEntity.TYPE) {
                        WrapperPlayClientUseEntity packet = new WrapperPlayClientUseEntity(event.getPacket());
                        int entID = packet.getTarget();
                        if (running.containsKey(event.getPlayer().getUniqueId()) && packet.getType() == EntityUseAction.ATTACK) {
                            running.get(event.getPlayer().getUniqueId()).markAsKilled(entID);
                        }
                    }
                }

            });
    this.isRegistered = true;
}
 
開發者ID:TechzoneMC,項目名稱:SimpleAntiAura,代碼行數:18,代碼來源:AntiAura.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();
	
	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

示例11: 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

示例12: 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

示例13: 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

示例14: 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 );
        }
    }

}
 
開發者ID:GuruFraser,項目名稱:NoGlint,代碼行數:18,代碼來源:EquipmentListener.java

示例15: 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 );
            }
        }
    }
}
 
開發者ID:GuruFraser,項目名稱:NoGlint,代碼行數:22,代碼來源:ItemListener.java


注:本文中的com.comphenix.protocol.events.PacketEvent類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。