protocolsupport.api.ProtocolType Java Examples

The following examples show how to use protocolsupport.api.ProtocolType. 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: 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 #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 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: 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 #5
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 #6
Source File: AbstractLoginListenerPlay.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void disconnect(final String s) {
	try {
		Bukkit.getLogger().info("Disconnecting " + getConnectionRepr() + ": " + s);
		ProtocolVersion version = connection.getVersion();
		if ((version.getProtocolType() == ProtocolType.PC) && version.isBetween(ProtocolVersion.MINECRAFT_1_7_5, ProtocolVersion.MINECRAFT_1_7_10)) {
			//first send join game that will make client actually switch to game state
			networkManager.sendPacket(ServerPlatform.get().getPacketFactory().createFakeJoinGamePacket());
			//send disconnect with a little delay
			connection.getIOExecutor().schedule(() -> disconnect0(s), 50, TimeUnit.MILLISECONDS);
		} else {
			disconnect0(s);
		}
	} catch (Throwable exception) {
		Bukkit.getLogger().log(Level.SEVERE, "Error whilst disconnecting player", exception);
		networkManager.close("Error whilst disconnecting player, force closing connection");
	}
}
 
Example #7
Source File: ProtocolVersionTests.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testGetAllBeforeE() {
	Assertions.assertArrayEquals(
		ProtocolVersion.getAllBeforeE(ProtocolVersion.MINECRAFT_1_11),
		ProtocolVersion.getAllBetween(ProtocolVersion.MINECRAFT_1_10, ProtocolVersion.getOldest(ProtocolType.PC))
	);
	Assertions.assertArrayEquals(ProtocolVersion.getAllBeforeE(ProtocolVersion.getOldest(ProtocolType.PC)), new ProtocolVersion[0]);
}
 
Example #8
Source File: PEReceiver.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onRawPacketReceiving(RawPacketEvent event) {
	if (connection.getVersion() == null) {
		return; //Keep going until version type is known.
	} else if (connection.getVersion().getProtocolType() == ProtocolType.PE) {
		decodehandle(connection, event.getData().copy()); //If version is PE, handle the packet.
	} else {
		connection.removePacketListener(this); //If version turns out not to be PE stop listening.
	}
}
 
Example #9
Source File: ProtocolVersionTests.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testGetAllBeforeI() {
	Assertions.assertArrayEquals(
		ProtocolVersion.getAllBeforeI(ProtocolVersion.MINECRAFT_1_11),
		ProtocolVersion.getAllBetween(ProtocolVersion.MINECRAFT_1_11, ProtocolVersion.getOldest(ProtocolType.PC))
	);
}
 
Example #10
Source File: ProtocolVersionTests.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testGetAllAfterE() {
	Assertions.assertArrayEquals(
		ProtocolVersion.getAllAfterE(ProtocolVersion.MINECRAFT_1_11),
		ProtocolVersion.getAllBetween(ProtocolVersion.MINECRAFT_1_11_1, ProtocolVersion.getLatest(ProtocolType.PC))
	);
	Assertions.assertArrayEquals(ProtocolVersion.getAllAfterE(ProtocolVersion.getLatest(ProtocolType.PC)), new ProtocolVersion[0]);
}
 
Example #11
Source File: ProtocolVersionTests.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testGetAllAfterI() {
	Assertions.assertArrayEquals(
		ProtocolVersion.getAllAfterI(ProtocolVersion.MINECRAFT_1_11),
		ProtocolVersion.getAllBetween(ProtocolVersion.MINECRAFT_1_11, ProtocolVersion.getLatest(ProtocolType.PC))
	);
}
 
Example #12
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 #13
Source File: MiddleCollectEffect.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void handleReadData() {
	//TODO: send needed collect packets from middle packet itself after implementing serverside entity position cache
	if (
		(collectorId == cache.getEntityCache().getSelfId()) &&
		(version.getProtocolType() == ProtocolType.PC) &&
		version.isBefore(ProtocolVersion.MINECRAFT_1_9)
	) {
		Player player = connection.getPlayer();
		NetworkEntity entity = cache.getEntityCache().getEntity(entityId);
		if ((entity != null) && (player != null)) {
			switch (entity.getType()) {
				case ITEM: {
					player.playSound(
						player.getLocation(), Sound.ENTITY_ITEM_PICKUP,
						0.2F, (((ThreadLocalRandom.current().nextFloat() - ThreadLocalRandom.current().nextFloat()) * 0.7F) + 1.0F) * 2.0F
					);
					break;
				}
				case EXP_ORB: {
					player.playSound(
						player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP,
						0.2F, (((ThreadLocalRandom.current().nextFloat() - ThreadLocalRandom.current().nextFloat()) * 0.7F) + 1.0F) * 2.0F
					);
					break;
				}
				default: {
					break;
				}
			}
		}
	}
}
 
Example #14
Source File: MerchantDataSerializer.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
protected static boolean isUsingDemand(ProtocolVersion version) {
	return (version.getProtocolType() == ProtocolType.PC) && version.isAfterOrEq(ProtocolVersion.MINECRAFT_1_14_4);
}
 
Example #15
Source File: AbstractLoginListener.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
protected static boolean hasCompression(ProtocolVersion version) {
	return (version.getProtocolType() == ProtocolType.PC) && version.isAfterOrEq(ProtocolVersion.MINECRAFT_1_8);
}
 
Example #16
Source File: AbstractLoginListener.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
protected static boolean isFullEncryption(ProtocolVersion version) {
	return (version.getProtocolType() == ProtocolType.PC) && version.isAfterOrEq(ProtocolVersion.MINECRAFT_1_7_5);
}
 
Example #17
Source File: MerchantDataSerializer.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
protected static boolean isUsingRestockingVillagerField(ProtocolVersion version) {
	return (version.getProtocolType() == ProtocolType.PC) && version.isAfterOrEq(ProtocolVersion.MINECRAFT_1_14_3);
}
 
Example #18
Source File: MerchantDataSerializer.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
protected static boolean isUsingUsesCount(ProtocolVersion version) {
	return (version.getProtocolType() == ProtocolType.PC) && version.isAfterOrEq(ProtocolVersion.MINECRAFT_1_8);
}
 
Example #19
Source File: MerchantDataSerializer.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
protected static boolean isUsingAdvancedTrading(ProtocolVersion version) {
	return (version.getProtocolType() == ProtocolType.PC) && version.isAfterOrEq(ProtocolVersion.MINECRAFT_1_14);
}
 
Example #20
Source File: StringSerializer.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
private static boolean isUsingUTF8(ProtocolVersion version) {
	return (version.getProtocolType() == ProtocolType.PC) && version.isAfterOrEq(ProtocolVersion.MINECRAFT_1_7_5);
}
 
Example #21
Source File: StringSerializer.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
private static boolean isUsingUTF16(ProtocolVersion version) {
	return (version.getProtocolType() == ProtocolType.PC) && version.isBeforeOrEq(ProtocolVersion.MINECRAFT_1_6_4);
}
 
Example #22
Source File: PSInitialHandler.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 4 votes vote down vote up
protected static boolean isFullEncryption(ProtocolVersion version) {
	return (version.getProtocolType() == ProtocolType.PC) && version.isAfterOrEq(ProtocolVersion.MINECRAFT_1_7_5);
}
 
Example #23
Source File: PSInitialHandler.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 4 votes vote down vote up
protected static boolean hasCompression(ProtocolVersion version) {
	return (version.getProtocolType() == ProtocolType.PC) && version.isAfterOrEq(ProtocolVersion.MINECRAFT_1_8);
}
 
Example #24
Source File: PocketCon.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 2 votes vote down vote up
/***
 * Checks if a connection is a pocket connection.
 * @param player
 * @return the truth.
 */
public static boolean isPocketConnection(Connection connection) {
	return connection.getVersion().getProtocolType().equals(ProtocolType.PE);
}
 
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);
}