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


Java PacketEvent.getPacketType方法代碼示例

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


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

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

示例2: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketSending(PacketEvent event) {
    int distance = SoundMuffler.DISTANCE * SoundMuffler.DISTANCE;
    if (event.getPacketType() == PacketType.Play.Server.NAMED_SOUND_EFFECT) {
        int x = event.getPacket().getIntegers().read(0) >> 3;
        int y = event.getPacket().getIntegers().read(1) >> 3;
        int z = event.getPacket().getIntegers().read(2) >> 3;
        Location loc = new Location(event.getPlayer().getWorld(), x, y, z);
        for (SoundMuffler sm : mufflers) {
            if (loc.getWorld().equals(sm.getLocation().getWorld()) && loc.distanceSquared(sm.getLocation()) < distance) {
                if (sm.getVolume() == 0) {
                    event.setCancelled(true);
                } else {
                    event.getPacket().getFloat().write(0, (float) sm.getVolume() / 100.0f);
                }
            }
        }
    }
}
 
開發者ID:desht,項目名稱:sensibletoolbox,代碼行數:20,代碼來源:SoundMufflerListener.java

示例3: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketSending(PacketEvent event) {
	if(event.getPacketType() == PacketType.Play.Server.PLAYER_INFO) {
		PacketContainer packet = event.getPacket();
		PlayerInfoAction action = packet.getPlayerInfoAction().read(0);
		Player player = Bukkit.getPlayer(packet.getPlayerInfoDataLists().read(0).get(0).getProfile().getUUID());
		boolean online = player != null && player.isOnline();
		if(online && action == PlayerInfoAction.REMOVE_PLAYER) event.setCancelled(true);
	}
}
 
開發者ID:TealNerd,項目名稱:RadarJammer,代碼行數:11,代碼來源:PlayerListManager.java

示例4: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketSending( PacketEvent event ) {
	if ( event.getPacketType() == PacketType.Play.Server.SET_SLOT ) {
		this.onSetSlot( event );
	} else if ( event.getPacketType() == PacketType.Play.Server.WINDOW_ITEMS ) {
		this.onWindowItems( event );
	}
}
 
開發者ID:BlackyPaw,項目名稱:I18N,代碼行數:9,代碼來源:InterceptorSlot.java

示例5: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketSending( PacketEvent event ) {
	if ( event.getPacketType() == PacketType.Play.Server.SCOREBOARD_OBJECTIVE ) {
		this.onScoreboardObjective( event );
	} else if ( event.getPacketType() == PacketType.Play.Server.SCOREBOARD_SCORE ) {
		this.onScoreboardScore( event );
	} else if ( event.getPacketType() == PacketType.Play.Server.SCOREBOARD_TEAM ) {
		this.onScoreboardTeam( event );
	}
}
 
開發者ID:BlackyPaw,項目名稱:I18N,代碼行數:11,代碼來源:InterceptorScoreboard.java

示例6: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketSending( PacketEvent event ) {
	if ( event.getPacketType() == PacketType.Play.Server.TILE_ENTITY_DATA ) {
		this.onTileEntityData( event );
	} else if ( event.getPacketType() == PacketType.Play.Server.MAP_CHUNK ) {
		this.onMapChunk( event );
	}
}
 
開發者ID:BlackyPaw,項目名稱:I18N,代碼行數:9,代碼來源:InterceptorSign.java

示例7: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void onPacketSending(final PacketEvent event) {
	if (event.getPacketType() != PacketType.Play.Server.CHAT) {
		return;
	}
	if (event.isCancelled()) {
		return;
	}
	final PacketContainer packet = event.getPacket();
	final List<WrappedChatComponent> chatComponentValues = packet.getChatComponents().getValues();

	// igonre system messages if set in config
	if (!main.getConfig().getBoolean("ignoreSystemMessages") || packet.getBytes().size() <= 0 || packet.getBytes().read(0) != 1) {
		// Parse Json, translate messages only
		event.setCancelled(true);
		final String lang = User.get(event.getPlayer()).getLanguage();
		for (final WrappedChatComponent chatComponent : chatComponentValues) {
			final Object parsed = JSONValue.parse(chatComponent.getJson());
			if (parsed == null) {
				if (chatComponent.getJson().isEmpty()) {
					continue;
				} else {
					// TODO print error
				}
			} else if (parsed instanceof String) {
				chatComponent.setJson(translator.getTranslationOf(((String) parsed), "auto", lang));
			} else if (parsed instanceof JSONArray) {
				chatComponent.setJson(parseAndTranslate((JSONArray) parsed, lang).toJSONString());
			} else if (parsed instanceof JSONObject) {
				chatComponent.setJson(parseAndTranslate((JSONObject) parsed, lang).toJSONString());
			}
		}
	}
}
 
開發者ID:davewolax,項目名稱:ChatTranslator,代碼行數:36,代碼來源:ChatMessageSendingListener.java

示例8: onPacketReceiving

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketReceiving(PacketEvent event) {
    if (event.getPacketType() == PacketType.Play.Client.TAB_COMPLETE) {
        try {
            if (!playerCache.isAuthenticated(event.getPlayer().getName())) {
                event.setCancelled(true);
            }
        } catch (FieldAccessException e) {
            ConsoleLogger.logException("Couldn't access field:", e);
        }
    }
}
 
開發者ID:AuthMe,項目名稱:AuthMeReloaded,代碼行數:13,代碼來源:TabCompletePacketAdapter.java

示例9: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketSending(PacketEvent pe) {
	if (pe.getPacketType() == PacketType.Play.Server.SPAWN_ENTITY) {
		PacketContainer packet = pe.getPacket();
		final Player player = pe.getPlayer();
		
		int entityID = packet.getIntegers().read(0);
		Location loc = new Location(
				player.getWorld(),
				((double)packet.getIntegers().read(1) / 32.0D),
				((double)packet.getIntegers().read(2) / 32.0D),
				((double)packet.getIntegers().read(3) / 32.0D)
		);
		int entityType = packet.getIntegers().read(9);
		int direction = packet.getIntegers().read(10);

		// Check if the entity is a item frame (Id 71)
		if (entityType != 71) {
			return;
		}

		Chunk chunk = loc.getChunk();
		if (!chunk.isLoaded()) {
			return;
		}

		Frame frame = FramePicturePlugin.getManager().getFrameWithEntityID(chunk, entityID);
		if (frame == null) {
			// Search the frame in the chunk.
			BlockFace facing = this.convertDirectionToBlockFace(direction);
			ItemFrame entity = Utils.getItemFrameFromChunk(chunk, loc, facing);
			if (entity == null) {
				return;
			}

			frame = FramePicturePlugin.getManager().getFrame(loc, facing);
			if (frame == null) {
				return;
			}
			frame.setEntity(entity);
		}

		final Frame frameToSend = frame;
		Bukkit.getScheduler().runTaskLater(FramePicturePlugin.getPlugin(), new Runnable() {
			@Override
			public void run() {
				frameToSend.sendTo(player);
			}
		}, 10L);
	}
}
 
開發者ID:Howaner,項目名稱:FramePicture,代碼行數:52,代碼來源:FramePacketListener.java


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