protocolsupport.api.ProtocolSupportAPI Java Examples

The following examples show how to use protocolsupport.api.ProtocolSupportAPI. 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: WorldResourcepacks.java    From ResourcepacksPlugins with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int getPlayerProtocol(UUID playerId) {
    Player player = getServer().getPlayer(playerId);
    if (player != null) {
        int protocol = serverProtocolVersion;
        if (viaApi != null) {
            protocol = viaApi.getPlayerVersion(playerId);
        }
        if (protocolSupportApi && protocol == serverProtocolVersion) { // if still same format test if player is using previous version
            ProtocolVersion version = ProtocolSupportAPI.getProtocolVersion(player);
            if (version.getProtocolType() == ProtocolType.PC) {
                protocol = version.getId();
            }
        }
        return protocol;
    }
    return -1;
}
 
Example #2
Source File: FeatureEmulation.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@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 #3
Source File: FeatureEmulation.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@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 #4
Source File: FeatureEmulation.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
public FeatureEmulation() {
	Bukkit.getScheduler().runTaskTimer(
		ProtocolSupport.getInstance(),
		() -> {
			for (Player player : Bukkit.getOnlinePlayers()) {
				ProtocolVersion version = ProtocolSupportAPI.getProtocolVersion(player);
				if ((version.getProtocolType() == ProtocolType.PC) && version.isBefore(ProtocolVersion.MINECRAFT_1_9)) {
					if (!player.isFlying() && (player.hasPotionEffect(PotionEffectType.LEVITATION) || player.hasPotionEffect(PotionEffectType.SLOW_FALLING))) {
						player.setVelocity(player.getVelocity());
					}
				}
			}
		},
		1, 1
	);
}
 
Example #5
Source File: TitleAPI.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 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 #6
Source File: InitialPacketDecoder.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
protected static ConnectionImpl prepare(Channel channel, ProtocolVersion version) {
	channel.pipeline().remove(ChannelHandlers.INITIAL_DECODER);
	ConnectionImpl connection = ConnectionImpl.getFromChannel(channel);
	if (ServerPlatform.get().getMiscUtils().isDebugging()) {
		ProtocolSupport.logInfo(MessageFormat.format("{0} connected with protocol version {1}", connection.getAddress(), version));
	}
	connection.getNetworkManagerWrapper().setPacketListener(ServerPlatform.get().getMiscUtils().createHandshakeListener(connection.getNetworkManagerWrapper()));
	if (!ProtocolSupportAPI.isProtocolVersionEnabled(version)) {
		if (version.getProtocolType() == ProtocolType.PC) {
			version = version.isBeforeOrEq(ProtocolVersion.MINECRAFT_1_6_4) ? ProtocolVersion.MINECRAFT_LEGACY : ProtocolVersion.MINECRAFT_FUTURE;
		} else {
			throw new IllegalArgumentException(MessageFormat.format("Unable to get legacy or future version for disabled protocol version {0}", version));
		}
	}
	connection.setVersion(version);
	return connection;
}
 
Example #7
Source File: PlayerListSubCommand.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public boolean handle(CommandSender sender, String[] args) {
	boolean verbose = (args.length == 1) && (args[0].equalsIgnoreCase("v") || args[0].equalsIgnoreCase("verbose"));
	sender.sendMessage(ChatColor.YELLOW + "ProtocolSupport Players:");
	for (ProtocolVersion version : ProtocolVersion.getAllSupported()) {
		List<String> players = Bukkit.getOnlinePlayers().stream()
		.filter(player -> ProtocolSupportAPI.getProtocolVersion(player) == version)
		.map(Player::getName)
		.collect(Collectors.toList());
		if (!players.isEmpty() || verbose) {
			sender.sendMessage(ChatColor.YELLOW + "[" + version.getName() + "]: " + ChatColor.GREEN + String.join(", ", players));
		}
	}
	if (!verbose) {
		sender.sendMessage(ChatColor.YELLOW + "List all compatible versions using by adding verbose or v argument to this command");
	}
	return true;
}
 
Example #8
Source File: CommandHandler.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void execute(CommandSender sender, String[] args) {
	if ((args.length == 1) || (args.length == 2)) {
		if (args[0].equalsIgnoreCase("list")) {
			sender.sendMessage(new TextComponent(ChatColor.GREEN + "ProtocolSupport Players:"));
			for (ProtocolVersion version : ProtocolVersion.getAllSupported()) {
				List<String> players = ProxyServer.getInstance().getPlayers().stream()
				.filter(player -> ProtocolSupportAPI.getProtocolVersion(player) == version)
				.map(player -> player.getName())
				.collect(Collectors.toList());
				if (!players.isEmpty() || ((args.length == 2) && (args[1].equalsIgnoreCase("v") || args[1].equalsIgnoreCase("verbose")))) {
					sender.sendMessage(new TextComponent(ChatColor.GOLD + "[" + version.getName() + "]: " + ChatColor.GREEN + String.join(", ", players)));
				}
			}
			if ((args.length == 1) || !(args[1].equalsIgnoreCase("v") || args[1].equalsIgnoreCase("verbose"))) {
				sender.sendMessage(new TextComponent(ChatColor.GOLD + "List all compatible versions using " + ChatColor.GREEN + "/psb list verbose"));
			}
		} else if (args[0].equalsIgnoreCase("connections")) {
			for (Connection connection : ProtocolSupportAPI.getConnections()) {
				sender.sendMessage(new TextComponent(ChatColor.GREEN + connection.toString()));
			}
		}
	}
}
 
Example #9
Source File: ConnectionsListSubCommand.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public boolean handle(CommandSender sender, String[] args) {
	for (Connection connection : ProtocolSupportAPI.getConnections()) {
		sender.sendMessage(ChatColor.YELLOW + connection.toString());
	}
	return true;
}
 
Example #10
Source File: FeatureEmulation.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 #11
Source File: MultiplePassengersRestrict.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
private static boolean needsRestrict() {
	for (ProtocolVersion version : singlePassengerVersions) {
		if (ProtocolSupportAPI.isProtocolVersionEnabled(version)) {
			return true;
		}
	}
	return false;
}
 
Example #12
Source File: SpigotStuff.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 #13
Source File: ProtocolSupportVersionProvider.java    From BungeeTabListPlus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean has113OrLater(ProxiedPlayer player) {
    ProtocolVersion protocolVersion = ProtocolSupportAPI.getProtocolVersion(player);
    if (psb12) {
        return false;
    } else {
        return protocolVersion.getId() >= 393;
    }
}
 
Example #14
Source File: ProtocolSupportVersionProvider.java    From BungeeTabListPlus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean has18OrLater(ProxiedPlayer player) {
    ProtocolVersion protocolVersion = ProtocolSupportAPI.getProtocolVersion(player);
    if (psb12) {
        switch (protocolVersion) {
            case MINECRAFT_1_8:
                return true;
            default:
                return false;
        }
    } else {
        return protocolVersion.isAfterOrEq(ProtocolVersion.MINECRAFT_1_8);
    }
}
 
Example #15
Source File: ProtocolSupportVersionProvider.java    From BungeeTabListPlus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public String getVersion(ProxiedPlayer player) {
    return ProtocolSupportAPI.getProtocolVersion(player).getName();
}
 
Example #16
Source File: ProtocolSupportVersionProvider.java    From BungeeTabListPlus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean is18(ProxiedPlayer player) {
    ProtocolVersion protocolVersion = ProtocolSupportAPI.getProtocolVersion(player);
    return protocolVersion == ProtocolVersion.MINECRAFT_1_8;
}
 
Example #17
Source File: TitleAPI.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * 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());
}
 
Example #18
Source File: BridgeImpl.java    From TabooLib with MIT License 4 votes vote down vote up
@Override
public int protocolSupportPlayerVersion(Player player) {
    return ProtocolSupportAPI.getProtocolVersion(player).getId();
}
 
Example #19
Source File: ChatAPI.java    From ProtocolSupport with GNU Affero General Public License v3.0 3 votes vote down vote up
/**
 * Sends message to player<br>
 * Allows setting position of the message
 * @param player player
 * @param messageJson chat json string
 * @param position message position
 */
public static void sendMessage(Player player, String messageJson, MessagePosition position) {
	Validate.notNull(player, "Player can't be null");
	Validate.notNull(messageJson, "Message can't be null");
	Validate.notNull(position, "Message position can't be null");
	ProtocolSupportAPI.getConnection(player).sendPacket(ServerPlatform.get().getPacketFactory().createOutboundChatPacket(messageJson, position.ordinal(), player.getUniqueId()));
}
 
Example #20
Source File: PocketPlayer.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 2 votes vote down vote up
/***
 * Sends a modal with an id specified.
 * <em>Nonono, don't use custom ids!</em>
 * If you like you can use this function in combination with
 * {@link Modals.INSTANCE.takeId} to send custom JSON to the player.
 * <br/><br/>
 * <i>When sending multiple packets to pocket it is advised
 * to get the connection using {@link ProtocolSupportAPI.getConnection}
 * first and then use {@link PocketCon} to send the packets.</i>
 * @param player
 * @param modal
 * @param modalCallback
 * @return the id of the modal.
 */
public static int sendModal(Player player, Modal modal, ModalCallback modalCallback) {
	return PocketCon.sendModal(ProtocolSupportAPI.getConnection(player), modal, modalCallback);
}
 
Example #21
Source File: PocketCon.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Gets all pocket connections on the server.
 * @return all pocket connections.
 */
public static Collection<? extends Connection> getPocketConnections() {
	return ProtocolSupportAPI.getConnections().stream().filter(pocketFilter()).collect(Collectors.toList());
}
 
Example #22
Source File: PocketPlayer.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 2 votes vote down vote up
/***
 * Sends a modal to a player and gets the callback id.
 * The id can be used to track response of this modal in events.
 * <br/><br/>
 * <i>When sending multiple packets to pocket it is advised
 * to get the connection using {@link ProtocolSupportAPI.getConnection}
 * first and then use {@link PocketCon} to send the packets.</i>
 * @param player
 * @param modal
 * @return the id of the modal.
 */
public static int sendModal(Player player, Modal modal) {
	return PocketCon.sendModal(ProtocolSupportAPI.getConnection(player), modal);
}
 
Example #23
Source File: TabAPI.java    From ProtocolSupport with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Sends header and footer to player
 * @param player player
 * @param header header
 * @param footer footer
 */
public static void sendHeaderFooter(Player player, BaseComponent header, BaseComponent footer) {
	Validate.notNull(player, "Player can't be null");
	ProtocolSupportAPI.getConnection(player).sendPacket(ServerPlatform.get().getPacketFactory().createTabHeaderFooterPacket(header, footer));
}
 
Example #24
Source File: PocketPlayer.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 2 votes vote down vote up
/***
 * Sends a packet to pocket.
 * <br/><br/>
 * <i>When sending multiple packets to pocket it is advised
 * to get the connection using {@link ProtocolSupportAPI.getConnection}
 * first and then use {@link PocketCon} to send the packets.</i>
 * @param player
 * @param packet
 */
public static void sendPocketPacket(Player player, PEPacket packet) {
	PocketCon.sendPocketPacket(ProtocolSupportAPI.getConnection(player), packet);
}
 
Example #25
Source File: PocketPlayer.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 2 votes vote down vote up
/***
 * Checks if the player is a pocket player.
 * @param player
 * @return the truth.
 */
public static boolean isPocketPlayer(Player player) {
	return ProtocolSupportAPI.getProtocolVersion(player).getProtocolType().equals(ProtocolType.PE);
}
 
Example #26
Source File: PocketPlayer.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 2 votes vote down vote up
/***
 * Sends a pc-like skin to a pocket connection.
 * <br/><br/>
 * <i>When sending multiple packets to pocket it is advised
 * to get the connection using {@link ProtocolSupportAPI.getConnection}
 * first and then use {@link PocketCon} to send the packets.</i>
 * @param player
 * @param uuid
 * @param skin
 * @param isSlim
 */
public static void sendSkin(Player player, UUID uuid, byte[] skin, boolean isSlim) {
	PocketCon.sendSkin(ProtocolSupportAPI.getConnection(player), uuid, skin, isSlim);
}
 
Example #27
Source File: PocketPlayer.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 2 votes vote down vote up
/***
 * Sends a modal with an id specified.
 * Nonono, don't use custom ids!
 * If you like you can use this function in combination with
 * {@link Modals.INSTANCE.takeId} to send custom JSON to the player.
 * <br/><br/>
 * <i>When sending multiple packets to pocket it is advised
 * to get the connection using {@link ProtocolSupportAPI.getConnection}
 * first and then use {@link PocketCon} to send the packets.</i>
 * @param player
 * @param modalId
 * @param modalJSON
 * @return the id of the modal.
 */
public static int sendModal(Player player, int modalId, String modalJSON) {
	return PocketCon.sendModal(ProtocolSupportAPI.getConnection(player), modalId, modalJSON);
}
 
Example #28
Source File: PocketPlayer.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 2 votes vote down vote up
/***
 * Sends a modal with an id specified.
 * <em>Nonono, don't use custom ids!</em>
 * If you like you can use this function in combination with
 * {@link Modals.INSTANCE.takeId} to send custom JSON to the player.
 * This method also registers specified callback (if not null)
 * which is called after modal is completed and events are handled.
 * <br/><br/>
 * <i>When sending multiple packets to pocket it is advised
 * to get the connection using {@link ProtocolSupportAPI.getConnection}
 * first and then use {@link PocketCon} to send the packets.</i>
 * @param player
 * @param modalId
 * @param modalJSON
 * @param callback
 * @return the id of the modal.
 */
public static int sendModal(Player player, int modalId, String modalJSON, ModalCallback callback) {
	return PocketCon.sendModal(ProtocolSupportAPI.getConnection(player), modalId, modalJSON, callback);
}
 
Example #29
Source File: PocketPlayer.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 2 votes vote down vote up
/***
 * Gets the client's information map.
 * @param player
 * @return
 */
public static HashMap<String, Object> getClientInformationMap(Player player) {
	return PocketCon.getClientInformationMap(ProtocolSupportAPI.getConnection(player));
}
 
Example #30
Source File: PocketPlayer.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 2 votes vote down vote up
/***
 * Gets the client version
 * @param player
 * @return client version
 */
public static String getClientVersion(Player player) {
	return PocketCon.getClientVersion(ProtocolSupportAPI.getConnection(player));
}