3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

Add possibility to get the supported versions from the api and status response (#402)

* Possibility  to send the Supported versions inside the status response packet

* Make lowercase
Dieser Commit ist enthalten in:
Mats 2016-05-19 19:56:42 +02:00 committet von Myles
Ursprung 9828e4ae1d
Commit bcc994b0dd
6 geänderte Dateien mit 59 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -33,10 +33,7 @@ import us.myles.ViaVersion.util.ReflectionUtil;
import java.io.File; import java.io.File;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future; import java.util.concurrent.Future;
@ -96,6 +93,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI, ViaVe
getLogger().warning("ViaVersion will not function on the current protocol."); getLogger().warning("ViaVersion will not function on the current protocol.");
} }
} }
ProtocolRegistry.refreshVersions();
} }
}); });
@ -363,6 +361,11 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI, ViaVe
return compatSpigotBuild; return compatSpigotBuild;
} }
@Override
public SortedSet<Integer> getSupportedVersions() {
return ProtocolRegistry.getSupportedVersions();
}
public boolean isCheckForUpdates() { public boolean isCheckForUpdates() {
return getConfig().getBoolean("checkforupdates", true); return getConfig().getBoolean("checkforupdates", true);
} }
@ -447,6 +450,11 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI, ViaVe
return getConfig().getBoolean("anti-xray-patch", true); return getConfig().getBoolean("anti-xray-patch", true);
} }
@Override
public boolean isSendSupportedVersions() {
return getConfig().getBoolean("send-supported-versions", false);
}
public boolean isAutoTeam() { public boolean isAutoTeam() {
// Collision has to be enabled first // Collision has to be enabled first
return isPreventCollision() && getConfig().getBoolean("auto-team", true); return isPreventCollision() && getConfig().getBoolean("auto-team", true);

Datei anzeigen

@ -7,6 +7,7 @@ import us.myles.ViaVersion.api.boss.BossColor;
import us.myles.ViaVersion.api.boss.BossStyle; import us.myles.ViaVersion.api.boss.BossStyle;
import us.myles.ViaVersion.api.command.ViaVersionCommand; import us.myles.ViaVersion.api.command.ViaVersionCommand;
import java.util.SortedSet;
import java.util.UUID; import java.util.UUID;
public interface ViaVersionAPI { public interface ViaVersionAPI {
@ -109,4 +110,11 @@ public interface ViaVersionAPI {
* @return True if it is * @return True if it is
*/ */
boolean isCompatSpigotBuild(); boolean isCompatSpigotBuild();
/**
* Get the supported protocol versions
*
* @return a list of protocol versions
*/
SortedSet<Integer> getSupportedVersions();
} }

Datei anzeigen

@ -149,4 +149,11 @@ public interface ViaVersionConfig {
* @return A boolean * @return A boolean
*/ */
boolean isAntiXRay(); boolean isAntiXRay();
/**
* Send supported versions in the status response packet
*
* @return If true, enabled
*/
boolean isSendSupportedVersions();
} }

Datei anzeigen

@ -1,5 +1,7 @@
package us.myles.ViaVersion.api.protocol; package us.myles.ViaVersion.api.protocol;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.protocols.base.BaseProtocol; import us.myles.ViaVersion.protocols.base.BaseProtocol;
@ -10,14 +12,16 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion.protocols.protocol1_9to1_9_1.Protocol1_9TO1_9_1; import us.myles.ViaVersion.protocols.protocol1_9to1_9_1.Protocol1_9TO1_9_1;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class ProtocolRegistry { public class ProtocolRegistry {
public static final Protocol BASE_PROTOCOL = new BaseProtocol();
public static int SERVER_PROTOCOL = -1; public static int SERVER_PROTOCOL = -1;
// Input Version -> Output Version & Protocol (Allows fast lookup) // Input Version -> Output Version & Protocol (Allows fast lookup)
private static Map<Integer, Map<Integer, Protocol>> registryMap = new HashMap<>(); private static Map<Integer, Map<Integer, Protocol>> registryMap = new ConcurrentHashMap<>();
private static Map<Pair<Integer, Integer>, List<Pair<Integer, Protocol>>> pathCache = new HashMap<>(); private static Map<Pair<Integer, Integer>, List<Pair<Integer, Protocol>>> pathCache = new ConcurrentHashMap<>();
private static List<Protocol> registerList = new ArrayList<>(); private static List<Protocol> registerList = Lists.newCopyOnWriteArrayList();
public static final Protocol BASE_PROTOCOL = new BaseProtocol(); private static Set<Integer> supportedVersions = Sets.newConcurrentHashSet();
static { static {
// Base Protocol // Base Protocol
@ -29,7 +33,6 @@ public class ProtocolRegistry {
// Only supported for 1.9.4 server to 1.9 (nothing else) // Only supported for 1.9.4 server to 1.9 (nothing else)
registerProtocol(new Protocol1_9TO1_9_1(), Arrays.asList(ProtocolVersion.v1_9.getId()), ProtocolVersion.v1_9_2.getId()); registerProtocol(new Protocol1_9TO1_9_1(), Arrays.asList(ProtocolVersion.v1_9.getId()), ProtocolVersion.v1_9_2.getId());
registerProtocol(new Protocol1_9_1_2TO1_9_3(), Arrays.asList(ProtocolVersion.v1_9_1.getId(), ProtocolVersion.v1_9_2.getId()), ProtocolVersion.v1_9_3.getId()); registerProtocol(new Protocol1_9_1_2TO1_9_3(), Arrays.asList(ProtocolVersion.v1_9_1.getId(), ProtocolVersion.v1_9_2.getId()), ProtocolVersion.v1_9_3.getId());
} }
/** /**
@ -54,11 +57,29 @@ public class ProtocolRegistry {
if (Bukkit.getPluginManager().getPlugin("ViaVersion").isEnabled()) { if (Bukkit.getPluginManager().getPlugin("ViaVersion").isEnabled()) {
protocol.registerListeners(); protocol.registerListeners();
refreshVersions();
} else { } else {
registerList.add(protocol); registerList.add(protocol);
} }
} }
public static void refreshVersions() {
supportedVersions.clear();
supportedVersions.add(ProtocolRegistry.SERVER_PROTOCOL);
for (ProtocolVersion versions : ProtocolVersion.getProtocols()) {
List<Pair<Integer, Protocol>> paths = getProtocolPath(versions.getId(), ProtocolRegistry.SERVER_PROTOCOL);
if (paths == null) continue;
supportedVersions.add(versions.getId());
for (Pair<Integer, Protocol> path : paths)
supportedVersions.add(path.getKey());
}
}
public static SortedSet<Integer> getSupportedVersions() {
return Collections.unmodifiableSortedSet(new TreeSet<>(supportedVersions));
}
/** /**
* Check if this plugin is useful to the server. * Check if this plugin is useful to the server.
* *
@ -90,7 +111,7 @@ public class ProtocolRegistry {
* @return The path which has been generated, null if failed. * @return The path which has been generated, null if failed.
*/ */
private static List<Pair<Integer, Protocol>> getProtocolPath(List<Pair<Integer, Protocol>> current, int clientVersion, int serverVersion) { private static List<Pair<Integer, Protocol>> getProtocolPath(List<Pair<Integer, Protocol>> current, int clientVersion, int serverVersion) {
if(clientVersion == serverVersion) return null; // We're already there if (clientVersion == serverVersion) return null; // We're already there
if (current.size() > 50) return null; // Fail safe, protocol too complicated. if (current.size() > 50) return null; // Fail safe, protocol too complicated.
// First check if there is any protocols for this // First check if there is any protocols for this

Datei anzeigen

@ -42,6 +42,8 @@ public class BaseProtocol extends Protocol {
try { try {
JSONObject json = (JSONObject) new JSONParser().parse(originalStatus); JSONObject json = (JSONObject) new JSONParser().parse(originalStatus);
JSONObject version = (JSONObject) json.get("version"); JSONObject version = (JSONObject) json.get("version");
if (ViaVersion.getConfig().isSendSupportedVersions())
version.put("supportedVersions", ViaVersion.getInstance().getSupportedVersions());
if (ProtocolRegistry.SERVER_PROTOCOL == -1) { if (ProtocolRegistry.SERVER_PROTOCOL == -1) {
Long original = (Long) version.get("protocol"); Long original = (Long) version.get("protocol");
ProtocolRegistry.SERVER_PROTOCOL = original.intValue(); ProtocolRegistry.SERVER_PROTOCOL = original.intValue();

Datei anzeigen

@ -53,4 +53,6 @@ tracking-warning-pps: 120
tracking-max-warnings: 4 tracking-max-warnings: 4
tracking-max-kick-msg: "You are sending too many packets, :(" tracking-max-kick-msg: "You are sending too many packets, :("
# Patch the Anti xray to work on 1.9 (If your server is 1.8) This can cost more performance, so disable it if you don't use it. # Patch the Anti xray to work on 1.9 (If your server is 1.8) This can cost more performance, so disable it if you don't use it.
anti-xray-patch: true anti-xray-patch: true
# Send the supported versions with the Status response packet
send-supported-versions: false