Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-06 00:00:47 +01:00
Ursprung
53aa92db92
Commit
25b5e00125
@ -2,9 +2,11 @@ plugins {
|
|||||||
id 'java'
|
id 'java'
|
||||||
id 'com.github.johnrengelman.shadow' version '2.0.4'
|
id 'com.github.johnrengelman.shadow' version '2.0.4'
|
||||||
id 'maven-publish'
|
id 'maven-publish'
|
||||||
|
id 'checkstyle'
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: '../gradle/checkerframework.gradle'
|
apply from: '../gradle/checkerframework.gradle'
|
||||||
|
apply from: '../gradle/checkstyle.gradle'
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
ap {
|
ap {
|
||||||
|
@ -3,7 +3,11 @@ package com.velocitypowered.api.plugin.ap;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.velocitypowered.api.plugin.Plugin;
|
import com.velocitypowered.api.plugin.Plugin;
|
||||||
import com.velocitypowered.api.plugin.PluginDescription;
|
import com.velocitypowered.api.plugin.PluginDescription;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
import javax.annotation.processing.AbstractProcessor;
|
import javax.annotation.processing.AbstractProcessor;
|
||||||
import javax.annotation.processing.ProcessingEnvironment;
|
import javax.annotation.processing.ProcessingEnvironment;
|
||||||
import javax.annotation.processing.RoundEnvironment;
|
import javax.annotation.processing.RoundEnvironment;
|
||||||
@ -16,14 +20,10 @@ import javax.lang.model.element.TypeElement;
|
|||||||
import javax.tools.Diagnostic;
|
import javax.tools.Diagnostic;
|
||||||
import javax.tools.FileObject;
|
import javax.tools.FileObject;
|
||||||
import javax.tools.StandardLocation;
|
import javax.tools.StandardLocation;
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@SupportedAnnotationTypes({"com.velocitypowered.api.plugin.Plugin"})
|
@SupportedAnnotationTypes({"com.velocitypowered.api.plugin.Plugin"})
|
||||||
public class PluginAnnotationProcessor extends AbstractProcessor {
|
public class PluginAnnotationProcessor extends AbstractProcessor {
|
||||||
|
|
||||||
private ProcessingEnvironment environment;
|
private ProcessingEnvironment environment;
|
||||||
private String pluginClassFound;
|
private String pluginClassFound;
|
||||||
private boolean warnedAboutMultiplePlugins;
|
private boolean warnedAboutMultiplePlugins;
|
||||||
@ -46,7 +46,8 @@ public class PluginAnnotationProcessor extends AbstractProcessor {
|
|||||||
|
|
||||||
for (Element element : roundEnv.getElementsAnnotatedWith(Plugin.class)) {
|
for (Element element : roundEnv.getElementsAnnotatedWith(Plugin.class)) {
|
||||||
if (element.getKind() != ElementKind.CLASS) {
|
if (element.getKind() != ElementKind.CLASS) {
|
||||||
environment.getMessager().printMessage(Diagnostic.Kind.ERROR, "Only classes can be annotated with "
|
environment.getMessager()
|
||||||
|
.printMessage(Diagnostic.Kind.ERROR, "Only classes can be annotated with "
|
||||||
+ Plugin.class.getCanonicalName());
|
+ Plugin.class.getCanonicalName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -55,8 +56,10 @@ public class PluginAnnotationProcessor extends AbstractProcessor {
|
|||||||
|
|
||||||
if (Objects.equals(pluginClassFound, qualifiedName.toString())) {
|
if (Objects.equals(pluginClassFound, qualifiedName.toString())) {
|
||||||
if (!warnedAboutMultiplePlugins) {
|
if (!warnedAboutMultiplePlugins) {
|
||||||
environment.getMessager().printMessage(Diagnostic.Kind.WARNING, "Velocity does not yet currently support " +
|
environment.getMessager()
|
||||||
"multiple plugins. We are using " + pluginClassFound + " for your plugin's main class.");
|
.printMessage(Diagnostic.Kind.WARNING, "Velocity does not yet currently support " +
|
||||||
|
"multiple plugins. We are using " + pluginClassFound
|
||||||
|
+ " for your plugin's main class.");
|
||||||
warnedAboutMultiplePlugins = true;
|
warnedAboutMultiplePlugins = true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -65,21 +68,25 @@ public class PluginAnnotationProcessor extends AbstractProcessor {
|
|||||||
Plugin plugin = element.getAnnotation(Plugin.class);
|
Plugin plugin = element.getAnnotation(Plugin.class);
|
||||||
if (!PluginDescription.ID_PATTERN.matcher(plugin.id()).matches()) {
|
if (!PluginDescription.ID_PATTERN.matcher(plugin.id()).matches()) {
|
||||||
environment.getMessager().printMessage(Diagnostic.Kind.ERROR, "Invalid ID for plugin "
|
environment.getMessager().printMessage(Diagnostic.Kind.ERROR, "Invalid ID for plugin "
|
||||||
+ qualifiedName + ". IDs must start alphabetically, have alphanumeric characters, and can " +
|
+ qualifiedName
|
||||||
|
+ ". IDs must start alphabetically, have alphanumeric characters, and can " +
|
||||||
"contain dashes or underscores.");
|
"contain dashes or underscores.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// All good, generate the velocity-plugin.json.
|
// All good, generate the velocity-plugin.json.
|
||||||
SerializedPluginDescription description = SerializedPluginDescription.from(plugin, qualifiedName.toString());
|
SerializedPluginDescription description = SerializedPluginDescription
|
||||||
|
.from(plugin, qualifiedName.toString());
|
||||||
try {
|
try {
|
||||||
FileObject object = environment.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "velocity-plugin.json");
|
FileObject object = environment.getFiler()
|
||||||
|
.createResource(StandardLocation.CLASS_OUTPUT, "", "velocity-plugin.json");
|
||||||
try (Writer writer = new BufferedWriter(object.openWriter())) {
|
try (Writer writer = new BufferedWriter(object.openWriter())) {
|
||||||
new Gson().toJson(description, writer);
|
new Gson().toJson(description, writer);
|
||||||
}
|
}
|
||||||
pluginClassFound = qualifiedName.toString();
|
pluginClassFound = qualifiedName.toString();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
environment.getMessager().printMessage(Diagnostic.Kind.ERROR, "Unable to generate plugin file");
|
environment.getMessager()
|
||||||
|
.printMessage(Diagnostic.Kind.ERROR, "Unable to generate plugin file");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,15 +4,15 @@ import com.google.common.base.Preconditions;
|
|||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.velocitypowered.api.plugin.Plugin;
|
import com.velocitypowered.api.plugin.Plugin;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class SerializedPluginDescription {
|
public class SerializedPluginDescription {
|
||||||
|
|
||||||
// @Nullable is used here to make GSON skip these in the serialized file
|
// @Nullable is used here to make GSON skip these in the serialized file
|
||||||
private final String id;
|
private final String id;
|
||||||
private final @Nullable String name;
|
private final @Nullable String name;
|
||||||
@ -23,7 +23,8 @@ public class SerializedPluginDescription {
|
|||||||
private final @Nullable List<Dependency> dependencies;
|
private final @Nullable List<Dependency> dependencies;
|
||||||
private final String main;
|
private final String main;
|
||||||
|
|
||||||
public SerializedPluginDescription(String id, String name, String version, String description, String url,
|
public SerializedPluginDescription(String id, String name, String version, String description,
|
||||||
|
String url,
|
||||||
List<String> authors, List<Dependency> dependencies, String main) {
|
List<String> authors, List<Dependency> dependencies, String main) {
|
||||||
this.id = Preconditions.checkNotNull(id, "id");
|
this.id = Preconditions.checkNotNull(id, "id");
|
||||||
this.name = Strings.emptyToNull(name);
|
this.name = Strings.emptyToNull(name);
|
||||||
@ -31,7 +32,8 @@ public class SerializedPluginDescription {
|
|||||||
this.description = Strings.emptyToNull(description);
|
this.description = Strings.emptyToNull(description);
|
||||||
this.url = Strings.emptyToNull(url);
|
this.url = Strings.emptyToNull(url);
|
||||||
this.authors = authors == null || authors.isEmpty() ? ImmutableList.of() : authors;
|
this.authors = authors == null || authors.isEmpty() ? ImmutableList.of() : authors;
|
||||||
this.dependencies = dependencies == null || dependencies.isEmpty() ? ImmutableList.of() : dependencies;
|
this.dependencies =
|
||||||
|
dependencies == null || dependencies.isEmpty() ? ImmutableList.of() : dependencies;
|
||||||
this.main = Preconditions.checkNotNull(main, "main");
|
this.main = Preconditions.checkNotNull(main, "main");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,8 +42,10 @@ public class SerializedPluginDescription {
|
|||||||
for (com.velocitypowered.api.plugin.Dependency dependency : plugin.dependencies()) {
|
for (com.velocitypowered.api.plugin.Dependency dependency : plugin.dependencies()) {
|
||||||
dependencies.add(new Dependency(dependency.id(), dependency.optional()));
|
dependencies.add(new Dependency(dependency.id(), dependency.optional()));
|
||||||
}
|
}
|
||||||
return new SerializedPluginDescription(plugin.id(), plugin.name(), plugin.version(), plugin.description(), plugin.url(),
|
return new SerializedPluginDescription(plugin.id(), plugin.name(), plugin.version(),
|
||||||
Arrays.stream(plugin.authors()).filter(author -> !author.isEmpty()).collect(Collectors.toList()), dependencies, qualifiedName);
|
plugin.description(), plugin.url(),
|
||||||
|
Arrays.stream(plugin.authors()).filter(author -> !author.isEmpty())
|
||||||
|
.collect(Collectors.toList()), dependencies, qualifiedName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
@ -78,8 +82,12 @@ public class SerializedPluginDescription {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
SerializedPluginDescription that = (SerializedPluginDescription) o;
|
SerializedPluginDescription that = (SerializedPluginDescription) o;
|
||||||
return Objects.equals(id, that.id) &&
|
return Objects.equals(id, that.id) &&
|
||||||
Objects.equals(name, that.name) &&
|
Objects.equals(name, that.name) &&
|
||||||
@ -111,6 +119,7 @@ public class SerializedPluginDescription {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class Dependency {
|
public static class Dependency {
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
private final boolean optional;
|
private final boolean optional;
|
||||||
|
|
||||||
@ -129,8 +138,12 @@ public class SerializedPluginDescription {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Dependency that = (Dependency) o;
|
Dependency that = (Dependency) o;
|
||||||
return optional == that.optional &&
|
return optional == that.optional &&
|
||||||
Objects.equals(id, that.id);
|
Objects.equals(id, that.id);
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
package com.velocitypowered.api.command;
|
package com.velocitypowered.api.command;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import java.util.List;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a command that can be executed by a {@link CommandSource}, such as a {@link com.velocitypowered.api.proxy.Player}
|
* Represents a command that can be executed by a {@link CommandSource}, such as a {@link
|
||||||
* or the console.
|
* com.velocitypowered.api.proxy.Player} or the console.
|
||||||
*/
|
*/
|
||||||
public interface Command {
|
public interface Command {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the command for the specified {@link CommandSource}.
|
* Executes the command for the specified {@link CommandSource}.
|
||||||
|
*
|
||||||
* @param source the source of this command
|
* @param source the source of this command
|
||||||
* @param args the arguments for this command
|
* @param args the arguments for this command
|
||||||
*/
|
*/
|
||||||
@ -19,6 +20,7 @@ public interface Command {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides tab complete suggestions for a command for a specified {@link CommandSource}.
|
* Provides tab complete suggestions for a command for a specified {@link CommandSource}.
|
||||||
|
*
|
||||||
* @param source the source to run the command for
|
* @param source the source to run the command for
|
||||||
* @param currentArgs the current, partial arguments for this command
|
* @param currentArgs the current, partial arguments for this command
|
||||||
* @return tab complete suggestions
|
* @return tab complete suggestions
|
||||||
@ -28,8 +30,8 @@ public interface Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests to check if the {@code source} has permission to use this command
|
* Tests to check if the {@code source} has permission to use this command with the provided
|
||||||
* with the provided {@code args}.
|
* {@code args}.
|
||||||
*
|
*
|
||||||
* <p>If this method returns false, the handling will be forwarded onto
|
* <p>If this method returns false, the handling will be forwarded onto
|
||||||
* the players current server.</p>
|
* the players current server.</p>
|
||||||
|
@ -4,8 +4,10 @@ package com.velocitypowered.api.command;
|
|||||||
* Represents an interface to register a command executor with the proxy.
|
* Represents an interface to register a command executor with the proxy.
|
||||||
*/
|
*/
|
||||||
public interface CommandManager {
|
public interface CommandManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers the specified command with the manager with the specified aliases.
|
* Registers the specified command with the manager with the specified aliases.
|
||||||
|
*
|
||||||
* @param command the command to register
|
* @param command the command to register
|
||||||
* @param aliases the alias to use
|
* @param aliases the alias to use
|
||||||
*/
|
*/
|
||||||
@ -13,12 +15,14 @@ public interface CommandManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters a command.
|
* Unregisters a command.
|
||||||
|
*
|
||||||
* @param alias the command alias to unregister
|
* @param alias the command alias to unregister
|
||||||
*/
|
*/
|
||||||
void unregister(String alias);
|
void unregister(String alias);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to execute a command from the specified {@code cmdLine}.
|
* Attempts to execute a command from the specified {@code cmdLine}.
|
||||||
|
*
|
||||||
* @param source the command's source
|
* @param source the command's source
|
||||||
* @param cmdLine the command to run
|
* @param cmdLine the command to run
|
||||||
* @return true if the command was found and executed, false if it was not
|
* @return true if the command was found and executed, false if it was not
|
||||||
|
@ -7,8 +7,10 @@ import net.kyori.text.Component;
|
|||||||
* Represents something that can be used to run a {@link Command}.
|
* Represents something that can be used to run a {@link Command}.
|
||||||
*/
|
*/
|
||||||
public interface CommandSource extends PermissionSubject {
|
public interface CommandSource extends PermissionSubject {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the specified {@code component} to the invoker.
|
* Sends the specified {@code component} to the invoker.
|
||||||
|
*
|
||||||
* @param component the text component to send
|
* @param component the text component to send
|
||||||
*/
|
*/
|
||||||
void sendMessage(Component component);
|
void sendMessage(Component component);
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package com.velocitypowered.api.event;
|
package com.velocitypowered.api.event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an interface to perform direct dispatch of an event. This makes integration easier to achieve with platforms
|
* Represents an interface to perform direct dispatch of an event. This makes integration easier to
|
||||||
* such as RxJava.
|
* achieve with platforms such as RxJava.
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface EventHandler<E> {
|
public interface EventHandler<E> {
|
||||||
|
|
||||||
void execute(E event);
|
void execute(E event);
|
||||||
}
|
}
|
||||||
|
@ -6,15 +6,20 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
* Allows plugins to register and deregister listeners for event handlers.
|
* Allows plugins to register and deregister listeners for event handlers.
|
||||||
*/
|
*/
|
||||||
public interface EventManager {
|
public interface EventManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests that the specified {@code listener} listen for events and associate it with the {@code plugin}.
|
* Requests that the specified {@code listener} listen for events and associate it with the {@code
|
||||||
|
* plugin}.
|
||||||
|
*
|
||||||
* @param plugin the plugin to associate with the listener
|
* @param plugin the plugin to associate with the listener
|
||||||
* @param listener the listener to register
|
* @param listener the listener to register
|
||||||
*/
|
*/
|
||||||
void register(Object plugin, Object listener);
|
void register(Object plugin, Object listener);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests that the specified {@code handler} listen for events and associate it with the {@code plugin}.
|
* Requests that the specified {@code handler} listen for events and associate it with the {@code
|
||||||
|
* plugin}.
|
||||||
|
*
|
||||||
* @param plugin the plugin to associate with the handler
|
* @param plugin the plugin to associate with the handler
|
||||||
* @param eventClass the class for the event handler to register
|
* @param eventClass the class for the event handler to register
|
||||||
* @param handler the handler to register
|
* @param handler the handler to register
|
||||||
@ -25,18 +30,23 @@ public interface EventManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests that the specified {@code handler} listen for events and associate it with the {@code plugin}.
|
* Requests that the specified {@code handler} listen for events and associate it with the {@code
|
||||||
|
* plugin}.
|
||||||
|
*
|
||||||
* @param plugin the plugin to associate with the handler
|
* @param plugin the plugin to associate with the handler
|
||||||
* @param eventClass the class for the event handler to register
|
* @param eventClass the class for the event handler to register
|
||||||
* @param postOrder the order in which events should be posted to the handler
|
* @param postOrder the order in which events should be posted to the handler
|
||||||
* @param handler the handler to register
|
* @param handler the handler to register
|
||||||
* @param <E> the event type to handle
|
* @param <E> the event type to handle
|
||||||
*/
|
*/
|
||||||
<E> void register(Object plugin, Class<E> eventClass, PostOrder postOrder, EventHandler<E> handler);
|
<E> void register(Object plugin, Class<E> eventClass, PostOrder postOrder,
|
||||||
|
EventHandler<E> handler);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fires the specified event to the event bus asynchronously. This allows Velocity to continue servicing connections
|
* Fires the specified event to the event bus asynchronously. This allows Velocity to continue
|
||||||
* while a plugin handles a potentially long-running operation such as a database query.
|
* servicing connections while a plugin handles a potentially long-running operation such as a
|
||||||
|
* database query.
|
||||||
|
*
|
||||||
* @param event the event to fire
|
* @param event the event to fire
|
||||||
* @return a {@link CompletableFuture} representing the posted event
|
* @return a {@link CompletableFuture} representing the posted event
|
||||||
*/
|
*/
|
||||||
@ -44,6 +54,7 @@ public interface EventManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Posts the specified event to the event bus and discards the result.
|
* Posts the specified event to the event bus and discards the result.
|
||||||
|
*
|
||||||
* @param event the event to fire
|
* @param event the event to fire
|
||||||
*/
|
*/
|
||||||
default void fireAndForget(Object event) {
|
default void fireAndForget(Object event) {
|
||||||
@ -52,12 +63,14 @@ public interface EventManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters all listeners for the specified {@code plugin}.
|
* Unregisters all listeners for the specified {@code plugin}.
|
||||||
|
*
|
||||||
* @param plugin the plugin to deregister listeners for
|
* @param plugin the plugin to deregister listeners for
|
||||||
*/
|
*/
|
||||||
void unregisterListeners(Object plugin);
|
void unregisterListeners(Object plugin);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters a specific listener for a specific plugin.
|
* Unregisters a specific listener for a specific plugin.
|
||||||
|
*
|
||||||
* @param plugin the plugin associated with the listener
|
* @param plugin the plugin associated with the listener
|
||||||
* @param listener the listener to deregister
|
* @param listener the listener to deregister
|
||||||
*/
|
*/
|
||||||
@ -65,6 +78,7 @@ public interface EventManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters a specific event handler for a specific plugin.
|
* Unregisters a specific event handler for a specific plugin.
|
||||||
|
*
|
||||||
* @param plugin the plugin to associate with the handler
|
* @param plugin the plugin to associate with the handler
|
||||||
* @param handler the handler to register
|
* @param handler the handler to register
|
||||||
* @param <E> the event type to handle
|
* @param <E> the event type to handle
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package com.velocitypowered.api.event;
|
package com.velocitypowered.api.event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the order an event will be posted to a listener method, relative
|
* Represents the order an event will be posted to a listener method, relative to other listeners.
|
||||||
* to other listeners.
|
|
||||||
*/
|
*/
|
||||||
public enum PostOrder {
|
public enum PostOrder {
|
||||||
|
|
||||||
|
@ -1,25 +1,26 @@
|
|||||||
package com.velocitypowered.api.event;
|
package com.velocitypowered.api.event;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
import java.util.Optional;
|
||||||
import net.kyori.text.Component;
|
import net.kyori.text.Component;
|
||||||
import net.kyori.text.serializer.ComponentSerializers;
|
import net.kyori.text.serializer.ComponentSerializers;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates an event that has a result attached to it.
|
* Indicates an event that has a result attached to it.
|
||||||
*/
|
*/
|
||||||
public interface ResultedEvent<R extends ResultedEvent.Result> {
|
public interface ResultedEvent<R extends ResultedEvent.Result> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the result associated with this event.
|
* Returns the result associated with this event.
|
||||||
|
*
|
||||||
* @return the result of this event
|
* @return the result of this event
|
||||||
*/
|
*/
|
||||||
R getResult();
|
R getResult();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the result of this event. The result must be non-null.
|
* Sets the result of this event. The result must be non-null.
|
||||||
|
*
|
||||||
* @param result the new result
|
* @param result the new result
|
||||||
*/
|
*/
|
||||||
void setResult(R result);
|
void setResult(R result);
|
||||||
@ -28,9 +29,11 @@ public interface ResultedEvent<R extends ResultedEvent.Result> {
|
|||||||
* Represents a result for an event.
|
* Represents a result for an event.
|
||||||
*/
|
*/
|
||||||
interface Result {
|
interface Result {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether or not the event is allowed to proceed. Plugins may choose to skip denied events, and the
|
* Returns whether or not the event is allowed to proceed. Plugins may choose to skip denied
|
||||||
* proxy will respect the result of this method.
|
* events, and the proxy will respect the result of this method.
|
||||||
|
*
|
||||||
* @return whether or not the event is allowed to proceed
|
* @return whether or not the event is allowed to proceed
|
||||||
*/
|
*/
|
||||||
boolean isAllowed();
|
boolean isAllowed();
|
||||||
@ -40,6 +43,7 @@ public interface ResultedEvent<R extends ResultedEvent.Result> {
|
|||||||
* A generic "allowed/denied" result.
|
* A generic "allowed/denied" result.
|
||||||
*/
|
*/
|
||||||
final class GenericResult implements Result {
|
final class GenericResult implements Result {
|
||||||
|
|
||||||
private static final GenericResult ALLOWED = new GenericResult(true);
|
private static final GenericResult ALLOWED = new GenericResult(true);
|
||||||
private static final GenericResult DENIED = new GenericResult(false);
|
private static final GenericResult DENIED = new GenericResult(false);
|
||||||
|
|
||||||
@ -72,6 +76,7 @@ public interface ResultedEvent<R extends ResultedEvent.Result> {
|
|||||||
* Represents an "allowed/denied" result with a reason allowed for denial.
|
* Represents an "allowed/denied" result with a reason allowed for denial.
|
||||||
*/
|
*/
|
||||||
final class ComponentResult implements Result {
|
final class ComponentResult implements Result {
|
||||||
|
|
||||||
private static final ComponentResult ALLOWED = new ComponentResult(true, null);
|
private static final ComponentResult ALLOWED = new ComponentResult(true, null);
|
||||||
|
|
||||||
private final boolean status;
|
private final boolean status;
|
||||||
|
@ -7,6 +7,7 @@ import com.velocitypowered.api.proxy.InboundConnection;
|
|||||||
* This event is fired when a handshake is established between a client and Velocity.
|
* This event is fired when a handshake is established between a client and Velocity.
|
||||||
*/
|
*/
|
||||||
public final class ConnectionHandshakeEvent {
|
public final class ConnectionHandshakeEvent {
|
||||||
|
|
||||||
private final InboundConnection connection;
|
private final InboundConnection connection;
|
||||||
|
|
||||||
public ConnectionHandshakeEvent(InboundConnection connection) {
|
public ConnectionHandshakeEvent(InboundConnection connection) {
|
||||||
|
@ -4,10 +4,11 @@ import com.google.common.base.Preconditions;
|
|||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This event is fired when a player disconnects from the proxy. Operations on the provided player, aside from basic
|
* This event is fired when a player disconnects from the proxy. Operations on the provided player,
|
||||||
* data retrieval operations, may behave in undefined ways.
|
* aside from basic data retrieval operations, may behave in undefined ways.
|
||||||
*/
|
*/
|
||||||
public final class DisconnectEvent {
|
public final class DisconnectEvent {
|
||||||
|
|
||||||
private final Player player;
|
private final Player player;
|
||||||
|
|
||||||
public DisconnectEvent(Player player) {
|
public DisconnectEvent(Player player) {
|
||||||
|
@ -5,9 +5,11 @@ import com.velocitypowered.api.event.ResultedEvent;
|
|||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This event is fired once the player has been authenticated but before they connect to a server on the proxy.
|
* This event is fired once the player has been authenticated but before they connect to a server on
|
||||||
|
* the proxy.
|
||||||
*/
|
*/
|
||||||
public final class LoginEvent implements ResultedEvent<ResultedEvent.ComponentResult> {
|
public final class LoginEvent implements ResultedEvent<ResultedEvent.ComponentResult> {
|
||||||
|
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private ComponentResult result;
|
private ComponentResult result;
|
||||||
|
|
||||||
|
@ -7,22 +7,22 @@ import com.velocitypowered.api.event.ResultedEvent;
|
|||||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||||
import com.velocitypowered.api.proxy.messages.ChannelMessageSink;
|
import com.velocitypowered.api.proxy.messages.ChannelMessageSink;
|
||||||
import com.velocitypowered.api.proxy.messages.ChannelMessageSource;
|
import com.velocitypowered.api.proxy.messages.ChannelMessageSource;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This event is fired when a plugin message is sent to the proxy, either from a client ({@link com.velocitypowered.api.proxy.Player})
|
* This event is fired when a plugin message is sent to the proxy, either from a client ({@link
|
||||||
* or a server ({@link com.velocitypowered.api.proxy.ServerConnection}).
|
* com.velocitypowered.api.proxy.Player}) or a server ({@link com.velocitypowered.api.proxy.ServerConnection}).
|
||||||
*/
|
*/
|
||||||
public final class PluginMessageEvent implements ResultedEvent<PluginMessageEvent.ForwardResult> {
|
public final class PluginMessageEvent implements ResultedEvent<PluginMessageEvent.ForwardResult> {
|
||||||
|
|
||||||
private final ChannelMessageSource source;
|
private final ChannelMessageSource source;
|
||||||
private final ChannelMessageSink target;
|
private final ChannelMessageSink target;
|
||||||
private final ChannelIdentifier identifier;
|
private final ChannelIdentifier identifier;
|
||||||
private final byte[] data;
|
private final byte[] data;
|
||||||
private ForwardResult result;
|
private ForwardResult result;
|
||||||
|
|
||||||
public PluginMessageEvent(ChannelMessageSource source, ChannelMessageSink target, ChannelIdentifier identifier, byte[] data) {
|
public PluginMessageEvent(ChannelMessageSource source, ChannelMessageSink target,
|
||||||
|
ChannelIdentifier identifier, byte[] data) {
|
||||||
this.source = Preconditions.checkNotNull(source, "source");
|
this.source = Preconditions.checkNotNull(source, "source");
|
||||||
this.target = Preconditions.checkNotNull(target, "target");
|
this.target = Preconditions.checkNotNull(target, "target");
|
||||||
this.identifier = Preconditions.checkNotNull(identifier, "identifier");
|
this.identifier = Preconditions.checkNotNull(identifier, "identifier");
|
||||||
@ -75,6 +75,7 @@ public final class PluginMessageEvent implements ResultedEvent<PluginMessageEven
|
|||||||
* A result determining whether or not to forward this message on.
|
* A result determining whether or not to forward this message on.
|
||||||
*/
|
*/
|
||||||
public static final class ForwardResult implements ResultedEvent.Result {
|
public static final class ForwardResult implements ResultedEvent.Result {
|
||||||
|
|
||||||
private static final ForwardResult ALLOWED = new ForwardResult(true);
|
private static final ForwardResult ALLOWED = new ForwardResult(true);
|
||||||
private static final ForwardResult DENIED = new ForwardResult(false);
|
private static final ForwardResult DENIED = new ForwardResult(false);
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@ import com.google.common.base.Preconditions;
|
|||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This event is fired once the player has been successfully authenticated and
|
* This event is fired once the player has been successfully authenticated and fully initialized and
|
||||||
* fully initialized and player will be connected to server after this event
|
* player will be connected to server after this event
|
||||||
*/
|
*/
|
||||||
public final class PostLoginEvent {
|
public final class PostLoginEvent {
|
||||||
|
|
||||||
|
@ -3,17 +3,18 @@ package com.velocitypowered.api.event.connection;
|
|||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.velocitypowered.api.event.ResultedEvent;
|
import com.velocitypowered.api.event.ResultedEvent;
|
||||||
import com.velocitypowered.api.proxy.InboundConnection;
|
import com.velocitypowered.api.proxy.InboundConnection;
|
||||||
|
import java.util.Optional;
|
||||||
import net.kyori.text.Component;
|
import net.kyori.text.Component;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This event is fired when a player has initiated a connection with the proxy but before the proxy authenticates the
|
* This event is fired when a player has initiated a connection with the proxy but before the proxy
|
||||||
* player with Mojang or before the player's proxy connection is fully established (for offline mode).
|
* authenticates the player with Mojang or before the player's proxy connection is fully established
|
||||||
|
* (for offline mode).
|
||||||
*/
|
*/
|
||||||
public final class PreLoginEvent implements ResultedEvent<PreLoginEvent.PreLoginComponentResult> {
|
public final class PreLoginEvent implements ResultedEvent<PreLoginEvent.PreLoginComponentResult> {
|
||||||
|
|
||||||
private final InboundConnection connection;
|
private final InboundConnection connection;
|
||||||
private final String username;
|
private final String username;
|
||||||
private PreLoginComponentResult result;
|
private PreLoginComponentResult result;
|
||||||
@ -52,13 +53,17 @@ public final class PreLoginEvent implements ResultedEvent<PreLoginEvent.PreLogin
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an "allowed/allowed with forced online\offline mode/denied" result with a reason allowed for denial.
|
* Represents an "allowed/allowed with forced online\offline mode/denied" result with a reason
|
||||||
|
* allowed for denial.
|
||||||
*/
|
*/
|
||||||
public static final class PreLoginComponentResult implements ResultedEvent.Result {
|
public static final class PreLoginComponentResult implements ResultedEvent.Result {
|
||||||
|
|
||||||
private static final PreLoginComponentResult ALLOWED = new PreLoginComponentResult(Result.ALLOWED, null);
|
private static final PreLoginComponentResult ALLOWED = new PreLoginComponentResult(
|
||||||
private static final PreLoginComponentResult FORCE_ONLINEMODE = new PreLoginComponentResult(Result.FORCE_ONLINE, null);
|
Result.ALLOWED, null);
|
||||||
private static final PreLoginComponentResult FORCE_OFFLINEMODE = new PreLoginComponentResult(Result.FORCE_OFFLINE, null);
|
private static final PreLoginComponentResult FORCE_ONLINEMODE = new PreLoginComponentResult(
|
||||||
|
Result.FORCE_ONLINE, null);
|
||||||
|
private static final PreLoginComponentResult FORCE_OFFLINEMODE = new PreLoginComponentResult(
|
||||||
|
Result.FORCE_OFFLINE, null);
|
||||||
|
|
||||||
private final Result result;
|
private final Result result;
|
||||||
private final @Nullable Component reason;
|
private final @Nullable Component reason;
|
||||||
@ -100,8 +105,8 @@ public final class PreLoginEvent implements ResultedEvent<PreLoginEvent.PreLogin
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a result indicating the connection will be allowed through
|
* Returns a result indicating the connection will be allowed through the proxy.
|
||||||
* the proxy.
|
*
|
||||||
* @return the allowed result
|
* @return the allowed result
|
||||||
*/
|
*/
|
||||||
public static PreLoginComponentResult allowed() {
|
public static PreLoginComponentResult allowed() {
|
||||||
@ -109,10 +114,10 @@ public final class PreLoginEvent implements ResultedEvent<PreLoginEvent.PreLogin
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a result indicating the connection will be allowed through
|
* Returns a result indicating the connection will be allowed through the proxy, but the
|
||||||
* the proxy, but the connection will be forced to use online mode
|
* connection will be forced to use online mode provided that the proxy is in offline mode. This
|
||||||
* provided that the proxy is in offline mode. This acts similarly to
|
* acts similarly to {@link #allowed()} on an online-mode proxy.
|
||||||
* {@link #allowed()} on an online-mode proxy.
|
*
|
||||||
* @return the result
|
* @return the result
|
||||||
*/
|
*/
|
||||||
public static PreLoginComponentResult forceOnlineMode() {
|
public static PreLoginComponentResult forceOnlineMode() {
|
||||||
@ -120,9 +125,9 @@ public final class PreLoginEvent implements ResultedEvent<PreLoginEvent.PreLogin
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a result indicating the connection will be allowed through
|
* Returns a result indicating the connection will be allowed through the proxy, but the
|
||||||
* the proxy, but the connection will be forced to use offline mode even
|
* connection will be forced to use offline mode even when proxy running in online mode
|
||||||
* when proxy running in online mode
|
*
|
||||||
* @return the result
|
* @return the result
|
||||||
*/
|
*/
|
||||||
public static PreLoginComponentResult forceOfflineMode() {
|
public static PreLoginComponentResult forceOfflineMode() {
|
||||||
@ -131,6 +136,7 @@ public final class PreLoginEvent implements ResultedEvent<PreLoginEvent.PreLogin
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Denies the login with the specified reason.
|
* Denies the login with the specified reason.
|
||||||
|
*
|
||||||
* @param reason the reason for disallowing the connection
|
* @param reason the reason for disallowing the connection
|
||||||
* @return a new result
|
* @return a new result
|
||||||
*/
|
*/
|
||||||
|
@ -12,6 +12,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
* <p>This event is only called once per subject, on initialisation.</p>
|
* <p>This event is only called once per subject, on initialisation.</p>
|
||||||
*/
|
*/
|
||||||
public final class PermissionsSetupEvent {
|
public final class PermissionsSetupEvent {
|
||||||
|
|
||||||
private final PermissionSubject subject;
|
private final PermissionSubject subject;
|
||||||
private final PermissionProvider defaultProvider;
|
private final PermissionProvider defaultProvider;
|
||||||
private PermissionProvider provider;
|
private PermissionProvider provider;
|
||||||
@ -26,8 +27,7 @@ public final class PermissionsSetupEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses the provider function to obtain a {@link PermissionFunction} for
|
* Uses the provider function to obtain a {@link PermissionFunction} for the subject.
|
||||||
* the subject.
|
|
||||||
*
|
*
|
||||||
* @param subject the subject
|
* @param subject the subject
|
||||||
* @return the obtained permission function
|
* @return the obtained permission function
|
||||||
|
@ -6,17 +6,20 @@ import com.velocitypowered.api.util.GameProfile;
|
|||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This event is fired after the {@link com.velocitypowered.api.event.connection.PreLoginEvent} in order to set up the
|
* This event is fired after the {@link com.velocitypowered.api.event.connection.PreLoginEvent} in
|
||||||
* game profile for the user. This can be used to configure a custom profile for a user, i.e. skin replacement.
|
* order to set up the game profile for the user. This can be used to configure a custom profile for
|
||||||
|
* a user, i.e. skin replacement.
|
||||||
*/
|
*/
|
||||||
public final class GameProfileRequestEvent {
|
public final class GameProfileRequestEvent {
|
||||||
|
|
||||||
private final String username;
|
private final String username;
|
||||||
private final InboundConnection connection;
|
private final InboundConnection connection;
|
||||||
private final GameProfile originalProfile;
|
private final GameProfile originalProfile;
|
||||||
private final boolean onlineMode;
|
private final boolean onlineMode;
|
||||||
private @Nullable GameProfile gameProfile;
|
private @Nullable GameProfile gameProfile;
|
||||||
|
|
||||||
public GameProfileRequestEvent(InboundConnection connection, GameProfile originalProfile, boolean onlineMode) {
|
public GameProfileRequestEvent(InboundConnection connection, GameProfile originalProfile,
|
||||||
|
boolean onlineMode) {
|
||||||
this.connection = Preconditions.checkNotNull(connection, "connection");
|
this.connection = Preconditions.checkNotNull(connection, "connection");
|
||||||
this.originalProfile = Preconditions.checkNotNull(originalProfile, "originalProfile");
|
this.originalProfile = Preconditions.checkNotNull(originalProfile, "originalProfile");
|
||||||
this.username = originalProfile.getName();
|
this.username = originalProfile.getName();
|
||||||
@ -40,9 +43,10 @@ public final class GameProfileRequestEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the game profile that will be used to initialize the connection with. Should no profile be currently
|
* Returns the game profile that will be used to initialize the connection with. Should no profile
|
||||||
* specified, the one generated by the proxy (for offline mode) or retrieved from the Mojang session servers (for
|
* be currently specified, the one generated by the proxy (for offline mode) or retrieved from the
|
||||||
* online mode) will be returned instead.
|
* Mojang session servers (for online mode) will be returned instead.
|
||||||
|
*
|
||||||
* @return the user's {@link GameProfile}
|
* @return the user's {@link GameProfile}
|
||||||
*/
|
*/
|
||||||
public GameProfile getGameProfile() {
|
public GameProfile getGameProfile() {
|
||||||
@ -50,17 +54,21 @@ public final class GameProfileRequestEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the game profile to use for this connection. It is invalid to use this method on an online-mode connection.
|
* Sets the game profile to use for this connection. It is invalid to use this method on an
|
||||||
* @param gameProfile the profile to use for the connection, {@code null} uses the original profile
|
* online-mode connection.
|
||||||
|
*
|
||||||
|
* @param gameProfile the profile to use for the connection, {@code null} uses the original
|
||||||
|
* profile
|
||||||
*/
|
*/
|
||||||
public void setGameProfile(@Nullable GameProfile gameProfile) {
|
public void setGameProfile(@Nullable GameProfile gameProfile) {
|
||||||
Preconditions.checkState(!onlineMode, "Connection is in online mode, profiles can not be faked");
|
Preconditions
|
||||||
|
.checkState(!onlineMode, "Connection is in online mode, profiles can not be faked");
|
||||||
this.gameProfile = gameProfile;
|
this.gameProfile = gameProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "GameProfileRequestEvent{"+
|
return "GameProfileRequestEvent{" +
|
||||||
"username=" + username +
|
"username=" + username +
|
||||||
", gameProfile=" + gameProfile +
|
", gameProfile=" + gameProfile +
|
||||||
"}";
|
"}";
|
||||||
|
@ -8,17 +8,20 @@ import net.kyori.text.Component;
|
|||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fired when a player is kicked from a server. You may either allow Velocity to kick the player (with an optional reason
|
* Fired when a player is kicked from a server. You may either allow Velocity to kick the player
|
||||||
* override) or redirect the player to a separate server.
|
* (with an optional reason override) or redirect the player to a separate server.
|
||||||
*/
|
*/
|
||||||
public final class KickedFromServerEvent implements ResultedEvent<KickedFromServerEvent.ServerKickResult> {
|
public final class KickedFromServerEvent implements
|
||||||
|
ResultedEvent<KickedFromServerEvent.ServerKickResult> {
|
||||||
|
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final RegisteredServer server;
|
private final RegisteredServer server;
|
||||||
private final Component originalReason;
|
private final Component originalReason;
|
||||||
private final boolean duringLogin;
|
private final boolean duringLogin;
|
||||||
private ServerKickResult result;
|
private ServerKickResult result;
|
||||||
|
|
||||||
public KickedFromServerEvent(Player player, RegisteredServer server, Component originalReason, boolean duringLogin, Component fancyReason) {
|
public KickedFromServerEvent(Player player, RegisteredServer server, Component originalReason,
|
||||||
|
boolean duringLogin, Component fancyReason) {
|
||||||
this.player = Preconditions.checkNotNull(player, "player");
|
this.player = Preconditions.checkNotNull(player, "player");
|
||||||
this.server = Preconditions.checkNotNull(server, "server");
|
this.server = Preconditions.checkNotNull(server, "server");
|
||||||
this.originalReason = Preconditions.checkNotNull(originalReason, "originalReason");
|
this.originalReason = Preconditions.checkNotNull(originalReason, "originalReason");
|
||||||
@ -55,12 +58,15 @@ public final class KickedFromServerEvent implements ResultedEvent<KickedFromServ
|
|||||||
/**
|
/**
|
||||||
* Represents the base interface for {@link KickedFromServerEvent} results.
|
* Represents the base interface for {@link KickedFromServerEvent} results.
|
||||||
*/
|
*/
|
||||||
public interface ServerKickResult extends ResultedEvent.Result {}
|
public interface ServerKickResult extends ResultedEvent.Result {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells the proxy to disconnect the player with the specified reason.
|
* Tells the proxy to disconnect the player with the specified reason.
|
||||||
*/
|
*/
|
||||||
public static final class DisconnectPlayer implements ServerKickResult {
|
public static final class DisconnectPlayer implements ServerKickResult {
|
||||||
|
|
||||||
private final Component component;
|
private final Component component;
|
||||||
|
|
||||||
private DisconnectPlayer(Component component) {
|
private DisconnectPlayer(Component component) {
|
||||||
@ -78,6 +84,7 @@ public final class KickedFromServerEvent implements ResultedEvent<KickedFromServ
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link DisconnectPlayer} with the specified reason.
|
* Creates a new {@link DisconnectPlayer} with the specified reason.
|
||||||
|
*
|
||||||
* @param reason the reason to use when disconnecting the player
|
* @param reason the reason to use when disconnecting the player
|
||||||
* @return the disconnect result
|
* @return the disconnect result
|
||||||
*/
|
*/
|
||||||
@ -87,10 +94,11 @@ public final class KickedFromServerEvent implements ResultedEvent<KickedFromServ
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells the proxy to redirect the player to another server. No messages will be sent from the proxy
|
* Tells the proxy to redirect the player to another server. No messages will be sent from the
|
||||||
* when this result is used.
|
* proxy when this result is used.
|
||||||
*/
|
*/
|
||||||
public static final class RedirectPlayer implements ServerKickResult {
|
public static final class RedirectPlayer implements ServerKickResult {
|
||||||
|
|
||||||
private final RegisteredServer server;
|
private final RegisteredServer server;
|
||||||
|
|
||||||
private RedirectPlayer(RegisteredServer server) {
|
private RedirectPlayer(RegisteredServer server) {
|
||||||
@ -108,6 +116,7 @@ public final class KickedFromServerEvent implements ResultedEvent<KickedFromServ
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new redirect result to forward the player to the specified {@code server}.
|
* Creates a new redirect result to forward the player to the specified {@code server}.
|
||||||
|
*
|
||||||
* @param server the server to send the player to
|
* @param server the server to send the player to
|
||||||
* @return the redirect result
|
* @return the redirect result
|
||||||
*/
|
*/
|
||||||
|
@ -3,15 +3,15 @@ package com.velocitypowered.api.event.player;
|
|||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.velocitypowered.api.event.ResultedEvent;
|
import com.velocitypowered.api.event.ResultedEvent;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import java.util.Optional;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This event is fired when a player types in a chat message.
|
* This event is fired when a player types in a chat message.
|
||||||
*/
|
*/
|
||||||
public final class PlayerChatEvent implements ResultedEvent<PlayerChatEvent.ChatResult> {
|
public final class PlayerChatEvent implements ResultedEvent<PlayerChatEvent.ChatResult> {
|
||||||
|
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final String message;
|
private final String message;
|
||||||
private ChatResult result;
|
private ChatResult result;
|
||||||
@ -53,6 +53,7 @@ public final class PlayerChatEvent implements ResultedEvent<PlayerChatEvent.Chat
|
|||||||
* Represents the result of the {@link PlayerChatEvent}.
|
* Represents the result of the {@link PlayerChatEvent}.
|
||||||
*/
|
*/
|
||||||
public static final class ChatResult implements ResultedEvent.Result {
|
public static final class ChatResult implements ResultedEvent.Result {
|
||||||
|
|
||||||
private static final ChatResult ALLOWED = new ChatResult(true, null);
|
private static final ChatResult ALLOWED = new ChatResult(true, null);
|
||||||
private static final ChatResult DENIED = new ChatResult(false, null);
|
private static final ChatResult DENIED = new ChatResult(false, null);
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import com.velocitypowered.api.util.ModInfo;
|
|||||||
* This event is fired when the players ModInfo is changed.
|
* This event is fired when the players ModInfo is changed.
|
||||||
*/
|
*/
|
||||||
public final class PlayerModInfoEvent {
|
public final class PlayerModInfoEvent {
|
||||||
|
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final ModInfo modInfo;
|
private final ModInfo modInfo;
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import com.velocitypowered.api.proxy.Player;
|
|||||||
import com.velocitypowered.api.proxy.player.PlayerSettings;
|
import com.velocitypowered.api.proxy.player.PlayerSettings;
|
||||||
|
|
||||||
public final class PlayerSettingsChangedEvent {
|
public final class PlayerSettingsChangedEvent {
|
||||||
|
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final PlayerSettings playerSettings;
|
private final PlayerSettings playerSettings;
|
||||||
|
|
||||||
|
@ -5,10 +5,11 @@ import com.velocitypowered.api.proxy.Player;
|
|||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This event is fired once the player has successfully connected to the target server and the connection to the previous
|
* This event is fired once the player has successfully connected to the target server and the
|
||||||
* server has been de-established.
|
* connection to the previous server has been de-established.
|
||||||
*/
|
*/
|
||||||
public final class ServerConnectedEvent {
|
public final class ServerConnectedEvent {
|
||||||
|
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final RegisteredServer server;
|
private final RegisteredServer server;
|
||||||
|
|
||||||
|
@ -4,14 +4,15 @@ import com.google.common.base.Preconditions;
|
|||||||
import com.velocitypowered.api.event.ResultedEvent;
|
import com.velocitypowered.api.event.ResultedEvent;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This event is fired before the player connects to a server.
|
* This event is fired before the player connects to a server.
|
||||||
*/
|
*/
|
||||||
public final class ServerPreConnectEvent implements ResultedEvent<ServerPreConnectEvent.ServerResult> {
|
public final class ServerPreConnectEvent implements
|
||||||
|
ResultedEvent<ServerPreConnectEvent.ServerResult> {
|
||||||
|
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final RegisteredServer originalServer;
|
private final RegisteredServer originalServer;
|
||||||
private ServerResult result;
|
private ServerResult result;
|
||||||
@ -53,6 +54,7 @@ public final class ServerPreConnectEvent implements ResultedEvent<ServerPreConne
|
|||||||
* Represents the result of the {@link ServerPreConnectEvent}.
|
* Represents the result of the {@link ServerPreConnectEvent}.
|
||||||
*/
|
*/
|
||||||
public static class ServerResult implements ResultedEvent.Result {
|
public static class ServerResult implements ResultedEvent.Result {
|
||||||
|
|
||||||
private static final ServerResult DENIED = new ServerResult(null);
|
private static final ServerResult DENIED = new ServerResult(null);
|
||||||
|
|
||||||
private final @Nullable RegisteredServer server;
|
private final @Nullable RegisteredServer server;
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package com.velocitypowered.api.event.proxy;
|
package com.velocitypowered.api.event.proxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This event is fired by the proxy after plugins have been loaded but before the proxy starts accepting connections.
|
* This event is fired by the proxy after plugins have been loaded but before the proxy starts
|
||||||
|
* accepting connections.
|
||||||
*/
|
*/
|
||||||
public final class ProxyInitializeEvent {
|
public final class ProxyInitializeEvent {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ProxyInitializeEvent";
|
return "ProxyInitializeEvent";
|
||||||
|
@ -8,6 +8,7 @@ import com.velocitypowered.api.proxy.server.ServerPing;
|
|||||||
* This event is fired when a server list ping request is sent by a remote client.
|
* This event is fired when a server list ping request is sent by a remote client.
|
||||||
*/
|
*/
|
||||||
public final class ProxyPingEvent {
|
public final class ProxyPingEvent {
|
||||||
|
|
||||||
private final InboundConnection connection;
|
private final InboundConnection connection;
|
||||||
private ServerPing ping;
|
private ServerPing ping;
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package com.velocitypowered.api.event.proxy;
|
package com.velocitypowered.api.event.proxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This event is fired by the proxy after the proxy has stopped accepting connections but before the proxy process
|
* This event is fired by the proxy after the proxy has stopped accepting connections but before the
|
||||||
* exits.
|
* proxy process exits.
|
||||||
*/
|
*/
|
||||||
public final class ProxyShutdownEvent {
|
public final class ProxyShutdownEvent {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ProxyShutdownEvent";
|
return "ProxyShutdownEvent";
|
||||||
|
@ -2,14 +2,14 @@ package com.velocitypowered.api.event.query;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.velocitypowered.api.proxy.server.QueryResponse;
|
import com.velocitypowered.api.proxy.server.QueryResponse;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This event is fired if proxy is getting queried over GS4 Query protocol
|
* This event is fired if proxy is getting queried over GS4 Query protocol
|
||||||
*/
|
*/
|
||||||
public final class ProxyQueryEvent {
|
public final class ProxyQueryEvent {
|
||||||
|
|
||||||
private final QueryType queryType;
|
private final QueryType queryType;
|
||||||
private final InetAddress querierAddress;
|
private final InetAddress querierAddress;
|
||||||
private QueryResponse response;
|
private QueryResponse response;
|
||||||
@ -22,6 +22,7 @@ public final class ProxyQueryEvent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get query type
|
* Get query type
|
||||||
|
*
|
||||||
* @return query type
|
* @return query type
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -31,6 +32,7 @@ public final class ProxyQueryEvent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get querier address
|
* Get querier address
|
||||||
|
*
|
||||||
* @return querier address
|
* @return querier address
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -40,6 +42,7 @@ public final class ProxyQueryEvent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get query response
|
* Get query response
|
||||||
|
*
|
||||||
* @return query response
|
* @return query response
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -49,6 +52,7 @@ public final class ProxyQueryEvent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set query response
|
* Set query response
|
||||||
|
*
|
||||||
* @param response query response
|
* @param response query response
|
||||||
*/
|
*/
|
||||||
public void setResponse(@NonNull QueryResponse response) {
|
public void setResponse(@NonNull QueryResponse response) {
|
||||||
@ -69,15 +73,15 @@ public final class ProxyQueryEvent {
|
|||||||
*/
|
*/
|
||||||
public enum QueryType {
|
public enum QueryType {
|
||||||
/**
|
/**
|
||||||
* Basic query asks only a subset of information, such as hostname, game type (hardcoded to <pre>MINECRAFT</pre>), map,
|
* Basic query asks only a subset of information, such as hostname, game type (hardcoded to
|
||||||
* current players, max players, proxy port and proxy hostname
|
* <pre>MINECRAFT</pre>), map, current players, max players, proxy port and proxy hostname
|
||||||
*/
|
*/
|
||||||
BASIC,
|
BASIC,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Full query asks pretty much everything present on this event (only hardcoded values cannot be modified here).
|
* Full query asks pretty much everything present on this event (only hardcoded values cannot be
|
||||||
|
* modified here).
|
||||||
*/
|
*/
|
||||||
FULL
|
FULL;
|
||||||
;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.velocitypowered.api.permission;
|
package com.velocitypowered.api.permission;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function that calculates the permission settings for a given
|
* Function that calculates the permission settings for a given {@link PermissionSubject}.
|
||||||
* {@link PermissionSubject}.
|
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface PermissionFunction {
|
public interface PermissionFunction {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A permission function that always returns {@link Tristate#TRUE}.
|
* A permission function that always returns {@link Tristate#TRUE}.
|
||||||
*/
|
*/
|
||||||
|
@ -5,6 +5,7 @@ package com.velocitypowered.api.permission;
|
|||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface PermissionProvider {
|
public interface PermissionProvider {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link PermissionFunction} for the subject.
|
* Creates a {@link PermissionFunction} for the subject.
|
||||||
*
|
*
|
||||||
|
@ -4,6 +4,7 @@ package com.velocitypowered.api.permission;
|
|||||||
* Represents a object that has a set of queryable permissions.
|
* Represents a object that has a set of queryable permissions.
|
||||||
*/
|
*/
|
||||||
public interface PermissionSubject {
|
public interface PermissionSubject {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether or not the subject has a particular permission.
|
* Determines whether or not the subject has a particular permission.
|
||||||
*
|
*
|
||||||
|
@ -34,7 +34,8 @@ public enum Tristate {
|
|||||||
* Returns a {@link Tristate} from a boolean
|
* Returns a {@link Tristate} from a boolean
|
||||||
*
|
*
|
||||||
* @param val the boolean value
|
* @param val the boolean value
|
||||||
* @return {@link #TRUE} or {@link #FALSE}, if the value is <code>true</code> or <code>false</code>, respectively.
|
* @return {@link #TRUE} or {@link #FALSE}, if the value is <code>true</code> or
|
||||||
|
* <code>false</code>, respectively.
|
||||||
*/
|
*/
|
||||||
public static Tristate fromBoolean(boolean val) {
|
public static Tristate fromBoolean(boolean val) {
|
||||||
return val ? TRUE : FALSE;
|
return val ? TRUE : FALSE;
|
||||||
@ -47,8 +48,8 @@ public enum Tristate {
|
|||||||
* if the value is null.</p>
|
* if the value is null.</p>
|
||||||
*
|
*
|
||||||
* @param val the boolean value
|
* @param val the boolean value
|
||||||
* @return {@link #UNDEFINED}, {@link #TRUE} or {@link #FALSE}, if the value
|
* @return {@link #UNDEFINED}, {@link #TRUE} or {@link #FALSE}, if the value is <code>null</code>,
|
||||||
* is <code>null</code>, <code>true</code> or <code>false</code>, respectively.
|
* <code>true</code> or <code>false</code>, respectively.
|
||||||
*/
|
*/
|
||||||
public static Tristate fromNullableBoolean(@Nullable Boolean val) {
|
public static Tristate fromNullableBoolean(@Nullable Boolean val) {
|
||||||
if (val == null) {
|
if (val == null) {
|
||||||
|
@ -10,6 +10,7 @@ import java.lang.annotation.Target;
|
|||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target({})
|
@Target({})
|
||||||
public @interface Dependency {
|
public @interface Dependency {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The plugin ID of the dependency.
|
* The plugin ID of the dependency.
|
||||||
*
|
*
|
||||||
@ -19,8 +20,7 @@ public @interface Dependency {
|
|||||||
String id();
|
String id();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this dependency is optional for the plugin to work. By default
|
* If this dependency is optional for the plugin to work. By default this is {@code false}.
|
||||||
* this is {@code false}.
|
|
||||||
*
|
*
|
||||||
* @return true if the dependency is optional for the plugin to work
|
* @return true if the dependency is optional for the plugin to work
|
||||||
*/
|
*/
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.velocitypowered.api.plugin;
|
package com.velocitypowered.api.plugin;
|
||||||
|
|
||||||
public class InvalidPluginException extends Exception {
|
public class InvalidPluginException extends Exception {
|
||||||
|
|
||||||
public InvalidPluginException() {
|
public InvalidPluginException() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,9 @@ import java.lang.annotation.Target;
|
|||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.TYPE)
|
@Target(ElementType.TYPE)
|
||||||
public @interface Plugin {
|
public @interface Plugin {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ID of the plugin. This ID should be unique as to
|
* The ID of the plugin. This ID should be unique as to not conflict with other plugins.
|
||||||
* not conflict with other plugins.
|
|
||||||
*
|
*
|
||||||
* The plugin ID must match the {@link PluginDescription#ID_PATTERN}.
|
* The plugin ID must match the {@link PluginDescription#ID_PATTERN}.
|
||||||
*
|
*
|
||||||
@ -22,8 +22,7 @@ public @interface Plugin {
|
|||||||
String id();
|
String id();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The human readable name of the plugin as to be used in descriptions and
|
* The human readable name of the plugin as to be used in descriptions and similar things.
|
||||||
* similar things.
|
|
||||||
*
|
*
|
||||||
* @return The plugin name, or an empty string if unknown
|
* @return The plugin name, or an empty string if unknown
|
||||||
*/
|
*/
|
||||||
|
@ -6,6 +6,7 @@ import java.util.Optional;
|
|||||||
* A wrapper around a plugin loaded by the proxy.
|
* A wrapper around a plugin loaded by the proxy.
|
||||||
*/
|
*/
|
||||||
public interface PluginContainer {
|
public interface PluginContainer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the plugin's description.
|
* Returns the plugin's description.
|
||||||
*
|
*
|
||||||
|
@ -3,7 +3,6 @@ package com.velocitypowered.api.plugin;
|
|||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.velocitypowered.api.plugin.meta.PluginDependency;
|
import com.velocitypowered.api.plugin.meta.PluginDependency;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -14,10 +13,11 @@ import java.util.regex.Pattern;
|
|||||||
* Represents metadata for a specific version of a plugin.
|
* Represents metadata for a specific version of a plugin.
|
||||||
*/
|
*/
|
||||||
public interface PluginDescription {
|
public interface PluginDescription {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The pattern plugin IDs must match. Plugin IDs may only contain
|
* The pattern plugin IDs must match. Plugin IDs may only contain alphanumeric characters, dashes
|
||||||
* alphanumeric characters, dashes or underscores, must start with
|
* or underscores, must start with an alphabetic character and cannot be longer than 64
|
||||||
* an alphabetic character and cannot be longer than 64 characters.
|
* characters.
|
||||||
*/
|
*/
|
||||||
Pattern ID_PATTERN = Pattern.compile("[a-z][a-z0-9-_]{0,63}");
|
Pattern ID_PATTERN = Pattern.compile("[a-z][a-z0-9-_]{0,63}");
|
||||||
|
|
||||||
@ -80,8 +80,7 @@ public interface PluginDescription {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a {@link Collection} of all dependencies of the {@link Plugin} within
|
* Gets a {@link Collection} of all dependencies of the {@link Plugin} within this container.
|
||||||
* this container.
|
|
||||||
*
|
*
|
||||||
* @return the plugin dependencies, can be empty
|
* @return the plugin dependencies, can be empty
|
||||||
* @see Plugin#dependencies()
|
* @see Plugin#dependencies()
|
||||||
@ -97,8 +96,7 @@ public interface PluginDescription {
|
|||||||
/**
|
/**
|
||||||
* Returns the source the plugin was loaded from.
|
* Returns the source the plugin was loaded from.
|
||||||
*
|
*
|
||||||
* @return the source the plugin was loaded from or {@link Optional#empty()}
|
* @return the source the plugin was loaded from or {@link Optional#empty()} if unknown
|
||||||
* if unknown
|
|
||||||
*/
|
*/
|
||||||
default Optional<Path> getSource() {
|
default Optional<Path> getSource() {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
@ -5,10 +5,12 @@ import java.util.Collection;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages plugins loaded on the proxy. This manager can retrieve {@link PluginContainer}s from plugin instances
|
* Manages plugins loaded on the proxy. This manager can retrieve {@link PluginContainer}s from
|
||||||
* and inject arbitrary JAR files into the plugin classpath with {@link #addToClasspath(Object, Path)}.
|
* plugin instances and inject arbitrary JAR files into the plugin classpath with {@link
|
||||||
|
* #addToClasspath(Object, Path)}.
|
||||||
*/
|
*/
|
||||||
public interface PluginManager {
|
public interface PluginManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the plugin container from an instance.
|
* Gets the plugin container from an instance.
|
||||||
*
|
*
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
package com.velocitypowered.api.plugin.annotation;
|
package com.velocitypowered.api.plugin.annotation;
|
||||||
|
|
||||||
import com.google.inject.BindingAnnotation;
|
import com.google.inject.BindingAnnotation;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This annotation requests that Velocity inject a {@link java.nio.file.Path} instance with a plugin-specific data
|
* This annotation requests that Velocity inject a {@link java.nio.file.Path} instance with a
|
||||||
* directory.
|
* plugin-specific data directory.
|
||||||
*/
|
*/
|
||||||
@Target({ElementType.FIELD, ElementType.PARAMETER})
|
@Target({ElementType.FIELD, ElementType.PARAMETER})
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@BindingAnnotation
|
@BindingAnnotation
|
||||||
public @interface DataDirectory {
|
public @interface DataDirectory {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
package com.velocitypowered.api.plugin.meta;
|
package com.velocitypowered.api.plugin.meta;
|
||||||
|
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Strings.emptyToNull;
|
import static com.google.common.base.Strings.emptyToNull;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a dependency on another plugin.
|
* Represents a dependency on another plugin.
|
||||||
*/
|
*/
|
||||||
public final class PluginDependency {
|
public final class PluginDependency {
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final String version;
|
private final String version;
|
||||||
@ -45,8 +45,7 @@ public final class PluginDependency {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the dependency is optional for the plugin to work
|
* Returns whether the dependency is optional for the plugin to work correctly.
|
||||||
* correctly.
|
|
||||||
*
|
*
|
||||||
* @return true if dependency is optional
|
* @return true if dependency is optional
|
||||||
*/
|
*/
|
||||||
@ -56,8 +55,12 @@ public final class PluginDependency {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object o) {
|
public boolean equals(@Nullable Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
PluginDependency that = (PluginDependency) o;
|
PluginDependency that = (PluginDependency) o;
|
||||||
return optional == that.optional &&
|
return optional == that.optional &&
|
||||||
Objects.equals(id, that.id) &&
|
Objects.equals(id, that.id) &&
|
||||||
|
@ -1,39 +1,44 @@
|
|||||||
package com.velocitypowered.api.proxy;
|
package com.velocitypowered.api.proxy;
|
||||||
|
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
import net.kyori.text.Component;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import net.kyori.text.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a fluent interface to compose and send a connection request to another server behind the proxy. A connection
|
* Provides a fluent interface to compose and send a connection request to another server behind the
|
||||||
* request is created using {@link Player#createConnectionRequest(RegisteredServer)}.
|
* proxy. A connection request is created using {@link Player#createConnectionRequest(RegisteredServer)}.
|
||||||
*/
|
*/
|
||||||
public interface ConnectionRequestBuilder {
|
public interface ConnectionRequestBuilder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the server that this connection request represents.
|
* Returns the server that this connection request represents.
|
||||||
|
*
|
||||||
* @return the server this request will connect to
|
* @return the server this request will connect to
|
||||||
*/
|
*/
|
||||||
RegisteredServer getServer();
|
RegisteredServer getServer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initiates the connection to the remote server and emits a result on the {@link CompletableFuture} after the user
|
* Initiates the connection to the remote server and emits a result on the {@link
|
||||||
* has logged on. No messages will be communicated to the client: the user is responsible for all error handling.
|
* CompletableFuture} after the user has logged on. No messages will be communicated to the
|
||||||
|
* client: the user is responsible for all error handling.
|
||||||
|
*
|
||||||
* @return a {@link CompletableFuture} representing the status of this connection
|
* @return a {@link CompletableFuture} representing the status of this connection
|
||||||
*/
|
*/
|
||||||
CompletableFuture<Result> connect();
|
CompletableFuture<Result> connect();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initiates the connection to the remote server and emits a result on the {@link CompletableFuture} after the user
|
* Initiates the connection to the remote server and emits a result on the {@link
|
||||||
* has logged on. Velocity's own built-in handling will be used to provide errors to the client.
|
* CompletableFuture} after the user has logged on. Velocity's own built-in handling will be used
|
||||||
|
* to provide errors to the client.
|
||||||
|
*
|
||||||
* @return a {@link CompletableFuture} representing the status of this connection
|
* @return a {@link CompletableFuture} representing the status of this connection
|
||||||
*/
|
*/
|
||||||
CompletableFuture<Boolean> connectWithIndication();
|
CompletableFuture<Boolean> connectWithIndication();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initiates the connection to the remote server without waiting for a result. Velocity will use generic error
|
* Initiates the connection to the remote server without waiting for a result. Velocity will use
|
||||||
* handling code to notify the user.
|
* generic error handling code to notify the user.
|
||||||
*/
|
*/
|
||||||
void fireAndForget();
|
void fireAndForget();
|
||||||
|
|
||||||
@ -41,8 +46,10 @@ public interface ConnectionRequestBuilder {
|
|||||||
* Represents the result of a connection request.
|
* Represents the result of a connection request.
|
||||||
*/
|
*/
|
||||||
interface Result {
|
interface Result {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether or not the connection request was successful.
|
* Determines whether or not the connection request was successful.
|
||||||
|
*
|
||||||
* @return whether or not the request succeeded
|
* @return whether or not the request succeeded
|
||||||
*/
|
*/
|
||||||
default boolean isSuccessful() {
|
default boolean isSuccessful() {
|
||||||
@ -51,12 +58,14 @@ public interface ConnectionRequestBuilder {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the status associated with this result.
|
* Returns the status associated with this result.
|
||||||
|
*
|
||||||
* @return the status for this result
|
* @return the status for this result
|
||||||
*/
|
*/
|
||||||
Status getStatus();
|
Status getStatus();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an (optional) textual reason for the failure to connect to the server.
|
* Returns an (optional) textual reason for the failure to connect to the server.
|
||||||
|
*
|
||||||
* @return the reason why the user could not connect to the server
|
* @return the reason why the user could not connect to the server
|
||||||
*/
|
*/
|
||||||
Optional<Component> getReason();
|
Optional<Component> getReason();
|
||||||
|
@ -7,26 +7,31 @@ import java.util.Optional;
|
|||||||
* Represents an incoming connection to the proxy.
|
* Represents an incoming connection to the proxy.
|
||||||
*/
|
*/
|
||||||
public interface InboundConnection {
|
public interface InboundConnection {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the player's IP address.
|
* Returns the player's IP address.
|
||||||
|
*
|
||||||
* @return the player's IP
|
* @return the player's IP
|
||||||
*/
|
*/
|
||||||
InetSocketAddress getRemoteAddress();
|
InetSocketAddress getRemoteAddress();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the hostname that the user entered into the client, if applicable.
|
* Returns the hostname that the user entered into the client, if applicable.
|
||||||
|
*
|
||||||
* @return the hostname from the client
|
* @return the hostname from the client
|
||||||
*/
|
*/
|
||||||
Optional<InetSocketAddress> getVirtualHost();
|
Optional<InetSocketAddress> getVirtualHost();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine whether or not the player remains online.
|
* Determine whether or not the player remains online.
|
||||||
|
*
|
||||||
* @return whether or not the player active
|
* @return whether or not the player active
|
||||||
*/
|
*/
|
||||||
boolean isActive();
|
boolean isActive();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current protocol version this connection uses.
|
* Returns the current protocol version this connection uses.
|
||||||
|
*
|
||||||
* @return the protocol version the connection uses
|
* @return the protocol version the connection uses
|
||||||
*/
|
*/
|
||||||
int getProtocolVersion();
|
int getProtocolVersion();
|
||||||
|
@ -4,61 +4,68 @@ import com.velocitypowered.api.command.CommandSource;
|
|||||||
import com.velocitypowered.api.proxy.messages.ChannelMessageSink;
|
import com.velocitypowered.api.proxy.messages.ChannelMessageSink;
|
||||||
import com.velocitypowered.api.proxy.messages.ChannelMessageSource;
|
import com.velocitypowered.api.proxy.messages.ChannelMessageSource;
|
||||||
import com.velocitypowered.api.proxy.player.PlayerSettings;
|
import com.velocitypowered.api.proxy.player.PlayerSettings;
|
||||||
|
import com.velocitypowered.api.proxy.player.TabList;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
import com.velocitypowered.api.util.GameProfile;
|
import com.velocitypowered.api.util.GameProfile;
|
||||||
import com.velocitypowered.api.proxy.player.TabList;
|
|
||||||
import com.velocitypowered.api.util.MessagePosition;
|
import com.velocitypowered.api.util.MessagePosition;
|
||||||
import com.velocitypowered.api.util.ModInfo;
|
import com.velocitypowered.api.util.ModInfo;
|
||||||
import com.velocitypowered.api.util.title.Title;
|
import com.velocitypowered.api.util.title.Title;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.kyori.text.Component;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import net.kyori.text.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a player who is connected to the proxy.
|
* Represents a player who is connected to the proxy.
|
||||||
*/
|
*/
|
||||||
public interface Player extends CommandSource, InboundConnection, ChannelMessageSource, ChannelMessageSink {
|
public interface Player extends CommandSource, InboundConnection, ChannelMessageSource,
|
||||||
|
ChannelMessageSink {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the player's current username.
|
* Returns the player's current username.
|
||||||
|
*
|
||||||
* @return the username
|
* @return the username
|
||||||
*/
|
*/
|
||||||
String getUsername();
|
String getUsername();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the player's UUID.
|
* Returns the player's UUID.
|
||||||
|
*
|
||||||
* @return the UUID
|
* @return the UUID
|
||||||
*/
|
*/
|
||||||
UUID getUniqueId();
|
UUID getUniqueId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the server that the player is currently connected to.
|
* Returns the server that the player is currently connected to.
|
||||||
|
*
|
||||||
* @return an {@link Optional} the server that the player is connected to, which may be empty
|
* @return an {@link Optional} the server that the player is connected to, which may be empty
|
||||||
*/
|
*/
|
||||||
Optional<ServerConnection> getCurrentServer();
|
Optional<ServerConnection> getCurrentServer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the player settings
|
* Returns the player settings
|
||||||
|
*
|
||||||
* @return the settings
|
* @return the settings
|
||||||
*/
|
*/
|
||||||
PlayerSettings getPlayerSettings();
|
PlayerSettings getPlayerSettings();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the player's mod info if they have a modded client.
|
* Returns the player's mod info if they have a modded client.
|
||||||
|
*
|
||||||
* @return an {@link Optional} the mod info. which may be empty
|
* @return an {@link Optional} the mod info. which may be empty
|
||||||
*/
|
*/
|
||||||
Optional<ModInfo> getModInfo();
|
Optional<ModInfo> getModInfo();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current player's ping
|
* Returns the current player's ping
|
||||||
|
*
|
||||||
* @return the player's ping or -1 if ping information is currently unknown
|
* @return the player's ping or -1 if ping information is currently unknown
|
||||||
*/
|
*/
|
||||||
long getPing();
|
long getPing();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a chat message to the player's client.
|
* Sends a chat message to the player's client.
|
||||||
|
*
|
||||||
* @param component the chat message to send
|
* @param component the chat message to send
|
||||||
*/
|
*/
|
||||||
default void sendMessage(Component component) {
|
default void sendMessage(Component component) {
|
||||||
@ -67,6 +74,7 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a chat message to the player's client in the specified position.
|
* Sends a chat message to the player's client in the specified position.
|
||||||
|
*
|
||||||
* @param component the chat message to send
|
* @param component the chat message to send
|
||||||
* @param position the position for the message
|
* @param position the position for the message
|
||||||
*/
|
*/
|
||||||
@ -74,6 +82,7 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new connection request so that the player can connect to another server.
|
* Creates a new connection request so that the player can connect to another server.
|
||||||
|
*
|
||||||
* @param server the server to connect to
|
* @param server the server to connect to
|
||||||
* @return a new connection request
|
* @return a new connection request
|
||||||
*/
|
*/
|
||||||
@ -97,6 +106,7 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the tab list header and footer for the player.
|
* Sets the tab list header and footer for the player.
|
||||||
|
*
|
||||||
* @param header the header component
|
* @param header the header component
|
||||||
* @param footer the footer component
|
* @param footer the footer component
|
||||||
* @deprecated Use {@link TabList#setHeaderAndFooter(Component, Component)}.
|
* @deprecated Use {@link TabList#setHeaderAndFooter(Component, Component)}.
|
||||||
@ -106,6 +116,7 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the tab list header and footer for the player.
|
* Clears the tab list header and footer for the player.
|
||||||
|
*
|
||||||
* @deprecated Use {@link TabList#clearHeaderAndFooter()}.
|
* @deprecated Use {@link TabList#clearHeaderAndFooter()}.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@ -113,26 +124,29 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the player's tab list.
|
* Returns the player's tab list.
|
||||||
|
*
|
||||||
* @return this player's tab list
|
* @return this player's tab list
|
||||||
*/
|
*/
|
||||||
TabList getTabList();
|
TabList getTabList();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disconnects the player with the specified reason. Once this method is called, further calls to other {@link Player}
|
* Disconnects the player with the specified reason. Once this method is called, further calls to
|
||||||
* methods will become undefined.
|
* other {@link Player} methods will become undefined.
|
||||||
|
*
|
||||||
* @param reason component with the reason
|
* @param reason component with the reason
|
||||||
*/
|
*/
|
||||||
void disconnect(Component reason);
|
void disconnect(Component reason);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the specified title to the client.
|
* Sends the specified title to the client.
|
||||||
|
*
|
||||||
* @param title the title to send
|
* @param title the title to send
|
||||||
*/
|
*/
|
||||||
void sendTitle(Title title);
|
void sendTitle(Title title);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends chat input onto the players current server as if they typed it
|
* Sends chat input onto the players current server as if they typed it into the client chat box.
|
||||||
* into the client chat box.
|
*
|
||||||
* @param input the chat input to send
|
* @param input the chat input to send
|
||||||
*/
|
*/
|
||||||
void spoofChatInput(String input);
|
void spoofChatInput(String input);
|
||||||
|
@ -10,19 +10,21 @@ import com.velocitypowered.api.proxy.server.RegisteredServer;
|
|||||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||||
import com.velocitypowered.api.scheduler.Scheduler;
|
import com.velocitypowered.api.scheduler.Scheduler;
|
||||||
import com.velocitypowered.api.util.ProxyVersion;
|
import com.velocitypowered.api.util.ProxyVersion;
|
||||||
import net.kyori.text.Component;
|
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import net.kyori.text.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides an interface to a Minecraft server proxy.
|
* Provides an interface to a Minecraft server proxy.
|
||||||
*/
|
*/
|
||||||
public interface ProxyServer {
|
public interface ProxyServer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the player currently connected to this proxy by their Minecraft username. The search is case-insensitive.
|
* Retrieves the player currently connected to this proxy by their Minecraft username. The search
|
||||||
|
* is case-insensitive.
|
||||||
|
*
|
||||||
* @param username the username to search for
|
* @param username the username to search for
|
||||||
* @return an {@link Optional} with the player, which may be empty
|
* @return an {@link Optional} with the player, which may be empty
|
||||||
*/
|
*/
|
||||||
@ -30,6 +32,7 @@ public interface ProxyServer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the player currently connected to this proxy by their Minecraft UUID.
|
* Retrieves the player currently connected to this proxy by their Minecraft UUID.
|
||||||
|
*
|
||||||
* @param uuid the UUID
|
* @param uuid the UUID
|
||||||
* @return an {@link Optional} with the player, which may be empty
|
* @return an {@link Optional} with the player, which may be empty
|
||||||
*/
|
*/
|
||||||
@ -37,25 +40,30 @@ public interface ProxyServer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Broadcasts a message to all players currently online.
|
* Broadcasts a message to all players currently online.
|
||||||
|
*
|
||||||
* @param component the message to send
|
* @param component the message to send
|
||||||
*/
|
*/
|
||||||
void broadcast(Component component);
|
void broadcast(Component component);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves all players currently connected to this proxy. This call may or may not be a snapshot of all players
|
* Retrieves all players currently connected to this proxy. This call may or may not be a snapshot
|
||||||
* online.
|
* of all players online.
|
||||||
|
*
|
||||||
* @return the players online on this proxy
|
* @return the players online on this proxy
|
||||||
*/
|
*/
|
||||||
Collection<Player> getAllPlayers();
|
Collection<Player> getAllPlayers();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of players currently connected to this proxy.
|
* Returns the number of players currently connected to this proxy.
|
||||||
|
*
|
||||||
* @return the players on this proxy
|
* @return the players on this proxy
|
||||||
*/
|
*/
|
||||||
int getPlayerCount();
|
int getPlayerCount();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a registered {@link RegisteredServer} instance by its name. The search is case-insensitive.
|
* Retrieves a registered {@link RegisteredServer} instance by its name. The search is
|
||||||
|
* case-insensitive.
|
||||||
|
*
|
||||||
* @param name the name of the server
|
* @param name the name of the server
|
||||||
* @return the registered server, which may be empty
|
* @return the registered server, which may be empty
|
||||||
*/
|
*/
|
||||||
@ -63,12 +71,14 @@ public interface ProxyServer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves all {@link RegisteredServer}s registered with this proxy.
|
* Retrieves all {@link RegisteredServer}s registered with this proxy.
|
||||||
|
*
|
||||||
* @return the servers registered with this proxy
|
* @return the servers registered with this proxy
|
||||||
*/
|
*/
|
||||||
Collection<RegisteredServer> getAllServers();
|
Collection<RegisteredServer> getAllServers();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a server with this proxy. A server with this name should not already exist.
|
* Registers a server with this proxy. A server with this name should not already exist.
|
||||||
|
*
|
||||||
* @param server the server to register
|
* @param server the server to register
|
||||||
* @return the newly registered server
|
* @return the newly registered server
|
||||||
*/
|
*/
|
||||||
@ -76,14 +86,17 @@ public interface ProxyServer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters this server from the proxy.
|
* Unregisters this server from the proxy.
|
||||||
|
*
|
||||||
* @param server the server to unregister
|
* @param server the server to unregister
|
||||||
*/
|
*/
|
||||||
void unregisterServer(ServerInfo server);
|
void unregisterServer(ServerInfo server);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an instance of {@link CommandSource} that can be used to determine if the command is being invoked by
|
* Returns an instance of {@link CommandSource} that can be used to determine if the command is
|
||||||
* the console or a console-like executor. Plugins that execute commands are strongly urged to implement their own
|
* being invoked by the console or a console-like executor. Plugins that execute commands are
|
||||||
* {@link CommandSource} instead of using the console invoker.
|
* strongly urged to implement their own {@link CommandSource} instead of using the console
|
||||||
|
* invoker.
|
||||||
|
*
|
||||||
* @return the console command invoker
|
* @return the console command invoker
|
||||||
*/
|
*/
|
||||||
CommandSource getConsoleCommandSource();
|
CommandSource getConsoleCommandSource();
|
||||||
@ -104,37 +117,43 @@ public interface ProxyServer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the {@link CommandManager} instance.
|
* Gets the {@link CommandManager} instance.
|
||||||
|
*
|
||||||
* @return the command manager
|
* @return the command manager
|
||||||
*/
|
*/
|
||||||
CommandManager getCommandManager();
|
CommandManager getCommandManager();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the {@link Scheduler} instance.
|
* Gets the {@link Scheduler} instance.
|
||||||
|
*
|
||||||
* @return the scheduler instance
|
* @return the scheduler instance
|
||||||
*/
|
*/
|
||||||
Scheduler getScheduler();
|
Scheduler getScheduler();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the {@link ChannelRegistrar} instance.
|
* Gets the {@link ChannelRegistrar} instance.
|
||||||
|
*
|
||||||
* @return the channel registrar
|
* @return the channel registrar
|
||||||
*/
|
*/
|
||||||
ChannelRegistrar getChannelRegistrar();
|
ChannelRegistrar getChannelRegistrar();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the address that this proxy is bound to. This does not necessarily indicate the external IP address of the
|
* Gets the address that this proxy is bound to. This does not necessarily indicate the external
|
||||||
* proxy.
|
* IP address of the proxy.
|
||||||
|
*
|
||||||
* @return the address the proxy is bound to
|
* @return the address the proxy is bound to
|
||||||
*/
|
*/
|
||||||
InetSocketAddress getBoundAddress();
|
InetSocketAddress getBoundAddress();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the {@link ProxyConfig} instance.
|
* Gets the {@link ProxyConfig} instance.
|
||||||
|
*
|
||||||
* @return the proxy config
|
* @return the proxy config
|
||||||
* */
|
*/
|
||||||
ProxyConfig getConfiguration();
|
ProxyConfig getConfiguration();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the version of the proxy.
|
* Returns the version of the proxy.
|
||||||
|
*
|
||||||
* @return the proxy version
|
* @return the proxy version
|
||||||
*/
|
*/
|
||||||
ProxyVersion getVersion();
|
ProxyVersion getVersion();
|
||||||
|
@ -9,20 +9,24 @@ import com.velocitypowered.api.proxy.server.ServerInfo;
|
|||||||
* Represents a connection to a backend server from the proxy for a client.
|
* Represents a connection to a backend server from the proxy for a client.
|
||||||
*/
|
*/
|
||||||
public interface ServerConnection extends ChannelMessageSource, ChannelMessageSink {
|
public interface ServerConnection extends ChannelMessageSource, ChannelMessageSink {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the server that this connection is connected to.
|
* Returns the server that this connection is connected to.
|
||||||
|
*
|
||||||
* @return the server this connection is connected to
|
* @return the server this connection is connected to
|
||||||
*/
|
*/
|
||||||
RegisteredServer getServer();
|
RegisteredServer getServer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the server info for this connection.
|
* Returns the server info for this connection.
|
||||||
|
*
|
||||||
* @return the server info for this connection
|
* @return the server info for this connection
|
||||||
*/
|
*/
|
||||||
ServerInfo getServerInfo();
|
ServerInfo getServerInfo();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the player that this connection is associated with.
|
* Returns the player that this connection is associated with.
|
||||||
|
*
|
||||||
* @return the player for this connection
|
* @return the player for this connection
|
||||||
*/
|
*/
|
||||||
Player getPlayer();
|
Player getPlayer();
|
||||||
|
@ -1,115 +1,132 @@
|
|||||||
package com.velocitypowered.api.proxy.config;
|
package com.velocitypowered.api.proxy.config;
|
||||||
|
|
||||||
import com.velocitypowered.api.util.Favicon;
|
import com.velocitypowered.api.util.Favicon;
|
||||||
import net.kyori.text.Component;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import net.kyori.text.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides an interface to a proxy configuration
|
* Provides an interface to a proxy configuration
|
||||||
*/
|
*/
|
||||||
public interface ProxyConfig {
|
public interface ProxyConfig {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether GameSpy 4 queries are accepted by the proxy
|
* Whether GameSpy 4 queries are accepted by the proxy
|
||||||
|
*
|
||||||
* @return queries enabled
|
* @return queries enabled
|
||||||
*/
|
*/
|
||||||
boolean isQueryEnabled();
|
boolean isQueryEnabled();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the port GameSpy 4 queries are accepted on
|
* Get the port GameSpy 4 queries are accepted on
|
||||||
|
*
|
||||||
* @return the query port
|
* @return the query port
|
||||||
*/
|
*/
|
||||||
int getQueryPort();
|
int getQueryPort();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the map name reported to GameSpy 4 query services
|
* Get the map name reported to GameSpy 4 query services
|
||||||
|
*
|
||||||
* @return the map name
|
* @return the map name
|
||||||
*/
|
*/
|
||||||
String getQueryMap();
|
String getQueryMap();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether GameSpy 4 queries should show plugins installed on
|
* Whether GameSpy 4 queries should show plugins installed on Velocity by default
|
||||||
* Velocity by default
|
*
|
||||||
* @return show plugins in query
|
* @return show plugins in query
|
||||||
*/
|
*/
|
||||||
boolean shouldQueryShowPlugins();
|
boolean shouldQueryShowPlugins();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the MOTD component shown in the tab list
|
* Get the MOTD component shown in the tab list
|
||||||
|
*
|
||||||
* @return the motd component
|
* @return the motd component
|
||||||
*/
|
*/
|
||||||
Component getMotdComponent();
|
Component getMotdComponent();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the maximum players shown in the tab list
|
* Get the maximum players shown in the tab list
|
||||||
|
*
|
||||||
* @return max players
|
* @return max players
|
||||||
*/
|
*/
|
||||||
int getShowMaxPlayers();
|
int getShowMaxPlayers();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get whether the proxy is online mode. This determines if players are authenticated with Mojang servers.
|
* Get whether the proxy is online mode. This determines if players are authenticated with Mojang
|
||||||
|
* servers.
|
||||||
|
*
|
||||||
* @return online mode enabled
|
* @return online mode enabled
|
||||||
*/
|
*/
|
||||||
boolean isOnlineMode();
|
boolean isOnlineMode();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a Map of all servers registered on this proxy
|
* Get a Map of all servers registered on this proxy
|
||||||
|
*
|
||||||
* @return registered servers map
|
* @return registered servers map
|
||||||
*/
|
*/
|
||||||
Map<String, String> getServers();
|
Map<String, String> getServers();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the order of servers that players will be connected to
|
* Get the order of servers that players will be connected to
|
||||||
|
*
|
||||||
* @return connection order list
|
* @return connection order list
|
||||||
*/
|
*/
|
||||||
List<String> getAttemptConnectionOrder();
|
List<String> getAttemptConnectionOrder();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get forced servers mapped to given virtual host
|
* Get forced servers mapped to given virtual host
|
||||||
|
*
|
||||||
* @return list of server names
|
* @return list of server names
|
||||||
*/
|
*/
|
||||||
Map<String, List<String>> getForcedHosts();
|
Map<String, List<String>> getForcedHosts();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the minimum compression threshold for packets
|
* Get the minimum compression threshold for packets
|
||||||
|
*
|
||||||
* @return the compression threshold
|
* @return the compression threshold
|
||||||
*/
|
*/
|
||||||
int getCompressionThreshold();
|
int getCompressionThreshold();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the level of compression that packets will be compressed to
|
* Get the level of compression that packets will be compressed to
|
||||||
|
*
|
||||||
* @return the compression level
|
* @return the compression level
|
||||||
*/
|
*/
|
||||||
int getCompressionLevel();
|
int getCompressionLevel();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the limit for how long a player must wait to log back in
|
* Get the limit for how long a player must wait to log back in
|
||||||
|
*
|
||||||
* @return the login rate limit (in milliseconds)
|
* @return the login rate limit (in milliseconds)
|
||||||
*/
|
*/
|
||||||
int getLoginRatelimit();
|
int getLoginRatelimit();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the proxy favicon shown in the tablist
|
* Get the proxy favicon shown in the tablist
|
||||||
|
*
|
||||||
* @return optional favicon
|
* @return optional favicon
|
||||||
*/
|
*/
|
||||||
Optional<Favicon> getFavicon();
|
Optional<Favicon> getFavicon();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get whether this proxy displays that it supports Forge/FML
|
* Get whether this proxy displays that it supports Forge/FML
|
||||||
|
*
|
||||||
* @return forge announce enabled
|
* @return forge announce enabled
|
||||||
*/
|
*/
|
||||||
boolean isAnnounceForge();
|
boolean isAnnounceForge();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get how long this proxy will wait until performing a read timeout
|
* Get how long this proxy will wait until performing a read timeout
|
||||||
|
*
|
||||||
* @return connection timeout (in milliseconds)
|
* @return connection timeout (in milliseconds)
|
||||||
*/
|
*/
|
||||||
int getConnectTimeout();
|
int getConnectTimeout();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get how long this proxy will wait until performing a read timeout
|
* Get how long this proxy will wait until performing a read timeout
|
||||||
|
*
|
||||||
* @return read timeout (in milliseconds)
|
* @return read timeout (in milliseconds)
|
||||||
*/
|
*/
|
||||||
int getReadTimeout();
|
int getReadTimeout();
|
||||||
|
@ -4,8 +4,10 @@ package com.velocitypowered.api.proxy.messages;
|
|||||||
* Represents a kind of channel identifier.
|
* Represents a kind of channel identifier.
|
||||||
*/
|
*/
|
||||||
public interface ChannelIdentifier {
|
public interface ChannelIdentifier {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the textual representation of this identifier.
|
* Returns the textual representation of this identifier.
|
||||||
|
*
|
||||||
* @return the textual representation of the identifier
|
* @return the textual representation of the identifier
|
||||||
*/
|
*/
|
||||||
String getId();
|
String getId();
|
||||||
|
@ -4,8 +4,10 @@ package com.velocitypowered.api.proxy.messages;
|
|||||||
* Represents something that can send plugin messages.
|
* Represents something that can send plugin messages.
|
||||||
*/
|
*/
|
||||||
public interface ChannelMessageSink {
|
public interface ChannelMessageSink {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a plugin message to this target.
|
* Sends a plugin message to this target.
|
||||||
|
*
|
||||||
* @param identifier the channel identifier to send the message on
|
* @param identifier the channel identifier to send the message on
|
||||||
* @param data the data to send
|
* @param data the data to send
|
||||||
* @return whether or not the message could be sent
|
* @return whether or not the message could be sent
|
||||||
|
@ -4,4 +4,5 @@ package com.velocitypowered.api.proxy.messages;
|
|||||||
* A marker interface that indicates a source of plugin messages.
|
* A marker interface that indicates a source of plugin messages.
|
||||||
*/
|
*/
|
||||||
public interface ChannelMessageSource {
|
public interface ChannelMessageSource {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,21 @@
|
|||||||
package com.velocitypowered.api.proxy.messages;
|
package com.velocitypowered.api.proxy.messages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an interface to register and unregister {@link ChannelIdentifier}s for the proxy to listen on.
|
* Represents an interface to register and unregister {@link ChannelIdentifier}s for the proxy to
|
||||||
|
* listen on.
|
||||||
*/
|
*/
|
||||||
public interface ChannelRegistrar {
|
public interface ChannelRegistrar {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers the specified message identifiers to listen on for the
|
* Registers the specified message identifiers to listen on for the
|
||||||
|
*
|
||||||
* @param identifiers the channel identifiers to register
|
* @param identifiers the channel identifiers to register
|
||||||
*/
|
*/
|
||||||
void register(ChannelIdentifier... identifiers);
|
void register(ChannelIdentifier... identifiers);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters the handler for the specified channel.
|
* Unregisters the handler for the specified channel.
|
||||||
|
*
|
||||||
* @param identifiers the identifiers to unregister
|
* @param identifiers the identifiers to unregister
|
||||||
*/
|
*/
|
||||||
void unregister(ChannelIdentifier... identifiers);
|
void unregister(ChannelIdentifier... identifiers);
|
||||||
|
@ -2,15 +2,16 @@ package com.velocitypowered.api.proxy.messages;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
import java.util.Objects;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reperesents a legacy channel identifier (for Minecraft 1.12 and below). For modern 1.13 plugin messages, please see
|
* Reperesents a legacy channel identifier (for Minecraft 1.12 and below). For modern 1.13 plugin
|
||||||
* {@link MinecraftChannelIdentifier}. This class is immutable and safe for multi-threaded use.
|
* messages, please see {@link MinecraftChannelIdentifier}. This class is immutable and safe for
|
||||||
|
* multi-threaded use.
|
||||||
*/
|
*/
|
||||||
public final class LegacyChannelIdentifier implements ChannelIdentifier {
|
public final class LegacyChannelIdentifier implements ChannelIdentifier {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
public LegacyChannelIdentifier(String name) {
|
public LegacyChannelIdentifier(String name) {
|
||||||
@ -29,8 +30,12 @@ public final class LegacyChannelIdentifier implements ChannelIdentifier {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object o) {
|
public boolean equals(@Nullable Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
LegacyChannelIdentifier that = (LegacyChannelIdentifier) o;
|
LegacyChannelIdentifier that = (LegacyChannelIdentifier) o;
|
||||||
return Objects.equals(name, that.name);
|
return Objects.equals(name, that.name);
|
||||||
}
|
}
|
||||||
|
@ -2,15 +2,16 @@ package com.velocitypowered.api.proxy.messages;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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\\-_]+");
|
private static final Pattern VALID_IDENTIFIER_REGEX = Pattern.compile("[a-z0-9\\-_]+");
|
||||||
|
|
||||||
private final String namespace;
|
private final String namespace;
|
||||||
@ -22,8 +23,9 @@ public final class MinecraftChannelIdentifier implements ChannelIdentifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an identifier in the default namespace ({@code minecraft}). Plugins are strongly encouraged to provide
|
* Creates an identifier in the default namespace ({@code minecraft}). Plugins are strongly
|
||||||
* their own namespace.
|
* encouraged to provide their own namespace.
|
||||||
|
*
|
||||||
* @param name the name in the default namespace to use
|
* @param name the name in the default namespace to use
|
||||||
* @return a new channel identifier
|
* @return a new channel identifier
|
||||||
*/
|
*/
|
||||||
@ -33,6 +35,7 @@ public final class MinecraftChannelIdentifier implements ChannelIdentifier {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an identifier in the specified namespace.
|
* Creates an identifier in the specified namespace.
|
||||||
|
*
|
||||||
* @param namespace the namespace to use
|
* @param namespace the namespace to use
|
||||||
* @param name the channel name inside the specified namespace
|
* @param name the channel name inside the specified namespace
|
||||||
* @return a new channel identifier
|
* @return a new channel identifier
|
||||||
@ -40,8 +43,10 @@ public final class MinecraftChannelIdentifier implements ChannelIdentifier {
|
|||||||
public static MinecraftChannelIdentifier create(String namespace, String name) {
|
public static MinecraftChannelIdentifier create(String namespace, String name) {
|
||||||
Preconditions.checkArgument(!Strings.isNullOrEmpty(namespace), "namespace is null or empty");
|
Preconditions.checkArgument(!Strings.isNullOrEmpty(namespace), "namespace is null or empty");
|
||||||
Preconditions.checkArgument(!Strings.isNullOrEmpty(name), "namespace is null or empty");
|
Preconditions.checkArgument(!Strings.isNullOrEmpty(name), "namespace is null or empty");
|
||||||
Preconditions.checkArgument(VALID_IDENTIFIER_REGEX.matcher(namespace).matches(), "namespace is not valid");
|
Preconditions.checkArgument(VALID_IDENTIFIER_REGEX.matcher(namespace).matches(),
|
||||||
Preconditions.checkArgument(VALID_IDENTIFIER_REGEX.matcher(name).matches(), "name is not valid");
|
"namespace is not valid");
|
||||||
|
Preconditions
|
||||||
|
.checkArgument(VALID_IDENTIFIER_REGEX.matcher(name).matches(), "name is not valid");
|
||||||
return new MinecraftChannelIdentifier(namespace, name);
|
return new MinecraftChannelIdentifier(namespace, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,8 +65,12 @@ public final class MinecraftChannelIdentifier implements ChannelIdentifier {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object o) {
|
public boolean equals(@Nullable Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
MinecraftChannelIdentifier that = (MinecraftChannelIdentifier) o;
|
MinecraftChannelIdentifier that = (MinecraftChannelIdentifier) o;
|
||||||
return Objects.equals(namespace, that.namespace) &&
|
return Objects.equals(namespace, that.namespace) &&
|
||||||
Objects.equals(name, that.name);
|
Objects.equals(name, that.name);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Provides an interface to receive, handle, and send plugin messages on the proxy from clients and servers.
|
* Provides an interface to receive, handle, and send plugin messages on the proxy from clients and
|
||||||
|
* servers.
|
||||||
*/
|
*/
|
||||||
package com.velocitypowered.api.proxy.messages;
|
package com.velocitypowered.api.proxy.messages;
|
@ -6,39 +6,46 @@ import java.util.Locale;
|
|||||||
* Represents the client settings for the player.
|
* Represents the client settings for the player.
|
||||||
*/
|
*/
|
||||||
public interface PlayerSettings {
|
public interface PlayerSettings {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the locale of the Minecraft client.
|
* Returns the locale of the Minecraft client.
|
||||||
|
*
|
||||||
* @return the client locale
|
* @return the client locale
|
||||||
*/
|
*/
|
||||||
Locale getLocale();
|
Locale getLocale();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the client's view distance. This does not guarantee the client will see this many chunks, since your
|
* Returns the client's view distance. This does not guarantee the client will see this many
|
||||||
* servers are responsible for sending the chunks.
|
* chunks, since your servers are responsible for sending the chunks.
|
||||||
|
*
|
||||||
* @return the client view distance
|
* @return the client view distance
|
||||||
*/
|
*/
|
||||||
byte getViewDistance();
|
byte getViewDistance();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the chat setting for the client.
|
* Returns the chat setting for the client.
|
||||||
|
*
|
||||||
* @return the chat setting
|
* @return the chat setting
|
||||||
*/
|
*/
|
||||||
ChatMode getChatMode();
|
ChatMode getChatMode();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether or not the client has chat colors disabled.
|
* Returns whether or not the client has chat colors disabled.
|
||||||
|
*
|
||||||
* @return whether or not the client has chat colors disabled
|
* @return whether or not the client has chat colors disabled
|
||||||
*/
|
*/
|
||||||
boolean hasChatColors();
|
boolean hasChatColors();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the parts of player skins the client will show.
|
* Returns the parts of player skins the client will show.
|
||||||
|
*
|
||||||
* @return the skin parts for the client
|
* @return the skin parts for the client
|
||||||
*/
|
*/
|
||||||
SkinParts getSkinParts();
|
SkinParts getSkinParts();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the primary hand of the client.
|
* Returns the primary hand of the client.
|
||||||
|
*
|
||||||
* @return the primary hand of the client
|
* @return the primary hand of the client
|
||||||
*/
|
*/
|
||||||
MainHand getMainHand();
|
MainHand getMainHand();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.velocitypowered.api.proxy.player;
|
package com.velocitypowered.api.proxy.player;
|
||||||
|
|
||||||
public final class SkinParts {
|
public final class SkinParts {
|
||||||
|
|
||||||
private final byte bitmask;
|
private final byte bitmask;
|
||||||
|
|
||||||
public SkinParts(byte skinBitmask) {
|
public SkinParts(byte skinBitmask) {
|
||||||
|
@ -2,19 +2,20 @@ package com.velocitypowered.api.proxy.player;
|
|||||||
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.util.GameProfile;
|
import com.velocitypowered.api.util.GameProfile;
|
||||||
import net.kyori.text.Component;
|
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import net.kyori.text.Component;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the tab list of a {@link Player}.
|
* Represents the tab list of a {@link Player}.
|
||||||
*/
|
*/
|
||||||
public interface TabList {
|
public interface TabList {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the tab list header and footer for the player.
|
* Sets the tab list header and footer for the player.
|
||||||
|
*
|
||||||
* @param header the header component
|
* @param header the header component
|
||||||
* @param footer the footer component
|
* @param footer the footer component
|
||||||
*/
|
*/
|
||||||
@ -27,26 +28,30 @@ public interface TabList {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a {@link TabListEntry} to the {@link Player}'s tab list.
|
* Adds a {@link TabListEntry} to the {@link Player}'s tab list.
|
||||||
|
*
|
||||||
* @param entry to add to the tab list
|
* @param entry to add to the tab list
|
||||||
*/
|
*/
|
||||||
void addEntry(TabListEntry entry);
|
void addEntry(TabListEntry entry);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the {@link TabListEntry} from the tab list with the {@link GameProfile}
|
* Removes the {@link TabListEntry} from the tab list with the {@link GameProfile} identified with
|
||||||
* identified with the specified {@link UUID}.
|
* the specified {@link UUID}.
|
||||||
|
*
|
||||||
* @param uuid of the
|
* @param uuid of the
|
||||||
* @return {@link Optional} containing the removed {@link TabListEntry} if present,
|
* @return {@link Optional} containing the removed {@link TabListEntry} if present, otherwise
|
||||||
* otherwise {@link Optional#empty()}
|
* {@link Optional#empty()}
|
||||||
*/
|
*/
|
||||||
Optional<TabListEntry> removeEntry(UUID uuid);
|
Optional<TabListEntry> removeEntry(UUID uuid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an immutable {@link Collection} of the {@link TabListEntry}s in the tab list.
|
* Returns an immutable {@link Collection} of the {@link TabListEntry}s in the tab list.
|
||||||
|
*
|
||||||
* @return immutable {@link Collection} of tab list entries
|
* @return immutable {@link Collection} of tab list entries
|
||||||
*/
|
*/
|
||||||
Collection<TabListEntry> getEntries();
|
Collection<TabListEntry> getEntries();
|
||||||
|
|
||||||
// Necessary because the TabListEntry implementation isn't in the api
|
// Necessary because the TabListEntry implementation isn't in the api
|
||||||
@Deprecated
|
@Deprecated
|
||||||
TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency, int gameMode);
|
TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
|
||||||
|
int gameMode);
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,27 @@
|
|||||||
package com.velocitypowered.api.proxy.player;
|
package com.velocitypowered.api.proxy.player;
|
||||||
|
|
||||||
import com.velocitypowered.api.util.GameProfile;
|
import com.velocitypowered.api.util.GameProfile;
|
||||||
|
import java.util.Optional;
|
||||||
import net.kyori.text.Component;
|
import net.kyori.text.Component;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a single entry in a {@link TabList}.
|
* Represents a single entry in a {@link TabList}.
|
||||||
*/
|
*/
|
||||||
public interface TabListEntry {
|
public interface TabListEntry {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the parent {@link TabList} of this {@code this} {@link TabListEntry}.
|
* Returns the parent {@link TabList} of this {@code this} {@link TabListEntry}.
|
||||||
|
*
|
||||||
* @return parent {@link TabList}
|
* @return parent {@link TabList}
|
||||||
*/
|
*/
|
||||||
TabList getTabList();
|
TabList getTabList();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link GameProfile} of the entry, which uniquely identifies the entry
|
* Returns the {@link GameProfile} of the entry, which uniquely identifies the entry with the
|
||||||
* with the containing {@link java.util.UUID}, as well as deciding what is shown
|
* containing {@link java.util.UUID}, as well as deciding what is shown as the player head in the
|
||||||
* as the player head in the tab list.
|
* tab list.
|
||||||
|
*
|
||||||
* @return {@link GameProfile} of the entry
|
* @return {@link GameProfile} of the entry
|
||||||
*/
|
*/
|
||||||
GameProfile getProfile();
|
GameProfile getProfile();
|
||||||
@ -27,13 +29,15 @@ public interface TabListEntry {
|
|||||||
/**
|
/**
|
||||||
* Returns {@link Optional} text {@link Component}, which if present is the text displayed for
|
* Returns {@link Optional} text {@link Component}, which if present is the text displayed for
|
||||||
* {@code this} entry in the {@link TabList}, otherwise {@link GameProfile#getName()} is shown.
|
* {@code this} entry in the {@link TabList}, otherwise {@link GameProfile#getName()} is shown.
|
||||||
|
*
|
||||||
* @return {@link Optional} text {@link Component} of name displayed in the tab list
|
* @return {@link Optional} text {@link Component} of name displayed in the tab list
|
||||||
*/
|
*/
|
||||||
Optional<Component> getDisplayName();
|
Optional<Component> getDisplayName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the text {@link Component} to be displayed for {@code this} {@link TabListEntry}.
|
* Sets the text {@link Component} to be displayed for {@code this} {@link TabListEntry}. If
|
||||||
* If {@code null}, {@link GameProfile#getName()} will be shown.
|
* {@code null}, {@link GameProfile#getName()} will be shown.
|
||||||
|
*
|
||||||
* @param displayName to show in the {@link TabList} for {@code this} entry
|
* @param displayName to show in the {@link TabList} for {@code this} entry
|
||||||
* @return {@code this}, for chaining
|
* @return {@code this}, for chaining
|
||||||
*/
|
*/
|
||||||
@ -51,15 +55,17 @@ public interface TabListEntry {
|
|||||||
* <li>A latency move than 1 second will display 1 bar</li>
|
* <li>A latency move than 1 second will display 1 bar</li>
|
||||||
* <li></li>
|
* <li></li>
|
||||||
* </ul>
|
* </ul>
|
||||||
|
*
|
||||||
* @return latency set for {@code this} entry
|
* @return latency set for {@code this} entry
|
||||||
*/
|
*/
|
||||||
int getLatency();
|
int getLatency();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the latency for {@code this} entry to the specified value
|
* Sets the latency for {@code this} entry to the specified value
|
||||||
* @see #getLatency()
|
*
|
||||||
* @param latency to changed to
|
* @param latency to changed to
|
||||||
* @return {@code this}, for chaining
|
* @return {@code this}, for chaining
|
||||||
|
* @see #getLatency()
|
||||||
*/
|
*/
|
||||||
TabListEntry setLatency(int latency);
|
TabListEntry setLatency(int latency);
|
||||||
|
|
||||||
@ -72,20 +78,23 @@ public interface TabListEntry {
|
|||||||
* <li>Adventure</li>
|
* <li>Adventure</li>
|
||||||
* <li>Spectator</li>
|
* <li>Spectator</li>
|
||||||
* </ol>
|
* </ol>
|
||||||
|
*
|
||||||
* @return the game mode
|
* @return the game mode
|
||||||
*/
|
*/
|
||||||
int getGameMode();
|
int getGameMode();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the game mode for {@code this} entry to the specified value
|
* Sets the game mode for {@code this} entry to the specified value
|
||||||
* @see #getGameMode()
|
*
|
||||||
* @param gameMode to change to
|
* @param gameMode to change to
|
||||||
* @return {@code this}, for chaining
|
* @return {@code this}, for chaining
|
||||||
|
* @see #getGameMode()
|
||||||
*/
|
*/
|
||||||
TabListEntry setGameMode(int gameMode);
|
TabListEntry setGameMode(int gameMode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link Builder} to create a {@link TabListEntry}.
|
* Returns a {@link Builder} to create a {@link TabListEntry}.
|
||||||
|
*
|
||||||
* @return {@link TabListEntry} builder
|
* @return {@link TabListEntry} builder
|
||||||
*/
|
*/
|
||||||
static Builder builder() {
|
static Builder builder() {
|
||||||
@ -94,20 +103,24 @@ public interface TabListEntry {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a builder which creates {@link TabListEntry}s.
|
* Represents a builder which creates {@link TabListEntry}s.
|
||||||
|
*
|
||||||
* @see TabListEntry
|
* @see TabListEntry
|
||||||
*/
|
*/
|
||||||
class Builder {
|
class Builder {
|
||||||
|
|
||||||
private @Nullable TabList tabList;
|
private @Nullable TabList tabList;
|
||||||
private @Nullable GameProfile profile;
|
private @Nullable GameProfile profile;
|
||||||
private @Nullable Component displayName;
|
private @Nullable Component displayName;
|
||||||
private int latency = 0;
|
private int latency = 0;
|
||||||
private int gameMode = 0;
|
private int gameMode = 0;
|
||||||
|
|
||||||
private Builder() {}
|
private Builder() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the parent {@link TabList} for this entry,
|
* Sets the parent {@link TabList} for this entry, the entry will only be able to be added to
|
||||||
* the entry will only be able to be added to that specific {@link TabList}.
|
* that specific {@link TabList}.
|
||||||
|
*
|
||||||
* @param tabList to set
|
* @param tabList to set
|
||||||
* @return {@code this}, for chaining
|
* @return {@code this}, for chaining
|
||||||
*/
|
*/
|
||||||
@ -118,9 +131,10 @@ public interface TabListEntry {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the {@link GameProfile} of the {@link TabListEntry}.
|
* Sets the {@link GameProfile} of the {@link TabListEntry}.
|
||||||
* @see TabListEntry#getProfile()
|
*
|
||||||
* @param profile to set
|
* @param profile to set
|
||||||
* @return {@code this}, for chaining
|
* @return {@code this}, for chaining
|
||||||
|
* @see TabListEntry#getProfile()
|
||||||
*/
|
*/
|
||||||
public Builder profile(GameProfile profile) {
|
public Builder profile(GameProfile profile) {
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
@ -129,9 +143,10 @@ public interface TabListEntry {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the displayed name of the {@link TabListEntry}
|
* Sets the displayed name of the {@link TabListEntry}
|
||||||
* @see TabListEntry#getDisplayName()
|
*
|
||||||
* @param displayName to set
|
* @param displayName to set
|
||||||
* @return {@code this}, for chaining
|
* @return {@code this}, for chaining
|
||||||
|
* @see TabListEntry#getDisplayName()
|
||||||
*/
|
*/
|
||||||
public Builder displayName(@Nullable Component displayName) {
|
public Builder displayName(@Nullable Component displayName) {
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
@ -140,9 +155,10 @@ public interface TabListEntry {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the latency of the {@link TabListEntry}
|
* Sets the latency of the {@link TabListEntry}
|
||||||
* @see TabListEntry#getLatency()
|
*
|
||||||
* @param latency to set
|
* @param latency to set
|
||||||
* @return {@code this}, for chaining
|
* @return {@code this}, for chaining
|
||||||
|
* @see TabListEntry#getLatency()
|
||||||
*/
|
*/
|
||||||
public Builder latency(int latency) {
|
public Builder latency(int latency) {
|
||||||
this.latency = latency;
|
this.latency = latency;
|
||||||
@ -151,9 +167,10 @@ public interface TabListEntry {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the game mode of the {@link TabListEntry}
|
* Sets the game mode of the {@link TabListEntry}
|
||||||
* @see TabListEntry#getGameMode()
|
*
|
||||||
* @param gameMode to set
|
* @param gameMode to set
|
||||||
* @return {@code this}, for chaining
|
* @return {@code this}, for chaining
|
||||||
|
* @see TabListEntry#getGameMode()
|
||||||
*/
|
*/
|
||||||
public Builder gameMode(int gameMode) {
|
public Builder gameMode(int gameMode) {
|
||||||
this.gameMode = gameMode;
|
this.gameMode = gameMode;
|
||||||
@ -162,6 +179,7 @@ public interface TabListEntry {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs the {@link TabListEntry} specified by {@code this} {@link Builder}.
|
* Constructs the {@link TabListEntry} specified by {@code this} {@link Builder}.
|
||||||
|
*
|
||||||
* @return the constructed {@link TabListEntry}
|
* @return the constructed {@link TabListEntry}
|
||||||
*/
|
*/
|
||||||
public TabListEntry build() {
|
public TabListEntry build() {
|
||||||
|
@ -3,18 +3,18 @@ package com.velocitypowered.api.proxy.server;
|
|||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.velocitypowered.api.proxy.config.ProxyConfig;
|
import com.velocitypowered.api.proxy.config.ProxyConfig;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GS4 query response. This class is immutable.
|
* GS4 query response. This class is immutable.
|
||||||
*/
|
*/
|
||||||
public final class QueryResponse {
|
public final class QueryResponse {
|
||||||
|
|
||||||
private final String hostname;
|
private final String hostname;
|
||||||
private final String gameVersion;
|
private final String gameVersion;
|
||||||
private final String map;
|
private final String map;
|
||||||
@ -26,7 +26,9 @@ public final class QueryResponse {
|
|||||||
private final String proxyVersion;
|
private final String proxyVersion;
|
||||||
private final Collection<PluginInformation> plugins;
|
private final Collection<PluginInformation> plugins;
|
||||||
|
|
||||||
private QueryResponse(String hostname, String gameVersion, String map, int currentPlayers, int maxPlayers, String proxyHost, int proxyPort, Collection<String> players, String proxyVersion, Collection<PluginInformation> plugins) {
|
private QueryResponse(String hostname, String gameVersion, String map, int currentPlayers,
|
||||||
|
int maxPlayers, String proxyHost, int proxyPort, Collection<String> players,
|
||||||
|
String proxyVersion, Collection<PluginInformation> plugins) {
|
||||||
this.hostname = hostname;
|
this.hostname = hostname;
|
||||||
this.gameVersion = gameVersion;
|
this.gameVersion = gameVersion;
|
||||||
this.map = map;
|
this.map = map;
|
||||||
@ -40,7 +42,9 @@ public final class QueryResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get hostname which will be used to reply to the query. By default it is {@link ProxyConfig#getMotdComponent()} in plain text without colour codes.
|
* Get hostname which will be used to reply to the query. By default it is {@link
|
||||||
|
* ProxyConfig#getMotdComponent()} in plain text without colour codes.
|
||||||
|
*
|
||||||
* @return hostname
|
* @return hostname
|
||||||
*/
|
*/
|
||||||
public String getHostname() {
|
public String getHostname() {
|
||||||
@ -48,7 +52,9 @@ public final class QueryResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get game version which will be used to reply to the query. By default supported Minecraft versions range is sent.
|
* Get game version which will be used to reply to the query. By default supported Minecraft
|
||||||
|
* versions range is sent.
|
||||||
|
*
|
||||||
* @return game version
|
* @return game version
|
||||||
*/
|
*/
|
||||||
public String getGameVersion() {
|
public String getGameVersion() {
|
||||||
@ -56,7 +62,9 @@ public final class QueryResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get map name which will be used to reply to the query. By default {@link ProxyConfig#getQueryMap()} is sent.
|
* Get map name which will be used to reply to the query. By default {@link
|
||||||
|
* ProxyConfig#getQueryMap()} is sent.
|
||||||
|
*
|
||||||
* @return map name
|
* @return map name
|
||||||
*/
|
*/
|
||||||
public String getMap() {
|
public String getMap() {
|
||||||
@ -65,6 +73,7 @@ public final class QueryResponse {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current online player count which will be used to reply to the query.
|
* Get current online player count which will be used to reply to the query.
|
||||||
|
*
|
||||||
* @return online player count
|
* @return online player count
|
||||||
*/
|
*/
|
||||||
public int getCurrentPlayers() {
|
public int getCurrentPlayers() {
|
||||||
@ -73,6 +82,7 @@ public final class QueryResponse {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get max player count which will be used to reply to the query.
|
* Get max player count which will be used to reply to the query.
|
||||||
|
*
|
||||||
* @return max player count
|
* @return max player count
|
||||||
*/
|
*/
|
||||||
public int getMaxPlayers() {
|
public int getMaxPlayers() {
|
||||||
@ -81,6 +91,7 @@ public final class QueryResponse {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get proxy (public facing) hostname
|
* Get proxy (public facing) hostname
|
||||||
|
*
|
||||||
* @return proxy hostname
|
* @return proxy hostname
|
||||||
*/
|
*/
|
||||||
public String getProxyHost() {
|
public String getProxyHost() {
|
||||||
@ -89,6 +100,7 @@ public final class QueryResponse {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get proxy (public facing) port
|
* Get proxy (public facing) port
|
||||||
|
*
|
||||||
* @return proxy port
|
* @return proxy port
|
||||||
*/
|
*/
|
||||||
public int getProxyPort() {
|
public int getProxyPort() {
|
||||||
@ -97,6 +109,7 @@ public final class QueryResponse {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get collection of players which will be used to reply to the query.
|
* Get collection of players which will be used to reply to the query.
|
||||||
|
*
|
||||||
* @return collection of players
|
* @return collection of players
|
||||||
*/
|
*/
|
||||||
public Collection<String> getPlayers() {
|
public Collection<String> getPlayers() {
|
||||||
@ -105,6 +118,7 @@ public final class QueryResponse {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get server software (name and version) which will be used to reply to the query.
|
* Get server software (name and version) which will be used to reply to the query.
|
||||||
|
*
|
||||||
* @return server software
|
* @return server software
|
||||||
*/
|
*/
|
||||||
public String getProxyVersion() {
|
public String getProxyVersion() {
|
||||||
@ -113,6 +127,7 @@ public final class QueryResponse {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get list of plugins which will be used to reply to the query.
|
* Get list of plugins which will be used to reply to the query.
|
||||||
|
*
|
||||||
* @return collection of plugins
|
* @return collection of plugins
|
||||||
*/
|
*/
|
||||||
public Collection<PluginInformation> getPlugins() {
|
public Collection<PluginInformation> getPlugins() {
|
||||||
@ -122,6 +137,7 @@ public final class QueryResponse {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link Builder} instance from data represented by this response
|
* Creates a new {@link Builder} instance from data represented by this response
|
||||||
|
*
|
||||||
* @return {@link QueryResponse} builder
|
* @return {@link QueryResponse} builder
|
||||||
*/
|
*/
|
||||||
public Builder toBuilder() {
|
public Builder toBuilder() {
|
||||||
@ -140,6 +156,7 @@ public final class QueryResponse {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link Builder} instance
|
* Creates a new {@link Builder} instance
|
||||||
|
*
|
||||||
* @return {@link QueryResponse} builder
|
* @return {@link QueryResponse} builder
|
||||||
*/
|
*/
|
||||||
public static Builder builder() {
|
public static Builder builder() {
|
||||||
@ -150,6 +167,7 @@ public final class QueryResponse {
|
|||||||
* A builder for {@link QueryResponse} objects.
|
* A builder for {@link QueryResponse} objects.
|
||||||
*/
|
*/
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
|
|
||||||
@MonotonicNonNull
|
@MonotonicNonNull
|
||||||
private String hostname;
|
private String hostname;
|
||||||
|
|
||||||
@ -172,7 +190,8 @@ public final class QueryResponse {
|
|||||||
private List<String> players = new ArrayList<>();
|
private List<String> players = new ArrayList<>();
|
||||||
private List<PluginInformation> plugins = new ArrayList<>();
|
private List<PluginInformation> plugins = new ArrayList<>();
|
||||||
|
|
||||||
private Builder() {}
|
private Builder() {
|
||||||
|
}
|
||||||
|
|
||||||
public Builder hostname(String hostname) {
|
public Builder hostname(String hostname) {
|
||||||
this.hostname = Preconditions.checkNotNull(hostname, "hostname");
|
this.hostname = Preconditions.checkNotNull(hostname, "hostname");
|
||||||
@ -207,7 +226,8 @@ public final class QueryResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Builder proxyPort(int proxyPort) {
|
public Builder proxyPort(int proxyPort) {
|
||||||
Preconditions.checkArgument(proxyPort >= 1 && proxyPort <= 65535, "proxyPort must be between 1-65535");
|
Preconditions
|
||||||
|
.checkArgument(proxyPort >= 1 && proxyPort <= 65535, "proxyPort must be between 1-65535");
|
||||||
this.proxyPort = proxyPort;
|
this.proxyPort = proxyPort;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -249,6 +269,7 @@ public final class QueryResponse {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds new {@link QueryResponse} with supplied data
|
* Builds new {@link QueryResponse} with supplied data
|
||||||
|
*
|
||||||
* @return response
|
* @return response
|
||||||
*/
|
*/
|
||||||
public QueryResponse build() {
|
public QueryResponse build() {
|
||||||
@ -271,6 +292,7 @@ public final class QueryResponse {
|
|||||||
* Plugin information
|
* Plugin information
|
||||||
*/
|
*/
|
||||||
public static class PluginInformation {
|
public static class PluginInformation {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package com.velocitypowered.api.proxy.server;
|
|||||||
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.messages.ChannelMessageSink;
|
import com.velocitypowered.api.proxy.messages.ChannelMessageSink;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@ -10,20 +9,24 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
* Represents a server that has been registered with the proxy.
|
* Represents a server that has been registered with the proxy.
|
||||||
*/
|
*/
|
||||||
public interface RegisteredServer extends ChannelMessageSink {
|
public interface RegisteredServer extends ChannelMessageSink {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link ServerInfo} for this server.
|
* Returns the {@link ServerInfo} for this server.
|
||||||
|
*
|
||||||
* @return the server info
|
* @return the server info
|
||||||
*/
|
*/
|
||||||
ServerInfo getServerInfo();
|
ServerInfo getServerInfo();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of all the players currently connected to this server on this proxy.
|
* Returns a list of all the players currently connected to this server on this proxy.
|
||||||
|
*
|
||||||
* @return the players on this proxy
|
* @return the players on this proxy
|
||||||
*/
|
*/
|
||||||
Collection<Player> getPlayersConnected();
|
Collection<Player> getPlayersConnected();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to ping the remote server and return the server list ping result.
|
* Attempts to ping the remote server and return the server list ping result.
|
||||||
|
*
|
||||||
* @return the server ping result from the server
|
* @return the server ping result from the server
|
||||||
*/
|
*/
|
||||||
CompletableFuture<ServerPing> ping();
|
CompletableFuture<ServerPing> ping();
|
||||||
|
@ -1,20 +1,22 @@
|
|||||||
package com.velocitypowered.api.proxy.server;
|
package com.velocitypowered.api.proxy.server;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ServerInfo represents a server that a player can connect to. This object is immutable and safe for concurrent access.
|
* ServerInfo represents a server that a player can connect to. This object is immutable and safe
|
||||||
|
* for concurrent access.
|
||||||
*/
|
*/
|
||||||
public final class ServerInfo {
|
public final class ServerInfo {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final InetSocketAddress address;
|
private final InetSocketAddress address;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new ServerInfo object.
|
* Creates a new ServerInfo object.
|
||||||
|
*
|
||||||
* @param name the name for the server
|
* @param name the name for the server
|
||||||
* @param address the address of the server to connect to
|
* @param address the address of the server to connect to
|
||||||
*/
|
*/
|
||||||
@ -41,8 +43,12 @@ public final class ServerInfo {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean equals(@Nullable Object o) {
|
public final boolean equals(@Nullable Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
ServerInfo that = (ServerInfo) o;
|
ServerInfo that = (ServerInfo) o;
|
||||||
return Objects.equals(name, that.name) &&
|
return Objects.equals(name, that.name) &&
|
||||||
Objects.equals(address, that.address);
|
Objects.equals(address, that.address);
|
||||||
|
@ -4,26 +4,32 @@ import com.google.common.base.Preconditions;
|
|||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.velocitypowered.api.util.Favicon;
|
import com.velocitypowered.api.util.Favicon;
|
||||||
import com.velocitypowered.api.util.ModInfo;
|
import com.velocitypowered.api.util.ModInfo;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
import net.kyori.text.Component;
|
import net.kyori.text.Component;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a 1.7 and above server list ping response. This class is immutable.
|
* Represents a 1.7 and above server list ping response. This class is immutable.
|
||||||
*/
|
*/
|
||||||
public final class ServerPing {
|
public final class ServerPing {
|
||||||
|
|
||||||
private final Version version;
|
private final Version version;
|
||||||
private final @Nullable Players players;
|
private final @Nullable Players players;
|
||||||
private final Component description;
|
private final Component description;
|
||||||
private final @Nullable Favicon favicon;
|
private final @Nullable Favicon favicon;
|
||||||
private final @Nullable ModInfo modinfo;
|
private final @Nullable ModInfo modinfo;
|
||||||
|
|
||||||
public ServerPing(Version version, @Nullable Players players, Component description, @Nullable Favicon favicon) {
|
public ServerPing(Version version, @Nullable Players players, Component description,
|
||||||
|
@Nullable Favicon favicon) {
|
||||||
this(version, players, description, favicon, ModInfo.DEFAULT);
|
this(version, players, description, favicon, ModInfo.DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServerPing(Version version, @Nullable Players players, Component description, @Nullable Favicon favicon, @Nullable ModInfo modinfo) {
|
public ServerPing(Version version, @Nullable Players players, Component description,
|
||||||
|
@Nullable Favicon favicon, @Nullable ModInfo modinfo) {
|
||||||
this.version = Preconditions.checkNotNull(version, "version");
|
this.version = Preconditions.checkNotNull(version, "version");
|
||||||
this.players = players;
|
this.players = players;
|
||||||
this.description = Preconditions.checkNotNull(description, "description");
|
this.description = Preconditions.checkNotNull(description, "description");
|
||||||
@ -89,6 +95,7 @@ public final class ServerPing {
|
|||||||
* A builder for {@link ServerPing} objects.
|
* A builder for {@link ServerPing} objects.
|
||||||
*/
|
*/
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
|
|
||||||
private Version version = new Version(0, "Unknown");
|
private Version version = new Version(0, "Unknown");
|
||||||
private int onlinePlayers;
|
private int onlinePlayers;
|
||||||
private int maximumPlayers;
|
private int maximumPlayers;
|
||||||
@ -171,7 +178,8 @@ public final class ServerPing {
|
|||||||
if (this.description == null) {
|
if (this.description == null) {
|
||||||
throw new IllegalStateException("no server description supplied");
|
throw new IllegalStateException("no server description supplied");
|
||||||
}
|
}
|
||||||
return new ServerPing(version, nullOutPlayers ? null : new Players(onlinePlayers, maximumPlayers, samplePlayers),
|
return new ServerPing(version,
|
||||||
|
nullOutPlayers ? null : new Players(onlinePlayers, maximumPlayers, samplePlayers),
|
||||||
description, favicon, nullOutModinfo ? null : new ModInfo(modType, mods));
|
description, favicon, nullOutModinfo ? null : new ModInfo(modType, mods));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,6 +233,7 @@ public final class ServerPing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final class Version {
|
public static final class Version {
|
||||||
|
|
||||||
private final int protocol;
|
private final int protocol;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
@ -251,6 +260,7 @@ public final class ServerPing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final class Players {
|
public static final class Players {
|
||||||
|
|
||||||
private final int online;
|
private final int online;
|
||||||
private final int max;
|
private final int max;
|
||||||
private final List<SamplePlayer> sample;
|
private final List<SamplePlayer> sample;
|
||||||
@ -284,6 +294,7 @@ public final class ServerPing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final class SamplePlayer {
|
public static final class SamplePlayer {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final UUID id;
|
private final UUID id;
|
||||||
|
|
||||||
|
@ -4,21 +4,24 @@ package com.velocitypowered.api.scheduler;
|
|||||||
* Represents a task that is scheduled to run on the proxy.
|
* Represents a task that is scheduled to run on the proxy.
|
||||||
*/
|
*/
|
||||||
public interface ScheduledTask {
|
public interface ScheduledTask {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the plugin that scheduled this task.
|
* Returns the plugin that scheduled this task.
|
||||||
|
*
|
||||||
* @return the plugin that scheduled this task
|
* @return the plugin that scheduled this task
|
||||||
*/
|
*/
|
||||||
Object plugin();
|
Object plugin();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current status of this task.
|
* Returns the current status of this task.
|
||||||
|
*
|
||||||
* @return the current status of this task
|
* @return the current status of this task
|
||||||
*/
|
*/
|
||||||
TaskStatus status();
|
TaskStatus status();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancels this task. If the task is already running, the thread in which it is running will be interrupted.
|
* Cancels this task. If the task is already running, the thread in which it is running will be
|
||||||
* If the task is not currently running, Velocity will terminate it safely.
|
* interrupted. If the task is not currently running, Velocity will terminate it safely.
|
||||||
*/
|
*/
|
||||||
void cancel();
|
void cancel();
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
package com.velocitypowered.api.scheduler;
|
package com.velocitypowered.api.scheduler;
|
||||||
|
|
||||||
import org.checkerframework.common.value.qual.IntRange;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import org.checkerframework.common.value.qual.IntRange;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a scheduler to execute tasks on the proxy.
|
* Represents a scheduler to execute tasks on the proxy.
|
||||||
*/
|
*/
|
||||||
public interface Scheduler {
|
public interface Scheduler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a new {@link TaskBuilder} for creating a task on the proxy.
|
* Initializes a new {@link TaskBuilder} for creating a task on the proxy.
|
||||||
|
*
|
||||||
* @param plugin the plugin to request the task for
|
* @param plugin the plugin to request the task for
|
||||||
* @param runnable the task to run when scheduled
|
* @param runnable the task to run when scheduled
|
||||||
* @return the task builder
|
* @return the task builder
|
||||||
@ -20,8 +21,10 @@ public interface Scheduler {
|
|||||||
* Represents a fluent interface to schedule tasks on the proxy.
|
* Represents a fluent interface to schedule tasks on the proxy.
|
||||||
*/
|
*/
|
||||||
interface TaskBuilder {
|
interface TaskBuilder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies that the task should delay its execution by the specified amount of time.
|
* Specifies that the task should delay its execution by the specified amount of time.
|
||||||
|
*
|
||||||
* @param time the time to delay by
|
* @param time the time to delay by
|
||||||
* @param unit the unit of time for {@code time}
|
* @param unit the unit of time for {@code time}
|
||||||
* @return this builder, for chaining
|
* @return this builder, for chaining
|
||||||
@ -29,7 +32,9 @@ public interface Scheduler {
|
|||||||
TaskBuilder delay(@IntRange(from = 0) long time, TimeUnit unit);
|
TaskBuilder delay(@IntRange(from = 0) long time, TimeUnit unit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies that the task should continue running after waiting for the specified amount, until it is cancelled.
|
* Specifies that the task should continue running after waiting for the specified amount, until
|
||||||
|
* it is cancelled.
|
||||||
|
*
|
||||||
* @param time the time to delay by
|
* @param time the time to delay by
|
||||||
* @param unit the unit of time for {@code time}
|
* @param unit the unit of time for {@code time}
|
||||||
* @return this builder, for chaining
|
* @return this builder, for chaining
|
||||||
@ -38,18 +43,21 @@ public interface Scheduler {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the delay on this task.
|
* Clears the delay on this task.
|
||||||
|
*
|
||||||
* @return this builder, for chaining
|
* @return this builder, for chaining
|
||||||
*/
|
*/
|
||||||
TaskBuilder clearDelay();
|
TaskBuilder clearDelay();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the repeat interval on this task.
|
* Clears the repeat interval on this task.
|
||||||
|
*
|
||||||
* @return this builder, for chaining
|
* @return this builder, for chaining
|
||||||
*/
|
*/
|
||||||
TaskBuilder clearRepeat();
|
TaskBuilder clearRepeat();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schedules this task for execution.
|
* Schedules this task for execution.
|
||||||
|
*
|
||||||
* @return the scheduled task
|
* @return the scheduled task
|
||||||
*/
|
*/
|
||||||
ScheduledTask schedule();
|
ScheduledTask schedule();
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package com.velocitypowered.api.util;
|
package com.velocitypowered.api.util;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -12,17 +9,22 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a Minecraft server favicon. A Minecraft server favicon is a 64x64 image that can be displayed to a remote
|
* Represents a Minecraft server favicon. A Minecraft server favicon is a 64x64 image that can be
|
||||||
* client that sends a Server List Ping packet, and is automatically displayed in the Minecraft client.
|
* displayed to a remote client that sends a Server List Ping packet, and is automatically displayed
|
||||||
|
* in the Minecraft client.
|
||||||
*/
|
*/
|
||||||
public final class Favicon {
|
public final class Favicon {
|
||||||
|
|
||||||
private final String base64Url;
|
private final String base64Url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Directly create a favicon using its Base64 URL directly. You are generally better served by the create() series
|
* Directly create a favicon using its Base64 URL directly. You are generally better served by the
|
||||||
* of functions.
|
* create() series of functions.
|
||||||
|
*
|
||||||
* @param base64Url the url for use with this favicon
|
* @param base64Url the url for use with this favicon
|
||||||
*/
|
*/
|
||||||
public Favicon(String base64Url) {
|
public Favicon(String base64Url) {
|
||||||
@ -31,6 +33,7 @@ public final class Favicon {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Base64-encoded URI for this image.
|
* Returns the Base64-encoded URI for this image.
|
||||||
|
*
|
||||||
* @return a URL representing this favicon
|
* @return a URL representing this favicon
|
||||||
*/
|
*/
|
||||||
public String getBase64Url() {
|
public String getBase64Url() {
|
||||||
@ -39,8 +42,12 @@ public final class Favicon {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object o) {
|
public boolean equals(@Nullable Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Favicon favicon = (Favicon) o;
|
Favicon favicon = (Favicon) o;
|
||||||
return Objects.equals(base64Url, favicon.base64Url);
|
return Objects.equals(base64Url, favicon.base64Url);
|
||||||
}
|
}
|
||||||
@ -59,12 +66,14 @@ public final class Favicon {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@code Favicon} from the specified {@code image}.
|
* Creates a new {@code Favicon} from the specified {@code image}.
|
||||||
|
*
|
||||||
* @param image the image to use for the favicon
|
* @param image the image to use for the favicon
|
||||||
* @return the created {@link Favicon} instance
|
* @return the created {@link Favicon} instance
|
||||||
*/
|
*/
|
||||||
public static Favicon create(BufferedImage image) {
|
public static Favicon create(BufferedImage image) {
|
||||||
Preconditions.checkNotNull(image, "image");
|
Preconditions.checkNotNull(image, "image");
|
||||||
Preconditions.checkArgument(image.getWidth() == 64 && image.getHeight() == 64, "Image does not have" +
|
Preconditions
|
||||||
|
.checkArgument(image.getWidth() == 64 && image.getHeight() == 64, "Image does not have" +
|
||||||
" 64x64 dimensions (found %sx%s)", image.getWidth(), image.getHeight());
|
" 64x64 dimensions (found %sx%s)", image.getWidth(), image.getHeight());
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
try {
|
try {
|
||||||
@ -72,11 +81,13 @@ public final class Favicon {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
}
|
}
|
||||||
return new Favicon("data:image/png;base64," + Base64.getEncoder().encodeToString(os.toByteArray()));
|
return new Favicon(
|
||||||
|
"data:image/png;base64," + Base64.getEncoder().encodeToString(os.toByteArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@code Favicon} by reading the image from the specified {@code path}.
|
* Creates a new {@code Favicon} by reading the image from the specified {@code path}.
|
||||||
|
*
|
||||||
* @param path the path to the image to create a favicon for
|
* @param path the path to the image to create a favicon for
|
||||||
* @return the created {@link Favicon} instance
|
* @return the created {@link Favicon} instance
|
||||||
* @throws IOException if the file could not be read from the path
|
* @throws IOException if the file could not be read from the path
|
||||||
|
@ -2,7 +2,6 @@ package com.velocitypowered.api.util;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -10,6 +9,7 @@ import java.util.UUID;
|
|||||||
* Represents a Mojang game profile. This class is immutable.
|
* Represents a Mojang game profile. This class is immutable.
|
||||||
*/
|
*/
|
||||||
public final class GameProfile {
|
public final class GameProfile {
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final List<Property> properties;
|
private final List<Property> properties;
|
||||||
@ -38,6 +38,7 @@ public final class GameProfile {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a game profile suitable for use in offline-mode.
|
* Creates a game profile suitable for use in offline-mode.
|
||||||
|
*
|
||||||
* @param username the username to use
|
* @param username the username to use
|
||||||
* @return the new offline-mode game profile
|
* @return the new offline-mode game profile
|
||||||
*/
|
*/
|
||||||
@ -57,6 +58,7 @@ public final class GameProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final class Property {
|
public static final class Property {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String value;
|
private final String value;
|
||||||
private final String signature;
|
private final String signature;
|
||||||
|
@ -5,7 +5,8 @@ package com.velocitypowered.api.util;
|
|||||||
*/
|
*/
|
||||||
public enum MessagePosition {
|
public enum MessagePosition {
|
||||||
/**
|
/**
|
||||||
* The chat message will appear in the client's HUD. These messages can be filtered out by the client.
|
* The chat message will appear in the client's HUD. These messages can be filtered out by the
|
||||||
|
* client.
|
||||||
*/
|
*/
|
||||||
CHAT,
|
CHAT,
|
||||||
/**
|
/**
|
||||||
@ -13,8 +14,8 @@ public enum MessagePosition {
|
|||||||
*/
|
*/
|
||||||
SYSTEM,
|
SYSTEM,
|
||||||
/**
|
/**
|
||||||
* The chat message will appear above the player's main HUD. This text format doesn't support many component features,
|
* The chat message will appear above the player's main HUD. This text format doesn't support many
|
||||||
* such as hover events.
|
* component features, such as hover events.
|
||||||
*/
|
*/
|
||||||
ACTION_BAR
|
ACTION_BAR
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,10 @@ package com.velocitypowered.api.util;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public final class ModInfo {
|
public final class ModInfo {
|
||||||
|
|
||||||
public static final ModInfo DEFAULT = new ModInfo("FML", ImmutableList.of());
|
public static final ModInfo DEFAULT = new ModInfo("FML", ImmutableList.of());
|
||||||
|
|
||||||
private final String type;
|
private final String type;
|
||||||
@ -33,6 +33,7 @@ public final class ModInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final class Mod {
|
public static final class Mod {
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
private final String version;
|
private final String version;
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
package com.velocitypowered.api.util;
|
package com.velocitypowered.api.util;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a version object for the proxy.
|
* Provides a version object for the proxy.
|
||||||
*/
|
*/
|
||||||
public final class ProxyVersion {
|
public final class ProxyVersion {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String vendor;
|
private final String vendor;
|
||||||
private final String version;
|
private final String version;
|
||||||
@ -33,8 +33,12 @@ public final class ProxyVersion {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object o) {
|
public boolean equals(@Nullable Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
ProxyVersion that = (ProxyVersion) o;
|
ProxyVersion that = (ProxyVersion) o;
|
||||||
return Objects.equals(name, that.name) &&
|
return Objects.equals(name, that.name) &&
|
||||||
Objects.equals(vendor, that.vendor) &&
|
Objects.equals(vendor, that.vendor) &&
|
||||||
|
@ -2,7 +2,6 @@ package com.velocitypowered.api.util;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -11,12 +10,14 @@ import java.util.UUID;
|
|||||||
* Provides a small, useful selection of utilities for working with Minecraft UUIDs.
|
* Provides a small, useful selection of utilities for working with Minecraft UUIDs.
|
||||||
*/
|
*/
|
||||||
public final class UuidUtils {
|
public final class UuidUtils {
|
||||||
|
|
||||||
private UuidUtils() {
|
private UuidUtils() {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts from an undashed Mojang-style UUID into a Java {@link UUID} object.
|
* Converts from an undashed Mojang-style UUID into a Java {@link UUID} object.
|
||||||
|
*
|
||||||
* @param string the string to convert
|
* @param string the string to convert
|
||||||
* @return the UUID object
|
* @return the UUID object
|
||||||
*/
|
*/
|
||||||
@ -31,6 +32,7 @@ public final class UuidUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts from a Java {@link UUID} object into an undashed Mojang-style UUID.
|
* Converts from a Java {@link UUID} object into an undashed Mojang-style UUID.
|
||||||
|
*
|
||||||
* @param uuid the UUID to convert
|
* @param uuid the UUID to convert
|
||||||
* @return the undashed UUID
|
* @return the undashed UUID
|
||||||
*/
|
*/
|
||||||
@ -42,6 +44,7 @@ public final class UuidUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a UUID for use for offline mode.
|
* Generates a UUID for use for offline mode.
|
||||||
|
*
|
||||||
* @param username the username to use
|
* @param username the username to use
|
||||||
* @return the offline mode UUID
|
* @return the offline mode UUID
|
||||||
*/
|
*/
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
package com.velocitypowered.api.util.title;
|
package com.velocitypowered.api.util.title;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import net.kyori.text.Component;
|
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import net.kyori.text.Component;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a "full" title, including all components. This class is immutable.
|
* Represents a "full" title, including all components. This class is immutable.
|
||||||
*/
|
*/
|
||||||
public final class TextTitle implements Title {
|
public final class TextTitle implements Title {
|
||||||
|
|
||||||
private final @Nullable Component title;
|
private final @Nullable Component title;
|
||||||
private final @Nullable Component subtitle;
|
private final @Nullable Component subtitle;
|
||||||
private final int stay;
|
private final int stay;
|
||||||
@ -29,6 +29,7 @@ public final class TextTitle implements Title {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the main title this title has, if any.
|
* Returns the main title this title has, if any.
|
||||||
|
*
|
||||||
* @return the main title of this title
|
* @return the main title of this title
|
||||||
*/
|
*/
|
||||||
public Optional<Component> getTitle() {
|
public Optional<Component> getTitle() {
|
||||||
@ -37,6 +38,7 @@ public final class TextTitle implements Title {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the subtitle this title has, if any.
|
* Returns the subtitle this title has, if any.
|
||||||
|
*
|
||||||
* @return the subtitle
|
* @return the subtitle
|
||||||
*/
|
*/
|
||||||
public Optional<Component> getSubtitle() {
|
public Optional<Component> getSubtitle() {
|
||||||
@ -45,6 +47,7 @@ public final class TextTitle implements Title {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of ticks this title will stay up.
|
* Returns the number of ticks this title will stay up.
|
||||||
|
*
|
||||||
* @return how long the title will stay, in ticks
|
* @return how long the title will stay, in ticks
|
||||||
*/
|
*/
|
||||||
public int getStay() {
|
public int getStay() {
|
||||||
@ -53,6 +56,7 @@ public final class TextTitle implements Title {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of ticks over which this title will fade in.
|
* Returns the number of ticks over which this title will fade in.
|
||||||
|
*
|
||||||
* @return how long the title will fade in, in ticks
|
* @return how long the title will fade in, in ticks
|
||||||
*/
|
*/
|
||||||
public int getFadeIn() {
|
public int getFadeIn() {
|
||||||
@ -61,6 +65,7 @@ public final class TextTitle implements Title {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of ticks over which this title will fade out.
|
* Returns the number of ticks over which this title will fade out.
|
||||||
|
*
|
||||||
* @return how long the title will fade out, in ticks
|
* @return how long the title will fade out, in ticks
|
||||||
*/
|
*/
|
||||||
public int getFadeOut() {
|
public int getFadeOut() {
|
||||||
@ -68,8 +73,9 @@ public final class TextTitle implements Title {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether or not a reset packet will be sent before this title is sent. By default, unless explicitly
|
* Returns whether or not a reset packet will be sent before this title is sent. By default,
|
||||||
* disabled, this is enabled by default.
|
* unless explicitly disabled, this is enabled by default.
|
||||||
|
*
|
||||||
* @return whether or not a reset packet will be sent before this title is sent
|
* @return whether or not a reset packet will be sent before this title is sent
|
||||||
*/
|
*/
|
||||||
public boolean isResetBeforeSend() {
|
public boolean isResetBeforeSend() {
|
||||||
@ -77,8 +83,9 @@ public final class TextTitle implements Title {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether or not this title has times set on it. If none are set, it will update the previous title
|
* Determines whether or not this title has times set on it. If none are set, it will update the
|
||||||
* set on the client.
|
* previous title set on the client.
|
||||||
|
*
|
||||||
* @return whether or not this title has times set on it
|
* @return whether or not this title has times set on it
|
||||||
*/
|
*/
|
||||||
public boolean areTimesSet() {
|
public boolean areTimesSet() {
|
||||||
@ -87,6 +94,7 @@ public final class TextTitle implements Title {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new builder from the contents of this title so that it may be changed.
|
* Creates a new builder from the contents of this title so that it may be changed.
|
||||||
|
*
|
||||||
* @return a builder instance with the contents of this title
|
* @return a builder instance with the contents of this title
|
||||||
*/
|
*/
|
||||||
public Builder toBuilder() {
|
public Builder toBuilder() {
|
||||||
@ -95,8 +103,12 @@ public final class TextTitle implements Title {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object o) {
|
public boolean equals(@Nullable Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
TextTitle textTitle = (TextTitle) o;
|
TextTitle textTitle = (TextTitle) o;
|
||||||
return stay == textTitle.stay &&
|
return stay == textTitle.stay &&
|
||||||
fadeIn == textTitle.fadeIn &&
|
fadeIn == textTitle.fadeIn &&
|
||||||
@ -125,6 +137,7 @@ public final class TextTitle implements Title {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new builder for constructing titles.
|
* Creates a new builder for constructing titles.
|
||||||
|
*
|
||||||
* @return a builder for constructing titles
|
* @return a builder for constructing titles
|
||||||
*/
|
*/
|
||||||
public static Builder builder() {
|
public static Builder builder() {
|
||||||
@ -132,6 +145,7 @@ public final class TextTitle implements Title {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
private @Nullable Component title;
|
private @Nullable Component title;
|
||||||
private @Nullable Component subtitle;
|
private @Nullable Component subtitle;
|
||||||
private int stay;
|
private int stay;
|
||||||
@ -139,7 +153,8 @@ public final class TextTitle implements Title {
|
|||||||
private int fadeOut;
|
private int fadeOut;
|
||||||
private boolean resetBeforeSend = true;
|
private boolean resetBeforeSend = true;
|
||||||
|
|
||||||
private Builder() {}
|
private Builder() {
|
||||||
|
}
|
||||||
|
|
||||||
private Builder(TextTitle copy) {
|
private Builder(TextTitle copy) {
|
||||||
this.title = copy.title;
|
this.title = copy.title;
|
||||||
|
@ -4,4 +4,5 @@ package com.velocitypowered.api.util.title;
|
|||||||
* Represents a title that can be sent to a Minecraft client.
|
* Represents a title that can be sent to a Minecraft client.
|
||||||
*/
|
*/
|
||||||
public interface Title {
|
public interface Title {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ package com.velocitypowered.api.util.title;
|
|||||||
* Provides special-purpose titles.
|
* Provides special-purpose titles.
|
||||||
*/
|
*/
|
||||||
public final class Titles {
|
public final class Titles {
|
||||||
|
|
||||||
private Titles() {
|
private Titles() {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
@ -23,8 +24,9 @@ public final class Titles {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a title that, when sent to the client, will cause all title data to be reset and any existing title to be
|
* Returns a title that, when sent to the client, will cause all title data to be reset and any
|
||||||
* hidden.
|
* existing title to be hidden.
|
||||||
|
*
|
||||||
* @return the reset title
|
* @return the reset title
|
||||||
*/
|
*/
|
||||||
public static Title reset() {
|
public static Title reset() {
|
||||||
@ -32,8 +34,9 @@ public final class Titles {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a title that, when sent to the client, will cause any existing title to be hidden. The title may be
|
* Returns a title that, when sent to the client, will cause any existing title to be hidden. The
|
||||||
* restored by a {@link TextTitle} with no title or subtitle (only a time).
|
* title may be restored by a {@link TextTitle} with no title or subtitle (only a time).
|
||||||
|
*
|
||||||
* @return the hide title
|
* @return the hide title
|
||||||
*/
|
*/
|
||||||
public static Title hide() {
|
public static Title hide() {
|
||||||
@ -42,6 +45,7 @@ public final class Titles {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a builder for {@link TextTitle}s.
|
* Returns a builder for {@link TextTitle}s.
|
||||||
|
*
|
||||||
* @return a builder for text titles
|
* @return a builder for text titles
|
||||||
*/
|
*/
|
||||||
public static TextTitle.Builder text() {
|
public static TextTitle.Builder text() {
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
package com.velocitypowered.api.util;
|
package com.velocitypowered.api.util;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
||||||
|
|
||||||
class UuidUtilsTest {
|
class UuidUtilsTest {
|
||||||
private static final UUID EXPECTED_DASHED_UUID = UUID.fromString("6b501978-d3be-4f33-bcf6-6e7808f37a0d");
|
|
||||||
private static final String ACTUAL_UNDASHED_UUID = EXPECTED_DASHED_UUID.toString().replace("-", "");
|
private static final UUID EXPECTED_DASHED_UUID = UUID
|
||||||
|
.fromString("6b501978-d3be-4f33-bcf6-6e7808f37a0d");
|
||||||
|
private static final String ACTUAL_UNDASHED_UUID = EXPECTED_DASHED_UUID.toString()
|
||||||
|
.replace("-", "");
|
||||||
|
|
||||||
private static final UUID ISSUE_109_ZERO_UUID = new UUID(0, 0);
|
private static final UUID ISSUE_109_ZERO_UUID = new UUID(0, 0);
|
||||||
private static final String ISSUE_109_ZERO_UUID_UNDASHED = "00000000000000000000000000000000";
|
private static final String ISSUE_109_ZERO_UUID_UNDASHED = "00000000000000000000000000000000";
|
||||||
@ -20,48 +21,61 @@ class UuidUtilsTest {
|
|||||||
private static final UUID ISSUE_109_ONE_MLSB_UUID = new UUID(1, 1);
|
private static final UUID ISSUE_109_ONE_MLSB_UUID = new UUID(1, 1);
|
||||||
private static final String ISSUE_109_ONE_MLSB_UUID_UNDASHED = "00000000000000010000000000000001";
|
private static final String ISSUE_109_ONE_MLSB_UUID_UNDASHED = "00000000000000010000000000000001";
|
||||||
|
|
||||||
private static final UUID ISSUE_109_LEADING_ZERO_UUID = UUID.fromString("0d470a25-0416-48a1-b7a6-2a27aa5eb251");
|
private static final UUID ISSUE_109_LEADING_ZERO_UUID = UUID
|
||||||
|
.fromString("0d470a25-0416-48a1-b7a6-2a27aa5eb251");
|
||||||
private static final String ISSUE_109_LEADING_ZERO_UNDASHED = "0d470a25041648a1b7a62a27aa5eb251";
|
private static final String ISSUE_109_LEADING_ZERO_UNDASHED = "0d470a25041648a1b7a62a27aa5eb251";
|
||||||
|
|
||||||
private static final UUID TEST_OFFLINE_PLAYER_UUID = UUID.fromString("708f6260-183d-3912-bbde-5e279a5e739a");
|
private static final UUID TEST_OFFLINE_PLAYER_UUID = UUID
|
||||||
|
.fromString("708f6260-183d-3912-bbde-5e279a5e739a");
|
||||||
private static final String TEST_OFFLINE_PLAYER = "tuxed";
|
private static final String TEST_OFFLINE_PLAYER = "tuxed";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void generateOfflinePlayerUuid() {
|
void generateOfflinePlayerUuid() {
|
||||||
assertEquals(TEST_OFFLINE_PLAYER_UUID, UuidUtils.generateOfflinePlayerUuid(TEST_OFFLINE_PLAYER), "UUIDs do not match");
|
assertEquals(TEST_OFFLINE_PLAYER_UUID, UuidUtils.generateOfflinePlayerUuid(TEST_OFFLINE_PLAYER),
|
||||||
|
"UUIDs do not match");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void fromUndashed() {
|
void fromUndashed() {
|
||||||
assertEquals(EXPECTED_DASHED_UUID, UuidUtils.fromUndashed(ACTUAL_UNDASHED_UUID), "UUIDs do not match");
|
assertEquals(EXPECTED_DASHED_UUID, UuidUtils.fromUndashed(ACTUAL_UNDASHED_UUID),
|
||||||
|
"UUIDs do not match");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void toUndashed() {
|
void toUndashed() {
|
||||||
assertEquals(ACTUAL_UNDASHED_UUID, UuidUtils.toUndashed(EXPECTED_DASHED_UUID), "UUIDs do not match");
|
assertEquals(ACTUAL_UNDASHED_UUID, UuidUtils.toUndashed(EXPECTED_DASHED_UUID),
|
||||||
|
"UUIDs do not match");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void zeroUuidIssue109() {
|
void zeroUuidIssue109() {
|
||||||
assertEquals(ISSUE_109_ZERO_UUID, UuidUtils.fromUndashed(ISSUE_109_ZERO_UUID_UNDASHED), "UUIDs do not match");
|
assertEquals(ISSUE_109_ZERO_UUID, UuidUtils.fromUndashed(ISSUE_109_ZERO_UUID_UNDASHED),
|
||||||
assertEquals(ISSUE_109_ZERO_UUID_UNDASHED, UuidUtils.toUndashed(ISSUE_109_ZERO_UUID), "UUIDs do not match");
|
"UUIDs do not match");
|
||||||
|
assertEquals(ISSUE_109_ZERO_UUID_UNDASHED, UuidUtils.toUndashed(ISSUE_109_ZERO_UUID),
|
||||||
|
"UUIDs do not match");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void leadingZeroUuidIssue109() {
|
void leadingZeroUuidIssue109() {
|
||||||
assertEquals(ISSUE_109_LEADING_ZERO_UUID, UuidUtils.fromUndashed(ISSUE_109_LEADING_ZERO_UNDASHED), "UUIDs do not match");
|
assertEquals(ISSUE_109_LEADING_ZERO_UUID,
|
||||||
assertEquals(ISSUE_109_LEADING_ZERO_UNDASHED, UuidUtils.toUndashed(ISSUE_109_LEADING_ZERO_UUID), "UUIDs do not match");
|
UuidUtils.fromUndashed(ISSUE_109_LEADING_ZERO_UNDASHED), "UUIDs do not match");
|
||||||
|
assertEquals(ISSUE_109_LEADING_ZERO_UNDASHED, UuidUtils.toUndashed(ISSUE_109_LEADING_ZERO_UUID),
|
||||||
|
"UUIDs do not match");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void oneUuidLsbIssue109() {
|
void oneUuidLsbIssue109() {
|
||||||
assertEquals(ISSUE_109_ONE_LSB_UUID, UuidUtils.fromUndashed(ISSUE_109_ONE_LSB_UUID_UNDASHED), "UUIDs do not match");
|
assertEquals(ISSUE_109_ONE_LSB_UUID, UuidUtils.fromUndashed(ISSUE_109_ONE_LSB_UUID_UNDASHED),
|
||||||
assertEquals(ISSUE_109_ONE_LSB_UUID_UNDASHED, UuidUtils.toUndashed(ISSUE_109_ONE_LSB_UUID), "UUIDs do not match");
|
"UUIDs do not match");
|
||||||
|
assertEquals(ISSUE_109_ONE_LSB_UUID_UNDASHED, UuidUtils.toUndashed(ISSUE_109_ONE_LSB_UUID),
|
||||||
|
"UUIDs do not match");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void oneUuidMsbAndLsbIssue109() {
|
void oneUuidMsbAndLsbIssue109() {
|
||||||
assertEquals(ISSUE_109_ONE_MLSB_UUID, UuidUtils.fromUndashed(ISSUE_109_ONE_MLSB_UUID_UNDASHED), "UUIDs do not match");
|
assertEquals(ISSUE_109_ONE_MLSB_UUID, UuidUtils.fromUndashed(ISSUE_109_ONE_MLSB_UUID_UNDASHED),
|
||||||
assertEquals(ISSUE_109_ONE_MLSB_UUID_UNDASHED, UuidUtils.toUndashed(ISSUE_109_ONE_MLSB_UUID), "UUIDs do not match");
|
"UUIDs do not match");
|
||||||
|
assertEquals(ISSUE_109_ONE_MLSB_UUID_UNDASHED, UuidUtils.toUndashed(ISSUE_109_ONE_MLSB_UUID),
|
||||||
|
"UUIDs do not match");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
256
config/checkstyle/checkstyle.xml
Normale Datei
256
config/checkstyle/checkstyle.xml
Normale Datei
@ -0,0 +1,256 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!DOCTYPE module PUBLIC
|
||||||
|
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
|
||||||
|
"https://checkstyle.org/dtds/configuration_1_3.dtd">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Checkstyle configuration that checks the Google coding conventions from Google Java Style
|
||||||
|
that can be found at https://google.github.io/styleguide/javaguide.html.
|
||||||
|
|
||||||
|
Checkstyle is very configurable. Be sure to read the documentation at
|
||||||
|
http://checkstyle.sf.net (or in your downloaded distribution).
|
||||||
|
|
||||||
|
To completely disable a check, just comment it out or delete it from the file.
|
||||||
|
|
||||||
|
Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<module name="Checker">
|
||||||
|
<property name="charset" value="UTF-8"/>
|
||||||
|
|
||||||
|
<property name="severity" value="warning"/>
|
||||||
|
|
||||||
|
<property name="fileExtensions" value="java, properties, xml"/>
|
||||||
|
<!-- Checks for whitespace -->
|
||||||
|
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
|
||||||
|
<module name="FileTabCharacter">
|
||||||
|
<property name="eachLine" value="true"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="TreeWalker">
|
||||||
|
<module name="OuterTypeFilename"/>
|
||||||
|
<module name="IllegalTokenText">
|
||||||
|
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
|
||||||
|
<property name="format"
|
||||||
|
value="\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
|
||||||
|
<property name="message"
|
||||||
|
value="Consider using special escape sequence instead of octal value or Unicode escaped value."/>
|
||||||
|
</module>
|
||||||
|
<module name="AvoidEscapedUnicodeCharacters">
|
||||||
|
<property name="allowEscapesForControlCharacters" value="true"/>
|
||||||
|
<property name="allowByTailComment" value="true"/>
|
||||||
|
<property name="allowNonPrintableEscapes" value="true"/>
|
||||||
|
</module>
|
||||||
|
<module name="LineLength">
|
||||||
|
<property name="max" value="100"/>
|
||||||
|
<property name="ignorePattern"
|
||||||
|
value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
|
||||||
|
</module>
|
||||||
|
<module name="AvoidStarImport"/>
|
||||||
|
<module name="OneTopLevelClass"/>
|
||||||
|
<module name="NoLineWrap"/>
|
||||||
|
<module name="EmptyBlock">
|
||||||
|
<property name="option" value="TEXT"/>
|
||||||
|
<property name="tokens"
|
||||||
|
value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
|
||||||
|
</module>
|
||||||
|
<module name="NeedBraces"/>
|
||||||
|
<module name="LeftCurly"/>
|
||||||
|
<module name="RightCurly">
|
||||||
|
<property name="id" value="RightCurlySame"/>
|
||||||
|
<property name="tokens"
|
||||||
|
value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE,
|
||||||
|
LITERAL_DO"/>
|
||||||
|
</module>
|
||||||
|
<module name="RightCurly">
|
||||||
|
<property name="id" value="RightCurlyAlone"/>
|
||||||
|
<property name="option" value="alone"/>
|
||||||
|
<property name="tokens"
|
||||||
|
value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, STATIC_INIT,
|
||||||
|
INSTANCE_INIT"/>
|
||||||
|
</module>
|
||||||
|
<module name="WhitespaceAround">
|
||||||
|
<property name="allowEmptyConstructors" value="true"/>
|
||||||
|
<property name="allowEmptyMethods" value="true"/>
|
||||||
|
<property name="allowEmptyTypes" value="true"/>
|
||||||
|
<property name="allowEmptyLoops" value="true"/>
|
||||||
|
<message key="ws.notFollowed"
|
||||||
|
value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
|
||||||
|
<message key="ws.notPreceded"
|
||||||
|
value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
|
||||||
|
</module>
|
||||||
|
<module name="OneStatementPerLine"/>
|
||||||
|
<module name="MultipleVariableDeclarations"/>
|
||||||
|
<module name="ArrayTypeStyle"/>
|
||||||
|
<module name="MissingSwitchDefault"/>
|
||||||
|
<module name="FallThrough"/>
|
||||||
|
<module name="UpperEll"/>
|
||||||
|
<module name="ModifierOrder"/>
|
||||||
|
<module name="EmptyLineSeparator">
|
||||||
|
<property name="allowNoEmptyLineBetweenFields" value="true"/>
|
||||||
|
</module>
|
||||||
|
<module name="SeparatorWrap">
|
||||||
|
<property name="id" value="SeparatorWrapDot"/>
|
||||||
|
<property name="tokens" value="DOT"/>
|
||||||
|
<property name="option" value="nl"/>
|
||||||
|
</module>
|
||||||
|
<module name="SeparatorWrap">
|
||||||
|
<property name="id" value="SeparatorWrapComma"/>
|
||||||
|
<property name="tokens" value="COMMA"/>
|
||||||
|
<property name="option" value="EOL"/>
|
||||||
|
</module>
|
||||||
|
<module name="SeparatorWrap">
|
||||||
|
<!-- ELLIPSIS is EOL until https://github.com/google/styleguide/issues/258 -->
|
||||||
|
<property name="id" value="SeparatorWrapEllipsis"/>
|
||||||
|
<property name="tokens" value="ELLIPSIS"/>
|
||||||
|
<property name="option" value="EOL"/>
|
||||||
|
</module>
|
||||||
|
<module name="SeparatorWrap">
|
||||||
|
<!-- ARRAY_DECLARATOR is EOL until https://github.com/google/styleguide/issues/259 -->
|
||||||
|
<property name="id" value="SeparatorWrapArrayDeclarator"/>
|
||||||
|
<property name="tokens" value="ARRAY_DECLARATOR"/>
|
||||||
|
<property name="option" value="EOL"/>
|
||||||
|
</module>
|
||||||
|
<module name="SeparatorWrap">
|
||||||
|
<property name="id" value="SeparatorWrapMethodRef"/>
|
||||||
|
<property name="tokens" value="METHOD_REF"/>
|
||||||
|
<property name="option" value="nl"/>
|
||||||
|
</module>
|
||||||
|
<module name="PackageName">
|
||||||
|
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
|
||||||
|
<message key="name.invalidPattern"
|
||||||
|
value="Package name ''{0}'' must match pattern ''{1}''."/>
|
||||||
|
</module>
|
||||||
|
<module name="TypeName">
|
||||||
|
<message key="name.invalidPattern"
|
||||||
|
value="Type name ''{0}'' must match pattern ''{1}''."/>
|
||||||
|
</module>
|
||||||
|
<module name="MemberName">
|
||||||
|
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
|
||||||
|
<message key="name.invalidPattern"
|
||||||
|
value="Member name ''{0}'' must match pattern ''{1}''."/>
|
||||||
|
</module>
|
||||||
|
<module name="ParameterName">
|
||||||
|
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
|
||||||
|
<message key="name.invalidPattern"
|
||||||
|
value="Parameter name ''{0}'' must match pattern ''{1}''."/>
|
||||||
|
</module>
|
||||||
|
<module name="LambdaParameterName">
|
||||||
|
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
|
||||||
|
<message key="name.invalidPattern"
|
||||||
|
value="Lambda parameter name ''{0}'' must match pattern ''{1}''."/>
|
||||||
|
</module>
|
||||||
|
<module name="CatchParameterName">
|
||||||
|
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
|
||||||
|
<message key="name.invalidPattern"
|
||||||
|
value="Catch parameter name ''{0}'' must match pattern ''{1}''."/>
|
||||||
|
</module>
|
||||||
|
<module name="LocalVariableName">
|
||||||
|
<property name="tokens" value="VARIABLE_DEF"/>
|
||||||
|
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
|
||||||
|
<message key="name.invalidPattern"
|
||||||
|
value="Local variable name ''{0}'' must match pattern ''{1}''."/>
|
||||||
|
</module>
|
||||||
|
<module name="ClassTypeParameterName">
|
||||||
|
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
|
||||||
|
<message key="name.invalidPattern"
|
||||||
|
value="Class type name ''{0}'' must match pattern ''{1}''."/>
|
||||||
|
</module>
|
||||||
|
<module name="MethodTypeParameterName">
|
||||||
|
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
|
||||||
|
<message key="name.invalidPattern"
|
||||||
|
value="Method type name ''{0}'' must match pattern ''{1}''."/>
|
||||||
|
</module>
|
||||||
|
<module name="InterfaceTypeParameterName">
|
||||||
|
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
|
||||||
|
<message key="name.invalidPattern"
|
||||||
|
value="Interface type name ''{0}'' must match pattern ''{1}''."/>
|
||||||
|
</module>
|
||||||
|
<module name="NoFinalizer"/>
|
||||||
|
<module name="GenericWhitespace">
|
||||||
|
<message key="ws.followed"
|
||||||
|
value="GenericWhitespace ''{0}'' is followed by whitespace."/>
|
||||||
|
<message key="ws.preceded"
|
||||||
|
value="GenericWhitespace ''{0}'' is preceded with whitespace."/>
|
||||||
|
<message key="ws.illegalFollow"
|
||||||
|
value="GenericWhitespace ''{0}'' should followed by whitespace."/>
|
||||||
|
<message key="ws.notPreceded"
|
||||||
|
value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
|
||||||
|
</module>
|
||||||
|
<module name="Indentation">
|
||||||
|
<property name="basicOffset" value="2"/>
|
||||||
|
<property name="braceAdjustment" value="0"/>
|
||||||
|
<property name="caseIndent" value="2"/>
|
||||||
|
<property name="throwsIndent" value="4"/>
|
||||||
|
<property name="lineWrappingIndentation" value="4"/>
|
||||||
|
<property name="arrayInitIndent" value="2"/>
|
||||||
|
</module>
|
||||||
|
<module name="AbbreviationAsWordInName">
|
||||||
|
<property name="ignoreFinal" value="false"/>
|
||||||
|
<property name="allowedAbbreviationLength" value="1"/>
|
||||||
|
</module>
|
||||||
|
<module name="OverloadMethodsDeclarationOrder"/>
|
||||||
|
<module name="VariableDeclarationUsageDistance"/>
|
||||||
|
<module name="CustomImportOrder">
|
||||||
|
<property name="sortImportsInGroupAlphabetically" value="true"/>
|
||||||
|
<property name="separateLineBetweenGroups" value="true"/>
|
||||||
|
<property name="customImportOrderRules" value="STATIC###THIRD_PARTY_PACKAGE"/>
|
||||||
|
</module>
|
||||||
|
<module name="MethodParamPad"/>
|
||||||
|
<module name="NoWhitespaceBefore">
|
||||||
|
<property name="tokens"
|
||||||
|
value="COMMA, SEMI, POST_INC, POST_DEC, DOT, ELLIPSIS, METHOD_REF"/>
|
||||||
|
<property name="allowLineBreaks" value="true"/>
|
||||||
|
</module>
|
||||||
|
<module name="ParenPad"/>
|
||||||
|
<module name="OperatorWrap">
|
||||||
|
<property name="option" value="NL"/>
|
||||||
|
<property name="tokens"
|
||||||
|
value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR,
|
||||||
|
LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR, METHOD_REF "/>
|
||||||
|
</module>
|
||||||
|
<module name="AnnotationLocation">
|
||||||
|
<property name="id" value="AnnotationLocationMostCases"/>
|
||||||
|
<property name="tokens"
|
||||||
|
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/>
|
||||||
|
</module>
|
||||||
|
<module name="AnnotationLocation">
|
||||||
|
<property name="id" value="AnnotationLocationVariables"/>
|
||||||
|
<property name="tokens" value="VARIABLE_DEF"/>
|
||||||
|
<property name="allowSamelineMultipleAnnotations" value="true"/>
|
||||||
|
</module>
|
||||||
|
<module name="NonEmptyAtclauseDescription"/>
|
||||||
|
<module name="JavadocTagContinuationIndentation"/>
|
||||||
|
<module name="SummaryJavadoc">
|
||||||
|
<property name="forbiddenSummaryFragments"
|
||||||
|
value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/>
|
||||||
|
</module>
|
||||||
|
<module name="JavadocParagraph"/>
|
||||||
|
<module name="AtclauseOrder">
|
||||||
|
<property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
|
||||||
|
<property name="target"
|
||||||
|
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
|
||||||
|
</module>
|
||||||
|
<module name="JavadocMethod">
|
||||||
|
<property name="scope" value="public"/>
|
||||||
|
<property name="allowMissingParamTags" value="true"/>
|
||||||
|
<property name="allowMissingThrowsTags" value="true"/>
|
||||||
|
<property name="allowMissingReturnTag" value="true"/>
|
||||||
|
<property name="minLineCount" value="2"/>
|
||||||
|
<property name="allowedAnnotations" value="Override, Test"/>
|
||||||
|
<property name="allowThrowsTagsForSubclasses" value="true"/>
|
||||||
|
</module>
|
||||||
|
<module name="MethodName">
|
||||||
|
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
|
||||||
|
<message key="name.invalidPattern"
|
||||||
|
value="Method name ''{0}'' must match pattern ''{1}''."/>
|
||||||
|
</module>
|
||||||
|
<module name="SingleLineJavadoc">
|
||||||
|
<property name="ignoreInlineTags" value="false"/>
|
||||||
|
</module>
|
||||||
|
<module name="EmptyCatchBlock">
|
||||||
|
<property name="exceptionVariableName" value="expected"/>
|
||||||
|
</module>
|
||||||
|
<module name="CommentsIndentation"/>
|
||||||
|
</module>
|
||||||
|
</module>
|
@ -25,7 +25,7 @@ dependencies {
|
|||||||
implementation "org.checkerframework:checker-qual:${checkerFrameworkVersion}"
|
implementation "org.checkerframework:checker-qual:${checkerFrameworkVersion}"
|
||||||
} else if (System.getenv("CHECKERFRAMEWORK") == null) {
|
} else if (System.getenv("CHECKERFRAMEWORK") == null) {
|
||||||
throw new GradleException("Environment variable CHECKERFRAMEWORK is not set")
|
throw new GradleException("Environment variable CHECKERFRAMEWORK is not set")
|
||||||
} else if (! file(System.getenv("CHECKERFRAMEWORK")).exists()) {
|
} else if (!file(System.getenv("CHECKERFRAMEWORK")).exists()) {
|
||||||
throw new GradleException("Environment variable CHECKERFRAMEWORK is set to non-existent directory " + System.getenv("CHECKERFRAMEWORK"));
|
throw new GradleException("Environment variable CHECKERFRAMEWORK is set to non-existent directory " + System.getenv("CHECKERFRAMEWORK"));
|
||||||
} else {
|
} else {
|
||||||
ext.checkerframeworkdist = "$System.env.CHECKERFRAMEWORK/checker/dist"
|
ext.checkerframeworkdist = "$System.env.CHECKERFRAMEWORK/checker/dist"
|
||||||
|
4
gradle/checkstyle.gradle
Normale Datei
4
gradle/checkstyle.gradle
Normale Datei
@ -0,0 +1,4 @@
|
|||||||
|
checkstyle {
|
||||||
|
toolVersion '8.14'
|
||||||
|
configFile new File(project.rootDir, ['config', 'checkstyle', 'checkstyle.xml'].join(File.separator))
|
||||||
|
}
|
@ -1,8 +1,10 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
|
id 'checkstyle'
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: '../gradle/checkerframework.gradle'
|
apply from: '../gradle/checkerframework.gradle'
|
||||||
|
apply from: '../gradle/checkstyle.gradle'
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile "com.google.guava:guava:${guavaVersion}"
|
compile "com.google.guava:guava:${guavaVersion}"
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
package com.velocitypowered.natives;
|
package com.velocitypowered.natives;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This marker interface indicates that this object should be explicitly disposed before the object can no longer be used.
|
* This marker interface indicates that this object should be explicitly disposed before the object
|
||||||
* Not disposing these objects will likely leak native resources and eventually lead to resource exhaustion.
|
* can no longer be used. Not disposing these objects will likely leak native resources and
|
||||||
|
* eventually lead to resource exhaustion.
|
||||||
*/
|
*/
|
||||||
public interface Disposable {
|
public interface Disposable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disposes this object. After this call returns, any use of this object becomes invalid. Multiple calls to
|
* Disposes this object. After this call returns, any use of this object becomes invalid. Multiple
|
||||||
* this function should be safe: there should be no side-effects once an object is disposed.
|
* calls to this function should be safe: there should be no side-effects once an object is
|
||||||
|
* disposed.
|
||||||
*/
|
*/
|
||||||
void dispose();
|
void dispose();
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,12 @@ package com.velocitypowered.natives.compression;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
import java.util.zip.DataFormatException;
|
import java.util.zip.DataFormatException;
|
||||||
import java.util.zip.Deflater;
|
import java.util.zip.Deflater;
|
||||||
import java.util.zip.Inflater;
|
import java.util.zip.Inflater;
|
||||||
|
|
||||||
public class JavaVelocityCompressor implements VelocityCompressor {
|
public class JavaVelocityCompressor implements VelocityCompressor {
|
||||||
|
|
||||||
public static final VelocityCompressorFactory FACTORY = JavaVelocityCompressor::new;
|
public static final VelocityCompressorFactory FACTORY = JavaVelocityCompressor::new;
|
||||||
|
|
||||||
private final Deflater deflater;
|
private final Deflater deflater;
|
||||||
|
@ -2,10 +2,10 @@ package com.velocitypowered.natives.compression;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
import java.util.zip.DataFormatException;
|
import java.util.zip.DataFormatException;
|
||||||
|
|
||||||
public class NativeVelocityCompressor implements VelocityCompressor {
|
public class NativeVelocityCompressor implements VelocityCompressor {
|
||||||
|
|
||||||
public static final VelocityCompressorFactory FACTORY = NativeVelocityCompressor::new;
|
public static final VelocityCompressorFactory FACTORY = NativeVelocityCompressor::new;
|
||||||
|
|
||||||
private final NativeZlibInflate inflate = new NativeZlibInflate();
|
private final NativeZlibInflate inflate = new NativeZlibInflate();
|
||||||
@ -29,7 +29,8 @@ public class NativeVelocityCompressor implements VelocityCompressor {
|
|||||||
if (!destination.isWritable()) {
|
if (!destination.isWritable()) {
|
||||||
destination.ensureWritable(ZLIB_BUFFER_SIZE);
|
destination.ensureWritable(ZLIB_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
int produced = inflate.process(inflateCtx, source.memoryAddress() + source.readerIndex(), source.readableBytes(),
|
int produced = inflate.process(inflateCtx, source.memoryAddress() + source.readerIndex(),
|
||||||
|
source.readableBytes(),
|
||||||
destination.memoryAddress() + destination.writerIndex(), destination.writableBytes());
|
destination.memoryAddress() + destination.writerIndex(), destination.writableBytes());
|
||||||
source.readerIndex(source.readerIndex() + inflate.consumed);
|
source.readerIndex(source.readerIndex() + inflate.consumed);
|
||||||
destination.writerIndex(destination.writerIndex() + produced);
|
destination.writerIndex(destination.writerIndex() + produced);
|
||||||
@ -50,8 +51,10 @@ public class NativeVelocityCompressor implements VelocityCompressor {
|
|||||||
if (!destination.isWritable()) {
|
if (!destination.isWritable()) {
|
||||||
destination.ensureWritable(ZLIB_BUFFER_SIZE);
|
destination.ensureWritable(ZLIB_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
int produced = deflate.process(deflateCtx, source.memoryAddress() + source.readerIndex(), source.readableBytes(),
|
int produced = deflate.process(deflateCtx, source.memoryAddress() + source.readerIndex(),
|
||||||
destination.memoryAddress() + destination.writerIndex(), destination.writableBytes(), !source.isReadable());
|
source.readableBytes(),
|
||||||
|
destination.memoryAddress() + destination.writerIndex(), destination.writableBytes(),
|
||||||
|
!source.isReadable());
|
||||||
source.readerIndex(source.readerIndex() + deflate.consumed);
|
source.readerIndex(source.readerIndex() + deflate.consumed);
|
||||||
destination.writerIndex(destination.writerIndex() + produced);
|
destination.writerIndex(destination.writerIndex() + produced);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ package com.velocitypowered.natives.compression;
|
|||||||
* Represents a native interface for zlib's deflate functions.
|
* Represents a native interface for zlib's deflate functions.
|
||||||
*/
|
*/
|
||||||
class NativeZlibDeflate {
|
class NativeZlibDeflate {
|
||||||
|
|
||||||
boolean finished;
|
boolean finished;
|
||||||
int consumed;
|
int consumed;
|
||||||
|
|
||||||
@ -11,7 +12,8 @@ class NativeZlibDeflate {
|
|||||||
|
|
||||||
native long free(long ctx);
|
native long free(long ctx);
|
||||||
|
|
||||||
native int process(long ctx, long sourceAddress, int sourceLength, long destinationAddress, int destinationLength,
|
native int process(long ctx, long sourceAddress, int sourceLength, long destinationAddress,
|
||||||
|
int destinationLength,
|
||||||
boolean flush);
|
boolean flush);
|
||||||
|
|
||||||
native void reset(long ctx);
|
native void reset(long ctx);
|
||||||
|
@ -4,6 +4,7 @@ package com.velocitypowered.natives.compression;
|
|||||||
* Represents a native interface for zlib's inflate functions.
|
* Represents a native interface for zlib's inflate functions.
|
||||||
*/
|
*/
|
||||||
class NativeZlibInflate {
|
class NativeZlibInflate {
|
||||||
|
|
||||||
boolean finished;
|
boolean finished;
|
||||||
int consumed;
|
int consumed;
|
||||||
|
|
||||||
@ -11,7 +12,8 @@ class NativeZlibInflate {
|
|||||||
|
|
||||||
native long free(long ctx);
|
native long free(long ctx);
|
||||||
|
|
||||||
native int process(long ctx, long sourceAddress, int sourceLength, long destinationAddress, int destinationLength);
|
native int process(long ctx, long sourceAddress, int sourceLength, long destinationAddress,
|
||||||
|
int destinationLength);
|
||||||
|
|
||||||
native void reset(long ctx);
|
native void reset(long ctx);
|
||||||
|
|
||||||
|
@ -2,13 +2,13 @@ package com.velocitypowered.natives.compression;
|
|||||||
|
|
||||||
import com.velocitypowered.natives.Disposable;
|
import com.velocitypowered.natives.Disposable;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
import java.util.zip.DataFormatException;
|
import java.util.zip.DataFormatException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides an interface to inflate and deflate {@link ByteBuf}s using zlib.
|
* Provides an interface to inflate and deflate {@link ByteBuf}s using zlib.
|
||||||
*/
|
*/
|
||||||
public interface VelocityCompressor extends Disposable {
|
public interface VelocityCompressor extends Disposable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default preferred output buffer size for zlib.
|
* The default preferred output buffer size for zlib.
|
||||||
*/
|
*/
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.velocitypowered.natives.compression;
|
package com.velocitypowered.natives.compression;
|
||||||
|
|
||||||
public interface VelocityCompressorFactory {
|
public interface VelocityCompressorFactory {
|
||||||
|
|
||||||
VelocityCompressor create(int level);
|
VelocityCompressor create(int level);
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,14 @@ package com.velocitypowered.natives.encryption;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import java.security.GeneralSecurityException;
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
import javax.crypto.ShortBufferException;
|
import javax.crypto.ShortBufferException;
|
||||||
import javax.crypto.spec.IvParameterSpec;
|
import javax.crypto.spec.IvParameterSpec;
|
||||||
import java.security.GeneralSecurityException;
|
|
||||||
|
|
||||||
public class JavaVelocityCipher implements VelocityCipher {
|
public class JavaVelocityCipher implements VelocityCipher {
|
||||||
|
|
||||||
public static final VelocityCipherFactory FACTORY = new VelocityCipherFactory() {
|
public static final VelocityCipherFactory FACTORY = new VelocityCipherFactory() {
|
||||||
@Override
|
@Override
|
||||||
public VelocityCipher forEncryption(SecretKey key) throws GeneralSecurityException {
|
public VelocityCipher forEncryption(SecretKey key) throws GeneralSecurityException {
|
||||||
@ -27,7 +27,8 @@ public class JavaVelocityCipher implements VelocityCipher {
|
|||||||
|
|
||||||
private JavaVelocityCipher(boolean encrypt, SecretKey key) throws GeneralSecurityException {
|
private JavaVelocityCipher(boolean encrypt, SecretKey key) throws GeneralSecurityException {
|
||||||
this.cipher = Cipher.getInstance("AES/CFB8/NoPadding");
|
this.cipher = Cipher.getInstance("AES/CFB8/NoPadding");
|
||||||
this.cipher.init(encrypt ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE, key, new IvParameterSpec(key.getEncoded()));
|
this.cipher.init(encrypt ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE, key,
|
||||||
|
new IvParameterSpec(key.getEncoded()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package com.velocitypowered.natives.encryption;
|
package com.velocitypowered.natives.encryption;
|
||||||
|
|
||||||
public class MbedtlsAesImpl {
|
public class MbedtlsAesImpl {
|
||||||
|
|
||||||
native long init(byte[] key);
|
native long init(byte[] key);
|
||||||
|
|
||||||
native void process(long ctx, long sourceAddress, int sourceLength, long destinationAddress, boolean encrypt);
|
native void process(long ctx, long sourceAddress, int sourceLength, long destinationAddress,
|
||||||
|
boolean encrypt);
|
||||||
|
|
||||||
native void free(long ptr);
|
native void free(long ptr);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package com.velocitypowered.natives.encryption;
|
package com.velocitypowered.natives.encryption;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import java.security.GeneralSecurityException;
|
||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
import javax.crypto.ShortBufferException;
|
import javax.crypto.ShortBufferException;
|
||||||
import java.security.GeneralSecurityException;
|
|
||||||
|
|
||||||
public class NativeVelocityCipher implements VelocityCipher {
|
public class NativeVelocityCipher implements VelocityCipher {
|
||||||
|
|
||||||
public static final VelocityCipherFactory FACTORY = new VelocityCipherFactory() {
|
public static final VelocityCipherFactory FACTORY = new VelocityCipherFactory() {
|
||||||
@Override
|
@Override
|
||||||
public VelocityCipher forEncryption(SecretKey key) throws GeneralSecurityException {
|
public VelocityCipher forEncryption(SecretKey key) throws GeneralSecurityException {
|
||||||
|
@ -2,9 +2,9 @@ package com.velocitypowered.natives.encryption;
|
|||||||
|
|
||||||
import com.velocitypowered.natives.Disposable;
|
import com.velocitypowered.natives.Disposable;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
import javax.crypto.ShortBufferException;
|
import javax.crypto.ShortBufferException;
|
||||||
|
|
||||||
public interface VelocityCipher extends Disposable {
|
public interface VelocityCipher extends Disposable {
|
||||||
|
|
||||||
void process(ByteBuf source, ByteBuf destination) throws ShortBufferException;
|
void process(ByteBuf source, ByteBuf destination) throws ShortBufferException;
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package com.velocitypowered.natives.encryption;
|
package com.velocitypowered.natives.encryption;
|
||||||
|
|
||||||
import javax.crypto.SecretKey;
|
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
|
import javax.crypto.SecretKey;
|
||||||
|
|
||||||
public interface VelocityCipherFactory {
|
public interface VelocityCipherFactory {
|
||||||
|
|
||||||
VelocityCipher forEncryption(SecretKey key) throws GeneralSecurityException;
|
VelocityCipher forEncryption(SecretKey key) throws GeneralSecurityException;
|
||||||
|
|
||||||
VelocityCipher forDecryption(SecretKey key) throws GeneralSecurityException;
|
VelocityCipher forDecryption(SecretKey key) throws GeneralSecurityException;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package com.velocitypowered.natives.util;
|
package com.velocitypowered.natives.util;
|
||||||
|
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.BooleanSupplier;
|
import java.util.function.BooleanSupplier;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public final class NativeCodeLoader<T> implements Supplier<T> {
|
public final class NativeCodeLoader<T> implements Supplier<T> {
|
||||||
|
|
||||||
private final Variant<T> selected;
|
private final Variant<T> selected;
|
||||||
|
|
||||||
NativeCodeLoader(List<Variant<T>> variants) {
|
NativeCodeLoader(List<Variant<T>> variants) {
|
||||||
@ -34,13 +34,15 @@ public final class NativeCodeLoader<T> implements Supplier<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static class Variant<T> {
|
static class Variant<T> {
|
||||||
|
|
||||||
private Status status;
|
private Status status;
|
||||||
private final Runnable setup;
|
private final Runnable setup;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final T object;
|
private final T object;
|
||||||
|
|
||||||
Variant(BooleanSupplier possiblyAvailable, Runnable setup, String name, T object) {
|
Variant(BooleanSupplier possiblyAvailable, Runnable setup, String name, T object) {
|
||||||
this.status = possiblyAvailable.getAsBoolean() ? Status.POSSIBLY_AVAILABLE : Status.NOT_AVAILABLE;
|
this.status =
|
||||||
|
possiblyAvailable.getAsBoolean() ? Status.POSSIBLY_AVAILABLE : Status.NOT_AVAILABLE;
|
||||||
this.setup = setup;
|
this.setup = setup;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.object = object;
|
this.object = object;
|
||||||
@ -73,9 +75,11 @@ public final class NativeCodeLoader<T> implements Supplier<T> {
|
|||||||
SETUP_FAILURE
|
SETUP_FAILURE
|
||||||
}
|
}
|
||||||
|
|
||||||
static final BooleanSupplier MACOS = () -> System.getProperty("os.name", "").equalsIgnoreCase("Mac OS X") &&
|
static final BooleanSupplier MACOS = () ->
|
||||||
|
System.getProperty("os.name", "").equalsIgnoreCase("Mac OS X") &&
|
||||||
System.getProperty("os.arch").equals("x86_64");
|
System.getProperty("os.arch").equals("x86_64");
|
||||||
static final BooleanSupplier LINUX = () -> System.getProperties().getProperty("os.name", "").equalsIgnoreCase("Linux") &&
|
static final BooleanSupplier LINUX = () ->
|
||||||
|
System.getProperties().getProperty("os.name", "").equalsIgnoreCase("Linux") &&
|
||||||
System.getProperty("os.arch").equals("amd64");
|
System.getProperty("os.arch").equals("amd64");
|
||||||
static final BooleanSupplier ALWAYS = () -> true;
|
static final BooleanSupplier ALWAYS = () -> true;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import com.velocitypowered.natives.compression.NativeVelocityCompressor;
|
|||||||
import com.velocitypowered.natives.compression.VelocityCompressorFactory;
|
import com.velocitypowered.natives.compression.VelocityCompressorFactory;
|
||||||
import com.velocitypowered.natives.encryption.JavaVelocityCipher;
|
import com.velocitypowered.natives.encryption.JavaVelocityCipher;
|
||||||
import com.velocitypowered.natives.encryption.VelocityCipherFactory;
|
import com.velocitypowered.natives.encryption.VelocityCipherFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@ -14,6 +13,7 @@ import java.nio.file.Path;
|
|||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
|
|
||||||
public class Natives {
|
public class Natives {
|
||||||
|
|
||||||
private Natives() {
|
private Natives() {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
@ -50,7 +50,8 @@ public class Natives {
|
|||||||
new NativeCodeLoader.Variant<>(NativeCodeLoader.LINUX,
|
new NativeCodeLoader.Variant<>(NativeCodeLoader.LINUX,
|
||||||
copyAndLoadNative("/linux_x64/velocity-compress.so"), "native (Linux amd64)",
|
copyAndLoadNative("/linux_x64/velocity-compress.so"), "native (Linux amd64)",
|
||||||
NativeVelocityCompressor.FACTORY),
|
NativeVelocityCompressor.FACTORY),
|
||||||
new NativeCodeLoader.Variant<>(NativeCodeLoader.ALWAYS, () -> {}, "Java", JavaVelocityCompressor.FACTORY)
|
new NativeCodeLoader.Variant<>(NativeCodeLoader.ALWAYS, () -> {
|
||||||
|
}, "Java", JavaVelocityCompressor.FACTORY)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -62,7 +63,8 @@ public class Natives {
|
|||||||
new NativeCodeLoader.Variant<>(NativeCodeLoader.LINUX,
|
new NativeCodeLoader.Variant<>(NativeCodeLoader.LINUX,
|
||||||
copyAndLoadNative("/linux_x64/velocity-cipher.so"), "mbed TLS (Linux amd64)",
|
copyAndLoadNative("/linux_x64/velocity-cipher.so"), "mbed TLS (Linux amd64)",
|
||||||
NativeVelocityCipher.FACTORY),*/
|
NativeVelocityCipher.FACTORY),*/
|
||||||
new NativeCodeLoader.Variant<>(NativeCodeLoader.ALWAYS, () -> {}, "Java", JavaVelocityCipher.FACTORY)
|
new NativeCodeLoader.Variant<>(NativeCodeLoader.ALWAYS, () -> {
|
||||||
|
}, "Java", JavaVelocityCipher.FACTORY)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
package com.velocitypowered.natives.compression;
|
package com.velocitypowered.natives.compression;
|
||||||
|
|
||||||
import com.velocitypowered.natives.util.Natives;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import io.netty.buffer.ByteBufUtil;
|
|
||||||
import io.netty.buffer.Unpooled;
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.api.condition.EnabledOnOs;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.zip.DataFormatException;
|
|
||||||
import java.util.zip.Deflater;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
import static org.junit.jupiter.api.condition.OS.LINUX;
|
import static org.junit.jupiter.api.condition.OS.LINUX;
|
||||||
import static org.junit.jupiter.api.condition.OS.MAC;
|
import static org.junit.jupiter.api.condition.OS.MAC;
|
||||||
|
|
||||||
|
import com.velocitypowered.natives.util.Natives;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.ByteBufUtil;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.zip.DataFormatException;
|
||||||
|
import java.util.zip.Deflater;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.condition.EnabledOnOs;
|
||||||
|
|
||||||
class VelocityCompressorTest {
|
class VelocityCompressorTest {
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void checkNatives() {
|
static void checkNatives() {
|
||||||
Natives.compressor.getLoadedVariant();
|
Natives.compressor.getLoadedVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnabledOnOs({ MAC, LINUX })
|
@EnabledOnOs({MAC, LINUX})
|
||||||
void nativeIntegrityCheck() throws DataFormatException {
|
void nativeIntegrityCheck() throws DataFormatException {
|
||||||
VelocityCompressor compressor = Natives.compressor.get().create(Deflater.DEFAULT_COMPRESSION);
|
VelocityCompressor compressor = Natives.compressor.get().create(Deflater.DEFAULT_COMPRESSION);
|
||||||
if (compressor instanceof JavaVelocityCompressor) {
|
if (compressor instanceof JavaVelocityCompressor) {
|
||||||
@ -36,7 +36,8 @@ class VelocityCompressorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void javaIntegrityCheck() throws DataFormatException {
|
void javaIntegrityCheck() throws DataFormatException {
|
||||||
VelocityCompressor compressor = JavaVelocityCompressor.FACTORY.create(Deflater.DEFAULT_COMPRESSION);
|
VelocityCompressor compressor = JavaVelocityCompressor.FACTORY
|
||||||
|
.create(Deflater.DEFAULT_COMPRESSION);
|
||||||
check(compressor);
|
check(compressor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
package com.velocitypowered.natives.encryption;
|
package com.velocitypowered.natives.encryption;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import com.velocitypowered.natives.util.Natives;
|
import com.velocitypowered.natives.util.Natives;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufUtil;
|
import io.netty.buffer.ByteBufUtil;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
|
import java.security.GeneralSecurityException;
|
||||||
|
import java.util.Random;
|
||||||
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
|
||||||
import java.security.GeneralSecurityException;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
class VelocityCipherTest {
|
class VelocityCipherTest {
|
||||||
|
|
||||||
private static final int ENCRYPT_DATA_SIZE = 1 << 16;
|
private static final int ENCRYPT_DATA_SIZE = 1 << 16;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
|
@ -2,17 +2,11 @@ plugins {
|
|||||||
id 'java'
|
id 'java'
|
||||||
id 'com.github.johnrengelman.shadow' version '2.0.4'
|
id 'com.github.johnrengelman.shadow' version '2.0.4'
|
||||||
id 'de.sebastianboegl.shadow.transformer.log4j' version '2.1.1'
|
id 'de.sebastianboegl.shadow.transformer.log4j' version '2.1.1'
|
||||||
|
id 'checkstyle'
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: '../gradle/checkerframework.gradle'
|
apply from: '../gradle/checkerframework.gradle'
|
||||||
|
apply from: '../gradle/checkstyle.gradle'
|
||||||
compileJava {
|
|
||||||
options.compilerArgs += ['-proc:none']
|
|
||||||
}
|
|
||||||
|
|
||||||
compileTestJava {
|
|
||||||
options.compilerArgs += ['-proc:none']
|
|
||||||
}
|
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
manifest {
|
manifest {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.velocitypowered.proxy;
|
package com.velocitypowered.proxy;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
|
||||||
|
|
||||||
public class Velocity {
|
public class Velocity {
|
||||||
|
|
||||||
private static final Logger logger = LogManager.getLogger(Velocity.class);
|
private static final Logger logger = LogManager.getLogger(Velocity.class);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
@ -24,7 +24,6 @@ import com.velocitypowered.proxy.config.AnnotatedConfig;
|
|||||||
import com.velocitypowered.proxy.config.VelocityConfiguration;
|
import com.velocitypowered.proxy.config.VelocityConfiguration;
|
||||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||||
import com.velocitypowered.proxy.console.VelocityConsole;
|
import com.velocitypowered.proxy.console.VelocityConsole;
|
||||||
import com.velocitypowered.proxy.util.VelocityChannelRegistrar;
|
|
||||||
import com.velocitypowered.proxy.network.ConnectionManager;
|
import com.velocitypowered.proxy.network.ConnectionManager;
|
||||||
import com.velocitypowered.proxy.network.http.NettyHttpClient;
|
import com.velocitypowered.proxy.network.http.NettyHttpClient;
|
||||||
import com.velocitypowered.proxy.plugin.VelocityEventManager;
|
import com.velocitypowered.proxy.plugin.VelocityEventManager;
|
||||||
@ -36,22 +35,28 @@ import com.velocitypowered.proxy.server.ServerMap;
|
|||||||
import com.velocitypowered.proxy.util.AddressUtil;
|
import com.velocitypowered.proxy.util.AddressUtil;
|
||||||
import com.velocitypowered.proxy.util.EncryptionUtils;
|
import com.velocitypowered.proxy.util.EncryptionUtils;
|
||||||
import com.velocitypowered.proxy.util.Ratelimiter;
|
import com.velocitypowered.proxy.util.Ratelimiter;
|
||||||
|
import com.velocitypowered.proxy.util.VelocityChannelRegistrar;
|
||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import net.kyori.text.Component;
|
|
||||||
import net.kyori.text.TextComponent;
|
|
||||||
import net.kyori.text.serializer.GsonComponentSerializer;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.checkerframework.checker.nullness.qual.*;
|
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.security.KeyPair;
|
import java.security.KeyPair;
|
||||||
import java.util.*;
|
import java.util.Collection;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import net.kyori.text.Component;
|
||||||
|
import net.kyori.text.TextComponent;
|
||||||
|
import net.kyori.text.serializer.GsonComponentSerializer;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||||
|
|
||||||
public class VelocityServer implements ProxyServer {
|
public class VelocityServer implements ProxyServer {
|
||||||
|
|
||||||
@ -118,7 +123,8 @@ public class VelocityServer implements ProxyServer {
|
|||||||
return commandManager;
|
return commandManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EnsuresNonNull({"serverKeyPair", "servers", "pluginManager", "eventManager", "scheduler", "console", "cm", "configuration"})
|
@EnsuresNonNull({"serverKeyPair", "servers", "pluginManager", "eventManager", "scheduler",
|
||||||
|
"console", "cm", "configuration"})
|
||||||
public void start() {
|
public void start() {
|
||||||
logger.info("Booting up {} {}...", getVersion().getName(), getVersion().getVersion());
|
logger.info("Booting up {} {}...", getVersion().getName(), getVersion().getVersion());
|
||||||
|
|
||||||
@ -142,12 +148,14 @@ public class VelocityServer implements ProxyServer {
|
|||||||
configuration = VelocityConfiguration.read(configPath);
|
configuration = VelocityConfiguration.read(configPath);
|
||||||
|
|
||||||
if (!configuration.validate()) {
|
if (!configuration.validate()) {
|
||||||
logger.error("Your configuration is invalid. Velocity will refuse to start up until the errors are resolved.");
|
logger.error(
|
||||||
|
"Your configuration is invalid. Velocity will refuse to start up until the errors are resolved.");
|
||||||
LogManager.shutdown();
|
LogManager.shutdown();
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
AnnotatedConfig.saveConfig(configuration.dumpConfig(), configPath); //Resave config to add new values
|
AnnotatedConfig
|
||||||
|
.saveConfig(configuration.dumpConfig(), configPath); //Resave config to add new values
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable to read/load/save your velocity.toml. The server will shut down.", e);
|
logger.error("Unable to read/load/save your velocity.toml. The server will shut down.", e);
|
||||||
@ -188,7 +196,8 @@ public class VelocityServer implements ProxyServer {
|
|||||||
Files.createDirectory(pluginPath);
|
Files.createDirectory(pluginPath);
|
||||||
} else {
|
} else {
|
||||||
if (!pluginPath.toFile().isDirectory()) {
|
if (!pluginPath.toFile().isDirectory()) {
|
||||||
logger.warn("Plugin location {} is not a directory, continuing without loading plugins", pluginPath);
|
logger.warn("Plugin location {} is not a directory, continuing without loading plugins",
|
||||||
|
pluginPath);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,7 +393,8 @@ public class VelocityServer implements ProxyServer {
|
|||||||
@Override
|
@Override
|
||||||
public InetSocketAddress getBoundAddress() {
|
public InetSocketAddress getBoundAddress() {
|
||||||
if (configuration == null) {
|
if (configuration == null) {
|
||||||
throw new IllegalStateException("No configuration"); // even though you'll never get the chance... heh, heh
|
throw new IllegalStateException(
|
||||||
|
"No configuration"); // even though you'll never get the chance... heh, heh
|
||||||
}
|
}
|
||||||
return configuration.getBind();
|
return configuration.getBind();
|
||||||
}
|
}
|
||||||
|
@ -9,17 +9,17 @@ import com.velocitypowered.api.proxy.ProxyServer;
|
|||||||
import com.velocitypowered.api.proxy.ServerConnection;
|
import com.velocitypowered.api.proxy.ServerConnection;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import net.kyori.text.TextComponent;
|
import net.kyori.text.TextComponent;
|
||||||
import net.kyori.text.event.ClickEvent;
|
import net.kyori.text.event.ClickEvent;
|
||||||
import net.kyori.text.event.HoverEvent;
|
import net.kyori.text.event.HoverEvent;
|
||||||
import net.kyori.text.format.TextColor;
|
import net.kyori.text.format.TextColor;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class ServerCommand implements Command {
|
public class ServerCommand implements Command {
|
||||||
|
|
||||||
private final ProxyServer server;
|
private final ProxyServer server;
|
||||||
|
|
||||||
public ServerCommand(ProxyServer server) {
|
public ServerCommand(ProxyServer server) {
|
||||||
@ -39,18 +39,22 @@ public class ServerCommand implements Command {
|
|||||||
String serverName = args[0];
|
String serverName = args[0];
|
||||||
Optional<RegisteredServer> toConnect = server.getServer(serverName);
|
Optional<RegisteredServer> toConnect = server.getServer(serverName);
|
||||||
if (!toConnect.isPresent()) {
|
if (!toConnect.isPresent()) {
|
||||||
player.sendMessage(TextComponent.of("Server " + serverName + " doesn't exist.", TextColor.RED));
|
player.sendMessage(
|
||||||
|
TextComponent.of("Server " + serverName + " doesn't exist.", TextColor.RED));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
player.createConnectionRequest(toConnect.get()).fireAndForget();
|
player.createConnectionRequest(toConnect.get()).fireAndForget();
|
||||||
} else {
|
} else {
|
||||||
String currentServer = player.getCurrentServer().map(ServerConnection::getServerInfo).map(ServerInfo::getName)
|
String currentServer = player.getCurrentServer().map(ServerConnection::getServerInfo)
|
||||||
|
.map(ServerInfo::getName)
|
||||||
.orElse("<unknown>");
|
.orElse("<unknown>");
|
||||||
player.sendMessage(TextComponent.of("You are currently connected to " + currentServer + ".", TextColor.YELLOW));
|
player.sendMessage(TextComponent
|
||||||
|
.of("You are currently connected to " + currentServer + ".", TextColor.YELLOW));
|
||||||
|
|
||||||
// Assemble the list of servers as components
|
// Assemble the list of servers as components
|
||||||
TextComponent.Builder serverListBuilder = TextComponent.builder("Available servers: ").color(TextColor.YELLOW);
|
TextComponent.Builder serverListBuilder = TextComponent.builder("Available servers: ")
|
||||||
|
.color(TextColor.YELLOW);
|
||||||
List<RegisteredServer> infos = ImmutableList.copyOf(server.getAllServers());
|
List<RegisteredServer> infos = ImmutableList.copyOf(server.getAllServers());
|
||||||
for (int i = 0; i < infos.size(); i++) {
|
for (int i = 0; i < infos.size(); i++) {
|
||||||
RegisteredServer rs = infos.get(i);
|
RegisteredServer rs = infos.get(i);
|
||||||
@ -62,8 +66,10 @@ public class ServerCommand implements Command {
|
|||||||
TextComponent.of("Currently connected to this server\n" + playersText)));
|
TextComponent.of("Currently connected to this server\n" + playersText)));
|
||||||
} else {
|
} else {
|
||||||
infoComponent = infoComponent.color(TextColor.GRAY)
|
infoComponent = infoComponent.color(TextColor.GRAY)
|
||||||
.clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/server " + rs.getServerInfo().getName()))
|
.clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND,
|
||||||
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to connect to this server\n" + playersText)));
|
"/server " + rs.getServerInfo().getName()))
|
||||||
|
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||||
|
TextComponent.of("Click to connect to this server\n" + playersText)));
|
||||||
}
|
}
|
||||||
serverListBuilder.append(infoComponent);
|
serverListBuilder.append(infoComponent);
|
||||||
if (i != infos.size() - 1) {
|
if (i != infos.size() - 1) {
|
||||||
|
@ -8,6 +8,7 @@ import net.kyori.text.format.TextColor;
|
|||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public class ShutdownCommand implements Command {
|
public class ShutdownCommand implements Command {
|
||||||
|
|
||||||
private final VelocityServer server;
|
private final VelocityServer server;
|
||||||
|
|
||||||
public ShutdownCommand(VelocityServer server) {
|
public ShutdownCommand(VelocityServer server) {
|
||||||
@ -17,7 +18,8 @@ public class ShutdownCommand implements Command {
|
|||||||
@Override
|
@Override
|
||||||
public void execute(CommandSource source, String @NonNull [] args) {
|
public void execute(CommandSource source, String @NonNull [] args) {
|
||||||
if (source != server.getConsoleCommandSource()) {
|
if (source != server.getConsoleCommandSource()) {
|
||||||
source.sendMessage(TextComponent.of("You are not allowed to use this command.", TextColor.RED));
|
source
|
||||||
|
.sendMessage(TextComponent.of("You are not allowed to use this command.", TextColor.RED));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
server.shutdown();
|
server.shutdown();
|
||||||
|
@ -7,19 +7,19 @@ import com.velocitypowered.api.command.CommandSource;
|
|||||||
import com.velocitypowered.api.permission.Tristate;
|
import com.velocitypowered.api.permission.Tristate;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
import com.velocitypowered.api.util.ProxyVersion;
|
import com.velocitypowered.api.util.ProxyVersion;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import net.kyori.text.TextComponent;
|
import net.kyori.text.TextComponent;
|
||||||
import net.kyori.text.event.ClickEvent;
|
import net.kyori.text.event.ClickEvent;
|
||||||
import net.kyori.text.format.TextColor;
|
import net.kyori.text.format.TextColor;
|
||||||
import net.kyori.text.format.TextDecoration;
|
import net.kyori.text.format.TextDecoration;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class VelocityCommand implements Command {
|
public class VelocityCommand implements Command {
|
||||||
|
|
||||||
private final Map<String, Command> subcommands;
|
private final Map<String, Command> subcommands;
|
||||||
|
|
||||||
public VelocityCommand(ProxyServer server) {
|
public VelocityCommand(ProxyServer server) {
|
||||||
@ -86,6 +86,7 @@ public class VelocityCommand implements Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class Info implements Command {
|
private static class Info implements Command {
|
||||||
|
|
||||||
private final ProxyServer server;
|
private final ProxyServer server;
|
||||||
|
|
||||||
private Info(ProxyServer server) {
|
private Info(ProxyServer server) {
|
||||||
@ -101,7 +102,9 @@ public class VelocityCommand implements Command {
|
|||||||
.color(TextColor.DARK_AQUA)
|
.color(TextColor.DARK_AQUA)
|
||||||
.append(TextComponent.of(version.getVersion()).decoration(TextDecoration.BOLD, false))
|
.append(TextComponent.of(version.getVersion()).decoration(TextDecoration.BOLD, false))
|
||||||
.build();
|
.build();
|
||||||
TextComponent copyright = TextComponent.of("Copyright 2018 " + version.getVendor() + ". " + version.getName() + " is freely licensed under the terms of the " +
|
TextComponent copyright = TextComponent
|
||||||
|
.of("Copyright 2018 " + version.getVendor() + ". " + version.getName()
|
||||||
|
+ " is freely licensed under the terms of the " +
|
||||||
"MIT License.");
|
"MIT License.");
|
||||||
source.sendMessage(velocity);
|
source.sendMessage(velocity);
|
||||||
source.sendMessage(copyright);
|
source.sendMessage(copyright);
|
||||||
@ -111,12 +114,14 @@ public class VelocityCommand implements Command {
|
|||||||
.content("Visit the ")
|
.content("Visit the ")
|
||||||
.append(TextComponent.builder("Velocity website")
|
.append(TextComponent.builder("Velocity website")
|
||||||
.color(TextColor.GREEN)
|
.color(TextColor.GREEN)
|
||||||
.clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.velocitypowered.com"))
|
.clickEvent(
|
||||||
|
new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.velocitypowered.com"))
|
||||||
.build())
|
.build())
|
||||||
.append(TextComponent.of(" or the ").resetStyle())
|
.append(TextComponent.of(" or the ").resetStyle())
|
||||||
.append(TextComponent.builder("Velocity GitHub")
|
.append(TextComponent.builder("Velocity GitHub")
|
||||||
.color(TextColor.GREEN)
|
.color(TextColor.GREEN)
|
||||||
.clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/VelocityPowered/Velocity"))
|
.clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL,
|
||||||
|
"https://github.com/VelocityPowered/Velocity"))
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
source.sendMessage(velocityWebsite);
|
source.sendMessage(velocityWebsite);
|
||||||
|
@ -5,11 +5,16 @@ import com.google.common.collect.ImmutableList;
|
|||||||
import com.velocitypowered.api.command.Command;
|
import com.velocitypowered.api.command.Command;
|
||||||
import com.velocitypowered.api.command.CommandManager;
|
import com.velocitypowered.api.command.CommandManager;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class VelocityCommandManager implements CommandManager {
|
public class VelocityCommandManager implements CommandManager {
|
||||||
|
|
||||||
private final Map<String, Command> commands = new HashMap<>();
|
private final Map<String, Command> commands = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -98,7 +103,8 @@ public class VelocityCommandManager implements CommandManager {
|
|||||||
|
|
||||||
return command.suggest(source, actualArgs);
|
return command.suggest(source, actualArgs);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Unable to invoke suggestions for command " + alias + " for " + source, e);
|
throw new RuntimeException(
|
||||||
|
"Unable to invoke suggestions for command " + alias + " for " + source, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden Mehr anzeigen
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren