3
0
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:
KennyTV 2021-04-24 20:54:38 +02:00
Ursprung f18e2b3875
Commit c02047aaf8
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
3 geänderte Dateien mit 60 neuen und 46 gelöschten Zeilen

Datei anzeigen

@ -26,44 +26,56 @@ import com.google.common.base.Preconditions;
import us.myles.ViaVersion.ViaManager;
import us.myles.ViaVersion.api.platform.ViaPlatform;
public class Via {
public final class Via {
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.
*
* @param viaManager The ViaManager
* @throws IllegalArgumentException if the manager has already been set
*/
public static void init(ViaManager viaManager) {
Preconditions.checkArgument(manager == null, "ViaManager is already set");
Via.manager = viaManager;
}
/**
* Returns the API associated with the current platform.
*
* @return API instance
*/
public static ViaAPI getAPI() {
private static ViaManager manager() {
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;
}
}

Datei anzeigen

@ -7,7 +7,7 @@ plugins {
}
allprojects {
group = "us.myles"
group = "com.viaversion"
version = "4.0.0-21w16a"
description = "Allow newer clients to join older server versions."
}

Datei anzeigen

@ -45,22 +45,16 @@ import java.util.Set;
import static us.myles.ViaVersion.api.command.ViaSubCommand.color;
public abstract class ViaCommandHandler implements ViaVersionCommand {
private final Map<String, ViaSubCommand> commandMap;
private final Map<String, ViaSubCommand> commandMap = new HashMap<>();
public ViaCommandHandler() {
commandMap = new HashMap<>();
try {
protected ViaCommandHandler() {
registerDefaults();
} catch (Exception e) {
//ignore never throws exception because it doesn't exists
}
}
@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.");
if (hasSubCommand(command.name()))
throw new Exception("ViaSubCommand " + command.name() + " does already exists!"); //Maybe another exception later.
Preconditions.checkArgument(!hasSubCommand(command.name()), "ViaSubCommand " + command.name() + " does already exists!");
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);
boolean result = handler.execute(sender, subArgs);
if (!result)
if (!result) {
sender.sendMessage("Usage: /viaversion " + handler.usage());
}
return result;
}
@ -108,20 +103,24 @@ public abstract class ViaCommandHandler implements ViaVersionCommand {
//SubCommands tabcomplete
if (args.length == 1) {
if (!args[0].isEmpty()) {
for (ViaSubCommand sub : allowed)
if (sub.name().toLowerCase().startsWith(args[0].toLowerCase(Locale.ROOT)))
for (ViaSubCommand sub : allowed) {
if (sub.name().toLowerCase().startsWith(args[0].toLowerCase(Locale.ROOT))) {
output.add(sub.name());
}
}
} else {
for (ViaSubCommand sub : allowed)
for (ViaSubCommand sub : allowed) {
output.add(sub.name());
}
}
}
//Let the SubCommand handle it
else if (args.length >= 2) {
if (getSubCommand(args[0]) != null) {
ViaSubCommand sub = getSubCommand(args[0]);
if (!allowed.contains(sub))
if (!allowed.contains(sub)) {
return output;
}
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("&6Commands:"));
for (ViaSubCommand cmd : allowed)
for (ViaSubCommand cmd : allowed) {
sender.sendMessage(color(String.format("&2/viaversion %s &7- &6%s", cmd.usage(), cmd.description())));
}
allowed.clear();
}
private Set<ViaSubCommand> calculateAllowedCommands(ViaCommandSender sender) {
Set<ViaSubCommand> cmds = new HashSet<>();
for (ViaSubCommand sub : commandMap.values())
if (hasPermission(sender, sub.permission()))
for (ViaSubCommand sub : commandMap.values()) {
if (hasPermission(sender, sub.permission())) {
cmds.add(sub);
}
}
return cmds;
}
@ -164,7 +166,7 @@ public abstract class ViaCommandHandler implements ViaVersionCommand {
return permission == null || sender.hasPermission(permission);
}
private void registerDefaults() throws Exception {
private void registerDefaults() {
registerSubCommand(new ListSubCmd());
registerSubCommand(new PPSSubCmd());
registerSubCommand(new DebugSubCmd());