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