commit 68fe6c1ee42e710e59ae2736300caf364a3ea71c Author: Etzelia Date: Thu Aug 6 17:31:57 2020 -0500 Initial Commit Signed-off-by: Etzelia diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3d13e3f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.idea/ +*.iml +target/ +dependency-reduced-pom.xml \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..82b4eb1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2020 Etzelia + +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. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..de3b6a7 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# ServerAPI + +TBD + +## License + +[MIT](LICENSE) diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..a8fd9b8 --- /dev/null +++ b/pom.xml @@ -0,0 +1,135 @@ + + 4.0.0 + xyz.etztech + ServerAPI + + 0.0.1 + jar + + + + ServerAPI + An API about your Minecraft server. + https://git.etztech.xyz/Minecraft/ServerAPI + + + + + EtzTech + https://git.etztech.xyz/ + + + + + + EtzTech + xyz.etztech.serverapi.ServerAPI + UTF-8 + + + + + org.spigotmc + spigot-api + 1.16.1-R0.1-SNAPSHOT + provided + + + commons-lang + commons-lang + 2.6 + + + io.javalin + javalin + 3.9.1 + + + + + + + spigotmc-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + etztech-repo + http://repo.etztech.xyz/ + + + mvn-repo + https://mvnrepository.com/artifact/ + + + jcenter + https://jcenter.bintray.com + + + jitpack.io + https://jitpack.io + + + + + src/main/java + clean install + + + src/main/resources + + true + + plugin.yml + config.yml + + + + src/main/resources + + false + + **/*.java + plugin.yml + + + + + + maven-compiler-plugin + 3.1 + + 8 + 8 + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.0.2 + + + + true + lib/ + xyz.etztech.serverapi.ServerAPI + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.1.1 + + + package + + shade + + + + + + + \ No newline at end of file diff --git a/src/main/java/xyz/etztech/serverapi/Color.java b/src/main/java/xyz/etztech/serverapi/Color.java new file mode 100644 index 0000000..2ecab78 --- /dev/null +++ b/src/main/java/xyz/etztech/serverapi/Color.java @@ -0,0 +1,55 @@ +package xyz.etztech.serverapi; + +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; + +public class Color { + public static Color DEFAULT = new Color("#AAAAAA"); + public static Color ERROR = new Color("#F14668"); + public static Color INFO = new Color("#3298DC"); + public static Color PRIMARY = new Color("#3273DC"); + + private final String hex; + private final ChatColor chatColor; + + public Color(String hex) { + this.hex = hex; + this.chatColor = ChatColor.of(hex); + } + + public String getHex() { + return hex; + } + + public int getInt() { + return hexToInt(hex); + } + + public ChatColor getChatColor() { + return chatColor; + } + + public void sms(CommandSender commandSender, String message) { + if (commandSender instanceof ConsoleCommandSender) { + ServerAPI.getInstance().log(message); + return; + } + TextComponent text = new TextComponent(message); + text.setColor(this.chatColor); + commandSender.spigot().sendMessage(text); + } + + public static int hexToInt(String hex) { + if (hex.startsWith("#")) { + hex = hex.substring(1); + } + + if (hex.length() != 6) { + return 0; + } + + return Integer.parseInt(hex, 16); + } +} diff --git a/src/main/java/xyz/etztech/serverapi/Lang.java b/src/main/java/xyz/etztech/serverapi/Lang.java new file mode 100644 index 0000000..4017c6b --- /dev/null +++ b/src/main/java/xyz/etztech/serverapi/Lang.java @@ -0,0 +1,30 @@ +package xyz.etztech.serverapi; + + +import org.bukkit.command.CommandSender; + +public enum Lang { + NO_PERMISSION("You don't have permission to do that.", Color.ERROR), + UNKNOWN_COMMAND("This command wasn't recognized.", Color.ERROR), + PLUGIN_RELOADED("ServerAPI reloaded.", Color.INFO); + + private final String message; + private final Color color; + + Lang(String message, Color color) { + this.message = message; + this.color = color; + } + + public String getMessage(Object ...args) { + return String.format(this.message, args); + } + + public Color getColor() { + return this.color; + } + + public void sms(CommandSender sender, Object ...args) { + this.color.sms(sender, String.format(this.message, args)); + } +} diff --git a/src/main/java/xyz/etztech/serverapi/ServerAPI.java b/src/main/java/xyz/etztech/serverapi/ServerAPI.java new file mode 100644 index 0000000..44982f6 --- /dev/null +++ b/src/main/java/xyz/etztech/serverapi/ServerAPI.java @@ -0,0 +1,32 @@ +package xyz.etztech.serverapi; + + +import org.bukkit.plugin.java.JavaPlugin; +import xyz.etztech.serverapi.commands.MainCommand; + +import java.util.logging.Logger; + +public class ServerAPI extends JavaPlugin { + + private static ServerAPI instance; + private final Logger log = Logger.getLogger( "Minecraft" ); + + public void onEnable() { + instance = this; + saveDefaultConfig(); + reloadConfig(); + + if (isEnabled()) { + new MainCommand(this); + } + } + + public void log(String message) { + log.info( "[ServerAPI]: " + message ); + } + + public static ServerAPI getInstance() { + return instance; + } +} + diff --git a/src/main/java/xyz/etztech/serverapi/commands/MainCommand.java b/src/main/java/xyz/etztech/serverapi/commands/MainCommand.java new file mode 100644 index 0000000..86a3562 --- /dev/null +++ b/src/main/java/xyz/etztech/serverapi/commands/MainCommand.java @@ -0,0 +1,62 @@ +package xyz.etztech.serverapi.commands; + +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import xyz.etztech.serverapi.Color; +import xyz.etztech.serverapi.Lang; +import xyz.etztech.serverapi.ServerAPI; + +public class MainCommand implements CommandExecutor { + + + ServerAPI plugin; + + public MainCommand(ServerAPI plugin) { + this.plugin = plugin; + this.plugin.getCommand("serverapi").setExecutor(this); + } + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { + if (!commandSender.hasPermission("serverapi.admin")) { + Lang.NO_PERMISSION.sms(commandSender); + return true; + } + if (args.length == 0) { + help(commandSender); + } else { + switch (args[0]) { + case "help": + help(commandSender); + break; + case "reload": + reload(commandSender); + break; + default: + Lang.UNKNOWN_COMMAND.sms(commandSender); + break; + } + } + return true; + } + + private void help(CommandSender commandSender) { + String version = Bukkit.getPluginManager().getPlugin("ServerAPI").getDescription().getVersion(); + BaseComponent[] message = new ComponentBuilder() + .append(String.format("===== ServerAPI v%s =====", version)).color(Color.PRIMARY.getChatColor()) + .append("\n/serverapi help - Show this message").color(Color.INFO.getChatColor()) + .append("\n/serverapi reload - Reload the config").color(Color.INFO.getChatColor()) + .create(); + commandSender.spigot().sendMessage(message); + } + + private void reload(CommandSender commandSender) { + this.plugin.reloadConfig(); + Lang.PLUGIN_RELOADED.sms(commandSender); + } + +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..c2279d3 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,15 @@ +name: ${name} +version: ${version} +description: ${description} +author: ${author} +website: ${url} +main: ${mainClass} +api-version: 1.16 +commands: + serverapi: + aliases: sapi + description: Base command +permissions: + serverapi.admin: + description: Ability to reload the plugin + default: op