Add the ability to add messages into Plex

Code originally from TFMExtras by taah
This commit is contained in:
Telesphoreo 2022-06-05 22:27:24 -05:00
parent 5fe48cfd7f
commit c8a35c8e0e
2 changed files with 37 additions and 3 deletions

View File

@ -22,7 +22,6 @@ import org.bukkit.configuration.file.YamlConfiguration;
@Getter @Getter
public class ModuleManager public class ModuleManager
{ {
private final List<PlexModule> modules = Lists.newArrayList(); private final List<PlexModule> modules = Lists.newArrayList();
private final LibraryLoader libraryLoader; private final LibraryLoader libraryLoader;
@ -70,7 +69,7 @@ public class ModuleManager
Class<? extends PlexModule> module = (Class<? extends PlexModule>) Class.forName(main, true, loader); Class<? extends PlexModule> module = (Class<? extends PlexModule>) Class.forName(main, true, loader);
PlexModule plexModule = module.getConstructor().newInstance(); PlexModule plexModule = module.getConstructor().newInstance();
plexModule.setPlex(Plex.get()); plexModule.setPlugin(Plex.get());
plexModule.setPlexModuleFile(plexModuleFile); plexModule.setPlexModuleFile(plexModuleFile);
plexModule.setDataFolder(new File(Plex.get().getModulesFolder() + File.separator + plexModuleFile.getName())); plexModule.setDataFolder(new File(Plex.get().getModulesFolder() + File.separator + plexModuleFile.getName()));

View File

@ -4,11 +4,13 @@ import com.google.common.collect.Lists;
import dev.plex.Plex; import dev.plex.Plex;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.listener.PlexListener; import dev.plex.listener.PlexListener;
import dev.plex.util.PlexLog;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import lombok.AccessLevel; import lombok.AccessLevel;
@ -29,7 +31,7 @@ public abstract class PlexModule
@Getter(AccessLevel.MODULE) @Getter(AccessLevel.MODULE)
private final List<PlexListener> listeners = Lists.newArrayList(); private final List<PlexListener> listeners = Lists.newArrayList();
private Plex plex; private Plex plugin;
private PlexModuleFile plexModuleFile; private PlexModuleFile plexModuleFile;
private File dataFolder; private File dataFolder;
private Logger logger; private Logger logger;
@ -72,6 +74,39 @@ public abstract class PlexModule
return commands.stream().filter(plexCommand -> plexCommand.getName().equalsIgnoreCase(name) || plexCommand.getAliases().stream().map(String::toLowerCase).toList().contains(name.toLowerCase(Locale.ROOT))).findFirst().orElse(null); 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
*/
private void addDefaultMessage(String message, Object initValue)
{
if (plugin.messages.getString(message) == null)
{
plugin.messages.set(message, initValue);
plugin.messages.save();
PlexLog.debug("'{0}' message added from TFMExtras module", 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
*/
private void addDefaultMessage(String message, Object initValue, String... comments)
{
if (plugin.messages.getString(message) == null)
{
plugin.messages.set(message, initValue);
plugin.messages.save();
plugin.messages.setComments(message, Arrays.asList(comments));
plugin.messages.save();
PlexLog.debug("'{0}' message added from TFMExtras module", message);
}
}
@Nullable @Nullable
public InputStream getResource(@NotNull String filename) public InputStream getResource(@NotNull String filename)
{ {