Module: Bukkit
- Defined in:
- lib/bukkit.rb,
lib/bukkit/new.rb,
lib/bukkit/help.rb,
lib/bukkit/start.rb,
lib/bukkit/update.rb,
lib/bukkit/install.rb,
lib/bukkit/version.rb,
lib/bukkit/website.rb,
lib/bukkit/download.rb
Constant Summary collapse
- VERSION =
"0.1.3"- VERSION_FULL =
"Bukkit-CLI v#{VERSION}"
Class Method Summary collapse
- .download(filename, uri) ⇒ Object
- .help ⇒ Object
- .install ⇒ Object
- .new ⇒ Object
- .start ⇒ Object
- .update ⇒ Object
- .website(plugin_name) ⇒ Object
Class Method Details
.download(filename, uri) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/bukkit/download.rb', line 4 def self.download(filename, uri) begin File.open("#{filename}", "wb") do |file| file.write open("#{uri}").read end rescue Errno::ENOENT abort "Error! No internet connection." end end |
.help ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bukkit/help.rb', line 2 def self.help puts " Commands:" puts " Create new server:" puts " bukkit new SERVER_NAME" puts "\n" puts " Start the server:" puts " bukkit start" puts "\n" puts " Install a plugin:" puts " bukkit install PLUGIN_NAME" puts "\n" puts " Open a plugin's website:" puts " bukkit website PLUGIN_NAME" puts "\n" puts " Update your version of CraftBukkit:" puts " bukkit update" puts "\n" # Put Last puts " Show this page:" puts " bukkit --help OR bukkit -h" puts "\n" puts " Get version:" puts " bukkit --version OR bukkit -v" end |
.install ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bukkit/install.rb', line 7 def self.install $opt2 = ARGV[1].downcase abort("USAGE: bukkit install PLUGIN_NAME") if $opt2.nil? begin plugins_api = JSON.parse(open("http://api.bukget.org/3/plugins/bukkit/#{$opt2}").read) website = plugins_api["website"] download = plugins_api["versions"][0]["download"] filename = plugins_api["versions"][0]["filename"] Dir.chdir("plugins") puts "Downloading #{$opt2} from #{website}..." Bukkit::download(filename, download) if File.extname(filename) == ".zip" # Extract Zip Archive Archive::Zip.extract(filename, $opt2) Dir.chdir($opt2) jarfiles = Dir.glob("*.jar") # Move each jar file outside the folder. jarfiles.each do |jar| %x(mv #{jar} ../) end Dir.chdir("../") # Delete the extracted folder. %x(rm -rf #{$opt2}/) # Delete the archive. %x(rm #{filename}) puts "Plugin successfully installed!" ask_website else puts "Plugin successfully installed!" ask_website end rescue Errno::ENOENT puts " You aren't in a server's root directory.\n 'plugins' directory not found." rescue puts " Plugin not found." end end |
.new ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bukkit/new.rb', line 2 def self.new create_folder puts " Do want the recommended build, beta build, or dev build?" print " rb, beta, dev? " q1 = $stdin.gets.chomp case q1 when "rb", "recommended", "r" puts "Downloading CraftBukkit Recommended build... (this could take a minute)\n" Bukkit::download("craftbukkit.jar", "http://cbukk.it/craftbukkit.jar") puts "\nSuccessfully downloaded Recommended build." Bukkit::start when "beta", "b" puts "Downloading CraftBukkit Beta build... (this could take a minute)\n" Bukkit::download("craftbukkit.jar", "http://cbukk.it/craftbukkit-beta.jar") puts "\nSuccessfully downloaded Beta build." Bukkit::start when "dev", "development", "d" puts "Downloading CraftBukkit Development build... (this could take a minute)\n" Bukkit::download("craftbukkit.jar", "http://cbukk.it/craftbukkit-dev.jar") puts "\nSuccessfully downloaded Development build." Bukkit::start else if q1.length > 0 abort(" \"#{q1}\" is not an option.") else abort(" You didn't enter an option.") end end end |
.start ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 |
# File 'lib/bukkit/start.rb', line 2 def self.start if ARGV.include? "-s" abort elsif ARGV.include? "-s" abort else puts "Make sure that you're in your server's root directory." puts "If Java runtime is not present, run 'bukkit start' once Java is installed to complete the installation." system 'java -jar craftbukkit.jar' end end |
.update ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bukkit/update.rb', line 2 def self.update begin puts " Do want the recommended build, beta build, or dev build?" print " rb, beta, dev? " q1 = $stdin.gets.chomp case q1 when "rb", "recommended", "r" puts "Downloading CraftBukkit Recommended build... (this could take a minute)\n" Bukkit::download("craftbukkit.jar", "http://cbukk.it/craftbukkit.jar") puts "\nSuccessfully updated." when "beta", "b" puts "Downloading CraftBukkit Beta build... (this could take a minute)\n" Bukkit::download("craftbukkit.jar", "http://cbukk.it/craftbukkit-beta.jar") puts "\nSuccessfully updated." when "dev", "development", "d" puts "Downloading CraftBukkit Development build... (this could take a minute)\n" Bukkit::download("craftbukkit.jar", "http://cbukk.it/craftbukkit-dev.jar") puts "\nSuccessfully updated." else if q1.length > 0 abort(" \"#{q1}\" is not an option.") else abort(" You didn't enter an option.") end end rescue puts "Uh oh! Something failed. Please report what you were doing at the time of this bug, and any other info you have at: https://github.com/JesseHerrick/bukkit/issues/new" end end |
.website(plugin_name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/bukkit/website.rb', line 6 def self.website(plugin_name) begin plugins_api = JSON.parse(open("http://api.bukget.org/3/plugins/bukkit/#{plugin_name}").read) website = plugins_api["website"] puts "Opening #{plugin_name}'s website in your default browser." Launchy.open(website) rescue OpenURI::HTTPError puts " Plugin not found.\n Make sure you have the name correct." end end |