From 5d1fe4ba21e29836c41d615e708d709ba9dcd5e5 Mon Sep 17 00:00:00 2001 From: JaTiTV Date: Tue, 21 Dec 2021 05:55:23 +0100 Subject: [PATCH] 1.0.4 --- .gitattributes | 2 + .gitignore | 113 +++ pom.xml | 170 ++++ .../java/net/t2code/alias/Bungee/BMain.java | 47 + .../t2code/alias/Bungee/system/BListener.java | 38 + .../net/t2code/alias/Bungee/system/BLoad.java | 24 + .../t2code/alias/Bungee/system/BMetrics.java | 846 +++++++++++++++++ .../java/net/t2code/alias/Spigot/Main.java | 70 ++ .../cmdManagement/Alias_CmdExecuter.java | 100 ++ .../alias/Spigot/cmdManagement/Commands.java | 38 + .../cmdManagement/RegisterCommands.java | 166 ++++ .../Spigot/config/config/CreateConfig.java | 45 + .../config/CreateExampleAliasConfig.java | 111 +++ .../Spigot/config/config/SelectAlias.java | 69 ++ .../Spigot/config/config/SelectConfig.java | 25 + .../config/languages/LanguagesCreate.java | 92 ++ .../alias/Spigot/config/languages/MSG.java | 49 + .../config/languages/SelectMessages.java | 52 ++ .../alias/Spigot/objects/Alias_Objekt.java | 112 +++ .../alias/Spigot/system/AliasRegister.java | 104 +++ .../system/Alias_RegisterPermissions.java | 21 + .../system/BCommand_Sender_Reciver.java | 35 + .../t2code/alias/Spigot/system/JoinEvent.java | 34 + .../net/t2code/alias/Spigot/system/Load.java | 58 ++ .../t2code/alias/Spigot/system/Metrics.java | 854 ++++++++++++++++++ .../alias/Spigot/system/UpdateChecker.java | 116 +++ src/main/java/net/t2code/alias/Util.java | 9 + src/main/resources/bungee.yml | 6 + src/main/resources/plugin.yml | 32 + 29 files changed, 3438 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/net/t2code/alias/Bungee/BMain.java create mode 100644 src/main/java/net/t2code/alias/Bungee/system/BListener.java create mode 100644 src/main/java/net/t2code/alias/Bungee/system/BLoad.java create mode 100644 src/main/java/net/t2code/alias/Bungee/system/BMetrics.java create mode 100644 src/main/java/net/t2code/alias/Spigot/Main.java create mode 100644 src/main/java/net/t2code/alias/Spigot/cmdManagement/Alias_CmdExecuter.java create mode 100644 src/main/java/net/t2code/alias/Spigot/cmdManagement/Commands.java create mode 100644 src/main/java/net/t2code/alias/Spigot/cmdManagement/RegisterCommands.java create mode 100644 src/main/java/net/t2code/alias/Spigot/config/config/CreateConfig.java create mode 100644 src/main/java/net/t2code/alias/Spigot/config/config/CreateExampleAliasConfig.java create mode 100644 src/main/java/net/t2code/alias/Spigot/config/config/SelectAlias.java create mode 100644 src/main/java/net/t2code/alias/Spigot/config/config/SelectConfig.java create mode 100644 src/main/java/net/t2code/alias/Spigot/config/languages/LanguagesCreate.java create mode 100644 src/main/java/net/t2code/alias/Spigot/config/languages/MSG.java create mode 100644 src/main/java/net/t2code/alias/Spigot/config/languages/SelectMessages.java create mode 100644 src/main/java/net/t2code/alias/Spigot/objects/Alias_Objekt.java create mode 100644 src/main/java/net/t2code/alias/Spigot/system/AliasRegister.java create mode 100644 src/main/java/net/t2code/alias/Spigot/system/Alias_RegisterPermissions.java create mode 100644 src/main/java/net/t2code/alias/Spigot/system/BCommand_Sender_Reciver.java create mode 100644 src/main/java/net/t2code/alias/Spigot/system/JoinEvent.java create mode 100644 src/main/java/net/t2code/alias/Spigot/system/Load.java create mode 100644 src/main/java/net/t2code/alias/Spigot/system/Metrics.java create mode 100644 src/main/java/net/t2code/alias/Spigot/system/UpdateChecker.java create mode 100644 src/main/java/net/t2code/alias/Util.java create mode 100644 src/main/resources/bungee.yml create mode 100644 src/main/resources/plugin.yml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4788b4b --- /dev/null +++ b/.gitignore @@ -0,0 +1,113 @@ +# User-specific stuff +.idea/ + +*.iml +*.ipr +*.iws + +# IntelliJ +out/ + +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +target/ + +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next + +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar +.flattened-pom.xml + +# Common working directory +run/ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..7a8293f --- /dev/null +++ b/pom.xml @@ -0,0 +1,170 @@ + + + 4.0.0 + + net.t2code + Alias + 1.0.4 + jar + + T2C-Alias + + T2Code Alias + + 1.8 + UTF-8 + + T2Code.net + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + false + + + + + + + + src/main/resources + true + + + + + + + Builders-Paradise + https://dojagames.net:8081/repository/Builders-Paradise/ + + + T2Code + https://dojagames.net:8081/repository/T2Code/ + + + + + + net.t2code + bungee + 1615 + + + net.t2code + PlugmanGUI + 3.0 + + + net.t2code + T2CodeLib + 7.4 + + + net.t2code.minecraft.1_18.r1 + spigot + 1.18r1 + + + net.t2code.minecraft.1_17.r1 + spigot + 1.17r1 + + + net.t2code.minecraft.1_16.r3 + spigot + 1.16r3 + + + net.t2code.minecraft.1_16.r2 + spigot + 1.16r2 + + + net.t2code.minecraft.1_16.r1 + spigot + 1.16r1 + + + net.t2code.minecraft.1_15.r1 + spigot + 1.15r1 + + + net.t2code.minecraft.1_14.r1 + spigot + 1.14r1 + + + net.t2code.minecraft.1_13.r2 + spigot + 1.13r2 + + + net.t2code.minecraft.1_13.r1 + spigot + 1.13r1 + + + net.t2code.minecraft.1_12.r1 + spigot + 1.12r1 + + + net.t2code.minecraft.1_11.r1 + spigot + 1.11r1 + + + net.t2code.minecraft.1_10.r1 + spigot + 1.10r1 + + + net.t2code.minecraft.1_9.r2 + spigot + 1.9r2 + + + net.t2code.minecraft.1_9.r1 + spigot + 1.9r1 + + + net.t2code.minecraft.1_8.r3 + spigot + 1.8r3 + + + net.t2code.minecraft.1_8.r2 + spigot + 1.8r2 + + + net.t2code.minecraft.1_8.r1 + spigot + 1.8r1 + + + diff --git a/src/main/java/net/t2code/alias/Bungee/BMain.java b/src/main/java/net/t2code/alias/Bungee/BMain.java new file mode 100644 index 0000000..d610b04 --- /dev/null +++ b/src/main/java/net/t2code/alias/Bungee/BMain.java @@ -0,0 +1,47 @@ +package net.t2code.alias.Bungee; + +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.plugin.Plugin; +import net.t2code.alias.Bungee.system.BLoad; +import net.t2code.alias.Util; +import net.t2code.lib.Bungee.Lib.messages.BT2CodeTemplate; + +import java.util.logging.Level; + +public final class BMain extends Plugin { + + + public static Plugin plugin; + public static String version; + public static String autor; + + public static String prefix = Util.Prefix; + public static Integer spigotID = Util.SpigotID; + public static Integer bstatsID = Util.BstatsID; + public static String spigot = Util.Spigot; + public static String discord = Util.Discord; + + + @Override + public void onEnable() { + // Plugin startup logic + plugin = this; + version = plugin.getDescription().getVersion(); + autor = plugin.getDescription().getAuthor(); + if (ProxyServer.getInstance().getPluginManager().getPlugin("T2CodeLib") == null) { + plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!"); + ProxyServer.getInstance().getConsole().sendMessage(prefix + " §eT2CodeLib §4could not be found. Please download it here: " + + "§6https://www.spigotmc.org/resources/t2codelib.96388/ §4to be able to use this plugin."); + getProxy().getPluginManager().getPlugin(plugin.getDescription().getName()).onDisable(); + return; + } + BLoad.onLoad(plugin, prefix, autor, version, spigot, discord, spigotID, bstatsID); + } + + @Override + public void onDisable() { + // Plugin shutdown logic + if (ProxyServer.getInstance().getPluginManager().getPlugin("T2CodeLib") == null) return; + BT2CodeTemplate.onDisable(prefix, autor, version, spigot, discord); + } +} diff --git a/src/main/java/net/t2code/alias/Bungee/system/BListener.java b/src/main/java/net/t2code/alias/Bungee/system/BListener.java new file mode 100644 index 0000000..f1dec39 --- /dev/null +++ b/src/main/java/net/t2code/alias/Bungee/system/BListener.java @@ -0,0 +1,38 @@ +package net.t2code.alias.Bungee.system; + +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.PluginMessageEvent; +import net.md_5.bungee.api.plugin.Listener; +import net.md_5.bungee.event.EventHandler; + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; + +public class BListener implements Listener { + + @EventHandler + public void onPluginmessage(PluginMessageEvent event) { + if (event.getTag().equalsIgnoreCase("t2codealias:bungee")) { + + DataInputStream stream = new DataInputStream(new ByteArrayInputStream(event.getData())); + try { + String channel = stream.readUTF(); + String input = stream.readUTF(); + if (channel.equals("T2Code-Console")) { + ProxyServer.getInstance().getConsole().sendMessage("Command Console: "+ input); + ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getConsole(), input); + } else { + ProxiedPlayer player = ProxyServer.getInstance().getPlayer(channel); + if (player != null) { + ProxyServer.getInstance().getConsole().sendMessage("Command " + player +": "+ input); + ProxyServer.getInstance().getPluginManager().dispatchCommand(player, input); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } +} diff --git a/src/main/java/net/t2code/alias/Bungee/system/BLoad.java b/src/main/java/net/t2code/alias/Bungee/system/BLoad.java new file mode 100644 index 0000000..f222d12 --- /dev/null +++ b/src/main/java/net/t2code/alias/Bungee/system/BLoad.java @@ -0,0 +1,24 @@ +package net.t2code.alias.Bungee.system; + +import net.md_5.bungee.api.plugin.Plugin; +import net.t2code.lib.Bungee.Lib.messages.BT2CodeTemplate; +import net.t2code.lib.Bungee.Lib.messages.Bsend; +import net.t2code.lib.Bungee.Lib.update.BUpdateAPI; + +public class BLoad { + + public static void onLoad(Plugin plugin, String prefix, String autor, String version, String spigot, String discord, Integer spigotID, Integer bstatsID) { + Long long_ = BT2CodeTemplate.onLoadHeader(prefix,autor,version,spigot,discord); + + + plugin.getProxy().registerChannel("t2codealias:bungee"); + Bsend.console(prefix + " registerChannel(t2codealias:bungee)"); + plugin.getProxy().getPluginManager().registerListener(plugin, new BListener()); + + BMetrics metrics = new BMetrics(plugin, bstatsID); + + BUpdateAPI.onUpdateCheckTimer(plugin, prefix, spigot, discord, spigotID); + + BT2CodeTemplate.onLoadFooter(prefix, long_); + } +} diff --git a/src/main/java/net/t2code/alias/Bungee/system/BMetrics.java b/src/main/java/net/t2code/alias/Bungee/system/BMetrics.java new file mode 100644 index 0000000..dd141c7 --- /dev/null +++ b/src/main/java/net/t2code/alias/Bungee/system/BMetrics.java @@ -0,0 +1,846 @@ +package net.t2code.alias.Bungee.system; + +import net.md_5.bungee.api.plugin.Plugin; +import net.md_5.bungee.config.Configuration; +import net.md_5.bungee.config.ConfigurationProvider; +import net.md_5.bungee.config.YamlConfiguration; + +import javax.net.ssl.HttpsURLConnection; +import java.io.*; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.concurrent.Callable; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import java.util.function.Supplier; +import java.util.logging.Level; +import java.util.stream.Collectors; +import java.util.zip.GZIPOutputStream; + +public class BMetrics { + + private final Plugin plugin; + + private final MetricsBase metricsBase; + + private boolean enabled; + + private String serverUUID; + + private boolean logErrors = false; + + private boolean logSentData; + + private boolean logResponseStatusText; + + /** + * Creates a new Metrics instance. + * + * @param plugin Your plugin instance. + * @param serviceId The id of the service. It can be found at What is my plugin id? + */ + public BMetrics(Plugin plugin, int serviceId) { + this.plugin = plugin; + try { + loadConfig(); + } catch (IOException e) { + // Failed to load configuration + plugin.getLogger().log(Level.WARNING, "Failed to load bStats config!", e); + metricsBase = null; + return; + } + metricsBase = + new MetricsBase( + "bungeecord", + serverUUID, + serviceId, + enabled, + this::appendPlatformData, + this::appendServiceData, + null, + () -> true, + (message, error) -> this.plugin.getLogger().log(Level.WARNING, message, error), + (message) -> this.plugin.getLogger().log(Level.INFO, message), + logErrors, + logSentData, + logResponseStatusText); + } + + /** Loads the bStats configuration. */ + private void loadConfig() throws IOException { + File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats"); + bStatsFolder.mkdirs(); + File configFile = new File(bStatsFolder, "config.yml"); + if (!configFile.exists()) { + writeFile( + configFile, + "# bStats (https://bStats.org) collects some basic information for plugin authors, like how", + "# many people use their plugin and their total player count. It's recommended to keep bStats", + "# enabled, but if you're not comfortable with this, you can turn this setting off. There is no", + "# performance penalty associated with having metrics enabled, and data sent to bStats is fully", + "# anonymous.", + "enabled: true", + "serverUuid: \"" + UUID.randomUUID() + "\"", + "logFailedRequests: false", + "logSentData: false", + "logResponseStatusText: false"); + } + Configuration configuration = + ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); + // Load configuration + enabled = configuration.getBoolean("enabled", true); + serverUUID = configuration.getString("serverUuid"); + logErrors = configuration.getBoolean("logFailedRequests", false); + logSentData = configuration.getBoolean("logSentData", false); + logResponseStatusText = configuration.getBoolean("logResponseStatusText", false); + } + + private void writeFile(File file, String... lines) throws IOException { + try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file))) { + for (String line : lines) { + bufferedWriter.write(line); + bufferedWriter.newLine(); + } + } + } + + /** + * Adds a custom chart. + * + * @param chart The chart to add. + */ + public void addCustomChart(CustomChart chart) { + metricsBase.addCustomChart(chart); + } + + private void appendPlatformData(JsonObjectBuilder builder) { + builder.appendField("playerAmount", plugin.getProxy().getOnlineCount()); + builder.appendField("managedServers", plugin.getProxy().getServers().size()); + builder.appendField("onlineMode", plugin.getProxy().getConfig().isOnlineMode() ? 1 : 0); + builder.appendField("bungeecordVersion", plugin.getProxy().getVersion()); + builder.appendField("javaVersion", System.getProperty("java.version")); + builder.appendField("osName", System.getProperty("os.name")); + builder.appendField("osArch", System.getProperty("os.arch")); + builder.appendField("osVersion", System.getProperty("os.version")); + builder.appendField("coreCount", Runtime.getRuntime().availableProcessors()); + } + + private void appendServiceData(JsonObjectBuilder builder) { + builder.appendField("pluginVersion", plugin.getDescription().getVersion()); + } + + public static class MetricsBase { + + /** The version of the Metrics class. */ + public static final String METRICS_VERSION = "2.2.1"; + + private static final ScheduledExecutorService scheduler = + Executors.newScheduledThreadPool(1, task -> new Thread(task, "bStats-Metrics")); + + private static final String REPORT_URL = "https://bStats.org/api/v2/data/%s"; + + private final String platform; + + private final String serverUuid; + + private final int serviceId; + + private final Consumer appendPlatformDataConsumer; + + private final Consumer appendServiceDataConsumer; + + private final Consumer submitTaskConsumer; + + private final Supplier checkServiceEnabledSupplier; + + private final BiConsumer errorLogger; + + private final Consumer infoLogger; + + private final boolean logErrors; + + private final boolean logSentData; + + private final boolean logResponseStatusText; + + private final Set customCharts = new HashSet<>(); + + private final boolean enabled; + + /** + * Creates a new MetricsBase class instance. + * + * @param platform The platform of the service. + * @param serviceId The id of the service. + * @param serverUuid The server uuid. + * @param enabled Whether or not data sending is enabled. + * @param appendPlatformDataConsumer A consumer that receives a {@code JsonObjectBuilder} and + * appends all platform-specific data. + * @param appendServiceDataConsumer A consumer that receives a {@code JsonObjectBuilder} and + * appends all service-specific data. + * @param submitTaskConsumer A consumer that takes a runnable with the submit task. This can be + * used to delegate the data collection to a another thread to prevent errors caused by + * concurrency. Can be {@code null}. + * @param checkServiceEnabledSupplier A supplier to check if the service is still enabled. + * @param errorLogger A consumer that accepts log message and an error. + * @param infoLogger A consumer that accepts info log messages. + * @param logErrors Whether or not errors should be logged. + * @param logSentData Whether or not the sent data should be logged. + * @param logResponseStatusText Whether or not the response status text should be logged. + */ + public MetricsBase( + String platform, + String serverUuid, + int serviceId, + boolean enabled, + Consumer appendPlatformDataConsumer, + Consumer appendServiceDataConsumer, + Consumer submitTaskConsumer, + Supplier checkServiceEnabledSupplier, + BiConsumer errorLogger, + Consumer infoLogger, + boolean logErrors, + boolean logSentData, + boolean logResponseStatusText) { + this.platform = platform; + this.serverUuid = serverUuid; + this.serviceId = serviceId; + this.enabled = enabled; + this.appendPlatformDataConsumer = appendPlatformDataConsumer; + this.appendServiceDataConsumer = appendServiceDataConsumer; + this.submitTaskConsumer = submitTaskConsumer; + this.checkServiceEnabledSupplier = checkServiceEnabledSupplier; + this.errorLogger = errorLogger; + this.infoLogger = infoLogger; + this.logErrors = logErrors; + this.logSentData = logSentData; + this.logResponseStatusText = logResponseStatusText; + checkRelocation(); + if (enabled) { + startSubmitting(); + } + } + + public void addCustomChart(CustomChart chart) { + this.customCharts.add(chart); + } + + private void startSubmitting() { + final Runnable submitTask = + () -> { + if (!enabled || !checkServiceEnabledSupplier.get()) { + // Submitting data or service is disabled + scheduler.shutdown(); + return; + } + if (submitTaskConsumer != null) { + submitTaskConsumer.accept(this::submitData); + } else { + this.submitData(); + } + }; + // Many servers tend to restart at a fixed time at xx:00 which causes an uneven distribution + // of requests on the + // bStats backend. To circumvent this problem, we introduce some randomness into the initial + // and second delay. + // WARNING: You must not modify and part of this Metrics class, including the submit delay or + // frequency! + // WARNING: Modifying this code will get your plugin banned on bStats. Just don't do it! + long initialDelay = (long) (1000 * 60 * (3 + Math.random() * 3)); + long secondDelay = (long) (1000 * 60 * (Math.random() * 30)); + scheduler.schedule(submitTask, initialDelay, TimeUnit.MILLISECONDS); + scheduler.scheduleAtFixedRate( + submitTask, initialDelay + secondDelay, 1000 * 60 * 30, TimeUnit.MILLISECONDS); + } + + private void submitData() { + final JsonObjectBuilder baseJsonBuilder = new JsonObjectBuilder(); + appendPlatformDataConsumer.accept(baseJsonBuilder); + final JsonObjectBuilder serviceJsonBuilder = new JsonObjectBuilder(); + appendServiceDataConsumer.accept(serviceJsonBuilder); + JsonObjectBuilder.JsonObject[] chartData = + customCharts.stream() + .map(customChart -> customChart.getRequestJsonObject(errorLogger, logErrors)) + .filter(Objects::nonNull) + .toArray(JsonObjectBuilder.JsonObject[]::new); + serviceJsonBuilder.appendField("id", serviceId); + serviceJsonBuilder.appendField("customCharts", chartData); + baseJsonBuilder.appendField("service", serviceJsonBuilder.build()); + baseJsonBuilder.appendField("serverUUID", serverUuid); + baseJsonBuilder.appendField("metricsVersion", METRICS_VERSION); + JsonObjectBuilder.JsonObject data = baseJsonBuilder.build(); + scheduler.execute( + () -> { + try { + // Send the data + sendData(data); + } catch (Exception e) { + // Something went wrong! :( + if (logErrors) { + errorLogger.accept("Could not submit bStats metrics data", e); + } + } + }); + } + + private void sendData(JsonObjectBuilder.JsonObject data) throws Exception { + if (logSentData) { + infoLogger.accept("Sent bStats metrics data: " + data.toString()); + } + String url = String.format(REPORT_URL, platform); + HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection(); + // Compress the data to save bandwidth + byte[] compressedData = compress(data.toString()); + connection.setRequestMethod("POST"); + connection.addRequestProperty("Accept", "application/json"); + connection.addRequestProperty("Connection", "close"); + connection.addRequestProperty("Content-Encoding", "gzip"); + connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length)); + connection.setRequestProperty("Content-Type", "application/json"); + connection.setRequestProperty("User-Agent", "Metrics-Service/1"); + connection.setDoOutput(true); + try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { + outputStream.write(compressedData); + } + StringBuilder builder = new StringBuilder(); + try (BufferedReader bufferedReader = + new BufferedReader(new InputStreamReader(connection.getInputStream()))) { + String line; + while ((line = bufferedReader.readLine()) != null) { + builder.append(line); + } + } + if (logResponseStatusText) { + infoLogger.accept("Sent data to bStats and received response: " + builder); + } + } + + /** Checks that the class was properly relocated. */ + private void checkRelocation() { + // You can use the property to disable the check in your test environment + if (System.getProperty("bstats.relocatecheck") == null + || !System.getProperty("bstats.relocatecheck").equals("false")) { + // Maven's Relocate is clever and changes strings, too. So we have to use this little + // "trick" ... :D + final String defaultPackage = + new String(new byte[] {'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's'}); + final String examplePackage = + new String(new byte[] {'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'}); + // We want to make sure no one just copy & pastes the example and uses the wrong package + // names + if (MetricsBase.class.getPackage().getName().startsWith(defaultPackage) + || MetricsBase.class.getPackage().getName().startsWith(examplePackage)) { + throw new IllegalStateException("bStats Metrics class has not been relocated correctly!"); + } + } + } + + /** + * Gzips the given string. + * + * @param str The string to gzip. + * @return The gzipped string. + */ + private static byte[] compress(final String str) throws IOException { + if (str == null) { + return null; + } + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) { + gzip.write(str.getBytes(StandardCharsets.UTF_8)); + } + return outputStream.toByteArray(); + } + } + + public static class AdvancedBarChart extends CustomChart { + + private final Callable> callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public AdvancedBarChart(String chartId, Callable> callable) { + super(chartId); + this.callable = callable; + } + + @Override + protected JsonObjectBuilder.JsonObject getChartData() throws Exception { + JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean allSkipped = true; + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue().length == 0) { + // Skip this invalid + continue; + } + allSkipped = false; + valuesBuilder.appendField(entry.getKey(), entry.getValue()); + } + if (allSkipped) { + // Null = skip the chart + return null; + } + return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); + } + } + + public static class SimpleBarChart extends CustomChart { + + private final Callable> callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public SimpleBarChart(String chartId, Callable> callable) { + super(chartId); + this.callable = callable; + } + + @Override + protected JsonObjectBuilder.JsonObject getChartData() throws Exception { + JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + for (Map.Entry entry : map.entrySet()) { + valuesBuilder.appendField(entry.getKey(), new int[] {entry.getValue()}); + } + return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); + } + } + + public static class MultiLineChart extends CustomChart { + + private final Callable> callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public MultiLineChart(String chartId, Callable> callable) { + super(chartId); + this.callable = callable; + } + + @Override + protected JsonObjectBuilder.JsonObject getChartData() throws Exception { + JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean allSkipped = true; + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue() == 0) { + // Skip this invalid + continue; + } + allSkipped = false; + valuesBuilder.appendField(entry.getKey(), entry.getValue()); + } + if (allSkipped) { + // Null = skip the chart + return null; + } + return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); + } + } + + public static class AdvancedPie extends CustomChart { + + private final Callable> callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public AdvancedPie(String chartId, Callable> callable) { + super(chartId); + this.callable = callable; + } + + @Override + protected JsonObjectBuilder.JsonObject getChartData() throws Exception { + JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean allSkipped = true; + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue() == 0) { + // Skip this invalid + continue; + } + allSkipped = false; + valuesBuilder.appendField(entry.getKey(), entry.getValue()); + } + if (allSkipped) { + // Null = skip the chart + return null; + } + return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); + } + } + + public abstract static class CustomChart { + + private final String chartId; + + protected CustomChart(String chartId) { + if (chartId == null) { + throw new IllegalArgumentException("chartId must not be null"); + } + this.chartId = chartId; + } + + public JsonObjectBuilder.JsonObject getRequestJsonObject( + BiConsumer errorLogger, boolean logErrors) { + JsonObjectBuilder builder = new JsonObjectBuilder(); + builder.appendField("chartId", chartId); + try { + JsonObjectBuilder.JsonObject data = getChartData(); + if (data == null) { + // If the data is null we don't send the chart. + return null; + } + builder.appendField("data", data); + } catch (Throwable t) { + if (logErrors) { + errorLogger.accept("Failed to get data for custom chart with id " + chartId, t); + } + return null; + } + return builder.build(); + } + + protected abstract JsonObjectBuilder.JsonObject getChartData() throws Exception; + } + + public static class SingleLineChart extends CustomChart { + + private final Callable callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public SingleLineChart(String chartId, Callable callable) { + super(chartId); + this.callable = callable; + } + + @Override + protected JsonObjectBuilder.JsonObject getChartData() throws Exception { + int value = callable.call(); + if (value == 0) { + // Null = skip the chart + return null; + } + return new JsonObjectBuilder().appendField("value", value).build(); + } + } + + public static class SimplePie extends CustomChart { + + private final Callable callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public SimplePie(String chartId, Callable callable) { + super(chartId); + this.callable = callable; + } + + @Override + protected JsonObjectBuilder.JsonObject getChartData() throws Exception { + String value = callable.call(); + if (value == null || value.isEmpty()) { + // Null = skip the chart + return null; + } + return new JsonObjectBuilder().appendField("value", value).build(); + } + } + + public static class DrilldownPie extends CustomChart { + + private final Callable>> callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public DrilldownPie(String chartId, Callable>> callable) { + super(chartId); + this.callable = callable; + } + + @Override + public JsonObjectBuilder.JsonObject getChartData() throws Exception { + JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); + Map> map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean reallyAllSkipped = true; + for (Map.Entry> entryValues : map.entrySet()) { + JsonObjectBuilder valueBuilder = new JsonObjectBuilder(); + boolean allSkipped = true; + for (Map.Entry valueEntry : map.get(entryValues.getKey()).entrySet()) { + valueBuilder.appendField(valueEntry.getKey(), valueEntry.getValue()); + allSkipped = false; + } + if (!allSkipped) { + reallyAllSkipped = false; + valuesBuilder.appendField(entryValues.getKey(), valueBuilder.build()); + } + } + if (reallyAllSkipped) { + // Null = skip the chart + return null; + } + return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); + } + } + + /** + * An extremely simple JSON builder. + * + *

While this class is neither feature-rich nor the most performant one, it's sufficient enough + * for its use-case. + */ + public static class JsonObjectBuilder { + + private StringBuilder builder = new StringBuilder(); + + private boolean hasAtLeastOneField = false; + + public JsonObjectBuilder() { + builder.append("{"); + } + + /** + * Appends a null field to the JSON. + * + * @param key The key of the field. + * @return A reference to this object. + */ + public JsonObjectBuilder appendNull(String key) { + appendFieldUnescaped(key, "null"); + return this; + } + + /** + * Appends a string field to the JSON. + * + * @param key The key of the field. + * @param value The value of the field. + * @return A reference to this object. + */ + public JsonObjectBuilder appendField(String key, String value) { + if (value == null) { + throw new IllegalArgumentException("JSON value must not be null"); + } + appendFieldUnescaped(key, "\"" + escape(value) + "\""); + return this; + } + + /** + * Appends an integer field to the JSON. + * + * @param key The key of the field. + * @param value The value of the field. + * @return A reference to this object. + */ + public JsonObjectBuilder appendField(String key, int value) { + appendFieldUnescaped(key, String.valueOf(value)); + return this; + } + + /** + * Appends an object to the JSON. + * + * @param key The key of the field. + * @param object The object. + * @return A reference to this object. + */ + public JsonObjectBuilder appendField(String key, JsonObject object) { + if (object == null) { + throw new IllegalArgumentException("JSON object must not be null"); + } + appendFieldUnescaped(key, object.toString()); + return this; + } + + /** + * Appends a string array to the JSON. + * + * @param key The key of the field. + * @param values The string array. + * @return A reference to this object. + */ + public JsonObjectBuilder appendField(String key, String[] values) { + if (values == null) { + throw new IllegalArgumentException("JSON values must not be null"); + } + String escapedValues = + Arrays.stream(values) + .map(value -> "\"" + escape(value) + "\"") + .collect(Collectors.joining(",")); + appendFieldUnescaped(key, "[" + escapedValues + "]"); + return this; + } + + /** + * Appends an integer array to the JSON. + * + * @param key The key of the field. + * @param values The integer array. + * @return A reference to this object. + */ + public JsonObjectBuilder appendField(String key, int[] values) { + if (values == null) { + throw new IllegalArgumentException("JSON values must not be null"); + } + String escapedValues = + Arrays.stream(values).mapToObj(String::valueOf).collect(Collectors.joining(",")); + appendFieldUnescaped(key, "[" + escapedValues + "]"); + return this; + } + + /** + * Appends an object array to the JSON. + * + * @param key The key of the field. + * @param values The integer array. + * @return A reference to this object. + */ + public JsonObjectBuilder appendField(String key, JsonObject[] values) { + if (values == null) { + throw new IllegalArgumentException("JSON values must not be null"); + } + String escapedValues = + Arrays.stream(values).map(JsonObject::toString).collect(Collectors.joining(",")); + appendFieldUnescaped(key, "[" + escapedValues + "]"); + return this; + } + + /** + * Appends a field to the object. + * + * @param key The key of the field. + * @param escapedValue The escaped value of the field. + */ + private void appendFieldUnescaped(String key, String escapedValue) { + if (builder == null) { + throw new IllegalStateException("JSON has already been built"); + } + if (key == null) { + throw new IllegalArgumentException("JSON key must not be null"); + } + if (hasAtLeastOneField) { + builder.append(","); + } + builder.append("\"").append(escape(key)).append("\":").append(escapedValue); + hasAtLeastOneField = true; + } + + /** + * Builds the JSON string and invalidates this builder. + * + * @return The built JSON string. + */ + public JsonObject build() { + if (builder == null) { + throw new IllegalStateException("JSON has already been built"); + } + JsonObject object = new JsonObject(builder.append("}").toString()); + builder = null; + return object; + } + + /** + * Escapes the given string like stated in https://www.ietf.org/rfc/rfc4627.txt. + * + *

This method escapes only the necessary characters '"', '\'. and '\u0000' - '\u001F'. + * Compact escapes are not used (e.g., '\n' is escaped as "\u000a" and not as "\n"). + * + * @param value The value to escape. + * @return The escaped value. + */ + private static String escape(String value) { + final StringBuilder builder = new StringBuilder(); + for (int i = 0; i < value.length(); i++) { + char c = value.charAt(i); + if (c == '"') { + builder.append("\\\""); + } else if (c == '\\') { + builder.append("\\\\"); + } else if (c <= '\u000F') { + builder.append("\\u000").append(Integer.toHexString(c)); + } else if (c <= '\u001F') { + builder.append("\\u00").append(Integer.toHexString(c)); + } else { + builder.append(c); + } + } + return builder.toString(); + } + + /** + * A super simple representation of a JSON object. + * + *

This class only exists to make methods of the {@link JsonObjectBuilder} type-safe and not + * allow a raw string inputs for methods like {@link JsonObjectBuilder#appendField(String, + * JsonObject)}. + */ + public static class JsonObject { + + private final String value; + + private JsonObject(String value) { + this.value = value; + } + + @Override + public String toString() { + return value; + } + } + } +} diff --git a/src/main/java/net/t2code/alias/Spigot/Main.java b/src/main/java/net/t2code/alias/Spigot/Main.java new file mode 100644 index 0000000..f5a4f3b --- /dev/null +++ b/src/main/java/net/t2code/alias/Spigot/Main.java @@ -0,0 +1,70 @@ +package net.t2code.alias.Spigot; + +import net.t2code.alias.Spigot.objects.Alias_Objekt; +import net.t2code.alias.Spigot.system.Load; +import net.t2code.alias.Util; +import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate; +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.logging.Level; + +public final class Main extends JavaPlugin { + public static File getPath() { + return plugin.getDataFolder(); + } + + public static String prefix = Util.Prefix; + public static Integer spigotID = Util.SpigotID; + public static Integer bstatsID = Util.BstatsID; + public static String spigot = Util.Spigot; + public static String discord = Util.Discord; + + + public static String version; + public static List autor; + + public static Main plugin; + + public static HashMap aliasHashMap = new HashMap<>(); + public static ArrayList allAliases = new ArrayList<>(); + + @Override + public void onEnable() { + // Plugin startup logic + plugin = this; + autor = plugin.getDescription().getAuthors(); + version = plugin.getDescription().getVersion(); + isPlugin("T2CodeLib",96388); + Load.onLoad(prefix, autor, version, spigot, spigotID, discord, bstatsID); + } + + + public void saveConfig() { + if (!new File(getPath(), "config.yml").exists()) + plugin.saveResource("config.yml", false); + } + + @Override + public void onDisable() { + // Plugin shutdown logic + aliasHashMap.clear(); + allAliases.clear(); + if (Bukkit.getPluginManager().getPlugin("T2CodeLib") == null) return; + T2CodeTemplate.onDisable(prefix, autor, version, spigot, discord); + } + + public static void isPlugin(String pl, Integer spigotID) { + if (Bukkit.getPluginManager().getPlugin(pl) == null) { + plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!"); + Bukkit.getConsoleSender().sendMessage(prefix + " §e" + pl + " §4could not be found. Please download it here: " + + "§6https://spigotmc.org/resources/" + pl + "." + spigotID + " §4to be able to use this plugin."); + Main.plugin.getPluginLoader().disablePlugin(Main.plugin); + return; + } + } +} diff --git a/src/main/java/net/t2code/alias/Spigot/cmdManagement/Alias_CmdExecuter.java b/src/main/java/net/t2code/alias/Spigot/cmdManagement/Alias_CmdExecuter.java new file mode 100644 index 0000000..d0b15d3 --- /dev/null +++ b/src/main/java/net/t2code/alias/Spigot/cmdManagement/Alias_CmdExecuter.java @@ -0,0 +1,100 @@ +package net.t2code.alias.Spigot.cmdManagement; + +import net.t2code.alias.Spigot.Main; +import net.t2code.alias.Spigot.config.languages.SelectMessages; +import net.t2code.lib.Spigot.Lib.messages.send; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class Alias_CmdExecuter implements CommandExecutor, TabCompleter { + String Prefix; + + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Prefix = Main.prefix; + + if (args.length == 0) { + // Command + if (sender.hasPermission("t2code.alias.command.info")) { + Commands.info(sender); + } else send.sender(sender, SelectMessages.NoPermissionForCommand.replace("[cmd]", "/t2code-alias info") + .replace("[perm]", "t2code.alias.command.info")); + } else { + switch (args[0].toLowerCase()) { + case "reload": + case "rl": + if (sender.hasPermission("t2code.alias.command.reload") || sender.isOp()) { + Commands.reload(sender); + } else send.sender(sender, SelectMessages.NoPermissionForCommand.replace("[cmd]", "/t2code-alias reload") + .replace("[perm]", "t2code.alias.command.reload")); + break; + case "info": + case "plugin": + case "veraion": + if (sender.hasPermission("t2code.alias.command.info")) { + Commands.info(sender); + } else send.sender(sender, SelectMessages.NoPermissionForCommand.replace("[cmd]", "/t2code-alias info") + .replace("[perm]", "t2code.alias.command.info")); + break; + + } + } + return false; + } + + //TabCompleter + private static HashMap arg1 = new HashMap() {{ + put("reload", "t2code.alias.command.reload"); + put("rl", "t2code.alias.command.reload"); + put("info", "t2code.alias.command.info"); + }}; + + @Override + public List onTabComplete(CommandSender sender, Command cmd, String s, String[] args) { + List list = new ArrayList<>(); + if (sender instanceof Player) { + Player p = (Player) sender; + if (args.length == 1) { + for (String command : arg1.keySet()) { + Boolean passend = true; + for (int i = 0; i < args[0].length(); i++) { + if (args[0].length() >= command.length()) { + passend = false; + } else { + if (args[0].charAt(i) != command.charAt(i)) { + passend = false; + } + } + } + if (hasPermission(p, arg1.get(command)) && passend) { + list.add(command); + } + } + } + } + return list; + } + + public static boolean hasPermission(Player player, String permission) { + if (player.isOp()) { + return true; + } + String[] Permissions = permission.split(";"); + for (String perm : Permissions) { + if (player.hasPermission(perm)) { + return true; + } + } + return false; + } + +} + diff --git a/src/main/java/net/t2code/alias/Spigot/cmdManagement/Commands.java b/src/main/java/net/t2code/alias/Spigot/cmdManagement/Commands.java new file mode 100644 index 0000000..4e45ec0 --- /dev/null +++ b/src/main/java/net/t2code/alias/Spigot/cmdManagement/Commands.java @@ -0,0 +1,38 @@ +package net.t2code.alias.Spigot.cmdManagement; + +import net.t2code.alias.Spigot.Main; +import net.t2code.alias.Spigot.config.languages.SelectMessages; +import net.t2code.alias.Spigot.system.Load; +import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate; +import net.t2code.lib.Spigot.Lib.messages.send; +import net.t2code.lib.Spigot.Lib.update.UpdateAPI; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import java.util.List; + +public class Commands { + private static Plugin plugin = Main.plugin; + private static String prefix = Main.prefix; + private static List autor = Main.autor; + private static String version = Main.version; + private static String spigot = Main.spigot; + private static String discord = Main.discord; + + public static void info(CommandSender sender) { + T2CodeTemplate.sendInfo(sender,prefix,spigot,discord,autor,version, UpdateAPI.PluginVersionen.get(plugin.getName()).publicVersion); + } + + public static void reload(CommandSender sender) { + if (sender instanceof Player) sender.sendMessage(SelectMessages.ReloadStart); + send.console(prefix + "§8-------------------------------"); + send.console(prefix + " §6Plugin reload..."); + send.console(prefix + "§8-------------------------------"); + Load.loadReload(); + if (sender instanceof Player) sender.sendMessage(SelectMessages.ReloadEnd); + send.console(prefix + "§8-------------------------------"); + send.console(prefix + " §2Plugin successfully reloaded."); + send.console(prefix + "§8-------------------------------"); + } +} diff --git a/src/main/java/net/t2code/alias/Spigot/cmdManagement/RegisterCommands.java b/src/main/java/net/t2code/alias/Spigot/cmdManagement/RegisterCommands.java new file mode 100644 index 0000000..1e2665e --- /dev/null +++ b/src/main/java/net/t2code/alias/Spigot/cmdManagement/RegisterCommands.java @@ -0,0 +1,166 @@ +package net.t2code.alias.Spigot.cmdManagement; + +import net.md_5.bungee.api.chat.ClickEvent; +import net.t2code.alias.Spigot.Main; +import net.t2code.alias.Spigot.config.config.SelectConfig; +import net.t2code.alias.Spigot.config.languages.SelectMessages; +import net.t2code.alias.Spigot.objects.Alias_Objekt; +import net.t2code.alias.Spigot.system.*; +import net.t2code.lib.Spigot.Lib.commands.Cmd; +import net.t2code.lib.Spigot.Lib.messages.TextBuilder; +import net.t2code.lib.Spigot.Lib.messages.send; +import net.t2code.lib.Spigot.Lib.plugins.PluginCheck; +import net.t2code.lib.Spigot.Lib.replace.Replace; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class RegisterCommands extends Command { + private String alias; + private String prefix = Main.prefix; + + public RegisterCommands(String alias) { + super(alias); + this.alias = alias; + } + + @Override + public boolean execute(CommandSender sender, String commandLabel, String[] args) { + Alias_Objekt Alias = Main.aliasHashMap.get(alias); + + if (!Alias.AliasEnable) { + send.sender(sender, SelectMessages.AliasDisabled); + return true; + } + if (sender instanceof Player) { + Player player = (Player) sender; + + if (Alias.AdminEnable) { + if (player.hasPermission(Alias.AdminPermission)) { + if (Alias.AdminCommandEnable) { + for (String cmd : Alias.AdminCommands) { + if (Alias.AdminBungeeCommand) { + if (SelectConfig.Bungee) { + if (Alias.AdminCommandAsConsole) { + BCommand_Sender_Reciver.sendToBungee(player, cmd.replace("[player]", player.getName()), true); + } else BCommand_Sender_Reciver.sendToBungee(player, cmd.replace("[player]", player.getName()), false); + + } else { + send.console(Main.prefix + " §4To use bungee commands, enable the Bungee option in the config."); + send.player(player, Main.prefix + " §4To use bungee commands, enable the Bungee option in the config."); + } + } else { + if (Alias.AdminCommandAsConsole) { + Cmd.console(cmd.replace("[player]", player.getName())); + } else { + Cmd.player(player, cmd.replace("[player]", player.getName())); + } + } + } + } + if (Alias.AdminMessageEnable) { + for (String msg : Alias.AdminMessages) { + String text; + String hover; + if (PluginCheck.papi()) { + text = Replace.replace(prefix, player, msg); + hover = Replace.replace(prefix, player, Alias.AdminHover); + } else { + text = Replace.replace(prefix, msg); + hover = Replace.replace(prefix, Alias.AdminHover); + } + if (Alias.AdminTextBuilder) { + TextBuilder textBuilder = new TextBuilder(text); + textBuilder.addHover(hover); + if (Alias.AdminClickEvent) { + textBuilder.addClickEvent(ClickEvent.Action.valueOf(Alias.AdminAction), Alias.AdminActionValue); + } + player.spigot().sendMessage(textBuilder.build()); + } else { + send.player(player, text); + } + } + } + return true; + } + } + + if (Alias.Perm_necessary) { + if (!(player.hasPermission("t2code.alias.use." + alias.toLowerCase()) || player.hasPermission("t2code.alias.admin"))) { + send.player(player, SelectMessages.NoPermissionForCommand.replace("[cmd]", "/" + alias.toLowerCase()) + .replace("[perm]", "t2code.alias.use." + alias.toLowerCase())); + return true; + } + } + if (Alias.Command_Enable) { + for (String cmd : Alias.Command) { + if (Alias.BungeeCommand) { + if (SelectConfig.Bungee) { + if (Alias.CommandAsConsole) { + BCommand_Sender_Reciver.sendToBungee(player, cmd.replace("[player]", player.getName()), true); + } else BCommand_Sender_Reciver.sendToBungee(player, cmd.replace("[player]", player.getName()), false); + + } else { + send.console(Main.prefix + " §4To use bungee commands, enable the Bungee option in the config."); + send.player(player, Main.prefix + " §4To use bungee commands, enable the Bungee option in the config."); + } + } else { + if (Alias.CommandAsConsole) { + Cmd.console(cmd.replace("[player]", player.getName())); + } else { + Cmd.player(player, cmd.replace("[player]", player.getName())); + } + } + } + } + if (Alias.Message_Enable) { + for (String msg : Alias.Messages) { + String text; + String hover; + if (PluginCheck.papi()) { + text = Replace.replace(prefix, player, msg); + hover = Replace.replace(prefix,player,Alias.Hover); + } else{ + text = Replace.replace(prefix, msg); + hover = Replace.replace(prefix,Alias.Hover); + } + if (Alias.TextBuilder) { + TextBuilder textBuilder = new TextBuilder(text); + textBuilder.addHover(hover); + if (Alias.ClickEvent) { + textBuilder.addClickEvent(ClickEvent.Action.valueOf(Alias.Action), Alias.ActionValue); + } + player.spigot().sendMessage(textBuilder.build()); + } else { + send.player(player, text); + } + } + } + } else { + if (Alias.ConsoleEnable) { + if (Alias.ConsoleCommandEnable) { + for (String cmd : Alias.ConsoleCommands) { + if (Alias.ConsoleBungeeCommand) { + if (SelectConfig.Bungee) { + BCommand_Sender_Reciver.sendToBungee(sender, cmd.replace("[player]", sender.getName()), true); + } else { + send.console(Main.prefix + " §4To use bungee commands, enable the Bungee option in the config."); + send.sender(sender, Main.prefix + " §4To use bungee commands, enable the Bungee option in the config."); + } + } else { + Cmd.console(cmd.replace("[player]", sender.getName())); + } + + } + } + if (Alias.ConsoleMessageEnable) { + for (String msg : Alias.ConsoleMessages) { + send.console(Replace.replace(prefix, msg)); + } + } + } else send.sender(sender, SelectMessages.OnlyForPlayer); + } + return true; + } +} + diff --git a/src/main/java/net/t2code/alias/Spigot/config/config/CreateConfig.java b/src/main/java/net/t2code/alias/Spigot/config/config/CreateConfig.java new file mode 100644 index 0000000..a58104f --- /dev/null +++ b/src/main/java/net/t2code/alias/Spigot/config/config/CreateConfig.java @@ -0,0 +1,45 @@ +package net.t2code.alias.Spigot.config.config; + +import net.t2code.alias.Spigot.Main; +import net.t2code.lib.Spigot.Lib.messages.send; +import net.t2code.lib.Spigot.Lib.yamlConfiguration.Config; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; +import java.io.IOException; + +public class CreateConfig { + public static Integer ConfigVersion = 1; + private static Boolean UpdateCheckOnJoin = true; + private static String language = "english"; + + private static Boolean Bungee = false; + private static String thisServer = "server"; + + public static void configCreate() { + Long long_ = Long.valueOf(System.currentTimeMillis()); + if (new File(Main.getPath(), "config.yml").exists()) { + if (Main.plugin.getConfig().getBoolean("Plugin.Debug")) send.console(Main.prefix + " §5DEBUG: §6" + " §4config.yml are created / updated..."); + } else send.console(Main.prefix + " §4config.yml are created..."); + + + File config = new File(Main.getPath(), "config.yml"); + YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config); + + yamlConfiguration.set("ConfigVersion", ConfigVersion); + + Config.set("Plugin.UpdateCheckOnJoin", UpdateCheckOnJoin, yamlConfiguration); + Config.set("Plugin.language", language, yamlConfiguration); + + Config.set("BungeeCord.Enable", Bungee, yamlConfiguration); + Config.set("BungeeCord.ThisServer", thisServer, yamlConfiguration); + + + try { + yamlConfiguration.save(config); + } catch (IOException e) { + e.printStackTrace(); + } + send.console(Main.prefix + " §2config.yml were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms"); + } +} diff --git a/src/main/java/net/t2code/alias/Spigot/config/config/CreateExampleAliasConfig.java b/src/main/java/net/t2code/alias/Spigot/config/config/CreateExampleAliasConfig.java new file mode 100644 index 0000000..f4b5181 --- /dev/null +++ b/src/main/java/net/t2code/alias/Spigot/config/config/CreateExampleAliasConfig.java @@ -0,0 +1,111 @@ +package net.t2code.alias.Spigot.config.config; + +import net.t2code.alias.Spigot.Main; +import net.t2code.lib.Spigot.Lib.messages.send; +import net.t2code.lib.Spigot.Lib.yamlConfiguration.Config; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +public class CreateExampleAliasConfig { + + private static Boolean Enable = true; + private static Boolean PermNecessary = true; + + private static Boolean CommandEnable = true; + private static Boolean CommandAsConsole = true; + private static Boolean BungeeCommand = false; + private static List Commands = Arrays.asList("say hi"); + + private static Boolean MessageEnable = false; + private static List Messages = Arrays.asList(); + private static Boolean TextBuilder = false; + private static String Hover = ""; + private static Boolean ClickEvent = false; + private static String Action = ""; + private static String ActionValue = ""; + + private static Boolean AdminEnable = true; + private static String AdminPermission = "t2code.alias.admin"; + + private static Boolean AdminCommandEnable = true; + private static Boolean AdminCommandAsConsole = true; + private static Boolean AdminBungeeCommand = false; + private static List AdminCommands = Arrays.asList("say hi"); + + private static Boolean AdminMessageEnable = false; + private static List AdminMessages = Arrays.asList(); + private static Boolean AdminTextBuilder = false; + private static String AdminHover = ""; + private static Boolean AdminClickEvent = false; + private static String AdminAction = ""; + private static String AdminActionValue = ""; + + private static Boolean ConsoleEnable = false; + private static Boolean ConsoleCommandEnable = false; + private static Boolean ConsoleBungeeCommand = false; + private static List ConsoleCommands = Arrays.asList(); + private static Boolean ConsoleMessageEnable = false; + private static List ConsoleMessages = Arrays.asList(); + + public static void configCreate() { + Long long_ = Long.valueOf(System.currentTimeMillis()); + if (new File(Main.getPath(), "config.yml").exists()) { + if (Main.plugin.getConfig().getBoolean("Plugin.Debug")) send.console(Main.prefix + " §5DEBUG: §6" + " §4config.yml are created / updated..."); + } else send.console(Main.prefix + " §4config.yml are created..."); + + + File config = new File(Main.getPath(), "Alias/aliasexample.yml"); + YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config); + + + Config.set("Alias.Enable", Enable, yamlConfiguration); + Config.set("Alias.Permission.Necessary", PermNecessary, yamlConfiguration); + + Config.set("Alias.Command.Enable", CommandEnable, yamlConfiguration); + Config.set("Alias.Command.CommandAsConsole", CommandAsConsole, yamlConfiguration); + Config.set("Alias.Command.BungeeCommand", BungeeCommand, yamlConfiguration); + Config.set("Alias.Command.Commands", Commands, yamlConfiguration); + + Config.set("Alias.Message.Enable", MessageEnable, yamlConfiguration); + Config.set("Alias.Message.Messages", Messages, yamlConfiguration); + Config.set("Alias.Message.TextBuilder.Enable", TextBuilder, yamlConfiguration); + Config.set("Alias.Message.TextBuilder.Hover", Hover, yamlConfiguration); + Config.set("Alias.Message.TextBuilder.ClickEvent.Enable", ClickEvent, yamlConfiguration); + Config.set("Alias.Message.TextBuilder.ClickEvent.Action", Action, yamlConfiguration); + Config.set("Alias.Message.TextBuilder.ClickEvent.ActionValue", ActionValue, yamlConfiguration); + + + Config.set("Alias.Admin.Enable", AdminEnable, yamlConfiguration); + Config.set("Alias.Admin.Permission", AdminPermission, yamlConfiguration); + + Config.set("Alias.Admin.Command.Enable", AdminCommandEnable, yamlConfiguration); + Config.set("Alias.Admin.Command.CommandAsConsole", AdminCommandAsConsole, yamlConfiguration); + Config.set("Alias.Admin.Command.BungeeCommand", AdminBungeeCommand, yamlConfiguration); + Config.set("Alias.Admin.Command.Commands", AdminCommands, yamlConfiguration); + + Config.set("Alias.Admin.Message.Enable", AdminMessageEnable, yamlConfiguration); + Config.set("Alias.Admin.Message.Messages", AdminMessages, yamlConfiguration); + Config.set("Alias.Admin.Message.TextBuilder.Enable", AdminTextBuilder, yamlConfiguration); + Config.set("Alias.Admin.Message.TextBuilder.Hover", AdminHover, yamlConfiguration); + Config.set("Alias.Admin.Message.TextBuilder.ClickEvent.Enable", AdminClickEvent, yamlConfiguration); + Config.set("Alias.Admin.Message.TextBuilder.ClickEvent.Action", AdminAction, yamlConfiguration); + Config.set("Alias.Admin.Message.TextBuilder.ClickEvent.ActionValue", AdminActionValue, yamlConfiguration); + + Config.set("Alias.Console.Enable", ConsoleEnable, yamlConfiguration); + Config.set("Alias.Console.Command.Enable", ConsoleCommandEnable, yamlConfiguration); + Config.set("Alias.Console.Command.BungeeCommand", ConsoleBungeeCommand, yamlConfiguration); + Config.set("Alias.Console.Command.Commands", ConsoleCommands, yamlConfiguration); + Config.set("Alias.Console.Message.Enable", ConsoleMessageEnable, yamlConfiguration); + Config.set("Alias.Console.Message.Messages", ConsoleMessages, yamlConfiguration); + try { + yamlConfiguration.save(config); + } catch (IOException e) { + e.printStackTrace(); + } + send.console(Main.prefix + " §2config.yml were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms"); + } +} diff --git a/src/main/java/net/t2code/alias/Spigot/config/config/SelectAlias.java b/src/main/java/net/t2code/alias/Spigot/config/config/SelectAlias.java new file mode 100644 index 0000000..0280c59 --- /dev/null +++ b/src/main/java/net/t2code/alias/Spigot/config/config/SelectAlias.java @@ -0,0 +1,69 @@ +package net.t2code.alias.Spigot.config.config; + +import net.t2code.alias.Spigot.Main; +import net.t2code.alias.Spigot.system.AliasRegister; +import net.t2code.alias.Spigot.objects.Alias_Objekt; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; + +public class SelectAlias { + private static String Prefix = Main.prefix; + public static void onSelect() { + + Main.aliasHashMap.clear(); + Main.allAliases.clear(); + File f = new File(Main.getPath() + "/Alias/"); + File[] fileArray = f.listFiles(); + + for (File config_gui : fileArray) { + Main.allAliases.add(config_gui.getName().replace(".yml", "")); + String sub = config_gui.getName().substring(config_gui.getName().length() - 4); + if (sub.equals(".yml")) { + YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config_gui); + + Alias_Objekt alias = new Alias_Objekt( + yamlConfiguration.getBoolean("Alias.Enable"), + yamlConfiguration.getBoolean("Alias.Permission.Necessary"), + + yamlConfiguration.getBoolean("Alias.Command.Enable"), + yamlConfiguration.getBoolean("Alias.Command.CommandAsConsole"), + yamlConfiguration.getBoolean("Alias.Command.BungeeCommand"), + yamlConfiguration.getStringList("Alias.Command.Commands"), + + yamlConfiguration.getBoolean("Alias.Message.Enable"), + yamlConfiguration.getStringList("Alias.Message.Messages"), + yamlConfiguration.getBoolean("Alias.Message.TextBuilder.Enable"), + yamlConfiguration.getString("Alias.Message.TextBuilder.Hover"), + yamlConfiguration.getBoolean("Alias.Message.TextBuilder.ClickEvent.Enable"), + yamlConfiguration.getString("Alias.Message.TextBuilder.ClickEvent.Action"), + yamlConfiguration.getString("Alias.Message.TextBuilder.ClickEvent.ActionValue"), + + yamlConfiguration.getBoolean("Alias.Admin.Enable"), + yamlConfiguration.getString("Alias.Admin.Permission"), + + yamlConfiguration.getBoolean("Alias.Admin.Command.Enable"), + yamlConfiguration.getBoolean("Alias.Admin.Command.CommandAsConsole"), + yamlConfiguration.getBoolean("Alias.Admin.Command.BungeeCommand"), + yamlConfiguration.getStringList("Alias.Admin.Command.Commands"), + + yamlConfiguration.getBoolean("Alias.Admin.Message.Enable"), + yamlConfiguration.getStringList("Alias.Admin.Message.Messages"), + yamlConfiguration.getBoolean("Alias.Admin.Message.TextBuilder.Enable"), + yamlConfiguration.getString("Alias.Admin.Message.TextBuilder.Hover"), + yamlConfiguration.getBoolean("Alias.Admin.Message.TextBuilder.ClickEvent.Enable"), + yamlConfiguration.getString("Alias.Admin.Message.TextBuilder.ClickEvent.Action"), + yamlConfiguration.getString("Alias.Admin.Message.TextBuilder.ClickEvent.ActionValue"), + + yamlConfiguration.getBoolean("Alias.Console.Enable"), + yamlConfiguration.getBoolean("Alias.Console.Command.Enable"), + yamlConfiguration.getBoolean("Alias.Console.Command.BungeeCommand"), + yamlConfiguration.getStringList("Alias.Console.Command.Commands"), + yamlConfiguration.getBoolean("Alias.Console.Message.Enable"), + yamlConfiguration.getStringList("Alias.Console.Message.Messages")); + Main.aliasHashMap.put(config_gui.getName().replace(".yml", ""), alias); + AliasRegister.onRegister(); + } + } + } +} diff --git a/src/main/java/net/t2code/alias/Spigot/config/config/SelectConfig.java b/src/main/java/net/t2code/alias/Spigot/config/config/SelectConfig.java new file mode 100644 index 0000000..794b0ea --- /dev/null +++ b/src/main/java/net/t2code/alias/Spigot/config/config/SelectConfig.java @@ -0,0 +1,25 @@ +package net.t2code.alias.Spigot.config.config; + +import net.t2code.alias.Spigot.Main; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; + +public class SelectConfig { + public static Integer ConfigVersion; + public static Boolean UpdateCheckOnJoin; + public static String language; + public static Boolean Bungee; + public static String thisServer; + public static void onSelect() { + File config = new File(Main.getPath(), "config.yml"); + YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config); + + ConfigVersion =yamlConfiguration.getInt("ConfigVersion"); + + UpdateCheckOnJoin = yamlConfiguration.getBoolean("Plugin.UpdateCheckOnJoin"); + language = yamlConfiguration.getString("Plugin.language"); + Bungee = yamlConfiguration.getBoolean("BungeeCord.Enable"); + thisServer = yamlConfiguration.getString("BungeeCord.ThisServer"); + } +} diff --git a/src/main/java/net/t2code/alias/Spigot/config/languages/LanguagesCreate.java b/src/main/java/net/t2code/alias/Spigot/config/languages/LanguagesCreate.java new file mode 100644 index 0000000..839b940 --- /dev/null +++ b/src/main/java/net/t2code/alias/Spigot/config/languages/LanguagesCreate.java @@ -0,0 +1,92 @@ +package net.t2code.alias.Spigot.config.languages; + +import net.t2code.alias.Spigot.Main; +import net.t2code.lib.Spigot.Lib.messages.send; +import net.t2code.lib.Spigot.Lib.yamlConfiguration.Config; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.Plugin; + +import java.io.File; +import java.io.IOException; + +public class LanguagesCreate { + private static Plugin plugin = Main.plugin; + + public static void langCreate() { + send.debug(plugin,"§4Language files are created / updated..."); + Long long_ = Long.valueOf(System.currentTimeMillis()); + + /** + * + * ENGLISH + * + */ + + File messagesEN = new File(Main.getPath(), "languages/english_messages.yml"); + YamlConfiguration yamlConfigurationEN = YamlConfiguration.loadConfiguration(messagesEN); + + Config.set("Plugin.OnlyForPlayer", MSG.EN_OnlyForPlayer, yamlConfigurationEN); + Config.set("Plugin.AliasDisabled", MSG.EN_Disabled, yamlConfigurationEN); + Config.set("Plugin.Reload.Start", MSG.EN_ReloadStart, yamlConfigurationEN); + Config.set("Plugin.Reload.End", MSG.EN_ReloadEnd, yamlConfigurationEN); + Config.set("Plugin.ForCommand", MSG.EN_NoPermissionForCommand, yamlConfigurationEN); + + try { + yamlConfigurationEN.save(messagesEN); + } catch (IOException e) { + send.warning(plugin,e.getMessage()); + e.printStackTrace(); + } + + /** + * + * GERMAN + * + */ + + + File messagesDE = new File(Main.getPath(), "languages/german_messages.yml"); + YamlConfiguration yamlConfigurationDE = YamlConfiguration.loadConfiguration(messagesDE); + + Config.set("Plugin.OnlyForPlayer", MSG.DE_OnlyForPlayer, yamlConfigurationDE); + Config.set("Plugin.AliasDisabled", MSG.DE_Disabled, yamlConfigurationDE); + Config.set("Plugin.Reload.Start", MSG.DE_ReloadStart, yamlConfigurationDE); + Config.set("Plugin.Reload.End", MSG.DE_ReloadEnd, yamlConfigurationDE); + Config.set("Plugin.ForCommand", MSG.DE_NoPermissionForCommand, yamlConfigurationDE); + + try { + yamlConfigurationDE.save(messagesDE); + } catch (IOException e) { + send.warning(plugin,e.getMessage()); + e.printStackTrace(); + } + + + /** + * + * norwegian + * + */ + + + File messagesNO = new File(Main.getPath(), "languages/norwegian_messages.yml"); + YamlConfiguration yamlConfigurationNO = YamlConfiguration.loadConfiguration(messagesNO); + + Config.set("Plugin.OnlyForPlayer", MSG.NO_OnlyForPlayer, yamlConfigurationNO); + Config.set("Plugin.AliasDisabled", MSG.NO_Disabled, yamlConfigurationNO); + Config.set("Plugin.Reload.Start", MSG.NO_ReloadStart, yamlConfigurationNO); + Config.set("Plugin.Reload.End", MSG.NO_ReloadEnd, yamlConfigurationNO); + Config.set("Plugin.ForCommand", MSG.NO_NoPermissionForCommand, yamlConfigurationNO); + + try { + yamlConfigurationNO.save(messagesNO); + } catch (IOException e) { + send.warning(plugin,e.getMessage()); + e.printStackTrace(); + } + + + send.console(Main.prefix + " §2Language files were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms"); + } + +} diff --git a/src/main/java/net/t2code/alias/Spigot/config/languages/MSG.java b/src/main/java/net/t2code/alias/Spigot/config/languages/MSG.java new file mode 100644 index 0000000..47e3df4 --- /dev/null +++ b/src/main/java/net/t2code/alias/Spigot/config/languages/MSG.java @@ -0,0 +1,49 @@ +// This claas was created by JaTiTV + +// ----------------------------- +// _____ _____ _ _ _____ +// / ____/ ____| | | |_ _| +// | | | | __| | | | | | +// | | | | |_ | | | | | | +// | |___| |__| | |__| |_| |_ +// \_____\_____|\____/|_____| +// ----------------------------- + +package net.t2code.alias.Spigot.config.languages; + +public class MSG { + + // EN + + public static String EN_OnlyForPlayer = "[prefix] &cThis command is for players only!"; + + public static String EN_Disabled = "Unknown command. Type ''/help'' for help."; + + public static String EN_ReloadStart = "[prefix] &6Plugin is reloaded..."; + public static String EN_ReloadEnd = "[prefix] &2Plugin was successfully reloaded."; + + public static String EN_NoPermissionForCommand = "[prefix] &cFor &b[cmd] &cyou lack the permission &6[perm]&c!"; + + // DE + public static String DE_OnlyForPlayer = "[prefix] &cDieser Command ist nur f[ue]r Spieler!"; + + public static String DE_Disabled = "Unknown command. Type ''/help'' for help."; + + public static String DE_ReloadStart = "[prefix] &6Plugin wird neu geladen..."; + public static String DE_ReloadEnd = "[prefix] &2Plugin wurde erfolgreich neu geladen."; + + public static String DE_NoPermissionForCommand = "[prefix] &cF[ue]r &b[cmd] &cfehlt dir die Permission &6[perm]&c!"; + // FR + + + // NO + public static String NO_OnlyForPlayer = "[prefix] &cDenne kommandoen er for spillere kun!"; + + public static String NO_Disabled = "Unknown command. Type ''/help'' for help."; + + public static String NO_ReloadStart = "[prefix] &6Pluginet blir relastet..."; + public static String NO_ReloadEnd = "[prefix] &2Pluginet har blitt lastet inn på nytt."; + + public static String NO_NoPermissionForCommand = "[prefix] &cFor &b[cmd] &cmangler du tillatelsen &6[perm]&c!"; + +} diff --git a/src/main/java/net/t2code/alias/Spigot/config/languages/SelectMessages.java b/src/main/java/net/t2code/alias/Spigot/config/languages/SelectMessages.java new file mode 100644 index 0000000..d46948b --- /dev/null +++ b/src/main/java/net/t2code/alias/Spigot/config/languages/SelectMessages.java @@ -0,0 +1,52 @@ +package net.t2code.alias.Spigot.config.languages; + +import net.t2code.alias.Spigot.Main; +import net.t2code.alias.Spigot.config.config.SelectConfig; +import net.t2code.lib.Spigot.Lib.messages.send; +import net.t2code.lib.Spigot.Lib.yamlConfiguration.Config; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; + +public class SelectMessages { + private static String prefix = Main.prefix; + + public static String selectMSG; + + public static String OnlyForPlayer; + public static String ReloadStart; + public static String ReloadEnd; + + public static String NoPermissionForCommand; + public static String AliasDisabled; + + + public static void onSelect(String Prefix) { + + send.debug(Main.plugin, "§4Select language..."); + Long long_ = Long.valueOf(System.currentTimeMillis()); + + File msg; + + msg = new File(Main.getPath(), "languages/" + SelectConfig.language + "_messages.yml"); + if (!msg.isFile()) { + send.console(Prefix); + send.console(Prefix + " §4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + send.console(Prefix + " §4The selected §c" + SelectConfig.language + " §4language file was not found."); + send.console(Prefix + " §6The default language §eEnglish §6is used!"); + send.console(Prefix + " §4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + send.console(Prefix); + msg = new File(Main.getPath(), "languages/" + "english_messages.yml"); + selectMSG = "english"; + } else selectMSG = SelectConfig.language; + YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(msg); + + OnlyForPlayer = Config.select(prefix, "Plugin.OnlyForPlayer", yamlConfiguration); + AliasDisabled = Config.select(prefix, "Plugin.AliasDisabled", yamlConfiguration); + ReloadStart = Config.select(prefix, "Plugin.Reload.Start", yamlConfiguration); + ReloadEnd = Config.select(prefix, "Plugin.Reload.End", yamlConfiguration); + NoPermissionForCommand = Config.select(prefix, "Plugin.ForCommand", yamlConfiguration); + + send.console(Prefix + " §2Language successfully selected to: §6" + selectMSG + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms"); + } +} diff --git a/src/main/java/net/t2code/alias/Spigot/objects/Alias_Objekt.java b/src/main/java/net/t2code/alias/Spigot/objects/Alias_Objekt.java new file mode 100644 index 0000000..e716996 --- /dev/null +++ b/src/main/java/net/t2code/alias/Spigot/objects/Alias_Objekt.java @@ -0,0 +1,112 @@ +package net.t2code.alias.Spigot.objects; + +import java.util.List; + +public class Alias_Objekt { + public Boolean AliasEnable; + public Boolean Command_Enable; + public Boolean Perm_necessary; + + public Boolean CommandAsConsole; + public Boolean BungeeCommand; + public List Command; + public Boolean Message_Enable; + public List Messages; + public Boolean TextBuilder; + public String Hover; + public Boolean ClickEvent; + public String Action; + public String ActionValue; + + public Boolean AdminEnable; + public String AdminPermission; + public Boolean AdminCommandEnable; + public Boolean AdminCommandAsConsole; + public Boolean AdminBungeeCommand; + public List AdminCommands; + public Boolean AdminMessageEnable; + public List AdminMessages; + public Boolean AdminTextBuilder; + public String AdminHover; + public Boolean AdminClickEvent; + public String AdminAction; + public String AdminActionValue; + public Boolean ConsoleEnable; + public Boolean ConsoleCommandEnable; + public Boolean ConsoleBungeeCommand; + public List ConsoleCommands; + public Boolean ConsoleMessageEnable; + public List ConsoleMessages; + + public Alias_Objekt(Boolean AliasEnable, + Boolean Perm_necessary, + + Boolean Command_Enable, + Boolean CommandAsConsole, + Boolean BungeeCommand, + List Command, + Boolean Message_Enable, + List Messages, + Boolean TextBuilder, + String Hover, + Boolean ClickEvent, + String Action, + String ActionValue, + + Boolean AdminEnable, + String AdminPermission, + Boolean AdminCommandEnable, + Boolean AdminCommandAsConsole, + Boolean AdminBungeeCommand, + List AdminCommands, + Boolean AdminMessageEnable, + List AdminMessages, + Boolean AdminTextBuilder, + String AdminHover, + Boolean AdminClickEvent, + String AdminAction, + String AdminActionValue, + + Boolean ConsoleEnable, + Boolean ConsoleCommandEnable, + Boolean ConsoleBungeeCommand, + List ConsoleCommands, + Boolean ConsoleMessageEnable, + List ConsoleMessages) { + this.AliasEnable = AliasEnable; + this.Perm_necessary = Perm_necessary; + + this.Command_Enable = Command_Enable; + this.CommandAsConsole = CommandAsConsole; + this.BungeeCommand = BungeeCommand; + this.Command = Command; + this.Message_Enable = Message_Enable; + this.Messages = Messages; + this.TextBuilder = TextBuilder; + this.Hover = Hover; + this.ClickEvent = ClickEvent; + this.Action = Action; + this.ActionValue = ActionValue; + this.AdminEnable = AdminEnable; + this.AdminPermission = AdminPermission; + this.AdminCommandEnable = AdminCommandEnable; + this.AdminCommandAsConsole = AdminCommandAsConsole; + this.AdminBungeeCommand = AdminBungeeCommand; + this.AdminCommands = AdminCommands; + this.AdminMessageEnable = AdminMessageEnable; + this.AdminMessages = AdminMessages; + this.AdminTextBuilder = AdminTextBuilder; + this.AdminHover = AdminHover; + this.AdminClickEvent = AdminClickEvent; + this.AdminAction = AdminAction; + this.AdminActionValue = AdminActionValue; + + this.ConsoleEnable = ConsoleEnable; + this.ConsoleCommandEnable = ConsoleCommandEnable; + this.ConsoleBungeeCommand = ConsoleBungeeCommand; + this.ConsoleCommands = ConsoleCommands; + this.ConsoleMessageEnable = ConsoleMessageEnable; + this.ConsoleMessages = ConsoleMessages; + + } +} diff --git a/src/main/java/net/t2code/alias/Spigot/system/AliasRegister.java b/src/main/java/net/t2code/alias/Spigot/system/AliasRegister.java new file mode 100644 index 0000000..22a46bf --- /dev/null +++ b/src/main/java/net/t2code/alias/Spigot/system/AliasRegister.java @@ -0,0 +1,104 @@ +package net.t2code.alias.Spigot.system; + +import net.t2code.alias.Spigot.Main; +import net.t2code.alias.Spigot.cmdManagement.RegisterCommands; +import net.t2code.lib.Spigot.Lib.messages.send; +import net.t2code.lib.Spigot.Lib.minecraftVersion.NMSVersion; +import org.bukkit.plugin.Plugin; + +public class AliasRegister { + public static void onRegister() { + Plugin plugin = Main.plugin; + for (String alias : Main.allAliases) { + if (Main.aliasHashMap.get(alias) != null) { + if (Main.aliasHashMap.get(alias).AliasEnable) { + if (NMSVersion.v1_8_R1) { + send.debug(plugin, "Alias register 1.8_R1"); + org.bukkit.craftbukkit.v1_8_R1.CraftServer craftServer = (org.bukkit.craftbukkit.v1_8_R1.CraftServer) plugin.getServer(); + craftServer.getCommandMap().register(alias, new RegisterCommands(alias)); + } + if (NMSVersion.v1_8_R2) { + send.debug(plugin, "Alias register 1.8_R2"); + org.bukkit.craftbukkit.v1_8_R2.CraftServer craftServer = (org.bukkit.craftbukkit.v1_8_R2.CraftServer) plugin.getServer(); + craftServer.getCommandMap().register(alias, new RegisterCommands(alias)); + } + if (NMSVersion.v1_8_R3) { + send.debug(plugin, "Alias register 1.8_R3"); + org.bukkit.craftbukkit.v1_8_R3.CraftServer craftServer = (org.bukkit.craftbukkit.v1_8_R3.CraftServer) plugin.getServer(); + craftServer.getCommandMap().register(alias, new RegisterCommands(alias)); + } + if (NMSVersion.v1_9_R1) { + send.debug(plugin, "Alias register 1.9_R1"); + org.bukkit.craftbukkit.v1_9_R1.CraftServer craftServer = (org.bukkit.craftbukkit.v1_9_R1.CraftServer) plugin.getServer(); + craftServer.getCommandMap().register(alias, new RegisterCommands(alias)); + } + if (NMSVersion.v1_9_R2) { + send.debug(plugin, "Alias register 1.9_R2"); + org.bukkit.craftbukkit.v1_9_R2.CraftServer craftServer = (org.bukkit.craftbukkit.v1_9_R2.CraftServer) plugin.getServer(); + craftServer.getCommandMap().register(alias, new RegisterCommands(alias)); + } + if (NMSVersion.v1_10_R1) { + send.debug(plugin, "Alias register 1.10_R1"); + org.bukkit.craftbukkit.v1_10_R1.CraftServer craftServer = (org.bukkit.craftbukkit.v1_10_R1.CraftServer) plugin.getServer(); + craftServer.getCommandMap().register(alias, new RegisterCommands(alias)); + } + if (NMSVersion.v1_11_R1) { + send.debug(plugin, "Alias register 1.11_R1"); + org.bukkit.craftbukkit.v1_11_R1.CraftServer craftServer = (org.bukkit.craftbukkit.v1_11_R1.CraftServer) plugin.getServer(); + craftServer.getCommandMap().register(alias, new RegisterCommands(alias)); + } + if (NMSVersion.v1_12_R1) { + send.debug(plugin, "Alias register 1.12_R1"); + org.bukkit.craftbukkit.v1_12_R1.CraftServer craftServer = (org.bukkit.craftbukkit.v1_12_R1.CraftServer) plugin.getServer(); + craftServer.getCommandMap().register(alias, new RegisterCommands(alias)); + } + if (NMSVersion.v1_13_R1) { + send.debug(plugin, "Alias register 1.13_R1"); + org.bukkit.craftbukkit.v1_13_R1.CraftServer craftServer = (org.bukkit.craftbukkit.v1_13_R1.CraftServer) plugin.getServer(); + craftServer.getCommandMap().register(alias, new RegisterCommands(alias)); + } + if (NMSVersion.v1_13_R2) { + send.debug(plugin, "Alias register 1.13_R2"); + org.bukkit.craftbukkit.v1_13_R2.CraftServer craftServer = (org.bukkit.craftbukkit.v1_13_R2.CraftServer) plugin.getServer(); + craftServer.getCommandMap().register(alias, new RegisterCommands(alias)); + } + if (NMSVersion.v1_14_R1) { + send.debug(plugin, "Alias register 1.14_R1"); + org.bukkit.craftbukkit.v1_14_R1.CraftServer craftServer = (org.bukkit.craftbukkit.v1_14_R1.CraftServer) plugin.getServer(); + craftServer.getCommandMap().register(alias, new RegisterCommands(alias)); + } + if (NMSVersion.v1_15_R1) { + send.debug(plugin, "Alias register 1.15_R1"); + org.bukkit.craftbukkit.v1_15_R1.CraftServer craftServer = (org.bukkit.craftbukkit.v1_15_R1.CraftServer) plugin.getServer(); + craftServer.getCommandMap().register(alias, new RegisterCommands(alias)); + } + if (NMSVersion.v1_16_R1) { + send.debug(plugin, "Alias register 1.16_R1"); + org.bukkit.craftbukkit.v1_16_R1.CraftServer craftServer = (org.bukkit.craftbukkit.v1_16_R1.CraftServer) plugin.getServer(); + craftServer.getCommandMap().register(alias, new RegisterCommands(alias)); + } + if (NMSVersion.v1_16_R2) { + send.debug(plugin, "Alias register 1.16_R2"); + org.bukkit.craftbukkit.v1_16_R2.CraftServer craftServer = (org.bukkit.craftbukkit.v1_16_R2.CraftServer) plugin.getServer(); + craftServer.getCommandMap().register(alias, new RegisterCommands(alias)); + } + if (NMSVersion.v1_16_R3) { + send.debug(plugin, "Alias register 1.16_R3"); + org.bukkit.craftbukkit.v1_16_R3.CraftServer craftServer = (org.bukkit.craftbukkit.v1_16_R3.CraftServer) plugin.getServer(); + craftServer.getCommandMap().register(alias, new RegisterCommands(alias)); + } + if (NMSVersion.v1_17_R1) { + send.debug(plugin, "Alias register 1.17_R1"); + org.bukkit.craftbukkit.v1_17_R1.CraftServer craftServer = (org.bukkit.craftbukkit.v1_17_R1.CraftServer) plugin.getServer(); + craftServer.getCommandMap().register(alias, new RegisterCommands(alias)); + } + if (NMSVersion.v1_18_R1) { + send.debug(plugin, "Alias register 1.18_R1"); + org.bukkit.craftbukkit.v1_18_R1.CraftServer craftServer = (org.bukkit.craftbukkit.v1_18_R1.CraftServer) plugin.getServer(); + craftServer.getCommandMap().register(alias, new RegisterCommands(alias)); + } + } + } else send.warning(plugin, " §4AliasHashmap is null!"); + } + } +} diff --git a/src/main/java/net/t2code/alias/Spigot/system/Alias_RegisterPermissions.java b/src/main/java/net/t2code/alias/Spigot/system/Alias_RegisterPermissions.java new file mode 100644 index 0000000..f67cd3a --- /dev/null +++ b/src/main/java/net/t2code/alias/Spigot/system/Alias_RegisterPermissions.java @@ -0,0 +1,21 @@ +package net.t2code.alias.Spigot.system; + +import net.t2code.alias.Spigot.Main; +import net.t2code.lib.Spigot.Lib.register.Register; +import org.bukkit.Bukkit; +import org.bukkit.permissions.Permission; + +public class Alias_RegisterPermissions { + + public static void onPermRegister() { + for (String alias : Main.allAliases){ + if (Bukkit.getPluginManager().getPermission("t2code.alias.use." + alias.toLowerCase()) == null) { + Register.permission("t2code.alias.use." + alias.toLowerCase(), Main.plugin); + } + + //if (Bukkit.getPluginManager().getPermission(Main.aliasHashMap.get(alias).AdminPermission) == null){ + // Bukkit.getPluginManager().addPermission(new Permission(Main.aliasHashMap.get(alias).AdminPermission)); + //} + } + } +} \ No newline at end of file diff --git a/src/main/java/net/t2code/alias/Spigot/system/BCommand_Sender_Reciver.java b/src/main/java/net/t2code/alias/Spigot/system/BCommand_Sender_Reciver.java new file mode 100644 index 0000000..ce4e405 --- /dev/null +++ b/src/main/java/net/t2code/alias/Spigot/system/BCommand_Sender_Reciver.java @@ -0,0 +1,35 @@ +package net.t2code.alias.Spigot.system; + +import net.t2code.alias.Spigot.Main; +import net.t2code.lib.Spigot.Lib.messages.send; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +public class BCommand_Sender_Reciver { + + public static void sendToBungee(CommandSender sender, String information, Boolean console) { + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + DataOutputStream output = new DataOutputStream(stream); + try { + if (console){ + output.writeUTF("T2Code-Console"); + } else { + if (sender instanceof Player){ + output.writeUTF(sender.getName()); + } else { + output.writeUTF("T2Code-Console"); + } + } + output.writeUTF(information); + } catch (IOException e) { + e.printStackTrace(); + } + Bukkit.getServer().sendPluginMessage(Main.plugin, "t2codealias:bungee", stream.toByteArray()); + } + +} diff --git a/src/main/java/net/t2code/alias/Spigot/system/JoinEvent.java b/src/main/java/net/t2code/alias/Spigot/system/JoinEvent.java new file mode 100644 index 0000000..b2a18fc --- /dev/null +++ b/src/main/java/net/t2code/alias/Spigot/system/JoinEvent.java @@ -0,0 +1,34 @@ +// This claas was created by JaTiTV + +package net.t2code.alias.Spigot.system; + +import net.t2code.alias.Spigot.Main; +import net.t2code.lib.Spigot.Lib.messages.send; +import net.t2code.lib.Spigot.Lib.update.UpdateAPI; +import net.t2code.lib.Spigot.system.config.SelectLibConfig; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerLoginEvent; +import org.bukkit.scheduler.BukkitRunnable; + +public class JoinEvent implements Listener { + + @EventHandler + public void onJoinEvent(PlayerLoginEvent event) { + Player player = event.getPlayer(); + new BukkitRunnable() { + @Override + public void run() { + String publicVersion = UpdateAPI.PluginVersionen.get(Main.plugin.getName()).publicVersion; + if (player.hasPermission("alias.updatemsg") || player.isOp()) { + if (!Main.version.equals(publicVersion)) { + if (SelectLibConfig.UpdateCheckOnJoin) { + UpdateAPI.sendUpdateMsg(Main.prefix, Main.spigot, Main.discord, Main.version, publicVersion, player); + } + } + } + } + }.runTaskLater(Main.plugin, 200L); + } +} \ No newline at end of file diff --git a/src/main/java/net/t2code/alias/Spigot/system/Load.java b/src/main/java/net/t2code/alias/Spigot/system/Load.java new file mode 100644 index 0000000..1fa2fd5 --- /dev/null +++ b/src/main/java/net/t2code/alias/Spigot/system/Load.java @@ -0,0 +1,58 @@ +package net.t2code.alias.Spigot.system; + +import net.t2code.alias.Spigot.Main; +import net.t2code.alias.Spigot.cmdManagement.Alias_CmdExecuter; +import net.t2code.alias.Spigot.config.config.CreateConfig; +import net.t2code.alias.Spigot.config.config.CreateExampleAliasConfig; +import net.t2code.alias.Spigot.config.config.SelectAlias; +import net.t2code.alias.Spigot.config.config.SelectConfig; +import net.t2code.alias.Spigot.config.languages.LanguagesCreate; +import net.t2code.alias.Spigot.config.languages.SelectMessages; +import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate; +import net.t2code.lib.Spigot.Lib.update.UpdateAPI; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; + + +import java.io.File; +import java.util.List; + +public class Load { + static Plugin plugin = Main.plugin; + public static void onLoad(String prefix, List autor, String version, String spigot, int spigotID, String discord, int bstatsID) { + Long long_ = T2CodeTemplate.onLoadHeader(prefix, autor, version, spigot, discord); + Main.plugin.getCommand("alias").setExecutor(new Alias_CmdExecuter()); + loadReload(); + UpdateAPI.onUpdateCheck(plugin, prefix, spigot, spigotID, discord); + Bukkit.getServer().getPluginManager().registerEvents(new JoinEvent(), plugin); + + T2CodeTemplate.onLoadFooter(prefix, long_,version); + Metrics.Bstats(plugin, bstatsID); + } + + public static void loadReload() { + + if (!new File(Main.getPath(), "config.yml").exists()) { + try { + CreateExampleAliasConfig.configCreate(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + CreateConfig.configCreate(); + LanguagesCreate.langCreate(); + SelectConfig.onSelect(); + SelectMessages.onSelect(Main.prefix); + SelectAlias.onSelect(); + + if (SelectConfig.Bungee) { + Main.plugin.getServer().getMessenger().registerOutgoingPluginChannel(Main.plugin, "BungeeCord"); + Bukkit.getMessenger().registerOutgoingPluginChannel(Main.plugin, "t2codealias:bungee"); + } + Alias_RegisterPermissions.onPermRegister(); + + + } + +} diff --git a/src/main/java/net/t2code/alias/Spigot/system/Metrics.java b/src/main/java/net/t2code/alias/Spigot/system/Metrics.java new file mode 100644 index 0000000..d459b9a --- /dev/null +++ b/src/main/java/net/t2code/alias/Spigot/system/Metrics.java @@ -0,0 +1,854 @@ +// This claas was created by JaTiTV + + +package net.t2code.alias.Spigot.system; + +import net.t2code.alias.Spigot.Main; +import net.t2code.alias.Spigot.config.config.SelectConfig; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; + +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; + +import javax.net.ssl.HttpsURLConnection; +import java.io.*; +import java.lang.reflect.Method; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.concurrent.Callable; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import java.util.function.Supplier; +import java.util.logging.Level; +import java.util.stream.Collectors; +import java.util.zip.GZIPOutputStream; + +public class Metrics { + + public static void Bstats(Plugin plugin, int bstatsID) { + int pluginId = bstatsID; // <-- Replace with the id of your plugin! + Metrics metrics = new Metrics((JavaPlugin) plugin, pluginId); + metrics.addCustomChart(new SimplePie("updatecheckonjoin", () -> String.valueOf(SelectConfig.UpdateCheckOnJoin))); + } + + private final Plugin plugin; + + private final MetricsBase metricsBase; + + /** + * Creates a new Metrics instance. + * + * @param plugin Your plugin instance. + * @param serviceId The id of the service. It can be found at What is my plugin id? + */ + public Metrics(JavaPlugin plugin, int serviceId) { + this.plugin = plugin; + // Get the config file + File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats"); + File configFile = new File(bStatsFolder, "config.yml"); + YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); + if (!config.isSet("serverUuid")) { + config.addDefault("enabled", true); + config.addDefault("serverUuid", UUID.randomUUID().toString()); + config.addDefault("logFailedRequests", false); + config.addDefault("logSentData", false); + config.addDefault("logResponseStatusText", false); + // Inform the server owners about bStats + config + .options() + .header( + "bStats (https://bStats.org) collects some basic information for plugin authors, like how\n" + + "many people use their plugin and their total player count. It's recommended to keep bStats\n" + + "enabled, but if you're not comfortable with this, you can turn this setting off. There is no\n" + + "performance penalty associated with having metrics enabled, and data sent to bStats is fully\n" + + "anonymous.") + .copyDefaults(true); + try { + config.save(configFile); + } catch (IOException ignored) { + } + } + // Load the data + boolean enabled = config.getBoolean("enabled", true); + String serverUUID = config.getString("serverUuid"); + boolean logErrors = config.getBoolean("logFailedRequests", false); + boolean logSentData = config.getBoolean("logSentData", false); + boolean logResponseStatusText = config.getBoolean("logResponseStatusText", false); + metricsBase = + new MetricsBase( + "bukkit", + serverUUID, + serviceId, + enabled, + this::appendPlatformData, + this::appendServiceData, + submitDataTask -> Bukkit.getScheduler().runTask(plugin, submitDataTask), + plugin::isEnabled, + (message, error) -> this.plugin.getLogger().log(Level.WARNING, message, error), + (message) -> this.plugin.getLogger().log(Level.INFO, message), + logErrors, + logSentData, + logResponseStatusText); + } + + /** + * Adds a custom chart. + * + * @param chart The chart to add. + */ + public void addCustomChart(CustomChart chart) { + metricsBase.addCustomChart(chart); + } + + private void appendPlatformData(JsonObjectBuilder builder) { + builder.appendField("playerAmount", getPlayerAmount()); + builder.appendField("onlineMode", Bukkit.getOnlineMode() ? 1 : 0); + builder.appendField("bukkitVersion", Bukkit.getVersion()); + builder.appendField("bukkitName", Bukkit.getName()); + builder.appendField("javaVersion", System.getProperty("java.version")); + builder.appendField("osName", System.getProperty("os.name")); + builder.appendField("osArch", System.getProperty("os.arch")); + builder.appendField("osVersion", System.getProperty("os.version")); + builder.appendField("coreCount", Runtime.getRuntime().availableProcessors()); + } + + private void appendServiceData(JsonObjectBuilder builder) { + builder.appendField("pluginVersion", plugin.getDescription().getVersion()); + } + + private int getPlayerAmount() { + try { + // Around MC 1.8 the return type was changed from an array to a collection, + // This fixes java.lang.NoSuchMethodError: + // org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection; + Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers"); + return onlinePlayersMethod.getReturnType().equals(Collection.class) + ? ((Collection) onlinePlayersMethod.invoke(Bukkit.getServer())).size() + : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length; + } catch (Exception e) { + // Just use the new method if the reflection failed + return Bukkit.getOnlinePlayers().size(); + } + } + + public static class MetricsBase { + + /** + * The version of the Metrics class. + */ + public static final String METRICS_VERSION = "2.2.1"; + + private static final ScheduledExecutorService scheduler = + Executors.newScheduledThreadPool(1, task -> new Thread(task, "bStats-Metrics")); + + private static final String REPORT_URL = "https://bStats.org/api/v2/data/%s"; + + private final String platform; + + private final String serverUuid; + + private final int serviceId; + + private final Consumer appendPlatformDataConsumer; + + private final Consumer appendServiceDataConsumer; + + private final Consumer submitTaskConsumer; + + private final Supplier checkServiceEnabledSupplier; + + private final BiConsumer errorLogger; + + private final Consumer infoLogger; + + private final boolean logErrors; + + private final boolean logSentData; + + private final boolean logResponseStatusText; + + private final Set customCharts = new HashSet<>(); + + private final boolean enabled; + + /** + * Creates a new MetricsBase class instance. + * + * @param platform The platform of the service. + * @param serviceId The id of the service. + * @param serverUuid The server uuid. + * @param enabled Whether or not data sending is enabled. + * @param appendPlatformDataConsumer A consumer that receives a {@code JsonObjectBuilder} and + * appends all platform-specific data. + * @param appendServiceDataConsumer A consumer that receives a {@code JsonObjectBuilder} and + * appends all service-specific data. + * @param submitTaskConsumer A consumer that takes a runnable with the submit task. This can be + * used to delegate the data collection to a another thread to prevent errors caused by + * concurrency. Can be {@code null}. + * @param checkServiceEnabledSupplier A supplier to check if the service is still enabled. + * @param errorLogger A consumer that accepts log message and an error. + * @param infoLogger A consumer that accepts info log messages. + * @param logErrors Whether or not errors should be logged. + * @param logSentData Whether or not the sent data should be logged. + * @param logResponseStatusText Whether or not the response status text should be logged. + */ + public MetricsBase( + String platform, + String serverUuid, + int serviceId, + boolean enabled, + Consumer appendPlatformDataConsumer, + Consumer appendServiceDataConsumer, + Consumer submitTaskConsumer, + Supplier checkServiceEnabledSupplier, + BiConsumer errorLogger, + Consumer infoLogger, + boolean logErrors, + boolean logSentData, + boolean logResponseStatusText) { + this.platform = platform; + this.serverUuid = serverUuid; + this.serviceId = serviceId; + this.enabled = enabled; + this.appendPlatformDataConsumer = appendPlatformDataConsumer; + this.appendServiceDataConsumer = appendServiceDataConsumer; + this.submitTaskConsumer = submitTaskConsumer; + this.checkServiceEnabledSupplier = checkServiceEnabledSupplier; + this.errorLogger = errorLogger; + this.infoLogger = infoLogger; + this.logErrors = logErrors; + this.logSentData = logSentData; + this.logResponseStatusText = logResponseStatusText; + checkRelocation(); + if (enabled) { + startSubmitting(); + } + } + + public void addCustomChart(CustomChart chart) { + this.customCharts.add(chart); + } + + private void startSubmitting() { + final Runnable submitTask = + () -> { + if (!enabled || !checkServiceEnabledSupplier.get()) { + // Submitting data or service is disabled + scheduler.shutdown(); + return; + } + if (submitTaskConsumer != null) { + submitTaskConsumer.accept(this::submitData); + } else { + this.submitData(); + } + }; + // Many servers tend to restart at a fixed time at xx:00 which causes an uneven distribution + // of requests on the + // bStats backend. To circumvent this problem, we introduce some randomness into the initial + // and second delay. + // WARNING: You must not modify and part of this Metrics class, including the submit delay or + // frequency! + // WARNING: Modifying this code will get your plugin banned on bStats. Just don't do it! + long initialDelay = (long) (1000 * 60 * (3 + Math.random() * 3)); + long secondDelay = (long) (1000 * 60 * (Math.random() * 30)); + scheduler.schedule(submitTask, initialDelay, TimeUnit.MILLISECONDS); + scheduler.scheduleAtFixedRate( + submitTask, initialDelay + secondDelay, 1000 * 60 * 30, TimeUnit.MILLISECONDS); + } + + private void submitData() { + final JsonObjectBuilder baseJsonBuilder = new JsonObjectBuilder(); + appendPlatformDataConsumer.accept(baseJsonBuilder); + final JsonObjectBuilder serviceJsonBuilder = new JsonObjectBuilder(); + appendServiceDataConsumer.accept(serviceJsonBuilder); + JsonObjectBuilder.JsonObject[] chartData = + customCharts.stream() + .map(customChart -> customChart.getRequestJsonObject(errorLogger, logErrors)) + .filter(Objects::nonNull) + .toArray(JsonObjectBuilder.JsonObject[]::new); + serviceJsonBuilder.appendField("id", serviceId); + serviceJsonBuilder.appendField("customCharts", chartData); + baseJsonBuilder.appendField("service", serviceJsonBuilder.build()); + baseJsonBuilder.appendField("serverUUID", serverUuid); + baseJsonBuilder.appendField("metricsVersion", METRICS_VERSION); + JsonObjectBuilder.JsonObject data = baseJsonBuilder.build(); + scheduler.execute( + () -> { + try { + // Send the data + sendData(data); + } catch (Exception e) { + // Something went wrong! :( + if (logErrors) { + errorLogger.accept("Could not submit bStats metrics data", e); + } + } + }); + } + + private void sendData(JsonObjectBuilder.JsonObject data) throws Exception { + if (logSentData) { + infoLogger.accept("Sent bStats metrics data: " + data.toString()); + } + String url = String.format(REPORT_URL, platform); + HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection(); + // Compress the data to save bandwidth + byte[] compressedData = compress(data.toString()); + connection.setRequestMethod("POST"); + connection.addRequestProperty("Accept", "application/json"); + connection.addRequestProperty("Connection", "close"); + connection.addRequestProperty("Content-Encoding", "gzip"); + connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length)); + connection.setRequestProperty("Content-Type", "application/json"); + connection.setRequestProperty("User-Agent", "Metrics-Service/1"); + connection.setDoOutput(true); + try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { + outputStream.write(compressedData); + } + StringBuilder builder = new StringBuilder(); + try (BufferedReader bufferedReader = + new BufferedReader(new InputStreamReader(connection.getInputStream()))) { + String line; + while ((line = bufferedReader.readLine()) != null) { + builder.append(line); + } + } + if (logResponseStatusText) { + infoLogger.accept("Sent data to bStats and received response: " + builder); + } + } + + /** + * Checks that the class was properly relocated. + */ + private void checkRelocation() { + // You can use the property to disable the check in your test environment + if (System.getProperty("bstats.relocatecheck") == null + || !System.getProperty("bstats.relocatecheck").equals("false")) { + // Maven's Relocate is clever and changes strings, too. So we have to use this little + // "trick" ... :D + final String defaultPackage = + new String(new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's'}); + final String examplePackage = + new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'}); + // We want to make sure no one just copy & pastes the example and uses the wrong package + // names + if (MetricsBase.class.getPackage().getName().startsWith(defaultPackage) + || MetricsBase.class.getPackage().getName().startsWith(examplePackage)) { + throw new IllegalStateException("bStats Metrics class has not been relocated correctly!"); + } + } + } + + /** + * Gzips the given string. + * + * @param str The string to gzip. + * @return The gzipped string. + */ + private static byte[] compress(final String str) throws IOException { + if (str == null) { + return null; + } + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) { + gzip.write(str.getBytes(StandardCharsets.UTF_8)); + } + return outputStream.toByteArray(); + } + } + + public static class AdvancedBarChart extends CustomChart { + + private final Callable> callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public AdvancedBarChart(String chartId, Callable> callable) { + super(chartId); + this.callable = callable; + } + + @Override + protected JsonObjectBuilder.JsonObject getChartData() throws Exception { + JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean allSkipped = true; + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue().length == 0) { + // Skip this invalid + continue; + } + allSkipped = false; + valuesBuilder.appendField(entry.getKey(), entry.getValue()); + } + if (allSkipped) { + // Null = skip the chart + return null; + } + return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); + } + } + + public static class SimpleBarChart extends CustomChart { + + private final Callable> callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public SimpleBarChart(String chartId, Callable> callable) { + super(chartId); + this.callable = callable; + } + + @Override + protected JsonObjectBuilder.JsonObject getChartData() throws Exception { + JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + for (Map.Entry entry : map.entrySet()) { + valuesBuilder.appendField(entry.getKey(), new int[]{entry.getValue()}); + } + return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); + } + } + + public static class MultiLineChart extends CustomChart { + + private final Callable> callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public MultiLineChart(String chartId, Callable> callable) { + super(chartId); + this.callable = callable; + } + + @Override + protected JsonObjectBuilder.JsonObject getChartData() throws Exception { + JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean allSkipped = true; + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue() == 0) { + // Skip this invalid + continue; + } + allSkipped = false; + valuesBuilder.appendField(entry.getKey(), entry.getValue()); + } + if (allSkipped) { + // Null = skip the chart + return null; + } + return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); + } + } + + public static class AdvancedPie extends CustomChart { + + private final Callable> callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public AdvancedPie(String chartId, Callable> callable) { + super(chartId); + this.callable = callable; + } + + @Override + protected JsonObjectBuilder.JsonObject getChartData() throws Exception { + JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean allSkipped = true; + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue() == 0) { + // Skip this invalid + continue; + } + allSkipped = false; + valuesBuilder.appendField(entry.getKey(), entry.getValue()); + } + if (allSkipped) { + // Null = skip the chart + return null; + } + return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); + } + } + + public abstract static class CustomChart { + + private final String chartId; + + protected CustomChart(String chartId) { + if (chartId == null) { + throw new IllegalArgumentException("chartId must not be null"); + } + this.chartId = chartId; + } + + public JsonObjectBuilder.JsonObject getRequestJsonObject( + BiConsumer errorLogger, boolean logErrors) { + JsonObjectBuilder builder = new JsonObjectBuilder(); + builder.appendField("chartId", chartId); + try { + JsonObjectBuilder.JsonObject data = getChartData(); + if (data == null) { + // If the data is null we don't send the chart. + return null; + } + builder.appendField("data", data); + } catch (Throwable t) { + if (logErrors) { + errorLogger.accept("Failed to get data for custom chart with id " + chartId, t); + } + return null; + } + return builder.build(); + } + + protected abstract JsonObjectBuilder.JsonObject getChartData() throws Exception; + } + + public static class SingleLineChart extends CustomChart { + + private final Callable callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public SingleLineChart(String chartId, Callable callable) { + super(chartId); + this.callable = callable; + } + + @Override + protected JsonObjectBuilder.JsonObject getChartData() throws Exception { + int value = callable.call(); + if (value == 0) { + // Null = skip the chart + return null; + } + return new JsonObjectBuilder().appendField("value", value).build(); + } + } + + public static class SimplePie extends CustomChart { + + private final Callable callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public SimplePie(String chartId, Callable callable) { + super(chartId); + this.callable = callable; + } + + @Override + protected JsonObjectBuilder.JsonObject getChartData() throws Exception { + String value = callable.call(); + if (value == null || value.isEmpty()) { + // Null = skip the chart + return null; + } + return new JsonObjectBuilder().appendField("value", value).build(); + } + } + + public static class DrilldownPie extends CustomChart { + + private final Callable>> callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public DrilldownPie(String chartId, Callable>> callable) { + super(chartId); + this.callable = callable; + } + + @Override + public JsonObjectBuilder.JsonObject getChartData() throws Exception { + JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); + Map> map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean reallyAllSkipped = true; + for (Map.Entry> entryValues : map.entrySet()) { + JsonObjectBuilder valueBuilder = new JsonObjectBuilder(); + boolean allSkipped = true; + for (Map.Entry valueEntry : map.get(entryValues.getKey()).entrySet()) { + valueBuilder.appendField(valueEntry.getKey(), valueEntry.getValue()); + allSkipped = false; + } + if (!allSkipped) { + reallyAllSkipped = false; + valuesBuilder.appendField(entryValues.getKey(), valueBuilder.build()); + } + } + if (reallyAllSkipped) { + // Null = skip the chart + return null; + } + return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); + } + } + + /** + * An extremely simple JSON builder. + * + *

While this class is neither feature-rich nor the most performant one, it's sufficient enough + * for its use-case. + */ + public static class JsonObjectBuilder { + + private StringBuilder builder = new StringBuilder(); + + private boolean hasAtLeastOneField = false; + + public JsonObjectBuilder() { + builder.append("{"); + } + + /** + * Appends a null field to the JSON. + * + * @param key The key of the field. + * @return A reference to this object. + */ + public JsonObjectBuilder appendNull(String key) { + appendFieldUnescaped(key, "null"); + return this; + } + + /** + * Appends a string field to the JSON. + * + * @param key The key of the field. + * @param value The value of the field. + * @return A reference to this object. + */ + public JsonObjectBuilder appendField(String key, String value) { + if (value == null) { + throw new IllegalArgumentException("JSON value must not be null"); + } + appendFieldUnescaped(key, "\"" + escape(value) + "\""); + return this; + } + + /** + * Appends an integer field to the JSON. + * + * @param key The key of the field. + * @param value The value of the field. + * @return A reference to this object. + */ + public JsonObjectBuilder appendField(String key, int value) { + appendFieldUnescaped(key, String.valueOf(value)); + return this; + } + + /** + * Appends an object to the JSON. + * + * @param key The key of the field. + * @param object The object. + * @return A reference to this object. + */ + public JsonObjectBuilder appendField(String key, JsonObject object) { + if (object == null) { + throw new IllegalArgumentException("JSON object must not be null"); + } + appendFieldUnescaped(key, object.toString()); + return this; + } + + /** + * Appends a string array to the JSON. + * + * @param key The key of the field. + * @param values The string array. + * @return A reference to this object. + */ + public JsonObjectBuilder appendField(String key, String[] values) { + if (values == null) { + throw new IllegalArgumentException("JSON values must not be null"); + } + String escapedValues = + Arrays.stream(values) + .map(value -> "\"" + escape(value) + "\"") + .collect(Collectors.joining(",")); + appendFieldUnescaped(key, "[" + escapedValues + "]"); + return this; + } + + /** + * Appends an integer array to the JSON. + * + * @param key The key of the field. + * @param values The integer array. + * @return A reference to this object. + */ + public JsonObjectBuilder appendField(String key, int[] values) { + if (values == null) { + throw new IllegalArgumentException("JSON values must not be null"); + } + String escapedValues = + Arrays.stream(values).mapToObj(String::valueOf).collect(Collectors.joining(",")); + appendFieldUnescaped(key, "[" + escapedValues + "]"); + return this; + } + + /** + * Appends an object array to the JSON. + * + * @param key The key of the field. + * @param values The integer array. + * @return A reference to this object. + */ + public JsonObjectBuilder appendField(String key, JsonObject[] values) { + if (values == null) { + throw new IllegalArgumentException("JSON values must not be null"); + } + String escapedValues = + Arrays.stream(values).map(JsonObject::toString).collect(Collectors.joining(",")); + appendFieldUnescaped(key, "[" + escapedValues + "]"); + return this; + } + + /** + * Appends a field to the object. + * + * @param key The key of the field. + * @param escapedValue The escaped value of the field. + */ + private void appendFieldUnescaped(String key, String escapedValue) { + if (builder == null) { + throw new IllegalStateException("JSON has already been built"); + } + if (key == null) { + throw new IllegalArgumentException("JSON key must not be null"); + } + if (hasAtLeastOneField) { + builder.append(","); + } + builder.append("\"").append(escape(key)).append("\":").append(escapedValue); + hasAtLeastOneField = true; + } + + /** + * Builds the JSON string and invalidates this builder. + * + * @return The built JSON string. + */ + public JsonObject build() { + if (builder == null) { + throw new IllegalStateException("JSON has already been built"); + } + JsonObject object = new JsonObject(builder.append("}").toString()); + builder = null; + return object; + } + + /** + * Escapes the given string like stated in https://www.ietf.org/rfc/rfc4627.txt. + * + *

This method escapes only the necessary characters '"', '\'. and '\u0000' - '\u001F'. + * Compact escapes are not used (e.g., '\n' is escaped as "\u000a" and not as "\n"). + * + * @param value The value to escape. + * @return The escaped value. + */ + private static String escape(String value) { + final StringBuilder builder = new StringBuilder(); + for (int i = 0; i < value.length(); i++) { + char c = value.charAt(i); + if (c == '"') { + builder.append("\\\""); + } else if (c == '\\') { + builder.append("\\\\"); + } else if (c <= '\u000F') { + builder.append("\\u000").append(Integer.toHexString(c)); + } else if (c <= '\u001F') { + builder.append("\\u00").append(Integer.toHexString(c)); + } else { + builder.append(c); + } + } + return builder.toString(); + } + + /** + * A super simple representation of a JSON object. + * + *

This class only exists to make methods of the {@link JsonObjectBuilder} type-safe and not + * allow a raw string inputs for methods like {@link JsonObjectBuilder#appendField(String, + * JsonObject)}. + */ + public static class JsonObject { + + private final String value; + + private JsonObject(String value) { + this.value = value; + } + + @Override + public String toString() { + return value; + } + } + } +} \ No newline at end of file diff --git a/src/main/java/net/t2code/alias/Spigot/system/UpdateChecker.java b/src/main/java/net/t2code/alias/Spigot/system/UpdateChecker.java new file mode 100644 index 0000000..8906c53 --- /dev/null +++ b/src/main/java/net/t2code/alias/Spigot/system/UpdateChecker.java @@ -0,0 +1,116 @@ +// This claas was created by JaTiTV + +package net.t2code.alias.Spigot.system; + +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.TextComponent; +import net.t2code.alias.Spigot.Main; +import net.t2code.lib.Spigot.Lib.messages.TextBuilder; +import net.t2code.lib.Spigot.Lib.messages.send; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Scanner; +import java.util.function.Consumer; + +public class UpdateChecker { + + public static void sendUpdateMsg(String Prefix, String foundVersion, String update_version) { + send.console("§4=========== " + Prefix + " §4==========="); + send.console("§6A new version was found!"); + send.console("§6Your version: §c" + foundVersion + " §7- §6Current version: §a" + update_version); + send.console("§6You can download it here: §e" + Main.spigot); + send.console("§6You can find more information on Discord: §e" + Main.discord); + send.console("§4=========== " + Prefix + " §4==========="); + } + + public static void sendUpdateMsg(String Prefix, String foundVersion, String update_version, Player player) { + TextComponent comp = new TextBuilder(Prefix + " §6A new version was found!") + .addHover("§6You can download it here: §e" + Main.spigot).addClickEvent(ClickEvent.Action.OPEN_URL, Main.spigot).build(); + player.spigot().sendMessage(comp); + TextComponent comp1 = new TextBuilder(Prefix + " §c" + foundVersion + " §7-> §a" + update_version) + .addHover("§6You can download it here: §e" + Main.spigot).addClickEvent(ClickEvent.Action.OPEN_URL, Main.spigot).build(); + player.spigot().sendMessage(comp1); + TextComponent comp2 = new TextBuilder(Prefix + " §6You can find more information on Discord.") + .addHover("§e" + Main.discord).addClickEvent(ClickEvent.Action.OPEN_URL, Main.discord).build(); + player.spigot().sendMessage(comp2); + } + + private static Boolean noUpdate = true; + public static void onUpdateCheck() { + int taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.plugin, new Runnable() { + public void run() { + (new UpdateChecker(Main.plugin, Main.spigotID)).getVersion((update_version) -> { + String foundVersion = Main.plugin.getDescription().getVersion(); + // Main.update_version = update_version; + if (!foundVersion.equalsIgnoreCase(update_version)) { + new BukkitRunnable() { + @Override + public void run() { + sendUpdateMsg(Main.prefix, foundVersion, update_version); + } + }.runTaskLater(Main.plugin, 600L); + }else { + if (noUpdate) { + send.console(Main.prefix + " §2No update found."); + noUpdate = false; + } + } + }); + } + }, 0L, 20 * 60 * 60L); + } + + private JavaPlugin plugin; + private int resourceId; + + public UpdateChecker(JavaPlugin plugin, int resourceId) { + this.plugin = plugin; + this.resourceId = resourceId; + } + + public void getVersion(Consumer consumer) { + Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> { + try { + InputStream inputStream = (new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId)).openStream(); + try { + Scanner scanner = new Scanner(inputStream); + + try { + if (scanner.hasNext()) { + consumer.accept(scanner.next()); + } + } catch (Throwable var8) { + try { + scanner.close(); + } catch (Throwable var7) { + var8.addSuppressed(var7); + } + throw var8; + } + scanner.close(); + } catch (Throwable var9) { + if (inputStream != null) { + try { + inputStream.close(); + } catch (Throwable var6) { + var9.addSuppressed(var6); + } + } + throw var9; + } + if (inputStream != null) { + inputStream.close(); + } + } catch (IOException var10) { + // Main.update_version = " §4No public version found!"; + this.plugin.getLogger().severe(Main.prefix + "§4 Cannot look for updates: " + var10.getMessage()); + } + }); + } +} diff --git a/src/main/java/net/t2code/alias/Util.java b/src/main/java/net/t2code/alias/Util.java new file mode 100644 index 0000000..c5c6b06 --- /dev/null +++ b/src/main/java/net/t2code/alias/Util.java @@ -0,0 +1,9 @@ +package net.t2code.alias; + +public class Util { + public static String Prefix = "§8[§4T2Code§7-§aAlias§8]"; + public static Integer SpigotID = 96389; + public static Integer BstatsID = 12517; + public static String Spigot = "https://www.spigotmc.org/resources/" + SpigotID; + public static String Discord = "http://dc.t2code.net"; +} diff --git a/src/main/resources/bungee.yml b/src/main/resources/bungee.yml new file mode 100644 index 0000000..e5345e8 --- /dev/null +++ b/src/main/resources/bungee.yml @@ -0,0 +1,6 @@ +name: T2C-Alias +version: ${project.version} +main: net.t2code.alias.Bungee.BMain +description: T2Code Alias Plugin +author: JaTiTV +softdepends: [T2CodeLib] diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..377effa --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,32 @@ +name: T2C-Alias +version: ${project.version} +main: net.t2code.alias.Spigot.Main +api-version: 1.13 + +prefix: T2Code-Alias +authors: [ JaTiTV ] +description: T2Code Alias Plugin +website: https://spigotmc.org/resources/t2c-alias.96389/ +softdepend: [T2CodeLib] + + +commands: + t2code-alias: + description: Alias main Command. + aliases: [t2c-a, alias] + +permissions: + t2code.alias.admin: + default: op + children: + t2code.alias.updatemsg: true + t2code.alias.command.reload: true + t2code.alias.command.info: true + + + t2code.alias.updatemsg: + default: op + t2code.alias.command.reload: + default: op + t2code.alias.command.info: + default: op