diff --git a/.idea/artifacts/PluginInstaller_jar.xml b/.idea/artifacts/PluginInstaller_jar.xml new file mode 100644 index 0000000..deb4c07 --- /dev/null +++ b/.idea/artifacts/PluginInstaller_jar.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/out/artifacts/PluginInstaller_jar + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/artifacts/PluginInstaller_jar/PluginInstaller.jar b/out/artifacts/PluginInstaller_jar/PluginInstaller.jar new file mode 100644 index 0000000..e0cef4b Binary files /dev/null and b/out/artifacts/PluginInstaller_jar/PluginInstaller.jar differ diff --git a/src/main/java/tech/nully/PluginInstaller/InstallCommand.java b/src/main/java/tech/nully/PluginInstaller/InstallCommand.java index 861a711..2ae96da 100644 --- a/src/main/java/tech/nully/PluginInstaller/InstallCommand.java +++ b/src/main/java/tech/nully/PluginInstaller/InstallCommand.java @@ -1,31 +1,43 @@ package tech.nully.PluginInstaller; +import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import org.bukkit.craftbukkit.libs.org.ibex.nestedvm.util.Seekable; +import org.bukkit.command.ConsoleCommandSender; import java.io.IOException; import java.io.InputStream; -import java.net.MalformedURLException; import java.net.URI; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Paths; +import java.util.Locale; public class InstallCommand implements CommandExecutor { + @Override public boolean onCommand(CommandSender snder, Command cmd, String label, String[] args) { + // Name checker if (cmd.getName().equalsIgnoreCase("installpl")) { - Installer ins = new Installer(); - String Install_Jar = cmd.getName(); - if (ins.JARURLs.containsKey(Install_Jar)) { - try (InputStream in = URI.create(ins.JARURLs.get(Install_Jar)).toURL().openStream()) { - ins.InstallPlugin(in); - } catch (IOException e) { + snder.sendMessage("Check 1 passed"); + if (snder.isOp() || snder instanceof ConsoleCommandSender) { + snder.sendMessage("Check 2 passed"); + Installer ins = new Installer(); + if (args.length != 1) return false; + snder.sendMessage("Check 3 passed"); + String Install_Jar = args[0].toLowerCase(); + + // Checks if the list of plugin links contains what the user wants to install + if (Main.getJavaURLs().containsKey(Install_Jar)) { + snder.sendMessage("Check 4 passed"); + // Creates an input stream based on the corresponding URL from the players first argument + try (InputStream in = URI.create(Main.getJavaURLs().get(Install_Jar)).toURL().openStream()) { + snder.sendMessage("Check 5 passed"); + // Installs the plugin + ins.InstallPlugin(in, Install_Jar.toLowerCase(), snder); + snder.sendMessage("You have successfully installed the " + ChatColor.GREEN + Install_Jar.toUpperCase() + ChatColor.WHITE + " plugin!"); + return true; + } catch (IOException e) { + } } - - } } return false; diff --git a/src/main/java/tech/nully/PluginInstaller/Installer.java b/src/main/java/tech/nully/PluginInstaller/Installer.java index 628fa76..9449b63 100644 --- a/src/main/java/tech/nully/PluginInstaller/Installer.java +++ b/src/main/java/tech/nully/PluginInstaller/Installer.java @@ -1,5 +1,9 @@ package tech.nully.PluginInstaller; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; + +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; @@ -7,14 +11,24 @@ import java.nio.file.StandardCopyOption; import java.util.HashMap; public class Installer { - public HashMap JARURLs = new HashMap<>(); + private HashMap JARURLs = new HashMap<>(); - public static void SetupInstaller() { + public static HashMap SetupInstaller() { Installer ins = new Installer(); - ins.JARURLs.put("dynmap", "https://github.com/darverdevs/PluginInstallerRepo/raw/main/dynmap-1.9.1.jar"); + ins.JARURLs.put("dynmap", "https://github.com/darverdevs/PluginInstallerRepo/raw/main/dynmap-1.9.1.jar");; + ins.JARURLs.put("factions", "https://github.com/darverdevs/PluginInstallerRepo/raw/main/Factions.jar"); + ins.JARURLs.put("permissionsex", "https://github.com/darverdevs/PluginInstallerRepo/raw/main/PermissionSex.jar"); + ins.JARURLs.put("protocollib", "https://github.com/darverdevs/PluginInstallerRepo/raw/main/ProtocolLib.jar"); + ins.JARURLs.put("vault", "https://github.com/darverdevs/PluginInstallerRepo/raw/main/Vault.jar"); + ins.JARURLs.put("mcore", "https://github.com/darverdevs/PluginInstallerRepo/raw/main/mcore.jar"); + return ins.JARURLs; } - public void InstallPlugin(InputStream in) throws IOException { - Files.copy(in, Main.getInstance().getDataFolder().toPath(), StandardCopyOption.REPLACE_EXISTING); + public void InstallPlugin(InputStream in, String pluginName, CommandSender s) throws IOException { + File f = new File(Main.getInstance().getDataFolder().getParent() + "/" + pluginName + ".jar"); + s.sendMessage("Check 1x passed"); + Files.copy(in, f.toPath(), StandardCopyOption.REPLACE_EXISTING); + System.out.println(f.toPath().toString()); + s.sendMessage("Check 2x passed"); } } diff --git a/src/main/java/tech/nully/PluginInstaller/Main.java b/src/main/java/tech/nully/PluginInstaller/Main.java index 08fadb2..35f0a57 100644 --- a/src/main/java/tech/nully/PluginInstaller/Main.java +++ b/src/main/java/tech/nully/PluginInstaller/Main.java @@ -1,20 +1,40 @@ package tech.nully.PluginInstaller; +import org.bukkit.ChatColor; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; +import java.util.HashMap; + public class Main extends JavaPlugin { private static Plugin instance = null; public static Plugin getInstance() { return instance; } + private static HashMap javaURLs = null; + public static HashMap getJavaURLs() { + return javaURLs; + } @Override public void onEnable() { instance = this; + getCommand("installpl").setExecutor(new InstallCommand()); + javaURLs = Installer.SetupInstaller(); + getServer().getConsoleSender().sendMessage("--------------------------------------------"); + getServer().getConsoleSender().sendMessage("--------------------------------------------"); + getServer().getConsoleSender().sendMessage( + ChatColor.GREEN + "[PluginInstaller]" + ChatColor.AQUA + " PluginInstaller V1.0.0 is now Enabled! :D"); + getServer().getConsoleSender().sendMessage("--------------------------------------------"); + getServer().getConsoleSender().sendMessage("--------------------------------------------"); } @Override public void onDisable() { - getLogger().info("Plugin has been disabled!"); + getServer().getConsoleSender().sendMessage("--------------------------------------------"); + getServer().getConsoleSender().sendMessage("--------------------------------------------"); + getServer().getConsoleSender().sendMessage( + ChatColor.GREEN + "[PluginInstaller]" + ChatColor.AQUA + " PluginInstaller V1.0.0 is now Disabled! D:"); + getServer().getConsoleSender().sendMessage("--------------------------------------------"); + getServer().getConsoleSender().sendMessage("--------------------------------------------"); } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..eee3df5 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,11 @@ +name: PluginInstaller +version: 1.0.0 +main: tech.nully.PluginInstaller.Main +prefix: [PluginInstaller] +authors: [BongoCat] +description: A plugin that is capable of installing the latest compatible version of plugins with eaglercraft +website: nully.tech +commands: + installpl: + usage: / + description: Installs the latest compatible version of the requested plugin diff --git a/target/classes/plugin.yml b/target/classes/plugin.yml new file mode 100644 index 0000000..eee3df5 --- /dev/null +++ b/target/classes/plugin.yml @@ -0,0 +1,11 @@ +name: PluginInstaller +version: 1.0.0 +main: tech.nully.PluginInstaller.Main +prefix: [PluginInstaller] +authors: [BongoCat] +description: A plugin that is capable of installing the latest compatible version of plugins with eaglercraft +website: nully.tech +commands: + installpl: + usage: / + description: Installs the latest compatible version of the requested plugin diff --git a/target/classes/tech/nully/PluginInstaller/InstallCommand.class b/target/classes/tech/nully/PluginInstaller/InstallCommand.class new file mode 100644 index 0000000..feac3a0 Binary files /dev/null and b/target/classes/tech/nully/PluginInstaller/InstallCommand.class differ diff --git a/target/classes/tech/nully/PluginInstaller/Installer.class b/target/classes/tech/nully/PluginInstaller/Installer.class new file mode 100644 index 0000000..41aec8c Binary files /dev/null and b/target/classes/tech/nully/PluginInstaller/Installer.class differ diff --git a/target/classes/tech/nully/PluginInstaller/Main.class b/target/classes/tech/nully/PluginInstaller/Main.class new file mode 100644 index 0000000..3b617c3 Binary files /dev/null and b/target/classes/tech/nully/PluginInstaller/Main.class differ