Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 00:22:51 +01:00
Change group id to com.viaversion
Dieser Commit ist enthalten in:
Ursprung
f18e2b3875
Commit
c02047aaf8
@ -26,44 +26,56 @@ import com.google.common.base.Preconditions;
|
|||||||
import us.myles.ViaVersion.ViaManager;
|
import us.myles.ViaVersion.ViaManager;
|
||||||
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
||||||
|
|
||||||
public class Via {
|
public final class Via {
|
||||||
private static ViaManager manager;
|
private static ViaManager manager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the API associated with the current platform.
|
||||||
|
*
|
||||||
|
* @return API instance
|
||||||
|
* @throws IllegalArgumentException if the platform has not loaded yet
|
||||||
|
*/
|
||||||
|
public static ViaAPI getAPI() {
|
||||||
|
return manager().getPlatform().getApi();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ViaManager with methods beyond the simple API {@link ViaAPI} provides.
|
||||||
|
*
|
||||||
|
* @return manager to interact with various Via parts
|
||||||
|
* @throws IllegalArgumentException if the platform has not loaded yet
|
||||||
|
*/
|
||||||
|
public static ViaManager getManager() {
|
||||||
|
return manager();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the config associated with the current platform.
|
||||||
|
*
|
||||||
|
* @return config instance
|
||||||
|
* @throws IllegalArgumentException if the platform has not loaded yet
|
||||||
|
*/
|
||||||
|
public static ViaVersionConfig getConfig() {
|
||||||
|
return manager().getPlatform().getConf();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ViaPlatform getPlatform() {
|
||||||
|
return manager().getPlatform();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the ViaManager associated with the platform.
|
* Register the ViaManager associated with the platform.
|
||||||
*
|
*
|
||||||
* @param viaManager The ViaManager
|
* @param viaManager The ViaManager
|
||||||
|
* @throws IllegalArgumentException if the manager has already been set
|
||||||
*/
|
*/
|
||||||
public static void init(ViaManager viaManager) {
|
public static void init(ViaManager viaManager) {
|
||||||
Preconditions.checkArgument(manager == null, "ViaManager is already set");
|
Preconditions.checkArgument(manager == null, "ViaManager is already set");
|
||||||
Via.manager = viaManager;
|
Via.manager = viaManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private static ViaManager manager() {
|
||||||
* Returns the API associated with the current platform.
|
|
||||||
*
|
|
||||||
* @return API instance
|
|
||||||
*/
|
|
||||||
public static ViaAPI getAPI() {
|
|
||||||
Preconditions.checkArgument(manager != null, "ViaVersion has not loaded the platform yet");
|
Preconditions.checkArgument(manager != null, "ViaVersion has not loaded the platform yet");
|
||||||
return manager.getPlatform().getApi();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the config associated with the current platform.
|
|
||||||
*
|
|
||||||
* @return Config instance
|
|
||||||
*/
|
|
||||||
public static ViaVersionConfig getConfig() {
|
|
||||||
Preconditions.checkArgument(manager != null, "ViaVersion has not loaded the platform yet");
|
|
||||||
return manager.getPlatform().getConf();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ViaPlatform getPlatform() {
|
|
||||||
return manager.getPlatform();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ViaManager getManager() {
|
|
||||||
return manager;
|
return manager;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
group = "us.myles"
|
group = "com.viaversion"
|
||||||
version = "4.0.0-21w16a"
|
version = "4.0.0-21w16a"
|
||||||
description = "Allow newer clients to join older server versions."
|
description = "Allow newer clients to join older server versions."
|
||||||
}
|
}
|
||||||
|
@ -45,22 +45,16 @@ import java.util.Set;
|
|||||||
import static us.myles.ViaVersion.api.command.ViaSubCommand.color;
|
import static us.myles.ViaVersion.api.command.ViaSubCommand.color;
|
||||||
|
|
||||||
public abstract class ViaCommandHandler implements ViaVersionCommand {
|
public abstract class ViaCommandHandler implements ViaVersionCommand {
|
||||||
private final Map<String, ViaSubCommand> commandMap;
|
private final Map<String, ViaSubCommand> commandMap = new HashMap<>();
|
||||||
|
|
||||||
public ViaCommandHandler() {
|
protected ViaCommandHandler() {
|
||||||
commandMap = new HashMap<>();
|
registerDefaults();
|
||||||
try {
|
|
||||||
registerDefaults();
|
|
||||||
} catch (Exception e) {
|
|
||||||
//ignore never throws exception because it doesn't exists
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerSubCommand(ViaSubCommand command) throws Exception {
|
public void registerSubCommand(ViaSubCommand command) {
|
||||||
Preconditions.checkArgument(command.name().matches("^[a-z0-9_-]{3,15}$"), command.name() + " is not a valid sub-command name.");
|
Preconditions.checkArgument(command.name().matches("^[a-z0-9_-]{3,15}$"), command.name() + " is not a valid sub-command name.");
|
||||||
if (hasSubCommand(command.name()))
|
Preconditions.checkArgument(!hasSubCommand(command.name()), "ViaSubCommand " + command.name() + " does already exists!");
|
||||||
throw new Exception("ViaSubCommand " + command.name() + " does already exists!"); //Maybe another exception later.
|
|
||||||
commandMap.put(command.name().toLowerCase(Locale.ROOT), command);
|
commandMap.put(command.name().toLowerCase(Locale.ROOT), command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,8 +89,9 @@ public abstract class ViaCommandHandler implements ViaVersionCommand {
|
|||||||
|
|
||||||
String[] subArgs = Arrays.copyOfRange(args, 1, args.length);
|
String[] subArgs = Arrays.copyOfRange(args, 1, args.length);
|
||||||
boolean result = handler.execute(sender, subArgs);
|
boolean result = handler.execute(sender, subArgs);
|
||||||
if (!result)
|
if (!result) {
|
||||||
sender.sendMessage("Usage: /viaversion " + handler.usage());
|
sender.sendMessage("Usage: /viaversion " + handler.usage());
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,20 +103,24 @@ public abstract class ViaCommandHandler implements ViaVersionCommand {
|
|||||||
//SubCommands tabcomplete
|
//SubCommands tabcomplete
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
if (!args[0].isEmpty()) {
|
if (!args[0].isEmpty()) {
|
||||||
for (ViaSubCommand sub : allowed)
|
for (ViaSubCommand sub : allowed) {
|
||||||
if (sub.name().toLowerCase().startsWith(args[0].toLowerCase(Locale.ROOT)))
|
if (sub.name().toLowerCase().startsWith(args[0].toLowerCase(Locale.ROOT))) {
|
||||||
output.add(sub.name());
|
output.add(sub.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
for (ViaSubCommand sub : allowed)
|
for (ViaSubCommand sub : allowed) {
|
||||||
output.add(sub.name());
|
output.add(sub.name());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Let the SubCommand handle it
|
//Let the SubCommand handle it
|
||||||
else if (args.length >= 2) {
|
else if (args.length >= 2) {
|
||||||
if (getSubCommand(args[0]) != null) {
|
if (getSubCommand(args[0]) != null) {
|
||||||
ViaSubCommand sub = getSubCommand(args[0]);
|
ViaSubCommand sub = getSubCommand(args[0]);
|
||||||
if (!allowed.contains(sub))
|
if (!allowed.contains(sub)) {
|
||||||
return output;
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
String[] subArgs = Arrays.copyOfRange(args, 1, args.length);
|
String[] subArgs = Arrays.copyOfRange(args, 1, args.length);
|
||||||
|
|
||||||
@ -147,16 +146,19 @@ public abstract class ViaCommandHandler implements ViaVersionCommand {
|
|||||||
}
|
}
|
||||||
sender.sendMessage(color("&aViaVersion &c" + Via.getPlatform().getPluginVersion()));
|
sender.sendMessage(color("&aViaVersion &c" + Via.getPlatform().getPluginVersion()));
|
||||||
sender.sendMessage(color("&6Commands:"));
|
sender.sendMessage(color("&6Commands:"));
|
||||||
for (ViaSubCommand cmd : allowed)
|
for (ViaSubCommand cmd : allowed) {
|
||||||
sender.sendMessage(color(String.format("&2/viaversion %s &7- &6%s", cmd.usage(), cmd.description())));
|
sender.sendMessage(color(String.format("&2/viaversion %s &7- &6%s", cmd.usage(), cmd.description())));
|
||||||
|
}
|
||||||
allowed.clear();
|
allowed.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<ViaSubCommand> calculateAllowedCommands(ViaCommandSender sender) {
|
private Set<ViaSubCommand> calculateAllowedCommands(ViaCommandSender sender) {
|
||||||
Set<ViaSubCommand> cmds = new HashSet<>();
|
Set<ViaSubCommand> cmds = new HashSet<>();
|
||||||
for (ViaSubCommand sub : commandMap.values())
|
for (ViaSubCommand sub : commandMap.values()) {
|
||||||
if (hasPermission(sender, sub.permission()))
|
if (hasPermission(sender, sub.permission())) {
|
||||||
cmds.add(sub);
|
cmds.add(sub);
|
||||||
|
}
|
||||||
|
}
|
||||||
return cmds;
|
return cmds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +166,7 @@ public abstract class ViaCommandHandler implements ViaVersionCommand {
|
|||||||
return permission == null || sender.hasPermission(permission);
|
return permission == null || sender.hasPermission(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerDefaults() throws Exception {
|
private void registerDefaults() {
|
||||||
registerSubCommand(new ListSubCmd());
|
registerSubCommand(new ListSubCmd());
|
||||||
registerSubCommand(new PPSSubCmd());
|
registerSubCommand(new PPSSubCmd());
|
||||||
registerSubCommand(new DebugSubCmd());
|
registerSubCommand(new DebugSubCmd());
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren