geforkt von Mirrors/Velocity
Merge branch 'master' into registered-server
Dieser Commit ist enthalten in:
Commit
89b5da25be
1
.gitignore
vendored
1
.gitignore
vendored
@ -135,3 +135,4 @@ logs/
|
|||||||
server-icon.png
|
server-icon.png
|
||||||
/bin/
|
/bin/
|
||||||
run/
|
run/
|
||||||
|
plugins/
|
@ -10,7 +10,7 @@ import java.util.regex.Pattern;
|
|||||||
* Represents a Minecraft 1.13+ channel identifier. This class is immutable and safe for multi-threaded use.
|
* Represents a Minecraft 1.13+ channel identifier. This class is immutable and safe for multi-threaded use.
|
||||||
*/
|
*/
|
||||||
public final class MinecraftChannelIdentifier implements ChannelIdentifier {
|
public final class MinecraftChannelIdentifier implements ChannelIdentifier {
|
||||||
private static final Pattern VALID_IDENTIFIER_REGEX = Pattern.compile("[a-z0-9\\-_]+", Pattern.CASE_INSENSITIVE);
|
private static final Pattern VALID_IDENTIFIER_REGEX = Pattern.compile("[a-z0-9\\-_]+");
|
||||||
|
|
||||||
private final String namespace;
|
private final String namespace;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
@ -74,6 +74,7 @@ public class ServerPing {
|
|||||||
builder.favicon = favicon;
|
builder.favicon = favicon;
|
||||||
builder.nullOutModinfo = modinfo == null;
|
builder.nullOutModinfo = modinfo == null;
|
||||||
if (modinfo != null) {
|
if (modinfo != null) {
|
||||||
|
builder.modType = modinfo.type;
|
||||||
builder.mods.addAll(modinfo.modList);
|
builder.mods.addAll(modinfo.modList);
|
||||||
}
|
}
|
||||||
return builder;
|
return builder;
|
||||||
@ -91,6 +92,7 @@ public class ServerPing {
|
|||||||
private int onlinePlayers;
|
private int onlinePlayers;
|
||||||
private int maximumPlayers;
|
private int maximumPlayers;
|
||||||
private final List<SamplePlayer> samplePlayers = new ArrayList<>();
|
private final List<SamplePlayer> samplePlayers = new ArrayList<>();
|
||||||
|
private String modType;
|
||||||
private final List<Mod> mods = new ArrayList<>();
|
private final List<Mod> mods = new ArrayList<>();
|
||||||
private Component description;
|
private Component description;
|
||||||
private Favicon favicon;
|
private Favicon favicon;
|
||||||
@ -121,6 +123,11 @@ public class ServerPing {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder modType(String modType) {
|
||||||
|
this.modType = Preconditions.checkNotNull(modType, "modType");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Builder mods(Mod... mods) {
|
public Builder mods(Mod... mods) {
|
||||||
this.mods.addAll(Arrays.asList(mods));
|
this.mods.addAll(Arrays.asList(mods));
|
||||||
return this;
|
return this;
|
||||||
@ -158,7 +165,7 @@ public class ServerPing {
|
|||||||
|
|
||||||
public ServerPing build() {
|
public ServerPing build() {
|
||||||
return new ServerPing(version, nullOutPlayers ? null : new Players(onlinePlayers, maximumPlayers, samplePlayers), description, favicon,
|
return new ServerPing(version, nullOutPlayers ? null : new Players(onlinePlayers, maximumPlayers, samplePlayers), description, favicon,
|
||||||
nullOutModinfo ? null : new Modinfo(mods));
|
nullOutModinfo ? null : new Modinfo(modType, mods));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Version getVersion() {
|
public Version getVersion() {
|
||||||
@ -185,6 +192,10 @@ public class ServerPing {
|
|||||||
return favicon;
|
return favicon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getModType() {
|
||||||
|
return modType;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Mod> getMods() {
|
public List<Mod> getMods() {
|
||||||
return mods;
|
return mods;
|
||||||
}
|
}
|
||||||
@ -196,6 +207,7 @@ public class ServerPing {
|
|||||||
", onlinePlayers=" + onlinePlayers +
|
", onlinePlayers=" + onlinePlayers +
|
||||||
", maximumPlayers=" + maximumPlayers +
|
", maximumPlayers=" + maximumPlayers +
|
||||||
", samplePlayers=" + samplePlayers +
|
", samplePlayers=" + samplePlayers +
|
||||||
|
", modType=" + modType +
|
||||||
", mods=" + mods +
|
", mods=" + mods +
|
||||||
", description=" + description +
|
", description=" + description +
|
||||||
", favicon=" + favicon +
|
", favicon=" + favicon +
|
||||||
@ -291,12 +303,13 @@ public class ServerPing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class Modinfo {
|
public static class Modinfo {
|
||||||
public static final Modinfo DEFAULT = new Modinfo(ImmutableList.of());
|
public static final Modinfo DEFAULT = new Modinfo("FML", ImmutableList.of());
|
||||||
|
|
||||||
private final String type = "FML";
|
private final String type;
|
||||||
private final List<Mod> modList;
|
private final List<Mod> modList;
|
||||||
|
|
||||||
public Modinfo(List<Mod> modList) {
|
public Modinfo(String type, List<Mod> modList) {
|
||||||
|
this.type = Preconditions.checkNotNull(type, "type");
|
||||||
this.modList = ImmutableList.copyOf(modList);
|
this.modList = ImmutableList.copyOf(modList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import java.util.function.Supplier;
|
|||||||
|
|
||||||
public class NativeCodeLoader<T> implements Supplier<T> {
|
public class NativeCodeLoader<T> implements Supplier<T> {
|
||||||
private final List<Variant<T>> variants;
|
private final List<Variant<T>> variants;
|
||||||
private Variant<T> selected;
|
private volatile Variant<T> selected;
|
||||||
|
|
||||||
public NativeCodeLoader(List<Variant<T>> variants) {
|
public NativeCodeLoader(List<Variant<T>> variants) {
|
||||||
this.variants = ImmutableList.copyOf(variants);
|
this.variants = ImmutableList.copyOf(variants);
|
||||||
@ -16,36 +16,41 @@ public class NativeCodeLoader<T> implements Supplier<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T get() {
|
public T get() {
|
||||||
if (selected == null) {
|
return tryLoad().object;
|
||||||
selected = select();
|
|
||||||
}
|
|
||||||
return selected.object;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Variant<T> select() {
|
private Variant<T> tryLoad() {
|
||||||
for (Variant<T> variant : variants) {
|
if (selected != null) {
|
||||||
T got = variant.get();
|
return selected;
|
||||||
if (got == null) {
|
}
|
||||||
continue;
|
|
||||||
}
|
synchronized (this) {
|
||||||
return variant;
|
if (selected != null) {
|
||||||
|
return selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Variant<T> variant : variants) {
|
||||||
|
T got = variant.get();
|
||||||
|
if (got == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
selected = variant;
|
||||||
|
return selected;
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Can't find any suitable variants");
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Can't find any suitable variants");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLoadedVariant() {
|
public String getLoadedVariant() {
|
||||||
if (selected == null) {
|
return tryLoad().name;
|
||||||
selected = select();
|
|
||||||
}
|
|
||||||
return selected.name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Variant<T> {
|
static class Variant<T> {
|
||||||
private boolean available;
|
private volatile boolean available;
|
||||||
private final Runnable setup;
|
private final Runnable setup;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final T object;
|
private final T object;
|
||||||
private boolean hasBeenSetup = false;
|
private volatile boolean hasBeenSetup = false;
|
||||||
|
|
||||||
Variant(BooleanSupplier available, Runnable setup, String name, T object) {
|
Variant(BooleanSupplier available, Runnable setup, String name, T object) {
|
||||||
this.available = available.getAsBoolean();
|
this.available = available.getAsBoolean();
|
||||||
@ -54,27 +59,34 @@ public class NativeCodeLoader<T> implements Supplier<T> {
|
|||||||
this.object = object;
|
this.object = object;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setup() {
|
public T get() {
|
||||||
if (available && !hasBeenSetup) {
|
if (!available) {
|
||||||
try {
|
return null;
|
||||||
setup.run();
|
}
|
||||||
hasBeenSetup = true;
|
|
||||||
} catch (Exception e) {
|
// Make sure setup happens only once
|
||||||
available = false;
|
if (!hasBeenSetup) {
|
||||||
|
synchronized (this) {
|
||||||
|
// We change availability if need be below, may as well check it again here for sanity.
|
||||||
|
if (!available) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Okay, now try the setup if we haven't done so yet.
|
||||||
|
if (!hasBeenSetup) {
|
||||||
|
try {
|
||||||
|
setup.run();
|
||||||
|
hasBeenSetup = true;
|
||||||
|
return object;
|
||||||
|
} catch (Exception e) {
|
||||||
|
available = false;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public T get() {
|
return object;
|
||||||
if (!hasBeenSetup) {
|
|
||||||
setup();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (available) {
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ public enum StateRegistry {
|
|||||||
},
|
},
|
||||||
STATUS {
|
STATUS {
|
||||||
{
|
{
|
||||||
SERVERBOUND.register(StatusRequest.class, StatusRequest::new,
|
SERVERBOUND.register(StatusRequest.class, () -> StatusRequest.INSTANCE,
|
||||||
genericMappings(0x00));
|
genericMappings(0x00));
|
||||||
SERVERBOUND.register(StatusPing.class, StatusPing::new,
|
SERVERBOUND.register(StatusPing.class, StatusPing::new,
|
||||||
genericMappings(0x01));
|
genericMappings(0x01));
|
||||||
|
@ -5,6 +5,12 @@ import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
public class StatusRequest implements MinecraftPacket {
|
public class StatusRequest implements MinecraftPacket {
|
||||||
|
public static final StatusRequest INSTANCE = new StatusRequest();
|
||||||
|
|
||||||
|
private StatusRequest() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||||
|
|
||||||
@ -14,4 +20,9 @@ public class StatusRequest implements MinecraftPacket {
|
|||||||
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "StatusRequest";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren