com.comphenix.protocol.wrappers.EnumWrappers Java Examples
The following examples show how to use
com.comphenix.protocol.wrappers.EnumWrappers.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnimationPattern.java From AACAdditionPro with GNU General Public License v3.0 | 6 votes |
@Override protected int process(User user, PacketEvent packetEvent) { if (packetEvent.getPacketType() == PacketType.Play.Client.ARM_ANIMATION) { user.getDataMap().setValue(DataKey.PACKET_ANALYSIS_ANIMATION_EXPECTED, false); } else { if (user.getDataMap().getBoolean(DataKey.PACKET_ANALYSIS_ANIMATION_EXPECTED)) { user.getDataMap().setValue(DataKey.PACKET_ANALYSIS_ANIMATION_EXPECTED, false); message = "PacketAnalysisData-Verbose | Player: " + user.getPlayer().getName() + " did not send animation packet after an attack."; return 10; } } if (packetEvent.getPacketType() == PacketType.Play.Client.USE_ENTITY) { // Make sure an arm animation packet is sent directly after an attack as it is the next packet in the client // code. final WrapperPlayClientUseEntity useEntityWrapper = new WrapperPlayClientUseEntity(packetEvent.getPacket()); if (useEntityWrapper.getType() == EnumWrappers.EntityUseAction.ATTACK) { user.getDataMap().setValue(DataKey.PACKET_ANALYSIS_ANIMATION_EXPECTED, true); } return 0; } return 0; }
Example #2
Source File: WrapperPlayServerEntityEquipment.java From AACAdditionPro with GNU General Public License v3.0 | 6 votes |
/** * Sets all equipment slots of the entity to air for the observer. * * @param entityId the id of the {@link Entity} which slots should be cleared. * @param observer the {@link Player} who shall no longer see the equipment. */ public static void clearAllSlots(int entityId, Player observer) { for (final EnumWrappers.ItemSlot slot : EnumWrappers.ItemSlot.values()) { //Update the equipment with fake-packets final WrapperPlayServerEntityEquipment wrapperPlayServerEntityEquipment = new WrapperPlayServerEntityEquipment(); wrapperPlayServerEntityEquipment.setEntityID(entityId); wrapperPlayServerEntityEquipment.setItem(new ItemStack(Material.AIR)); // 1.8.8 is automatically included as of the bukkit-handling, therefore server-version specific handling // as of the different server classes / enums and the null-removal above. wrapperPlayServerEntityEquipment.setSlot(slot); wrapperPlayServerEntityEquipment.sendPacket(observer); } }
Example #3
Source File: VanishIndication.java From SuperVanish with Mozilla Public License 2.0 | 6 votes |
private void sendPlayerInfoChangeGameModePacket(Player p, Player change, boolean spectator) { PacketContainer packet = new PacketContainer(PLAYER_INFO); packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE); List<PlayerInfoData> data = new ArrayList<>(); int ping = ThreadLocalRandom.current().nextInt(20) + 15; data.add(new PlayerInfoData(WrappedGameProfile.fromPlayer(change), ping, spectator ? EnumWrappers.NativeGameMode.SPECTATOR : EnumWrappers.NativeGameMode.fromBukkit(change.getGameMode()), WrappedChatComponent.fromText(change.getPlayerListName()))); packet.getPlayerInfoDataLists().write(0, data); try { ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet); } catch (InvocationTargetException e) { throw new RuntimeException("Cannot send packet", e); } }
Example #4
Source File: SkinApplier.java From ChangeSkin with MIT License | 6 votes |
private PacketContainer createRespawnPacket(NativeGameMode gamemode) throws ReflectiveOperationException { PacketContainer respawn = new PacketContainer(RESPAWN); Difficulty difficulty = EnumWrappers.getDifficultyConverter().getSpecific(receiver.getWorld().getDifficulty()); //<= 1.13.1 int dimensionId = receiver.getWorld().getEnvironment().getId(); respawn.getIntegers().writeSafely(0, dimensionId); //> 1.13.1 if (MinecraftVersion.getCurrentVersion().compareTo(MinecraftVersion.AQUATIC_UPDATE) > 0) { try { respawn.getDimensions().writeSafely(0, dimensionId); } catch (NoSuchMethodError noSuchMethodError) { throw new ReflectiveOperationException("Unable to find dimension setter. " + "Your ProtocolLib version is incompatible with this plugin version in combination with " + "Minecraft 1.13.1. " + "Try to download an update of ProtocolLib.", noSuchMethodError); } } respawn.getDifficulties().writeSafely(0, difficulty); respawn.getGameModes().write(0, gamemode); respawn.getWorldTypeModifier().write(0, receiver.getWorld().getWorldType()); return respawn; }
Example #5
Source File: TabListRemoveCommand.java From AACAdditionPro with GNU General Public License v3.0 | 5 votes |
private void updatePlayerInfo(final EnumWrappers.PlayerInfoAction action, final Player affectedPlayer, final Player modifiedPlayer) { DisplayInformation.updatePlayerInformation(action, WrappedGameProfile.fromPlayer(modifiedPlayer), ServerUtil.getPing(modifiedPlayer), EnumWrappers.NativeGameMode.fromBukkit(modifiedPlayer.getGameMode()), null, affectedPlayer); }
Example #6
Source File: CFIPacketListener.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
private Vector getRelative(PacketEvent container, Vector pt) { PacketContainer packet = container.getPacket(); StructureModifier<EnumWrappers.Direction> dirs = packet.getDirections(); EnumWrappers.Direction dir = dirs.readSafely(0); if (dir == null) return pt; switch (dir.ordinal()) { case 0: return pt.add(0, -1, 0); case 1: return pt.add(0, 1, 0); case 2: return pt.add(0, 0, -1); case 3: return pt.add(0, 0, 1); case 4: return pt.add(-1, 0, 0); case 5: return pt.add(1, 0, 0); default: return pt; } }
Example #7
Source File: WrapperPlayServerChat.java From BetonQuest with GNU General Public License v3.0 | 5 votes |
/** * Set Position. * * @param value - new value. * @deprecated Magic values replaced by enum */ @Deprecated public void setPosition(byte value) { handle.getBytes().writeSafely(0, value); if (EnumWrappers.getChatTypeClass() != null) { Arrays.stream(ChatType.values()).filter(t -> t.getId() == value).findAny() .ifPresent(t -> handle.getChatTypes().writeSafely(0, t)); } }
Example #8
Source File: ProtocolUtils.java From UhcCore with GNU General Public License v3.0 | 4 votes |
private ProtocolUtils(){ protocolUtils = this; ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(UhcCore.getPlugin(), PacketType.Play.Server.PLAYER_INFO) { @Override public void onPacketSending(PacketEvent event) { if (event.getPacket().getPlayerInfoAction().read(0) != EnumWrappers.PlayerInfoAction.ADD_PLAYER){ return; } List<PlayerInfoData> newPlayerInfoDataList = new ArrayList<>(); List<PlayerInfoData> playerInfoDataList = event.getPacket().getPlayerInfoDataLists().read(0); PlayersManager pm = GameManager.getGameManager().getPlayersManager(); for (PlayerInfoData playerInfoData : playerInfoDataList) { if ( playerInfoData == null || playerInfoData.getProfile() == null || Bukkit.getPlayer(playerInfoData.getProfile().getUUID()) == null ){ // Unknown player newPlayerInfoDataList.add(playerInfoData); continue; } WrappedGameProfile profile = playerInfoData.getProfile(); UhcPlayer uhcPlayer; try { uhcPlayer = pm.getUhcPlayer(profile.getUUID()); }catch (UhcPlayerDoesntExistException ex){ // UhcPlayer does not exist newPlayerInfoDataList.add(playerInfoData); continue; } // No display-name so don't change player data. if (!uhcPlayer.hasNickName()){ newPlayerInfoDataList.add(playerInfoData); continue; } profile = profile.withName(uhcPlayer.getName()); PlayerInfoData newPlayerInfoData = new PlayerInfoData(profile, playerInfoData.getPing(), playerInfoData.getGameMode(), playerInfoData.getDisplayName()); newPlayerInfoDataList.add(newPlayerInfoData); } event.getPacket().getPlayerInfoDataLists().write(0, newPlayerInfoDataList); } }); }
Example #9
Source File: WrapperPlayServerPosition.java From AACAdditionPro with GNU General Public License v3.0 | 4 votes |
private StructureModifier<Set<PlayerTeleportFlag>> getFlagsModifier() { return handle.getSets(EnumWrappers.getGenericConverter(FLAGS_CLASS, PlayerTeleportFlag.class)); }
Example #10
Source File: TabListRemoveCommand.java From AACAdditionPro with GNU General Public License v3.0 | 4 votes |
@Override protected void execute(CommandSender sender, Queue<String> arguments) { /* * [0] represents the the affected player * [1] represents the modified player */ final Player[] players = new Player[2]; for (int i = 0; i < players.length; i++) { players[i] = AACAdditionPro.getInstance().getServer().getPlayer(arguments.remove()); if (players[i] == null) { ChatMessage.sendPlayerNotFoundMessage(sender); return; } } // This prevents the crashing of the player. if (players[0].getUniqueId().equals(players[1].getUniqueId())) { ChatMessage.sendErrorMessage(sender, "The affected player must not be the removed player."); return; } long ticks = 0; try { if (!arguments.isEmpty()) { ticks = Long.parseLong(arguments.remove()); } } catch (NumberFormatException e) { ChatMessage.sendErrorMessage(sender, "Please specify a valid integer."); return; } sender.sendMessage(ChatColor.GOLD + "Removed player " + ChatColor.RED + players[1].getName() + ChatColor.GOLD + " from " + ChatColor.RED + players[0].getName() + ChatColor.GOLD + "'s tablist for " + ChatColor.RED + ticks + ChatColor.GOLD + " ticks."); updatePlayerInfo(EnumWrappers.PlayerInfoAction.REMOVE_PLAYER, players[0], players[1]); if (ticks == 0) { updatePlayerInfo(EnumWrappers.PlayerInfoAction.ADD_PLAYER, players[0], players[1]); } else { Bukkit.getScheduler().runTaskLater(AACAdditionPro.getInstance(), () -> updatePlayerInfo(EnumWrappers.PlayerInfoAction.ADD_PLAYER, players[0], players[1]), ticks); } }
Example #11
Source File: VanishIndication.java From SuperVanish with Mozilla Public License 2.0 | 4 votes |
@Override public void onEnable() { ProtocolLibrary.getProtocolManager().addPacketListener( new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.PLAYER_INFO) { @Override public void onPacketSending(PacketEvent event) { // multiple events share same packet object event.setPacket(event.getPacket().shallowClone()); List<PlayerInfoData> infoDataList = new ArrayList<>( event.getPacket().getPlayerInfoDataLists().read(0)); Player receiver = event.getPlayer(); for (PlayerInfoData infoData : ImmutableList.copyOf(infoDataList)) { try { if (!VanishIndication.this.plugin.getVisibilityChanger().getHider() .isHidden(infoData.getProfile().getUUID(), receiver) && VanishIndication.this.plugin.getVanishStateMgr() .isVanished(infoData.getProfile().getUUID())) { if (!receiver.getUniqueId().equals(infoData.getProfile().getUUID())) if (infoData.getGameMode() != EnumWrappers.NativeGameMode.SPECTATOR) { int latency; try { latency = infoData.getLatency(); } catch (NoSuchMethodError e) { latency = 21; } if (event.getPacket().getPlayerInfoAction().read(0) != EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE) { continue; } PlayerInfoData newData = new PlayerInfoData(infoData.getProfile(), latency, EnumWrappers.NativeGameMode.SPECTATOR, infoData.getDisplayName()); infoDataList.remove(infoData); infoDataList.add(newData); } } } catch (UnsupportedOperationException ignored) { // Ignore temporary players } } event.getPacket().getPlayerInfoDataLists().write(0, infoDataList); } }); }
Example #12
Source File: DisplayInformation.java From AACAdditionPro with GNU General Public License v3.0 | 3 votes |
/** * This method updates the player information, and thus the tablist of a player. * * @param action the {@link com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction} that will be executed. * @param gameProfile the {@link WrappedGameProfile} of the player whose information will be updated.<br> * Use {@link WrappedGameProfile#fromPlayer(Player)} in order to get a {@link WrappedGameProfile} from a {@link Player}. * @param ping the new ping of the updated {@link Player}. * @param gameMode the {@link com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode} of the updated {@link Player}. * Use {@link de.photon.aacadditionpro.util.server.ServerUtil#getPing(Player)} to get the ping of a {@link Player}. * @param displayName the new displayName of the updated {@link Player} * @param affectedPlayer the {@link Player} who will see the updated information as the packet is sent to him. */ public static void updatePlayerInformation(final EnumWrappers.PlayerInfoAction action, final WrappedGameProfile gameProfile, final int ping, final EnumWrappers.NativeGameMode gameMode, final WrappedChatComponent displayName, final Player affectedPlayer) { final PlayerInfoData playerInfoData = new PlayerInfoData(gameProfile, ping, gameMode, displayName); final WrapperPlayServerPlayerInfo playerInfoWrapper = new WrapperPlayServerPlayerInfo(); playerInfoWrapper.setAction(action); playerInfoWrapper.setData(Collections.singletonList(playerInfoData)); playerInfoWrapper.sendPacket(affectedPlayer); }