From dceb74dfb196da7fcf4a4ff7a36950165d651c7f Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 4 May 2019 11:36:42 -0700 Subject: [PATCH] Adds safety code to copy BSkyBlock to addons if it is run as a plugin. --- .../bentobox/bskyblock/CopyToBentoBox.java | 44 +++++++++++++++++++ src/main/resources/plugin.yml | 6 +++ 2 files changed, 50 insertions(+) create mode 100644 src/main/java/world/bentobox/bskyblock/CopyToBentoBox.java create mode 100644 src/main/resources/plugin.yml diff --git a/src/main/java/world/bentobox/bskyblock/CopyToBentoBox.java b/src/main/java/world/bentobox/bskyblock/CopyToBentoBox.java new file mode 100644 index 0000000..a18683f --- /dev/null +++ b/src/main/java/world/bentobox/bskyblock/CopyToBentoBox.java @@ -0,0 +1,44 @@ +package world.bentobox.bskyblock; + +import java.io.File; +import java.io.IOException; + +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; + +import com.google.common.io.Files; + +import world.bentobox.bentobox.api.events.BentoBoxReadyEvent; + +public class CopyToBentoBox extends JavaPlugin implements Listener { + + @Override + public void onEnable() { + Bukkit.getPluginManager().registerEvents(this, this); + } + + @EventHandler + public void onBentoBoxReady(BentoBoxReadyEvent e) { + getLogger().severe("BSkyBlock.jar must be in the BentoBox/addons folder! Trying to move it there..."); + File addons = new File(getFile().getParent(), "BentoBox/addons"); + if (addons.exists()) { + File to = new File(addons, getFile().getName()); + if (!to.exists()) { + + try { + Files.move(getFile(), to); + getLogger().severe(getFile().getName() + " moved successfully. Restart server now to activate!"); + + } catch (IOException ex) { + getLogger().severe("Failed to move it. " + ex.getMessage()); + getLogger().severe("Move " + getFile().getName() + " manually into the BentoBox/addons folder. Then restart server."); + } + } + } else { + getLogger().severe("BentoBox folders do not exist! " + addons.getAbsolutePath()); + } + + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..0540d9d --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,6 @@ +name: BSkyBlock +main: world.bentobox.bskyblock.CopyToBentoBox +version: ${version} +description: A SkyBlock Plugin +author: tastybento +depend: [BentoBox]