diff --git a/.github/dependabot.yml b/.github/dependabot.yml index d48f8d28..6d09dd62 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,18 +1,18 @@ version: 2 updates: - - package-ecosystem: gradle - target-branch: "development" - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 - ignore: - - dependency-name: org.mariadb.jdbc:mariadb-java-client - versions: - - 2.7.2 - - dependency-name: org.hsqldb:hsqldb - versions: - - 2.5.1 - - dependency-name: com.zaxxer:HikariCP - versions: - - 4.0.1 \ No newline at end of file +- package-ecosystem: gradle + target-branch: "development" + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 4 + ignore: + - dependency-name: org.mariadb.jdbc:mariadb-java-client + versions: + - 2.7.2 + - dependency-name: org.hsqldb:hsqldb + versions: + - 2.5.1 + - dependency-name: com.zaxxer:HikariCP + versions: + - 4.0.1 \ No newline at end of file diff --git a/.gitignore b/.gitignore index dc7bdebf..831749ff 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,15 @@ *.rar # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* \ No newline at end of file +hs_err_pid* + + + + +# Custom files +build/ +.idea/ +gradle/ +.gradle/ +gradlew +gradlew.bat \ No newline at end of file diff --git a/build.gradle b/build.gradle index 16e52884..2d8274e7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,28 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + +import org.apache.tools.ant.filters.ReplaceTokens + plugins { id 'com.github.johnrengelman.shadow' version '6.1.0' id 'java' @@ -78,18 +102,17 @@ dependencies { compileOnly 'com.github.DevLeoko:AdvancedBan:b4bbb6a' compileOnly 'com.discordsrv:discordsrv:1.24.0' compileOnly 'me.clip:placeholderapi:2.9.2' + compileOnly 'com.gitlab.ruany:LiteBansAPI:0.3.4' implementation "org.flywaydb:flyway-core:7.5.3" - implementation "com.squareup.okhttp3:mockwebserver:4.9.2" implementation group: 'org.json', name: 'json', version: '20210307' - implementation 'gui.ava:html2image:2.0.1' - + implementation 'com.github.ben-manes.caffeine:caffeine:3.0.4' } group = 'me.bluetree.discordsrvutils' -version = '1.2.0-BETA-8' +version = '1.2.3-BETA-1' description = 'DiscordSRVUtils' compileJava.options.encoding 'UTF-8' -java.sourceCompatibility = JavaVersion.VERSION_1_8 +java.sourceCompatibility = JavaVersion.VERSION_11 publishing { publications { @@ -97,4 +120,10 @@ publishing { from(components.java) } } +} + +processResources { + from(sourceSets.main.resources.srcDirs) { + filter ReplaceTokens, tokens: [version: version] + } } \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 20e492ab..2697ec0b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + /* * This file was generated by the Gradle 'init' task. */ diff --git a/src/main/java/tk/bluetree242/discordsrvutils/DiscordSRVUtils.java b/src/main/java/tk/bluetree242/discordsrvutils/DiscordSRVUtils.java index c58ad157..492cc2b7 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/DiscordSRVUtils.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/DiscordSRVUtils.java @@ -1,6 +1,27 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils; -import com.vdurmont.emoji.EmojiParser; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; import github.scarsz.discordsrv.DiscordSRV; @@ -8,14 +29,18 @@ import github.scarsz.discordsrv.dependencies.jda.api.OnlineStatus; import github.scarsz.discordsrv.dependencies.jda.api.entities.*; import github.scarsz.discordsrv.dependencies.jda.api.hooks.ListenerAdapter; +import github.scarsz.discordsrv.dependencies.jda.api.interactions.components.Button; import github.scarsz.discordsrv.dependencies.jda.api.requests.GatewayIntent; import github.scarsz.discordsrv.dependencies.jda.api.requests.RestAction; +import github.scarsz.discordsrv.dependencies.okhttp3.*; import github.scarsz.discordsrv.dependencies.jda.api.utils.cache.CacheFlag; -import okhttp3.*; + + import org.bstats.bukkit.Metrics; +import org.bstats.charts.AdvancedPie; +import org.bstats.charts.SimplePie; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.command.CommandMap; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; @@ -38,16 +63,23 @@ import tk.bluetree242.discordsrvutils.leveling.listeners.bukkit.BukkitLevelingListener; import tk.bluetree242.discordsrvutils.leveling.listeners.jda.DiscordLevelingListener; import tk.bluetree242.discordsrvutils.listeners.afk.EssentialsAFKListener; +import tk.bluetree242.discordsrvutils.listeners.bukkit.JoinUpdateChecker; import tk.bluetree242.discordsrvutils.listeners.discordsrv.DiscordSRVListener; +import tk.bluetree242.discordsrvutils.listeners.jda.CustomDiscordAccountLinkListener; import tk.bluetree242.discordsrvutils.listeners.jda.WelcomerAndGoodByeListener; import tk.bluetree242.discordsrvutils.listeners.punishments.advancedban.AdvancedBanPunishmentListener; +import tk.bluetree242.discordsrvutils.listeners.punishments.litebans.LitebansPunishmentListener; import tk.bluetree242.discordsrvutils.messages.MessageManager; +import tk.bluetree242.discordsrvutils.suggestions.Suggestion; import tk.bluetree242.discordsrvutils.suggestions.SuggestionManager; -import tk.bluetree242.discordsrvutils.suggestions.listeners.SuggestionReactionListener; +import tk.bluetree242.discordsrvutils.suggestions.listeners.SuggestionVoteListener; +import tk.bluetree242.discordsrvutils.tickets.Panel; import tk.bluetree242.discordsrvutils.tickets.TicketManager; import tk.bluetree242.discordsrvutils.tickets.listeners.PanelReactListener; import tk.bluetree242.discordsrvutils.tickets.listeners.TicketCloseListener; import tk.bluetree242.discordsrvutils.tickets.listeners.TicketDeleteListener; +import tk.bluetree242.discordsrvutils.utils.FileWriter; +import tk.bluetree242.discordsrvutils.utils.SuggestionVoteMode; import tk.bluetree242.discordsrvutils.utils.Utils; import tk.bluetree242.discordsrvutils.waiter.WaiterManager; import tk.bluetree242.discordsrvutils.waiters.listeners.CreatePanelListener; @@ -63,10 +95,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.*; import java.util.function.Consumer; import java.util.function.Supplier; @@ -78,6 +107,8 @@ public class DiscordSRVUtils extends JavaPlugin { public static DiscordSRVUtils get() { return instance; } + public JSONObject levelingRolesRaw; + public boolean removedDiscordSRVAccountLinkListener = false; private ConfManager configmanager = ConfManager.create(getDataFolder().toPath(), "config.yml", Config.class); private Config config; public final String fileseparator = System.getProperty("file.separator"); @@ -93,12 +124,14 @@ public static DiscordSRVUtils get() { private ConfManager suggestionsConfigManager = ConfManager.create(getDataFolder().toPath(), "suggestions.yml", SuggestionsConfig.class); private SuggestionsConfig suggestionsConfig; public final Map defaultmessages = new HashMap<>(); + public SuggestionVoteMode voteMode; private ExecutorService pool = Executors.newFixedThreadPool(3, new ThreadFactory() { @Override public Thread newThread(@NotNull Runnable r) { Thread thread = new Thread(r); thread.setName("DSU-THREAD"); thread.setDaemon(true); + thread.setUncaughtExceptionHandler((t, e) -> defaultHandle(e)); return thread; } }); @@ -125,7 +158,8 @@ private void init() { listeners.add(new TicketCloseListener()); listeners.add(new EditPanelListener()); listeners.add(new DiscordLevelingListener()); - listeners.add(new SuggestionReactionListener()); + listeners.add(new SuggestionVoteListener()); + listeners.add(new CustomDiscordAccountLinkListener()); initDefaultMessages(); } @@ -141,23 +175,40 @@ public void onLoad() { public void onEnable() { Bukkit.getScheduler().runTaskAsynchronously(this, ()-> { try { + if (!isEnabled()) return; OkHttpClient client = new OkHttpClient(); MultipartBody form = new MultipartBody.Builder().setType(MediaType.get("multipart/form-data")).addFormDataPart("version", getDescription().getVersion()) .build(); - Request req = new Request.Builder().url("https://discordsrvutils.ml/updatecheck").post(form).build(); + Request req = new Request.Builder().url("https://discordsrvutils.xyz/updatecheck").post(form).build(); Response response = client.newCall(req).execute(); JSONObject res = new JSONObject(response.body().string()); response.close(); int versions_behind = res.getInt("versions_behind"); + String logger = res.getString("type") != null ? res.getString("type") :"INFO"; + String msg = null; if (res.isNull("message")) { if (versions_behind != 0) { - logger.info(ChatColor.GREEN + "Plugin is " + versions_behind + " versions behind. Please Update. Download from " + res.getString("downloadUrl")); + if (logger.equalsIgnoreCase("INFO")) { + + } + msg = (ChatColor.GREEN + "Plugin is " + versions_behind + " versions behind. Please Update. Download from " + res.getString("downloadUrl")); } else { - logger.info(ChatColor.GREEN + "Plugin is up to date!"); + msg = (ChatColor.GREEN + "Plugin is up to date!"); } } else { - logger.info(res.getString("message")); + msg = (res.getString("message")); + } + switch (logger) { + case "INFO": + getLogger().info(msg); + break; + case "WARNING": + getLogger().warning(msg); + break; + case "ERROR": + getLogger().warning(msg); + break; } } catch (Exception e) { logger.severe("Could not check for updates: " + e.getMessage()); @@ -188,9 +239,16 @@ public void onEnable() { "| &cStorage: &r" + storage + "\n&r" + "| &cSupport:\n&r" + "| &cGithub: &rhttps://github.com/BlueTree242/DiscordSRVUtils/issues\n" + - "| &cDiscord: &rhttps://discordsrvutils.ml/support\n" + + "| &cDiscord: &rhttps://discordsrvutils.xyz/support\n" + "[]================================[]")); System.setProperty("hsqldb.reconfig_logging", "false"); + try { + Class.forName("github.scarsz.discordsrv.dependencies.jda.api.events.interaction.ButtonClickEvent"); + } catch (ClassNotFoundException e) { + severe("Plugin could not enable because DiscordSRV is missing an important feature (buttons). This means your DiscordSRV is out of date please update it for DSU to work"); + setEnabled(false); + return; + } Class.forName("tk.bluetree242.discordsrvutils.dependencies.hsqldb.jdbc.JDBCDriver"); registerBukkitCommands(); @@ -207,6 +265,18 @@ public void onEnable() { } whenStarted(); Metrics metrics = new Metrics(this, 9456); + metrics.addCustomChart(new AdvancedPie("features", () -> { + Map valueMap = new HashMap<>(); + if (!TicketManager.get().getPanels().get().isEmpty()) + valueMap.put("Tickets", 1); + if (getLevelingConfig().enabled()) valueMap.put("Leveling", 1); + if (getSuggestionsConfig().enabled()) valueMap.put("Suggestions", 1); + if (getMainConfig().welcomer_enabled()) valueMap.put("Welcomer", 1); + if (getServer().getPluginManager().isPluginEnabled("Essentials") && getMainConfig().afk_message_enabled()) valueMap.put("AFK Messages", 1); + return valueMap; + })); + metrics.addCustomChart(new SimplePie("discordsrv_versions", () -> DiscordSRV.getPlugin().getDescription().getVersion())); + metrics.addCustomChart(new SimplePie("admins", () -> getAdminIds().size() + "")); } catch (Throwable ex) { throw new StartupException(ex); } @@ -315,7 +385,7 @@ private void initDefaultMessages() { JSONObject panelEmbed = new JSONObject(); panelEmbed.put("color", "cyan"); panelEmbed.put("title", "[panel.name]"); - panelEmbed.put("description", "React with \uD83C\uDFAB to open a ticket"); + panelEmbed.put("description", "Click on The Button to open a ticket"); panel.put("embed", panelEmbed); defaultmessages.put("panel", panel.toString(1)); JSONObject ticketOpened = new JSONObject(); @@ -323,7 +393,7 @@ private void initDefaultMessages() { ticketOpened.put("content", "[user.asMention] Here is your ticket"); ticketOpenedEmbed.put("description", String.join("\n", new String[]{ "Staff will be here shortly", - "React with \uD83D\uDD12 to close this ticket", + "Click `Close Ticket` to close this ticket", "**Panel Name: **[panel.name]" })); ticketOpenedEmbed.put("color", "green"); @@ -465,12 +535,35 @@ private void whenStarted() { } }); } + try { + File levelingRoles = new File(getDataFolder() + fileseparator + "leveling-roles.json"); + if (!levelingRoles.exists()) { + levelingRoles.createNewFile(); + FileWriter writer = new FileWriter(levelingRoles); + writer.write("{}"); + writer.close(); + levelingRolesRaw = new JSONObject(); + } else { + levelingRolesRaw = new JSONObject(Utils.readFile(levelingRoles)); + } + }catch (FileNotFoundException e) { + logger.severe("Error creating leveling-roles.json"); + } catch (IOException e) { + logger.severe("Error creating leveling-roles.json"); + } + + if (getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) { + new PAPIExpansion().register(); + } + + } public void registerListeners() { getJDA().addEventListener(listeners.toArray(new Object[0])); Bukkit.getServer().getPluginManager().registerEvents(new BukkitLevelingListener(), this); + Bukkit.getServer().getPluginManager().registerEvents(new JoinUpdateChecker(), this); } public void registerCommands() { @@ -511,6 +604,16 @@ public void reloadConfigs() throws IOException, InvalidConfigException { levelingConfig = levelingconfigManager.reloadConfigData(); suggestionsConfigManager.reloadConfig(); suggestionsConfig = suggestionsConfigManager.reloadConfigData(); + File levelingRoles = new File(getDataFolder() + fileseparator + "leveling-roles.json"); + if (!levelingRoles.exists()) { + levelingRoles.createNewFile(); + FileWriter writer = new FileWriter(levelingRoles); + writer.write("{}"); + writer.close(); + levelingRolesRaw = new JSONObject(); + } else { + levelingRolesRaw = new JSONObject(Utils.readFile(levelingRoles)); + } setSettings(); } @@ -543,31 +646,41 @@ public void executeAsync(Runnable r) { } public void whenReady() { - registerCommands(); - setSettings(); - registerListeners(); - if (getServer().getPluginManager().isPluginEnabled("Essentials")) { - getServer().getPluginManager().registerEvents(new EssentialsAFKListener(), this); - hookedPlugins.add(getServer().getPluginManager().getPlugin("Essentials")); - } - if (getServer().getPluginManager().isPluginEnabled("AdvancedBan")) { - getServer().getPluginManager().registerEvents(new AdvancedBanPunishmentListener(), this); - hookedPlugins.add(getServer().getPluginManager().getPlugin("AdvancedBan")); - } - if (getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) { - hookedPlugins.add(getServer().getPluginManager().getPlugin("PlaceholderAPI")); - } - if (getMainConfig().remove_discordsrv_link_listener()) { - for (Object listener : getJDA().getEventManager().getRegisteredListeners()) { - if (listener.getClass().getName().equals("github.scarsz.discordsrv.listeners.DiscordAccountLinkListener")) { - getJDA().removeEventListener(listener); + executeAsync(() -> { + registerCommands(); + setSettings(); + registerListeners(); + if (getServer().getPluginManager().isPluginEnabled("Essentials")) { + getServer().getPluginManager().registerEvents(new EssentialsAFKListener(), this); + hookedPlugins.add(getServer().getPluginManager().getPlugin("Essentials")); + } + if (getServer().getPluginManager().isPluginEnabled("AdvancedBan")) { + getServer().getPluginManager().registerEvents(new AdvancedBanPunishmentListener(), this); + hookedPlugins.add(getServer().getPluginManager().getPlugin("AdvancedBan")); + } + if (getServer().getPluginManager().isPluginEnabled("Litebans")) { + new LitebansPunishmentListener(); + hookedPlugins.add(getServer().getPluginManager().getPlugin("Litebans")); + } + if (getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) { + hookedPlugins.add(getServer().getPluginManager().getPlugin("PlaceholderAPI")); + } + if (getMainConfig().remove_discordsrv_link_listener()) { + for (Object listener : getJDA().getEventManager().getRegisteredListeners()) { + if (listener.getClass().getName().equals("github.scarsz.discordsrv.listeners.DiscordAccountLinkListener")) { + getJDA().removeEventListener(listener); + removedDiscordSRVAccountLinkListener = true; + } } } - } - fixTickets(); - logger.info("Plugin is ready to function."); + fixTickets(); + voteMode = SuggestionVoteMode.valueOf(suggestionsConfig.suggestions_vote_mode().toUpperCase()) == null ? SuggestionVoteMode.REACTIONS : SuggestionVoteMode.valueOf(suggestionsConfig.suggestions_vote_mode().toUpperCase()); + doSuggestions(); + logger.info("Plugin is ready to function."); + }); + } - public void fixTickets() { + private void fixTickets() { try (Connection conn = getDatabase()) { PreparedStatement p1 = conn.prepareStatement("SELECT * FROM tickets"); ResultSet r1 = p1.executeQuery(); @@ -579,15 +692,74 @@ public void fixTickets() { p.execute(); } } + p1 = conn.prepareStatement("SELECT * FROM ticket_panels"); + r1 = p1.executeQuery(); + while (r1.next()) { + Panel panel = TicketManager.get().getPanel(r1); + Message msg = getGuild().getTextChannelById(panel.getChannelId()).retrieveMessageById(panel.getMessageId()).complete(); + if (msg.getButtons().isEmpty()) { + msg.clearReactions().queue(); + msg.editMessage(msg).setActionRow(Button.secondary("open_ticket", Emoji.fromUnicode("\uD83C\uDFAB")).withLabel("Open Ticket")).queue(); + } + } + } catch (SQLException e) { + throw new UnCheckedSQLException(e); + } + } + + private void doSuggestions() { + String warnmsg = "Suggestions are being migrated to the new Suggestions Mode. Users may not vote for suggestions during this time"; + boolean sent = false; + try (Connection conn = getDatabase()) { + PreparedStatement p1 = conn.prepareStatement("SELECT * FROM suggestions"); + ResultSet r1 = p1.executeQuery(); + while (r1.next()) { + Suggestion suggestion = SuggestionManager.get().getSuggestion(r1); + Message msg = suggestion.getMessage(); + if (msg != null) { + if (msg.getButtons().isEmpty()) { + if (voteMode == SuggestionVoteMode.REACTIONS) { + } else { + if (!sent) { + logger.info(warnmsg); + sent = true; + SuggestionManager.get().loading = true; + } + msg.clearReactions().queue(); + msg.editMessage(suggestion.getCurrentMsg()).setActionRow( + Button.success("yes", SuggestionManager.getYesEmoji().toJDAEmoji()), + Button.danger("no", SuggestionManager.getNoEmoji().toJDAEmoji()), + Button.secondary("reset", Emoji.fromUnicode("⬜"))).queue(); + } + } else { + if (voteMode == SuggestionVoteMode.REACTIONS) { + if (!sent) { + SuggestionManager.get().loading = true; + logger.info(warnmsg); + sent = true; + } + msg.addReaction(SuggestionManager.getYesEmoji().getNameInReaction()).queue(); + msg.addReaction(SuggestionManager.getNoEmoji().getNameInReaction()).queue(); + msg.editMessage(msg).setActionRows(Collections.EMPTY_LIST).queue(); + } + } + } + } + if (sent) { + logger.info("Suggestions Migration has finished."); + } + SuggestionManager.get().loading = false; } catch (SQLException e) { throw new UnCheckedSQLException(e); } } + public void setSettings() { if (!isReady()) return; OnlineStatus onlineStatus = getMainConfig().onlinestatus().equalsIgnoreCase("DND") ? OnlineStatus.DO_NOT_DISTURB : OnlineStatus.valueOf(getMainConfig().onlinestatus().toUpperCase()); getJDA().getPresence().setStatus(onlineStatus); + LevelingManager.get().cachedUUIDS.refreshAll(LevelingManager.get().cachedUUIDS.asMap().keySet()); } public JDA getJDA() { @@ -652,11 +824,11 @@ public Guild getGuild() { } public CompletableFuture completableFuture(Supplier v) { - return CompletableFuture.supplyAsync(v); + return CompletableFuture.supplyAsync(v, pool); } public CompletableFuture completableFutureRun(Runnable r) { - return CompletableFuture.runAsync(r); + return CompletableFuture.runAsync(r, pool); } public RestAction queueMsg(Message msg, MessageChannel channel) { @@ -690,11 +862,16 @@ public U handleCFOnAnother(CompletableFuture cf) { } public void defaultHandle(Throwable ex, MessageChannel channel) { channel.sendMessage(Embed.error("An error happened. Check Console for details")).queue(); + logger.severe("The following error have a high chance to be caused by DiscordSRVUtils. Report at https://discordsrvutils.xyz/support and not discordsrv's Discord."); ex.printStackTrace(); } public void defaultHandle(Throwable ex) { - ex.printStackTrace(); - //Do nothing lol + if (!config.minimize_errors()) { + logger.severe("The following error have a high chance to be caused by DiscordSRVUtils. Report at https://discordsrvutils.xyz/support and not discordsrv's Discord."); + ex.printStackTrace(); + } else { + logger.severe("DiscordSRVUtils had an error. Error minimization enabled."); + } } diff --git a/src/main/java/tk/bluetree242/discordsrvutils/FileWriter.java b/src/main/java/tk/bluetree242/discordsrvutils/FileWriter.java deleted file mode 100644 index 9f450e96..00000000 --- a/src/main/java/tk/bluetree242/discordsrvutils/FileWriter.java +++ /dev/null @@ -1,19 +0,0 @@ -package tk.bluetree242.discordsrvutils; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.OutputStreamWriter; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; - -public class FileWriter extends OutputStreamWriter { - - public FileWriter(File file, Charset charset) throws FileNotFoundException { - super(new FileOutputStream(file), charset); - } - - public FileWriter(File file) throws FileNotFoundException { - super(new FileOutputStream(file), StandardCharsets.UTF_8); - } -} diff --git a/src/main/java/tk/bluetree242/discordsrvutils/PAPIExpansion.java b/src/main/java/tk/bluetree242/discordsrvutils/PAPIExpansion.java new file mode 100644 index 00000000..e41ac52e --- /dev/null +++ b/src/main/java/tk/bluetree242/discordsrvutils/PAPIExpansion.java @@ -0,0 +1,68 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + +package tk.bluetree242.discordsrvutils; + +import me.clip.placeholderapi.expansion.PlaceholderExpansion; +import org.bukkit.entity.Player; +import tk.bluetree242.discordsrvutils.leveling.LevelingManager; + +import java.util.regex.Pattern; + +public class PAPIExpansion extends PlaceholderExpansion { + private DiscordSRVUtils core = DiscordSRVUtils.get(); + @Override + public String getIdentifier() { + return "DiscordSRVUtils"; + } + + @Override + public boolean canRegister() { + return DiscordSRVUtils.get().isEnabled(); + } + + @Override + public String getAuthor() { + return String.join( ", ", core.getDescription().getAuthors()); + } + + @Override + public String getVersion() { + return core.getDescription().getVersion(); + } + + @Override + public String onPlaceholderRequest(Player p, String identifier) { + identifier = identifier.toLowerCase(); + if (identifier.equalsIgnoreCase("level")) { + if (p == null) return "Unknown"; + return LevelingManager.get().getCachedStats(p.getUniqueId()).getLevel() + ""; + } else if (identifier.equalsIgnoreCase("xp")) { + if (p == null) return "Unknown"; + return LevelingManager.get().getCachedStats(p.getUniqueId()).getXp() + ""; + } else if (identifier.equalsIgnoreCase("rank")) { + if (p == null) return "Unknown"; + return LevelingManager.get().getCachedStats(p.getUniqueId()).getRank() + ""; + } + return null; + } +} diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/BukkitCommand.java b/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/BukkitCommand.java index 16b1481d..899f77a1 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/BukkitCommand.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/BukkitCommand.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commandmanagement; import org.bukkit.command.Command; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/Command.java b/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/Command.java index 5f054f10..94e41d93 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/Command.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/Command.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commandmanagement; import github.scarsz.discordsrv.dependencies.jda.api.EmbedBuilder; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/CommandCategory.java b/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/CommandCategory.java index 6196520f..06c7659b 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/CommandCategory.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/CommandCategory.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commandmanagement; import java.util.*; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/CommandEvent.java b/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/CommandEvent.java index a7e2acc4..4a92b49b 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/CommandEvent.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/CommandEvent.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commandmanagement; @@ -116,13 +138,13 @@ public CompletableFuture handleCF(CompletableFuture cf, boolean shouldDM, String }).handleAsync((e, x) -> { Exception ex = (Exception) ((Throwable) x).getCause(); while (ex instanceof ExecutionException) ex = (Exception) ex.getCause(); - ex.printStackTrace(); MessageChannel channel = shouldDM ? getAuthor().openPrivateChannel().complete() : getChannel(); if (ex instanceof UnCheckedRateLimitedException) { channel.sendMessage(Embed.error(failure, "Rate limited. Try again in: " + Utils.getDuration(((RateLimitedException) ((UnCheckedRateLimitedException) ex).getCause()).getRetryAfter()))).queue(); } else if (!(ex instanceof InsufficientPermissionException)) { channel.sendMessage(Embed.error(failure)).queue(); + DiscordSRVUtils.get().defaultHandle(ex); } else { InsufficientPermissionException exc = (InsufficientPermissionException) ex; GuildChannel chnl = DiscordSRVUtils.get().getJDA().getShardManager().getGuildChannelById(exc.getChannelId()); @@ -141,13 +163,13 @@ public CompletableFuture handleCF(CompletableFuture cf, boolean should cf.handleAsync((e, x) -> { Exception ex = (Exception) ((Throwable) x).getCause(); while (ex instanceof ExecutionException) ex = (Exception) ex.getCause(); - ex.printStackTrace(); MessageChannel channel = shouldDM ? getAuthor().openPrivateChannel().complete() : getChannel(); if (ex instanceof UnCheckedRateLimitedException) { channel.sendMessage(Embed.error(failure, "Rate limited. Try again in: " + Utils.getDuration(((RateLimitedException) ((UnCheckedRateLimitedException) ex).getCause()).getRetryAfter()))).queue(); } else if (!(ex instanceof InsufficientPermissionException)) { channel.sendMessage(Embed.error(failure)).queue(); + DiscordSRVUtils.get().defaultHandle(ex); } else { InsufficientPermissionException exc = (InsufficientPermissionException) ex; GuildChannel chnl = DiscordSRVUtils.get().getJDA().getGuildChannelById(exc.getChannelId()); diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/CommandListener.java b/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/CommandListener.java index 3e679d1e..3ece84cc 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/CommandListener.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/CommandListener.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commandmanagement; import github.scarsz.discordsrv.dependencies.jda.api.Permission; @@ -7,24 +29,24 @@ import github.scarsz.discordsrv.dependencies.jda.api.events.message.MessageUpdateEvent; import github.scarsz.discordsrv.dependencies.jda.api.exceptions.InsufficientPermissionException; import github.scarsz.discordsrv.dependencies.jda.api.hooks.ListenerAdapter; -import org.w3c.dom.Text; import tk.bluetree242.discordsrvutils.DiscordSRVUtils; import tk.bluetree242.discordsrvutils.embeds.Embed; import java.util.regex.Pattern; public class CommandListener extends ListenerAdapter { - private final DiscordSRVUtils main = DiscordSRVUtils.get(); + private final DiscordSRVUtils core = DiscordSRVUtils.get(); public void onMessageReceived(MessageReceivedEvent e) { - main.executeAsync(() -> { + if (core.getMainConfig().bungee_mode()) return; + core.executeAsync(() -> { if (e.getMessage().isWebhookMessage() || e.getAuthor().isBot()) return; String[] args = e.getMessage().getContentRaw().split(" "); String cmd = args[0].toLowerCase(); - if (cmd.startsWith(main.getCommandPrefix())) { - cmd = cmd.replaceFirst(Pattern.quote(main.getCommandPrefix()), ""); + if (cmd.startsWith(core.getCommandPrefix())) { + cmd = cmd.replaceFirst(Pattern.quote(core.getCommandPrefix()), ""); Command executor = CommandManager.get().getCommandHashMap().get(cmd); if (executor == null) return; try { @@ -60,8 +82,8 @@ public void onMessageReceived(MessageReceivedEvent e) { } } if (executor.isAdminOnly()) { - if (!main.isAdmin(e.getAuthor().getIdLong())) { - e.getMessage().reply(Embed.error("Only Admins can use this command.")).queue(); + if (!core.isAdmin(e.getAuthor().getIdLong())) { + e.getMessage().reply(Embed.error("Only Admins can use this command.", "Your id must be in admin list on the config.yml")).queue(); return; } } @@ -75,7 +97,7 @@ public void onMessageReceived(MessageReceivedEvent e) { return; } } - main.getLogger().info(e.getAuthor().getAsTag() + " Used " + main.getCommandPrefix() + cmd + " Command"); + core.getLogger().info(e.getAuthor().getAsTag() + " Used " + core.getCommandPrefix() + cmd + " Command"); executor.run(new CommandEvent(e.getMember(), e.getMessage(), e.getAuthor(), e.getChannel(), e.getJDA())); } catch (InsufficientPermissionException ex) { ex.printStackTrace(); diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/CommandManager.java b/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/CommandManager.java index 2bf12202..b3466a06 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/CommandManager.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/CommandManager.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commandmanagement; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/CommandType.java b/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/CommandType.java index 74fbc36b..e63f3a1c 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/CommandType.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commandmanagement/CommandType.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commandmanagement; public enum CommandType { diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commands/bukkit/DiscordSRVUtilsCommand.java b/src/main/java/tk/bluetree242/discordsrvutils/commands/bukkit/DiscordSRVUtilsCommand.java index 1ebc3bb3..8f33e172 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commands/bukkit/DiscordSRVUtilsCommand.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commands/bukkit/DiscordSRVUtilsCommand.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commands.bukkit; import org.bukkit.ChatColor; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commands/bukkit/tabcompleters/DiscordSRVUtilsTabCompleter.java b/src/main/java/tk/bluetree242/discordsrvutils/commands/bukkit/tabcompleters/DiscordSRVUtilsTabCompleter.java index d6a559f1..6ba69ea8 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commands/bukkit/tabcompleters/DiscordSRVUtilsTabCompleter.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commands/bukkit/tabcompleters/DiscordSRVUtilsTabCompleter.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commands.bukkit.tabcompleters; import org.bukkit.command.Command; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/ApproveSuggestionCommand.java b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/ApproveSuggestionCommand.java index 15ce1319..46ba0817 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/ApproveSuggestionCommand.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/ApproveSuggestionCommand.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commands.discord; import github.scarsz.discordsrv.dependencies.jda.api.Permission; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/CloseCommand.java b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/CloseCommand.java index 34dff190..53ea329a 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/CloseCommand.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/CloseCommand.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commands.discord; import github.scarsz.discordsrv.dependencies.jda.api.Permission; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/CreatePanelCommand.java b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/CreatePanelCommand.java index 4ec5bcd5..507e1922 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/CreatePanelCommand.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/CreatePanelCommand.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commands.discord; import github.scarsz.discordsrv.dependencies.jda.api.EmbedBuilder; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/DeletePanelCommand.java b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/DeletePanelCommand.java index fc2250f2..9ec2173d 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/DeletePanelCommand.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/DeletePanelCommand.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commands.discord; import github.scarsz.discordsrv.dependencies.jda.api.EmbedBuilder; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/DenySuggestionCommand.java b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/DenySuggestionCommand.java index af904c39..8f5bb346 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/DenySuggestionCommand.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/DenySuggestionCommand.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commands.discord; import tk.bluetree242.discordsrvutils.commandmanagement.Command; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/EditPanelCommand.java b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/EditPanelCommand.java index d522af06..2c1220d2 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/EditPanelCommand.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/EditPanelCommand.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commands.discord; import github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/HelpCommand.java b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/HelpCommand.java index fbd388c8..91b06cfe 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/HelpCommand.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/HelpCommand.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commands.discord; import github.scarsz.discordsrv.dependencies.jda.api.EmbedBuilder; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/LeaderboardCommand.java b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/LeaderboardCommand.java index 6d7651ff..f9ac10ce 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/LeaderboardCommand.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/LeaderboardCommand.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commands.discord; import github.scarsz.discordsrv.dependencies.jda.api.EmbedBuilder; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/LevelCommand.java b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/LevelCommand.java index 99572c02..daf64e44 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/LevelCommand.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/LevelCommand.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commands.discord; import github.scarsz.discordsrv.dependencies.jda.api.Permission; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/PanelListCommand.java b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/PanelListCommand.java index 3a29677e..aa423e39 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/PanelListCommand.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/PanelListCommand.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commands.discord; import github.scarsz.discordsrv.dependencies.jda.api.EmbedBuilder; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/ReopenCommand.java b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/ReopenCommand.java index 8110a9be..f3476f0f 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/ReopenCommand.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/ReopenCommand.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commands.discord; import tk.bluetree242.discordsrvutils.DiscordSRVUtils; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/SuggestCommand.java b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/SuggestCommand.java index 4489d2fd..31a727f5 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/SuggestCommand.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/SuggestCommand.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commands.discord; import github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel; @@ -38,6 +60,11 @@ public void run(CommandEvent e) throws Exception { return; } + if (e.getMember().getRoles().contains(core.getGuild().getRoleById(core.getSuggestionsConfig().suggestion_muted_role()))) { + e.replyErr("You are suggestion muted").queue(); + return; + } + Long val = antispamMap.get(e.getAuthor().getIdLong()); if (val == null) { } else { diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/SuggestionNoteCommand.java b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/SuggestionNoteCommand.java index e8873c09..aa81db03 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/SuggestionNoteCommand.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/SuggestionNoteCommand.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commands.discord; import github.scarsz.discordsrv.dependencies.jda.api.Permission; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/TestMessageCommand.java b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/TestMessageCommand.java index 7091e794..8e6a0e95 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/TestMessageCommand.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/TestMessageCommand.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.commands.discord; import org.json.JSONException; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/config/ConfManager.java b/src/main/java/tk/bluetree242/discordsrvutils/config/ConfManager.java index b4ebf449..56c31c2f 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/config/ConfManager.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/config/ConfManager.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.config; import space.arim.dazzleconf.ConfigurationFactory; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/config/Config.java b/src/main/java/tk/bluetree242/discordsrvutils/config/Config.java index 04803ea8..efa8cfff 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/config/Config.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/config/Config.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.config; @@ -28,10 +50,16 @@ public interface Config { @AnnotationBasedSorter.Order(31) @ConfKey("remove-discordsrv-link-listener") - @ConfComments("#Should we remove DiscordSRV's account link listener?? bot won't respond to dm link codes") + @ConfComments("#Should we remove DiscordSRV's account link listener?? bot won't respond to dm link codes\n#NOTE: Plugin uses reflection to do this. Which is like hacking into DiscordSRV") @ConfDefault.DefaultBoolean(false) boolean remove_discordsrv_link_listener(); + @AnnotationBasedSorter.Order(32) + @ConfKey("linkaccount-channel") + @ConfComments("#Custom LinkAccount Channel. ") + @ConfDefault.DefaultLong(0) + long linkaccount_channel(); + @AnnotationBasedSorter.Order(40) @ConfKey("welcomer.enabled") @ConfComments("#Should we do Welcomer?") @@ -104,4 +132,16 @@ public interface Config { @ConfDefault.DefaultString("message:no-longer-afk") String no_longer_afk_message(); + @AnnotationBasedSorter.Order(150) + @ConfKey("bungee-mode") + @ConfComments("# Bungee Mode. This will make bot not respond to commands, and nothing will happen as if plugin not installed (only mc leveling is active). This option should be enabled on all servers except lobby if you use bungee") + @ConfDefault.DefaultBoolean(false) + Boolean bungee_mode(); + + @AnnotationBasedSorter.Order(160) + @ConfKey("minimize-errors") + @ConfComments("# Replace errors with small error note. Please note that this is a bad practise. If your console is spammed with errors (by this plugin) Please report at https://discordsrvutils.xyz/support") + @ConfDefault.DefaultBoolean(false) + Boolean minimize_errors(); + } diff --git a/src/main/java/tk/bluetree242/discordsrvutils/config/LevelingConfig.java b/src/main/java/tk/bluetree242/discordsrvutils/config/LevelingConfig.java index fb928210..50d29b5b 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/config/LevelingConfig.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/config/LevelingConfig.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.config; import space.arim.dazzleconf.annote.ConfComments; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/config/PunishmentsIntegrationConfig.java b/src/main/java/tk/bluetree242/discordsrvutils/config/PunishmentsIntegrationConfig.java index b1854982..6ff82ca8 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/config/PunishmentsIntegrationConfig.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/config/PunishmentsIntegrationConfig.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.config; import space.arim.dazzleconf.annote.ConfComments; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/config/SQLConfig.java b/src/main/java/tk/bluetree242/discordsrvutils/config/SQLConfig.java index 18695cb2..749dec42 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/config/SQLConfig.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/config/SQLConfig.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.config; import space.arim.dazzleconf.annote.ConfComments; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/config/SuggestionsConfig.java b/src/main/java/tk/bluetree242/discordsrvutils/config/SuggestionsConfig.java index b47f1601..5b3fb3da 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/config/SuggestionsConfig.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/config/SuggestionsConfig.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.config; import space.arim.dazzleconf.annote.ConfComments; @@ -40,10 +62,6 @@ public interface SuggestionsConfig { @ConfDefault.DefaultBoolean(false) Boolean allow_submitter_vote(); - @AnnotationBasedSorter.Order(50) - @ConfComments("# Should users be able to vote both yes and no?") - @ConfDefault.DefaultBoolean(false) - Boolean allow_both_vote(); @AnnotationBasedSorter.Order(60) @@ -82,4 +100,14 @@ public interface SuggestionsConfig { @ConfDefault.DefaultBoolean(false) Boolean dm_submitter_when_approved(); */ + + @AnnotationBasedSorter.Order(120) + @ConfComments("# Role that if user have they can't make suggestions") + @ConfDefault.DefaultLong(0) + Long suggestion_muted_role(); + + @AnnotationBasedSorter.Order(130) + @ConfComments("# Mode of the suggestions. Set to BUTTONS to make it use buttons instead of reactions/n# Note that changing this is not affected until server restart./n#Another note is that your votes will be reset by changing this") + @ConfDefault.DefaultString("REACTIONS") + String suggestions_vote_mode(); } diff --git a/src/main/java/tk/bluetree242/discordsrvutils/config/TicketsConfig.java b/src/main/java/tk/bluetree242/discordsrvutils/config/TicketsConfig.java index 6bce7d77..d71e5e54 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/config/TicketsConfig.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/config/TicketsConfig.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.config; import space.arim.dazzleconf.annote.ConfComments; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/embeds/Embed.java b/src/main/java/tk/bluetree242/discordsrvutils/embeds/Embed.java index 86758a54..a63da199 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/embeds/Embed.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/embeds/Embed.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.embeds; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/events/DiscordLevelupEvent.java b/src/main/java/tk/bluetree242/discordsrvutils/events/DiscordLevelupEvent.java index f69ba26b..3c766ab1 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/events/DiscordLevelupEvent.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/events/DiscordLevelupEvent.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.events; import github.scarsz.discordsrv.api.events.Event; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/events/MinecraftLevelupEvent.java b/src/main/java/tk/bluetree242/discordsrvutils/events/MinecraftLevelupEvent.java index c4a0fed0..dafc1163 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/events/MinecraftLevelupEvent.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/events/MinecraftLevelupEvent.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.events; import github.scarsz.discordsrv.api.events.Event; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/exceptions/ConfigurationLoadException.java b/src/main/java/tk/bluetree242/discordsrvutils/exceptions/ConfigurationLoadException.java index 2fd7396c..6dd78835 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/exceptions/ConfigurationLoadException.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/exceptions/ConfigurationLoadException.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.exceptions; import space.arim.dazzleconf.error.ConfigFormatSyntaxException; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/exceptions/EmbedNotFoundException.java b/src/main/java/tk/bluetree242/discordsrvutils/exceptions/EmbedNotFoundException.java index 0774679d..a8ba4c99 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/exceptions/EmbedNotFoundException.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/exceptions/EmbedNotFoundException.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.exceptions; public class EmbedNotFoundException extends RuntimeException{ diff --git a/src/main/java/tk/bluetree242/discordsrvutils/exceptions/PlaceholdException.java b/src/main/java/tk/bluetree242/discordsrvutils/exceptions/PlaceholdException.java index 5ab65ee5..1d5b9706 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/exceptions/PlaceholdException.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/exceptions/PlaceholdException.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.exceptions; public class PlaceholdException extends RuntimeException{ diff --git a/src/main/java/tk/bluetree242/discordsrvutils/exceptions/StartupException.java b/src/main/java/tk/bluetree242/discordsrvutils/exceptions/StartupException.java index d566c552..2eadbfd7 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/exceptions/StartupException.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/exceptions/StartupException.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.exceptions; public class StartupException extends RuntimeException{ diff --git a/src/main/java/tk/bluetree242/discordsrvutils/exceptions/UnCheckedRateLimitedException.java b/src/main/java/tk/bluetree242/discordsrvutils/exceptions/UnCheckedRateLimitedException.java index 58d8985a..b3d8de3b 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/exceptions/UnCheckedRateLimitedException.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/exceptions/UnCheckedRateLimitedException.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.exceptions; import github.scarsz.discordsrv.dependencies.jda.api.exceptions.RateLimitedException; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/exceptions/UnCheckedSQLException.java b/src/main/java/tk/bluetree242/discordsrvutils/exceptions/UnCheckedSQLException.java index 5ca2e5d6..0ad0dcdc 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/exceptions/UnCheckedSQLException.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/exceptions/UnCheckedSQLException.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.exceptions; import java.lang.Thread.UncaughtExceptionHandler; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/interfaces/Punishment.java b/src/main/java/tk/bluetree242/discordsrvutils/interfaces/Punishment.java index b5348181..c9a57e29 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/interfaces/Punishment.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/interfaces/Punishment.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.interfaces; public interface Punishment { diff --git a/src/main/java/tk/bluetree242/discordsrvutils/leveling/LevelingManager.java b/src/main/java/tk/bluetree242/discordsrvutils/leveling/LevelingManager.java index 7187dfbc..56f93acf 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/leveling/LevelingManager.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/leveling/LevelingManager.java @@ -1,10 +1,33 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.leveling; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.LoadingCache; import github.scarsz.discordsrv.DiscordSRV; -import org.bukkit.Bukkit; +import github.scarsz.discordsrv.dependencies.jda.api.entities.Role; import tk.bluetree242.discordsrvutils.DiscordSRVUtils; import tk.bluetree242.discordsrvutils.exceptions.UnCheckedSQLException; -import tk.bluetree242.discordsrvutils.leveling.listeners.bukkit.BukkitLevelingListener; import java.sql.Connection; import java.sql.PreparedStatement; @@ -13,6 +36,7 @@ import java.time.Duration; import java.util.*; import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; public class LevelingManager { public final Long MAP_EXPIRATION_NANOS = Duration.ofSeconds(60L).toNanos(); @@ -22,11 +46,20 @@ public class LevelingManager { public static LevelingManager get() { return main; } - public LevelingManager() { main = this; } - + private boolean adding = false; + public LoadingCache cachedUUIDS = Caffeine.newBuilder() + .maximumSize(120) + .expireAfterWrite(Duration.ofMinutes(1)) + .refreshAfterWrite(Duration.ofSeconds(30)) + .build(key -> { + adding = true; + PlayerStats stats = getPlayerStats(key).get(); + adding = false; + return stats; + }); public CompletableFuture getPlayerStats(UUID uuid) { return core.completableFuture(() -> { try (Connection conn = core.getDatabase()) { @@ -37,6 +70,21 @@ public CompletableFuture getPlayerStats(UUID uuid) { }); } + public PlayerStats getCachedStats(UUID uuid) { + return cachedUUIDS.get(uuid); + } + public PlayerStats getCachedStats(long discordID) { + UUID uuid = DiscordSRV.getPlugin().getAccountLinkManager().getUuid(discordID + ""); + if (uuid == null) return null; + return cachedUUIDS.get(uuid); + } + + public boolean isLinked(UUID uuid) { + String discord = DiscordSRV.getPlugin().getAccountLinkManager().getDiscordId(uuid); + if (discord == null) return false; + return true; + } + public CompletableFuture getPlayerStats(long discordID) { return core.completableFuture(() -> { UUID uuid = DiscordSRV.getPlugin().getAccountLinkManager().getUuid(discordID + ""); @@ -82,7 +130,10 @@ public PlayerStats getPlayerStats(Connection conn, String name) throws SQLExcept return null; } public PlayerStats getPlayerStats(ResultSet r, int rank) throws SQLException { - return new PlayerStats(UUID.fromString(r.getString("UUID")), r.getString("Name"), r.getInt("level"), r.getInt("xp"), r.getInt("MinecraftMessages"), r.getInt("DiscordMessages"), rank); + PlayerStats stats = new PlayerStats(UUID.fromString(r.getString("UUID")), r.getString("Name"), r.getInt("level"), r.getInt("xp"), r.getInt("MinecraftMessages"), r.getInt("DiscordMessages"), rank); + if (!adding) + cachedUUIDS.put(stats.getUuid(), stats); + return stats; } public CompletableFuture> getLeaderboard(int max) { @@ -104,4 +155,32 @@ public CompletableFuture> getLeaderboard(int max) { } }); } + + public Role getRoleForLevel(int level) { + Map map = core.levelingRolesRaw.toMap(); + List keys = new ArrayList<>(map.keySet()); + keys = keys.stream().filter(num -> Integer.parseInt(num) <= level).collect(Collectors.toList()); + keys.sort(new Comparator() { + @Override + public int compare(String o1, String o2) { + return Integer.parseInt(o2) - Integer.parseInt(o1); + } + }); + Long id = (Long) map.get(keys.get(0)); + if (id != null) { + return core.getGuild().getRoleById(id); + } + return null; + } + + public List getRolesToRemove() { + List roles = new ArrayList<>(); + Map map = core.levelingRolesRaw.toMap(); + List values = new ArrayList<>(map.values()); + for (Object value : values) { + Long id = (Long) value; + roles.add(core.getGuild().getRoleById(id)); + } + return roles; + } } diff --git a/src/main/java/tk/bluetree242/discordsrvutils/leveling/MessageType.java b/src/main/java/tk/bluetree242/discordsrvutils/leveling/MessageType.java index 79af55a6..f80e0863 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/leveling/MessageType.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/leveling/MessageType.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.leveling; public enum MessageType { diff --git a/src/main/java/tk/bluetree242/discordsrvutils/leveling/PlayerStats.java b/src/main/java/tk/bluetree242/discordsrvutils/leveling/PlayerStats.java index 7ea4668c..6918e8f2 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/leveling/PlayerStats.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/leveling/PlayerStats.java @@ -1,5 +1,30 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.leveling; +import github.scarsz.discordsrv.DiscordSRV; +import github.scarsz.discordsrv.dependencies.jda.api.entities.Member; +import github.scarsz.discordsrv.dependencies.jda.api.entities.Role; import tk.bluetree242.discordsrvutils.DiscordSRVUtils; import tk.bluetree242.discordsrvutils.exceptions.UnCheckedSQLException; @@ -72,6 +97,19 @@ public CompletableFuture setXP(int xp) { p1.execute(); this.level = level + 1; this.xp = 0; + String id = DiscordSRV.getPlugin().getAccountLinkManager().getDiscordId(uuid); + if (id == null) return true; + LevelingManager manager = LevelingManager.get(); + Member member = core.getGuild().retrieveMemberById(id).complete(); + if (member == null) return true; + for (Role role : manager.getRolesToRemove()) { + if (member.getRoles().contains(role)) + core.getGuild().removeRoleFromMember(member, role).queue(); + } + Role toAdd = manager.getRoleForLevel(level); + if (toAdd != null) { + core.getGuild().addRoleToMember(member, toAdd).queue(); + } return true; } PreparedStatement p1 = conn.prepareStatement("UPDATE leveling SET XP=? WHERE UUID=?"); diff --git a/src/main/java/tk/bluetree242/discordsrvutils/leveling/listeners/bukkit/BukkitLevelingListener.java b/src/main/java/tk/bluetree242/discordsrvutils/leveling/listeners/bukkit/BukkitLevelingListener.java index a2eed801..24d0f567 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/leveling/listeners/bukkit/BukkitLevelingListener.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/leveling/listeners/bukkit/BukkitLevelingListener.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.leveling.listeners.bukkit; import github.scarsz.discordsrv.DiscordSRV; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/leveling/listeners/jda/DiscordLevelingListener.java b/src/main/java/tk/bluetree242/discordsrvutils/leveling/listeners/jda/DiscordLevelingListener.java index 00ca912a..f9862cfc 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/leveling/listeners/jda/DiscordLevelingListener.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/leveling/listeners/jda/DiscordLevelingListener.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.leveling.listeners.jda; @@ -19,6 +41,7 @@ public class DiscordLevelingListener extends ListenerAdapter { private DiscordSRVUtils core = DiscordSRVUtils.get(); public void onGuildMessageReceived(GuildMessageReceivedEvent e) { + if (core.getMainConfig().bungee_mode()) return; core.executeAsync(() -> { if (e.getMessage().isWebhookMessage()) return; if (e.getAuthor().isBot()) return; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/listeners/afk/EssentialsAFKListener.java b/src/main/java/tk/bluetree242/discordsrvutils/listeners/afk/EssentialsAFKListener.java index 8ece7378..6dd51cd2 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/listeners/afk/EssentialsAFKListener.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/listeners/afk/EssentialsAFKListener.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.listeners.afk; import github.scarsz.discordsrv.dependencies.jda.api.entities.Message; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/listeners/bukkit/JoinUpdateChecker.java b/src/main/java/tk/bluetree242/discordsrvutils/listeners/bukkit/JoinUpdateChecker.java new file mode 100644 index 00000000..1967e83a --- /dev/null +++ b/src/main/java/tk/bluetree242/discordsrvutils/listeners/bukkit/JoinUpdateChecker.java @@ -0,0 +1,66 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + +package tk.bluetree242.discordsrvutils.listeners.bukkit; + +import github.scarsz.discordsrv.dependencies.okhttp3.*; +import github.scarsz.discordsrv.dependencies.okhttp3.Response; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.json.JSONObject; +import tk.bluetree242.discordsrvutils.DiscordSRVUtils; +import tk.bluetree242.discordsrvutils.utils.Utils; + +public class JoinUpdateChecker implements Listener { + + + @EventHandler + public void playerJoin(PlayerJoinEvent e) { + if (e.getPlayer().hasPermission("discordsrvutils.updatechecker")) + Bukkit.getScheduler().runTaskAsynchronously(DiscordSRVUtils.get(), ()-> { + try { + OkHttpClient client = new OkHttpClient(); + MultipartBody form = new MultipartBody.Builder().setType(MediaType.get("multipart/form-data")).addFormDataPart("version", DiscordSRVUtils.get().getDescription().getVersion()) + .build(); + + Request req = new Request.Builder().url("https://discordsrvutils.ml/updatecheck").post(form).build(); + Response response = client.newCall(req).execute(); + JSONObject res = new JSONObject(response.body().string()); + response.close(); + int versions_behind = res.getInt("versions_behind"); + if (res.isNull("message")) { + if (versions_behind != 0) { + e.getPlayer().sendMessage(Utils.colors("&7[&eDSU&7] &c" + ChatColor.GREEN + "Plugin is " + versions_behind + " versions behind. Please Update. Download from " + res.getString("downloadUrl"))); + } + } else { + e.getPlayer().sendMessage(Utils.colors("&7[&eDSU&7] &c" + res.getString("message"))); + } + } catch (Exception ex) { + DiscordSRVUtils.get().getLogger().severe("Could not check for updates: " + ex.getMessage()); + } + + }); + } +} diff --git a/src/main/java/tk/bluetree242/discordsrvutils/listeners/discordsrv/DiscordSRVListener.java b/src/main/java/tk/bluetree242/discordsrvutils/listeners/discordsrv/DiscordSRVListener.java index 90037616..c7bd9757 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/listeners/discordsrv/DiscordSRVListener.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/listeners/discordsrv/DiscordSRVListener.java @@ -1,10 +1,36 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.listeners.discordsrv; +import github.scarsz.discordsrv.DiscordSRV; import github.scarsz.discordsrv.api.Subscribe; -import github.scarsz.discordsrv.api.events.DiscordReadyEvent; +import github.scarsz.discordsrv.api.events.*; +import github.scarsz.discordsrv.dependencies.jda.api.entities.Member; +import github.scarsz.discordsrv.dependencies.jda.api.entities.Role; import org.bukkit.Bukkit; import tk.bluetree242.discordsrvutils.DiscordSRVUtils; import tk.bluetree242.discordsrvutils.exceptions.StartupException; +import tk.bluetree242.discordsrvutils.leveling.LevelingManager; public class DiscordSRVListener { private final DiscordSRVUtils core = DiscordSRVUtils.get(); @@ -17,4 +43,49 @@ public void onReady(DiscordReadyEvent e) { Bukkit.getPluginManager().disablePlugin(core); } } + + @Subscribe + public void onLink(AccountLinkedEvent e) { + if (!core.isReady()) return; + LevelingManager manager = LevelingManager.get(); + manager.getPlayerStats(e.getUser().getIdLong()).thenAcceptAsync(stats -> { + int level = stats.getLevel(); + if (stats == null) return; + String id = DiscordSRV.getPlugin().getAccountLinkManager().getDiscordId(stats.getUuid()); + if (id == null) return; + Member member = core.getGuild().retrieveMemberById(id).complete(); + if (member == null) return; + for (Role role : manager.getRolesToRemove()) { + if (member.getRoles().contains(role)) + core.getGuild().removeRoleFromMember(member, role).queue(); + } + Role toAdd = manager.getRoleForLevel(level); + if (toAdd != null) { + core.getGuild().addRoleToMember(member, toAdd).queue(); + } + }); + + } + + @Subscribe + public void onUnlink(AccountUnlinkedEvent e) { + if (!core.isReady()) return; + + LevelingManager manager = LevelingManager.get(); + core.executeAsync(() -> { + Member member = core.getGuild().retrieveMemberById(e.getDiscordId()).complete(); + if (member != null) { + for (Role role : manager.getRolesToRemove()) { + if (member.getRoles().contains(role)) + core.getGuild().removeRoleFromMember(member, role).queue(); + } + } + }); + } + + @Subscribe + public void onDiscordMsg(DiscordGuildMessagePreProcessEvent e) { + if (e.getMessage().getContentRaw().toLowerCase().startsWith(core.getCommandPrefix().toLowerCase())) + e.setCancelled(true); + } } diff --git a/src/main/java/tk/bluetree242/discordsrvutils/listeners/jda/CustomDiscordAccountLinkListener.java b/src/main/java/tk/bluetree242/discordsrvutils/listeners/jda/CustomDiscordAccountLinkListener.java new file mode 100644 index 00000000..52615848 --- /dev/null +++ b/src/main/java/tk/bluetree242/discordsrvutils/listeners/jda/CustomDiscordAccountLinkListener.java @@ -0,0 +1,65 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + +package tk.bluetree242.discordsrvutils.listeners.jda; + +import github.scarsz.discordsrv.Debug; +import github.scarsz.discordsrv.DiscordSRV; +import github.scarsz.discordsrv.dependencies.jda.api.entities.Role; +import github.scarsz.discordsrv.dependencies.jda.api.events.guild.member.GuildMemberJoinEvent; +import github.scarsz.discordsrv.dependencies.jda.api.events.message.guild.GuildMessageReceivedEvent; +import github.scarsz.discordsrv.dependencies.jda.api.hooks.ListenerAdapter; +import github.scarsz.discordsrv.util.DiscordUtil; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import tk.bluetree242.discordsrvutils.DiscordSRVUtils; + +import java.util.UUID; + +public class CustomDiscordAccountLinkListener extends ListenerAdapter { + // Original From DiscordAccountLinkListener DiscordSRV Class + public void onGuildMessageReceived(GuildMessageReceivedEvent event) { + if (event.getAuthor().isBot()) return; + if (event.getChannel().getIdLong() != DiscordSRVUtils.get().getMainConfig().linkaccount_channel()) return; + String response = DiscordSRV.getPlugin().getAccountLinkManager().process(event.getMessage().getContentRaw(), event.getAuthor().getId()); + if (response != null) event.getMessage().reply(response).queue(); + } + + + public void onGuildMemberJoin(GuildMemberJoinEvent event) { + if (!DiscordSRVUtils.get().removedDiscordSRVAccountLinkListener) return; + // add linked role and nickname back to people when they rejoin the server + UUID uuid = DiscordSRV.getPlugin().getAccountLinkManager().getUuid(event.getUser().getId()); + if (uuid != null) { + Role roleToAdd = DiscordUtil.resolveRole(DiscordSRV.config().getString("MinecraftDiscordAccountLinkedRoleNameToAddUserTo")); + if (roleToAdd != null) DiscordUtil.addRoleToMember(event.getMember(), roleToAdd); + else DiscordSRV.debug(Debug.GROUP_SYNC, "Couldn't add user to null role"); + + if (DiscordSRV.config().getBoolean("NicknameSynchronizationEnabled")) { + OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); + DiscordSRV.getPlugin().getNicknameUpdater().setNickname(event.getMember(), player); + } + } + } + + +} diff --git a/src/main/java/tk/bluetree242/discordsrvutils/listeners/jda/WelcomerAndGoodByeListener.java b/src/main/java/tk/bluetree242/discordsrvutils/listeners/jda/WelcomerAndGoodByeListener.java index 4c05b385..c141abd4 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/listeners/jda/WelcomerAndGoodByeListener.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/listeners/jda/WelcomerAndGoodByeListener.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.listeners.jda; import github.scarsz.discordsrv.dependencies.jda.api.entities.MessageChannel; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/listeners/punishments/advancedban/AdvancedBanPunishment.java b/src/main/java/tk/bluetree242/discordsrvutils/listeners/punishments/advancedban/AdvancedBanPunishment.java index 8f68bf35..bcfab4d0 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/listeners/punishments/advancedban/AdvancedBanPunishment.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/listeners/punishments/advancedban/AdvancedBanPunishment.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.listeners.punishments.advancedban; import tk.bluetree242.discordsrvutils.interfaces.Punishment; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/listeners/punishments/advancedban/AdvancedBanPunishmentListener.java b/src/main/java/tk/bluetree242/discordsrvutils/listeners/punishments/advancedban/AdvancedBanPunishmentListener.java index 19345475..d875b1dd 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/listeners/punishments/advancedban/AdvancedBanPunishmentListener.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/listeners/punishments/advancedban/AdvancedBanPunishmentListener.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.listeners.punishments.advancedban; import github.scarsz.discordsrv.DiscordSRV; @@ -98,8 +120,9 @@ public void onPunish(PunishmentEvent e) { } private void syncPunishment(Punishment punishment, boolean un) { - User discordUser = core.getJDA().getUserById(DiscordSRV.getPlugin().getAccountLinkManager().getDiscordId(Bukkit.getOfflinePlayer(punishment.getName()).getUniqueId())); - if (discordUser == null) return; + String id = DiscordSRV.getPlugin().getAccountLinkManager().getDiscordId(Bukkit.getOfflinePlayer(punishment.getName()).getUniqueId()); + if (id == null) return; + User discordUser = core.getJDA().retrieveUserById(id).complete(); if (!un) { if (!core.getBansConfig().isSyncPunishmentsWithDiscord()) return; switch (punishment.getType()) { diff --git a/src/main/java/tk/bluetree242/discordsrvutils/listeners/punishments/litebans/LitebansPunishment.java b/src/main/java/tk/bluetree242/discordsrvutils/listeners/punishments/litebans/LitebansPunishment.java new file mode 100644 index 00000000..f38e90e2 --- /dev/null +++ b/src/main/java/tk/bluetree242/discordsrvutils/listeners/punishments/litebans/LitebansPunishment.java @@ -0,0 +1,65 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + +package tk.bluetree242.discordsrvutils.listeners.punishments.litebans; + +import litebans.api.Entry; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import tk.bluetree242.discordsrvutils.interfaces.Punishment; +import tk.bluetree242.discordsrvutils.utils.Utils; + +import java.util.UUID; + +public class LitebansPunishment implements Punishment { + private final Entry punishment; + public LitebansPunishment(Entry entry) { + punishment = entry; + } + @Override + public String getDuration() { + if (punishment.isPermanent()) + return "Permanent"; + return Utils.getDuration((punishment.getDateEnd() - punishment.getDateStart())); + } + + @Override + public String getOperator() { + return punishment.getExecutorName(); + } + + @Override + public String getName() { + OfflinePlayer p = toOfflinePlayer(punishment.getUuid()); + if (p == null) return "Unknown"; + return p.getName() == null ? "Unknown" : p.getName(); + } + + @Override + public String getReason() { + return punishment.getReason(); + } + + protected static OfflinePlayer toOfflinePlayer(String uuid) { + return Bukkit.getOfflinePlayer(UUID.fromString(uuid)); + } +} diff --git a/src/main/java/tk/bluetree242/discordsrvutils/listeners/punishments/litebans/LitebansPunishmentListener.java b/src/main/java/tk/bluetree242/discordsrvutils/listeners/punishments/litebans/LitebansPunishmentListener.java new file mode 100644 index 00000000..3dae3d22 --- /dev/null +++ b/src/main/java/tk/bluetree242/discordsrvutils/listeners/punishments/litebans/LitebansPunishmentListener.java @@ -0,0 +1,161 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + +package tk.bluetree242.discordsrvutils.listeners.punishments.litebans; + +import github.scarsz.discordsrv.DiscordSRV; +import github.scarsz.discordsrv.dependencies.jda.api.entities.Message; +import github.scarsz.discordsrv.dependencies.jda.api.entities.Role; +import github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel; +import github.scarsz.discordsrv.dependencies.jda.api.entities.User; +import litebans.api.*; +import org.bukkit.Bukkit; +import tk.bluetree242.discordsrvutils.DiscordSRVUtils; +import tk.bluetree242.discordsrvutils.messages.MessageManager; +import tk.bluetree242.discordsrvutils.placeholder.PlaceholdObject; +import tk.bluetree242.discordsrvutils.placeholder.PlaceholdObjectList; + + +public class LitebansPunishmentListener extends Events.Listener { + + public LitebansPunishmentListener() { + litebans.api.Events.get().register(this); + } + private DiscordSRVUtils core = DiscordSRVUtils.get(); + public void entryAdded(Entry e) { + core.executeAsync(() -> { + if (!core.isReady()) return; + LitebansPunishment punishment = new LitebansPunishment(e); + + Message msg = null; + switch (e.getType().toUpperCase()) { + case "BAN": + msg = MessageManager.get().getMessage(core.getBansConfig().bannedMessage(), PlaceholdObjectList.ofArray(new PlaceholdObject(punishment, "punishment")), null).build(); + if (!e.isPermanent()) { + msg =MessageManager.get().getMessage(core.getBansConfig().tempBannedMessage(), PlaceholdObjectList.ofArray(new PlaceholdObject(punishment, "punishment")), null).build(); + } + if (e.isIpban()) { + msg =MessageManager.get().getMessage(core.getBansConfig().IPBannedMessage(), PlaceholdObjectList.ofArray(new PlaceholdObject(punishment, "punishment")), null).build(); + } + if (e.isPermanent() && e.isIpban()) { + msg =MessageManager.get().getMessage(core.getBansConfig().TempIPBannedMessage(), PlaceholdObjectList.ofArray(new PlaceholdObject(punishment, "punishment")), null).build(); + } + break; + case "MUTE" : + msg =MessageManager.get().getMessage(core.getBansConfig().MutedMessage(), PlaceholdObjectList.ofArray(new PlaceholdObject(punishment, "punishment")), null).build(); + if (!e.isPermanent()) { + msg =MessageManager.get().getMessage(core.getBansConfig().tempBannedMessage(), PlaceholdObjectList.ofArray(new PlaceholdObject(punishment, "punishment")), null).build(); + } + break; + default: + break; + } + if (!e.isSilent()) + if (msg != null) { + if (core.getBansConfig().isSendPunishmentmsgesToDiscord()) { + TextChannel channel = core.getChannel(core.getBansConfig().channel_id()); + if (channel == null) { + core.severe("No channel was found with id " + core.getBansConfig().channel_id() + " For Punishment message"); + return; + } else + core.queueMsg(msg, channel).queue(); + } + } + syncPunishment(e, false); + }); + } + + public void entryRemoved(Entry e) { + if (!core.isReady()) return; + core.executeAsync(() -> { + if (!core.isEnabled()) return; + LitebansPunishment punishment = new LitebansPunishment(e); + + Message msg = null; + switch (e.getType().toUpperCase()) { + case "BAN": + msg = MessageManager.get().getMessage(core.getBansConfig().unbannedMessage(), PlaceholdObjectList.ofArray(new PlaceholdObject(punishment, "punishment")), null).build(); + if (e.isIpban()) { + msg =MessageManager.get().getMessage(core.getBansConfig().unipbannedMessage(), PlaceholdObjectList.ofArray(new PlaceholdObject(punishment, "punishment")), null).build(); + } + break; + case "MUTE" : + msg =MessageManager.get().getMessage(core.getBansConfig().unmuteMessage(), PlaceholdObjectList.ofArray(new PlaceholdObject(punishment, "punishment")), null).build(); + break; + } + if (!e.isSilent()) + if (msg != null) { + if (core.getBansConfig().isSendPunishmentmsgesToDiscord()) { + TextChannel channel = core.getChannel(core.getBansConfig().channel_id()); + if (channel == null) { + core.severe("No channel was found with id " + core.getBansConfig().channel_id() + " For Punishment message"); + return; + } else + core.queueMsg(msg, channel).queue(); + } + } + syncPunishment(e, false); + }); + } + + private void syncPunishment(Entry punishment, boolean un) { + String id = DiscordSRV.getPlugin().getAccountLinkManager().getDiscordId(Bukkit.getOfflinePlayer(LitebansPunishment.toOfflinePlayer(punishment.getUuid()).getUniqueId()).getUniqueId()); + if (id == null) return; + User discordUser = core.getJDA().retrieveUserById(id).complete(); + if (!un) { + if (!core.getBansConfig().isSyncPunishmentsWithDiscord()) return; + switch (punishment.getType()) { + case "BAN": + core.getGuild().ban(discordUser, 0, "Minecraft Synced Ban").queue(); + break; + case "MUTE": + Role role = core.getJDA().getRoleById(core.getBansConfig().mutedRole()); + if (role == null) { + if (core.getBansConfig().mutedRole() != 0) core.severe("No Role was found with id " + core.getBansConfig().mutedRole() + ". Could not mute " + Bukkit.getOfflinePlayer(LitebansPunishment.toOfflinePlayer(punishment.getUuid()).getName())); + return; + } + core.getGuild().addRoleToMember(discordUser.getIdLong(), role).reason("Mute Synced with Minecraft").queue(); + break; + default: + break; + } + } else { + if (!core.getBansConfig().isSyncUnpunishmentsWithDiscord()) return; + switch (punishment.getType()) { + case "BAN": + core.getGuild().unban(discordUser).reason("Minecraft Synced unban").queue(); + break; + case "MUTE": + Role role = core.getJDA().getRoleById(core.getBansConfig().mutedRole()); + if (role == null) { + if (core.getBansConfig().mutedRole() != 0) core.severe("No Role was found with id " + core.getBansConfig().mutedRole() + ". Could not unmute " + Bukkit.getOfflinePlayer(LitebansPunishment.toOfflinePlayer(punishment.getUuid()).getName())); + return; + } + core.getGuild().removeRoleFromMember(discordUser.getIdLong(), role).reason("Unmute Synced with Minecraft").queue(); + default:break; + } + } + } + + + +} diff --git a/src/main/java/tk/bluetree242/discordsrvutils/messages/MessageManager.java b/src/main/java/tk/bluetree242/discordsrvutils/messages/MessageManager.java index cfd2c5c9..3abd0f75 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/messages/MessageManager.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/messages/MessageManager.java @@ -1,14 +1,34 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.messages; import github.scarsz.discordsrv.dependencies.jda.api.EmbedBuilder; import github.scarsz.discordsrv.dependencies.jda.api.MessageBuilder; -import org.bukkit.ChatColor; -import org.bukkit.entity.Horse; import org.bukkit.entity.Player; import org.json.JSONArray; import org.json.JSONObject; import tk.bluetree242.discordsrvutils.DiscordSRVUtils; -import tk.bluetree242.discordsrvutils.FileWriter; +import tk.bluetree242.discordsrvutils.utils.FileWriter; import tk.bluetree242.discordsrvutils.exceptions.EmbedNotFoundException; import tk.bluetree242.discordsrvutils.placeholder.PlaceholdObject; import tk.bluetree242.discordsrvutils.placeholder.PlaceholdObjectList; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/placeholder/PlaceholdObject.java b/src/main/java/tk/bluetree242/discordsrvutils/placeholder/PlaceholdObject.java index dfbf1ab4..13663af7 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/placeholder/PlaceholdObject.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/placeholder/PlaceholdObject.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.placeholder; import github.scarsz.discordsrv.DiscordSRV; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/placeholder/PlaceholdObjectList.java b/src/main/java/tk/bluetree242/discordsrvutils/placeholder/PlaceholdObjectList.java index 4d99f318..32161430 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/placeholder/PlaceholdObjectList.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/placeholder/PlaceholdObjectList.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.placeholder; import github.scarsz.discordsrv.util.NamedValueFormatter; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/suggestions/Suggestion.java b/src/main/java/tk/bluetree242/discordsrvutils/suggestions/Suggestion.java index 7ab75d0a..88286cea 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/suggestions/Suggestion.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/suggestions/Suggestion.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.suggestions; import github.scarsz.discordsrv.dependencies.jda.api.EmbedBuilder; @@ -9,6 +31,7 @@ import tk.bluetree242.discordsrvutils.placeholder.PlaceholdObject; import tk.bluetree242.discordsrvutils.placeholder.PlaceholdObjectList; import tk.bluetree242.discordsrvutils.utils.Emoji; +import tk.bluetree242.discordsrvutils.utils.SuggestionVoteMode; import tk.bluetree242.discordsrvutils.utils.Utils; import java.sql.Connection; @@ -31,8 +54,8 @@ public class Suggestion { protected Boolean Approved; protected Message msg; protected Long approver; - - public Suggestion(String text, int number, Long submitter, Long channelID, Long creationTime, Set notes, Long MessageID, Boolean Approved, Long approver) { + Set votes; + public Suggestion(String text, int number, Long submitter, Long channelID, Long creationTime, Set notes, Long MessageID, Boolean Approved, Long approver, Set votes) { this.text = text; this.number = number; this.submitter = submitter; @@ -42,9 +65,13 @@ public Suggestion(String text, int number, Long submitter, Long channelID, Long this.MessageID = MessageID; this.Approved = Approved; this.approver = approver; + this.votes = votes; } + public Set getVotes() { + return votes; + } public Long getApprover() { return approver; @@ -133,11 +160,16 @@ public Message getMessage() { } public int getYesCount() { - return getMessage().getReactions().stream().filter(reaction -> reaction.getReactionEmote().getName().equals(Utils.getEmoji(core.getSuggestionsConfig().yes_reaction(), new Emoji("✅")).getName())).collect(Collectors.toList()).get(0).getCount() -1; + if (core.voteMode == SuggestionVoteMode.BUTTONS) { + List votes = getVotes().stream().filter(v -> v.isAgree()).collect(Collectors.toList()); + return votes.size(); + } else return getMessage().getReactions().stream().filter(reaction -> reaction.getReactionEmote().getName().equals(Utils.getEmoji(core.getSuggestionsConfig().yes_reaction(), new Emoji("✅")).getName())).collect(Collectors.toList()).get(0).getCount() -1; } public int getNoCount() { - return getMessage().getReactions().stream().filter(reaction -> reaction.getReactionEmote().getName().equals(Utils.getEmoji(core.getSuggestionsConfig().no_reaction(), new Emoji("❌")).getName())).collect(Collectors.toList()).get(0).getCount() -1; + if (core.voteMode == SuggestionVoteMode.BUTTONS) { + List votes = getVotes().stream().filter(v -> !v.isAgree()).collect(Collectors.toList()); + return votes.size();} else return getMessage().getReactions().stream().filter(reaction -> reaction.getReactionEmote().getName().equals(Utils.getEmoji(core.getSuggestionsConfig().no_reaction(), new Emoji("❌")).getName())).collect(Collectors.toList()).get(0).getCount() -1; } public Message getCurrentMsg() { diff --git a/src/main/java/tk/bluetree242/discordsrvutils/suggestions/SuggestionManager.java b/src/main/java/tk/bluetree242/discordsrvutils/suggestions/SuggestionManager.java index 53ce8860..960ad6dc 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/suggestions/SuggestionManager.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/suggestions/SuggestionManager.java @@ -1,28 +1,52 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.suggestions; -import github.scarsz.discordsrv.dependencies.jda.api.entities.Message; -import github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel; -import github.scarsz.discordsrv.dependencies.jda.api.entities.User; +import github.scarsz.discordsrv.dependencies.jda.api.MessageBuilder; +import github.scarsz.discordsrv.dependencies.jda.api.entities.*; +import github.scarsz.discordsrv.dependencies.jda.api.interactions.components.ActionRow; +import github.scarsz.discordsrv.dependencies.jda.api.interactions.components.Button; import tk.bluetree242.discordsrvutils.DiscordSRVUtils; import tk.bluetree242.discordsrvutils.exceptions.UnCheckedSQLException; import tk.bluetree242.discordsrvutils.messages.MessageManager; import tk.bluetree242.discordsrvutils.placeholder.PlaceholdObject; import tk.bluetree242.discordsrvutils.placeholder.PlaceholdObjectList; import tk.bluetree242.discordsrvutils.utils.Emoji; +import tk.bluetree242.discordsrvutils.utils.SuggestionVoteMode; import tk.bluetree242.discordsrvutils.utils.Utils; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.HashSet; -import java.util.Set; +import java.util.*; import java.util.concurrent.CompletableFuture; public class SuggestionManager { private static SuggestionManager main; private DiscordSRVUtils core = DiscordSRVUtils.get(); + public boolean loading = false; public static SuggestionManager get() { return main; @@ -42,6 +66,8 @@ public CompletableFuture getSuggestionByNumber(int num) { }); } + + public CompletableFuture getSuggestionByMessageID(Long MessageID) { return core.completableFuture(() -> { try (Connection conn = core.getDatabase()) { @@ -70,16 +96,23 @@ public Suggestion getSuggestionByMessageID(Long MessageID, Connection conn) thro public Suggestion getSuggestion(ResultSet r) throws SQLException { - return getSuggestion(r, null); + return getSuggestion(r, null, null); } - public Suggestion getSuggestion(ResultSet r, ResultSet notesr) throws SQLException { + public Suggestion getSuggestion(ResultSet r, ResultSet notesr, ResultSet votesr) throws SQLException { if (notesr == null) { PreparedStatement p1 = r.getStatement().getConnection().prepareStatement("SELECT * FROM suggestion_notes WHERE SuggestionNumber=?"); p1.setInt(1, r.getInt("SuggestionNumber")); notesr = p1.executeQuery(); } + if (core.voteMode != SuggestionVoteMode.REACTIONS) + if (votesr == null) { + PreparedStatement p1 = r.getStatement().getConnection().prepareStatement("SELECT * FROM suggestions_votes WHERE SuggestionNumber=?"); + p1.setInt(1, r.getInt("SuggestionNumber")); + votesr = p1.executeQuery(); + } Set notes = new HashSet<>(); + Set votes = new HashSet<>(); while (notesr.next()) { notes.add(new SuggestionNote( notesr.getLong("StaffID"), @@ -88,12 +121,38 @@ public Suggestion getSuggestion(ResultSet r, ResultSet notesr) throws SQLExcepti notesr.getLong("CreationTime") )); } - return new Suggestion( + Suggestion suggestion = new Suggestion( Utils.b64Decode(r.getString("SuggestionText")), r.getInt("SuggestionNumber"), r.getLong("Submitter"), r.getLong("ChannelID"), r.getLong("CreationTime"), notes, r.getLong("MessageID"), - r.getString("Approved") == null ? null : Utils.getDBoolean(r.getString("Approved")), r.getLong("Approver")); + r.getString("Approved") == null ? null : Utils.getDBoolean(r.getString("Approved")), r.getLong("Approver"), votes); + if (core.voteMode == SuggestionVoteMode.BUTTONS) { + while (votesr.next()) { + votes.add(new SuggestionVote(votesr.getLong("UserID"), votesr.getInt("SuggestionNumber"), Utils.getDBoolean(votesr.getString("Agree")))); + } + + }else { + /* + for (MessageReaction reaction : suggestion.getMessage().getReactions()) { + if (reaction.getReactionEmote().getName().equals(SuggestionManager.getYesEmoji().getName())) { + List users = reaction.retrieveUsers().complete(); + for (User user : users) { + if (!user.isBot()) + votes.add(new SuggestionVote(user.getIdLong(), suggestion.getNumber(), true)); + } + } else if (reaction.getReactionEmote().getName().equals(SuggestionManager.getNoEmoji().getName())) { + List users = reaction.retrieveUsers().complete(); + for (User user : users) { + if (!user.isBot()) + votes.add(new SuggestionVote(user.getIdLong(), suggestion.getNumber(), true)); + } + } + } + + */ + } + return suggestion; } @@ -110,6 +169,7 @@ public CompletableFuture makeSuggestion(String text, Long SubmitterI if (channel == null) { throw new IllegalStateException("Suggestions Channel not found"); } + return core.completableFuture(() -> { try (Connection conn = core.getDatabase()) { PreparedStatement p1 = conn.prepareStatement("SELECT * FROM suggestions ORDER BY SuggestionNumber DESC "); @@ -119,11 +179,17 @@ public CompletableFuture makeSuggestion(String text, Long SubmitterI num = r1.getInt("SuggestionNumber") + 1; } - Suggestion suggestion = new Suggestion(text, num, SubmitterID, channelId, System.currentTimeMillis(), new HashSet<>(), null, null, null); + Suggestion suggestion = new Suggestion(text, num, SubmitterID, channelId, System.currentTimeMillis(), new HashSet<>(), null, null, null, new HashSet<>()); User submitter = core.getJDA().retrieveUserById(SubmitterID).complete(); - Message msg = core.queueMsg(MessageManager.get().getMessage(core.getSuggestionsConfig().suggestions_message(), + MessageBuilder builder = MessageManager.get().getMessage(core.getSuggestionsConfig().suggestions_message(), PlaceholdObjectList.ofArray(new PlaceholdObject(suggestion, "suggestion"), new PlaceholdObject(submitter, "submitter")) - ,null).build(), channel).complete(); + ,null); + if (core.voteMode == SuggestionVoteMode.BUTTONS) { + builder.setActionRows(ActionRow.of( + Button.success("yes", SuggestionManager.getYesEmoji().toJDAEmoji()), + Button.danger("no", SuggestionManager.getNoEmoji().toJDAEmoji()))); + } + Message msg = core.queueMsg(builder.build(), channel).complete(); PreparedStatement p2 = conn.prepareStatement("INSERT INTO suggestions(suggestionnumber, suggestiontext, submitter, messageid, channelid, creationtime) VALUES (?,?,?,?,?,?)"); p2.setInt(1, num); p2.setString(2, Utils.b64Encode(text)); @@ -132,8 +198,10 @@ public CompletableFuture makeSuggestion(String text, Long SubmitterI p2.setLong(5, channelId); p2.setLong(6, System.currentTimeMillis()); p2.execute(); - msg.addReaction(Utils.getEmoji(core.getSuggestionsConfig().yes_reaction(), new Emoji("✅")).getNameInReaction()).queue(); - msg.addReaction(Utils.getEmoji(core.getSuggestionsConfig().no_reaction(), new Emoji("❌")).getNameInReaction()).queue(); + if (core.voteMode == SuggestionVoteMode.REACTIONS) { + msg.addReaction(getYesEmoji().getNameInReaction()).queue(); + msg.addReaction(getNoEmoji().getNameInReaction()).queue(); + } return suggestion; } catch (SQLException e) { throw new UnCheckedSQLException(e); @@ -141,6 +209,22 @@ public CompletableFuture makeSuggestion(String text, Long SubmitterI }); } + public static Emoji getYesEmoji() { + return Utils.getEmoji(DiscordSRVUtils.get().getSuggestionsConfig().yes_reaction(), new Emoji("✅")); + } + public static Emoji getNoEmoji() { + return Utils.getEmoji(DiscordSRVUtils.get().getSuggestionsConfig().no_reaction(), new Emoji("❌")); + } + + public static ActionRow getActionRow() { + return ActionRow.of(Button.success("yes", SuggestionManager.getYesEmoji().toJDAEmoji()), + Button.danger("no", SuggestionManager.getNoEmoji().toJDAEmoji()), + Button.secondary("reset", github.scarsz.discordsrv.dependencies.jda.api.entities.Emoji.fromUnicode("⬜"))); + } + + + + diff --git a/src/main/java/tk/bluetree242/discordsrvutils/suggestions/SuggestionNote.java b/src/main/java/tk/bluetree242/discordsrvutils/suggestions/SuggestionNote.java index b9c9b359..14c59ae4 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/suggestions/SuggestionNote.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/suggestions/SuggestionNote.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.suggestions; public class SuggestionNote { diff --git a/src/main/java/tk/bluetree242/discordsrvutils/suggestions/SuggestionVote.java b/src/main/java/tk/bluetree242/discordsrvutils/suggestions/SuggestionVote.java new file mode 100644 index 00000000..a2b177cb --- /dev/null +++ b/src/main/java/tk/bluetree242/discordsrvutils/suggestions/SuggestionVote.java @@ -0,0 +1,48 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + +package tk.bluetree242.discordsrvutils.suggestions; + +public class SuggestionVote { + + private Long id; + private int SuggestionNumber; + private boolean agree; + + public SuggestionVote(Long id, int suggestionNumber, boolean agree) { + this.id = id; + SuggestionNumber = suggestionNumber; + this.agree = agree; + } + + public Long getId() { + return id; + } + + public int getSuggestionNumber() { + return SuggestionNumber; + } + + public boolean isAgree() { + return agree; + } +} diff --git a/src/main/java/tk/bluetree242/discordsrvutils/suggestions/listeners/SuggestionReactionListener.java b/src/main/java/tk/bluetree242/discordsrvutils/suggestions/listeners/SuggestionReactionListener.java deleted file mode 100644 index d0c07656..00000000 --- a/src/main/java/tk/bluetree242/discordsrvutils/suggestions/listeners/SuggestionReactionListener.java +++ /dev/null @@ -1,39 +0,0 @@ -package tk.bluetree242.discordsrvutils.suggestions.listeners; - -import github.scarsz.discordsrv.dependencies.jda.api.entities.Message; -import github.scarsz.discordsrv.dependencies.jda.api.events.message.guild.react.GuildMessageReactionAddEvent; -import github.scarsz.discordsrv.dependencies.jda.api.hooks.ListenerAdapter; -import tk.bluetree242.discordsrvutils.DiscordSRVUtils; -import tk.bluetree242.discordsrvutils.suggestions.SuggestionManager; -import tk.bluetree242.discordsrvutils.tickets.TicketManager; -import tk.bluetree242.discordsrvutils.utils.Emoji; -import tk.bluetree242.discordsrvutils.utils.Utils; - -public class SuggestionReactionListener extends ListenerAdapter { - - - private DiscordSRVUtils core= DiscordSRVUtils.get(); - public void onGuildMessageReactionAdd(GuildMessageReactionAddEvent e) { - if (e.getUser().isBot()) return; - core.handleCF(SuggestionManager.get().getSuggestionByMessageID(e.getMessageIdLong()), suggestion -> { - - Message msg = e.getChannel().retrieveMessageById(e.getMessageIdLong()).complete(); - Emoji yes = Utils.getEmoji(core.getSuggestionsConfig().yes_reaction(), new Emoji("✅")); - Emoji no = Utils.getEmoji(core.getSuggestionsConfig().no_reaction(), new Emoji("❌")); - if(!core.getSuggestionsConfig().allow_submitter_vote()) { - if (e.getUser().getIdLong() == suggestion.getSubmitter()) { - e.getReaction().removeReaction(e.getUser()).queue(); - return; - }} - if (!core.getSuggestionsConfig().allow_both_vote()) { - if (e.getReactionEmote().getName().equals(yes.getName())) { - msg.removeReaction(no.getNameInReaction(), e.getUser()).queue(); - } else if (e.getReactionEmote().getName().equals(no.getName())) { - msg.removeReaction(yes.getNameInReaction(), e.getUser()).queue(); - } - } - }, error -> { - error.printStackTrace(); - }); - } -} diff --git a/src/main/java/tk/bluetree242/discordsrvutils/suggestions/listeners/SuggestionVoteListener.java b/src/main/java/tk/bluetree242/discordsrvutils/suggestions/listeners/SuggestionVoteListener.java new file mode 100644 index 00000000..df0da315 --- /dev/null +++ b/src/main/java/tk/bluetree242/discordsrvutils/suggestions/listeners/SuggestionVoteListener.java @@ -0,0 +1,169 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + +package tk.bluetree242.discordsrvutils.suggestions.listeners; + +import github.scarsz.discordsrv.dependencies.jda.api.entities.Message; +import github.scarsz.discordsrv.dependencies.jda.api.entities.MessageReaction; +import github.scarsz.discordsrv.dependencies.jda.api.entities.User; +import github.scarsz.discordsrv.dependencies.jda.api.events.interaction.ButtonClickEvent; +import github.scarsz.discordsrv.dependencies.jda.api.events.message.guild.react.GuildMessageReactionAddEvent; +import github.scarsz.discordsrv.dependencies.jda.api.events.message.guild.react.GuildMessageReactionRemoveEvent; +import github.scarsz.discordsrv.dependencies.jda.api.hooks.ListenerAdapter; +import tk.bluetree242.discordsrvutils.DiscordSRVUtils; +import tk.bluetree242.discordsrvutils.suggestions.SuggestionManager; +import tk.bluetree242.discordsrvutils.suggestions.SuggestionVote; +import tk.bluetree242.discordsrvutils.tickets.TicketManager; +import tk.bluetree242.discordsrvutils.utils.Emoji; +import tk.bluetree242.discordsrvutils.utils.Utils; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.List; + +public class SuggestionVoteListener extends ListenerAdapter { + + + private DiscordSRVUtils core= DiscordSRVUtils.get(); + public void onGuildMessageReactionAdd(GuildMessageReactionAddEvent e) { + if (core.getMainConfig().bungee_mode()) return; + if (e.getUser().isBot()) return; + core.handleCF(SuggestionManager.get().getSuggestionByMessageID(e.getMessageIdLong()), suggestion -> { + + Message msg = e.getChannel().retrieveMessageById(e.getMessageIdLong()).complete(); + Emoji yes = Utils.getEmoji(core.getSuggestionsConfig().yes_reaction(), new Emoji("✅")); + Emoji no = Utils.getEmoji(core.getSuggestionsConfig().no_reaction(), new Emoji("❌")); + if (SuggestionManager.get().loading) { + e.getReaction().removeReaction(e.getUser()).queue(); + return; + } + if(!core.getSuggestionsConfig().allow_submitter_vote()) { + if (e.getUser().getIdLong() == suggestion.getSubmitter()) { + e.getReaction().removeReaction(e.getUser()).queue(); + return; + }} + + if (e.getReactionEmote().getName().equals(yes.getName())) { + msg.removeReaction(no.getNameInReaction(), e.getUser()).queue(); + } else if (e.getReactionEmote().getName().equals(no.getName())) { + msg.removeReaction(yes.getNameInReaction(), e.getUser()).queue(); + } + msg.editMessage(suggestion.getCurrentMsg()).queue(); + }, error -> { + core.defaultHandle(error); + }); + } + public void onGuildMessageReactionRemove(GuildMessageReactionRemoveEvent e) { + core.handleCF(SuggestionManager.get().getSuggestionByMessageID(e.getMessageIdLong()), suggestion -> { + Message msg = suggestion.getMessage(); + if ((System.currentTimeMillis() - msg.getTimeEdited().toEpochSecond() ) > 1000) { + msg.editMessage(suggestion.getCurrentMsg()).queue(); + } + }, error -> { + core.defaultHandle(error); + }); + } + + + + + public void onButtonClick(ButtonClickEvent e) { + if (core.getMainConfig().bungee_mode()) return; + if (e.getUser().isBot()) return; + core.handleCF(SuggestionManager.get().getSuggestionByMessageID(e.getMessageIdLong()), suggestion -> { + + Message msg = e.getChannel().retrieveMessageById(e.getMessageIdLong()).complete(); + Emoji yes = Utils.getEmoji(core.getSuggestionsConfig().yes_reaction(), new Emoji("✅")); + Emoji no = Utils.getEmoji(core.getSuggestionsConfig().no_reaction(), new Emoji("❌")); + if (SuggestionManager.get().loading) { + return; + } + if(!core.getSuggestionsConfig().allow_submitter_vote()) { + if (e.getUser().getIdLong() == suggestion.getSubmitter()) { + e.deferReply(true).setContent("You may not vote your own suggestion").queue(); + return; + }} + if (e.getButton().getId().equals("yes")) { + try (Connection conn = core.getDatabase()){ + PreparedStatement p1 = conn.prepareStatement("DELETE FROM suggestions_votes WHERE UserID=? AND SuggestionNumber=?"); + p1.setLong(1, e.getUser().getIdLong()); + p1.setInt(2, suggestion.getNumber()); + p1.execute(); + p1 = conn.prepareStatement("INSERT INTO suggestions_votes (UserID, SuggestionNumber, Agree) VALUES (?,?,?)"); + p1.setLong(1, e.getUser().getIdLong()); + p1.setInt(2, suggestion.getNumber()); + p1.setString(3, "true"); + p1.execute(); + for (SuggestionVote vote : suggestion.getVotes()) { + if (vote.getId() == e.getUser().getIdLong()) suggestion.getVotes().remove(vote); + } + suggestion.getVotes().add(new SuggestionVote(e.getUser().getIdLong(), suggestion.getNumber(), true)); + } catch (SQLException ex) { + core.defaultHandle(ex); + return; + } + e.deferReply(true).setContent("You now agree with this suggestion").queue(); + } else if (e.getButton().getId().equals("no")) { + try (Connection conn = core.getDatabase()){ + PreparedStatement p1 = conn.prepareStatement("DELETE FROM suggestions_votes WHERE UserID=? AND SuggestionNumber=?"); + p1.setLong(1, e.getUser().getIdLong()); + p1.setInt(2, suggestion.getNumber()); + p1.execute(); + p1 = conn.prepareStatement("INSERT INTO suggestions_votes (UserID, SuggestionNumber, Agree) VALUES (?,?,?)"); + p1.setLong(1, e.getUser().getIdLong()); + p1.setInt(2, suggestion.getNumber()); + p1.setString(3, "true"); + p1.execute(); + for (SuggestionVote vote : suggestion.getVotes()) { + if (vote.getId() == e.getUser().getIdLong()) suggestion.getVotes().remove(vote); + } + suggestion.getVotes().add(new SuggestionVote(e.getUser().getIdLong(), suggestion.getNumber(), false)); + + } catch (SQLException ex) { + core.defaultHandle(ex); + return; + } + e.deferReply(true).setContent("You now disagree with this suggestion").queue(); + } else if (e.getButton().getId().equals("reset")) { + try (Connection conn = core.getDatabase()){ + PreparedStatement p1 = conn.prepareStatement("DELETE FROM suggestions_votes WHERE UserID=? AND SuggestionNumber=?"); + p1.setLong(1, e.getUser().getIdLong()); + p1.setInt(2, suggestion.getNumber()); + p1.execute(); + for (SuggestionVote vote : suggestion.getVotes()) { + if (vote.getId() == e.getUser().getIdLong()) suggestion.getVotes().remove(vote); + } + e.deferReply(true).setContent("Cleared your vote to this suggestion").queue(); + } catch (SQLException ex) { + core.defaultHandle(ex); + return; + } + } + msg.editMessage(suggestion.getCurrentMsg()).setActionRows(SuggestionManager.getActionRow()).queue(); + }, error -> { + error.printStackTrace(); + }); + } + + +} diff --git a/src/main/java/tk/bluetree242/discordsrvutils/tickets/Panel.java b/src/main/java/tk/bluetree242/discordsrvutils/tickets/Panel.java index e06a360b..81fec306 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/tickets/Panel.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/tickets/Panel.java @@ -1,10 +1,34 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.tickets; import github.scarsz.discordsrv.dependencies.jda.api.Permission; +import github.scarsz.discordsrv.dependencies.jda.api.entities.Emoji; import github.scarsz.discordsrv.dependencies.jda.api.entities.Message; import github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel; import github.scarsz.discordsrv.dependencies.jda.api.entities.User; import github.scarsz.discordsrv.dependencies.jda.api.exceptions.ErrorResponseException; +import github.scarsz.discordsrv.dependencies.jda.api.interactions.components.Button; import github.scarsz.discordsrv.dependencies.jda.api.requests.restaction.ChannelAction; import github.scarsz.discordsrv.dependencies.jda.internal.utils.Checks; import org.jetbrains.annotations.Nullable; @@ -147,8 +171,7 @@ public CompletableFuture> getTicketsForUser(User user, boolean inclu new PlaceholdObject(user, "user"), new PlaceholdObject(this, "panel"), new PlaceholdObject(core.getGuild(), "guild") - ),null).build()).complete(); - msg.addReaction("\uD83D\uDD12").queue(); + ),null).build()).setActionRow(Button.danger("close_ticket", Emoji.fromUnicode("\uD83D\uDD12")).withLabel("Close Ticket")).complete(); PreparedStatement p1 = conn.prepareStatement("INSERT INTO tickets (ID, Channel, MessageID, Closed, UserID, OpenTime) VALUES (?, ?, ?, ?, ?, ?)"); p1.setString(1, id); p1.setLong(2, channel.getIdLong()); @@ -229,8 +252,7 @@ public CompletableFuture create() { throw new IllegalArgumentException("Channel was not found"); } Panel panel = new Panel(name, new KeyGenerator().toString(), null, channelId, openedCategory, closedCategory, allowedRoles); - Message msg = channel.sendMessage(MessageManager.get().getMessage(core.getTicketsConfig().panel_message(), PlaceholdObjectList.ofArray(new PlaceholdObject(panel, "panel")), null).build()).complete(); - msg.addReaction("\uD83C\uDFAB").queue(); + Message msg = channel.sendMessage(MessageManager.get().getMessage(core.getTicketsConfig().panel_message(), PlaceholdObjectList.ofArray(new PlaceholdObject(panel, "panel")), null).build()).setActionRow(Button.secondary("open_ticket", Emoji.fromUnicode("\uD83C\uDFAB")).withLabel("Open Ticket")).complete(); panel.messageId = msg.getIdLong(); try (Connection conn = core.getDatabase()) { PreparedStatement p1 = conn.prepareStatement("INSERT INTO ticket_panels(Name, ID, Channel, MessageID, OpenedCategory, ClosedCategory) VALUES (?, ?, ?, ?, ?, ?)"); diff --git a/src/main/java/tk/bluetree242/discordsrvutils/tickets/Ticket.java b/src/main/java/tk/bluetree242/discordsrvutils/tickets/Ticket.java index 7cf11c7f..6d9a07e6 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/tickets/Ticket.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/tickets/Ticket.java @@ -1,8 +1,31 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.tickets; import github.scarsz.discordsrv.dependencies.jda.api.EmbedBuilder; import github.scarsz.discordsrv.dependencies.jda.api.Permission; import github.scarsz.discordsrv.dependencies.jda.api.entities.*; +import github.scarsz.discordsrv.dependencies.jda.api.interactions.components.Button; import tk.bluetree242.discordsrvutils.DiscordSRVUtils; import tk.bluetree242.discordsrvutils.exceptions.UnCheckedSQLException; import tk.bluetree242.discordsrvutils.messages.MessageManager; @@ -73,15 +96,15 @@ public CompletableFuture close(User userWhoClosed) { if (override != null) { override.getManager().deny(Permission.VIEW_CHANNEL).deny(Permission.MESSAGE_WRITE).queue(); } - core.getGuild().getTextChannelById(channelID).sendMessage(MessageManager.get().getMessage(core.getTicketsConfig().ticket_closed_message(), PlaceholdObjectList.ofArray( + Message msg = core.getGuild().getTextChannelById(channelID).sendMessage(MessageManager.get().getMessage(core.getTicketsConfig().ticket_closed_message(), PlaceholdObjectList.ofArray( new PlaceholdObject(userWhoClosed, "user"), new PlaceholdObject(core.getGuild().getMember(userWhoClosed), "member"), new PlaceholdObject(core.getGuild(), "guild"), new PlaceholdObject(panel, "panel") - ),null).build()).queue(); - Message msg = core.getGuild().getTextChannelById(channelID).sendMessage(new EmbedBuilder().setColor(Color.ORANGE).setDescription("\uD83D\uDD13 Reopen Ticket\n\uD83D\uDDD1️ Delete Ticket").setFooter("More Options coming soon").build()).complete(); - msg.addReaction("\uD83D\uDD13").queue(); - msg.addReaction("\uD83D\uDDD1️").queue(); + ),null).build()).setActionRow( + Button.success("reopen_ticket", Emoji.fromUnicode("\uD83D\uDD13")).withLabel("Reopen Ticket"), + Button.danger("delete_ticket", Emoji.fromUnicode("\uD83D\uDDD1️")).withLabel("Delete Ticket") + ).complete(); messageID = msg.getIdLong(); PreparedStatement p2 = conn.prepareStatement("UPDATE tickets SET MessageID=?, Closed='true', OpenTime=? WHERE UserID=? AND ID=? "); p2.setLong(1, messageID); @@ -118,8 +141,7 @@ public CompletableFuture reopen(User userWhoOpened) { new PlaceholdObject(core.getGuild().getMember(userWhoOpened), "member"), new PlaceholdObject(core.getGuild(), "guild"), new PlaceholdObject(panel, "panel") - ), null).build()).complete(); - msg.addReaction("\uD83D\uDD12").queue(); + ), null).build()).setActionRow(Button.danger("close_ticket", Emoji.fromUnicode("\uD83D\uDD12")).withLabel("Close Ticket")).complete(); messageID = msg.getIdLong(); PreparedStatement p2 = conn.prepareStatement("UPDATE tickets SET MessageID=?, Closed='false' WHERE UserID=? AND ID=? "); p2.setLong(1, messageID); diff --git a/src/main/java/tk/bluetree242/discordsrvutils/tickets/TicketManager.java b/src/main/java/tk/bluetree242/discordsrvutils/tickets/TicketManager.java index 9a1de068..7f932736 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/tickets/TicketManager.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/tickets/TicketManager.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.tickets; import tk.bluetree242.discordsrvutils.DiscordSRVUtils; @@ -60,7 +82,7 @@ public CompletableFuture> getPanels() { }); } - protected Panel getPanel(ResultSet r) throws SQLException { + public Panel getPanel(ResultSet r) throws SQLException { Set allowedRoles = new HashSet<>(); PreparedStatement p = r.getStatement().getConnection().prepareStatement("SELECT * FROM panel_allowed_roles WHERE PanelID=?"); p.setString(1, r.getString("ID")); diff --git a/src/main/java/tk/bluetree242/discordsrvutils/tickets/listeners/PanelReactListener.java b/src/main/java/tk/bluetree242/discordsrvutils/tickets/listeners/PanelReactListener.java index 70f11186..e43945ca 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/tickets/listeners/PanelReactListener.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/tickets/listeners/PanelReactListener.java @@ -1,6 +1,29 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.tickets.listeners; +import github.scarsz.discordsrv.dependencies.jda.api.events.interaction.ButtonClickEvent; import github.scarsz.discordsrv.dependencies.jda.api.events.message.guild.react.GuildMessageReactionAddEvent; import github.scarsz.discordsrv.dependencies.jda.api.events.message.react.MessageReactionAddEvent; import github.scarsz.discordsrv.dependencies.jda.api.hooks.ListenerAdapter; @@ -10,6 +33,7 @@ public class PanelReactListener extends ListenerAdapter { private DiscordSRVUtils core= DiscordSRVUtils.get(); public void onGuildMessageReactionAdd(GuildMessageReactionAddEvent e) { + if (core.getMainConfig().bungee_mode()) return; core.handleCF(TicketManager.get().getPanelByMessageId(e.getMessageIdLong()), panel -> { if (panel != null) { if (e.getUser().isBot()) return; @@ -19,4 +43,16 @@ public void onGuildMessageReactionAdd(GuildMessageReactionAddEvent e) { }, null); } + public void onButtonClick(ButtonClickEvent e) { + if (core.getMainConfig().bungee_mode()) return; + core.handleCF(TicketManager.get().getPanelByMessageId(e.getMessageIdLong()), panel -> { + if (panel != null) { + if (e.getUser().isBot()) return; + core.handleCF(panel.openTicket(e.getUser()).thenAcceptAsync(t -> { + e.deferReply(true).setContent("Ticket opened at " + core.getGuild().getTextChannelById(t.getChannelID()).getAsMention()).queue(); + }), null, er -> {core.defaultHandle(er); }); + } + }, null); + } + } diff --git a/src/main/java/tk/bluetree242/discordsrvutils/tickets/listeners/TicketCloseListener.java b/src/main/java/tk/bluetree242/discordsrvutils/tickets/listeners/TicketCloseListener.java index 564122aa..ab0a4828 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/tickets/listeners/TicketCloseListener.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/tickets/listeners/TicketCloseListener.java @@ -1,8 +1,30 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.tickets.listeners; +import github.scarsz.discordsrv.dependencies.jda.api.events.interaction.ButtonClickEvent; import github.scarsz.discordsrv.dependencies.jda.api.events.message.guild.react.GuildMessageReactionAddEvent; -import github.scarsz.discordsrv.dependencies.jda.api.events.message.react.MessageReactionAddEvent; import github.scarsz.discordsrv.dependencies.jda.api.hooks.ListenerAdapter; import tk.bluetree242.discordsrvutils.DiscordSRVUtils; import tk.bluetree242.discordsrvutils.tickets.TicketManager; @@ -12,6 +34,7 @@ public class TicketCloseListener extends ListenerAdapter { private DiscordSRVUtils core = DiscordSRVUtils.get(); public void onGuildMessageReactionAdd(GuildMessageReactionAddEvent e) { + if (core.getMainConfig().bungee_mode()) return; core.handleCF(TicketManager.get().getTicketByMessageId(e.getMessageIdLong()), ticket -> { if (ticket != null) { if (e.getUser().isBot()) return; @@ -33,4 +56,28 @@ public void onGuildMessageReactionAdd(GuildMessageReactionAddEvent e) { } }, null); } + + public void onButtonClick(ButtonClickEvent e) { + if (core.getMainConfig().bungee_mode()) return; + core.handleCF(TicketManager.get().getTicketByMessageId(e.getMessageIdLong()), ticket -> { + if (ticket != null) { + if (e.getUser().isBot()) return; + if (e.getButton().getId().equals("close_ticket")) { + e.deferEdit().queue(); + if (!ticket.isClosed()) + ticket.close(e.getUser()); + } else if (e.getButton().getId().equals("delete_ticket")) { + e.deferEdit().queue(); + if (ticket.isClosed()) { + ticket.delete(); + } + } if (e.getButton().getId().equals("reopen_ticket")) { + e.deferEdit().queue(); + if (ticket.isClosed()) { + core.handleCF(ticket.reopen(e.getUser()), null, ex -> {core.defaultHandle(ex);}); + } + } else return; + } + }, null); + } } diff --git a/src/main/java/tk/bluetree242/discordsrvutils/tickets/listeners/TicketDeleteListener.java b/src/main/java/tk/bluetree242/discordsrvutils/tickets/listeners/TicketDeleteListener.java index 5d297d74..38145dbe 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/tickets/listeners/TicketDeleteListener.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/tickets/listeners/TicketDeleteListener.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.tickets.listeners; @@ -15,7 +37,8 @@ public class TicketDeleteListener extends ListenerAdapter { public void onTextChannelDelete(TextChannelDeleteEvent e) { - DiscordSRVUtils.get().executeAsync(() -> { + if (DiscordSRVUtils.get().getMainConfig().bungee_mode()) return; + DiscordSRVUtils.get().executeAsync(() -> { try (Connection conn = DiscordSRVUtils.get().getDatabase()) { PreparedStatement p1 = conn.prepareStatement("DELETE FROM tickets WHERE Channel=?"); p1.setLong(1, e.getChannel().getIdLong()); diff --git a/src/main/java/tk/bluetree242/discordsrvutils/utils/DebugUtil.java b/src/main/java/tk/bluetree242/discordsrvutils/utils/DebugUtil.java index 8eeb8c8f..1024e713 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/utils/DebugUtil.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/utils/DebugUtil.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.utils; import github.scarsz.discordsrv.DiscordSRV; @@ -14,7 +36,7 @@ import github.scarsz.discordsrv.util.DiscordUtil; import github.scarsz.discordsrv.util.PlayerUtil; import github.scarsz.discordsrv.util.PluginUtil; -import okhttp3.*; +import github.scarsz.discordsrv.dependencies.okhttp3.*; import org.bukkit.Bukkit; import org.json.JSONArray; import org.json.JSONObject; @@ -27,6 +49,7 @@ import java.lang.management.ManagementFactory; import java.nio.charset.StandardCharsets; import java.nio.file.Paths; +import java.security.InvalidKeyException; import java.security.SecureRandom; import java.util.*; import java.util.concurrent.TimeUnit; @@ -46,7 +69,6 @@ public static String run() { JSONArray data = new JSONArray(); Map information = new HashMap<>(); - information.put("name", "Information"); information.put("DSU Version", core.getDescription().getVersion()); information.put("Plugins Hooked", String.join(", " + core.hookedPlugins)); information.put("DSU Command Executor", Bukkit.getServer().getPluginCommand("discordsrvutils").getPlugin() + ""); @@ -86,7 +108,7 @@ public static String run() { data.put(new JSONObject().put("type", "files").put("name", "DSU Messages Files").put("data", FilesToArray(files))); int aesBits = 256; String key = RandomStringUtils.randomAlphanumeric(aesBits == 256 ? 32 : 16); - RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("data", Utils.b64Encode(new String(encrypt(key.getBytes(), data.toString().getBytes())))).build(); + RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("data", Utils.b64Encode(encrypt(key.getBytes(), data.toString()))).build(); Request request = new Request.Builder().post(body).url("https://mcdebug.bluetree242.tk/api/v1/createDebug").build(); try { Response response = client.newCall(request).execute(); @@ -297,12 +319,24 @@ public static byte[] encrypt(byte[] key, String data){ private static final SecureRandom RANDOM = new SecureRandom(); public static byte[] encrypt(byte[] key, byte[] data) throws Exception{ - Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); - byte[] iv = new byte[cipher.getBlockSize()]; - RANDOM.nextBytes(iv); - cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "AES"), new IvParameterSpec(iv)); - byte[] encrypted = cipher.doFinal(data); - return ArrayUtils.addAll(iv, encrypted); + try { + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); + byte[] iv = new byte[cipher.getBlockSize()]; + RANDOM.nextBytes(iv); + cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "AES"), new IvParameterSpec(iv)); + byte[] encrypted = cipher.doFinal(data); + return ArrayUtils.addAll(iv, encrypted); + } catch (InvalidKeyException e) { + if (e.getMessage().toLowerCase().contains("illegal key size")) { + throw new RuntimeException(e.getMessage(), e); + } else { + DiscordSRV.error(e); + } + return null; + } catch (Exception ex) { + DiscordSRV.error(ex); + return null; + } } diff --git a/src/main/java/tk/bluetree242/discordsrvutils/utils/Emoji.java b/src/main/java/tk/bluetree242/discordsrvutils/utils/Emoji.java index 0193b270..8cdcc643 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/utils/Emoji.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/utils/Emoji.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.utils; public class Emoji { @@ -43,5 +65,13 @@ public String getNameInReaction() { return nameInReaction; } + public github.scarsz.discordsrv.dependencies.jda.api.entities.Emoji toJDAEmoji() { + if (emote) { + return github.scarsz.discordsrv.dependencies.jda.api.entities.Emoji.fromEmote(name, id, animated); + } else { + return github.scarsz.discordsrv.dependencies.jda.api.entities.Emoji.fromUnicode(name); + } + } + } diff --git a/src/main/java/tk/bluetree242/discordsrvutils/utils/FileWriter.java b/src/main/java/tk/bluetree242/discordsrvutils/utils/FileWriter.java new file mode 100644 index 00000000..d3721744 --- /dev/null +++ b/src/main/java/tk/bluetree242/discordsrvutils/utils/FileWriter.java @@ -0,0 +1,41 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + +package tk.bluetree242.discordsrvutils.utils; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.OutputStreamWriter; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +public class FileWriter extends OutputStreamWriter { + + public FileWriter(File file, Charset charset) throws FileNotFoundException { + super(new FileOutputStream(file), charset); + } + + public FileWriter(File file) throws FileNotFoundException { + super(new FileOutputStream(file), StandardCharsets.UTF_8); + } +} diff --git a/src/main/java/tk/bluetree242/discordsrvutils/utils/KeyGenerator.java b/src/main/java/tk/bluetree242/discordsrvutils/utils/KeyGenerator.java index dd5edc5e..89e55f5b 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/utils/KeyGenerator.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/utils/KeyGenerator.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.utils; import java.security.SecureRandom; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/utils/SuggestionVoteMode.java b/src/main/java/tk/bluetree242/discordsrvutils/utils/SuggestionVoteMode.java new file mode 100644 index 00000000..fa6f33ee --- /dev/null +++ b/src/main/java/tk/bluetree242/discordsrvutils/utils/SuggestionVoteMode.java @@ -0,0 +1,27 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + +package tk.bluetree242.discordsrvutils.utils; + +public enum SuggestionVoteMode { + REACTIONS, BUTTONS; +} diff --git a/src/main/java/tk/bluetree242/discordsrvutils/utils/Utils.java b/src/main/java/tk/bluetree242/discordsrvutils/utils/Utils.java index b12155c3..89b945a9 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/utils/Utils.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/utils/Utils.java @@ -1,8 +1,32 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.utils; import com.vdurmont.emoji.EmojiParser; import github.scarsz.discordsrv.dependencies.jda.api.entities.Emote; import org.bukkit.ChatColor; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; import tk.bluetree242.discordsrvutils.DiscordSRVUtils; import java.io.File; @@ -145,16 +169,21 @@ public static String trim(String s, int limit) { return s; } - public static String b64Encode(String text) { + public static String b64Encode(@NotNull String text) { return Base64.getEncoder().encodeToString(text.getBytes()); } - public static String b64Decode(String text) { + public static String b64Encode(@NotNull byte[] bytes) { + return Base64.getEncoder().encodeToString(bytes); + } + + @Contract("_ -> new") + public static @NotNull String b64Decode(String text) { return new String(Base64.getDecoder().decode(text), StandardCharsets.UTF_8); } - public static String parseArgs(String[] args, int start, int end) { + public static @NotNull String parseArgs(String[] args, int start, int end) { String argss = ""; for (int i = start; i < args.length; i++) { if (i <= end) { @@ -164,7 +193,7 @@ public static String parseArgs(String[] args, int start, int end) { return argss.replaceAll("\\s+$", ""); } - public static String parseArgs(String[] args, int start) { + public static @NotNull String parseArgs(String @NotNull [] args, int start) { String argss = ""; for (int i = start; i < args.length; i++) { argss = argss + args[i] + " "; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/waiter/Waiter.java b/src/main/java/tk/bluetree242/discordsrvutils/waiter/Waiter.java index c59d86f0..fe53c613 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/waiter/Waiter.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/waiter/Waiter.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.waiter; import github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/waiter/WaiterCanceller.java b/src/main/java/tk/bluetree242/discordsrvutils/waiter/WaiterCanceller.java index 3eb6009c..2034506d 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/waiter/WaiterCanceller.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/waiter/WaiterCanceller.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.waiter; import java.util.Set; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/waiter/WaiterManager.java b/src/main/java/tk/bluetree242/discordsrvutils/waiter/WaiterManager.java index 6ca2ec97..41a90743 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/waiter/WaiterManager.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/waiter/WaiterManager.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.waiter; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/waiters/CreatePanelWaiter.java b/src/main/java/tk/bluetree242/discordsrvutils/waiters/CreatePanelWaiter.java index 77f67e7a..9b5a477f 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/waiters/CreatePanelWaiter.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/waiters/CreatePanelWaiter.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.waiters; import github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/waiters/EditPanelWaiter.java b/src/main/java/tk/bluetree242/discordsrvutils/waiters/EditPanelWaiter.java index f5f9f41d..0b86b496 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/waiters/EditPanelWaiter.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/waiters/EditPanelWaiter.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.waiters; import github.scarsz.discordsrv.dependencies.jda.api.EmbedBuilder; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/waiters/PaginationWaiter.java b/src/main/java/tk/bluetree242/discordsrvutils/waiters/PaginationWaiter.java index 6f4344ce..cda3ece1 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/waiters/PaginationWaiter.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/waiters/PaginationWaiter.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.waiters; import github.scarsz.discordsrv.dependencies.jda.api.Permission; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/waiters/listeners/CreatePanelListener.java b/src/main/java/tk/bluetree242/discordsrvutils/waiters/listeners/CreatePanelListener.java index b32cfc09..a47cb168 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/waiters/listeners/CreatePanelListener.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/waiters/listeners/CreatePanelListener.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.waiters.listeners; @@ -41,11 +63,11 @@ public void onGuildMessageReceived(GuildMessageReceivedEvent e) { embed.setDescription("**Step 2: Please mention the channel the panel should be sent to**"); e.getChannel().sendMessage(embed.build()).queue(); } else if (waiter.getStep() ==2) { - TextChannel channel = e.getMessage().getMentionedChannels().get(0); - if (channel == null) { + if (e.getMessage().getMentionedChannels().isEmpty()) { e.getChannel().sendMessage(Embed.error("You did not mention a channel. Please try again")).queue(); return; } + TextChannel channel = e.getMessage().getMentionedChannels().get(0); if (channel.getGuild().getIdLong() != core.getGuild().getIdLong()) { e.getChannel().sendMessage(Embed.error("Channel cannot be outside of the main guild")).queue(); return; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/waiters/listeners/EditPanelListener.java b/src/main/java/tk/bluetree242/discordsrvutils/waiters/listeners/EditPanelListener.java index e10b6510..e128debd 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/waiters/listeners/EditPanelListener.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/waiters/listeners/EditPanelListener.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.waiters.listeners; diff --git a/src/main/java/tk/bluetree242/discordsrvutils/waiters/listeners/PaginationListener.java b/src/main/java/tk/bluetree242/discordsrvutils/waiters/listeners/PaginationListener.java index 278df674..60030100 100644 --- a/src/main/java/tk/bluetree242/discordsrvutils/waiters/listeners/PaginationListener.java +++ b/src/main/java/tk/bluetree242/discordsrvutils/waiters/listeners/PaginationListener.java @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + package tk.bluetree242.discordsrvutils.waiters.listeners; import github.scarsz.discordsrv.dependencies.jda.api.Permission; diff --git a/src/main/resources/migrations/V1__PANELS_AND_TICKETS.sql b/src/main/resources/migrations/V1__PANELS_AND_TICKETS.sql index 5fbea861..151fb5b3 100644 --- a/src/main/resources/migrations/V1__PANELS_AND_TICKETS.sql +++ b/src/main/resources/migrations/V1__PANELS_AND_TICKETS.sql @@ -1,2 +1,24 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + CREATE TABLE ticket_panels(Name varchar(32), ID varchar(10), Channel BIGINT, MessageID BIGINT, OpenedCategory Bigint, ClosedCategory Bigint); CREATE TABLE tickets(ID varchar(10), Channel Bigint, MessageID Bigint, Closed varchar(4)); \ No newline at end of file diff --git a/src/main/resources/migrations/V2__PANEL_ALLOWED_ROLES.sql b/src/main/resources/migrations/V2__PANEL_ALLOWED_ROLES.sql index b8aec6da..41259c26 100644 --- a/src/main/resources/migrations/V2__PANEL_ALLOWED_ROLES.sql +++ b/src/main/resources/migrations/V2__PANEL_ALLOWED_ROLES.sql @@ -1 +1,23 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + CREATE TABLE panel_allowed_roles(RoleID Bigint, PanelID varchar(10)) \ No newline at end of file diff --git a/src/main/resources/migrations/V3__ADD_MORE_TO_TICKETS.sql b/src/main/resources/migrations/V3__ADD_MORE_TO_TICKETS.sql index dbffe5fe..bebd9db0 100644 --- a/src/main/resources/migrations/V3__ADD_MORE_TO_TICKETS.sql +++ b/src/main/resources/migrations/V3__ADD_MORE_TO_TICKETS.sql @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + ALTER TABLE tickets ADD COLUMN UserID Bigint; ALTER TABLE tickets ADD COLUMN OpenTime BIGINT; \ No newline at end of file diff --git a/src/main/resources/migrations/V4__FIX_TICKET_CLOSED_BUG.sql b/src/main/resources/migrations/V4__FIX_TICKET_CLOSED_BUG.sql index d16988c6..d35a9efc 100644 --- a/src/main/resources/migrations/V4__FIX_TICKET_CLOSED_BUG.sql +++ b/src/main/resources/migrations/V4__FIX_TICKET_CLOSED_BUG.sql @@ -1,2 +1,24 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + ALTER TABLE tickets DROP COLUMN Closed; ALTER TABLE tickets ADD COLUMN Closed varchar(5) \ No newline at end of file diff --git a/src/main/resources/migrations/V5__LEVELING.sql b/src/main/resources/migrations/V5__LEVELING.sql index a576746e..4c7b82f2 100644 --- a/src/main/resources/migrations/V5__LEVELING.sql +++ b/src/main/resources/migrations/V5__LEVELING.sql @@ -1 +1,23 @@ -CREATE TABLE leveling(UUID varchar(1000) PRIMARY KEY , Name varchar(50), Level int, XP int, DiscordMessages int, MinecraftMessages int) \ No newline at end of file +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + +CREATE TABLE leveling(UUID varchar(50) PRIMARY KEY , Name varchar(50), Level int, XP int, DiscordMessages int, MinecraftMessages int) diff --git a/src/main/resources/migrations/V6__SUGGESTIONS.sql b/src/main/resources/migrations/V6__SUGGESTIONS.sql index 1ed93186..5c37ad78 100644 --- a/src/main/resources/migrations/V6__SUGGESTIONS.sql +++ b/src/main/resources/migrations/V6__SUGGESTIONS.sql @@ -1,3 +1,25 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + CREATE TABLE suggestions(SuggestionNumber int PRIMARY KEY, SuggestionText LONGTEXT, Submitter BIGINT, MessageID BIGINT, ChannelID BIGINT, CreationTime BIGINT, Approved varchar(5), Approver BIGINT); CREATE TABLE suggestion_notes(StaffID BIGINT,NoteText LONGTEXT,SuggestionNumber int, CreationTime BIGINT) \ No newline at end of file diff --git a/src/main/resources/migrations/V7__SUGGESTIONS_VOTES.sql b/src/main/resources/migrations/V7__SUGGESTIONS_VOTES.sql new file mode 100644 index 00000000..3544be3a --- /dev/null +++ b/src/main/resources/migrations/V7__SUGGESTIONS_VOTES.sql @@ -0,0 +1,23 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2021 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + +CREATE TABLE suggestions_votes(UserID BIGINT, SuggestionNumber BIGINT, Agree varchar(5)) \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index a3b4548a..0e8e0890 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,10 +1,12 @@ name: DiscordSRVUtils -softdepend: +depend: - DiscordSRV +softdepend: - Essentials - Advancedban - PlaceholderAPI -version: 1.2.0-BETA-8 + - Litebans +version: @version@ main: tk.bluetree242.discordsrvutils.DiscordSRVUtils author: BlueTree242 api-version: 1.13