Plex/src/main/java/dev/plex/module/PlexModule.java

83 lines
2.2 KiB
Java
Raw Normal View History

2022-03-06 01:04:34 +00:00
package dev.plex.module;
2022-03-06 01:17:14 +00:00
import com.google.common.collect.Lists;
2022-03-06 01:04:34 +00:00
import dev.plex.Plex;
2022-03-06 01:17:14 +00:00
import dev.plex.command.PlexCommand;
import dev.plex.listener.PlexListener;
2022-03-06 01:04:34 +00:00
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.apache.logging.log4j.Logger;
2022-03-06 01:17:14 +00:00
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Locale;
2022-03-06 01:04:34 +00:00
@Getter
@Setter(AccessLevel.MODULE)
public abstract class PlexModule {
2022-03-06 01:17:14 +00:00
@Getter(AccessLevel.MODULE)
private final List<PlexCommand> commands = Lists.newArrayList();
@Getter(AccessLevel.MODULE)
private final List<PlexListener> listeners = Lists.newArrayList();
2022-03-06 01:04:34 +00:00
private Plex plex;
private PlexModuleFile plexModuleFile;
private File dataFolder;
private Logger logger;
public void load() {
2022-03-17 22:16:17 +00:00
}
2022-03-06 01:04:34 +00:00
public void enable() {
2022-03-17 22:16:17 +00:00
}
2022-03-06 01:04:34 +00:00
public void disable() {
2022-03-17 22:16:17 +00:00
}
2022-03-06 01:17:14 +00:00
public void registerListener(PlexListener listener) {
2022-03-06 01:17:14 +00:00
listeners.add(listener);
}
public void unregisterListener(PlexListener listener) {
2022-03-06 01:17:14 +00:00
listeners.remove(listener);
HandlerList.unregisterAll(listener);
}
public void registerCommand(PlexCommand command) {
2022-03-06 01:17:14 +00:00
commands.add(command);
}
public void unregisterCommand(PlexCommand command) {
2022-03-06 01:17:14 +00:00
commands.remove(command);
}
public PlexCommand getCommand(String name) {
2022-03-06 01:17:14 +00:00
return commands.stream().filter(plexCommand -> plexCommand.getName().equalsIgnoreCase(name) || plexCommand.getAliases().stream().map(String::toLowerCase).toList().contains(name.toLowerCase(Locale.ROOT))).findFirst().orElse(null);
}
@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;
}
}
2022-03-06 01:04:34 +00:00
}