mirror of
https://github.com/plexusorg/Plex.git
synced 2026-06-04 21:46:55 +00:00
Begin work on the Plex API
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package dev.plex.api.impl;
|
||||
|
||||
import dev.plex.api.ApiCompatibility;
|
||||
|
||||
final class DefaultApiCompatibility implements ApiCompatibility
|
||||
{
|
||||
private final int version;
|
||||
|
||||
DefaultApiCompatibility(int version)
|
||||
{
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package dev.plex.api.impl;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.api.config.ConfigurationApi;
|
||||
import dev.plex.api.config.PlexConfiguration;
|
||||
|
||||
final class DefaultConfigurationApi implements ConfigurationApi
|
||||
{
|
||||
private final Plex plugin;
|
||||
|
||||
DefaultConfigurationApi(Plex plugin)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlexConfiguration mainConfig()
|
||||
{
|
||||
return new DefaultPlexConfiguration(plugin.getConfig());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlexConfiguration messages()
|
||||
{
|
||||
throw new UnsupportedOperationException("Proxy does not provide messages configuration");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlexConfiguration indefiniteBans()
|
||||
{
|
||||
throw new UnsupportedOperationException("Proxy does not provide indefinite bans configuration");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlexConfiguration toggles()
|
||||
{
|
||||
throw new UnsupportedOperationException("Proxy does not provide toggles configuration");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package dev.plex.api.impl;
|
||||
|
||||
import dev.plex.api.module.ModulesApi;
|
||||
import dev.plex.module.PlexModuleFile;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
final class DefaultModulesApi implements ModulesApi
|
||||
{
|
||||
@Override
|
||||
public Collection<PlexModuleFile> loadedModules()
|
||||
{
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PlexModuleFile> module(String name)
|
||||
{
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package dev.plex.api.impl;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.api.ApiCompatibility;
|
||||
import dev.plex.api.PlexApi;
|
||||
import dev.plex.api.command.CommandApi;
|
||||
import dev.plex.api.config.ConfigurationApi;
|
||||
import dev.plex.api.config.ModuleConfigApi;
|
||||
import dev.plex.api.listener.ListenerApi;
|
||||
import dev.plex.api.logging.LoggingApi;
|
||||
import dev.plex.api.message.MessageApi;
|
||||
import dev.plex.api.module.ModulesApi;
|
||||
import dev.plex.api.player.PlayersApi;
|
||||
import dev.plex.api.punishment.PunishmentsApi;
|
||||
import dev.plex.api.scheduler.SchedulerApi;
|
||||
import dev.plex.api.storage.StorageApi;
|
||||
|
||||
public final class DefaultPlexApi implements PlexApi
|
||||
{
|
||||
private final ApiCompatibility compatibility;
|
||||
private final ConfigurationApi configuration;
|
||||
private final ModulesApi modules;
|
||||
|
||||
public DefaultPlexApi(Plex plugin, int apiCompatibilityVersion)
|
||||
{
|
||||
this.compatibility = new DefaultApiCompatibility(apiCompatibilityVersion);
|
||||
this.configuration = new DefaultConfigurationApi(plugin);
|
||||
this.modules = new DefaultModulesApi();
|
||||
}
|
||||
|
||||
@Override public ApiCompatibility compatibility() { return compatibility; }
|
||||
@Override public ConfigurationApi configuration() { return configuration; }
|
||||
@Override public ModulesApi modules() { return modules; }
|
||||
@Override public CommandApi commands() { throw unsupported(); }
|
||||
@Override public ListenerApi listeners() { throw unsupported(); }
|
||||
@Override public ModuleConfigApi moduleConfigs() { throw unsupported(); }
|
||||
@Override public LoggingApi logging() { throw unsupported(); }
|
||||
@Override public MessageApi messages() { throw unsupported(); }
|
||||
@Override public PlayersApi players() { throw unsupported(); }
|
||||
@Override public PunishmentsApi punishments() { throw unsupported(); }
|
||||
@Override public SchedulerApi scheduler() { throw unsupported(); }
|
||||
@Override public StorageApi storage() { throw unsupported(); }
|
||||
|
||||
private static UnsupportedOperationException unsupported()
|
||||
{
|
||||
return new UnsupportedOperationException("This Plex API service is only available on the server platform");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package dev.plex.api.impl;
|
||||
|
||||
import dev.plex.api.config.PlexConfiguration;
|
||||
import dev.plex.config.TomlConfig;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
final class DefaultPlexConfiguration implements PlexConfiguration
|
||||
{
|
||||
private final TomlConfig config;
|
||||
|
||||
DefaultPlexConfiguration(TomlConfig config)
|
||||
{
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String path)
|
||||
{
|
||||
return config.getToml().getString(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String path)
|
||||
{
|
||||
return config.getToml().getBoolean(path, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(String path)
|
||||
{
|
||||
Long value = config.getToml().getLong(path, 0L);
|
||||
return value.intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getStringList(String path)
|
||||
{
|
||||
return config.getToml().getList(path, List.of());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(String path, Object value)
|
||||
{
|
||||
throw new UnsupportedOperationException("Proxy TOML configuration writes are not supported through PlexConfiguration");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComments(String path, List<String> comments)
|
||||
{
|
||||
throw new UnsupportedOperationException("Proxy TOML configuration comments are not supported through PlexConfiguration");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save()
|
||||
{
|
||||
throw new UnsupportedOperationException("Proxy TOML configuration saves are not supported through PlexConfiguration");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user