Skip to content

Commit

Permalink
2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
codedcosmos committed Aug 30, 2020
1 parent e3085ed commit 966421d
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 52 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group 'codedcosmos'
version '1.4'
version '2.0'
mainClassName = 'codedcosmos.enderbot.core.EnderBot'

sourceCompatibility = 1.8
Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion res/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: EnderBot
version: 1.4
version: 2.0
author: codedcosmos
main: codedcosmos.enderbot.plugin.MinecraftPlugin
api-version: 1.16
Expand Down
16 changes: 3 additions & 13 deletions src/codedcosmos/enderbot/core/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
}
17 changes: 2 additions & 15 deletions src/codedcosmos/enderbot/core/EnderBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions src/codedcosmos/enderbot/discord/JDABot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion src/codedcosmos/enderbot/plugin/MinecraftChatListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 +"]`");
Expand Down
44 changes: 34 additions & 10 deletions src/codedcosmos/enderbot/plugin/MinecraftPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,33 +31,55 @@ 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;

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();
}
}
1 change: 1 addition & 0 deletions src/codedcosmos/enderbot/utils/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
3 changes: 3 additions & 0 deletions src/codedcosmos/enderbot/utils/GoogleDrive.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions src/codedcosmos/enderbot/utils/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 966421d

Please sign in to comment.