本文整理汇总了Java中com.comphenix.protocol.events.PacketContainer类的典型用法代码示例。如果您正苦于以下问题:Java PacketContainer类的具体用法?Java PacketContainer怎么用?Java PacketContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PacketContainer类属于com.comphenix.protocol.events包,在下文中一共展示了PacketContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newObjectivePacket
import com.comphenix.protocol.events.PacketContainer; //导入依赖的package包/类
private PacketContainer newObjectivePacket(UpdateType mode) {
// http://wiki.vg/Protocol#Scoreboard_Objective
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_OBJECTIVE);
// set name - limited to String(16)
packet.getStrings().write(0, getId());
// set mode - 0 to create the scoreboard. 1 to remove the scoreboard. 2 to update the display text.
packet.getIntegers().write(0, mode.getCode());
// set display name - limited to String(16) - Only if mode is 0 or 2. The text to be displayed for the score
packet.getStrings().write(1, getDisplayName());
// set type - either "integer" or "hearts"
packet.getEnumModifier(HealthDisplay.class, 2).write(0, HealthDisplay.INTEGER);
return packet;
}
示例2: newScorePacket
import com.comphenix.protocol.events.PacketContainer; //导入依赖的package包/类
private PacketContainer newScorePacket(String name, int value, ScoreboardAction action) {
// http://wiki.vg/Protocol#Update_Score
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_SCORE);
// set "Entity name" - aka the name of the score - limited to 40.
packet.getStrings().write(0, name);
// set the action - 0 to create/update an item. 1 to remove an item.
packet.getScoreboardActions().write(0, action);
// set objective name - The name of the objective the score belongs to
packet.getStrings().write(1, getId());
// set value of the score- The score to be displayed next to the entry. Only sent when Action does not equal 1.
packet.getIntegers().write(0, value);
return packet;
}
示例3: newTeamMemberUpdatePacket
import com.comphenix.protocol.events.PacketContainer; //导入依赖的package包/类
private PacketContainer newTeamMemberUpdatePacket(String player, MemberAction action) {
// http://wiki.vg/Protocol#Teams
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM);
// set team name - String (16)
packet.getStrings().write(0, getId());
// set mode
switch (action) {
case ADD:
packet.getIntegers().write(1, UpdateType.ADD_PLAYERS.getCode());
break;
case REMOVE:
packet.getIntegers().write(1, UpdateType.REMOVE_PLAYERS.getCode());
break;
default:
throw new RuntimeException();
}
// set players - Array of String (40)
packet.getSpecificModifier(Collection.class).write(0, Collections.singletonList(player));
return packet;
}
示例4: sendTabListAddPacket
import com.comphenix.protocol.events.PacketContainer; //导入依赖的package包/类
@Override
public void sendTabListAddPacket(Player playerToAdd, GameProfileWrapper newProfile, Player seer) {
PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO);
int ping = (int) ReflectUtil.getFieldValue(ReflectUtil.invokeMethod(playerToAdd, GET_HANDLE).getOrThrow(), PING).getOrThrow();
packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.ADD_PLAYER);
PlayerInfoData playerInfoData = new PlayerInfoData(getProtocolLibProfileWrapper(newProfile), ping, EnumWrappers.NativeGameMode.fromBukkit(playerToAdd.getGameMode()), WrappedChatComponent.fromText(playerToAdd.getPlayerListName()));
packet.getPlayerInfoDataLists().write(0, Collections.singletonList(playerInfoData));
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(seer, packet);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
示例5: sendNamedEntitySpawnPacket
import com.comphenix.protocol.events.PacketContainer; //导入依赖的package包/类
@Override
public void sendNamedEntitySpawnPacket(Player playerToSpawn, Player seer) {
PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
packet.getIntegers().write(0, playerToSpawn.getEntityId());
packet.getUUIDs().write(0, playerToSpawn.getUniqueId());
if (ReflectUtil.isVersionHigherThan(1, 8, 8)) {
packet.getDoubles().write(0, playerToSpawn.getLocation().getX());
packet.getDoubles().write(1, playerToSpawn.getLocation().getY());
packet.getDoubles().write(2, playerToSpawn.getLocation().getZ());
} else {
packet.getIntegers().write(0, (int) Math.floor(playerToSpawn.getLocation().getX() * 32D));
packet.getIntegers().write(1, (int) Math.floor(playerToSpawn.getLocation().getY() * 32D));
packet.getIntegers().write(2, (int) Math.floor(playerToSpawn.getLocation().getZ() * 32D));
}
packet.getBytes().write(0, (byte) (playerToSpawn.getLocation().getYaw() * 256F / 360F));
packet.getBytes().write(1, (byte) (playerToSpawn.getLocation().getPitch() * 256F / 360F));
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(seer, packet);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
示例6: openFor
import com.comphenix.protocol.events.PacketContainer; //导入依赖的package包/类
@Override
public void openFor(Player player) throws InvocationTargetException {
if (AuthMeApi.getInstance().isAuthenticated(player)) {
return;
}
PacketContainer fakeBlockChange = new PacketContainer(PacketType.Play.Server.BLOCK_CHANGE);
PacketContainer updateEntity = new PacketContainer(PacketType.Play.Server.TILE_ENTITY_DATA);
PacketContainer sign = new PacketContainer(PacketType.Play.Server.OPEN_SIGN_EDITOR);
Location block = player.getLocation().getBlock().getLocation();
BlockPosition position = new BlockPosition(block.getBlockX(), block.getBlockY() + 1, block.getBlockZ());
fakeBlockChange.getBlockPositionModifier().write(0, position);
fakeBlockChange.getBlockData().write(0, WrappedBlockData.createData(Material.SIGN_POST));
protocolManager.sendServerPacket(player, fakeBlockChange);
updateEntity.getBlockPositionModifier().write(0, position);
updateEntity.getIntegers().write(0, 9);
NbtCompound signNbt = (NbtCompound) updateEntity.getNbtModifier().read(0);
signNbt = signNbt == null ? NbtFactory.ofCompound("") : signNbt;
List<String> lines = this.getInfoFor(player);
for (int i = 0; i < lines.size() || i < 4; i++) {
signNbt.put("Text" + (i + 1), "{\"text\":\"" + lines.get(i) + "\"}");
}
updateEntity.getNbtModifier().write(0, signNbt);
protocolManager.sendServerPacket(player, updateEntity);
sign.getBlockPositionModifier().write(0, position);
protocolManager.sendServerPacket(player, sign);
}
示例7: fromMapPacket
import com.comphenix.protocol.events.PacketContainer; //导入依赖的package包/类
/**
* Construct a chunk packet processor from a givne MAP_CHUNK packet.
* @param packet - the map chunk packet.
* @return The chunk packet processor.
*/
public static ChunkPacketProcessor fromMapPacket(PacketContainer packet, World world) {
if (!packet.getType().equals(PacketType.Play.Server.MAP_CHUNK))
throw new IllegalArgumentException(packet + " must be a MAP_CHUNK packet.");
StructureModifier<Integer> ints = packet.getIntegers();
StructureModifier<byte[]> byteArray = packet.getByteArrays();
// Create an info objects
ChunkPacketProcessor processor = new ChunkPacketProcessor();
processor.world = world;
processor.chunkX = ints.read(0); // packet.a;
processor.chunkZ = ints.read(1); // packet.b;
processor.chunkMask = ints.read(2); // packet.c;
processor.extraMask = ints.read(3); // packet.d;
processor.data = byteArray.read(1); // packet.inflatedBuffer;
processor.startIndex = 0;
if (packet.getBooleans().size() > 0) {
processor.hasContinous = packet.getBooleans().read(0);
}
return processor;
}
示例8: hideEntity
import com.comphenix.protocol.events.PacketContainer; //导入依赖的package包/类
/**
* Prevent the observer from seeing a given entity.
* @param observer - the player observer.
* @param entity - the entity to hide.
* @return TRUE if the entity was previously visible, FALSE otherwise.
*/
public boolean hideEntity(Player observer, Entity entity) {
validate(observer, entity);
boolean visibleBefore = setVisibility(observer, entity.getEntityId(), false);
if (visibleBefore) {
PacketContainer destroyEntity = new PacketContainer(ENTITY_DESTROY);
destroyEntity.getIntegerArrays().write(0, new int[] { entity.getEntityId() });
// Make the entity disappear
try {
manager.sendServerPacket(observer, destroyEntity);
} catch (InvocationTargetException e) {
throw new RuntimeException("Cannot send server packet.", e);
}
}
return visibleBefore;
}
示例9: sendMessage
import com.comphenix.protocol.events.PacketContainer; //导入依赖的package包/类
public static void sendMessage(Player player, String message, int slot, int second) {
ItemStack item = player.getOpenInventory().getItem(slot);
if (item != null && item.getType() != Material.AIR) {
ItemStack newItem = new ItemBuilder(item)
.display(message)
.build();
PlayerWrapper wrapper = new PlayerWrapper(player);
Bukkit.getScheduler().runTask(MCLibrary.getPlugin(), () -> {
PacketContainer packet = MCLibrary.getPacketFactory().createSetSlot(
wrapper.getContainerCounter(), slot, newItem
);
MCUtils.sendPacket(player, packet);
Bukkit.getScheduler().runTaskLater(MCLibrary.getPlugin(), () -> {
packet.getItemModifier().write(0, item);
MCUtils.sendPacket(player, packet);
}, second * 20L);
});
}
}
示例10: sendKeepAlive
import com.comphenix.protocol.events.PacketContainer; //导入依赖的package包/类
public static void sendKeepAlive(List<Player> player) {
for (Player p : player) {
try {
PacketContainer packet = get().createPacket(PacketType.Play.Client.KEEP_ALIVE);
packet.getIntegers().write(0, random.nextInt());
get().sendServerPacket(p, packet);
} catch (InvocationTargetException ex) {
ex.printStackTrace();
}
}
}
示例11: newDisplaySlotPacket
import com.comphenix.protocol.events.PacketContainer; //导入依赖的package包/类
private PacketContainer newDisplaySlotPacket(DisplaySlot displaySlot) {
// http://wiki.vg/Protocol#Display_Scoreboard
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_DISPLAY_OBJECTIVE);
// set position
final int slot;
switch (displaySlot) {
case PLAYER_LIST:
slot = 0;
break;
case SIDEBAR:
slot = 1;
break;
case BELOW_NAME:
slot = 2;
break;
default:
throw new RuntimeException();
}
packet.getIntegers().write(0, slot);
// set objective name - The unique name for the scoreboard to be displayed.
packet.getStrings().write(0, getId());
return packet;
}
示例12: sendPacket
import com.comphenix.protocol.events.PacketContainer; //导入依赖的package包/类
/**
* Sends a packet to a player, absorbing any exceptions thrown in the process
*
* @param packet the packet to send
* @param player the player to send the packet to
*/
void sendPacket(PacketContainer packet, Player player) {
try {
protocolManager.sendServerPacket(player, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
示例13: newCreatePacket
import com.comphenix.protocol.events.PacketContainer; //导入依赖的package包/类
private PacketContainer newCreatePacket() {
// create an update packet (as that contains a number of values required by the create packet)
PacketContainer packet = newUpdatePacket();
// set mode - byte
packet.getIntegers().write(1, UpdateType.CREATE.getCode());
// add player info - array of String(40)
List<String> players = new ArrayList<>(getPlayers());
// set players - ProtocolLib handles setting 'Entity Count'
packet.getSpecificModifier(Collection.class).write(0, players);
return packet;
}
示例14: newRemovePacket
import com.comphenix.protocol.events.PacketContainer; //导入依赖的package包/类
private PacketContainer newRemovePacket() {
// http://wiki.vg/Protocol#Teams
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM);
// remove packet only has the default fields
// set team name - String (16)
packet.getStrings().write(0, getId());
// set mode - byte
packet.getIntegers().write(1, UpdateType.REMOVE.getCode());
return packet;
}
示例15: sendTabListRemovePacket
import com.comphenix.protocol.events.PacketContainer; //导入依赖的package包/类
@Override
public void sendTabListRemovePacket(Player playerToRemove, Player seer) {
PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO);
packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.REMOVE_PLAYER);
PlayerInfoData playerInfoData = new PlayerInfoData(WrappedGameProfile.fromPlayer(playerToRemove), 0, EnumWrappers.NativeGameMode.NOT_SET, null);
packet.getPlayerInfoDataLists().write(0, Collections.singletonList(playerInfoData));
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(seer, packet);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}