Skip to content

Commit a1d7fa6

Browse files
author
BuildTools
committed
1.0 update
1 parent aad1455 commit a1d7fa6

File tree

10 files changed

+162
-62
lines changed

10 files changed

+162
-62
lines changed

build.gradle

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group 'codedcosmos'
10-
version '0.1'
10+
version '1.0'
1111
mainClassName = 'codedcosmos.enderbot.core.EnderBot'
1212

1313
sourceCompatibility = 1.8
@@ -18,7 +18,14 @@ repositories {
1818
mavenCentral()
1919
jcenter()
2020
maven {
21-
url "https://hub.spigotmc.org/nexus/content/repositories/snapshots"
21+
url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
22+
23+
// As of Gradle 5.1, you can limit this to only those
24+
// dependencies you expect from it
25+
content {
26+
includeGroup 'org.bukkit'
27+
includeGroup 'org.spigotmc'
28+
}
2229
}
2330
}
2431

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

39-
compileOnly "org.spigotmc:spigot-api:1.15.1-R0.1-SNAPSHOT"
46+
compileOnly 'org.spigotmc:spigot:1.15.2-R0.1-SNAPSHOT'
4047
}
4148

4249
jar {

res/plugin.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
name: EnderBot
2-
version: 0.1
2+
version: 1.0
33
author: codedcosmos
44
main: codedcosmos.enderbot.plugin.MinecraftPlugin
5-
api-version: 1.15
5+
api-version: 1.15
6+
7+
commands:
8+
enderbackup:
9+
description: Backs up the world and uploads zip
10+
usage: /enderbackup

src/codedcosmos/enderbot/core/ConfigManager.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class ConfigManager {
3434
public static String minecraft_ingame_channel_name;
3535
public static String world_backups_channel_name;
3636
public static int world_backups_frequency_in_days;
37+
public static boolean world_backups_enabled;
3738

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

5051
// How often the world will be backed up (in days)
5152
defaults.put("world-backups-frequency-in-days", "30");
53+
54+
// Defines if the game will be backed up at all
55+
defaults.put("world-backups-enabled", "False");
5256

5357

5458
// Discord Developer API bot token
@@ -122,6 +126,15 @@ public static void load() {
122126
world_backups_frequency_in_days = 30;
123127
}
124128
Log.print("Loaded 'world-backups-frequency-in-days' as " + world_backups_frequency_in_days);
129+
130+
try {
131+
world_backups_enabled = Boolean.parseBoolean(prop.getProperty("world-backups-enabled").toLowerCase());
132+
} catch (NumberFormatException e) {
133+
Log.printErr("Failed to load config 'world-backups-frequency-in-days'");
134+
Log.printErr("Setting it as default!");
135+
world_backups_enabled = false;
136+
}
137+
Log.print("Loaded 'world-backups-enabled' as " + world_backups_enabled);
125138

126139

127140

src/codedcosmos/enderbot/core/EnderBot.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
*/
1414
package codedcosmos.enderbot.core;
1515

16+
import codedcosmos.enderbot.utils.GoogleDrive;
1617
import codedcosmos.enderbot.utils.Log;
1718

1819
public class EnderBot {
1920

20-
private static final String VERSION = "0.1";
21+
private static final String VERSION = "1.0";
2122
private static boolean runningInSpigot = false;
2223

2324
public static void load(boolean runningInSpigot) {
@@ -35,4 +36,8 @@ public static void load(boolean runningInSpigot) {
3536
public static boolean isRunningInSpigot() {
3637
return runningInSpigot;
3738
}
39+
40+
public static String getVersion() {
41+
return VERSION;
42+
}
3843
}

src/codedcosmos/enderbot/discord/JDABot.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
public class JDABot {
2626

27+
private static JDA jda;
28+
2729
public static void main(String[] args) {
2830
Log.print("Starting EnderBot Discord Subsystem");
2931
EnderBot.load(false);
@@ -40,11 +42,15 @@ public static void initBot() {
4042
builder.addEventListeners(new DiscordChatListener());
4143
builder.addEventListeners(new DiscordEventHandler());
4244

43-
JDA jda = builder.build();
45+
jda = builder.build();
4446

4547
jda.awaitReady();
4648
} catch (LoginException | InterruptedException e) {
4749
Log.printErr(e);
4850
}
4951
}
52+
53+
public static void stop() {
54+
jda.shutdownNow();
55+
}
5056
}

src/codedcosmos/enderbot/plugin/MinecraftChatListener.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import org.bukkit.event.EventHandler;
2121
import org.bukkit.event.Listener;
2222
import org.bukkit.event.player.AsyncPlayerChatEvent;
23+
import org.bukkit.event.player.PlayerJoinEvent;
24+
import org.bukkit.event.player.PlayerQuitEvent;
2325

2426
public class MinecraftChatListener implements Listener {
2527
@EventHandler
@@ -28,4 +30,18 @@ public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
2830
context.getInGameChannel().sendMessage("**"+event.getPlayer().getDisplayName()+"** : " + event.getMessage());
2931
}
3032
}
33+
34+
@EventHandler
35+
public void onPlayerJoin(PlayerJoinEvent event) {
36+
for (GuildContext context : Guilds.getContexts()) {
37+
context.getInGameChannel().sendMessage("`"+event.getPlayer().getDisplayName()+" joined the game`");
38+
}
39+
}
40+
41+
@EventHandler
42+
public void onPlayerQuit(PlayerQuitEvent event) {
43+
for (GuildContext context : Guilds.getContexts()) {
44+
context.getInGameChannel().sendMessage("`"+event.getPlayer().getDisplayName()+" left the game`");
45+
}
46+
}
3147
}

src/codedcosmos/enderbot/plugin/MinecraftPlugin.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
*/
1414
package codedcosmos.enderbot.plugin;
1515

16+
import codedcosmos.enderbot.core.ConfigManager;
1617
import codedcosmos.enderbot.discord.JDABot;
1718
import codedcosmos.enderbot.core.EnderBot;
19+
import codedcosmos.enderbot.plugin.commands.BackupCommand;
1820
import codedcosmos.enderbot.utils.GoogleDrive;
1921
import codedcosmos.enderbot.utils.Log;
2022
import org.bukkit.plugin.java.JavaPlugin;
@@ -26,22 +28,24 @@ public class MinecraftPlugin extends JavaPlugin {
2628
@Override
2729
public void onEnable(){
2830
//Fired when the server enables the plugin
29-
Log.print("Enabling EnderBot");
31+
Log.print("Enabling EnderBot v" + EnderBot.getVersion());
3032
EnderBot.load(true);
3133

3234
JDABot.initBot();
3335
mainPlugin = this;
36+
37+
this.getCommand("enderbackup").setExecutor(new BackupCommand());
3438

3539
getServer().getPluginManager().registerEvents(new MinecraftChatListener(), this);
36-
archiveLoop();
40+
41+
if (ConfigManager.world_backups_enabled) archiveLoop();
3742
}
3843

3944
public void archiveLoop() {
4045
JavaPlugin plugin = this;
4146
getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
4247
public void run() {
43-
int time = GoogleDrive.archiveIfNeeded();
44-
Log.print("Backup task completed in " + time + "ms");
48+
GoogleDrive.archiveIfNeeded();
4549
archiveLoop();
4650
}
4751
}, 20L*60*30);
@@ -52,5 +56,6 @@ public void run() {
5256
public void onDisable(){
5357
//Fired when the server stops and disables all plugins
5458
Log.print("Disabiling EnderBot");
59+
JDABot.stop();
5560
}
5661
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package codedcosmos.enderbot.plugin.commands;
2+
3+
import codedcosmos.enderbot.core.ConfigManager;
4+
import codedcosmos.enderbot.core.EnderBot;
5+
import codedcosmos.enderbot.utils.GoogleDrive;
6+
import net.minecraft.server.v1_15_R1.ItemMapEmpty;
7+
import org.bukkit.Material;
8+
import org.bukkit.command.Command;
9+
import org.bukkit.command.CommandExecutor;
10+
import org.bukkit.command.CommandSender;
11+
import org.bukkit.entity.Player;
12+
import org.bukkit.inventory.ItemStack;
13+
import org.bukkit.inventory.meta.ItemMeta;
14+
import org.bukkit.material.MaterialData;
15+
import org.jetbrains.annotations.NotNull;
16+
17+
import java.util.ArrayList;
18+
import java.util.List;
19+
20+
public class BackupCommand implements CommandExecutor {
21+
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
22+
if (sender instanceof Player) {
23+
Player player = (Player) sender;
24+
if (player.isOp()) {
25+
if (!ConfigManager.world_backups_enabled) {
26+
player.sendMessage("Backups are disabled");
27+
return true;
28+
}
29+
30+
GoogleDrive.archive();
31+
return true;
32+
} else {
33+
player.sendMessage("You must be op to use this command");
34+
}
35+
}
36+
return false;
37+
}
38+
}

src/codedcosmos/enderbot/utils/FileUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@
1414
package codedcosmos.enderbot.utils;
1515

1616
import java.io.File;
17+
import java.io.FileInputStream;
18+
import java.io.FileOutputStream;
1719
import java.io.IOException;
1820
import java.nio.file.Files;
1921
import java.nio.file.Path;
2022
import java.nio.file.Paths;
23+
import java.util.ArrayList;
2124
import java.util.zip.ZipEntry;
2225
import java.util.zip.ZipOutputStream;
2326

2427
public class FileUtils {
28+
2529
public static void zip(String source, String zipname) throws IOException {
2630
// Helpful console message
2731
Log.print("Creating zip file '" + zipname + "' for folder '" + source + "'");

0 commit comments

Comments
 (0)