diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..16090fa --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,25 @@ +# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.217.4/containers/java/.devcontainer/base.Dockerfile + +# [Choice] Java version (use -bullseye variants on local arm64/Apple Silicon): 11, 17, 11-bullseye, 17-bullseye, 11-buster, 17-buster +ARG VARIANT="17-bullseye" +FROM mcr.microsoft.com/vscode/devcontainers/java:0-${VARIANT} + +# [Option] Install Maven +ARG INSTALL_MAVEN="false" +ARG MAVEN_VERSION="" +# [Option] Install Gradle +ARG INSTALL_GRADLE="false" +ARG GRADLE_VERSION="" +RUN if [ "${INSTALL_MAVEN}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install maven \"${MAVEN_VERSION}\""; fi \ + && if [ "${INSTALL_GRADLE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install gradle \"${GRADLE_VERSION}\""; fi + +# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 +ARG NODE_VERSION="none" +RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment this line to install global node packages. +# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..d4cdea5 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,37 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.217.4/containers/java +{ + "name": "Java", + "build": { + "dockerfile": "Dockerfile", + "args": { + // Update the VARIANT arg to pick a Java version: 11, 17 + // Append -bullseye or -buster to pin to an OS version. + // Use the -bullseye variants on local arm64/Apple Silicon. + "VARIANT": "11-bullseye", + // Options + "INSTALL_MAVEN": "true", + "INSTALL_GRADLE": "false", + "NODE_VERSION": "none" + } + }, + + // Set *default* container specific settings.json values on container create. + "settings": { + "java.home": "/docker-java-home" + }, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "vscjava.vscode-java-pack" + ], + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "java -version", + + // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode" +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..857a608 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +target/ +.idea/ +ExamplePonderPlugin.iml \ No newline at end of file diff --git a/LICENSE b/LICENSE index 656bbc5..f11c656 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,21 @@ -MIT License - -Copyright (c) 2022 Preponderous Software - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +MIT License + +Copyright (c) 2022 Preponderous Software + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 321b03c..c43213a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# ExamplePonderPlugin -This is an example ponder plugin. +# ExamplePonderPlugin +This is an example ponder plugin. diff --git a/dependencies/Ponder-v0.15-alpha-2.jar b/dependencies/Ponder-v0.15-alpha-2.jar deleted file mode 100644 index 6b88d59..0000000 Binary files a/dependencies/Ponder-v0.15-alpha-2.jar and /dev/null differ diff --git a/installation-scripts/install-ponder.sh b/installation-scripts/install-ponder.sh deleted file mode 100644 index 35465ad..0000000 --- a/installation-scripts/install-ponder.sh +++ /dev/null @@ -1 +0,0 @@ -mvn install:install-file -Dfile=${PATH_TO_PONDER_JAR} -DgroupId=preponderous -DartifactId=ponder -Dversion=${PONDER_VERSION} -Dpackaging=Jar \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2ab79b6..db3b06f 100644 --- a/pom.xml +++ b/pom.xml @@ -1,80 +1,84 @@ - - - 4.0.0 - - preponderous - ExamplePonderPlugin - 0.3-alpha-3 - jar - - ExamplePonderPlugin - - - 1.8 - UTF-8 - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - 9 - 9 - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - false - - - - - - - - src/main/resources - true - - - - - - - spigotmc-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - sonatype - https://oss.sonatype.org/content/groups/public/ - - - - - - org.spigotmc - spigot-api - 1.17.1-R0.1-SNAPSHOT - provided - - - com.github.Preponderous-Software - ponder - 1.0 - compile - - - + + + 4.0.0 + + preponderous + ExamplePonderPlugin + 0.3-alpha-3 + jar + + ExamplePonderPlugin + + + 1.8 + UTF-8 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 9 + 9 + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + false + + + + + + + + src/main/resources + true + + + + + + + spigotmc-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + + jitpack.io + https://jitpack.io + + + + + + org.spigotmc + spigot-api + 1.17.1-R0.1-SNAPSHOT + provided + + + com.github.Preponderous-Software + ponder + 1.0 + compile + + + diff --git a/src/main/java/preponderous/exampleponderplugin/ExamplePonderPlugin.java b/src/main/java/preponderous/exampleponderplugin/ExamplePonderPlugin.java index b798f7e..867706d 100644 --- a/src/main/java/preponderous/exampleponderplugin/ExamplePonderPlugin.java +++ b/src/main/java/preponderous/exampleponderplugin/ExamplePonderPlugin.java @@ -1,142 +1,142 @@ -package preponderous.exampleponderplugin; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.event.Listener; -import preponderous.exampleponderplugin.commands.DefaultCommand; -import preponderous.exampleponderplugin.commands.HelpCommand; -import preponderous.exampleponderplugin.eventhandlers.JoinHandler; -import preponderous.exampleponderplugin.services.LocalConfigService; -import preponderous.ponder.minecraft.bukkit.PonderMC; -import preponderous.ponder.minecraft.bukkit.abs.AbstractPluginCommand; -import preponderous.ponder.minecraft.bukkit.abs.PonderBukkitPlugin; -import preponderous.ponder.minecraft.bukkit.services.CommandService; -import preponderous.ponder.minecraft.bukkit.tools.EventHandlerRegistry; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; - -/** - * @author Daniel McCoy Stephenson - */ -public final class ExamplePonderPlugin extends PonderBukkitPlugin { - private static ExamplePonderPlugin instance; - private final String pluginVersion = "v" + getDescription().getVersion(); - private final CommandService commandService = new CommandService((PonderMC) getPonder()); - - /** - * This can be used to get the instance of the main class that is managed by itself. - * @return The managed instance of the main class. - */ - public static ExamplePonderPlugin getInstance() { - return instance; - } - - /** - * This runs when the server starts. - */ - @Override - public void onEnable() { - instance = this; - initializeConfig(); - registerEventHandlers(); - initializeCommandService(); - } - - private void initializeConfig() { - if (configFileExists()) { - performCompatibilityChecks(); - } - else { - LocalConfigService.getInstance().saveMissingConfigDefaultsIfNotPresent(); - } - } - - private boolean configFileExists() { - return new File("./plugins/" + getName() + "/config.yml").exists(); - } - - private void performCompatibilityChecks() { - if (isVersionMismatched()) { - LocalConfigService.getInstance().saveMissingConfigDefaultsIfNotPresent(); - } - reloadConfig(); - } - - /** - * This runs when the server stops. - */ - @Override - public void onDisable() { - - } - - /** - * This method handles commands sent to the minecraft server and interprets them if the label matches one of the core commands. - * @param sender The sender of the command. - * @param cmd The command that was sent. This is unused. - * @param label The core command that has been invoked. - * @param args Arguments of the core command. Often sub-commands. - * @return A boolean indicating whether the execution of the command was successful. - */ - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (args.length == 0) { - DefaultCommand defaultCommand = new DefaultCommand(); - return defaultCommand.execute(sender); - } - - return commandService.interpretAndExecuteCommand(sender, label, args); - } - - /** - * This can be used to get the version of the plugin. - * @return A string containing the version preceded by 'v' - */ - public String getVersion() { - return pluginVersion; - } - - /** - * Checks if the version is mismatched. - * @return A boolean indicating if the version is mismatched. - */ - public boolean isVersionMismatched() { - String configVersion = this.getConfig().getString("version"); - if (configVersion == null || this.getVersion() == null) { - return false; - } else { - return !configVersion.equalsIgnoreCase(this.getVersion()); - } - } - - /** - * Checks if debug is enabled. - * @return Whether debug is enabled. - */ - public boolean isDebugEnabled() { - return LocalConfigService.getInstance().getBoolean("debugMode"); - } - - /** - * Registers the event handlers of the plugin using Ponder. - */ - private void registerEventHandlers() { - EventHandlerRegistry eventHandlerRegistry = new EventHandlerRegistry(); - ArrayList listeners = new ArrayList<>(Arrays.asList( - new JoinHandler() - )); - eventHandlerRegistry.registerEventHandlers(listeners, this); - } - - /** - * Initializes Ponder's command service with the plugin's commands. - */ - private void initializeCommandService() { - ArrayList commands = new ArrayList<>(Arrays.asList( - new HelpCommand() - )); - commandService.initialize(commands, "That command wasn't found."); - } -} +package preponderous.exampleponderplugin; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.event.Listener; +import preponderous.exampleponderplugin.commands.DefaultCommand; +import preponderous.exampleponderplugin.commands.HelpCommand; +import preponderous.exampleponderplugin.eventhandlers.JoinHandler; +import preponderous.exampleponderplugin.services.LocalConfigService; +import preponderous.ponder.minecraft.bukkit.PonderMC; +import preponderous.ponder.minecraft.bukkit.abs.AbstractPluginCommand; +import preponderous.ponder.minecraft.bukkit.abs.PonderBukkitPlugin; +import preponderous.ponder.minecraft.bukkit.services.CommandService; +import preponderous.ponder.minecraft.bukkit.tools.EventHandlerRegistry; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; + +/** + * @author Daniel McCoy Stephenson + */ +public final class ExamplePonderPlugin extends PonderBukkitPlugin { + private static ExamplePonderPlugin instance; + private final String pluginVersion = "v" + getDescription().getVersion(); + private final CommandService commandService = new CommandService((PonderMC) getPonder()); + + /** + * This can be used to get the instance of the main class that is managed by itself. + * @return The managed instance of the main class. + */ + public static ExamplePonderPlugin getInstance() { + return instance; + } + + /** + * This runs when the server starts. + */ + @Override + public void onEnable() { + instance = this; + initializeConfig(); + registerEventHandlers(); + initializeCommandService(); + } + + private void initializeConfig() { + if (configFileExists()) { + performCompatibilityChecks(); + } + else { + LocalConfigService.getInstance().saveMissingConfigDefaultsIfNotPresent(); + } + } + + private boolean configFileExists() { + return new File("./plugins/" + getName() + "/config.yml").exists(); + } + + private void performCompatibilityChecks() { + if (isVersionMismatched()) { + LocalConfigService.getInstance().saveMissingConfigDefaultsIfNotPresent(); + } + reloadConfig(); + } + + /** + * This runs when the server stops. + */ + @Override + public void onDisable() { + + } + + /** + * This method handles commands sent to the minecraft server and interprets them if the label matches one of the core commands. + * @param sender The sender of the command. + * @param cmd The command that was sent. This is unused. + * @param label The core command that has been invoked. + * @param args Arguments of the core command. Often sub-commands. + * @return A boolean indicating whether the execution of the command was successful. + */ + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (args.length == 0) { + DefaultCommand defaultCommand = new DefaultCommand(); + return defaultCommand.execute(sender); + } + + return commandService.interpretAndExecuteCommand(sender, label, args); + } + + /** + * This can be used to get the version of the plugin. + * @return A string containing the version preceded by 'v' + */ + public String getVersion() { + return pluginVersion; + } + + /** + * Checks if the version is mismatched. + * @return A boolean indicating if the version is mismatched. + */ + public boolean isVersionMismatched() { + String configVersion = this.getConfig().getString("version"); + if (configVersion == null || this.getVersion() == null) { + return false; + } else { + return !configVersion.equalsIgnoreCase(this.getVersion()); + } + } + + /** + * Checks if debug is enabled. + * @return Whether debug is enabled. + */ + public boolean isDebugEnabled() { + return LocalConfigService.getInstance().getBoolean("debugMode"); + } + + /** + * Registers the event handlers of the plugin using Ponder. + */ + private void registerEventHandlers() { + EventHandlerRegistry eventHandlerRegistry = new EventHandlerRegistry(); + ArrayList listeners = new ArrayList<>(Arrays.asList( + new JoinHandler() + )); + eventHandlerRegistry.registerEventHandlers(listeners, this); + } + + /** + * Initializes Ponder's command service with the plugin's commands. + */ + private void initializeCommandService() { + ArrayList commands = new ArrayList<>(Arrays.asList( + new HelpCommand() + )); + commandService.initialize(commands, "That command wasn't found."); + } +} diff --git a/src/main/java/preponderous/exampleponderplugin/commands/DefaultCommand.java b/src/main/java/preponderous/exampleponderplugin/commands/DefaultCommand.java index 6af1101..7ee287e 100644 --- a/src/main/java/preponderous/exampleponderplugin/commands/DefaultCommand.java +++ b/src/main/java/preponderous/exampleponderplugin/commands/DefaultCommand.java @@ -1,32 +1,32 @@ -package preponderous.exampleponderplugin.commands; - -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import preponderous.exampleponderplugin.ExamplePonderPlugin; -import preponderous.ponder.minecraft.bukkit.abs.AbstractPluginCommand; - -import java.util.ArrayList; -import java.util.Arrays; - -/** - * @author Daniel McCoy Stephenson - */ -public class DefaultCommand extends AbstractPluginCommand { - - public DefaultCommand() { - super(new ArrayList<>(Arrays.asList("default")), new ArrayList<>(Arrays.asList("epp.default"))); - } - - @Override - public boolean execute(CommandSender commandSender) { - commandSender.sendMessage(ChatColor.AQUA + "ExamplePonderPlugin " + ExamplePonderPlugin.getInstance().getVersion()); - commandSender.sendMessage(ChatColor.AQUA + "Developed by: Daniel Stephenson"); - commandSender.sendMessage(ChatColor.AQUA + "Wiki: https://github.com/Preponderous-Software/ExamplePonderPlugin/wiki"); - return true; - } - - @Override - public boolean execute(CommandSender commandSender, String[] strings) { - return execute(commandSender); - } +package preponderous.exampleponderplugin.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import preponderous.exampleponderplugin.ExamplePonderPlugin; +import preponderous.ponder.minecraft.bukkit.abs.AbstractPluginCommand; + +import java.util.ArrayList; +import java.util.Arrays; + +/** + * @author Daniel McCoy Stephenson + */ +public class DefaultCommand extends AbstractPluginCommand { + + public DefaultCommand() { + super(new ArrayList<>(Arrays.asList("default")), new ArrayList<>(Arrays.asList("epp.default"))); + } + + @Override + public boolean execute(CommandSender commandSender) { + commandSender.sendMessage(ChatColor.AQUA + "ExamplePonderPlugin " + ExamplePonderPlugin.getInstance().getVersion()); + commandSender.sendMessage(ChatColor.AQUA + "Developed by: Daniel Stephenson"); + commandSender.sendMessage(ChatColor.AQUA + "Wiki: https://github.com/Preponderous-Software/ExamplePonderPlugin/wiki"); + return true; + } + + @Override + public boolean execute(CommandSender commandSender, String[] strings) { + return execute(commandSender); + } } \ No newline at end of file diff --git a/src/main/java/preponderous/exampleponderplugin/commands/HelpCommand.java b/src/main/java/preponderous/exampleponderplugin/commands/HelpCommand.java index 48204d5..f580d87 100644 --- a/src/main/java/preponderous/exampleponderplugin/commands/HelpCommand.java +++ b/src/main/java/preponderous/exampleponderplugin/commands/HelpCommand.java @@ -1,29 +1,29 @@ -package preponderous.exampleponderplugin.commands; - -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import preponderous.ponder.minecraft.bukkit.abs.AbstractPluginCommand; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Daniel McCoy Stephenson - */ -public class HelpCommand extends AbstractPluginCommand { - - public HelpCommand() { - super(new ArrayList<>(List.of("help")), new ArrayList<>(List.of("epp.help"))); - } - - @Override - public boolean execute(CommandSender commandSender) { - commandSender.sendMessage(ChatColor.AQUA + "/epp help"); - return true; - } - - @Override - public boolean execute(CommandSender commandSender, String[] strings) { - return execute(commandSender); - } -} +package preponderous.exampleponderplugin.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import preponderous.ponder.minecraft.bukkit.abs.AbstractPluginCommand; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Daniel McCoy Stephenson + */ +public class HelpCommand extends AbstractPluginCommand { + + public HelpCommand() { + super(new ArrayList<>(List.of("help")), new ArrayList<>(List.of("epp.help"))); + } + + @Override + public boolean execute(CommandSender commandSender) { + commandSender.sendMessage(ChatColor.AQUA + "/epp help"); + return true; + } + + @Override + public boolean execute(CommandSender commandSender, String[] strings) { + return execute(commandSender); + } +} diff --git a/src/main/java/preponderous/exampleponderplugin/eventhandlers/JoinHandler.java b/src/main/java/preponderous/exampleponderplugin/eventhandlers/JoinHandler.java index aba1aa4..66ecf18 100644 --- a/src/main/java/preponderous/exampleponderplugin/eventhandlers/JoinHandler.java +++ b/src/main/java/preponderous/exampleponderplugin/eventhandlers/JoinHandler.java @@ -1,18 +1,18 @@ -package preponderous.exampleponderplugin.eventhandlers; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; - -/** - * @author Daniel McCoy Stephenson - */ -public class JoinHandler implements Listener { - @EventHandler() - public void handle(PlayerJoinEvent event) { - Player player = event.getPlayer(); - player.sendMessage(ChatColor.AQUA + "This message was sent by ExamplePonderPlugin."); - } +package preponderous.exampleponderplugin.eventhandlers; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +/** + * @author Daniel McCoy Stephenson + */ +public class JoinHandler implements Listener { + @EventHandler() + public void handle(PlayerJoinEvent event) { + Player player = event.getPlayer(); + player.sendMessage(ChatColor.AQUA + "This message was sent by ExamplePonderPlugin."); + } } \ No newline at end of file diff --git a/src/main/java/preponderous/exampleponderplugin/services/LocalConfigService.java b/src/main/java/preponderous/exampleponderplugin/services/LocalConfigService.java index ff554a9..ba01cb0 100644 --- a/src/main/java/preponderous/exampleponderplugin/services/LocalConfigService.java +++ b/src/main/java/preponderous/exampleponderplugin/services/LocalConfigService.java @@ -1,133 +1,133 @@ -package preponderous.exampleponderplugin.services; - -/* - To add a new config option, the following methods must be altered: - - saveMissingConfigDefaultsIfNotPresent - - setConfigOption() - - sendConfigList() - */ - -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.FileConfiguration; -import preponderous.exampleponderplugin.ExamplePonderPlugin; - -/** - * @author Daniel McCoy Stephenson - */ -public class LocalConfigService { - - private static LocalConfigService instance; - private boolean altered = false; - - private LocalConfigService() { - - } - - public static LocalConfigService getInstance() { - if (instance == null) { - instance = new LocalConfigService(); - } - return instance; - } - - public void saveMissingConfigDefaultsIfNotPresent() { - // set version - if (!getConfig().isString("version")) { - getConfig().addDefault("version", ExamplePonderPlugin.getInstance().getVersion()); - } else { - getConfig().set("version", ExamplePonderPlugin.getInstance().getVersion()); - } - - // save config options - if (!isSet("debugMode")) { getConfig().set("debugMode", false); } - - getConfig().options().copyDefaults(true); - ExamplePonderPlugin.getInstance().saveConfig(); - } - - public void setConfigOption(String option, String value, CommandSender sender) { - if (getConfig().isSet(option)) { - if (option.equalsIgnoreCase("version")) { - sender.sendMessage(ChatColor.RED + "Cannot set version."); - return; - } else if (option.equalsIgnoreCase("A")) { - getConfig().set(option, Integer.parseInt(value)); - sender.sendMessage(ChatColor.GREEN + "Integer set."); - } else if (option.equalsIgnoreCase("debugMode")) { - getConfig().set(option, Boolean.parseBoolean(value)); - sender.sendMessage(ChatColor.GREEN + "Boolean set."); - } else if (option.equalsIgnoreCase("C")) { - getConfig().set(option, Double.parseDouble(value)); - sender.sendMessage(ChatColor.GREEN + "Double set."); - } else { - getConfig().set(option, value); - sender.sendMessage(ChatColor.GREEN + "String set."); - } - - // save - ExamplePonderPlugin.getInstance().saveConfig(); - altered = true; - } else { - sender.sendMessage(ChatColor.RED + "That config option wasn't found."); - } - } - - public void sendConfigList(CommandSender sender) { - sender.sendMessage(ChatColor.AQUA + "=== Config List ==="); - sender.sendMessage(ChatColor.AQUA + "version: " + getConfig().getString("version") - + ", debugMode: " + getString("debugMode")); - } - - public boolean hasBeenAltered() { - return altered; - } - - public FileConfiguration getConfig() { - return ExamplePonderPlugin.getInstance().getConfig(); - } - - public boolean isSet(String option) { - return getConfig().isSet(option); - } - - public int getInt(String option) { - return getConfig().getInt(option); - } - - public int getIntOrDefault(String option, int defaultValue) { - int toReturn = getInt(option); - if (toReturn == 0) { - return defaultValue; - } - return toReturn; - } - - public boolean getBoolean(String option) { - return getConfig().getBoolean(option); - } - - public double getDouble(String option) { - return getConfig().getDouble(option); - } - - public double getDoubleOrDefault(String option, double defaultValue) { - double toReturn = getDouble(option); - if (toReturn == 0) { - return defaultValue; - } - return toReturn; - } - - public String getString(String option) { - return getConfig().getString(option); - } - - public String getStringOrDefault(String option, String defaultValue) { - String toReturn = getString(option); - if (toReturn == null) { - return defaultValue; - } - return toReturn; - } +package preponderous.exampleponderplugin.services; + +/* + To add a new config option, the following methods must be altered: + - saveMissingConfigDefaultsIfNotPresent + - setConfigOption() + - sendConfigList() + */ + +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import preponderous.exampleponderplugin.ExamplePonderPlugin; + +/** + * @author Daniel McCoy Stephenson + */ +public class LocalConfigService { + + private static LocalConfigService instance; + private boolean altered = false; + + private LocalConfigService() { + + } + + public static LocalConfigService getInstance() { + if (instance == null) { + instance = new LocalConfigService(); + } + return instance; + } + + public void saveMissingConfigDefaultsIfNotPresent() { + // set version + if (!getConfig().isString("version")) { + getConfig().addDefault("version", ExamplePonderPlugin.getInstance().getVersion()); + } else { + getConfig().set("version", ExamplePonderPlugin.getInstance().getVersion()); + } + + // save config options + if (!isSet("debugMode")) { getConfig().set("debugMode", false); } + + getConfig().options().copyDefaults(true); + ExamplePonderPlugin.getInstance().saveConfig(); + } + + public void setConfigOption(String option, String value, CommandSender sender) { + if (getConfig().isSet(option)) { + if (option.equalsIgnoreCase("version")) { + sender.sendMessage(ChatColor.RED + "Cannot set version."); + return; + } else if (option.equalsIgnoreCase("A")) { + getConfig().set(option, Integer.parseInt(value)); + sender.sendMessage(ChatColor.GREEN + "Integer set."); + } else if (option.equalsIgnoreCase("debugMode")) { + getConfig().set(option, Boolean.parseBoolean(value)); + sender.sendMessage(ChatColor.GREEN + "Boolean set."); + } else if (option.equalsIgnoreCase("C")) { + getConfig().set(option, Double.parseDouble(value)); + sender.sendMessage(ChatColor.GREEN + "Double set."); + } else { + getConfig().set(option, value); + sender.sendMessage(ChatColor.GREEN + "String set."); + } + + // save + ExamplePonderPlugin.getInstance().saveConfig(); + altered = true; + } else { + sender.sendMessage(ChatColor.RED + "That config option wasn't found."); + } + } + + public void sendConfigList(CommandSender sender) { + sender.sendMessage(ChatColor.AQUA + "=== Config List ==="); + sender.sendMessage(ChatColor.AQUA + "version: " + getConfig().getString("version") + + ", debugMode: " + getString("debugMode")); + } + + public boolean hasBeenAltered() { + return altered; + } + + public FileConfiguration getConfig() { + return ExamplePonderPlugin.getInstance().getConfig(); + } + + public boolean isSet(String option) { + return getConfig().isSet(option); + } + + public int getInt(String option) { + return getConfig().getInt(option); + } + + public int getIntOrDefault(String option, int defaultValue) { + int toReturn = getInt(option); + if (toReturn == 0) { + return defaultValue; + } + return toReturn; + } + + public boolean getBoolean(String option) { + return getConfig().getBoolean(option); + } + + public double getDouble(String option) { + return getConfig().getDouble(option); + } + + public double getDoubleOrDefault(String option, double defaultValue) { + double toReturn = getDouble(option); + if (toReturn == 0) { + return defaultValue; + } + return toReturn; + } + + public String getString(String option) { + return getConfig().getString(option); + } + + public String getStringOrDefault(String option, String defaultValue) { + String toReturn = getString(option); + if (toReturn == null) { + return defaultValue; + } + return toReturn; + } } \ No newline at end of file diff --git a/src/main/java/preponderous/exampleponderplugin/utils/Logger.java b/src/main/java/preponderous/exampleponderplugin/utils/Logger.java index f8ba949..d3761c1 100644 --- a/src/main/java/preponderous/exampleponderplugin/utils/Logger.java +++ b/src/main/java/preponderous/exampleponderplugin/utils/Logger.java @@ -1,29 +1,29 @@ -package preponderous.exampleponderplugin.utils; - -import preponderous.exampleponderplugin.ExamplePonderPlugin; - -/** - * @author Daniel McCoy Stephenson - */ -public class Logger { - - private static Logger instance; - - private Logger() { - - } - - public static Logger getInstance() { - if (instance == null) { - instance = new Logger(); - } - return instance; - } - - public void log(String message) { - if (ExamplePonderPlugin.getInstance().isDebugEnabled()) { - System.out.println("[ExamplePonderPlugin] " + message); - } - } - -} +package preponderous.exampleponderplugin.utils; + +import preponderous.exampleponderplugin.ExamplePonderPlugin; + +/** + * @author Daniel McCoy Stephenson + */ +public class Logger { + + private static Logger instance; + + private Logger() { + + } + + public static Logger getInstance() { + if (instance == null) { + instance = new Logger(); + } + return instance; + } + + public void log(String message) { + if (ExamplePonderPlugin.getInstance().isDebugEnabled()) { + System.out.println("[ExamplePonderPlugin] " + message); + } + } + +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index bf6d3d0..f40c011 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,12 +1,12 @@ -name: ExamplePonderPlugin -version: '${project.version}' -main: preponderous.exampleponderplugin.ExamplePonderPlugin -api-version: 1.13 - -commands: - exampleponderplugin: - epp: - -permissions: - epp.help: - default: true +name: ExamplePonderPlugin +version: '${project.version}' +main: preponderous.exampleponderplugin.ExamplePonderPlugin +api-version: 1.13 + +commands: + exampleponderplugin: + epp: + +permissions: + epp.help: + default: true