mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 09:07:37 +00:00
Merge branch 'master' of https://github.com/PlexDevelopment/Plex
This commit is contained in:
commit
1d9662acde
@ -90,7 +90,7 @@ public class Plex extends JavaPlugin {
|
||||
public void onEnable() {
|
||||
config.load();
|
||||
messages.load();
|
||||
indefBans.load();
|
||||
indefBans.load(false);
|
||||
|
||||
moduleManager.enableModules();
|
||||
|
||||
|
@ -63,7 +63,6 @@ public class PlexCMD extends PlexCommand {
|
||||
plugin.getModuleManager().loadAllModules();
|
||||
plugin.getModuleManager().loadModules();
|
||||
plugin.getModuleManager().enableModules();
|
||||
plugin.getModuleManager().disableModules();
|
||||
}
|
||||
} else {
|
||||
return usage();
|
||||
|
@ -89,11 +89,18 @@ public class ModuleManager {
|
||||
public void disableModules() {
|
||||
this.modules.forEach(module -> {
|
||||
PlexLog.log("Disabling module " + module.getPlexModuleFile().getName() + " with version " + module.getPlexModuleFile().getVersion());
|
||||
module.getCommands().stream().toList().forEach(plexCommand -> {
|
||||
module.unregisterCommand(plexCommand);
|
||||
Plex.get().getServer().getCommandMap().getKnownCommands().remove(plexCommand.getName());
|
||||
plexCommand.getAliases().forEach(alias -> Plex.get().getServer().getCommandMap().getKnownCommands().remove(alias));
|
||||
});
|
||||
module.getListeners().forEach(module::unregisterListener);
|
||||
module.disable();
|
||||
});
|
||||
}
|
||||
|
||||
public void unloadModules() {
|
||||
this.disableModules();
|
||||
this.modules.forEach(module -> {
|
||||
try {
|
||||
((URLClassLoader)module.getClass().getClassLoader()).close();
|
||||
|
@ -1,18 +1,31 @@
|
||||
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 lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
@Setter(AccessLevel.MODULE)
|
||||
public abstract class PlexModule
|
||||
{
|
||||
@Getter(AccessLevel.MODULE)
|
||||
private final List<PlexCommand> commands = Lists.newArrayList();
|
||||
|
||||
@Getter(AccessLevel.MODULE)
|
||||
private final List<PlexListener> listeners = Lists.newArrayList();
|
||||
|
||||
private Plex plex;
|
||||
private PlexModuleFile plexModuleFile;
|
||||
private File dataFolder;
|
||||
@ -23,4 +36,30 @@ public abstract class PlexModule
|
||||
public void enable() {}
|
||||
|
||||
public void disable() {}
|
||||
|
||||
public void registerListener(PlexListener listener)
|
||||
{
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void unregisterListener(PlexListener listener)
|
||||
{
|
||||
listeners.remove(listener);
|
||||
HandlerList.unregisterAll(listener);
|
||||
}
|
||||
|
||||
public void registerCommand(PlexCommand command)
|
||||
{
|
||||
commands.add(command);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user