use of com.viaversion.viaversion.api.connection.ProtocolInfo in project ViaVersion by ViaVersion.
the class BungeeMainHandProvider method setMainHand.
@Override
public void setMainHand(UserConnection user, int hand) {
ProtocolInfo info = user.getProtocolInfo();
if (info == null || info.getUuid() == null)
return;
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(info.getUuid());
if (player == null)
return;
try {
Object settings = getSettings.invoke(player);
if (settings != null) {
setMainHand.invoke(settings, hand);
}
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
use of com.viaversion.viaversion.api.connection.ProtocolInfo in project ViaVersion by ViaVersion.
the class BungeeVersionProvider method getClosestServerProtocol.
@Override
public int getClosestServerProtocol(UserConnection user) throws Exception {
if (ref == null)
return super.getClosestServerProtocol(user);
// TODO Have one constant list forever until restart? (Might limit plugins if they change this)
List<Integer> list = ReflectionUtil.getStatic(ref, "SUPPORTED_VERSION_IDS", List.class);
List<Integer> sorted = new ArrayList<>(list);
Collections.sort(sorted);
ProtocolInfo info = user.getProtocolInfo();
// Bungee supports it
if (sorted.contains(info.getProtocolVersion()))
return info.getProtocolVersion();
// Older than bungee supports, get the lowest version
if (info.getProtocolVersion() < sorted.get(0)) {
return getLowestSupportedVersion();
}
// This is more of a workaround for snapshot support by bungee.
for (Integer protocol : Lists.reverse(sorted)) {
if (info.getProtocolVersion() > protocol && ProtocolVersion.isRegistered(protocol))
return protocol;
}
Via.getPlatform().getLogger().severe("Panic, no protocol id found for " + info.getProtocolVersion());
return info.getProtocolVersion();
}
use of com.viaversion.viaversion.api.connection.ProtocolInfo in project ViaVersion by ViaVersion.
the class GlassConnectionHandler method getStates.
@Override
protected byte getStates(UserConnection user, Position position, int blockState) {
byte states = super.getStates(user, position, blockState);
if (states != 0)
return states;
ProtocolInfo protocolInfo = user.getProtocolInfo();
return protocolInfo.getServerProtocolVersion() <= 47 && protocolInfo.getServerProtocolVersion() != -1 ? 0xF : states;
}
use of com.viaversion.viaversion.api.connection.ProtocolInfo in project ViaVersion by ViaVersion.
the class BaseProtocol1_7 method registerPackets.
@Override
protected void registerPackets() {
/* Outgoing Packets */
// Status Response Packet
registerClientbound(ClientboundStatusPackets.STATUS_RESPONSE, new // Status Response Packet
PacketRemapper() {
@Override
public void registerMap() {
map(Type.STRING);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ProtocolInfo info = wrapper.user().getProtocolInfo();
String originalStatus = wrapper.get(Type.STRING, 0);
try {
JsonElement json = GsonUtil.getGson().fromJson(originalStatus, JsonElement.class);
JsonObject version;
// Unknown!
int protocolVersion = 0;
if (json.isJsonObject()) {
if (json.getAsJsonObject().has("version")) {
version = json.getAsJsonObject().get("version").getAsJsonObject();
if (version.has("protocol")) {
protocolVersion = ((Long) version.get("protocol").getAsLong()).intValue();
}
} else {
json.getAsJsonObject().add("version", version = new JsonObject());
}
} else {
// Format properly
json = new JsonObject();
json.getAsJsonObject().add("version", version = new JsonObject());
}
if (Via.getConfig().isSendSupportedVersions()) {
// Send supported versions
version.add("supportedVersions", GsonUtil.getGson().toJsonTree(Via.getAPI().getSupportedVersions()));
}
if (!Via.getAPI().getServerVersion().isKnown()) {
// Set the Server protocol if the detection on startup failed
ProtocolManagerImpl protocolManager = (ProtocolManagerImpl) Via.getManager().getProtocolManager();
protocolManager.setServerProtocol(new ServerProtocolVersionSingleton(ProtocolVersion.getProtocol(protocolVersion).getVersion()));
}
// Ensure the server has a version provider
VersionProvider versionProvider = Via.getManager().getProviders().get(VersionProvider.class);
if (versionProvider == null) {
wrapper.user().setActive(false);
return;
}
int closestServerProtocol = versionProvider.getClosestServerProtocol(wrapper.user());
List<ProtocolPathEntry> protocols = null;
if (info.getProtocolVersion() >= closestServerProtocol || Via.getPlatform().isOldClientsAllowed()) {
protocols = Via.getManager().getProtocolManager().getProtocolPath(info.getProtocolVersion(), closestServerProtocol);
}
if (protocols != null) {
if (protocolVersion == closestServerProtocol || protocolVersion == 0) {
// Fix ServerListPlus
ProtocolVersion prot = ProtocolVersion.getProtocol(info.getProtocolVersion());
version.addProperty("protocol", prot.getOriginalVersion());
}
} else {
// not compatible :(, *plays very sad violin*
wrapper.user().setActive(false);
}
if (Via.getConfig().blockedProtocolVersions().contains(info.getProtocolVersion())) {
// Show blocked versions as outdated
version.addProperty("protocol", -1);
}
// Update value
wrapper.set(Type.STRING, 0, GsonUtil.getGson().toJson(json));
} catch (JsonParseException e) {
e.printStackTrace();
}
}
});
}
});
// Login Success Packet
registerClientbound(ClientboundLoginPackets.GAME_PROFILE, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ProtocolInfo info = wrapper.user().getProtocolInfo();
info.setState(State.PLAY);
UUID uuid = passthroughLoginUUID(wrapper);
info.setUuid(uuid);
String username = wrapper.passthrough(Type.STRING);
info.setUsername(username);
// Add to ported clients
Via.getManager().getConnectionManager().onLoginSuccess(wrapper.user());
if (!info.getPipeline().hasNonBaseProtocols()) {
// Only base protocol
wrapper.user().setActive(false);
}
if (Via.getManager().isDebug()) {
// Print out the route to console
Via.getPlatform().getLogger().log(Level.INFO, "{0} logged in with protocol {1}, Route: {2}", new Object[] { username, info.getProtocolVersion(), Joiner.on(", ").join(info.getPipeline().pipes(), ", ") });
}
}
});
}
});
/* Incoming Packets */
// Login Start Packet
registerServerbound(ServerboundLoginPackets.HELLO, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(final PacketWrapper wrapper) throws Exception {
int protocol = wrapper.user().getProtocolInfo().getProtocolVersion();
if (Via.getConfig().blockedProtocolVersions().contains(protocol)) {
if (!wrapper.user().getChannel().isOpen())
return;
if (!wrapper.user().shouldApplyBlockProtocol())
return;
// Disconnect Packet
PacketWrapper disconnectPacket = PacketWrapper.create(ClientboundLoginPackets.LOGIN_DISCONNECT, wrapper.user());
Protocol1_9To1_8.FIX_JSON.write(disconnectPacket, ChatColorUtil.translateAlternateColorCodes(Via.getConfig().getBlockedDisconnectMsg()));
// cancel current
wrapper.cancel();
// Send and close
ChannelFuture future = disconnectPacket.sendFuture(BaseProtocol.class);
future.addListener(f -> wrapper.user().getChannel().close());
}
}
});
}
});
}
use of com.viaversion.viaversion.api.connection.ProtocolInfo in project ViaVersion by ViaVersion.
the class ViaIdleThread method run.
@Override
public void run() {
for (UserConnection info : Via.getManager().getConnectionManager().getConnections()) {
ProtocolInfo protocolInfo = info.getProtocolInfo();
if (protocolInfo == null || !protocolInfo.getPipeline().contains(Protocol1_9To1_8.class))
continue;
MovementTracker movementTracker = info.get(MovementTracker.class);
if (movementTracker == null)
continue;
long nextIdleUpdate = movementTracker.getNextIdlePacket();
if (nextIdleUpdate <= System.currentTimeMillis() && info.getChannel().isOpen()) {
Via.getManager().getProviders().get(MovementTransmitterProvider.class).sendPlayer(info);
}
}
}
Aggregations