Java Code Examples for protocolsupport.api.ProtocolSupportAPI#getConnection()
The following examples show how to use
protocolsupport.api.ProtocolSupportAPI#getConnection() .
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: TitleAPI.java From ProtocolSupport with GNU Affero General Public License v3.0 | 6 votes |
/** * Sends title, subtitle, and it's params <br> * Title and subtitle can't be both null * @param player Player to which title is sent * @param titleJson title chat json or null * @param subtitleJson subtitle chat json or null * @param fadeIn ticks to spend fading in * @param stay ticks to display * @param fadeOut ticks to spend fading out */ public static void sendSimpleTitle(Player player, String titleJson, String subtitleJson, int fadeIn, int stay, int fadeOut) { Validate.notNull(player, "Player can't be null"); if ((titleJson == null) && (subtitleJson == null)) { throw new IllegalArgumentException("Title and subtitle can't be both null"); } Connection connection = ProtocolSupportAPI.getConnection(player); connection.sendPacket(ServerPlatform.get().getPacketFactory().createTitleParamsPacket(fadeIn, stay, fadeOut)); if (subtitleJson != null) { connection.sendPacket(ServerPlatform.get().getPacketFactory().createTitleSubPacket(subtitleJson)); } if (titleJson == null) { titleJson = ""; } connection.sendPacket(ServerPlatform.get().getPacketFactory().createTitleMainPacket(titleJson)); }
Example 2
Source File: FeatureEmulation.java From ProtocolSupport with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPlace(BlockPlaceEvent event) { Player player = event.getPlayer(); Connection connection = ProtocolSupportAPI.getConnection(player); if ( (connection != null) && (connection.getVersion().getProtocolType() == ProtocolType.PC) && connection.getVersion().isBefore(ProtocolVersion.MINECRAFT_1_9) ) { BlockDataEntry blockdataentry = MinecraftBlockData.get(MaterialAPI.getBlockDataNetworkId(event.getBlock().getBlockData())); player.playSound( event.getBlock().getLocation(), blockdataentry.getBreakSound(), SoundCategory.BLOCKS, (blockdataentry.getVolume() + 1.0F) / 2.0F, blockdataentry.getPitch() * 0.8F ); } }
Example 3
Source File: FeatureEmulation.java From ProtocolSupport with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onEntityDamage(EntityDamageEvent event) { if (((event.getCause() == DamageCause.FIRE_TICK) || (event.getCause() == DamageCause.FIRE) || (event.getCause() == DamageCause.DROWNING))) { for (Player player : ServerPlatform.get().getMiscUtils().getNearbyPlayers(event.getEntity().getLocation(), 48, 128, 48)) { if (player != null) { Connection connection = ProtocolSupportAPI.getConnection(player); if ( (connection != null) && (connection.getVersion().getProtocolType() == ProtocolType.PC) && connection.getVersion().isBefore(ProtocolVersion.MINECRAFT_1_12) ) { connection.sendPacket(ServerPlatform.get().getPacketFactory().createEntityStatusPacket(event.getEntity(), 2)); } } } } }
Example 4
Source File: SpigotStuff.java From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") @Override public void sendPlayerSkin(Player player, SkinDataWrapper skindata) { Connection connection = ProtocolSupportAPI.getConnection(player); EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entityPlayer)); DimensionManager dimThing = null; switch (player.getWorld().getEnvironment()) { case NETHER: dimThing = DimensionManager.NETHER; break; case NORMAL: dimThing = DimensionManager.OVERWORLD; break; case THE_END: dimThing = DimensionManager.THE_END; break; } connection.sendPacket(new PacketPlayOutRespawn(dimThing, entityPlayer.world.getDifficulty(), WorldType.NORMAL, EnumGamemode.getById(player.getGameMode().getValue()))); player.setHealth(player.getHealth()); player.setMaxHealth(player.getMaxHealth()); player.setFlying(player.isFlying()); player.teleport(player.getLocation()); player.setLevel(player.getLevel()); player.setExp(player.getExp()); player.updateInventory(); connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entityPlayer)); }
Example 5
Source File: FeatureEmulation.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler public void onShift(PlayerToggleSneakEvent event) { Player player = event.getPlayer(); Connection connection = ProtocolSupportAPI.getConnection(player); if ( player.isInsideVehicle() && (connection != null) && (connection.getVersion().getProtocolType() == ProtocolType.PC) && connection.getVersion().isBeforeOrEq(ProtocolVersion.MINECRAFT_1_5_2) ) { player.leaveVehicle(); } }
Example 6
Source File: TitleAPI.java From ProtocolSupport with GNU Affero General Public License v3.0 | 4 votes |
/** * Removes and resets title, subtitle and it's params * @param player Player to which reset should be sent */ public static void removeSimpleTitle(Player player) { Connection connection = ProtocolSupportAPI.getConnection(player); connection.sendPacket(ServerPlatform.get().getPacketFactory().createTitleClearPacket()); connection.sendPacket(ServerPlatform.get().getPacketFactory().createTitleResetPacket()); }