use of com.viaversion.viaversion.api.protocol.version.ProtocolVersion in project Geyser by GeyserMC.
the class GeyserSpigotPlugin method isViaVersionNeeded.
/**
* This function should not run unless ViaVersion is installed on the server.
*
* @return true if there is any block mappings difference between the server and client.
*/
private boolean isViaVersionNeeded() {
ProtocolVersion serverVersion = getServerProtocolVersion();
List<ProtocolPathEntry> protocolList = Via.getManager().getProtocolManager().getProtocolPath(MinecraftProtocol.getJavaProtocolVersion(), serverVersion.getVersion());
if (protocolList == null) {
// No translation needed!
return false;
}
for (int i = protocolList.size() - 1; i >= 0; i--) {
MappingData mappingData = protocolList.get(i).getProtocol().getMappingData();
if (mappingData != null) {
return true;
}
}
// All mapping data is null, which means client and server block states are the same
return false;
}
use of com.viaversion.viaversion.api.protocol.version.ProtocolVersion in project ViaVersion by ViaVersion.
the class VelocityViaConfig method handleConfig.
@Override
protected void handleConfig(Map<String, Object> config) {
// Parse servers
Map<String, Object> servers;
if (!(config.get("velocity-servers") instanceof Map)) {
servers = new HashMap<>();
} else {
servers = (Map) config.get("velocity-servers");
}
// Convert any bad Protocol Ids
for (Map.Entry<String, Object> entry : new HashSet<>(servers.entrySet())) {
if (!(entry.getValue() instanceof Integer)) {
if (entry.getValue() instanceof String) {
ProtocolVersion found = ProtocolVersion.getClosest((String) entry.getValue());
if (found != null) {
servers.put(entry.getKey(), found.getVersion());
} else {
// Remove!
servers.remove(entry.getKey());
}
} else {
// Remove!
servers.remove(entry.getKey());
}
}
}
// Ensure default exists
if (!servers.containsKey("default")) {
// Side note: This doesn't use ProtocolRegistry as it doesn't know the protocol version at boot.
try {
servers.put("default", VelocityViaInjector.getLowestSupportedProtocolVersion());
} catch (Exception e) {
// Something went very wrong
e.printStackTrace();
}
}
// Put back
config.put("velocity-servers", servers);
}
use of com.viaversion.viaversion.api.protocol.version.ProtocolVersion in project ViaVersion by ViaVersion.
the class ProtocolInfoImpl method setProtocolVersion.
@Override
public void setProtocolVersion(int protocolVersion) {
// Map snapshot versions to the higher/orderer release version
ProtocolVersion protocol = ProtocolVersion.getProtocol(protocolVersion);
this.protocolVersion = protocol.getVersion();
}
use of com.viaversion.viaversion.api.protocol.version.ProtocolVersion in project ViaVersion by ViaVersion.
the class ProtocolInfoImpl method setServerProtocolVersion.
@Override
public void setServerProtocolVersion(int serverProtocolVersion) {
ProtocolVersion protocol = ProtocolVersion.getProtocol(serverProtocolVersion);
this.serverProtocolVersion = protocol.getVersion();
}
use of com.viaversion.viaversion.api.protocol.version.ProtocolVersion in project ViaVersion by ViaVersion.
the class ViaManagerImpl method loadServerProtocol.
private void loadServerProtocol() {
try {
ProtocolVersion serverProtocolVersion = ProtocolVersion.getProtocol(injector.getServerProtocolVersion());
ServerProtocolVersion versionInfo;
if (platform.isProxy()) {
IntSortedSet supportedVersions = injector.getServerProtocolVersions();
versionInfo = new ServerProtocolVersionRange(supportedVersions.firstInt(), supportedVersions.lastInt(), supportedVersions);
} else {
versionInfo = new ServerProtocolVersionSingleton(serverProtocolVersion.getVersion());
}
protocolManager.setServerProtocol(versionInfo);
} catch (Exception e) {
platform.getLogger().severe("ViaVersion failed to get the server protocol!");
e.printStackTrace();
}
}
Aggregations