Skip to content

Commit

Permalink
1.0 update
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Mar 20, 2020
1 parent aad1455 commit a1d7fa6
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 62 deletions.
13 changes: 10 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group 'codedcosmos'
version '0.1'
version '1.0'
mainClassName = 'codedcosmos.enderbot.core.EnderBot'

sourceCompatibility = 1.8
Expand All @@ -18,7 +18,14 @@ repositories {
mavenCentral()
jcenter()
maven {
url "https://hub.spigotmc.org/nexus/content/repositories/snapshots"
url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'

// As of Gradle 5.1, you can limit this to only those
// dependencies you expect from it
content {
includeGroup 'org.bukkit'
includeGroup 'org.spigotmc'
}
}
}

Expand All @@ -36,7 +43,7 @@ dependencies {
compile 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
compile 'com.google.apis:google-api-services-drive:v3-rev110-1.23.0'

compileOnly "org.spigotmc:spigot-api:1.15.1-R0.1-SNAPSHOT"
compileOnly 'org.spigotmc:spigot:1.15.2-R0.1-SNAPSHOT'
}

jar {
Expand Down
9 changes: 7 additions & 2 deletions res/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: EnderBot
version: 0.1
version: 1.0
author: codedcosmos
main: codedcosmos.enderbot.plugin.MinecraftPlugin
api-version: 1.15
api-version: 1.15

commands:
enderbackup:
description: Backs up the world and uploads zip
usage: /enderbackup
13 changes: 13 additions & 0 deletions src/codedcosmos/enderbot/core/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ConfigManager {
public static String minecraft_ingame_channel_name;
public static String world_backups_channel_name;
public static int world_backups_frequency_in_days;
public static boolean world_backups_enabled;

// Censored Config values
public static String discord_bot_token;
Expand All @@ -49,6 +50,9 @@ public static HashMap<String, String> getDefault() {

// How often the world will be backed up (in days)
defaults.put("world-backups-frequency-in-days", "30");

// Defines if the game will be backed up at all
defaults.put("world-backups-enabled", "False");


// Discord Developer API bot token
Expand Down Expand Up @@ -122,6 +126,15 @@ public static void load() {
world_backups_frequency_in_days = 30;
}
Log.print("Loaded 'world-backups-frequency-in-days' as " + world_backups_frequency_in_days);

try {
world_backups_enabled = Boolean.parseBoolean(prop.getProperty("world-backups-enabled").toLowerCase());
} catch (NumberFormatException e) {
Log.printErr("Failed to load config 'world-backups-frequency-in-days'");
Log.printErr("Setting it as default!");
world_backups_enabled = false;
}
Log.print("Loaded 'world-backups-enabled' as " + world_backups_enabled);



Expand Down
7 changes: 6 additions & 1 deletion src/codedcosmos/enderbot/core/EnderBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
*/
package codedcosmos.enderbot.core;

import codedcosmos.enderbot.utils.GoogleDrive;
import codedcosmos.enderbot.utils.Log;

public class EnderBot {

private static final String VERSION = "0.1";
private static final String VERSION = "1.0";
private static boolean runningInSpigot = false;

public static void load(boolean runningInSpigot) {
Expand All @@ -35,4 +36,8 @@ public static void load(boolean runningInSpigot) {
public static boolean isRunningInSpigot() {
return runningInSpigot;
}

public static String getVersion() {
return VERSION;
}
}
8 changes: 7 additions & 1 deletion src/codedcosmos/enderbot/discord/JDABot.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

public class JDABot {

private static JDA jda;

public static void main(String[] args) {
Log.print("Starting EnderBot Discord Subsystem");
EnderBot.load(false);
Expand All @@ -40,11 +42,15 @@ public static void initBot() {
builder.addEventListeners(new DiscordChatListener());
builder.addEventListeners(new DiscordEventHandler());

JDA jda = builder.build();
jda = builder.build();

jda.awaitReady();
} catch (LoginException | InterruptedException e) {
Log.printErr(e);
}
}

public static void stop() {
jda.shutdownNow();
}
}
16 changes: 16 additions & 0 deletions src/codedcosmos/enderbot/plugin/MinecraftChatListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;

public class MinecraftChatListener implements Listener {
@EventHandler
Expand All @@ -28,4 +30,18 @@ public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
context.getInGameChannel().sendMessage("**"+event.getPlayer().getDisplayName()+"** : " + event.getMessage());
}
}

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
for (GuildContext context : Guilds.getContexts()) {
context.getInGameChannel().sendMessage("`"+event.getPlayer().getDisplayName()+" joined the game`");
}
}

@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
for (GuildContext context : Guilds.getContexts()) {
context.getInGameChannel().sendMessage("`"+event.getPlayer().getDisplayName()+" left the game`");
}
}
}
13 changes: 9 additions & 4 deletions src/codedcosmos/enderbot/plugin/MinecraftPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
*/
package codedcosmos.enderbot.plugin;

import codedcosmos.enderbot.core.ConfigManager;
import codedcosmos.enderbot.discord.JDABot;
import codedcosmos.enderbot.core.EnderBot;
import codedcosmos.enderbot.plugin.commands.BackupCommand;
import codedcosmos.enderbot.utils.GoogleDrive;
import codedcosmos.enderbot.utils.Log;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -26,22 +28,24 @@ public class MinecraftPlugin extends JavaPlugin {
@Override
public void onEnable(){
//Fired when the server enables the plugin
Log.print("Enabling EnderBot");
Log.print("Enabling EnderBot v" + EnderBot.getVersion());
EnderBot.load(true);

JDABot.initBot();
mainPlugin = this;

this.getCommand("enderbackup").setExecutor(new BackupCommand());

getServer().getPluginManager().registerEvents(new MinecraftChatListener(), this);
archiveLoop();

if (ConfigManager.world_backups_enabled) archiveLoop();
}

public void archiveLoop() {
JavaPlugin plugin = this;
getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
public void run() {
int time = GoogleDrive.archiveIfNeeded();
Log.print("Backup task completed in " + time + "ms");
GoogleDrive.archiveIfNeeded();
archiveLoop();
}
}, 20L*60*30);
Expand All @@ -52,5 +56,6 @@ public void run() {
public void onDisable(){
//Fired when the server stops and disables all plugins
Log.print("Disabiling EnderBot");
JDABot.stop();
}
}
38 changes: 38 additions & 0 deletions src/codedcosmos/enderbot/plugin/commands/BackupCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package codedcosmos.enderbot.plugin.commands;

import codedcosmos.enderbot.core.ConfigManager;
import codedcosmos.enderbot.core.EnderBot;
import codedcosmos.enderbot.utils.GoogleDrive;
import net.minecraft.server.v1_15_R1.ItemMapEmpty;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.material.MaterialData;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class BackupCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (player.isOp()) {
if (!ConfigManager.world_backups_enabled) {
player.sendMessage("Backups are disabled");
return true;
}

GoogleDrive.archive();
return true;
} else {
player.sendMessage("You must be op to use this command");
}
}
return false;
}
}
4 changes: 4 additions & 0 deletions src/codedcosmos/enderbot/utils/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@
package codedcosmos.enderbot.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class FileUtils {

public static void zip(String source, String zipname) throws IOException {
// Helpful console message
Log.print("Creating zip file '" + zipname + "' for folder '" + source + "'");
Expand Down
Loading

0 comments on commit a1d7fa6

Please sign in to comment.