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


Java PacketAdapter類代碼示例

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


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

示例1: listenPackets

import com.comphenix.protocol.events.PacketAdapter; //導入依賴的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: constructProtocol

import com.comphenix.protocol.events.PacketAdapter; //導入依賴的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

示例3: onEnable

import com.comphenix.protocol.events.PacketAdapter; //導入依賴的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

示例4: register

import com.comphenix.protocol.events.PacketAdapter; //導入依賴的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

示例5: init

import com.comphenix.protocol.events.PacketAdapter; //導入依賴的package包/類
@Override
public void init(Plugin plugin) {
	ProtocolLibrary.getProtocolManager().addPacketListener(
			new PacketAdapter(PacketAdapter
					.params(plugin, PacketType.Play.Server.SET_SLOT,
							PacketType.Play.Server.WINDOW_ITEMS)
							.serverSide().listenerPriority(ListenerPriority.HIGH)) {

				@Override
				public void onPacketSending(PacketEvent event) {
					if (event.getPacketType().equals(PacketType.Play.Server.SET_SLOT)) {
						addGlow(new ItemStack[] { event.getPacket().getItemModifier().read(0) });
					} else {
						addGlow(event.getPacket().getItemArrayModifier().read(0));
					}
				}
			});
	
	_signManager = new ProtocolLibSignGUI(plugin);
	
	Bukkit.getServicesManager().register(SignGUI.class, _signManager, plugin, ServicePriority.Highest);
}
 
開發者ID:glen3b,項目名稱:BukkitLib,代碼行數:23,代碼來源:ProtocolLibUtilImplementation.java

示例6: enable

import com.comphenix.protocol.events.PacketAdapter; //導入依賴的package包/類
public void enable() {
	ProtocolLibrary.getProtocolManager().addPacketListener(
			new PacketAdapter(plugin, ConnectionSide.SERVER_SIDE, ListenerPriority.NORMAL, new Integer[] {
					Integer.valueOf(130) 
			})
			{
				public void onPacketSending(PacketEvent event) {
					if (event.getPacketID() == 130)
						try {
							event.setPacket(modify(event.getPacket(), event.getPlayer().getName()));
						} catch (FieldAccessException e) {
							plugin.getLogger().log(Level.SEVERE, "Couldn't access field.", e);
						}
				}
			});
	log("Enabled");
}
 
開發者ID:Esaych,項目名稱:DDCustomPlugin,代碼行數:18,代碼來源:JailSigns.java

示例7: constructProtocol

import com.comphenix.protocol.events.PacketAdapter; //導入依賴的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 index = event.getPacketType() == COMBAT_EVENT ? 1 : 0;

            Integer entityID = event.getPacket().getIntegers().readSafely(index);
            if (entityID != null) {
                if (!isVisible(event.getPlayer(), entityID)) {
                    event.setCancelled(true);
                }
            }
        }
    };
}
 
開發者ID:Co0sh,項目名稱:BetonQuest,代碼行數:25,代碼來源:EntityHider.java

示例8: register

import com.comphenix.protocol.events.PacketAdapter; //導入依賴的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.getTargetID();
                        if (running.containsKey(event.getPlayer().getUniqueId()) && packet.getType() == EntityUseAction.ATTACK) {
                            running.get(event.getPlayer().getUniqueId()).markAsKilled(entID);
                        }
                    }
                }

            });
    this.isRegistered = true;
}
 
開發者ID:maciekmm,項目名稱:AntiAura,代碼行數:18,代碼來源:AntiAura.java

示例9: setupPacketModification

import com.comphenix.protocol.events.PacketAdapter; //導入依賴的package包/類
/**
 * Set up packet listening for ENTITY_METADATA packets so they can be modified to actually contain
 * the dead horses' equipped armor.
 */
private void setupPacketModification() {
  if (getServer().getPluginManager().getPlugin(PROTOCOL_LIB) instanceof ProtocolLibrary) {
    fancyLog("ProtocolLib detected, creating hook for entity metadata packets.");
    ProtocolManager manager = ProtocolLibrary.getProtocolManager();
    manager.addPacketListener(new PacketAdapter(new PacketAdapter.AdapterParameteters()
        .plugin(this).serverSide().types(PacketType.Play.Server.ENTITY_METADATA)) {
      @Override
      public void onPacketSending(PacketEvent event) {
        if (config.isPacketModificationEnabled()) {
          handleMetadataPacket(event);
        }
      }
    });
    hookedProtocolLib = true;
    fancyLog("Entity metadata packet hooked.");
  }
}
 
開發者ID:EasyMFnE,項目名稱:DeadHorses,代碼行數:22,代碼來源:DeadHorses.java

示例10: registerPacketListeners

import com.comphenix.protocol.events.PacketAdapter; //導入依賴的package包/類
public void registerPacketListeners() {
	final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
	for (PacketType packetType : new PacketType[] { PacketType.Play.Client.POSITION }) {
		protocolManager
				.addPacketListener(new PacketAdapter(Crescent.getInstance(), ListenerPriority.NORMAL, packetType) {
					@Override
					public void onPacketReceiving(PacketEvent event) {
						if (event.getPacketType() == packetType) {
							Bukkit.getPluginManager()
									.callEvent(new PlayerPacketEvent(event.getPlayer(), event.getPacket()));
						}
					}
				});
	}
}
 
開發者ID:davidm98,項目名稱:Crescent,代碼行數:16,代碼來源:BehaviourListeners.java

示例11: RecipeDupePatch

import com.comphenix.protocol.events.PacketAdapter; //導入依賴的package包/類
public RecipeDupePatch() {
    keepers = Sets.newHashSet();
    
    ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(EscapeLag.MainThis, Play.Client.AUTO_RECIPE) {
        @Override
        public void onPacketReceiving(PacketEvent evt) {
            if (!ConfigPatch.autoRecipePatch) return;
            keepers.add(evt.getPlayer());
        }
    });
}
 
開發者ID:GelandiAssociation,項目名稱:EscapeLag,代碼行數:12,代碼來源:RecipeDupePatch.java

示例12: SignLoginWindow

import com.comphenix.protocol.events.PacketAdapter; //導入依賴的package包/類
public SignLoginWindow(ProtocolManager protocolManager, Plugin plugin) {
	super(protocolManager, plugin);
	protocolManager.addPacketListener(
			new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.UPDATE_SIGN) {
				@Override
				public void onPacketReceiving(PacketEvent event) {
					if (event.getPacketType() != PacketType.Play.Client.UPDATE_SIGN) {
						return;
					}
					if (AuthMeApi.getInstance().isAuthenticated(event.getPlayer())) {
						return;
					}
					PacketContainer packet = event.getPacket();
					String[] strings = packet.getStringArrays().read(0);
					if (strings[Variables.signLoginLine - 1].isEmpty()) {
						return;
					}
					boolean registered = AuthMeApi.getInstance().isRegistered(event.getPlayer().getName());
					String password = strings[Variables.signLoginLine - 1].substring(SignLoginWindow.this
							.getInfoFor(event.getPlayer(), Variables.signInfo.get(Variables.signLoginLine - 1))
							.length());
					if (!registered & !password.isEmpty()) {
						AuthMeApi.getInstance().registerPlayer(event.getPlayer().getName(), password);
					}
					Bukkit.getPluginCommand("login").execute(event.getPlayer(), "login", new String[] { password });
				}
			});
}
 
開發者ID:lj2000lj,項目名稱:AuthMeGUI,代碼行數:29,代碼來源:SignLoginWindow.java

示例13: register

import com.comphenix.protocol.events.PacketAdapter; //導入依賴的package包/類
public static void register() {
	ProtocolUtils.get().addPacketListener(
		new PacketAdapter(NeverLag.getInstance(), PacketType.Play.Client.SET_CREATIVE_SLOT) {
			@Override
			public void onPacketReceiving(PacketEvent e) {
				onSetCreativeSlotPacket(e);
			}
		});
}
 
開發者ID:jiongjionger,項目名稱:NeverLag,代碼行數:10,代碼來源:AntiAUWMod.java

示例14: hook

import com.comphenix.protocol.events.PacketAdapter; //導入依賴的package包/類
/**
 * Hooks ProtocolLibrary into a {@link JavaPlugin}.
 *
 * @param kairos
 *            the plugin to hook into
 */
public static void hook(HCF kairos) {
    ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
    protocolManager.addPacketListener(new PacketAdapter(kairos, ListenerPriority.NORMAL, PacketType.Play.Client.BLOCK_DIG) {
        @Override
        public void onPacketReceiving(PacketEvent event) {
            PacketContainer packet = event.getPacket();
            StructureModifier<Integer> modifier = packet.getIntegers();
            Player player = event.getPlayer();

            try {
                int status = modifier.read(4);
                // int face = modifier.read(3);
                if (status == STARTED_DIGGING || status == FINISHED_DIGGING) {
                    int x, y, z;
                    Location location = new Location(player.getWorld(), x = modifier.read(0), y = modifier.read(1), z = modifier.read(2));

                    // Validation
                    VisualBlock visualBlock = kairos.getVisualiseHandler().getVisualBlockAt(player, location);
                    if (visualBlock == null)
                        return;

                    event.setCancelled(true);
                    VisualBlockData data = visualBlock.getBlockData();
                    if (status == FINISHED_DIGGING) {
                        player.sendBlockChange(location, data.getBlockType(), data.getData());
                    } else if (status == STARTED_DIGGING) { // we check this because Blocks that broke pretty much straight away do not send a FINISHED for some weird reason.
                        EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
                        if (player.getGameMode() == GameMode.CREATIVE
                                || net.minecraft.server.v1_7_R4.Block.getById(data.getItemTypeId()).getDamage(entityPlayer, entityPlayer.world, x, y, z) > 1.0F) {

                            player.sendBlockChange(location, data.getBlockType(), data.getData());
                        }
                    }
                }
            } catch (FieldAccessException ignored) {
            }
        }
    });
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:46,代碼來源:ProtocolLibHook.java

示例15: constructProtocol

import com.comphenix.protocol.events.PacketAdapter; //導入依賴的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:ijoeleoli,項目名稱:ZorahPractice,代碼行數:19,代碼來源:EntityHider.java


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