本文整理匯總了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);
}
}
}
});
}
示例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);
}
}
};
}
示例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);
}
}
});
}
示例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;
}
示例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);
}
示例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");
}
示例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);
}
}
}
};
}
示例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;
}
示例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.");
}
}
示例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()));
}
}
});
}
}
示例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());
}
});
}
示例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 });
}
});
}
示例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);
}
});
}
示例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) {
}
}
});
}
示例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);
}
}
};
}