Begin work on the Plex API

This commit is contained in:
2026-05-19 12:32:56 -04:00
parent 64c691bb58
commit 9fa8d82217
142 changed files with 1960 additions and 566 deletions
+60
View File
@@ -1,7 +1,12 @@
package dev.plex;
import dev.plex.api.PlexApi;
import dev.plex.api.impl.DefaultPlexApi;
import dev.plex.cache.PlayerCache;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.config.Config;
import dev.plex.config.ModuleConfig;
import dev.plex.handlers.CommandHandler;
import dev.plex.handlers.ListenerHandler;
import dev.plex.hook.CoreProtectHook;
@@ -45,6 +50,7 @@ import org.bukkit.plugin.java.JavaPlugin;
public class Plex extends JavaPlugin
{
public static final BuildInfo build = new BuildInfo();
public static final int MODULE_API_COMPATIBILITY_VERSION = 1;
private static Plex plugin;
public Config config;
public Config messages;
@@ -66,6 +72,7 @@ public class Plex extends JavaPlugin
private ServiceManager serviceManager;
private PunishmentManager punishmentManager;
private UpdateChecker updateChecker;
private PlexApi api;
private Permission permissions;
private Chat chat;
@@ -88,6 +95,8 @@ public class Plex extends JavaPlugin
indefBans = new Config(this, "indefbans.yml");
toggles = new Config(this, "toggles.yml");
build.load(this);
api = new DefaultPlexApi(this, MODULE_API_COMPATIBILITY_VERSION);
installModuleApiRuntimes();
modulesFolder = new File(this.getDataFolder() + File.separator + "modules");
if (!modulesFolder.exists())
@@ -102,6 +111,57 @@ public class Plex extends JavaPlugin
//this.setChatHandler(new ChatListener.ChatHandlerImpl());
}
private void installModuleApiRuntimes()
{
ServerCommand.setRuntime(new ServerCommand.Runtime()
{
@Override
public Plex plugin()
{
return Plex.this;
}
@Override
public void register(org.bukkit.command.Command command)
{
api.commands().register(command);
}
});
PlexCommand.setRuntime(new PlexCommand.Runtime()
{
@Override
public void register(org.bukkit.command.Command command)
{
api.commands().register(command);
}
@Override
public net.kyori.adventure.text.Component messageComponent(String entry, Object... objects)
{
return api.messages().messageComponent(entry, objects);
}
@Override
public net.kyori.adventure.text.Component messageComponent(String entry, net.kyori.adventure.text.Component... objects)
{
return api.messages().messageComponent(entry, objects);
}
@Override
public String messageString(String entry, Object... objects)
{
return api.messages().messageString(entry, objects);
}
@Override
public net.kyori.adventure.text.Component miniMessage(String input)
{
return api.messages().miniMessage(input);
}
});
ModuleConfig.setFactory((module, from, to) -> api.moduleConfigs().create(module, from, to));
}
@Override
public void onEnable()
{
@@ -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,28 @@
package dev.plex.api.impl;
import dev.plex.Plex;
import dev.plex.api.command.CommandApi;
import org.bukkit.command.Command;
final class DefaultCommandApi implements CommandApi
{
private final Plex plugin;
DefaultCommandApi(Plex plugin) { this.plugin = plugin; }
@Override
public void register(Command command)
{
plugin.getServer().getCommandMap().getKnownCommands().remove(command.getName().toLowerCase());
command.getAliases().forEach(alias -> plugin.getServer().getCommandMap().getKnownCommands().remove(alias.toLowerCase()));
plugin.getServer().getCommandMap().register("plex", command);
}
@Override
public void unregister(Command command)
{
plugin.getServer().getCommandMap().getKnownCommands().remove(command.getName());
command.getAliases().forEach(alias -> plugin.getServer().getCommandMap().getKnownCommands().remove(alias));
command.unregister(plugin.getServer().getCommandMap());
}
}
@@ -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.config);
}
@Override
public PlexConfiguration messages()
{
return new DefaultPlexConfiguration(plugin.messages);
}
@Override
public PlexConfiguration indefiniteBans()
{
return new DefaultPlexConfiguration(plugin.indefBans);
}
@Override
public PlexConfiguration toggles()
{
return new DefaultPlexConfiguration(plugin.toggles);
}
}
@@ -0,0 +1,14 @@
package dev.plex.api.impl;
import dev.plex.api.punishment.IndefiniteBanView;
import dev.plex.punishment.PunishmentManager;
import java.util.List;
import java.util.UUID;
record DefaultIndefiniteBanView(PunishmentManager.IndefiniteBan ban) implements IndefiniteBanView
{
@Override public List<String> usernames() { return List.copyOf(ban.getUsernames()); }
@Override public List<UUID> uuids() { return List.copyOf(ban.getUuids()); }
@Override public List<String> ips() { return List.copyOf(ban.getIps()); }
@Override public String reason() { return ban.getReason(); }
}
@@ -0,0 +1,19 @@
package dev.plex.api.impl;
import dev.plex.Plex;
import dev.plex.api.listener.ListenerApi;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
final class DefaultListenerApi implements ListenerApi
{
private final Plex plugin;
DefaultListenerApi(Plex plugin) { this.plugin = plugin; }
@Override
public void register(Listener listener) { plugin.getServer().getPluginManager().registerEvents(listener, plugin); }
@Override
public void unregister(Listener listener) { HandlerList.unregisterAll(listener); }
}
@@ -0,0 +1,12 @@
package dev.plex.api.impl;
import dev.plex.api.logging.LoggingApi;
import dev.plex.util.PlexLog;
final class DefaultLoggingApi implements LoggingApi
{
@Override public void info(String message, Object... args) { PlexLog.log(message, args); }
@Override public void debug(String message, Object... args) { PlexLog.debug(message, args); }
@Override public void warn(String message, Object... args) { PlexLog.warn(message, args); }
@Override public void error(String message, Object... args) { PlexLog.error(message, args); }
}
@@ -0,0 +1,17 @@
package dev.plex.api.impl;
import dev.plex.api.message.MessageApi;
import dev.plex.util.PlexUtils;
import java.util.List;
import net.kyori.adventure.text.Component;
final class DefaultMessageApi implements MessageApi
{
@Override public Component messageComponent(String entry, Object... objects) { return PlexUtils.messageComponent(entry, objects); }
@Override public Component messageComponent(String entry, Component... objects) { return PlexUtils.messageComponent(entry, objects); }
@Override public String messageString(String entry, Object... objects) { return PlexUtils.messageString(entry, objects); }
@Override public Component miniMessage(String input) { return PlexUtils.mmDeserialize(input); }
@Override public void broadcast(String miniMessage) { PlexUtils.broadcast(miniMessage); }
@Override public void broadcast(Component component) { PlexUtils.broadcast(component); }
@Override public List<String> onlinePlayerNames() { return PlexUtils.getPlayerNameList(); }
}
@@ -0,0 +1,14 @@
package dev.plex.api.impl;
import dev.plex.api.config.ModuleConfigApi;
import dev.plex.api.config.ModuleConfiguration;
import dev.plex.module.PlexModule;
final class DefaultModuleConfigApi implements ModuleConfigApi
{
@Override
public ModuleConfiguration create(PlexModule module, String from, String to)
{
return new ServerModuleConfiguration(module, from, to);
}
}
@@ -0,0 +1,36 @@
package dev.plex.api.impl;
import dev.plex.Plex;
import dev.plex.api.module.ModulesApi;
import dev.plex.module.PlexModuleFile;
import java.util.Collection;
import java.util.Locale;
import java.util.Optional;
final class DefaultModulesApi implements ModulesApi
{
private final Plex plugin;
DefaultModulesApi(Plex plugin)
{
this.plugin = plugin;
}
@Override
public Collection<PlexModuleFile> loadedModules()
{
return plugin.getModuleManager().getModules().stream()
.map(module -> module.getPlexModuleFile())
.toList();
}
@Override
public Optional<PlexModuleFile> module(String name)
{
String normalizedName = name.toLowerCase(Locale.ROOT);
return loadedModules().stream()
.filter(module -> module.getName().toLowerCase(Locale.ROOT).equals(normalizedName))
.findFirst();
}
}
@@ -0,0 +1,27 @@
package dev.plex.api.impl;
import dev.plex.Plex;
import dev.plex.api.player.PlayersApi;
import dev.plex.api.player.PlexPlayerView;
import dev.plex.player.PlexPlayer;
import dev.plex.util.PlexUtils;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
final class DefaultPlayersApi implements PlayersApi
{
private final Plex plugin;
DefaultPlayersApi(Plex plugin) { this.plugin = plugin; }
@Override public Optional<? extends PlexPlayerView> byUuid(UUID uuid) { return Optional.ofNullable(plugin.getPlayerService().getPlayer(uuid)).map(DefaultPlexPlayerView::new); }
@Override public Optional<? extends PlexPlayerView> byName(String name) { return Optional.ofNullable(plugin.getPlayerService().getPlayer(name)).map(DefaultPlexPlayerView::new); }
@Override public List<String> onlineNames() { return PlexUtils.getPlayerNameList(); }
static PlexPlayer unwrap(PlexPlayerView view)
{
if (view instanceof DefaultPlexPlayerView wrapped) return wrapped.player();
return null;
}
}
@@ -0,0 +1,61 @@
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;
private final CommandApi commands;
private final ListenerApi listeners;
private final ModuleConfigApi moduleConfigs;
private final LoggingApi logging;
private final MessageApi messages;
private final PlayersApi players;
private final PunishmentsApi punishments;
private final SchedulerApi scheduler;
private final StorageApi storage;
public DefaultPlexApi(Plex plugin, int apiCompatibilityVersion)
{
this.compatibility = new DefaultApiCompatibility(apiCompatibilityVersion);
this.configuration = new DefaultConfigurationApi(plugin);
this.modules = new DefaultModulesApi(plugin);
this.commands = new DefaultCommandApi(plugin);
this.listeners = new DefaultListenerApi(plugin);
this.moduleConfigs = new DefaultModuleConfigApi();
this.logging = new DefaultLoggingApi();
this.messages = new DefaultMessageApi();
this.players = new DefaultPlayersApi(plugin);
this.punishments = new DefaultPunishmentsApi(plugin);
this.scheduler = new DefaultSchedulerApi(plugin);
this.storage = new DefaultStorageApi(plugin);
}
@Override public ApiCompatibility compatibility() { return compatibility; }
@Override public ConfigurationApi configuration() { return configuration; }
@Override public ModulesApi modules() { return modules; }
@Override public CommandApi commands() { return commands; }
@Override public ListenerApi listeners() { return listeners; }
@Override public ModuleConfigApi moduleConfigs() { return moduleConfigs; }
@Override public LoggingApi logging() { return logging; }
@Override public MessageApi messages() { return messages; }
@Override public PlayersApi players() { return players; }
@Override public PunishmentsApi punishments() { return punishments; }
@Override public SchedulerApi scheduler() { return scheduler; }
@Override public StorageApi storage() { return storage; }
}
@@ -0,0 +1,58 @@
package dev.plex.api.impl;
import dev.plex.api.config.PlexConfiguration;
import dev.plex.config.Config;
import java.util.List;
final class DefaultPlexConfiguration implements PlexConfiguration
{
private final Config config;
DefaultPlexConfiguration(Config config)
{
this.config = config;
}
@Override
public String getString(String path)
{
return config.getString(path);
}
@Override
public boolean getBoolean(String path)
{
return config.getBoolean(path);
}
@Override
public int getInt(String path)
{
return config.getInt(path);
}
@Override
public List<String> getStringList(String path)
{
return config.getStringList(path);
}
@Override
public void set(String path, Object value)
{
config.set(path, value);
}
@Override
public void setComments(String path, List<String> comments)
{
config.setComments(path, comments);
}
@Override
public void save()
{
config.save();
}
}
@@ -0,0 +1,20 @@
package dev.plex.api.impl;
import dev.plex.api.player.PlexPlayerView;
import dev.plex.api.punishment.PunishmentView;
import dev.plex.player.PlexPlayer;
import java.util.List;
import java.util.UUID;
import org.bukkit.entity.Player;
record DefaultPlexPlayerView(PlexPlayer player) implements PlexPlayerView
{
@Override public UUID uuid() { return player.getUuid(); }
@Override public String name() { return player.getName(); }
@Override public List<String> ips() { return List.copyOf(player.getIps()); }
@Override public List<? extends PunishmentView> punishments() { return player.getPunishments().stream().map(DefaultPunishmentView::new).toList(); }
@Override public boolean frozen() { return player.isFrozen(); }
@Override public boolean muted() { return player.isMuted(); }
@Override public boolean lockedUp() { return player.isLockedUp(); }
@Override public Player bukkitPlayer() { return player.getPlayer(); }
}
@@ -0,0 +1,22 @@
package dev.plex.api.impl;
import dev.plex.api.punishment.PunishmentType;
import dev.plex.api.punishment.PunishmentView;
import dev.plex.punishment.Punishment;
import java.time.ZonedDateTime;
import java.util.UUID;
record DefaultPunishmentView(Punishment punishment) implements PunishmentView
{
@Override public UUID punished() { return punishment.getPunished(); }
@Override public UUID punisher() { return punishment.getPunisher(); }
@Override public String punisherName() { return punishment.getPunisherName(); }
@Override public String ip() { return punishment.getIp(); }
@Override public String punishedUsername() { return punishment.getPunishedUsername(); }
@Override public PunishmentType type() { return PunishmentType.valueOf(punishment.getType().name()); }
@Override public String reason() { return punishment.getReason(); }
@Override public boolean customTime() { return punishment.isCustomTime(); }
@Override public boolean active() { return punishment.isActive(); }
@Override public ZonedDateTime issueDate() { return punishment.getIssueDate(); }
@Override public ZonedDateTime endDate() { return punishment.getEndDate(); }
}
@@ -0,0 +1,40 @@
package dev.plex.api.impl;
import dev.plex.Plex;
import dev.plex.api.player.PlexPlayerView;
import dev.plex.api.punishment.IndefiniteBanView;
import dev.plex.api.punishment.PunishmentRequest;
import dev.plex.api.punishment.PunishmentsApi;
import dev.plex.player.PlexPlayer;
import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
final class DefaultPunishmentsApi implements PunishmentsApi
{
private final Plex plugin;
DefaultPunishmentsApi(Plex plugin) { this.plugin = plugin; }
@Override public List<? extends IndefiniteBanView> indefiniteBans() { return plugin.getPunishmentManager().getIndefiniteBans().stream().map(DefaultIndefiniteBanView::new).toList(); }
@Override public Optional<? extends IndefiniteBanView> indefiniteBanByUuid(UUID uuid) { return Optional.ofNullable(plugin.getPunishmentManager().getIndefiniteBanByUUID(uuid)).map(DefaultIndefiniteBanView::new); }
@Override
public void punish(PlexPlayerView playerView, PunishmentRequest request)
{
PlexPlayer player = DefaultPlayersApi.unwrap(playerView);
if (player == null) player = plugin.getPlayerService().getPlayer(playerView.uuid());
Punishment punishment = new Punishment(request.punished(), request.punisher());
punishment.setPunisherName(request.punisherName());
punishment.setIp(request.ip());
punishment.setPunishedUsername(request.punishedUsername());
punishment.setType(PunishmentType.valueOf(request.type().name()));
punishment.setReason(request.reason());
punishment.setCustomTime(request.customTime());
punishment.setActive(request.active());
punishment.setEndDate(request.endDate());
plugin.getPunishmentManager().punish(player, punishment);
}
}
@@ -0,0 +1,15 @@
package dev.plex.api.impl;
import dev.plex.Plex;
import dev.plex.api.scheduler.SchedulerApi;
final class DefaultSchedulerApi implements SchedulerApi
{
private final Plex plugin;
DefaultSchedulerApi(Plex plugin) { this.plugin = plugin; }
@Override public Object runSync(Runnable task) { return plugin.getServer().getScheduler().runTask(plugin, task); }
@Override public Object runLater(Runnable task, long delayTicks) { return plugin.getServer().getScheduler().runTaskLater(plugin, task, delayTicks); }
@Override public Object runTimer(Runnable task, long delayTicks, long periodTicks) { return plugin.getServer().getScheduler().runTaskTimer(plugin, task, delayTicks, periodTicks); }
}
@@ -0,0 +1,22 @@
package dev.plex.api.impl;
import dev.plex.Plex;
import dev.plex.api.storage.StorageApi;
import java.sql.Connection;
import java.sql.SQLException;
final class DefaultStorageApi implements StorageApi
{
private final Plex plugin;
DefaultStorageApi(Plex plugin) { this.plugin = plugin; }
@Override
public <T> T withConnection(SqlFunction<T> function) throws SQLException
{
try (Connection connection = plugin.getSqlConnection().getCon())
{
return function.apply(connection);
}
}
}
@@ -1,60 +1,32 @@
package dev.plex.config;
package dev.plex.api.impl;
import dev.plex.api.config.ModuleConfiguration;
import dev.plex.config.ConfigDefaultsMerger;
import dev.plex.module.PlexModule;
import dev.plex.util.PlexLog;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
/**
* Creates a custom Config object
*/
public class ModuleConfig extends YamlConfiguration
final class ServerModuleConfiguration extends ModuleConfiguration
{
/**
* The plugin instance
*/
private final PlexModule module;
/**
* The File instance
*/
private final File file;
/**
* Where the file is in the module JAR
*/
private final String from;
/**
* Where it should be copied to in the module folder
*/
private final String to;
/**
* Creates a config object
*
* @param module The module instance
* @param to The file name
*/
public ModuleConfig(PlexModule module, String from, String to)
ServerModuleConfiguration(PlexModule module, String from, String to)
{
this.module = module;
this.file = new File(module.getDataFolder(), to);
this.to = to;
this.from = from;
if (!file.exists())
{
saveDefault();
}
this.to = to;
if (!file.exists()) saveDefault();
}
@Override
public void load()
{
try
@@ -64,8 +36,7 @@ public class ModuleConfig extends YamlConfiguration
{
PlexLog.log("Merged default key(s) into " + to + ": " + String.join(", ", result.addedKeys()));
}
this.options().parseComments(true);
options().parseComments(true);
super.load(file);
}
catch (IOException | InvalidConfigurationException ex)
@@ -74,33 +45,18 @@ public class ModuleConfig extends YamlConfiguration
}
}
/**
* Saves the configuration file
*/
@Override
public void save()
{
try
{
super.save(file);
}
catch (Exception ex)
{
ex.printStackTrace();
}
try { super.save(file); } catch (IOException ex) { ex.printStackTrace(); }
}
/**
* Moves the configuration file from the plugin's resources folder to the data folder (plugins/Plex/)
*/
private void saveDefault()
{
try
{
File parent = file.getParentFile();
if (parent != null)
{
parent.mkdirs();
}
if (parent != null) parent.mkdirs();
try (InputStream stream = module.getClass().getResourceAsStream("/" + from))
{
if (stream == null)
@@ -108,12 +64,12 @@ public class ModuleConfig extends YamlConfiguration
PlexLog.warn("Unable to save default module config " + to + ": missing resource " + from);
return;
}
Files.copy(stream, this.file.toPath());
Files.copy(stream, file.toPath());
}
}
catch (IOException e)
catch (IOException ex)
{
e.printStackTrace();
ex.printStackTrace();
}
}
}
@@ -35,10 +35,12 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Superclass for all commands
* Superclass for all server commands.
*/
public abstract class PlexCommand extends Command implements PluginIdentifiableCommand
public abstract class ServerCommand extends Command implements PluginIdentifiableCommand
{
private static Runtime runtime;
/**
* Returns the instance of the plugin
*/
@@ -59,13 +61,18 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
*/
private final RequiredCommandSource commandSource;
public static void setRuntime(Runtime runtime)
{
ServerCommand.runtime = runtime;
}
/**
* Creates an instance of the command
*/
public PlexCommand(boolean register)
public ServerCommand(boolean register)
{
super("");
this.plugin = Plex.get();
this.plugin = requireRuntime().plugin();
this.params = getClass().getAnnotation(CommandParameters.class);
this.perms = getClass().getAnnotation(CommandPermissions.class);
@@ -82,16 +89,11 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
if (register)
{
getMap().getKnownCommands().remove(this.getName().toLowerCase());
this.getAliases().forEach(s ->
{
getMap().getKnownCommands().remove(s.toLowerCase());
});
getMap().register("plex", this);
requireRuntime().register(this);
}
}
public PlexCommand()
public ServerCommand()
{
this(true);
}
@@ -480,4 +482,40 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
{
return plugin.getServer().getCommandMap();
}
private static Runtime requireRuntime()
{
if (runtime == null)
{
Plex plex = Plex.get();
if (plex == null)
{
throw new IllegalStateException("ServerCommand runtime has not been installed by Plex");
}
return new Runtime()
{
@Override
public Plex plugin()
{
return plex;
}
@Override
public void register(Command command)
{
plex.getServer().getCommandMap().getKnownCommands().remove(command.getName().toLowerCase());
command.getAliases().forEach(alias -> plex.getServer().getCommandMap().getKnownCommands().remove(alias.toLowerCase()));
plex.getServer().getCommandMap().register("plex", command);
}
};
}
return runtime;
}
public interface Runtime
{
Plex plugin();
void register(Command command);
}
}
@@ -1,39 +0,0 @@
package dev.plex.command.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Storage for a command's parameters
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface CommandParameters
{
/**
* The name
*
* @return Name of the command
*/
String name();
/**
* The description
*
* @return Description of the command
*/
String description() default "";
/**
* The usage (optional)
*
* @return The usage of the command
*/
String usage() default "/<command>";
/**
* The aliases (optional)
*
* @return The aliases of the command
*/
String aliases() default "";
}
@@ -1,28 +0,0 @@
package dev.plex.command.annotation;
import dev.plex.command.source.RequiredCommandSource;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Storage for the command's permissions
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface CommandPermissions
{
/**
* Required command source
*
* @return The required command source of the command
* @see RequiredCommandSource
*/
RequiredCommandSource source() default RequiredCommandSource.ANY;
/**
* The permission
*
* @return Permission of the command
*/
String permission() default ""; // No idea what to put here
}
@@ -1,9 +0,0 @@
package dev.plex.command.exception;
public class CommandFailException extends RuntimeException // this is literally just a runtime exception lol
{
public CommandFailException(String s)
{
super(s);
}
}
@@ -1,11 +0,0 @@
package dev.plex.command.exception;
import static dev.plex.util.PlexUtils.messageString;
public class ConsoleMustDefinePlayerException extends RuntimeException
{
public ConsoleMustDefinePlayerException()
{
super(messageString("consoleMustDefinePlayer"));
}
}
@@ -1,11 +0,0 @@
package dev.plex.command.exception;
import static dev.plex.util.PlexUtils.messageString;
public class ConsoleOnlyException extends RuntimeException
{
public ConsoleOnlyException()
{
super(messageString("consoleOnly"));
}
}
@@ -1,11 +0,0 @@
package dev.plex.command.exception;
import static dev.plex.util.PlexUtils.messageString;
public class PlayerNotBannedException extends RuntimeException
{
public PlayerNotBannedException()
{
super(messageString("playerNotBanned"));
}
}
@@ -1,11 +0,0 @@
package dev.plex.command.exception;
import static dev.plex.util.PlexUtils.messageString;
public class PlayerNotFoundException extends RuntimeException
{
public PlayerNotFoundException()
{
super(messageString("playerNotFound"));
}
}
@@ -1,6 +1,6 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
@@ -25,7 +25,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.adminchat", source = RequiredCommandSource.ANY)
@CommandParameters(name = "adminchat", description = "Talk privately with other admins", usage = "/<command> <message>", aliases = "o,ac,sc,staffchat")
public class AdminChatCMD extends PlexCommand
public class AdminChatCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,6 +1,6 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
@@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.adminworld", source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "adminworld", aliases = "aw", description = "Teleport to the adminworld")
public class AdminworldCMD extends PlexCommand
public class AdminworldCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,7 +1,7 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException;
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.gamemode.adventure", source = RequiredCommandSource.ANY)
@CommandParameters(name = "adventure", aliases = "gma,egma,eadventure,adventuremode,eadventuremode", description = "Set your own or another player's gamemode to adventure mode")
public class AdventureCMD extends PlexCommand
public class AdventureCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,7 +1,7 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.PlayerNotFoundException;
@@ -35,7 +35,7 @@ import org.prism_mc.prism.paper.api.activities.PaperActivityQuery;
@CommandParameters(name = "ban", usage = "/<command> <player> [reason] [-rb]", aliases = "offlineban,gtfo", description = "Bans a player, offline or online")
@CommandPermissions(permission = "plex.ban", source = RequiredCommandSource.ANY)
public class BanCMD extends PlexCommand
public class BanCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,7 +1,7 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.punishment.Punishment;
@@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "banlist", description = "Manages the banlist", usage = "/<command> [purge]")
@CommandPermissions(permission = "plex.banlist")
public class BanListCommand extends PlexCommand
public class BanListCommand extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
@@ -2,7 +2,7 @@ package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.PlayerNotFoundException;
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.broadcastloginmessage", source = RequiredCommandSource.ANY)
@CommandParameters(name = "bcastloginmessage", usage = "/<command> <player>", description = "Broadcast your login message (for vanish support)", aliases = "bcastlm")
public class BcastLoginMessageCMD extends PlexCommand
public class BcastLoginMessageCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,6 +1,6 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.listener.impl.BlockListener;
@@ -20,7 +20,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.blockedit")
@CommandParameters(name = "blockedit", usage = "/<command> [list | purge | all | <player>]", aliases = "bedit", description = "Prevent players from modifying blocks")
public class BlockEditCMD extends PlexCommand
public class BlockEditCMD extends ServerCommand
{
private final BlockListener bl = new BlockListener();
@@ -1,7 +1,7 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
@@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.commandspy", source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "commandspy", aliases = "cmdspy", description = "Spy on other player's commands")
public class CommandSpyCMD extends PlexCommand
public class CommandSpyCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
@@ -1,6 +1,6 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
@@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.consolesay", source = RequiredCommandSource.CONSOLE)
@CommandParameters(name = "consolesay", usage = "/<command> <message>", description = "Displays a message to everyone", aliases = "csay")
public class ConsoleSayCMD extends PlexCommand
public class ConsoleSayCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,7 +1,7 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException;
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.gamemode.creative", source = RequiredCommandSource.ANY)
@CommandParameters(name = "creative", aliases = "gmc,egmc,ecreative,eecreative,creativemode,ecreativemode", description = "Set your own or another player's gamemode to creative mode")
public class CreativeCMD extends PlexCommand
public class CreativeCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,7 +1,7 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.menu.impl.MaterialMenu;
@@ -24,7 +24,7 @@ import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "pdebug", description = "Plex's debug command", usage = "/<command> <aliases <command> | redis-reset <player> | gamerules>")
@CommandPermissions(permission = "plex.debug")
public class DebugCMD extends PlexCommand
public class DebugCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,6 +1,6 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
@@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.entitywipe", source = RequiredCommandSource.ANY)
@CommandParameters(name = "entitywipe", description = "Remove various server entities that may cause lag, such as dropped items, minecarts, and boats.", usage = "/<command> [entity] [radius]", aliases = "ew,rd")
public class EntityWipeCMD extends PlexCommand
public class EntityWipeCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
@@ -1,6 +1,6 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
@@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.flatlands", source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "flatlands", description = "Teleport to the flatlands")
public class FlatlandsCMD extends PlexCommand
public class FlatlandsCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,7 +1,7 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.player.PlexPlayer;
@@ -22,7 +22,7 @@ import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "freeze", description = "Freeze a player on the server", usage = "/<command> <player>", aliases = "fr")
@CommandPermissions(permission = "plex.freeze")
public class FreezeCMD extends PlexCommand
public class FreezeCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,6 +1,6 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException;
@@ -22,7 +22,7 @@ import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "gamemode", usage = "/<command> <creative | survival | adventure | default | spectator> [player]", description = "Change your gamemode", aliases = "gm,egamemode,gmt,egmt")
@CommandPermissions(permission = "plex.gamemode", source = RequiredCommandSource.ANY)
public class GamemodeCMD extends PlexCommand
public class GamemodeCMD extends ServerCommand
{
private GameMode gamemode;
@@ -2,7 +2,7 @@ package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.PlayerNotFoundException;
@@ -28,7 +28,7 @@ import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "kick", description = "Kicks a player", usage = "/<command> <player>")
@CommandPermissions(permission = "plex.kick", source = RequiredCommandSource.ANY)
public class KickCMD extends PlexCommand
public class KickCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,7 +1,7 @@
package dev.plex.command.impl;
import com.google.common.collect.Lists;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.hook.VaultHook;
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "list", description = "Show a list of all online players", usage = "/<command> [-d | -v]", aliases = "lsit,who,playerlist,online")
@CommandPermissions(permission = "plex.list")
public class ListCMD extends PlexCommand
public class ListCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,6 +1,6 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
@@ -16,7 +16,7 @@ import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "localspawn", description = "Teleport to the spawnpoint of the world you are in")
@CommandPermissions(permission = "plex.localspawn", source = RequiredCommandSource.IN_GAME)
public class LocalSpawnCMD extends PlexCommand
public class LocalSpawnCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,7 +1,7 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.player.PlexPlayer;
@@ -17,7 +17,7 @@ import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "lockup", description = "Lockup a player on the server", usage = "/<command> <player>")
@CommandPermissions(permission = "plex.lockup")
public class LockupCMD extends PlexCommand
public class LockupCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,6 +1,6 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
@@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.masterbuilderworld", source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "masterbuilderworld", aliases = "mbw", description = "Teleport to the Master Builder world")
public class MasterbuilderworldCMD extends PlexCommand
public class MasterbuilderworldCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,6 +1,6 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "moblimit", usage = "/<command> [on | off | setmax <limit>]", aliases = "entitylimit", description = "Manages the mob limit per chunk.")
@CommandPermissions(permission = "plex.moblimit", source = RequiredCommandSource.ANY)
public class MobLimitCMD extends PlexCommand
public class MobLimitCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,6 +1,6 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
@@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.mobpurge", source = RequiredCommandSource.ANY)
@CommandParameters(name = "mobpurge", description = "Purge all mobs.", usage = "/<command> [mob]", aliases = "mp")
public class MobPurgeCMD extends PlexCommand
public class MobPurgeCMD extends ServerCommand
{
private final List<EntityType> MOB_TYPES = new ArrayList<>();
@@ -1,7 +1,7 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.player.PlexPlayer;
@@ -22,7 +22,7 @@ import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "mute", description = "Mute a player on the server", usage = "/<command> <player>", aliases = "stfu")
@CommandPermissions(permission = "plex.mute")
public class MuteCMD extends PlexCommand
public class MuteCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,7 +1,7 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.player.PlexPlayer;
@@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "notes", description = "Manage notes for a player", usage = "/<command> <player> <list | add <note> | remove <id> | clear>")
@CommandPermissions(permission = "plex.notes")
public class NotesCMD extends PlexCommand
public class NotesCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,6 +1,6 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException;
@@ -28,7 +28,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(source = RequiredCommandSource.ANY)
@CommandParameters(name = "plex", usage = "/<command> [reload | redis | modules [reload]]", description = "Show information about Plex or reload it")
public class PlexCMD extends PlexCommand
public class PlexCMD extends ServerCommand
{
// Don't modify this command
@Override
@@ -2,7 +2,7 @@ package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.PlayerNotFoundException;
@@ -24,7 +24,7 @@ import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "punishments", usage = "/<command> [player]", description = "Opens the Punishments GUI", aliases = "punishlist,punishes")
@CommandPermissions(permission = "plex.punishments", source = RequiredCommandSource.IN_GAME)
public class PunishmentsCMD extends PlexCommand
public class PunishmentsCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,6 +1,6 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
@@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.rawsay", source = RequiredCommandSource.ANY)
@CommandParameters(name = "rawsay", usage = "/<command> <message>", description = "Displays a raw message to everyone")
public class RawSayCMD extends PlexCommand
public class RawSayCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -2,7 +2,7 @@ package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
@@ -19,7 +19,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.removeloginmessage", source = RequiredCommandSource.ANY)
@CommandParameters(name = "removeloginmessage", usage = "/<command> [-o <player>]", description = "Remove your own (or someone else's) login message", aliases = "rlm,removeloginmsg")
public class RemoveLoginMessageCMD extends PlexCommand
public class RemoveLoginMessageCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,6 +1,6 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
@@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.say", source = RequiredCommandSource.ANY)
@CommandParameters(name = "say", usage = "/<command> <message>", description = "Displays a message to everyone")
public class SayCMD extends PlexCommand
public class SayCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -2,7 +2,7 @@ package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException;
@@ -23,7 +23,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.setloginmessage", source = RequiredCommandSource.ANY)
@CommandParameters(name = "setloginmessage", usage = "/<command> [-o <player>] <message>", description = "Sets your (or someone else's) login message", aliases = "slm,setloginmsg")
public class SetLoginMessageCMD extends PlexCommand
public class SetLoginMessageCMD extends ServerCommand
{
private final boolean nameRequired = plugin.getConfig().getBoolean("loginmessages.name");
@@ -1,6 +1,6 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
@@ -29,7 +29,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.smite", source = RequiredCommandSource.ANY)
@CommandParameters(name = "smite", usage = "/<command> <player> [reason] [-ci | -q]", description = "Someone being a little bitch? Smite them down...")
public class SmiteCMD extends PlexCommand
public class SmiteCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,7 +1,7 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException;
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.gamemode.spectator", source = RequiredCommandSource.ANY)
@CommandParameters(name = "spectator", aliases = "gmsp,egmsp,spec", description = "Set your own or another player's gamemode to spectator mode")
public class SpectatorCMD extends PlexCommand
public class SpectatorCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,7 +1,7 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException;
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.gamemode.survival", source = RequiredCommandSource.ANY)
@CommandParameters(name = "survival", aliases = "gms,egms,esurvival,survivalmode,esurvivalmode", description = "Set your own or another player's gamemode to survival mode")
public class SurvivalCMD extends PlexCommand
public class SurvivalCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,7 +1,7 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
@@ -24,7 +24,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.tag", source = RequiredCommandSource.ANY)
@CommandParameters(name = "tag", aliases = "prefix", description = "Set or clear your prefix", usage = "/<command> <set <prefix> | clear <player>>")
public class TagCMD extends PlexCommand
public class TagCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -2,7 +2,7 @@ package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.PlayerNotFoundException;
@@ -29,7 +29,7 @@ import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "tempban", usage = "/<command> <player> <time> [reason] [-rb]", description = "Temporarily ban a player")
@CommandPermissions(permission = "plex.tempban", source = RequiredCommandSource.ANY)
public class TempbanCMD extends PlexCommand
public class TempbanCMD extends ServerCommand
{
@Override
public Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,7 +1,7 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.player.PlexPlayer;
@@ -23,7 +23,7 @@ import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "tempmute", description = "Temporarily mute a player on the server",
usage = "/<command> <player> <time> [reason]", aliases = "tmute")
@CommandPermissions(permission = "plex.tempmute")
public class TempmuteCMD extends PlexCommand
public class TempmuteCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,7 +1,7 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
@@ -19,7 +19,7 @@ import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "toggle", description = "Allows toggling various server aspects through a GUI", aliases = "toggles")
@CommandPermissions(permission = "plex.toggle", source = RequiredCommandSource.ANY)
public class ToggleCMD extends PlexCommand
public class ToggleCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -2,7 +2,7 @@ package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.PlayerNotBannedException;
@@ -22,7 +22,7 @@ import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "unban", usage = "/<command> <player>", description = "Unbans a player, offline or online")
@CommandPermissions(permission = "plex.ban", source = RequiredCommandSource.ANY)
public class UnbanCMD extends PlexCommand
public class UnbanCMD extends ServerCommand
{
@Override
public Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -2,7 +2,7 @@ package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException;
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.unfreeze")
@CommandParameters(name = "unfreeze", description = "Unfreeze a player", usage = "/<command> <player>")
public class UnfreezeCMD extends PlexCommand
public class UnfreezeCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -2,7 +2,7 @@ package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException;
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.unmute")
@CommandParameters(name = "unmute", description = "Unmute a player", usage = "/<command> <player>")
public class UnmuteCMD extends PlexCommand
public class UnmuteCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
@@ -1,7 +1,7 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.whohas")
@CommandParameters(name = "whohas", description = "Returns a list of players with a specific item in their inventory.", usage = "/<command> <material>", aliases = "wh")
public class WhoHasCMD extends PlexCommand
public class WhoHasCMD extends ServerCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
@@ -1,7 +1,7 @@
package dev.plex.command.impl;
import com.google.common.collect.Lists;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
@@ -20,7 +20,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(permission = "plex.world", source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "world", description = "Teleport to a world.", usage = "/<command> <world>")
public class WorldCMD extends PlexCommand
public class WorldCMD extends ServerCommand
{
private static final Pattern UUID_PATTERN = Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}");
@@ -1,8 +0,0 @@
package dev.plex.command.source;
public enum RequiredCommandSource
{
IN_GAME,
CONSOLE,
ANY
}
@@ -19,7 +19,7 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
final class ConfigDefaultsMerger
public final class ConfigDefaultsMerger
{
private static final Pattern KEY = Pattern.compile("^(\\s*)([A-Za-z0-9_-]+):(?:\\s+.*)?$");
@@ -27,7 +27,7 @@ final class ConfigDefaultsMerger
{
}
static Result merge(File file, InputStream defaultsStream, String displayName) throws IOException, InvalidConfigurationException
public static Result merge(File file, InputStream defaultsStream, String displayName) throws IOException, InvalidConfigurationException
{
if (defaultsStream == null)
{
@@ -214,7 +214,7 @@ final class ConfigDefaultsMerger
{
}
record Result(YamlConfiguration config, List<String> addedKeys, boolean changed)
public record Result(YamlConfiguration config, List<String> addedKeys, boolean changed)
{
}
}
@@ -2,7 +2,7 @@ package dev.plex.handlers;
import com.google.common.collect.Lists;
import dev.plex.Plex;
import dev.plex.command.PlexCommand;
import dev.plex.command.ServerCommand;
import dev.plex.command.impl.DebugCMD;
import dev.plex.util.PlexLog;
import dev.plex.util.ReflectionsUtil;
@@ -18,8 +18,8 @@ public class CommandHandler
public CommandHandler(Plex plugin)
{
this.plugin = plugin;
Set<Class<? extends PlexCommand>> commandSet = ReflectionsUtil.getClassesBySubType("dev.plex.command.impl", PlexCommand.class);
List<PlexCommand> commands = Lists.newArrayList();
Set<Class<? extends ServerCommand>> commandSet = ReflectionsUtil.getClassesBySubType("dev.plex.command.impl", ServerCommand.class);
List<ServerCommand> commands = Lists.newArrayList();
commandSet.forEach(clazz ->
{
@@ -2,7 +2,7 @@ package dev.plex.handlers;
import com.google.common.collect.Lists;
import dev.plex.Plex;
import dev.plex.listener.PlexListener;
import dev.plex.listener.ServerListenerBase;
import dev.plex.listener.annotation.Toggleable;
import dev.plex.util.PlexLog;
import dev.plex.util.ReflectionsUtil;
@@ -18,8 +18,8 @@ public class ListenerHandler
public ListenerHandler(Plex plugin)
{
this.plugin = plugin;
Set<Class<? extends PlexListener>> listenerSet = ReflectionsUtil.getClassesBySubType("dev.plex.listener.impl", PlexListener.class);
List<PlexListener> listeners = Lists.newArrayList();
Set<Class<? extends ServerListenerBase>> listenerSet = ReflectionsUtil.getClassesBySubType("dev.plex.listener.impl", ServerListenerBase.class);
List<ServerListenerBase> listeners = Lists.newArrayList();
listenerSet.forEach(clazz ->
{
@@ -3,16 +3,16 @@ package dev.plex.listener;
import dev.plex.Plex;
import org.bukkit.event.Listener;
public abstract class PlexListener implements Listener
public abstract class ServerListenerBase implements Listener
{
protected final Plex plugin;
public PlexListener()
public ServerListenerBase()
{
this(Plex.get());
}
protected PlexListener(Plex plugin)
protected ServerListenerBase(Plex plugin)
{
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
@@ -1,6 +1,6 @@
package dev.plex.listener.impl;
import dev.plex.listener.PlexListener;
import dev.plex.listener.ServerListenerBase;
import dev.plex.services.impl.TimingService;
import dev.plex.util.PlexUtils;
@@ -11,7 +11,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
public class AntiNukerListener extends PlexListener
public class AntiNukerListener extends ServerListenerBase
{
@EventHandler(priority = EventPriority.HIGH)
public void onBlockPlace(BlockPlaceEvent event)
@@ -1,6 +1,6 @@
package dev.plex.listener.impl;
import dev.plex.listener.PlexListener;
import dev.plex.listener.ServerListenerBase;
import dev.plex.services.impl.TimingService;
import dev.plex.util.PlexUtils;
import io.papermc.paper.event.player.AsyncChatEvent;
@@ -11,7 +11,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class AntiSpamListener extends PlexListener
public class AntiSpamListener extends ServerListenerBase
{
@EventHandler
public void onChat(AsyncChatEvent event)
@@ -1,6 +1,6 @@
package dev.plex.listener.impl;
import dev.plex.listener.PlexListener;
import dev.plex.listener.ServerListenerBase;
import dev.plex.player.PlexPlayer;
import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentManager;
@@ -9,7 +9,7 @@ import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
public class BanListener extends PlexListener
public class BanListener extends ServerListenerBase
{
@EventHandler
public void onPreLogin(AsyncPlayerPreLoginEvent event)
@@ -1,6 +1,6 @@
package dev.plex.listener.impl;
import dev.plex.listener.PlexListener;
import dev.plex.listener.ServerListenerBase;
import dev.plex.util.PlexUtils;
import java.util.ArrayList;
@@ -17,7 +17,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
public class BlockListener extends PlexListener
public class BlockListener extends ServerListenerBase
{
private static final List<Material> blockedBlocks = new ArrayList<>();
private static final List<Material> SIGNS = Arrays.stream(Material.values()).filter((mat) -> mat.name().endsWith("_SIGN")).toList();
@@ -1,6 +1,6 @@
package dev.plex.listener.impl;
import dev.plex.listener.PlexListener;
import dev.plex.listener.ServerListenerBase;
import dev.plex.util.PlexUtils;
import dev.plex.util.minimessage.SafeMiniMessage;
import net.kyori.adventure.text.Component;
@@ -12,7 +12,7 @@ import org.bukkit.inventory.meta.BookMeta;
import java.util.ArrayList;
import java.util.List;
public class BookListener extends PlexListener
public class BookListener extends ServerListenerBase
{
@EventHandler(priority = EventPriority.LOW)
public void onBookEdit(PlayerEditBookEvent event)
@@ -1,7 +1,7 @@
package dev.plex.listener.impl;
import dev.plex.hook.VaultHook;
import dev.plex.listener.PlexListener;
import dev.plex.listener.ServerListenerBase;
import dev.plex.listener.annotation.Toggleable;
import dev.plex.meta.PlayerMeta;
import dev.plex.player.PlexPlayer;
@@ -25,7 +25,7 @@ import org.bukkit.event.EventPriority;
import org.jetbrains.annotations.NotNull;
@Toggleable("chat.enabled")
public class ChatListener extends PlexListener
public class ChatListener extends ServerListenerBase
{
public static final TextReplacementConfig URL_REPLACEMENT_CONFIG = TextReplacementConfig
.builder()
@@ -1,6 +1,6 @@
package dev.plex.listener.impl;
import dev.plex.listener.PlexListener;
import dev.plex.listener.ServerListenerBase;
import dev.plex.player.PlexPlayer;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@@ -10,7 +10,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class CommandListener extends PlexListener
public class CommandListener extends ServerListenerBase
{
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
@@ -1,10 +1,10 @@
package dev.plex.listener.impl;
import dev.plex.listener.PlexListener;
import dev.plex.listener.ServerListenerBase;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerDropItemEvent;
public class DropListener extends PlexListener
public class DropListener extends ServerListenerBase
{
@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event)
@@ -1,13 +1,13 @@
package dev.plex.listener.impl;
import dev.plex.listener.PlexListener;
import dev.plex.listener.ServerListenerBase;
import dev.plex.player.PlexPlayer;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
public class FreezeListener extends PlexListener
public class FreezeListener extends ServerListenerBase
{
@EventHandler
public void onPlayerMove(PlayerMoveEvent e)
@@ -1,13 +1,13 @@
package dev.plex.listener.impl;
import dev.plex.event.GameModeUpdateEvent;
import dev.plex.listener.PlexListener;
import dev.plex.listener.ServerListenerBase;
import dev.plex.util.PlexUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
public class GameModeListener extends PlexListener
public class GameModeListener extends ServerListenerBase
{
@EventHandler
public void onGameModeUpdate(GameModeUpdateEvent event)
@@ -1,6 +1,6 @@
package dev.plex.listener.impl;
import dev.plex.listener.PlexListener;
import dev.plex.listener.ServerListenerBase;
import dev.plex.menu.AbstractMenu;
import dev.plex.menu.pagination.PageableMenu;
import org.bukkit.entity.Player;
@@ -13,7 +13,7 @@ import org.bukkit.inventory.meta.ItemMeta;
* @author Taah
* @since 7:01 AM [02-09-2023]
*/
public class MenuListener extends PlexListener
public class MenuListener extends ServerListenerBase
{
@EventHandler(priority = EventPriority.LOWEST)
public void onClick(InventoryClickEvent event)
@@ -1,6 +1,6 @@
package dev.plex.listener.impl;
import dev.plex.listener.PlexListener;
import dev.plex.listener.ServerListenerBase;
import dev.plex.util.BlockUtils;
import dev.plex.util.PlexUtils;
import org.bukkit.Chunk;
@@ -28,7 +28,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.List;
public class MobListener extends PlexListener
public class MobListener extends ServerListenerBase
{
private static final List<Material> SPAWN_EGGS = Arrays.stream(Material.values()).filter((mat) -> mat.name().endsWith("_SPAWN_EGG")).toList();
@@ -1,6 +1,6 @@
package dev.plex.listener.impl;
import dev.plex.listener.PlexListener;
import dev.plex.listener.ServerListenerBase;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import io.papermc.paper.event.player.AsyncChatEvent;
@@ -13,7 +13,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class MuteListener extends PlexListener
public class MuteListener extends ServerListenerBase
{
List<String> commands = plugin.config.getStringList("block_on_mute");
@@ -1,7 +1,7 @@
package dev.plex.listener.impl;
import dev.plex.listener.PlexListener;
import dev.plex.listener.ServerListenerBase;
import dev.plex.meta.PlayerMeta;
import dev.plex.player.PlexPlayer;
import dev.plex.util.PlexLog;
@@ -18,7 +18,7 @@ import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class PlayerListener extends PlexListener
public class PlayerListener extends ServerListenerBase
{
// setting up a player's data
@EventHandler(priority = EventPriority.HIGHEST)
@@ -2,7 +2,7 @@ package dev.plex.listener.impl;
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
import com.destroystokyo.paper.event.server.PaperServerListPingEvent.ListedPlayerInfo;
import dev.plex.listener.PlexListener;
import dev.plex.listener.ServerListenerBase;
import dev.plex.util.PlexUtils;
import dev.plex.util.RandomUtil;
@@ -14,7 +14,7 @@ import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
public class ServerListener extends PlexListener
public class ServerListener extends ServerListenerBase
{
@EventHandler
public void onServerPing(PaperServerListPingEvent event)
@@ -2,7 +2,7 @@ package dev.plex.listener.impl;
import dev.plex.hook.VaultHook;
import dev.plex.listener.PlexListener;
import dev.plex.listener.ServerListenerBase;
import dev.plex.meta.PlayerMeta;
import dev.plex.player.PlexPlayer;
import dev.plex.util.PlexUtils;
@@ -12,7 +12,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
public class TabListener extends PlexListener
public class TabListener extends ServerListenerBase
{
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerJoin(PlayerJoinEvent event)
@@ -1,6 +1,6 @@
package dev.plex.listener.impl;
import dev.plex.listener.PlexListener;
import dev.plex.listener.ServerListenerBase;
import dev.plex.util.PlexUtils;
import io.papermc.paper.event.player.AsyncChatEvent;
import io.papermc.paper.event.player.PrePlayerAttackEntityEvent;
@@ -23,7 +23,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.projectiles.ProjectileSource;
public class TogglesListener extends PlexListener
public class TogglesListener extends ServerListenerBase
{
List<String> commands = plugin.config.getStringList("block_on_mute");
@@ -2,14 +2,14 @@ package dev.plex.listener.impl;
import de.myzelyam.api.vanish.PlayerShowEvent;
import dev.plex.listener.PlexListener;
import dev.plex.listener.ServerListenerBase;
import dev.plex.meta.PlayerMeta;
import dev.plex.player.PlexPlayer;
import dev.plex.util.PlexUtils;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
public class VanishListener extends PlexListener
public class VanishListener extends ServerListenerBase
{
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerUnvanish(PlayerShowEvent event)
@@ -1,6 +1,6 @@
package dev.plex.listener.impl;
import dev.plex.listener.PlexListener;
import dev.plex.listener.ServerListenerBase;
import java.util.Arrays;
import java.util.List;
@@ -25,7 +25,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemDamageEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
public class WorldListener extends PlexListener
public class WorldListener extends ServerListenerBase
{
private final List<String> EDIT_COMMANDS = Arrays.asList("bigtree", "ebigtree", "largetree", "elargetree", "break", "ebreak", "antioch", "nuke", "editsign", "tree", "etree");
@@ -7,6 +7,7 @@ import dev.plex.util.PlexLog;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
@@ -34,8 +35,15 @@ public class ModuleManager
public void loadAllModules()
{
this.modules.clear();
PlexLog.debug(String.valueOf(plugin.getModulesFolder().listFiles().length));
Arrays.stream(plugin.getModulesFolder().listFiles()).forEach(file ->
File[] moduleFiles = plugin.getModulesFolder().listFiles();
if (moduleFiles == null)
{
PlexLog.warn("Unable to read modules folder " + plugin.getModulesFolder().getAbsolutePath());
return;
}
PlexLog.debug(String.valueOf(moduleFiles.length));
Arrays.stream(moduleFiles).forEach(file ->
{
if (file.getName().endsWith(".jar"))
{
@@ -46,7 +54,13 @@ public class ModuleManager
Plex.class.getClassLoader()
);
InputStreamReader internalModuleFile = new InputStreamReader(loader.getResourceAsStream("module.yml"), StandardCharsets.UTF_8);
InputStream moduleDescriptor = loader.getResourceAsStream("module.yml");
if (moduleDescriptor == null)
{
throw new ModuleLoadException("Plex module " + file.getName() + " does not contain module.yml");
}
InputStreamReader internalModuleFile = new InputStreamReader(moduleDescriptor, StandardCharsets.UTF_8);
YamlConfiguration internalModuleConfig = YamlConfiguration.loadConfiguration(internalModuleFile);
String name = internalModuleConfig.getString("name");
@@ -63,14 +77,25 @@ public class ModuleManager
String description = internalModuleConfig.getString("description", "A Plex module");
String version = internalModuleConfig.getString("version", "1.0");
if (!internalModuleConfig.isInt("apiCompatibility"))
{
throw new ModuleLoadException("Plex module " + name + " must declare an integer apiCompatibility in module.yml");
}
int apiCompatibility = internalModuleConfig.getInt("apiCompatibility");
if (apiCompatibility != plugin.getApi().compatibility().version())
{
throw new ModuleLoadException("Plex module " + name + " requires API compatibility " + apiCompatibility + ", but this Plex build provides API compatibility " + plugin.getApi().compatibility().version());
}
List<String> libraries = internalModuleConfig.getStringList("libraries");
PlexModuleFile plexModuleFile = new PlexModuleFile(name, main, description, version);
PlexModuleFile plexModuleFile = new PlexModuleFile(name, main, description, version, apiCompatibility);
plexModuleFile.setLibraries(libraries);
Class<? extends PlexModule> module = (Class<? extends PlexModule>) Class.forName(main, true, loader);
PlexModule plexModule = module.getConstructor().newInstance();
plexModule.setPlex(plugin);
plexModule.setApi(plugin.getApi());
plexModule.setPlexModuleFile(plexModuleFile);
plexModule.setDataFolder(new File(plugin.getModulesFolder() + File.separator + plexModuleFile.getName()));
@@ -87,6 +112,10 @@ public class ModuleManager
{
e.printStackTrace();
}
catch (ModuleLoadException e)
{
PlexLog.warn("Skipping module " + file.getName() + ": " + e.getMessage());
}
}
});
}
@@ -1,154 +0,0 @@
package dev.plex.module;
import com.google.common.collect.Lists;
import dev.plex.Plex;
import dev.plex.command.PlexCommand;
import dev.plex.listener.PlexListener;
import dev.plex.util.PlexLog;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.apache.logging.log4j.Logger;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@Getter
@Setter(AccessLevel.PACKAGE)
public abstract class PlexModule
{
@Getter(AccessLevel.PACKAGE)
private final List<PlexCommand> commands = Lists.newArrayList();
@Getter(AccessLevel.PACKAGE)
private final List<PlexListener> listeners = Lists.newArrayList();
private Plex plex;
private PlexModuleFile plexModuleFile;
private File dataFolder;
private Logger logger;
public void load()
{
}
public void enable()
{
}
public void disable()
{
}
/**
* Registers a PlexListener within a module
*
* @param listener The PlexListener to be registered
*/
public void registerListener(PlexListener listener)
{
listeners.add(listener);
}
/**
* Unregisters a PlexListener. Handled by Plex automatically
*
* @param listener The PlexListener to be registered
*/
public void unregisterListener(PlexListener listener)
{
listeners.remove(listener);
HandlerList.unregisterAll(listener);
}
/**
* Registers a PlexCommand within a module
*
* @param command The PlexCommand to be registered
*/
public void registerCommand(PlexCommand command)
{
commands.add(command);
}
/**
* Unregisters a PlexCommand. Handled by Plex automatically
*
* @param command The PlexCommand to be registered
*/
public void unregisterCommand(PlexCommand command)
{
commands.remove(command);
}
public PlexCommand getCommand(String name)
{
return commands.stream().filter(plexCommand -> plexCommand.getName().equalsIgnoreCase(name) || plexCommand.getAliases().stream().map(String::toLowerCase).toList().contains(name.toLowerCase(Locale.ROOT))).findFirst().orElse(null);
}
/**
* Adds a message to the messages.yml file
*
* @param message The key value for the message
* @param initValue The message itself
*/
public void addDefaultMessage(String message, Object initValue)
{
if (plex.messages.getString(message) == null)
{
plex.messages.set(message, initValue);
plex.messages.save();
PlexLog.debug("'{0}' message added from " + plexModuleFile.getName(), message);
}
}
/**
* Adds a message to the messages.yml with a comment
*
* @param message The key value for the message
* @param initValue The message itself
* @param comments The comments to be placed above the message
*/
public void addDefaultMessage(String message, Object initValue, String... comments)
{
if (plex.messages.getString(message) == null)
{
plex.messages.set(message, initValue);
plex.messages.save();
plex.messages.setComments(message, Arrays.asList(comments));
plex.messages.save();
PlexLog.debug("'{0}' message added from " + plexModuleFile.getName(), message);
}
}
@Nullable
public InputStream getResource(@NotNull String filename)
{
try
{
URL url = this.getClass().getClassLoader().getResource(filename);
if (url == null)
{
return null;
}
URLConnection connection = url.openConnection();
connection.setUseCaches(false);
return connection.getInputStream();
}
catch (IOException ex)
{
return null;
}
}
}
@@ -1,19 +0,0 @@
package dev.plex.module;
import com.google.common.collect.ImmutableList;
import java.util.List;
import lombok.Data;
@Data
public class PlexModuleFile
{
private final String name;
private final String main;
private final String description;
private final String version;
//TODO: does not work
private List<String> libraries = ImmutableList.of();
}