commit
68fe6c1ee4
|
@ -0,0 +1,4 @@
|
||||||
|
.idea/
|
||||||
|
*.iml
|
||||||
|
target/
|
||||||
|
dependency-reduced-pom.xml
|
|
@ -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.
|
|
@ -0,0 +1,135 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>xyz.etztech</groupId>
|
||||||
|
<artifactId>ServerAPI</artifactId>
|
||||||
|
<!-- Version is used in plugin.yml -->
|
||||||
|
<version>0.0.1</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<!-- Plugin Information -->
|
||||||
|
<!-- Name, Description, and URL are used in plugin.yml -->
|
||||||
|
<name>ServerAPI</name>
|
||||||
|
<description>An API about your Minecraft server.</description>
|
||||||
|
<url>https://git.etztech.xyz/Minecraft/ServerAPI</url>
|
||||||
|
|
||||||
|
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<name>EtzTech</name>
|
||||||
|
<url>https://git.etztech.xyz/</url>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<!-- Author and MainClass are used in plugin.yml -->
|
||||||
|
<author>EtzTech</author>
|
||||||
|
<mainClass>xyz.etztech.serverapi.ServerAPI</mainClass>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.16.1-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-lang</groupId>
|
||||||
|
<artifactId>commons-lang</artifactId>
|
||||||
|
<version>2.6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.javalin</groupId>
|
||||||
|
<artifactId>javalin</artifactId>
|
||||||
|
<version>3.9.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spigotmc-repo</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>etztech-repo</id>
|
||||||
|
<url>http://repo.etztech.xyz/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>mvn-repo</id>
|
||||||
|
<url>https://mvnrepository.com/artifact/</url>
|
||||||
|
</repository>
|
||||||
|
<repository> <!-- This repo fixes issues with transitive dependencies -->
|
||||||
|
<id>jcenter</id>
|
||||||
|
<url>https://jcenter.bintray.com</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>jitpack.io</id>
|
||||||
|
<url>https://jitpack.io</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>src/main/java</sourceDirectory>
|
||||||
|
<defaultGoal>clean install</defaultGoal>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<!-- Keeping filtering at true here reduces plugin.yml redundancy! -->
|
||||||
|
<filtering>true</filtering>
|
||||||
|
<includes>
|
||||||
|
<include>plugin.yml</include>
|
||||||
|
<include>config.yml</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<!-- Keep filtering at false for other resources to prevent bad magic -->
|
||||||
|
<filtering>false</filtering>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*.java</exclude>
|
||||||
|
<exclude>plugin.yml</exclude>
|
||||||
|
</excludes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>8</source>
|
||||||
|
<target>8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<!-- Build an executable JAR -->
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<addClasspath>true</addClasspath>
|
||||||
|
<classpathPrefix>lib/</classpathPrefix>
|
||||||
|
<mainClass>xyz.etztech.serverapi.ServerAPI</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.1.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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
|
Loading…
Reference in New Issue