Sha256: 54a63ac7ef1155c83fcce0233b174351acf71d99efb9f0e0f97f04ecc59d37c8
Contents?: true
Size: 1.31 KB
Versions: 14
Compression:
Stored size: 1.31 KB
Contents
require 'open-uri' require 'json' require 'archive/zip' module Bukkit class Plugin # Install a new plugin. def install # Get server's download link. @download_url = @plugin_api["versions"][0]["download"] @filename = @plugin_api["versions"][0]["filename"] # Fail... gracefully, if craftbukkit.jar does not exist. abort "You're not in a server's root directory!".red unless File.exists? "craftbukkit.jar" # Go into plugins and download the plugin. Dir.chdir("plugins") Bukkit::Server.download(@download_url, :filename => @filename) file_ext = File.extname(@filename) # Unzip if it's a zip case file_ext when ".zip" # Extract Zip Archive Archive::Zip.extract(@filename, @name) Dir.chdir(@name) jarfiles = Dir.glob("*.jar") # Move each jar file outside the folder. jarfiles.each do |jar| FileUtils.mv(jar, "../") end puts " Unarchived: ".yellow + @filename Dir.chdir("../") # Delete the extracted folder. FileUtils.rm_rf("#{@name}/") # Delete the archive. FileUtils.rm_rf(@filename) when ".jar" nil else abort "Something weird happened...\nThe file extension is #{file_ext}, not '.zip' or '.jar'." end puts " Installed: ".light_green + @name puts @name.light_green + " successfully installed!".green end end end
Version data entries
14 entries across 14 versions & 1 rubygems