From 966421d2ab72760f547585eceba5888ec5084b39 Mon Sep 17 00:00:00 2001 From: codedcosmos Date: Sun, 30 Aug 2020 15:38:37 +1000 Subject: [PATCH] 2.0 --- build.gradle | 4 +- res/plugin.yml | 2 +- .../enderbot/core/ConfigManager.java | 16 ++----- src/codedcosmos/enderbot/core/EnderBot.java | 17 +------ src/codedcosmos/enderbot/discord/JDABot.java | 6 --- .../plugin/MinecraftChatListener.java | 6 ++- .../enderbot/plugin/MinecraftPlugin.java | 44 ++++++++++++++----- src/codedcosmos/enderbot/utils/FileUtils.java | 1 + .../enderbot/utils/GoogleDrive.java | 3 ++ src/codedcosmos/enderbot/utils/Log.java | 6 +-- 10 files changed, 53 insertions(+), 52 deletions(-) diff --git a/build.gradle b/build.gradle index b1cc6a0..647f978 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { } group 'codedcosmos' -version '1.4' +version '2.0' mainClassName = 'codedcosmos.enderbot.core.EnderBot' sourceCompatibility = 1.8 @@ -35,7 +35,7 @@ sourceSets { } dependencies { - compile 'net.dv8tion:JDA:4.2.0_175' + compile 'net.dv8tion:JDA:4.2.0_192' compile 'com.google.api-client:google-api-client:1.23.0' compile 'com.google.oauth-client:google-oauth-client-jetty:1.23.0' diff --git a/res/plugin.yml b/res/plugin.yml index d5c0b71..a704ec2 100644 --- a/res/plugin.yml +++ b/res/plugin.yml @@ -1,5 +1,5 @@ name: EnderBot -version: 1.4 +version: 2.0 author: codedcosmos main: codedcosmos.enderbot.plugin.MinecraftPlugin api-version: 1.16 diff --git a/src/codedcosmos/enderbot/core/ConfigManager.java b/src/codedcosmos/enderbot/core/ConfigManager.java index 45f6fa3..b50e3c4 100644 --- a/src/codedcosmos/enderbot/core/ConfigManager.java +++ b/src/codedcosmos/enderbot/core/ConfigManager.java @@ -65,9 +65,7 @@ public static void createIfMissing() { if (!FileUtils.doesFileExist(getConfig())) { Log.print("EnderBot Config File does not exist, generating!"); - if (EnderBot.isRunningInSpigot()) { - FileUtils.mkdir(CONFIG_SPIGOT_PATH); - } + FileUtils.mkdir(CONFIG_SPIGOT_PATH); // Write to file try { @@ -154,18 +152,10 @@ public static void load() { } private static String getPath() { - if (EnderBot.isRunningInSpigot()) { - return CONFIG_SPIGOT_PATH; - } else { - return CONFIG_RUNTIME_PATH; - } + return CONFIG_SPIGOT_PATH; } private static String getConfig() { - if (EnderBot.isRunningInSpigot()) { - return CONFIG_SPIGOT; - } else { - return CONFIG_RUNTIME; - } + return CONFIG_SPIGOT; } } diff --git a/src/codedcosmos/enderbot/core/EnderBot.java b/src/codedcosmos/enderbot/core/EnderBot.java index 8062017..6cef0bf 100644 --- a/src/codedcosmos/enderbot/core/EnderBot.java +++ b/src/codedcosmos/enderbot/core/EnderBot.java @@ -18,24 +18,11 @@ public class EnderBot { - private static final String VERSION = "1.4"; - private static boolean runningInSpigot = false; - - public static void load(boolean runningInSpigot) { - EnderBot.runningInSpigot = runningInSpigot; - - if (runningInSpigot) { - Log.print("Loading for Spigot Runtime"); - } else { - Log.print("Loading for Local Runtime"); - } + private static final String VERSION = "2.0"; + public static void load() { ConfigManager.load(); } - - public static boolean isRunningInSpigot() { - return runningInSpigot; - } public static String getVersion() { return VERSION; diff --git a/src/codedcosmos/enderbot/discord/JDABot.java b/src/codedcosmos/enderbot/discord/JDABot.java index 194eeb0..b19fdb0 100644 --- a/src/codedcosmos/enderbot/discord/JDABot.java +++ b/src/codedcosmos/enderbot/discord/JDABot.java @@ -25,12 +25,6 @@ public class JDABot { private static JDA jda; - - public static void main(String[] args) { - Log.print("Starting EnderBot Discord Subsystem"); - EnderBot.load(false); - initBot(); - } public static void initBot() { Guilds.init(); diff --git a/src/codedcosmos/enderbot/plugin/MinecraftChatListener.java b/src/codedcosmos/enderbot/plugin/MinecraftChatListener.java index a3ef9ac..21e0392 100644 --- a/src/codedcosmos/enderbot/plugin/MinecraftChatListener.java +++ b/src/codedcosmos/enderbot/plugin/MinecraftChatListener.java @@ -51,7 +51,11 @@ public void onPlayerQuit(PlayerQuitEvent event) { @EventHandler public void onPlayerAdvancementDone(PlayerAdvancementDoneEvent event) { String advancement = event.getAdvancement().getKey().getKey(); - if (advancement.startsWith("recipe")) return; + if (!advancement.startsWith("adventure") && + !advancement.startsWith("end") && + !advancement.startsWith("husbandry") && + !advancement.startsWith("nether") && + !advancement.startsWith("story")) return; for (GuildContext context : Guilds.getContexts()) { context.getInGameChannel().sendMessage("`"+format(event.getPlayer().getDisplayName()) + " has made the advancement ["+ advancement +"]`"); diff --git a/src/codedcosmos/enderbot/plugin/MinecraftPlugin.java b/src/codedcosmos/enderbot/plugin/MinecraftPlugin.java index 571fdf4..6544f3e 100644 --- a/src/codedcosmos/enderbot/plugin/MinecraftPlugin.java +++ b/src/codedcosmos/enderbot/plugin/MinecraftPlugin.java @@ -14,6 +14,8 @@ package codedcosmos.enderbot.plugin; import codedcosmos.enderbot.core.ConfigManager; +import codedcosmos.enderbot.discord.GuildContext; +import codedcosmos.enderbot.discord.Guilds; import codedcosmos.enderbot.discord.JDABot; import codedcosmos.enderbot.core.EnderBot; import codedcosmos.enderbot.plugin.commands.BackupCommand; @@ -29,7 +31,7 @@ public class MinecraftPlugin extends JavaPlugin { public void onEnable(){ //Fired when the server enables the plugin Log.print("Enabling EnderBot v" + EnderBot.getVersion()); - EnderBot.load(true); + EnderBot.load(); JDABot.initBot(); mainPlugin = this; @@ -37,25 +39,47 @@ public void onEnable(){ this.getCommand("enderbackup").setExecutor(new BackupCommand()); getServer().getPluginManager().registerEvents(new MinecraftChatListener(), this); + + for (GuildContext context : Guilds.getContexts()) { + context.getInGameChannel().sendMessage("`Server is Online`"); + } - if (ConfigManager.world_backups_enabled) archiveLoop(); + if (ConfigManager.world_backups_enabled) { + GoogleDrive.archiveIfNeeded(); + // Bad code but whatever + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + archiveLoop(); + } } public void archiveLoop() { - JavaPlugin plugin = this; - getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { - public void run() { - GoogleDrive.archiveIfNeeded(); - archiveLoop(); - } - }, 20L*60*30); + getServer().getScheduler().scheduleSyncDelayedTask(this, () -> { + GoogleDrive.archiveIfNeeded(); + archiveLoop(); + }, 20L*60*60*4); } @Override public void onDisable(){ - //Fired when the server stops and disables all plugins + // Fired when the server stops and disables all plugins Log.print("Disabiling EnderBot"); + + for (GuildContext context : Guilds.getContexts()) { + context.getInGameChannel().sendMessage("`Server is Offline`"); + } + + // Terrible idea but it works I guess + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + JDABot.stop(); } } diff --git a/src/codedcosmos/enderbot/utils/FileUtils.java b/src/codedcosmos/enderbot/utils/FileUtils.java index 0bc2805..096412c 100644 --- a/src/codedcosmos/enderbot/utils/FileUtils.java +++ b/src/codedcosmos/enderbot/utils/FileUtils.java @@ -49,6 +49,7 @@ public static void zip(String source, String zipname) throws IOException { zs.putNextEntry(zipEntry); Files.copy(path, zs); zs.closeEntry(); + Log.print("Zipping " + path); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/codedcosmos/enderbot/utils/GoogleDrive.java b/src/codedcosmos/enderbot/utils/GoogleDrive.java index 21846cc..a92bb05 100644 --- a/src/codedcosmos/enderbot/utils/GoogleDrive.java +++ b/src/codedcosmos/enderbot/utils/GoogleDrive.java @@ -65,6 +65,7 @@ public class GoogleDrive { public static final String BACKUP_PATH = "plugins/EnderBot/backups"; public static void archiveIfNeeded() { + Log.print("Checking archive"); if (shouldArchive()) { archive(); } @@ -149,8 +150,10 @@ public void run() { } catch (IOException e) { e.printStackTrace(); } + Console.print("Created zip file"); // Upload it + Console.print("Uploading"); upload(); int timeMS = (int) (System.currentTimeMillis()-start); diff --git a/src/codedcosmos/enderbot/utils/Log.java b/src/codedcosmos/enderbot/utils/Log.java index f0e4dc3..a6656a2 100644 --- a/src/codedcosmos/enderbot/utils/Log.java +++ b/src/codedcosmos/enderbot/utils/Log.java @@ -30,15 +30,13 @@ public class Log { public static void print(Object... line) { String completedLine = getCompletedLine(line); - if (EnderBot.isRunningInSpigot()) System.out.print(completedLine); - else System.out.println(completedLine); + System.out.println(completedLine); } public static void printErr(Object... line) { String completedLine = getCompletedLine(line); - if (EnderBot.isRunningInSpigot()) System.err.print(completedLine); - else System.err.println(completedLine); + System.err.println(completedLine); } // Insert line