本文整理汇总了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);
}
}
}
});
}
示例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
}
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
};
}
示例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);
}
}
});
}
示例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);
}
}
}
示例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;
}
示例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 ) ) );
}
}
示例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() );
}
}
}
}
}
示例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 );
}
}
示例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);
}
}
}
示例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 );
}
}
}
示例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 );
}
}
}
}