Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
4c57fec686 | |||
b84d0dc02b | |||
e0f9eb6f58 | |||
edddd93850 | |||
f2ab07e4c2 | |||
60edfc7dc1 |
20
pom.xml
20
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>net.t2code</groupId>
|
||||
<artifactId>AutoResponse</artifactId>
|
||||
<version>0.2.0</version>
|
||||
<version>1.4_dev-1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>T2C-AutoResponse</name>
|
||||
@@ -18,14 +18,15 @@
|
||||
<url>git.t2code.net</url>
|
||||
|
||||
<build>
|
||||
<finalName>${project.name}_${project.version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
<source>11</source>
|
||||
<target>11</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
@@ -65,20 +66,31 @@
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<!-- repo.t2code / T2Code -->
|
||||
<dependency>
|
||||
<groupId>net.t2code.minecraft.1_8.r1</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.8r1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.t2code</groupId>
|
||||
<artifactId>T2CodeLib</artifactId>
|
||||
<version>12.5</version>
|
||||
<version>16.7</version>
|
||||
<classifier>dev-24</classifier>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.t2code</groupId>
|
||||
<artifactId>bungee</artifactId>
|
||||
<version>1615</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.30</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@@ -1,40 +0,0 @@
|
||||
package net.t2code.autoresponse.Bungee;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.t2code.autoresponse.Bungee.system.BLoad;
|
||||
import net.t2code.autoresponse.Util;
|
||||
import net.t2code.lib.Bungee.Lib.messages.BT2CodeTemplate;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public final class BMain extends Plugin {
|
||||
|
||||
|
||||
private static Plugin plugin;
|
||||
private static String version;
|
||||
private static String autor;
|
||||
|
||||
@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(Util.getPrefix() + " §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, Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord(), Util.getSpigotID(), Util.getBstatsID());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
if (ProxyServer.getInstance().getPluginManager().getPlugin("T2CodeLib") == null) return;
|
||||
BT2CodeTemplate.onDisable(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
|
||||
}
|
||||
}
|
@@ -1,48 +0,0 @@
|
||||
package net.t2code.autoresponse.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 net.t2code.lib.Bungee.Lib.messages.Bsend;
|
||||
|
||||
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("t2car:bungee")) {
|
||||
DataInputStream stream = new DataInputStream(new ByteArrayInputStream(event.getData()));
|
||||
event.setCancelled(true);
|
||||
try {
|
||||
String channel = stream.readUTF();
|
||||
String input = stream.readUTF();
|
||||
|
||||
switch (channel) {
|
||||
case "ConC":
|
||||
ProxyServer.getInstance().getConsole().sendMessage("Command Console: " + input);
|
||||
ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getConsole(), input);
|
||||
break;
|
||||
case "ALLPMSG":
|
||||
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
|
||||
Bsend.player(player, input);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(channel);
|
||||
if (player != null) {
|
||||
ProxyServer.getInstance().getConsole().sendMessage("Command " + player + ": " + input);
|
||||
ProxyServer.getInstance().getPluginManager().dispatchCommand(player, input);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
package net.t2code.autoresponse.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("t2car:bungee");
|
||||
Bsend.console(prefix + " registerChannel(t2car: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_);
|
||||
}
|
||||
}
|
@@ -1,846 +0,0 @@
|
||||
package net.t2code.autoresponse.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 <a
|
||||
* href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
|
||||
*/
|
||||
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<JsonObjectBuilder> appendPlatformDataConsumer;
|
||||
|
||||
private final Consumer<JsonObjectBuilder> appendServiceDataConsumer;
|
||||
|
||||
private final Consumer<Runnable> submitTaskConsumer;
|
||||
|
||||
private final Supplier<Boolean> checkServiceEnabledSupplier;
|
||||
|
||||
private final BiConsumer<String, Throwable> errorLogger;
|
||||
|
||||
private final Consumer<String> infoLogger;
|
||||
|
||||
private final boolean logErrors;
|
||||
|
||||
private final boolean logSentData;
|
||||
|
||||
private final boolean logResponseStatusText;
|
||||
|
||||
private final Set<CustomChart> 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<JsonObjectBuilder> appendPlatformDataConsumer,
|
||||
Consumer<JsonObjectBuilder> appendServiceDataConsumer,
|
||||
Consumer<Runnable> submitTaskConsumer,
|
||||
Supplier<Boolean> checkServiceEnabledSupplier,
|
||||
BiConsumer<String, Throwable> errorLogger,
|
||||
Consumer<String> 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<Map<String, int[]>> 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<Map<String, int[]>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||
Map<String, int[]> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, int[]> 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<Map<String, Integer>> 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<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
for (Map.Entry<String, Integer> 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<Map<String, Integer>> 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<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> 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<Map<String, Integer>> 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<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> 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<String, Throwable> 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<Integer> 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<Integer> 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<String> 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<String> 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<Map<String, Map<String, Integer>>> 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<Map<String, Map<String, Integer>>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||
Map<String, Map<String, Integer>> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean reallyAllSkipped = true;
|
||||
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
|
||||
JsonObjectBuilder valueBuilder = new JsonObjectBuilder();
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> 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.
|
||||
*
|
||||
* <p>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.
|
||||
*
|
||||
* <p>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.
|
||||
*
|
||||
* <p>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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,7 +3,8 @@ package net.t2code.autoresponse.Spigot;
|
||||
import net.t2code.autoresponse.Spigot.objects.ResponsesObject;
|
||||
import net.t2code.autoresponse.Spigot.system.Load;
|
||||
import net.t2code.autoresponse.Util;
|
||||
import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate;
|
||||
|
||||
import net.t2code.t2codelib.SPIGOT.api.messages.T2C_Template;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@@ -34,7 +35,6 @@ public final class Main extends JavaPlugin {
|
||||
version = plugin.getDescription().getVersion();
|
||||
if (pluginNotFound("T2CodeLib", 96388, Util.getRequiredT2CodeLibVersion())) return;
|
||||
Load.onLoad(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getSpigotID(), Util.getDiscord(), Util.getBstatsID());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,7 +42,7 @@ public final class Main extends JavaPlugin {
|
||||
// Plugin shutdown logic
|
||||
allResponses.clear();
|
||||
if (Bukkit.getPluginManager().getPlugin("T2CodeLib") == null) return;
|
||||
T2CodeTemplate.onDisable(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
|
||||
T2C_Template.onDisable(Util.getPrefix(), plugin);
|
||||
}
|
||||
|
||||
public static Boolean pluginNotFound(String pl, Integer spigotID, String ver) {
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package net.t2code.autoresponse.Spigot.cmdManagement;
|
||||
|
||||
import net.t2code.autoresponse.Spigot.config.languages.SelectMessages;
|
||||
import net.t2code.autoresponse.Spigot.config.languages.Languages;
|
||||
import net.t2code.autoresponse.Spigot.system.Permissions;
|
||||
import net.t2code.lib.Spigot.Lib.messages.send;
|
||||
import net.t2code.t2codelib.SPIGOT.api.messages.T2C_Send;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -17,16 +17,14 @@ public class CmdExecuter implements CommandExecutor, TabCompleter {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length == 0) {
|
||||
if (args.length != 0) {
|
||||
// Command
|
||||
|
||||
} else {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "reload":
|
||||
case "rl":
|
||||
if (sender.hasPermission(Permissions.admin) || sender.isOp()) {
|
||||
Commands.reload(sender);
|
||||
} else send.sender(sender, SelectMessages.NoPermissionForCommand.replace("[cmd]", "/t2code-autoresponse reload")
|
||||
} else T2C_Send.sender(sender, Languages.VALUES.noPermissionForCommand.getValue().toString().replace("[cmd]", "/t2code-autoresponse reload")
|
||||
.replace("[perm]", Permissions.admin));
|
||||
break;
|
||||
case "info":
|
||||
@@ -34,7 +32,7 @@ public class CmdExecuter implements CommandExecutor, TabCompleter {
|
||||
case "version":
|
||||
if (sender.hasPermission(Permissions.info)) {
|
||||
Commands.info(sender);
|
||||
} else send.sender(sender, SelectMessages.NoPermissionForCommand.replace("[cmd]", "/t2code-autoresponse info")
|
||||
} else T2C_Send.sender(sender, Languages.VALUES.noPermissionForCommand.getValue().toString().replace("[cmd]", "/t2code-autoresponse info")
|
||||
.replace("[perm]", Permissions.info));
|
||||
break;
|
||||
|
||||
@@ -44,7 +42,7 @@ public class CmdExecuter implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
|
||||
//TabCompleter
|
||||
private static HashMap<String, String> arg1 = new HashMap<String, String>() {{
|
||||
private static final HashMap<String, String> arg1 = new HashMap<String, String>() {{
|
||||
put("reload", Permissions.admin);
|
||||
put("rl", Permissions.admin);
|
||||
put("info", Permissions.info);
|
||||
@@ -57,7 +55,7 @@ public class CmdExecuter implements CommandExecutor, TabCompleter {
|
||||
Player p = (Player) sender;
|
||||
if (args.length == 1) {
|
||||
for (String command : arg1.keySet()) {
|
||||
Boolean passend = true;
|
||||
boolean passend = true;
|
||||
for (int i = 0; i < args[0].length(); i++) {
|
||||
if (args[0].length() >= command.length()) {
|
||||
passend = false;
|
||||
|
@@ -1,29 +1,28 @@
|
||||
package net.t2code.autoresponse.Spigot.cmdManagement;
|
||||
|
||||
import net.t2code.autoresponse.Spigot.config.languages.Languages;
|
||||
import net.t2code.autoresponse.Util;
|
||||
import net.t2code.autoresponse.Spigot.config.languages.SelectMessages;
|
||||
import net.t2code.autoresponse.Spigot.system.Load;
|
||||
import net.t2code.autoresponse.Spigot.Main;
|
||||
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 net.t2code.t2codelib.SPIGOT.api.messages.T2C_Send;
|
||||
import net.t2code.t2codelib.SPIGOT.api.messages.T2C_Template;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands {
|
||||
public static void info(CommandSender sender) {
|
||||
T2CodeTemplate.sendInfo(sender, Util.getPrefix(),Util.getSpigot(),Util.getDiscord(), Main.getAutor(),Main.getVersion(), UpdateAPI.PluginVersionen.get(Main.getPlugin().getName()).publicVersion);
|
||||
T2C_Template.sendInfo(sender,Main.getPlugin(),Util.getSpigotID(),Util.getDiscord(),Util.getInfoText());
|
||||
}
|
||||
|
||||
public static void reload(CommandSender sender) {
|
||||
if (sender instanceof Player) sender.sendMessage(SelectMessages.ReloadStart);
|
||||
send.console(Util.getPrefix() + "§8-------------------------------");
|
||||
send.console(Util.getPrefix() + " §6Plugin reload...");
|
||||
send.console(Util.getPrefix() + "§8-------------------------------");
|
||||
Load.loadReload();
|
||||
if (sender instanceof Player) sender.sendMessage(SelectMessages.ReloadEnd);
|
||||
send.console(Util.getPrefix() + "§8-------------------------------");
|
||||
send.console(Util.getPrefix() + " §2Plugin successfully reloaded.");
|
||||
send.console(Util.getPrefix() + "§8-------------------------------");
|
||||
if (sender instanceof Player) sender.sendMessage(Languages.VALUES.reloadStart.getValue().toString());
|
||||
T2C_Send.console(Util.getPrefix() + "§8-------------------------------");
|
||||
T2C_Send.console(Util.getPrefix() + " §6Plugin reload...");
|
||||
T2C_Send.console(Util.getPrefix() + "§8-------------------------------");
|
||||
Load.loadReload(true);
|
||||
if (sender instanceof Player) sender.sendMessage(Languages.VALUES.reloadEnd.getValue().toString());
|
||||
T2C_Send.console(Util.getPrefix() + "§8-------------------------------");
|
||||
T2C_Send.console(Util.getPrefix() + " §2Plugin successfully reloaded.");
|
||||
T2C_Send.console(Util.getPrefix() + "§8-------------------------------");
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,116 @@
|
||||
// This class was created by JaTiTV.
|
||||
|
||||
package net.t2code.autoresponse.Spigot.config.config;
|
||||
|
||||
import net.t2code.autoresponse.Spigot.Main;
|
||||
import net.t2code.autoresponse.Util;
|
||||
import net.t2code.t2codelib.SPIGOT.api.yaml.T2C_ConfigWriter;
|
||||
import net.t2code.t2codelib.SPIGOT.system.T2C_Main;
|
||||
import net.t2code.t2codelib.SPIGOT.system.config.config.T2C_LibConfig;
|
||||
import net.t2code.t2codelib.util.T2C_ConfigItem;
|
||||
import net.t2code.t2codelib.util.T2C_LanguageEnum;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class Config {
|
||||
public enum VALUES implements T2C_ConfigItem {
|
||||
language("plugin.language", T2C_LanguageEnum.english, true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of("In dieser Option kannst du die Sprache des Plugins einstellen."));
|
||||
put(T2C_LanguageEnum.english, List.of("In this option you can set the language of the plugin."));
|
||||
}}),
|
||||
updateCheckOnJoin("plugin.updateCheck.onJoin", true, true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
updateCheckSeePreReleaseUpdates("plugin.updateCheck.seePreReleaseUpdates", true, true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
updateCheckTimeInterval("plugin.updateCheck.timeInterval", 60, true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
keywordSeparation("plugin.responseKeys.keywordSeparation", "##", true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
logConsole("log.console.enable", true, true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
|
||||
;
|
||||
|
||||
private final String path;
|
||||
private Object value;
|
||||
private final boolean forceSet;
|
||||
private final HashMap<T2C_LanguageEnum, List<String>> comments;
|
||||
|
||||
VALUES(String path, Object value, boolean forceSet, HashMap<T2C_LanguageEnum, List<String>> comments) {
|
||||
this.path = path;
|
||||
this.value = value;
|
||||
this.forceSet = forceSet;
|
||||
this.comments = comments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getForceSet() {
|
||||
return forceSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<T2C_LanguageEnum, List<String>> getComments() {
|
||||
return comments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguagePath() {
|
||||
return language.path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Object newValue) {
|
||||
value = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static void set(boolean isReload) {
|
||||
convert();
|
||||
T2C_ConfigWriter.createConfig(Util.getPrefix(), new File(Main.getPath(), "config.yml"), T2C_LibConfig.VALUES.values(), isReload, Util.getConfigLogo());
|
||||
}
|
||||
|
||||
private static void convert() {
|
||||
File config = new File(Main.getPath(), "config.yml");
|
||||
|
||||
if (!config.exists()) return;
|
||||
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
|
||||
|
||||
if (!yamlConfiguration.contains("Plugin")) return;
|
||||
|
||||
set("Plugin.language", VALUES.language, yamlConfiguration);
|
||||
set("Plugin.updateCheck.onJoin", VALUES.updateCheckOnJoin, yamlConfiguration);
|
||||
set("Plugin.updateCheck.seePreReleaseUpdates", VALUES.updateCheckSeePreReleaseUpdates, yamlConfiguration);
|
||||
set("Plugin.updateCheck.timeInterval", VALUES.updateCheckTimeInterval, yamlConfiguration);
|
||||
set("Plugin.responseKeys.keywordSeperation", VALUES.keywordSeparation, yamlConfiguration);
|
||||
set("Log.Console.Enable", VALUES.logConsole, yamlConfiguration);
|
||||
}
|
||||
|
||||
private static void set(String path, T2C_ConfigItem item, YamlConfiguration yamlConfiguration) {
|
||||
if (yamlConfiguration.contains(path)) {
|
||||
item.setValue(yamlConfiguration.get(path));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
package net.t2code.autoresponse.Spigot.config.config;
|
||||
|
||||
import net.t2code.autoresponse.Util;
|
||||
import net.t2code.autoresponse.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 void configCreate() {
|
||||
long long_ = System.currentTimeMillis();
|
||||
File config = new File(Main.getPath(), "config.yml");
|
||||
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
|
||||
|
||||
Config.set("Plugin.language", "english", yamlConfiguration);
|
||||
Config.set("BungeeCord.Enable", false, yamlConfiguration);
|
||||
|
||||
Config.set("Log.Console.Enable", true, yamlConfiguration);
|
||||
|
||||
try {
|
||||
yamlConfiguration.save(config);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
send.console(Util.getPrefix() + " §2config.yml were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||
}
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
package net.t2code.autoresponse.Spigot.config.config;
|
||||
|
||||
import net.t2code.autoresponse.Spigot.Main;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class SelectConfig {
|
||||
public static String language;
|
||||
public static Boolean bungee;
|
||||
public static Boolean logConsole;
|
||||
|
||||
public static void onSelect() {
|
||||
File config = new File(Main.getPath(), "config.yml");
|
||||
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
|
||||
|
||||
language = yamlConfiguration.getString("Plugin.language");
|
||||
bungee = yamlConfiguration.getBoolean("BungeeCord.Enable");
|
||||
logConsole = yamlConfiguration.getBoolean("Log.Console.Enable");
|
||||
}
|
||||
}
|
@@ -1,63 +0,0 @@
|
||||
package net.t2code.autoresponse.Spigot.config.languages;
|
||||
|
||||
import net.t2code.autoresponse.Util;
|
||||
import net.t2code.autoresponse.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 CreateMessages {
|
||||
private static Plugin plugin = Main.getPlugin();
|
||||
|
||||
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.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.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();
|
||||
}
|
||||
|
||||
send.console(Util.getPrefix() + " §2Language files were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms");
|
||||
}
|
||||
}
|
@@ -0,0 +1,116 @@
|
||||
// This class was created by JaTiTV.
|
||||
|
||||
package net.t2code.autoresponse.Spigot.config.languages;
|
||||
|
||||
import lombok.NonNull;
|
||||
import net.t2code.autoresponse.Spigot.Main;
|
||||
import net.t2code.autoresponse.Util;
|
||||
import net.t2code.t2codelib.SPIGOT.api.yaml.T2C_LanguageWriter;
|
||||
import net.t2code.t2codelib.SPIGOT.system.T2C_Main;
|
||||
import net.t2code.t2codelib.SPIGOT.system.config.config.T2C_LibConfig;
|
||||
import net.t2code.t2codelib.SPIGOT.system.config.languages.T2CLibLanguages;
|
||||
import net.t2code.t2codelib.util.T2C_ConfigItemLanguages;
|
||||
import net.t2code.t2codelib.util.T2C_LanguageEnum;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class Languages {
|
||||
public enum VALUES implements T2C_ConfigItemLanguages {
|
||||
otherLang("plugin", null, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, null);
|
||||
put(T2C_LanguageEnum.english, null);
|
||||
}}, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of("Wenn du eine Eigene Sprache hinzufügen magst, dann kopiere einfach eine Sprachdatei und benenne sie in deine Sprache, dies kannst du dann in der config.yml einstellen.", ""));
|
||||
put(T2C_LanguageEnum.english, List.of("If you want to add your own language, simply copy a language file and rename it to your language, you can then set this in config.yml.", ""));
|
||||
}}),
|
||||
reloadStart("plugin.reload.start", null, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of("[prefix] &6Plugin wird neu geladen..."));
|
||||
put(T2C_LanguageEnum.english, List.of("[prefix] &6Plugin is reloaded..."));
|
||||
}}, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
reloadEnd("plugin.reload.end", null, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of("[prefix] &2Plugin wurde erfolgreich neu geladen."));
|
||||
put(T2C_LanguageEnum.english, List.of("[prefix] &2Plugin was successfully reloaded."));
|
||||
}}, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
noPermissionForCommand("plugin.forCommand", null, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of("[prefix] &cF[ue]r &b[cmd] &cfehlt dir die Permission &6[perm]&c!"));
|
||||
put(T2C_LanguageEnum.english, List.of("[prefix] &cFor &b[cmd] &cyou lack the permission &6[perm]&c!"));
|
||||
}}, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
;
|
||||
private final String path;
|
||||
private Object value;
|
||||
private final HashMap<T2C_LanguageEnum, List<String>> lang;
|
||||
private final HashMap<T2C_LanguageEnum, List<String>> comments;
|
||||
|
||||
VALUES(String path, Object value, @NonNull HashMap<T2C_LanguageEnum, List<String>> lang, HashMap<T2C_LanguageEnum, List<String>> comments) {
|
||||
this.path = path;
|
||||
this.value = value;
|
||||
this.lang = lang;
|
||||
this.comments = comments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
if (value == null) {
|
||||
return lang.get(T2C_LanguageEnum.english);
|
||||
} else return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<T2C_LanguageEnum, List<String>> getLanguage() {
|
||||
return lang;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<T2C_LanguageEnum, List<String>> getComments() {
|
||||
return comments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Object newValue) {
|
||||
value = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static void set(boolean isReload) {
|
||||
convert(isReload);
|
||||
T2C_LanguageWriter.createConfig(Util.getPrefix(), Main.getPath(), T2CLibLanguages.VALUES.values(), T2C_LibConfig.VALUES.language.getValue().toString(), isReload, Util.getConfigLogo());
|
||||
}
|
||||
|
||||
private static void convert(boolean isReload) {
|
||||
File f = new File(Main.getPath() + "/languages/");
|
||||
File[] fileArray = f.listFiles();
|
||||
if (fileArray == null) return;
|
||||
|
||||
for (File file : fileArray) {
|
||||
String sub = file.getName().substring(file.getName().length() - 4);
|
||||
if (sub.equals(".yml")) {
|
||||
if (file.getName().contains("_messages")) {
|
||||
File nf = new File(file.getName().replace("_messages", ""));
|
||||
if (file.renameTo(nf)) {
|
||||
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(nf);
|
||||
VALUES.reloadStart.setValue(yamlConfiguration.getString("Plugin.Reload.Start"));
|
||||
VALUES.reloadEnd.setValue(yamlConfiguration.getString("Plugin.Reload.End"));
|
||||
VALUES.noPermissionForCommand.setValue(yamlConfiguration.getString("Plugin.ForCommand"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
// This claas was created by JaTiTV
|
||||
|
||||
// -----------------------------
|
||||
// _____ _____ _ _ _____
|
||||
// / ____/ ____| | | |_ _|
|
||||
// | | | | __| | | | | |
|
||||
// | | | | |_ | | | | | |
|
||||
// | |___| |__| | |__| |_| |_
|
||||
// \_____\_____|\____/|_____|
|
||||
// -----------------------------
|
||||
|
||||
package net.t2code.autoresponse.Spigot.config.languages;
|
||||
|
||||
public class MSG {
|
||||
|
||||
// EN
|
||||
protected static String EN_ReloadStart = "[prefix] &6Plugin is reloaded...";
|
||||
protected static String EN_ReloadEnd = "[prefix] &2Plugin was successfully reloaded.";
|
||||
protected static String EN_NoPermissionForCommand = "[prefix] &cFor &b[cmd] &cyou lack the permission &6[perm]&c!";
|
||||
|
||||
// DE
|
||||
protected static String DE_ReloadStart = "[prefix] &6Plugin wird neu geladen...";
|
||||
protected static String DE_ReloadEnd = "[prefix] &2Plugin wurde erfolgreich neu geladen.";
|
||||
protected static String DE_NoPermissionForCommand = "[prefix] &cF[ue]r &b[cmd] &cfehlt dir die Permission &6[perm]&c!";
|
||||
}
|
@@ -1,51 +0,0 @@
|
||||
package net.t2code.autoresponse.Spigot.config.languages;
|
||||
|
||||
import net.t2code.autoresponse.Util;
|
||||
import net.t2code.autoresponse.Spigot.config.config.SelectConfig;
|
||||
import net.t2code.autoresponse.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;
|
||||
|
||||
public class SelectMessages {
|
||||
private static String prefix = Util.getPrefix();
|
||||
|
||||
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.getPlugin(), "§4Select language...");
|
||||
long long_ = 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);
|
||||
|
||||
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_) + "ms");
|
||||
}
|
||||
}
|
@@ -1,57 +0,0 @@
|
||||
package net.t2code.autoresponse.Spigot.config.response;
|
||||
|
||||
import net.t2code.autoresponse.Util;
|
||||
import net.t2code.autoresponse.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.Collections;
|
||||
|
||||
public class CreateExampleResponse {
|
||||
|
||||
public static void configCreate() {
|
||||
long long_ = System.currentTimeMillis();
|
||||
if (new File(Main.getPath(), "config.yml").exists()) {
|
||||
if (Main.getPlugin().getConfig().getBoolean("Plugin.Debug")) send.console(Util.getPrefix() + " §5DEBUG: §6" + " §4config.yml are created / updated...");
|
||||
} else send.console(Util.getPrefix() + " §4config.yml are created...");
|
||||
|
||||
|
||||
File config = new File(Main.getPath(), "Responses/responseexample.yml");
|
||||
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
|
||||
|
||||
Config.set("Response.Enable", true, yamlConfiguration);
|
||||
Config.set("Response.ResponseKeys", Collections.singletonList(".example"), yamlConfiguration);
|
||||
Config.set("Response.Contains", false, yamlConfiguration);
|
||||
Config.set("Response.BlockKeyMessage", true, yamlConfiguration);
|
||||
Config.set("Response.Permission.Necessary", true, yamlConfiguration);
|
||||
Config.set("Response.Permission.Permission", "t2c-autoresponse.response.example", yamlConfiguration);
|
||||
|
||||
Config.set("Response.Command.Enable", false, yamlConfiguration);
|
||||
Config.set("Response.Command.CommandAsConsole", false, yamlConfiguration);
|
||||
Config.set("Response.Command.BungeeCommand", false, yamlConfiguration);
|
||||
Config.set("Response.Command.Commands", Collections.singletonList("say hi"), yamlConfiguration);
|
||||
|
||||
Config.set("Response.Message.Enable", true, yamlConfiguration);
|
||||
Config.set("Response.Message.Global.Enable", false, yamlConfiguration);
|
||||
Config.set("Response.Message.Global.Bungee", false, yamlConfiguration);
|
||||
Config.set("Response.Message.Messages", Arrays.asList("[prefix] <dark_green>This is an Automated response from <dark_gray>[<dark_red>T2Code</dark_red><gray>-</gray><aqua>AutoResponse</aqua>]</dark_gray>.</dark_green>", "[prefix] <gold>Contact us for questions / support on our <dark_purple><hover:show_text:'<dark_purple>Discord:</dark_purple> <yellow>dc.t2code.net</yellow>'><click:open_url:'http://dc.t2code.net'>Discord</click></hover></dark_purple>.</gold>"), yamlConfiguration);
|
||||
|
||||
Config.set("Response.Protection.GameMode.Enable", false, yamlConfiguration);
|
||||
Config.set("Response.Protection.GameMode.Mode", "blacklist", yamlConfiguration);
|
||||
Config.set("Response.Protection.GameMode.List", Arrays.asList("CREATIVE","SPECTATOR"), yamlConfiguration);
|
||||
Config.set("Response.Protection.World.Enable", false, yamlConfiguration);
|
||||
Config.set("Response.Protection.World.Mode", "blacklist", yamlConfiguration);
|
||||
Config.set("Response.Protection.World.List", Arrays.asList("World1","World2"), yamlConfiguration);
|
||||
|
||||
try {
|
||||
yamlConfiguration.save(config);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
send.console(Util.getPrefix() + " §2config.yml were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||
}
|
||||
}
|
@@ -0,0 +1,270 @@
|
||||
// This class was created by JaTiTV.
|
||||
|
||||
package net.t2code.autoresponse.Spigot.config.response;
|
||||
|
||||
import net.t2code.autoresponse.Spigot.Main;
|
||||
import net.t2code.autoresponse.Spigot.config.config.Config;
|
||||
import net.t2code.autoresponse.Spigot.objects.ResponsesObject;
|
||||
import net.t2code.autoresponse.Util;
|
||||
import net.t2code.t2codelib.SPIGOT.api.yaml.T2C_ConfigWriter;
|
||||
import net.t2code.t2codelib.SPIGOT.system.T2C_Main;
|
||||
import net.t2code.t2codelib.util.T2C_ConfigItem;
|
||||
import net.t2code.t2codelib.util.T2C_LanguageEnum;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class ResponseFile {
|
||||
public enum VALUES implements T2C_ConfigItem {
|
||||
enable("response.enable", true, true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of("In dieser Option kannst du die Sprache des Plugins einstellen."));
|
||||
put(T2C_LanguageEnum.english, List.of("In this option you can set the language of the plugin."));
|
||||
}}),
|
||||
responseKeys("response.responseKeys", List.of(".example"), true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
contains("response.contains", false, true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
blockKeyMessage("response.blockKeyMessage", true, true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
permNecessary("response.permission.necessary", true, true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
permission("response.permission.permission", "t2c-autoresponse.response.example", true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
delayInTicks("response.response.delayInTicks", 0, true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
delayAsync("response.response.async", true, true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
commandEnable("response.command.enable", false, true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
commandAsConsole("response.command.commandAsConsole", false, true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
bungeeCommand("response.command.proxyCommand", false, true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
command("response.command.commands", List.of("say hi"), true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
messageEnable("response.message.enable", true, true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
messageGlobalServer("response.message.global.enable", false, true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
messageGlobalProxy("response.message.global.proxy", false, true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
messages("response.message.messages", List.of("[prefix] <dark_green>This is an Automated response from <dark_gray>[<dark_red>T2Code</dark_red><gray>-</gray><aqua>AutoResponse</aqua>]</dark_gray>.</dark_green>", "[prefix] <gold>Contact us for questions / support on our <dark_purple><hover:show_text:'<dark_purple>Discord:</dark_purple> <yellow>dc.t2code.net</yellow>'><click:open_url:'http://dc.t2code.net'>Discord</click></hover></dark_purple>.</gold>"), true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
protectionGameModeEnable("response.protection.gameMode.enable", false, true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
protectionGameModeMode("response.protection.gameMode.mode", "blacklist", true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
protectionGameModeList("response.protection.gameMode.list", List.of("CREATIVE", "SPECTATOR"), true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
protectionWorldEnable("response.protection.world.enable", false, true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
protectionWorldMode("response.protection.world.mode", "blacklist", true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
protectionWorldList("response.protection.world.list", List.of("World1", "World2"), true, new HashMap<>() {{
|
||||
put(T2C_LanguageEnum.german, List.of());
|
||||
put(T2C_LanguageEnum.english, List.of());
|
||||
}}),
|
||||
|
||||
|
||||
;
|
||||
|
||||
private final String path;
|
||||
private Object value;
|
||||
private final boolean forceSet;
|
||||
private final HashMap<T2C_LanguageEnum, List<String>> comments;
|
||||
|
||||
VALUES(String path, Object value, boolean forceSet, HashMap<T2C_LanguageEnum, List<String>> comments) {
|
||||
this.path = path;
|
||||
this.value = value;
|
||||
this.forceSet = forceSet;
|
||||
this.comments = comments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getForceSet() {
|
||||
return forceSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<T2C_LanguageEnum, List<String>> getComments() {
|
||||
return comments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguagePath() {
|
||||
return Config.VALUES.language.getValue().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Object newValue) {
|
||||
value = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void set(boolean isReload) {
|
||||
File of = new File(Main.getPath() + "/Responses/");
|
||||
if (of.exists()){
|
||||
convert(isReload);
|
||||
}
|
||||
|
||||
Main.allResponses.clear();
|
||||
Main.allResponse.clear();
|
||||
File f = new File(Main.getPath() + "/responses/");
|
||||
File[] fileArray = f.listFiles();
|
||||
if (fileArray == null) {
|
||||
T2C_ConfigWriter.createConfig(Util.getPrefix(), new File(Main.getPath(), "/responses/responseExample.yml"), VALUES.values(), isReload, Util.getConfigLogo());
|
||||
}
|
||||
|
||||
for (File file : fileArray) {
|
||||
String sub = file.getName().substring(file.getName().length() - 4);
|
||||
if (sub.equals(".yml")) {
|
||||
T2C_ConfigWriter.createConfig(Util.getPrefix(), new File(Main.getPath(), "/responses/" + file.getName()), VALUES.values(), isReload, Util.getConfigLogo());
|
||||
ResponsesObject response = new ResponsesObject(
|
||||
(boolean) VALUES.enable.value,
|
||||
(List<String>) VALUES.responseKeys.value,
|
||||
(boolean) VALUES.contains.value,
|
||||
(boolean) VALUES.blockKeyMessage.value,
|
||||
(boolean) VALUES.permNecessary.value,
|
||||
VALUES.permission.value.toString(),
|
||||
(int) VALUES.delayInTicks.value,
|
||||
(boolean) VALUES.delayAsync.value,
|
||||
(boolean) VALUES.commandEnable.value,
|
||||
(boolean) VALUES.commandAsConsole.value,
|
||||
(boolean) VALUES.bungeeCommand.value,
|
||||
(List<String>) VALUES.command.value,
|
||||
(boolean) VALUES.messageEnable.value,
|
||||
(boolean) VALUES.messageGlobalServer.value,
|
||||
(boolean) VALUES.messageGlobalProxy.value,
|
||||
(List<String>) VALUES.messages.value,
|
||||
(boolean) VALUES.protectionGameModeEnable.value,
|
||||
VALUES.protectionGameModeMode.value.toString(),
|
||||
(List<String>) VALUES.protectionGameModeList.value,
|
||||
(boolean) VALUES.protectionWorldEnable.value,
|
||||
VALUES.protectionWorldMode.value.toString(),
|
||||
(List<String>) VALUES.protectionWorldList.value
|
||||
);
|
||||
Main.allResponses.add(response);
|
||||
Main.allResponse.addAll((List<String>) VALUES.responseKeys.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void convert(boolean isReload) {
|
||||
File x = new File(Main.getPath() + "/Responses/");
|
||||
x.renameTo(new File(Main.getPath() + "/oldResponses/"));
|
||||
|
||||
File f = new File(Main.getPath() + "/oldResponses/");
|
||||
File[] fileArray = f.listFiles();
|
||||
if (fileArray == null) return;
|
||||
for (File file : fileArray) {
|
||||
String sub = file.getName().substring(file.getName().length() - 4);
|
||||
if (sub.equals(".yml")) {
|
||||
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
ResponseFile.VALUES.enable.setValue(yamlConfiguration.getBoolean("Response.Enable"));
|
||||
ResponseFile.VALUES.responseKeys.setValue(yamlConfiguration.getStringList("Response.ResponseKeys"));
|
||||
ResponseFile.VALUES.contains.setValue(yamlConfiguration.getBoolean("Response.Contains"));
|
||||
|
||||
ResponseFile.VALUES.blockKeyMessage.setValue(yamlConfiguration.getBoolean("Response.BlockKeyMessage"));
|
||||
ResponseFile.VALUES.permNecessary.setValue(yamlConfiguration.getBoolean("Response.Permission.Necessary"));
|
||||
ResponseFile.VALUES.permission.setValue(yamlConfiguration.getString("Response.Permission.Permission"));
|
||||
|
||||
ResponseFile.VALUES.delayInTicks.setValue(yamlConfiguration.getInt("Response.Response.DelayInTicks"));
|
||||
ResponseFile.VALUES.delayAsync.setValue(yamlConfiguration.getBoolean("Response.Response.Async"));
|
||||
|
||||
ResponseFile.VALUES.commandEnable.setValue(yamlConfiguration.getBoolean("Response.Command.Enable"));
|
||||
ResponseFile.VALUES.commandAsConsole.setValue(yamlConfiguration.getBoolean("Response.Command.CommandAsConsole"));
|
||||
ResponseFile.VALUES.bungeeCommand.setValue(yamlConfiguration.getBoolean("Response.Command.BungeeCommand"));
|
||||
ResponseFile.VALUES.command.setValue(yamlConfiguration.getStringList("Response.Command.Commands"));
|
||||
|
||||
ResponseFile.VALUES.messageEnable.setValue(yamlConfiguration.getBoolean("Response.Message.Enable"));
|
||||
ResponseFile.VALUES.messageGlobalServer.setValue(yamlConfiguration.getBoolean("Response.Message.Global.Enable"));
|
||||
ResponseFile.VALUES.messageGlobalProxy.setValue(yamlConfiguration.getBoolean("Response.Message.Global.Bungee"));
|
||||
ResponseFile.VALUES.messages.setValue(yamlConfiguration.getStringList("Response.Message.Messages"));
|
||||
|
||||
ResponseFile.VALUES.protectionGameModeEnable.setValue(yamlConfiguration.getBoolean("Response.Protection.GameMode.Enable"));
|
||||
ResponseFile.VALUES.protectionGameModeMode.setValue(yamlConfiguration.getString("Response.Protection.GameMode.Mode"));
|
||||
ResponseFile.VALUES.protectionGameModeList.setValue(yamlConfiguration.getStringList("Response.Protection.GameMode.List"));
|
||||
ResponseFile.VALUES.protectionWorldEnable.setValue(yamlConfiguration.getBoolean("Response.Protection.World.Enable"));
|
||||
ResponseFile.VALUES.protectionWorldMode.setValue(yamlConfiguration.getString("Response.Protection.World.Mode"));
|
||||
ResponseFile.VALUES.protectionWorldList.setValue(yamlConfiguration.getStringList("Response.Protection.World.List"));
|
||||
T2C_ConfigWriter.createConfig(Util.getPrefix(), new File(Main.getPath(), "/responses/" + file.getName()), VALUES.values(), isReload, Util.getConfigLogo());
|
||||
|
||||
}
|
||||
}
|
||||
File[] fileArray2 = f.listFiles();
|
||||
if (fileArray2 == null) return;
|
||||
Path directory = Paths.get(Main.getPath() + "/oldResponses/");
|
||||
try {
|
||||
Files.walk(directory)
|
||||
.sorted(Comparator.reverseOrder())
|
||||
.forEach(path -> {
|
||||
try {
|
||||
Files.delete(path);
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error when deleting " + path + ": " + e.getMessage());
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error when going through the directory: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
package net.t2code.autoresponse.Spigot.config.response;
|
||||
|
||||
import net.t2code.autoresponse.Util;
|
||||
import net.t2code.autoresponse.Spigot.objects.ResponsesObject;
|
||||
import net.t2code.autoresponse.Spigot.Main;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class SelectResponses {
|
||||
private static String Prefix = Util.getPrefix();
|
||||
public static void onSelect() {
|
||||
Main.allResponses.clear();
|
||||
Main.allResponse.clear();
|
||||
File f = new File(Main.getPath() + "/Responses/");
|
||||
File[] fileArray = f.listFiles();
|
||||
for (File config_gui : fileArray) {
|
||||
String sub = config_gui.getName().substring(config_gui.getName().length() - 4);
|
||||
if (sub.equals(".yml")) {
|
||||
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config_gui);
|
||||
ResponsesObject response = new ResponsesObject(
|
||||
yamlConfiguration.getBoolean("Response.Enable"),
|
||||
yamlConfiguration.getStringList("Response.ResponseKeys"),
|
||||
yamlConfiguration.getBoolean("Response.Contains"),
|
||||
yamlConfiguration.getBoolean("Response.BlockKeyMessage"),
|
||||
yamlConfiguration.getBoolean("Response.Permission.Necessary"),
|
||||
yamlConfiguration.getString("Response.Permission.Permission"),
|
||||
|
||||
yamlConfiguration.getBoolean("Response.Command.Enable"),
|
||||
yamlConfiguration.getBoolean("Response.Command.CommandAsConsole"),
|
||||
yamlConfiguration.getBoolean("Response.Command.BungeeCommand"),
|
||||
yamlConfiguration.getStringList("Response.Command.Commands"),
|
||||
|
||||
yamlConfiguration.getBoolean("Response.Message.Enable"),
|
||||
yamlConfiguration.getBoolean("Response.Message.Global.Enable"),
|
||||
yamlConfiguration.getBoolean("Response.Message.Global.Bungee"),
|
||||
yamlConfiguration.getStringList("Response.Message.Messages"),
|
||||
|
||||
yamlConfiguration.getBoolean("Response.Protection.GameMode.Enable"),
|
||||
yamlConfiguration.getString("Response.Protection.GameMode.Mode"),
|
||||
yamlConfiguration.getStringList("Response.Protection.GameMode.List"),
|
||||
yamlConfiguration.getBoolean("Response.Protection.World.Enable"),
|
||||
yamlConfiguration.getString("Response.Protection.World.Mode"),
|
||||
yamlConfiguration.getStringList("Response.Protection.World.List"));
|
||||
Main.allResponses.add(response);
|
||||
Main.allResponse.addAll(yamlConfiguration.getStringList("Response.ResponseKeys"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,18 +1,16 @@
|
||||
package net.t2code.autoresponse.Spigot.event;
|
||||
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.t2code.autoresponse.Spigot.system.BungeeSend;
|
||||
import net.t2code.autoresponse.Util;
|
||||
import net.t2code.autoresponse.Spigot.config.config.SelectConfig;
|
||||
import net.t2code.autoresponse.Spigot.objects.ResponsesObject;
|
||||
import net.t2code.autoresponse.Spigot.system.BCommand_Sender_Reciver;
|
||||
|
||||
import net.t2code.autoresponse.Spigot.Main;
|
||||
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 net.t2code.autoresponse.Spigot.config.config.Config;
|
||||
import net.t2code.autoresponse.Spigot.objects.ResponsesObject;
|
||||
import net.t2code.autoresponse.Spigot.system.ProxyCommandSenderReciver;
|
||||
import net.t2code.autoresponse.Spigot.system.ProxySend;
|
||||
import net.t2code.autoresponse.Util;
|
||||
import net.t2code.t2codelib.SPIGOT.api.commands.T2C_Cmd;
|
||||
import net.t2code.t2codelib.SPIGOT.api.messages.T2C_Replace;
|
||||
import net.t2code.t2codelib.SPIGOT.api.messages.T2C_Send;
|
||||
import net.t2code.t2codelib.SPIGOT.api.plugins.T2C_PluginCheck;
|
||||
import net.t2code.t2codelib.SPIGOT.system.config.config.T2C_LibConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -25,24 +23,38 @@ public class ResponseListener implements Listener {
|
||||
@EventHandler
|
||||
public static void ChatListener(AsyncPlayerChatEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
boolean bool = false;
|
||||
/* boolean bool = false;
|
||||
for (String s : Main.allResponse) {
|
||||
if (e.getMessage().contains(s)) bool = true;
|
||||
}
|
||||
if (!bool) return;
|
||||
|
||||
*/
|
||||
for (ResponsesObject response : Main.allResponses) {
|
||||
if (!response.permNecessary || player.hasPermission(response.permission)) {
|
||||
if (response.contains) {
|
||||
for (String responseKey : response.responseKeys) {
|
||||
if (e.getMessage().contains(responseKey)) {
|
||||
execute(e, player, response, responseKey);
|
||||
if (responseKey.contains(Config.VALUES.keywordSeparation.getValue().toString())) {
|
||||
String[] key = responseKey.split(Config.VALUES.keywordSeparation.getValue().toString());
|
||||
boolean allContains = false;
|
||||
for (String s : key) {
|
||||
if (e.getMessage().toLowerCase().contains(s.toLowerCase())) {
|
||||
allContains = true;
|
||||
} else return;
|
||||
}
|
||||
if (allContains) {
|
||||
execute1(e, player, response, responseKey);
|
||||
return;
|
||||
}
|
||||
} else if (e.getMessage().toLowerCase().contains(responseKey.toLowerCase())) {
|
||||
execute1(e, player, response, responseKey);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (String responseKey : response.responseKeys) {
|
||||
if (e.getMessage().equals(responseKey)) {
|
||||
execute(e, player, response, responseKey);
|
||||
if (e.getMessage().equalsIgnoreCase(responseKey)) {
|
||||
execute1(e, player, response, responseKey);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -51,8 +63,7 @@ public class ResponseListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private static void execute(AsyncPlayerChatEvent e, Player player, ResponsesObject response, String responseKey) {
|
||||
|
||||
private static void execute1(AsyncPlayerChatEvent e, Player player, ResponsesObject response, String responseKey) {
|
||||
if (response.protectionGameModeEnable) {
|
||||
if (response.protectionGameModeMode.equalsIgnoreCase("blacklist") && response.protectionGameModeList.contains(player.getGameMode().toString())) {
|
||||
return;
|
||||
@@ -70,29 +81,44 @@ public class ResponseListener implements Listener {
|
||||
}
|
||||
}
|
||||
use(e, player, responseKey, response);
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(Main.getPlugin(), () -> {
|
||||
if (response.async) {
|
||||
executeAsync(player, response);
|
||||
} else executeSync(player, response);
|
||||
}, 2L);
|
||||
}
|
||||
|
||||
private static void executeSync(Player player, ResponsesObject response) {
|
||||
Bukkit.getScheduler().runTaskLater(Main.getPlugin(), () -> executeFinal(player, response), (long) response.delayInTicks);
|
||||
}
|
||||
|
||||
private static void executeAsync(Player player, ResponsesObject response) {
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(Main.getPlugin(), () -> executeFinal(player, response), (long) response.delayInTicks);
|
||||
}
|
||||
|
||||
private static void executeFinal(Player player, ResponsesObject response) {
|
||||
if (response.commandEnable) {
|
||||
for (String cmd : response.command) {
|
||||
if (response.bungeeCommand) {
|
||||
if (SelectConfig.bungee) {
|
||||
if ((boolean) T2C_LibConfig.VALUES.proxy.getValue()) {
|
||||
if (response.commandAsConsole) {
|
||||
BCommand_Sender_Reciver.sendToBungee(player, cmd.replace("[player]", player.getName()), BungeeSend.BUNGEECOMMAND);
|
||||
} else BCommand_Sender_Reciver.sendToBungee(player, cmd.replace("[player]", player.getName()), BungeeSend.COMMAND);
|
||||
ProxyCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), ProxySend.BUNGEECOMMAND);
|
||||
} else ProxyCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), ProxySend.COMMAND);
|
||||
} else {
|
||||
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
send.sender(player, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
T2C_Send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
T2C_Send.sender(player, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
}
|
||||
} else {
|
||||
if (response.commandAsConsole) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cmd.console(cmd.replace("[player]", player.getName()));
|
||||
T2C_Cmd.console(cmd.replace("[player]", player.getName()));
|
||||
}
|
||||
}.runTaskLater(Main.getPlugin(), 1L);
|
||||
|
||||
} else {
|
||||
Cmd.player(player, cmd.replace("[player]", player.getName()));
|
||||
T2C_Cmd.player(player, cmd.replace("[player]", player.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,26 +126,26 @@ public class ResponseListener implements Listener {
|
||||
if (response.messageEnable) {
|
||||
for (String msg : response.messages) {
|
||||
String text;
|
||||
if (PluginCheck.papi()) {
|
||||
text = Replace.replace(Util.getPrefix(), player, msg);
|
||||
if (T2C_PluginCheck.papi()) {
|
||||
text = T2C_Replace.replace(Util.getPrefix(), player, msg);
|
||||
} else {
|
||||
text = Replace.replace(Util.getPrefix(), msg);
|
||||
text = T2C_Replace.replace(Util.getPrefix(), msg);
|
||||
}
|
||||
if (response.messageGlobal) {
|
||||
if (response.messageGlobalBungee) {
|
||||
BCommand_Sender_Reciver.sendToBungee(player, text, BungeeSend.ALLPLAYERMSG);
|
||||
ProxyCommandSenderReciver.sendToBungee(player, text, ProxySend.ALLPLAYERMSG);
|
||||
} else {
|
||||
for (Player player1 : Bukkit.getOnlinePlayers()) {
|
||||
send.player(player1, text);
|
||||
T2C_Send.player(player1, text);
|
||||
}
|
||||
}
|
||||
} else send.player(player, text);
|
||||
} else T2C_Send.player(player, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void use(AsyncPlayerChatEvent e, Player player, String responseKey, ResponsesObject response) {
|
||||
if (response.blockKeyMessage) e.setCancelled(true);
|
||||
if (SelectConfig.logConsole) send.console(Util.getPrefix() + " §6Player: §e" + player.getName() + " §6use AutoResponse: §e" + responseKey);
|
||||
if ((boolean) Config.VALUES.logConsole.getValue()) T2C_Send.console(Util.getPrefix() + " §6Player: §e" + player.getName() + " §6use AutoResponse: §e" + responseKey);
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,9 @@ public class ResponsesObject {
|
||||
public Boolean permNecessary;
|
||||
public String permission;
|
||||
|
||||
public Integer delayInTicks;
|
||||
public Boolean async;
|
||||
|
||||
public Boolean commandAsConsole;
|
||||
public Boolean bungeeCommand;
|
||||
public List<String> command;
|
||||
@@ -33,6 +36,8 @@ public class ResponsesObject {
|
||||
Boolean blockKeyMessage,
|
||||
Boolean permNecessary,
|
||||
String permission,
|
||||
Integer delayInTicks,
|
||||
Boolean delayAsync,
|
||||
Boolean commandEnable,
|
||||
Boolean commandAsConsole,
|
||||
Boolean bungeeCommand,
|
||||
@@ -62,6 +67,9 @@ public class ResponsesObject {
|
||||
this.messageGlobalBungee = messageGlobalBungee;
|
||||
this.messages = messages;
|
||||
|
||||
this.delayInTicks = delayInTicks;
|
||||
this.async = delayAsync;
|
||||
|
||||
this.protectionGameModeEnable = protectionGameModeEnable;
|
||||
this.protectionGameModeMode = protectionGameModeMode;
|
||||
this.protectionGameModeList = protectionGameModeList;
|
||||
|
@@ -4,7 +4,7 @@ package net.t2code.autoresponse.Spigot.system;
|
||||
|
||||
import net.t2code.autoresponse.Spigot.Main;
|
||||
import net.t2code.autoresponse.Util;
|
||||
import net.t2code.lib.Spigot.Lib.update.UpdateAPI;
|
||||
import net.t2code.t2codelib.SPIGOT.api.update.T2C_UpdateAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -18,6 +18,6 @@ public class JoinEvent implements Listener {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
UpdateAPI.join(Main.getPlugin(), Util.getPrefix(),Permissions.updatemsg,player,Util.getSpigot(), Util.getDiscord());
|
||||
T2C_UpdateAPI.join(Main.getPlugin(), Util.getPrefix(),Permissions.updatemsg,player,Util.getSpigotID(), Util.getDiscord());
|
||||
}
|
||||
}
|
@@ -1,49 +1,44 @@
|
||||
package net.t2code.autoresponse.Spigot.system;
|
||||
|
||||
import net.t2code.autoresponse.Spigot.Main;
|
||||
import net.t2code.autoresponse.Spigot.config.config.Config;
|
||||
import net.t2code.autoresponse.Spigot.config.languages.Languages;
|
||||
import net.t2code.autoresponse.Spigot.config.response.ResponseFile;
|
||||
import net.t2code.autoresponse.Util;
|
||||
import net.t2code.autoresponse.Spigot.cmdManagement.CmdExecuter;
|
||||
import net.t2code.autoresponse.Spigot.config.config.CreateConfig;
|
||||
import net.t2code.autoresponse.Spigot.config.config.SelectConfig;
|
||||
import net.t2code.autoresponse.Spigot.config.languages.CreateMessages;
|
||||
import net.t2code.autoresponse.Spigot.config.languages.SelectMessages;
|
||||
import net.t2code.autoresponse.Spigot.config.response.CreateExampleResponse;
|
||||
import net.t2code.autoresponse.Spigot.config.response.SelectResponses;
|
||||
import net.t2code.autoresponse.Spigot.event.ResponseListener;
|
||||
import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate;
|
||||
import net.t2code.lib.Spigot.Lib.update.UpdateAPI;
|
||||
import net.t2code.t2codelib.SPIGOT.api.messages.T2C_Template;
|
||||
import net.t2code.t2codelib.SPIGOT.api.update.T2C_UpdateAPI;
|
||||
import net.t2code.t2codelib.SPIGOT.system.config.config.T2C_LibConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Load {
|
||||
static Main plugin = Main.getPlugin();
|
||||
|
||||
public static void onLoad(String prefix, List<String> autor, String version, String spigot, int spigotID, String discord, int bstatsID) {
|
||||
Long long_ = T2CodeTemplate.onLoadHeader(prefix, autor, version, spigot, discord);
|
||||
Long long_ = T2C_Template.onLoadHeader(prefix, autor, version, spigot, discord);
|
||||
plugin.getCommand("t2code-autoresponse").setExecutor(new CmdExecuter());
|
||||
|
||||
loadReload();
|
||||
UpdateAPI.onUpdateCheck(plugin, prefix, spigot, spigotID, discord);
|
||||
loadReload(false);
|
||||
T2C_UpdateAPI.onUpdateCheck(plugin, prefix, Util.getGit(), spigotID, discord,
|
||||
(boolean) Config.VALUES.updateCheckOnJoin.getValue(), (boolean) Config.VALUES.updateCheckSeePreReleaseUpdates.getValue(), (int) Config.VALUES.updateCheckTimeInterval.getValue());
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new JoinEvent(), plugin);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new ResponseListener(), plugin);
|
||||
|
||||
T2CodeTemplate.onLoadFooter(prefix, long_,version);
|
||||
T2C_Template.onLoadFooter(prefix, long_);
|
||||
Metrics.Bstats(plugin, bstatsID);
|
||||
if (SelectConfig.bungee) {
|
||||
if ((boolean) T2C_LibConfig.VALUES.proxy.getValue()) {
|
||||
plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "BungeeCord");
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "t2car:bungee");
|
||||
}
|
||||
Permissions.register();
|
||||
}
|
||||
|
||||
public static void loadReload() {
|
||||
CreateConfig.configCreate();
|
||||
CreateMessages.langCreate();
|
||||
CreateExampleResponse.configCreate();
|
||||
|
||||
SelectConfig.onSelect();
|
||||
SelectMessages.onSelect(Util.getPrefix());
|
||||
SelectResponses.onSelect();
|
||||
public static void loadReload(boolean isReload) {
|
||||
Config.set(isReload);
|
||||
Languages.set(isReload);
|
||||
ResponseFile.set(isReload);
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@ package net.t2code.autoresponse.Spigot.system;
|
||||
|
||||
import net.t2code.autoresponse.Spigot.Main;
|
||||
import net.t2code.autoresponse.Spigot.objects.ResponsesObject;
|
||||
import net.t2code.lib.Spigot.Lib.register.Register;
|
||||
import net.t2code.t2codelib.SPIGOT.api.register.T2C_Register;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
public class Permissions {
|
||||
@@ -15,12 +15,12 @@ public class Permissions {
|
||||
public static final PermissionDefault notOp = PermissionDefault.NOT_OP;
|
||||
|
||||
protected static void register() {
|
||||
Register.permission(info, op, Main.getPlugin());
|
||||
Register.permission(updatemsg, op, Main.getPlugin());
|
||||
Register.permission(admin, op, info, true, Main.getPlugin());
|
||||
Register.permission(admin, op, updatemsg, true, Main.getPlugin());
|
||||
T2C_Register.permission(info, op, Main.getPlugin());
|
||||
T2C_Register.permission(updatemsg, op, Main.getPlugin());
|
||||
T2C_Register.permission(admin, op, info, true, Main.getPlugin());
|
||||
T2C_Register.permission(admin, op, updatemsg, true, Main.getPlugin());
|
||||
for (ResponsesObject response : Main.allResponses) {
|
||||
Register.permission(response.permission, op, Main.getPlugin());
|
||||
T2C_Register.permission(response.permission, op, Main.getPlugin());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,9 +9,9 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class BCommand_Sender_Reciver {
|
||||
public class ProxyCommandSenderReciver {
|
||||
|
||||
public static void sendToBungee(CommandSender sender, String information, BungeeSend type) {
|
||||
public static void sendToBungee(CommandSender sender, String information, ProxySend type) {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
DataOutputStream output = new DataOutputStream(stream);
|
||||
|
||||
@@ -38,10 +38,10 @@ public class BCommand_Sender_Reciver {
|
||||
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
player.sendPluginMessage(Main.getPlugin(), "t2car:bungee", stream.toByteArray());
|
||||
player.sendPluginMessage(Main.getPlugin(), "t2c:aresp", stream.toByteArray());
|
||||
} else {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
player.sendPluginMessage(Main.getPlugin(), "t2car:bungee", stream.toByteArray());
|
||||
player.sendPluginMessage(Main.getPlugin(), "t2c:aresp", stream.toByteArray());
|
||||
return;
|
||||
}
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
package net.t2code.autoresponse.Spigot.system;
|
||||
|
||||
public enum BungeeSend {
|
||||
public enum ProxySend {
|
||||
BUNGEECOMMAND,
|
||||
COMMAND,
|
||||
ALLPLAYERMSG
|
@@ -1,34 +1,36 @@
|
||||
package net.t2code.autoresponse;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
import net.t2code.t2codelib.util.T2C_Util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Util {
|
||||
private static String requiredT2CodeLibVersion = "12.5";
|
||||
private static String Prefix = "§8[§4T2Code§7-§bAutoResponse§8]";
|
||||
private static Integer SpigotID = 100603;
|
||||
private static Integer BstatsID = 14091;
|
||||
private static String Spigot = "https://www.spigotmc.org/resources/" + SpigotID;
|
||||
private static String Discord = "http://dc.t2code.net";
|
||||
|
||||
public static String getRequiredT2CodeLibVersion() {
|
||||
return requiredT2CodeLibVersion;
|
||||
@Getter
|
||||
private static final String infoText = "";
|
||||
@Getter
|
||||
private static final String requiredT2CodeLibVersion = "16.7";
|
||||
@Getter
|
||||
private static final String prefix = "§8[§4T2Code§7-§bAutoResponse§8]";
|
||||
@Getter
|
||||
private static final Integer spigotID = 100603;
|
||||
@Getter
|
||||
private static final String Git="JaTiTV/T2C-AutoResponse";
|
||||
@Getter
|
||||
private static final Integer bstatsID = 14091;
|
||||
@Getter
|
||||
private static final String spigot = "https://spigotmc.org/resources/" +spigotID;
|
||||
@Getter
|
||||
private static final String discord = "http://dc.t2code.net";
|
||||
|
||||
public static String[] getConfigLogo() {
|
||||
ArrayList<String> arrayList = new ArrayList<>(T2C_Util.getConfigT2CodeLogo());
|
||||
arrayList.addAll(Arrays.asList("", "# Spigot: " + spigot));
|
||||
return arrayList.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public static String getPrefix() {
|
||||
return Prefix;
|
||||
}
|
||||
|
||||
public static Integer getSpigotID() {
|
||||
return SpigotID;
|
||||
}
|
||||
|
||||
public static Integer getBstatsID() {
|
||||
return BstatsID;
|
||||
}
|
||||
|
||||
public static String getSpigot() {
|
||||
return Spigot;
|
||||
}
|
||||
|
||||
public static String getDiscord() {
|
||||
return Discord;
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +0,0 @@
|
||||
name: T2C-AutoResponse
|
||||
version: ${project.version}
|
||||
main: net.t2code.autoresponse.Bungee.BMain
|
||||
description: T2Code Alias Plugin
|
||||
author: JaTiTV
|
||||
softdepends: [T2CodeLib]
|
Reference in New Issue
Block a user