Module: Bukkit
- Defined in:
- lib/bukkit.rb,
lib/bukkit/new.rb,
lib/bukkit/help.rb,
lib/bukkit/start.rb,
lib/bukkit/install.rb,
lib/bukkit/version.rb,
lib/bukkit/website.rb
Constant Summary collapse
- VERSION =
"0.0.8"
Class Method Summary collapse
- .ask_website ⇒ Object
- .help ⇒ Object
- .install ⇒ Object
- .new ⇒ Object
- .start ⇒ Object
- .website ⇒ Object
Class Method Details
.ask_website ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bukkit/website.rb', line 18 def self.ask_website print "Would you like to visit the plugin's website? (y/n) " q2 = $stdin.gets.chomp case q2 when "y", "yes" puts " Opening #{$opt2}'s website in your default browser." Launchy.open($website) when "n", "no" abort("If you change your mind.\nRun the command 'bukkit website PLUGIN_NAME'.") else puts "'#{q2}' is not an option." 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 |
# 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" # 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 "Website: #{$website}" %x(curl -L #{download} > #{filename}) 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...\n" %x(curl -L http://cbukk.it/craftbukkit.jar > craftbukkit.jar) puts "\nSuccessfully downloaded Recommended build." Bukkit::start when "beta", "b" puts "Downloading CraftBukkit Beta build...\n" %x(curl -L http://cbukk.it/craftbukkit-beta.jar > craftbukkit.jar) puts "\nSuccessfully downloaded Beta build." Bukkit::start when "dev", "development", "d" puts "Downloading CraftBukkit Development build...\n" %x(curl -L http://cbukk.it/craftbukkit-dev.jar > craftbukkit.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 |
# File 'lib/bukkit/start.rb', line 2 def self.start 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 |
.website ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/bukkit/website.rb', line 6 def self.website begin $opt2 = ARGV[1].downcase plugins_api = JSON.parse(open("http://api.bukget.org/3/plugins/bukkit/#{$opt2}").read) $website = plugins_api["website"] puts " Opening #{$opt2}'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 |