mirror of
https://github.com/darksaid98/SupremeTags.git
synced 2026-12-01 14:38:56 +00:00
push 1.14.0 update
This commit is contained in:
1 parent
cfb760a582
commit
18860082de
21 files changed
+1434
-167
No files matched your search
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>net.noscape.project.supremetags</groupId>
|
||||
<artifactId>SupremeTags</artifactId>
|
||||
<version>1.3.9-3</version>
|
||||
<version>1.4.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>SupremeTags</name>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.noscape.project.supremetags;
|
||||
|
||||
import net.noscape.project.supremetags.checkers.*;
|
||||
import net.noscape.project.supremetags.commands.*;
|
||||
import net.noscape.project.supremetags.handlers.hooks.*;
|
||||
import net.noscape.project.supremetags.handlers.menu.*;
|
||||
@@ -17,23 +18,62 @@ public final class SupremeTags extends JavaPlugin {
|
||||
private final TagManager tagManager = new TagManager();
|
||||
private final CategoryManager categoryManager = new CategoryManager();
|
||||
|
||||
private static MySQL mysql;
|
||||
private static H2Database h2;
|
||||
private final H2UserData h2user = new H2UserData();
|
||||
private static String connectionURL;
|
||||
private static Database data;
|
||||
private final UserData userData = new UserData();
|
||||
private final MySQLUserData user = new MySQLUserData();
|
||||
|
||||
private static final HashMap<Player, MenuUtil> menuUtilMap = new HashMap<>();
|
||||
|
||||
private final String host = getConfig().getString("data.address");
|
||||
private final int port = getConfig().getInt("data.port");
|
||||
private final String database = getConfig().getString("data.database");
|
||||
private final String username = getConfig().getString("data.username");
|
||||
private final String password = getConfig().getString("data.password");
|
||||
private final String options = getConfig().getString("data.options");
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
|
||||
connectionURL = "jdbc:h2:" + getDataFolder().getAbsolutePath() + "/database";
|
||||
data = new Database(connectionURL);
|
||||
this.saveDefaultConfig();
|
||||
this.callMetrics();
|
||||
|
||||
saveDefaultConfig();
|
||||
if (isH2()) {
|
||||
connectionURL = "jdbc:h2:" + getDataFolder().getAbsolutePath() + "/database";
|
||||
h2 = new H2Database(connectionURL);
|
||||
}
|
||||
|
||||
if (isMySQL()) {
|
||||
mysql = new MySQL(host, port, database, username, password, options);
|
||||
}
|
||||
|
||||
if (getConfig().getBoolean("settings.update-check")) {
|
||||
UpdateChecker updater = new UpdateChecker(this);
|
||||
updater.fetch();
|
||||
if (updater.hasUpdateAvailable()) {
|
||||
getLogger().info("------------------------------");
|
||||
getLogger().info("SupremeTags-Checker");
|
||||
getLogger().info(" ");
|
||||
getLogger().info("An update for SupremeTags has been found!");
|
||||
getLogger().info("SupremeTags-" + updater.getSpigotVersion());
|
||||
getLogger().info("You are running " + getDescription().getVersion());
|
||||
getLogger().info(" ");
|
||||
getLogger().info("Download at https://www.spigotmc.org/resources/%E2%9C%85-supremetags-%E2%9C%85-1-8-1-19-placeholderapi-support-unlimited-tags-%E2%9C%85.103140/");
|
||||
getLogger().info("------------------------------");
|
||||
} else {
|
||||
getLogger().info("------------------------------");
|
||||
getLogger().info("Running latest version of SupremeTags-" + getDescription().getVersion());
|
||||
getLogger().info("------------------------------");
|
||||
}
|
||||
}
|
||||
|
||||
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
new PAPI(this).register();
|
||||
getLogger().info("------------------------------");
|
||||
getLogger().info("PlaceholderAPI found SupremeTags! Automatically downloaded cloud.");
|
||||
getLogger().info("------------------------------");
|
||||
}
|
||||
|
||||
Objects.requireNonNull(getCommand("tags")).setExecutor(new Tags());
|
||||
@@ -62,7 +102,7 @@ public final class SupremeTags extends JavaPlugin {
|
||||
if (menuUtilMap.containsKey(player)) {
|
||||
return menuUtilMap.get(player);
|
||||
} else {
|
||||
menuUtil = new MenuUtil(player, UserData.getActive(player));
|
||||
menuUtil = new MenuUtil(player, UserData.getActive(player.getUniqueId()));
|
||||
menuUtilMap.put(player, menuUtil);
|
||||
}
|
||||
|
||||
@@ -75,7 +115,7 @@ public final class SupremeTags extends JavaPlugin {
|
||||
if (menuUtilMap.containsKey(player)) {
|
||||
return menuUtilMap.get(player);
|
||||
} else {
|
||||
menuUtil = new MenuUtil(player, UserData.getActive(player), category);
|
||||
menuUtil = new MenuUtil(player, UserData.getActive(player.getUniqueId()), category);
|
||||
menuUtilMap.put(player, menuUtil);
|
||||
}
|
||||
|
||||
@@ -86,13 +126,53 @@ public final class SupremeTags extends JavaPlugin {
|
||||
return connectionURL;
|
||||
}
|
||||
|
||||
public UserData getUserData() { return userData; }
|
||||
public H2UserData getUserData() { return h2user; }
|
||||
|
||||
public static Database getDatabase() { return data; }
|
||||
public static H2Database getDatabase() { return h2; }
|
||||
|
||||
public MySQLUserData getUser() {
|
||||
return instance.user;
|
||||
}
|
||||
|
||||
public static MySQL getMysql() {
|
||||
return mysql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadConfig() {
|
||||
super.reloadConfig();
|
||||
}
|
||||
|
||||
public Boolean isH2() {
|
||||
return Objects.requireNonNull(getConfig().getString("data.type")).equalsIgnoreCase("H2");
|
||||
}
|
||||
|
||||
public Boolean isMySQL() {
|
||||
return Objects.requireNonNull(getConfig().getString("data.type")).equalsIgnoreCase("MYSQL");
|
||||
}
|
||||
|
||||
private void callMetrics() {
|
||||
int pluginId = 103140;
|
||||
Metrics metrics = new Metrics(this, pluginId);
|
||||
|
||||
metrics.addCustomChart(new Metrics.SimplePie("used_language", () -> getConfig().getString("language", "en")));
|
||||
|
||||
metrics.addCustomChart(new Metrics.DrilldownPie("java_version", () -> {
|
||||
Map<String, Map<String, Integer>> map = new HashMap<>();
|
||||
String javaVersion = System.getProperty("java.version");
|
||||
Map<String, Integer> entry = new HashMap<>();
|
||||
entry.put(javaVersion, 1);
|
||||
if (javaVersion.startsWith("1.7")) {
|
||||
map.put("Java 1.7", entry);
|
||||
} else if (javaVersion.startsWith("1.8")) {
|
||||
map.put("Java 1.8", entry);
|
||||
} else if (javaVersion.startsWith("1.9")) {
|
||||
map.put("Java 1.9", entry);
|
||||
} else {
|
||||
map.put("Other", entry);
|
||||
}
|
||||
return map;
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,724 @@
|
||||
package net.noscape.project.supremetags.checkers;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
/**
|
||||
* bStats collects some data for plugin authors.
|
||||
* <p>
|
||||
* Check out https://bStats.org/ to learn more about bStats!
|
||||
*/
|
||||
@SuppressWarnings({"WeakerAccess"})
|
||||
public class Metrics {
|
||||
|
||||
static {
|
||||
// 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', '.', 'b', 'u', 'k', 'k', 'i', 't'});
|
||||
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
|
||||
// We want to make sure nobody just copy & pastes the example and use the wrong package names
|
||||
if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) {
|
||||
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The version of this bStats class
|
||||
public static final int B_STATS_VERSION = 1;
|
||||
|
||||
// The url to which the data is sent
|
||||
private static final String URL = "https://bStats.org/submitData/bukkit";
|
||||
|
||||
// Is bStats enabled on this server?
|
||||
private boolean enabled;
|
||||
|
||||
// Should failed requests be logged?
|
||||
private static boolean logFailedRequests;
|
||||
|
||||
// Should the sent data be logged?
|
||||
private static boolean logSentData;
|
||||
|
||||
// Should the response text be logged?
|
||||
private static boolean logResponseStatusText;
|
||||
|
||||
// The uuid of the server
|
||||
private static String serverUUID;
|
||||
|
||||
// The plugin
|
||||
private final Plugin plugin;
|
||||
|
||||
// The plugin id
|
||||
private final int pluginId;
|
||||
|
||||
// A list with all custom charts
|
||||
private final List<CustomChart> charts = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param plugin The plugin which stats should be submitted.
|
||||
* @param pluginId The id of the plugin.
|
||||
* It can be found at <a href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
|
||||
*/
|
||||
public Metrics(Plugin plugin, int pluginId) {
|
||||
if (plugin == null) {
|
||||
throw new IllegalArgumentException("Plugin cannot be null!");
|
||||
}
|
||||
this.plugin = plugin;
|
||||
this.pluginId = pluginId;
|
||||
|
||||
// Get the config file
|
||||
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
|
||||
File configFile = new File(bStatsFolder, "config.yml");
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
// Check if the config file exists
|
||||
if (!config.isSet("serverUuid")) {
|
||||
|
||||
// Add default values
|
||||
config.addDefault("enabled", true);
|
||||
// Every server gets it's unique random id.
|
||||
config.addDefault("serverUuid", UUID.randomUUID().toString());
|
||||
// Should failed request be logged?
|
||||
config.addDefault("logFailedRequests", false);
|
||||
// Should the sent data be logged?
|
||||
config.addDefault("logSentData", false);
|
||||
// Should the response text be logged?
|
||||
config.addDefault("logResponseStatusText", false);
|
||||
|
||||
// Inform the server owners about bStats
|
||||
config.options().header(
|
||||
"bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
|
||||
"To honor their work, you should not disable it.\n" +
|
||||
"This has nearly no effect on the server performance!\n" +
|
||||
"Check out https://bStats.org/ to learn more :)"
|
||||
).copyDefaults(true);
|
||||
try {
|
||||
config.save(configFile);
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
// Load the data
|
||||
enabled = config.getBoolean("enabled", true);
|
||||
serverUUID = config.getString("serverUuid");
|
||||
logFailedRequests = config.getBoolean("logFailedRequests", false);
|
||||
logSentData = config.getBoolean("logSentData", false);
|
||||
logResponseStatusText = config.getBoolean("logResponseStatusText", false);
|
||||
|
||||
if (enabled) {
|
||||
boolean found = false;
|
||||
// Search for all other bStats Metrics classes to see if we are the first one
|
||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
||||
try {
|
||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
||||
found = true; // We aren't the first
|
||||
break;
|
||||
} catch (NoSuchFieldException ignored) {
|
||||
}
|
||||
}
|
||||
// Register our service
|
||||
Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
|
||||
if (!found) {
|
||||
// We are the first!
|
||||
startSubmitting();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if bStats is enabled.
|
||||
*
|
||||
* @return Whether bStats is enabled or not.
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a custom chart.
|
||||
*
|
||||
* @param chart The chart to add.
|
||||
*/
|
||||
public void addCustomChart(CustomChart chart) {
|
||||
if (chart == null) {
|
||||
throw new IllegalArgumentException("Chart cannot be null!");
|
||||
}
|
||||
charts.add(chart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the Scheduler which submits our data every 30 minutes.
|
||||
*/
|
||||
private void startSubmitting() {
|
||||
final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!plugin.isEnabled()) { // Plugin was disabled
|
||||
timer.cancel();
|
||||
return;
|
||||
}
|
||||
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
|
||||
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
|
||||
Bukkit.getScheduler().runTask(plugin, () -> submitData());
|
||||
}
|
||||
}, 1000 * 60 * 5, 1000 * 60 * 30);
|
||||
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
|
||||
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
|
||||
// WARNING: Just don't do it!
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin specific data.
|
||||
* This method is called using Reflection.
|
||||
*
|
||||
* @return The plugin specific data.
|
||||
*/
|
||||
public JsonObject getPluginData() {
|
||||
JsonObject data = new JsonObject();
|
||||
|
||||
String pluginName = plugin.getDescription().getName();
|
||||
String pluginVersion = plugin.getDescription().getVersion();
|
||||
|
||||
data.addProperty("pluginName", pluginName); // Append the name of the plugin
|
||||
data.addProperty("id", pluginId); // Append the id of the plugin
|
||||
data.addProperty("pluginVersion", pluginVersion); // Append the version of the plugin
|
||||
JsonArray customCharts = new JsonArray();
|
||||
for (CustomChart customChart : charts) {
|
||||
// Add the data of the custom charts
|
||||
JsonObject chart = customChart.getRequestJsonObject();
|
||||
if (chart == null) { // If the chart is null, we skip it
|
||||
continue;
|
||||
}
|
||||
customCharts.add(chart);
|
||||
}
|
||||
data.add("customCharts", customCharts);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server specific data.
|
||||
*
|
||||
* @return The server specific data.
|
||||
*/
|
||||
private JsonObject getServerData() {
|
||||
// Minecraft specific data
|
||||
int playerAmount;
|
||||
try {
|
||||
// Around MC 1.8 the return type was changed to a collection from an array,
|
||||
// This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
|
||||
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
|
||||
playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
|
||||
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
|
||||
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
|
||||
} catch (Exception e) {
|
||||
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
|
||||
}
|
||||
int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
|
||||
String bukkitVersion = Bukkit.getVersion();
|
||||
String bukkitName = Bukkit.getName();
|
||||
|
||||
// OS/Java specific data
|
||||
String javaVersion = System.getProperty("java.version");
|
||||
String osName = System.getProperty("os.name");
|
||||
String osArch = System.getProperty("os.arch");
|
||||
String osVersion = System.getProperty("os.version");
|
||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
JsonObject data = new JsonObject();
|
||||
|
||||
data.addProperty("serverUUID", serverUUID);
|
||||
|
||||
data.addProperty("playerAmount", playerAmount);
|
||||
data.addProperty("onlineMode", onlineMode);
|
||||
data.addProperty("bukkitVersion", bukkitVersion);
|
||||
data.addProperty("bukkitName", bukkitName);
|
||||
|
||||
data.addProperty("javaVersion", javaVersion);
|
||||
data.addProperty("osName", osName);
|
||||
data.addProperty("osArch", osArch);
|
||||
data.addProperty("osVersion", osVersion);
|
||||
data.addProperty("coreCount", coreCount);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects the data and sends it afterwards.
|
||||
*/
|
||||
private void submitData() {
|
||||
final JsonObject data = getServerData();
|
||||
|
||||
JsonArray pluginData = new JsonArray();
|
||||
// Search for all other bStats Metrics classes to get their plugin data
|
||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
||||
try {
|
||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
||||
|
||||
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
|
||||
try {
|
||||
Object plugin = provider.getService().getMethod("getPluginData").invoke(provider.getProvider());
|
||||
if (plugin instanceof JsonObject) {
|
||||
pluginData.add((JsonObject) plugin);
|
||||
} else { // old bstats version compatibility
|
||||
try {
|
||||
Class<?> jsonObjectJsonSimple = Class.forName("org.json.simple.JSONObject");
|
||||
if (plugin.getClass().isAssignableFrom(jsonObjectJsonSimple)) {
|
||||
Method jsonStringGetter = jsonObjectJsonSimple.getDeclaredMethod("toJSONString");
|
||||
jsonStringGetter.setAccessible(true);
|
||||
String jsonString = (String) jsonStringGetter.invoke(plugin);
|
||||
JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject();
|
||||
pluginData.add(object);
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
// minecraft version 1.14+
|
||||
if (logFailedRequests) {
|
||||
this.plugin.getLogger().log(Level.SEVERE, "Encountered unexpected exception", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
|
||||
}
|
||||
}
|
||||
} catch (NoSuchFieldException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
data.add("plugins", pluginData);
|
||||
|
||||
// Create a new thread for the connection to the bStats server
|
||||
new Thread(() -> {
|
||||
try {
|
||||
// Send the data
|
||||
sendData(plugin, data);
|
||||
} catch (Exception e) {
|
||||
// Something went wrong! :(
|
||||
if (logFailedRequests) {
|
||||
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the data to the bStats server.
|
||||
*
|
||||
* @param plugin Any plugin. It's just used to get a logger instance.
|
||||
* @param data The data to send.
|
||||
* @throws Exception If the request failed.
|
||||
*/
|
||||
private static void sendData(Plugin plugin, JsonObject data) throws Exception {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Data cannot be null!");
|
||||
}
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
throw new IllegalAccessException("This method must not be called from the main thread!");
|
||||
}
|
||||
if (logSentData) {
|
||||
plugin.getLogger().info("Sending data to bStats: " + data);
|
||||
}
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
||||
|
||||
// Compress the data to save bandwidth
|
||||
byte[] compressedData = compress(data.toString());
|
||||
|
||||
// Add headers
|
||||
connection.setRequestMethod("POST");
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
|
||||
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
||||
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
|
||||
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
|
||||
|
||||
// Send data
|
||||
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) {
|
||||
plugin.getLogger().info("Sent data to bStats and received response: " + builder);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gzips the given String.
|
||||
*
|
||||
* @param str The string to gzip.
|
||||
* @return The gzipped String.
|
||||
* @throws IOException If the compression failed.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom chart.
|
||||
*/
|
||||
public static abstract class CustomChart {
|
||||
|
||||
// The id of the chart
|
||||
final String chartId;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
*/
|
||||
CustomChart(String chartId) {
|
||||
if (chartId == null || chartId.isEmpty()) {
|
||||
throw new IllegalArgumentException("ChartId cannot be null or empty!");
|
||||
}
|
||||
this.chartId = chartId;
|
||||
}
|
||||
|
||||
private JsonObject getRequestJsonObject() {
|
||||
JsonObject chart = new JsonObject();
|
||||
chart.addProperty("chartId", chartId);
|
||||
try {
|
||||
JsonObject data = getChartData();
|
||||
if (data == null) {
|
||||
// If the data is null we don't send the chart.
|
||||
return null;
|
||||
}
|
||||
chart.add("data", data);
|
||||
} catch (Throwable t) {
|
||||
if (logFailedRequests) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return chart;
|
||||
}
|
||||
|
||||
protected abstract JsonObject getChartData() throws Exception;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom simple pie.
|
||||
*/
|
||||
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 JsonObject getChartData() throws Exception {
|
||||
JsonObject data = new JsonObject();
|
||||
String value = callable.call();
|
||||
if (value == null || value.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.addProperty("value", value);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom advanced pie.
|
||||
*/
|
||||
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 JsonObject getChartData() throws Exception {
|
||||
JsonObject data = new JsonObject();
|
||||
JsonObject values = new JsonObject();
|
||||
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) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
values.addProperty(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.add("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom drilldown pie.
|
||||
*/
|
||||
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 JsonObject getChartData() throws Exception {
|
||||
JsonObject data = new JsonObject();
|
||||
JsonObject values = new JsonObject();
|
||||
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()) {
|
||||
JsonObject value = new JsonObject();
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
|
||||
value.addProperty(valueEntry.getKey(), valueEntry.getValue());
|
||||
allSkipped = false;
|
||||
}
|
||||
if (!allSkipped) {
|
||||
reallyAllSkipped = false;
|
||||
values.add(entryValues.getKey(), value);
|
||||
}
|
||||
}
|
||||
if (reallyAllSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.add("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom single line chart.
|
||||
*/
|
||||
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 JsonObject getChartData() throws Exception {
|
||||
JsonObject data = new JsonObject();
|
||||
int value = callable.call();
|
||||
if (value == 0) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.addProperty("value", value);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom multi line chart.
|
||||
*/
|
||||
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 JsonObject getChartData() throws Exception {
|
||||
JsonObject data = new JsonObject();
|
||||
JsonObject values = new JsonObject();
|
||||
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) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
values.addProperty(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.add("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom simple bar chart.
|
||||
*/
|
||||
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 JsonObject getChartData() throws Exception {
|
||||
JsonObject data = new JsonObject();
|
||||
JsonObject values = new JsonObject();
|
||||
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()) {
|
||||
JsonArray categoryValues = new JsonArray();
|
||||
categoryValues.add(new JsonPrimitive(entry.getValue()));
|
||||
values.add(entry.getKey(), categoryValues);
|
||||
}
|
||||
data.add("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom advanced bar chart.
|
||||
*/
|
||||
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 JsonObject getChartData() throws Exception {
|
||||
JsonObject data = new JsonObject();
|
||||
JsonObject values = new JsonObject();
|
||||
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) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
JsonArray categoryValues = new JsonArray();
|
||||
for (int categoryValue : entry.getValue()) {
|
||||
categoryValues.add(new JsonPrimitive(categoryValue));
|
||||
}
|
||||
values.add(entry.getKey(), categoryValues);
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.add("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package net.noscape.project.supremetags.checkers;
|
||||
|
||||
import net.md_5.bungee.api.chat.*;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.event.*;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.plugin.*;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
import static net.noscape.project.supremetags.utils.Utils.*;
|
||||
|
||||
public class UpdateChecker implements Listener {
|
||||
|
||||
private final int RESOURCE_ID = 103140;
|
||||
|
||||
private final Plugin plugin;
|
||||
|
||||
private String spigotVersion;
|
||||
|
||||
private final String pluginVersion;
|
||||
|
||||
private boolean updateAvailable;
|
||||
|
||||
public UpdateChecker(Plugin instance) {
|
||||
this.plugin = instance;
|
||||
this.pluginVersion = instance.getDescription().getVersion();
|
||||
}
|
||||
|
||||
public boolean hasUpdateAvailable() {
|
||||
return this.updateAvailable;
|
||||
}
|
||||
|
||||
public String getSpigotVersion() {
|
||||
return this.spigotVersion;
|
||||
}
|
||||
|
||||
public void fetch() {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
try {
|
||||
HttpsURLConnection con = (HttpsURLConnection)(new URL("https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID)).openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
this.spigotVersion = (new BufferedReader(new InputStreamReader(con.getInputStream()))).readLine();
|
||||
} catch (Exception ex) {
|
||||
this.plugin.getLogger().info("Failed to check for updates on spigot.");
|
||||
return;
|
||||
}
|
||||
if (this.spigotVersion == null || this.spigotVersion.isEmpty())
|
||||
return;
|
||||
this.updateAvailable = spigotIsNewer();
|
||||
if (!this.updateAvailable)
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
private boolean spigotIsNewer() {
|
||||
if (this.spigotVersion == null || this.spigotVersion.isEmpty())
|
||||
return false;
|
||||
String plV = toReadable(this.pluginVersion);
|
||||
String spV = toReadable(this.spigotVersion);
|
||||
return (plV.compareTo(spV) < 0);
|
||||
}
|
||||
|
||||
private String toReadable(String version) {
|
||||
if (version.contains("-DEV-"))
|
||||
version = version.split("-DEV-")[0];
|
||||
return version.replaceAll("\\.", "");
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
if (e.getPlayer().hasPermission("supremetags.updates")) {
|
||||
if (hasUpdateAvailable()) {
|
||||
TextComponent message = new TextComponent(TextComponent.fromLegacyText(format("&7Click &a[HERE] &7download it!")));
|
||||
setClickBroadcastEvent(message, "/");
|
||||
e.getPlayer().spigot().sendMessage(message);
|
||||
|
||||
msgPlayer(e.getPlayer(), "&8[&aSupremeTags&8] &7Update found for &a&lST &8(&f&nSupremeTags-" + getSpigotVersion() + "&r&8)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setClickBroadcastEvent(TextComponent component, String click) {
|
||||
if (click == null || click.length() == 0)
|
||||
return;
|
||||
switch (click.charAt(0)) {
|
||||
case '/':
|
||||
component.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, click));
|
||||
return;
|
||||
case '*':
|
||||
component.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, click.substring(1)));
|
||||
return;
|
||||
}
|
||||
component.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, click));
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ public class Tags implements CommandExecutor {
|
||||
} else if (args[0].equalsIgnoreCase("reset")) {
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]);
|
||||
|
||||
UserData.setActive(target, "None");
|
||||
H2UserData.setActive(target, "None");
|
||||
msgPlayer(sender, "&8[&b&lTag&8] &7Reset &b" + target.getName() + "'s &7tag back to None.");
|
||||
} else {
|
||||
msgPlayer(sender, "",
|
||||
@@ -103,10 +103,11 @@ public class Tags implements CommandExecutor {
|
||||
if (args.length == 0) {
|
||||
if (player.hasPermission("supremetags.menu")) {
|
||||
if (hasTags(player)) {
|
||||
|
||||
// categories menu to be added.
|
||||
|
||||
new TagMenu(SupremeTags.getMenuUtil(player)).open();
|
||||
if (SupremeTags.getInstance().getConfig().getBoolean("settings.categories")) {
|
||||
new MainMenu(SupremeTags.getMenuUtil(player)).open();
|
||||
} else {
|
||||
new TagMenu(SupremeTags.getMenuUtil(player)).open();
|
||||
}
|
||||
} else {
|
||||
msgPlayer(player, "&cYou have no tags yet.");
|
||||
}
|
||||
@@ -132,6 +133,15 @@ public class Tags implements CommandExecutor {
|
||||
} else {
|
||||
msgPlayer(player, "&cNo Permission.");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("setcategory")) {
|
||||
if (player.hasPermission("supremetags.admin")) {
|
||||
String name = args[1];
|
||||
String category = args[2];
|
||||
|
||||
SupremeTags.getInstance().getTagManager().setCategory(player, name, category);
|
||||
} else {
|
||||
msgPlayer(player, "&cNo Permission.");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("set")) {
|
||||
if (player.hasPermission("supremetags.admin")) {
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]);
|
||||
@@ -169,6 +179,7 @@ public class Tags implements CommandExecutor {
|
||||
"&6/tags create <identifier> <tag> &7- creates a new tag.",
|
||||
"&6/tags delete <identifier> &7- creates a new tag.",
|
||||
"&6/tags settag <identifier> <tag> &7- sets tag style for the existing tag.",
|
||||
"&6/tags setcategory <identifier> <category> &7- sets the category of the tag.",
|
||||
"&6/tags set <player> <identifier> &7- sets a new tag for that player.",
|
||||
"&6/tags reset <player> &7- resets the players tag to None.",
|
||||
"&6/tags merge &7- merges deluxetags into supremetags.",
|
||||
@@ -223,7 +234,7 @@ public class Tags implements CommandExecutor {
|
||||
if (player.hasPermission("supremetags.admin")) {
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]);
|
||||
|
||||
UserData.setActive(target, "None");
|
||||
H2UserData.setActive(target, "None");
|
||||
msgPlayer(player, "&8[&b&lTag&8] &7Reset &b" + target.getName() + "'s &7tag back to None.");
|
||||
} else {
|
||||
msgPlayer(player, "&cNo Permission.");
|
||||
|
||||
@@ -17,14 +17,6 @@ import static net.noscape.project.supremetags.utils.Utils.format;
|
||||
|
||||
public class CategoryMenu extends Paged {
|
||||
|
||||
|
||||
|
||||
// ==============================================
|
||||
// !! THIS IS NOT YET BEEN IMPLEMENTED !!
|
||||
// ==============================================
|
||||
|
||||
|
||||
|
||||
private final Map<String, Tag> tags;
|
||||
private final Map<Integer, String> dataItem;
|
||||
|
||||
@@ -36,12 +28,12 @@ public class CategoryMenu extends Paged {
|
||||
|
||||
@Override
|
||||
public String getMenuName() {
|
||||
return format(SupremeTags.getInstance().getConfig().getString("categories." + menuUtil.getCategory() + ".title"));
|
||||
return format("&8Category Tag Menu");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots() {
|
||||
return 56;
|
||||
return 54;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,7 +46,7 @@ public class CategoryMenu extends Paged {
|
||||
if (Objects.requireNonNull(e.getCurrentItem()).getType().equals(Material.valueOf(Objects.requireNonNull(SupremeTags.getInstance().getConfig().getString("gui.layout.tag-material")).toUpperCase()))) {
|
||||
if (!ChatColor.stripColor(Objects.requireNonNull(e.getCurrentItem().getItemMeta()).getDisplayName()).startsWith("Active")) {
|
||||
String identifier = dataItem.get(e.getSlot());
|
||||
if (!UserData.getActive(player).equalsIgnoreCase(identifier) && identifier != null) {
|
||||
if (!UserData.getActive(player.getUniqueId()).equalsIgnoreCase(identifier) && identifier != null) {
|
||||
UserData.setActive(player, identifier);
|
||||
player.closeInventory();
|
||||
super.open();
|
||||
@@ -70,6 +62,9 @@ public class CategoryMenu extends Paged {
|
||||
super.open();
|
||||
menuUtil.setIdentifier("None");
|
||||
}
|
||||
} else if (e.getCurrentItem().getType().equals(Material.valueOf(Objects.requireNonNull(SupremeTags.getInstance().getConfig().getString("gui.layout.refresh-material")).toUpperCase()))) {
|
||||
player.closeInventory();
|
||||
super.open();
|
||||
} else if (e.getCurrentItem().getType().equals(Material.valueOf(Objects.requireNonNull(SupremeTags.getInstance().getConfig().getString("gui.layout.back-next-material")).toUpperCase()))) {
|
||||
if (ChatColor.stripColor(Objects.requireNonNull(e.getCurrentItem().getItemMeta()).getDisplayName()).equalsIgnoreCase("Back")) {
|
||||
if (page != 0) {
|
||||
@@ -88,8 +83,6 @@ public class CategoryMenu extends Paged {
|
||||
@Override
|
||||
public void setMenuItems() {
|
||||
|
||||
addBottom();
|
||||
|
||||
// add all category tags.
|
||||
ArrayList<String> tag = new ArrayList<>(tags.keySet());
|
||||
|
||||
@@ -100,13 +93,11 @@ public class CategoryMenu extends Paged {
|
||||
if (tag.get(index) != null) {
|
||||
|
||||
String permission = SupremeTags.getInstance().getConfig().getString("tags." + tag.get(index) + ".permission");
|
||||
|
||||
String cat = SupremeTags.getInstance().getConfig().getString("tags." + tag.get(index) + ".category");
|
||||
|
||||
assert permission != null;
|
||||
if (menuUtil.getCategory().equalsIgnoreCase(cat)) {
|
||||
if (menuUtil.getCategory() != null && menuUtil.getCategory().equalsIgnoreCase(cat)) {
|
||||
if (menuUtil.getOwner().hasPermission(permission) && !permission.equalsIgnoreCase("none")) {
|
||||
|
||||
ItemStack tagItem = new ItemStack(Material.valueOf(Objects.requireNonNull(SupremeTags.getInstance().getConfig().getString("gui.layout.tag-material")).toUpperCase()), 1);
|
||||
ItemMeta tagMeta = tagItem.getItemMeta();
|
||||
assert tagMeta != null;
|
||||
@@ -159,5 +150,7 @@ public class CategoryMenu extends Paged {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addBottom();
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import org.bukkit.entity.*;
|
||||
import org.bukkit.event.inventory.*;
|
||||
import org.bukkit.inventory.*;
|
||||
import org.bukkit.inventory.meta.*;
|
||||
import org.bukkit.scheduler.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -15,15 +16,7 @@ import static net.noscape.project.supremetags.utils.Utils.*;
|
||||
|
||||
public class MainMenu extends Menu {
|
||||
|
||||
|
||||
|
||||
// ==============================================
|
||||
// !! THIS IS NOT YET BEEN IMPLEMENTED !!
|
||||
// ==============================================
|
||||
|
||||
|
||||
|
||||
private final Map<String, Category> catorgies;
|
||||
private final List<String> catorgies;
|
||||
private final Map<Integer, String> dataItem = new HashMap<>();
|
||||
|
||||
public MainMenu(MenuUtil menuUtil) {
|
||||
@@ -55,6 +48,7 @@ public class MainMenu extends Menu {
|
||||
if (material != null && Objects.requireNonNull(e.getCurrentItem()).getType().equals(Material.valueOf(material.toUpperCase()))) {
|
||||
if (permission != null && player.hasPermission(permission)) {
|
||||
new CategoryMenu(SupremeTags.getMenuUtil(player, category)).open();
|
||||
menuUtil.setCategory(category);
|
||||
} else {
|
||||
msgPlayer(player, "&cYou don't have permission to access these tags.");
|
||||
}
|
||||
@@ -66,15 +60,15 @@ public class MainMenu extends Menu {
|
||||
public void setMenuItems() {
|
||||
|
||||
// loop through categories items.
|
||||
for (String config_cats : Objects.requireNonNull(SupremeTags.getInstance().getConfig().getConfigurationSection("categories")).getKeys(false)) {
|
||||
if (config_cats != null) {
|
||||
boolean permission_see_category = SupremeTags.getInstance().getConfig().getBoolean("categories." + config_cats + ".permission-see-category");
|
||||
String permission = SupremeTags.getInstance().getConfig().getString("categories." + config_cats + ".permission");
|
||||
String material = SupremeTags.getInstance().getConfig().getString("categories." + config_cats + ".material");
|
||||
int slot = SupremeTags.getInstance().getConfig().getInt("categories." + config_cats + ".slot");
|
||||
String displayname = SupremeTags.getInstance().getConfig().getString("categories." + config_cats + ".id_display");
|
||||
for (String cats : getCatorgies()) {
|
||||
if (cats != null) {
|
||||
boolean canSee = SupremeTags.getInstance().getConfig().getBoolean("categories." + cats + ".permission-see-category");
|
||||
String permission = SupremeTags.getInstance().getConfig().getString("categories." + cats + ".permission");
|
||||
String material = SupremeTags.getInstance().getConfig().getString("categories." + cats + ".material");
|
||||
int slot = SupremeTags.getInstance().getConfig().getInt("categories." + cats + ".slot");
|
||||
String displayname = SupremeTags.getInstance().getConfig().getString("categories." + cats + ".id_display");
|
||||
|
||||
if (permission_see_category && permission != null && menuUtil.getOwner().hasPermission(permission)) {
|
||||
if (permission != null && menuUtil.getOwner().hasPermission(permission) && canSee) {
|
||||
|
||||
assert material != null;
|
||||
ItemStack cat_item = new ItemStack(Material.valueOf(material.toUpperCase()), 1);
|
||||
@@ -88,16 +82,16 @@ public class MainMenu extends Menu {
|
||||
cat_itemMeta.addItemFlags(ItemFlag.HIDE_DESTROYS);
|
||||
|
||||
// set lore
|
||||
ArrayList<String> lore = (ArrayList<String>) SupremeTags.getInstance().getConfig().getStringList("categories." + config_cats + ".lore");
|
||||
lore.replaceAll(s -> ChatColor.translateAlternateColorCodes('&', s).replaceAll("%tags_amount%", String.valueOf(catorgies.get(config_cats).getTags().size())));
|
||||
ArrayList<String> lore = (ArrayList<String>) SupremeTags.getInstance().getConfig().getStringList("categories." + cats + ".lore");
|
||||
lore.replaceAll(s -> ChatColor.translateAlternateColorCodes('&', s).replaceAll("%tags_amount%", String.valueOf(catorgies.size())));
|
||||
cat_itemMeta.setLore(color(lore));
|
||||
|
||||
cat_item.setItemMeta(cat_itemMeta);
|
||||
|
||||
dataItem.put(slot, catorgies.get(config_cats).getCategory());
|
||||
dataItem.put(slot, cats);
|
||||
|
||||
inventory.setItem(slot, cat_item);
|
||||
} else if (!permission_see_category && permission != null && !menuUtil.getOwner().hasPermission(permission)) {
|
||||
} else if (permission != null && !menuUtil.getOwner().hasPermission(permission) && !canSee) {
|
||||
|
||||
assert material != null;
|
||||
ItemStack cat_item = new ItemStack(Material.valueOf(material.toUpperCase()), 1);
|
||||
@@ -111,23 +105,44 @@ public class MainMenu extends Menu {
|
||||
cat_itemMeta.addItemFlags(ItemFlag.HIDE_DESTROYS);
|
||||
|
||||
// set lore
|
||||
ArrayList<String> lore = (ArrayList<String>) SupremeTags.getInstance().getConfig().getStringList("categories." + config_cats + ".lore");
|
||||
lore.replaceAll(s -> ChatColor.translateAlternateColorCodes('&', s).replaceAll("%tags_amount%", String.valueOf(catorgies.get(config_cats).getTags().size())));
|
||||
ArrayList<String> lore = (ArrayList<String>) SupremeTags.getInstance().getConfig().getStringList("categories." + cats + ".lore");
|
||||
lore.replaceAll(s -> ChatColor.translateAlternateColorCodes('&', s).replaceAll("%tags_amount%", String.valueOf(catorgies.size())));
|
||||
cat_itemMeta.setLore(color(lore));
|
||||
|
||||
cat_item.setItemMeta(cat_itemMeta);
|
||||
|
||||
dataItem.put(slot, catorgies.get(config_cats).getCategory());
|
||||
dataItem.put(slot, cats);
|
||||
|
||||
inventory.setItem(slot, cat_item);
|
||||
} else if (permission != null && menuUtil.getOwner().hasPermission(permission) && !canSee) {
|
||||
|
||||
assert material != null;
|
||||
ItemStack cat_item = new ItemStack(Material.valueOf(material.toUpperCase()), 1);
|
||||
ItemMeta cat_itemMeta = cat_item.getItemMeta();
|
||||
|
||||
assert cat_itemMeta != null;
|
||||
cat_itemMeta.setDisplayName(format(displayname));
|
||||
|
||||
cat_itemMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
cat_itemMeta.addItemFlags(ItemFlag.HIDE_DYE);
|
||||
cat_itemMeta.addItemFlags(ItemFlag.HIDE_DESTROYS);
|
||||
|
||||
// set lore
|
||||
ArrayList<String> lore = (ArrayList<String>) SupremeTags.getInstance().getConfig().getStringList("categories." + cats + ".lore");
|
||||
lore.replaceAll(s -> ChatColor.translateAlternateColorCodes('&', s).replaceAll("%tags_amount%", String.valueOf(catorgies.size())));
|
||||
cat_itemMeta.setLore(color(lore));
|
||||
|
||||
cat_item.setItemMeta(cat_itemMeta);
|
||||
|
||||
dataItem.put(slot, cats);
|
||||
|
||||
inventory.setItem(slot, cat_item);
|
||||
}
|
||||
} else {
|
||||
msgPlayer(menuUtil.getOwner(), "&cCategories is null!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Category> getCatorgies() {
|
||||
public List<String> getCatorgies() {
|
||||
return catorgies;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public class TagMenu extends Paged {
|
||||
if (Objects.requireNonNull(e.getCurrentItem()).getType().equals(Material.valueOf(Objects.requireNonNull(SupremeTags.getInstance().getConfig().getString("gui.layout.tag-material")).toUpperCase()))) {
|
||||
if (!ChatColor.stripColor(Objects.requireNonNull(e.getCurrentItem().getItemMeta()).getDisplayName()).startsWith("Active")) {
|
||||
String identifier = dataItem.get(e.getSlot());
|
||||
if (!UserData.getActive(player).equalsIgnoreCase(identifier) && identifier != null) {
|
||||
if (!UserData.getActive(player.getUniqueId()).equalsIgnoreCase(identifier) && identifier != null) {
|
||||
UserData.setActive(player, identifier);
|
||||
player.closeInventory();
|
||||
super.open();
|
||||
@@ -87,7 +87,7 @@ public class TagMenu extends Paged {
|
||||
for(int i = 0; i < getMaxItems(); i++) {
|
||||
index = getMaxItems() * page + i;
|
||||
if(index >= tag.size()) break;
|
||||
if (tag.get(index) != null){
|
||||
if (tag.get(index) != null) {
|
||||
|
||||
String permission = SupremeTags.getInstance().getConfig().getString("tags." + tag.get(index) + ".permission");
|
||||
|
||||
|
||||
@@ -4,10 +4,14 @@ public class Tag {
|
||||
|
||||
private String identifier;
|
||||
private String tag;
|
||||
private String category;
|
||||
private String permission;
|
||||
|
||||
public Tag(String identifier, String tag) {
|
||||
public Tag(String identifier, String tag, String category, String permission) {
|
||||
this.identifier = identifier;
|
||||
this.tag = tag;
|
||||
this.category = category;
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
public String getIdentifier() {
|
||||
@@ -26,4 +30,19 @@ public class Tag {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public void setCategory(String category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
public void setPermission(String permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
}
|
||||
@@ -43,10 +43,10 @@ public class PAPI extends PlaceholderExpansion {
|
||||
if (params.equalsIgnoreCase("tag")) {
|
||||
String text;
|
||||
|
||||
if (UserData.getActive(Objects.requireNonNull(player.getPlayer())).equalsIgnoreCase("None")) {
|
||||
if (UserData.getActive(Objects.requireNonNull(player.getUniqueId())).equalsIgnoreCase("None")) {
|
||||
text = "";
|
||||
} else {
|
||||
text = tags.get(UserData.getActive(player.getPlayer())).getTag();
|
||||
text = tags.get(UserData.getActive(player.getUniqueId())).getTag();
|
||||
}
|
||||
|
||||
return text;
|
||||
@@ -55,10 +55,10 @@ public class PAPI extends PlaceholderExpansion {
|
||||
if (params.equalsIgnoreCase("identifier")) {
|
||||
String text;
|
||||
|
||||
if (UserData.getActive(Objects.requireNonNull(player.getPlayer())).equalsIgnoreCase("None")) {
|
||||
if (UserData.getActive(Objects.requireNonNull(player.getUniqueId())).equalsIgnoreCase("None")) {
|
||||
text = "";
|
||||
} else {
|
||||
text = UserData.getActive(player.getPlayer());
|
||||
text = UserData.getActive(player.getUniqueId());
|
||||
}
|
||||
|
||||
return text;
|
||||
|
||||
@@ -36,6 +36,11 @@ public abstract class Menu implements InventoryHolder {
|
||||
menuUtil.getOwner().openInventory(inventory);
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
menuUtil.getOwner().updateInventory();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
|
||||
@@ -29,7 +29,9 @@ public abstract class Paged extends Menu {
|
||||
inventory.setItem(46, makeItem(Material.valueOf(Objects.requireNonNull(SupremeTags.getInstance().getConfig().getString("gui.layout.reset-tag-material")).toUpperCase()), ChatColor.RED + "Reset Tag"));
|
||||
}
|
||||
|
||||
inventory.setItem(52, makeItem(Material.valueOf(Objects.requireNonNull(SupremeTags.getInstance().getConfig().getString("gui.layout.tag-material")).toUpperCase()), format("&7Active: &6" + UserData.getActive(menuUtil.getOwner()))));
|
||||
inventory.setItem(45, makeItem(Material.valueOf(Objects.requireNonNull(SupremeTags.getInstance().getConfig().getString("gui.layout.refresh-material")).toUpperCase()), ChatColor.GREEN + "Refresh Menu"));
|
||||
|
||||
inventory.setItem(52, makeItem(Material.valueOf(Objects.requireNonNull(SupremeTags.getInstance().getConfig().getString("gui.layout.tag-material")).toUpperCase()), format("&7Active: &6" + UserData.getActive(menuUtil.getOwner().getUniqueId()))));
|
||||
|
||||
inventory.setItem(36, super.GLASS);
|
||||
inventory.setItem(37, super.GLASS);
|
||||
|
||||
@@ -22,7 +22,7 @@ public class PlayerEvents implements Listener {
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
SupremeTags.getInstance().getUserData().createPlayer(player);
|
||||
UserData.createPlayer(player);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@@ -32,12 +32,12 @@ public class PlayerEvents implements Listener {
|
||||
String format = e.getFormat();
|
||||
|
||||
final String replace = format.replace("{tag}", "").replace("{supremetags_tag}", "").replace("{TAG}", "");
|
||||
if (UserData.getActive(player).equalsIgnoreCase("None")) {
|
||||
if (UserData.getActive(player.getUniqueId()).equalsIgnoreCase("None")) {
|
||||
e.setFormat(replace);
|
||||
} else if (UserData.getActive(player) == null) {
|
||||
} else if (UserData.getActive(player.getUniqueId()) == null) {
|
||||
e.setFormat(replace);
|
||||
} else {
|
||||
e.setFormat(format.replace("{tag}", format(SupremeTags.getInstance().getTagManager().getTags().get(UserData.getActive(player)).getTag())).replace("{supremetags_tag}", format(SupremeTags.getInstance().getTagManager().getTags().get(UserData.getActive(player)).getTag())).replace("{TAG}", format(SupremeTags.getInstance().getTagManager().getTags().get(UserData.getActive(player)).getTag())));
|
||||
e.setFormat(format.replace("{tag}", format(SupremeTags.getInstance().getTagManager().getTags().get(UserData.getActive(player.getUniqueId())).getTag())).replace("{supremetags_tag}", format(SupremeTags.getInstance().getTagManager().getTags().get(UserData.getActive(player.getUniqueId())).getTag())).replace("{TAG}", format(SupremeTags.getInstance().getTagManager().getTags().get(UserData.getActive(player.getUniqueId())).getTag())));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,46 +1,21 @@
|
||||
package net.noscape.project.supremetags.managers;
|
||||
|
||||
import net.noscape.project.supremetags.*;
|
||||
import net.noscape.project.supremetags.handlers.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CategoryManager {
|
||||
|
||||
private final Map<String, Category> catorgies = new HashMap<>();
|
||||
private final List<String> catorgies = new ArrayList<>();
|
||||
|
||||
public CategoryManager() {}
|
||||
|
||||
public void loadCategories() {
|
||||
|
||||
catorgies.clear();
|
||||
|
||||
for (String cats : Objects.requireNonNull(SupremeTags.getInstance().getConfig().getConfigurationSection("categories")).getKeys(false)) {
|
||||
List<String> tags = new ArrayList<>();
|
||||
|
||||
String name = null;
|
||||
|
||||
// loop through tags and see if the category equals the category you are setting.
|
||||
for (String tag : Objects.requireNonNull(SupremeTags.getInstance().getConfig().getConfigurationSection("tags")).getKeys(false)) {
|
||||
String cat = SupremeTags.getInstance().getConfig().getString("tags." + tag + ".category");
|
||||
|
||||
if (cat != null) {
|
||||
if (cats.contains(cat)) {
|
||||
tags.add(tag);
|
||||
}
|
||||
}
|
||||
|
||||
name = tag;
|
||||
}
|
||||
|
||||
Category category = new Category(name, tags);
|
||||
|
||||
// loads category into map
|
||||
catorgies.put(category.getCategory(), category);
|
||||
}
|
||||
catorgies.addAll(Objects.requireNonNull(SupremeTags.getInstance().getConfig().getConfigurationSection("categories")).getKeys(false));
|
||||
}
|
||||
|
||||
public Map<String, Category> getCatorgies() {
|
||||
public List<String> getCatorgies() {
|
||||
return catorgies;
|
||||
}
|
||||
}
|
||||
@@ -22,12 +22,16 @@ public class TagManager {
|
||||
|
||||
public void createTag(Player player, String identifier, String tag_string, String description, String permission) {
|
||||
if (!tags.containsKey(identifier)) {
|
||||
Tag tag = new Tag(identifier, tag_string);
|
||||
|
||||
String default_category = SupremeTags.getInstance().getConfig().getString("settings.default-category");
|
||||
|
||||
Tag tag = new Tag(identifier, tag_string, default_category, permission);
|
||||
tags.put(identifier, tag);
|
||||
|
||||
SupremeTags.getInstance().getConfig().set("tags." + identifier + ".tag", tag_string);
|
||||
SupremeTags.getInstance().getConfig().set("tags." + identifier + ".permission", permission);
|
||||
SupremeTags.getInstance().getConfig().set("tags." + identifier + ".description", description);
|
||||
SupremeTags.getInstance().getConfig().set("tags." + identifier + ".category", default_category);
|
||||
SupremeTags.getInstance().saveConfig();
|
||||
SupremeTags.getInstance().reloadConfig();
|
||||
|
||||
@@ -39,12 +43,16 @@ public class TagManager {
|
||||
|
||||
public void createTag(CommandSender player, String identifier, String tag_string, String description, String permission) {
|
||||
if (!tags.containsKey(identifier)) {
|
||||
Tag tag = new Tag(identifier, tag_string);
|
||||
|
||||
String default_category = SupremeTags.getInstance().getConfig().getString("settings.default-category");
|
||||
|
||||
Tag tag = new Tag(identifier, tag_string, default_category, permission);
|
||||
tags.put(identifier, tag);
|
||||
|
||||
SupremeTags.getInstance().getConfig().set("tags." + identifier + ".tag", tag_string);
|
||||
SupremeTags.getInstance().getConfig().set("tags." + identifier + ".permission", permission);
|
||||
SupremeTags.getInstance().getConfig().set("tags." + identifier + ".description", description);
|
||||
SupremeTags.getInstance().getConfig().set("tags." + identifier + ".category", default_category);
|
||||
SupremeTags.getInstance().saveConfig();
|
||||
SupremeTags.getInstance().reloadConfig();
|
||||
|
||||
@@ -94,8 +102,10 @@ public class TagManager {
|
||||
int count = 0;
|
||||
for (String identifier : Objects.requireNonNull(SupremeTags.getInstance().getConfig().getConfigurationSection("tags")).getKeys(false)) {
|
||||
String tag = SupremeTags.getInstance().getConfig().getString("tags." + identifier + ".tag");
|
||||
String category = SupremeTags.getInstance().getConfig().getString("tags." + identifier + ".category");
|
||||
String permission = SupremeTags.getInstance().getConfig().getString("tags." + identifier + ".permission");
|
||||
|
||||
Tag t = new Tag(identifier, tag);
|
||||
Tag t = new Tag(identifier, tag, category, permission);
|
||||
tags.put(identifier, t);
|
||||
|
||||
count++;
|
||||
@@ -134,6 +144,25 @@ public class TagManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void setCategory(Player player, String identifier, String category) {
|
||||
if (tags.containsKey(identifier)) {
|
||||
Tag t = tags.get(identifier);
|
||||
t.setCategory(category);
|
||||
|
||||
try {
|
||||
SupremeTags.getInstance().getConfig().set("tags." + identifier + ".category", t.getCategory());
|
||||
SupremeTags.getInstance().saveConfig();
|
||||
SupremeTags.getInstance().reloadConfig();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
msgPlayer(player, "&6[TAG] &6" + t.getIdentifier() + "'s category &7changed to " + t.getCategory());
|
||||
} else {
|
||||
msgPlayer(player, "&6[TAG] &7This category doesn't exist!");
|
||||
}
|
||||
}
|
||||
|
||||
public void setTag(CommandSender player, String identifier, String tag) {
|
||||
if (tags.containsKey(identifier)) {
|
||||
Tag t = tags.get(identifier);
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package net.noscape.project.supremetags.storage;
|
||||
|
||||
import net.noscape.project.supremetags.*;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class H2Database {
|
||||
|
||||
private final String ConnectionURL;
|
||||
|
||||
public H2Database(String connectionURL) {
|
||||
ConnectionURL = connectionURL;
|
||||
|
||||
this.initialiseDatabase();
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
|
||||
Connection connection = null;
|
||||
|
||||
try {
|
||||
Class.forName("org.h2.Driver");
|
||||
connection = DriverManager.getConnection(SupremeTags.getConnectionURL());
|
||||
} catch (SQLException | ClassNotFoundException throwables) {
|
||||
throwables.printStackTrace();
|
||||
SupremeTags.getInstance().getLogger().info("------------------------------");
|
||||
SupremeTags.getInstance().getLogger().info("H2: Something wrong with connecting to h2-sql for SupremeTags, contact the developer if you see this.");
|
||||
SupremeTags.getInstance().getLogger().info("------------------------------");
|
||||
}
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
public void initialiseDatabase() {
|
||||
PreparedStatement preparedStatement;
|
||||
|
||||
String userTable = "CREATE TABLE IF NOT EXISTS `users` " +
|
||||
"(`Name` VARCHAR(100), `UUID` VARCHAR(100) primary key, `Active` VARCHAR(100))";
|
||||
|
||||
try {
|
||||
preparedStatement = getConnection().prepareStatement(userTable);
|
||||
preparedStatement.executeUpdate();
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String getConnectionURL() {
|
||||
return ConnectionURL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package net.noscape.project.supremetags.storage;
|
||||
|
||||
import net.noscape.project.supremetags.*;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.*;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
public class H2UserData {
|
||||
|
||||
public boolean exists(Player player) {
|
||||
try {
|
||||
PreparedStatement statement = SupremeTags.getDatabase().getConnection().prepareStatement("SELECT * FROM `users` WHERE (UUID=?)");
|
||||
statement.setString(1, player.getUniqueId().toString());
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
|
||||
if (resultSet.next()) {
|
||||
return true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void createPlayer(Player player) {
|
||||
try {
|
||||
if (!exists(player)) {
|
||||
PreparedStatement statement = SupremeTags.getDatabase().getConnection().prepareStatement(
|
||||
"INSERT INTO `users` " +
|
||||
"(Name, UUID, Active) " +
|
||||
"VALUES " +
|
||||
"(?,?,?)");
|
||||
statement.setString(1, player.getName());
|
||||
statement.setString(2, player.getUniqueId().toString());
|
||||
statement.setString(3, SupremeTags.getInstance().getConfig().getString("settings.default-tag"));
|
||||
statement.executeUpdate();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setActive(OfflinePlayer player, String identifier) {
|
||||
try {
|
||||
PreparedStatement statement = SupremeTags.getDatabase().getConnection().prepareStatement("UPDATE `users` SET Active=? WHERE (UUID=?)");
|
||||
statement.setString(1, identifier);
|
||||
statement.setString(2, player.getUniqueId().toString());
|
||||
statement.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getActive(UUID uuid) {
|
||||
try {
|
||||
PreparedStatement statement = SupremeTags.getDatabase().getConnection().prepareStatement("SELECT * FROM `users` WHERE (UUID=?)");
|
||||
statement.setString(1, uuid.toString());
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
|
||||
String value;
|
||||
if (resultSet.next()) {
|
||||
value = resultSet.getString("Active");
|
||||
return value;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package net.noscape.project.supremetags.storage;
|
||||
|
||||
import net.noscape.project.supremetags.*;
|
||||
import org.bukkit.*;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.logging.*;
|
||||
|
||||
public class MySQL {
|
||||
|
||||
private final String host;
|
||||
private final int port;
|
||||
private final String database;
|
||||
private final String username;
|
||||
private final String password;
|
||||
private final String options;
|
||||
|
||||
public Connection connection;
|
||||
private boolean isconnected = false;
|
||||
|
||||
public MySQL(String host, int port, String database, String username, String password, String options) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.database = database;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.options = options;
|
||||
|
||||
this.connect(host, port, database, username, password, true);
|
||||
}
|
||||
|
||||
public void openConnection() throws SQLException {
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
this.connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?" + options, username, password);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void connect(String host, int port, String database, String user, String pass, boolean ssl) {
|
||||
try {
|
||||
synchronized (this) {
|
||||
if (connection != null && !connection.isClosed()) {
|
||||
Logger.getLogger("Error: connection to sql was not successful.");
|
||||
return;
|
||||
}
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
this.connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?useSSL=" + ssl + "&autoReconnect=true", user, pass);
|
||||
this.isconnected = true;
|
||||
createTable();
|
||||
}
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
Bukkit.getConsoleSender().sendMessage("MYSQL: Something wrong with connecting to mysql database type, check mysql data details before contacting the developer if you see this.");
|
||||
}
|
||||
}
|
||||
|
||||
public void createTable() throws SQLException {
|
||||
String userTable = "CREATE TABLE IF NOT EXISTS `users` " +
|
||||
"(`Name` VARCHAR(100), `UUID` VARCHAR(100) primary key, `Active` VARCHAR(100))";
|
||||
|
||||
Statement stmt = connection.createStatement();
|
||||
stmt.execute(userTable);
|
||||
}
|
||||
|
||||
public void updateQuery(String query) {
|
||||
Connection con = connection;
|
||||
PreparedStatement preparedStatement = null;
|
||||
try {
|
||||
preparedStatement = con.prepareStatement(query);
|
||||
preparedStatement.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
closeResources(null, preparedStatement);
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnected() {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
this.connection.close();
|
||||
this.isconnected = false;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public ResultSet executeQuery(String query) {
|
||||
if (isConnected()) {
|
||||
return null;
|
||||
} else {
|
||||
try {
|
||||
this.connection.createStatement().executeQuery(query);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void closeResources(ResultSet rs, PreparedStatement st) {
|
||||
if (rs != null) {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (st != null) {
|
||||
try {
|
||||
st.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return !this.isconnected;
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package net.noscape.project.supremetags.storage;
|
||||
|
||||
import net.noscape.project.supremetags.*;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.*;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
public class MySQLUserData {
|
||||
|
||||
public boolean exists(Player player) {
|
||||
try {
|
||||
PreparedStatement statement = SupremeTags.getMysql().getConnection().prepareStatement("SELECT * FROM `users` WHERE (UUID=?)");
|
||||
statement.setString(1, player.getUniqueId().toString());
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
|
||||
if (resultSet.next()) {
|
||||
return true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void createPlayer(Player player) {
|
||||
try {
|
||||
if (!exists(player)) {
|
||||
PreparedStatement statement = SupremeTags.getMysql().getConnection().prepareStatement(
|
||||
"INSERT INTO `users` " +
|
||||
"(Name, UUID, Active) " +
|
||||
"VALUES " +
|
||||
"(?,?,?)");
|
||||
statement.setString(1, player.getName());
|
||||
statement.setString(2, player.getUniqueId().toString());
|
||||
statement.setString(3, SupremeTags.getInstance().getConfig().getString("settings.default-tag"));
|
||||
statement.executeUpdate();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setActive(OfflinePlayer player, String identifier) {
|
||||
try {
|
||||
PreparedStatement statement = SupremeTags.getMysql().getConnection().prepareStatement("UPDATE `users` SET Active=? WHERE (UUID=?)");
|
||||
statement.setString(1, identifier);
|
||||
statement.setString(2, player.getUniqueId().toString());
|
||||
statement.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getActive(UUID uuid) {
|
||||
try {
|
||||
PreparedStatement statement = SupremeTags.getMysql().getConnection().prepareStatement("SELECT * FROM `users` WHERE (UUID=?)");
|
||||
statement.setString(1, uuid.toString());
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
|
||||
String value;
|
||||
if (resultSet.next()) {
|
||||
value = resultSet.getString("Active");
|
||||
return value;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -4,69 +4,32 @@ import net.noscape.project.supremetags.*;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.*;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
public class UserData {
|
||||
|
||||
public boolean exists(Player player) {
|
||||
try {
|
||||
PreparedStatement statement = SupremeTags.getDatabase().getConnection().prepareStatement("SELECT * FROM `users` WHERE (UUID=?)");
|
||||
statement.setString(1, player.getUniqueId().toString());
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
|
||||
if (resultSet.next()) {
|
||||
return true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void createPlayer(Player player) {
|
||||
try {
|
||||
if (!exists(player)) {
|
||||
PreparedStatement statement = SupremeTags.getDatabase().getConnection().prepareStatement(
|
||||
"INSERT INTO `users` " +
|
||||
"(Name, UUID, Active) " +
|
||||
"VALUES " +
|
||||
"(?,?,?)");
|
||||
statement.setString(1, player.getName());
|
||||
statement.setString(2, player.getUniqueId().toString());
|
||||
statement.setString(3, SupremeTags.getInstance().getConfig().getString("settings.default-tag"));
|
||||
statement.executeUpdate();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
public static void createPlayer(Player player) {
|
||||
if (SupremeTags.getInstance().isH2()) {
|
||||
SupremeTags.getInstance().getUserData().createPlayer(player);
|
||||
} else if (SupremeTags.getInstance().isMySQL()) {
|
||||
SupremeTags.getInstance().getUser().createPlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void setActive(OfflinePlayer player, String identifier) {
|
||||
try {
|
||||
PreparedStatement statement = SupremeTags.getDatabase().getConnection().prepareStatement("UPDATE `users` SET Active=? WHERE (UUID=?)");
|
||||
statement.setString(1, identifier);
|
||||
statement.setString(2, player.getUniqueId().toString());
|
||||
statement.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
if (SupremeTags.getInstance().isH2()) {
|
||||
H2UserData.setActive(player, identifier);
|
||||
} else if (SupremeTags.getInstance().isMySQL()) {
|
||||
MySQLUserData.setActive(player, identifier);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getActive(Player player) {
|
||||
try {
|
||||
PreparedStatement statement = SupremeTags.getDatabase().getConnection().prepareStatement("SELECT * FROM `users` WHERE (UUID=?)");
|
||||
statement.setString(1, player.getUniqueId().toString());
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
|
||||
String value;
|
||||
if (resultSet.next()) {
|
||||
value = resultSet.getString("Active");
|
||||
return value;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public static String getActive(UUID uuid) {
|
||||
if (SupremeTags.getInstance().isH2())
|
||||
return H2UserData.getActive(uuid);
|
||||
else if (SupremeTags.getInstance().isMySQL())
|
||||
return MySQLUserData.getActive(uuid);
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,7 +7,35 @@
|
||||
settings:
|
||||
default-tag: 'none' # set 'none' players start with no tag.
|
||||
forced-tag: false # this will make it force players to have a tag, they won't beable to take the tag off.
|
||||
categories: false # !! THIS IS NOT YET BEEN IMPLEMENTED !!
|
||||
categories: false # should supremetags use the category system?
|
||||
default-category: 'default' # used to set the tags category value when creating a new tag with the '/tag create' command
|
||||
update-check: true # the plugin will check if there is an update available.
|
||||
|
||||
############################################################
|
||||
# +------------------------------------------------------+ #
|
||||
# | Data | #
|
||||
# +------------------------------------------------------+ #
|
||||
############################################################
|
||||
|
||||
# mysql data settings.
|
||||
# make sure you can check your panel database info to make sure everything is correct.
|
||||
data:
|
||||
# types: [H2 OR MYSQL]
|
||||
type: 'H2'
|
||||
|
||||
# The address for the database server.
|
||||
# - to enable this part, change type to 'MYSQL'
|
||||
# - some hosts can use your domain or server ip.
|
||||
address: 'host'
|
||||
# The standard DB engine port is used by default
|
||||
port: 3306
|
||||
# The name of the database to store tag data in.
|
||||
database: 'database'
|
||||
# Credentials for the database.
|
||||
username: 'user'
|
||||
password: 'pass'
|
||||
# leave this, if you don't know how to use options.
|
||||
options: 'useSSL=false&autoReconnect=true'
|
||||
|
||||
############################################################
|
||||
# +------------------------------------------------------+ #
|
||||
@@ -39,13 +67,11 @@ gui:
|
||||
reset-tag-material: 'RED_DYE'
|
||||
close-menu-material: 'BARRIER'
|
||||
create-tag-material: 'NAME_TAG'
|
||||
refresh-material: 'GREEN_DYE'
|
||||
|
||||
############################################################
|
||||
# +------------------------------------------------------+ #
|
||||
# | Categories | #
|
||||
# | !! THIS IS NOT YET BEEN IMPLEMENTED !! | #
|
||||
# | | #
|
||||
# | This can still be pre-edited... | #
|
||||
# | Categories | #
|
||||
# +------------------------------------------------------+ #
|
||||
############################################################
|
||||
|
||||
@@ -54,7 +80,7 @@ categories:
|
||||
title: '&8Default Tags' # title of the category gui.
|
||||
material: 'NAME_TAG' # item material.
|
||||
id_display: '&7&lDefault Tags' # item displayname.
|
||||
slot: 12 # slot this item will be in the main menu.
|
||||
slot: 11 # slot this item will be in the main menu.
|
||||
lore:
|
||||
- '&8&m-----------------------------'
|
||||
- ''
|
||||
@@ -67,7 +93,7 @@ categories:
|
||||
title: '&8Rank Tags' # title of the category gui.
|
||||
material: 'NAME_TAG' # item material.
|
||||
id_display: '&6&lRank Tags' # item displayname.
|
||||
slot: 14 # slot this item will be in the main menu.
|
||||
slot: 13 # slot this item will be in the main menu.
|
||||
lore:
|
||||
- '&8&m-----------------------------'
|
||||
- ''
|
||||
@@ -80,19 +106,18 @@ categories:
|
||||
title: '&8Christmas Tags' # title of the category gui.
|
||||
material: 'NAME_TAG' # item material.
|
||||
id_display: '&c&lChristmas Tags' # item displayname.
|
||||
slot: 16 # slot this item will be in the main menu.
|
||||
slot: 15 # slot this item will be in the main menu.
|
||||
lore:
|
||||
- '&8&m-----------------------------'
|
||||
- ''
|
||||
- '&cDefault tags: &7%tags_amount%'
|
||||
- '&cChristmas tags: &7%tags_amount%'
|
||||
- ''
|
||||
- '&8&m-----------------------------'
|
||||
permission: 'supremetags.category.xmas' # permission players will need to open this menu
|
||||
permission-see-category: false # if set true and if player doesn't have the permission `supremetags.category.<category>` they will not see it.
|
||||
|
||||
############################################################
|
||||
# +------------------------------------------------------+ #
|
||||
# | Tags | #
|
||||
# | Tags | #
|
||||
# +------------------------------------------------------+ #
|
||||
############################################################
|
||||
|
||||
@@ -101,7 +126,7 @@ tags:
|
||||
tag: '&8[&c&lLove&8]' # the tag that will be display for 'legend'
|
||||
permission: 'supremetags.tag.love'
|
||||
description: '&7Love all around you!'
|
||||
category: 'default' # << !! THIS IS NOT YET BEEN IMPLEMENTED !!
|
||||
category: 'default' # << category the tag will be placed inside, if catorgies at the top is enabled.
|
||||
legend:
|
||||
tag: '&8[&6&lLegend&8]' # the tag that will be display for 'legend'
|
||||
permission: 'supremetags.tag.legend'
|
||||
|
||||
Reference in new issue
Block a user