Merge branch 'dev/1.1.0' into dev/2.0.0

# Conflicts:
#	build.gradle
This commit is contained in:
Andrew Steinborn
2020-10-28 20:33:57 -04:00
34 changed files with 650 additions and 114 deletions

View File

@@ -41,7 +41,7 @@ public enum ProtocolVersion {
MINECRAFT_1_16_1(736, "1.16.1"),
MINECRAFT_1_16_2(751, "1.16.2"),
MINECRAFT_1_16_3(753, "1.16.3"),
MINECRAFT_1_16_4(754, 2, "1.16.4");
MINECRAFT_1_16_4(754, "1.16.4");
private static final int SNAPSHOT_BIT = 30;

View File

@@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import java.util.Objects;
import java.util.regex.Pattern;
import net.kyori.minecraft.Key;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
@@ -50,6 +51,35 @@ public final class MinecraftChannelIdentifier implements ChannelIdentifier {
return new MinecraftChannelIdentifier(namespace, name);
}
/**
* Creates an channel identifier from the specified Minecraft identifier.
*
* @param identifier the Minecraft identifier
* @return a new channel identifier
*/
public static MinecraftChannelIdentifier from(String identifier) {
int colonPos = identifier.indexOf(':');
if (colonPos == -1) {
throw new IllegalArgumentException("Identifier does not contain a colon.");
}
if (colonPos + 1 == identifier.length()) {
throw new IllegalArgumentException("Identifier is empty.");
}
String namespace = identifier.substring(0, colonPos);
String name = identifier.substring(colonPos + 1);
return create(namespace, name);
}
/**
* Creates an channel identifier from the specified Minecraft identifier.
*
* @param key the Minecraft key to use
* @return a new channel identifier
*/
public static MinecraftChannelIdentifier from(Key key) {
return create(key.namespace(), key.value());
}
public String getNamespace() {
return namespace;
}
@@ -58,6 +88,10 @@ public final class MinecraftChannelIdentifier implements ChannelIdentifier {
return name;
}
public Key asKey() {
return Key.of(namespace, name);
}
@Override
public String toString() {
return namespace + ":" + name + " (modern)";

View File

@@ -104,8 +104,9 @@ public final class ServerPing {
/**
* Returns a copy of this {@link ServerPing} instance as a builder so that it can be modified.
* It is guaranteed that {@code ping.asBuilder().ping().equals(ping)}: that is, if no other
* changes are made to the returned builder, the built instance will equal the original instance.
* It is guaranteed that {@code ping.asBuilder().build().equals(ping)} is true: that is, if no
* other changes are made to the returned builder, the built instance will equal the original
* instance.
*
* @return a copy of this instance as a {@link Builder}
*/

View File

@@ -1,7 +1,9 @@
package com.velocitypowered.api.proxy.messages;
import static com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier.create;
import static com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier.from;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
@@ -26,4 +28,24 @@ class MinecraftChannelIdentifierTest {
() -> assertThrows(IllegalArgumentException.class, () -> create("minecraft", null))
);
}
@Test
void fromIdentifierIsCorrect() {
MinecraftChannelIdentifier expected = MinecraftChannelIdentifier.create("velocity", "test");
assertEquals(expected, MinecraftChannelIdentifier.from("velocity:test"));
}
@Test
void fromIdentifierThrowsOnBadValues() {
assertAll(
() -> assertThrows(IllegalArgumentException.class, () -> from("")),
() -> assertThrows(IllegalArgumentException.class, () -> from(":")),
() -> assertThrows(IllegalArgumentException.class, () -> from(":a")),
() -> assertThrows(IllegalArgumentException.class, () -> from("a:")),
() -> assertThrows(IllegalArgumentException.class, () -> from("hello:$$$$$$")),
() -> assertThrows(IllegalArgumentException.class, () -> from("hello::"))
);
}
}