mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-26 20:16:02 +01:00
Merge pull request #279 from HugoDaBosss/apiv2
Update BossBar API to use protocol version and add protocol version check by uuid API method
This commit is contained in:
commit
6197138380
@ -233,6 +233,13 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI, ViaVe
|
|||||||
return portedPlayers.get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion();
|
return portedPlayers.get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPlayerVersion(@NonNull UUID uuid) {
|
||||||
|
if (!isPorted(uuid))
|
||||||
|
return ProtocolRegistry.SERVER_PROTOCOL;
|
||||||
|
return portedPlayers.get(uuid).get(ProtocolInfo.class).getProtocolVersion();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPorted(UUID playerUUID) {
|
public boolean isPorted(UUID playerUUID) {
|
||||||
return portedPlayers.containsKey(playerUUID);
|
return portedPlayers.containsKey(playerUUID);
|
||||||
@ -257,7 +264,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI, ViaVe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException {
|
public void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException {
|
||||||
if (!isPorted(uuid)) throw new IllegalArgumentException("This player is not on 1.9");
|
if (!isPorted(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
||||||
UserConnection ci = portedPlayers.get(uuid);
|
UserConnection ci = portedPlayers.get(uuid);
|
||||||
ci.sendRawPacket(packet);
|
ci.sendRawPacket(packet);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,14 @@ public interface ViaVersionAPI {
|
|||||||
*/
|
*/
|
||||||
int getPlayerVersion(Player player);
|
int getPlayerVersion(Player player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get protocol number from a player
|
||||||
|
*
|
||||||
|
* @param uuid UUID of a player
|
||||||
|
* @return Protocol ID, For example (47=1.8-1.8.8, 107=1.9, 108=1.9.1)
|
||||||
|
*/
|
||||||
|
int getPlayerVersion(UUID uuid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is player using 1.9?
|
* Is player using 1.9?
|
||||||
*
|
*
|
||||||
|
@ -11,6 +11,7 @@ import us.myles.ViaVersion.api.boss.BossBar;
|
|||||||
import us.myles.ViaVersion.api.boss.BossColor;
|
import us.myles.ViaVersion.api.boss.BossColor;
|
||||||
import us.myles.ViaVersion.api.boss.BossFlag;
|
import us.myles.ViaVersion.api.boss.BossFlag;
|
||||||
import us.myles.ViaVersion.api.boss.BossStyle;
|
import us.myles.ViaVersion.api.boss.BossStyle;
|
||||||
|
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||||
|
|
||||||
@ -143,7 +144,7 @@ public class ViaBossBar implements BossBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendPacket(UUID uuid, ByteBuf buf) {
|
private void sendPacket(UUID uuid, ByteBuf buf) {
|
||||||
if (!ViaVersion.getInstance().isPorted(uuid)) {
|
if (!ViaVersion.getInstance().isPorted(uuid) || !(ViaVersion.getInstance().getPlayerVersion(uuid) >= ProtocolVersion.V1_9)) {
|
||||||
players.remove(uuid);
|
players.remove(uuid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user