Class: Bukkit::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/bukkit.rb,
lib/bukkit/install.rb,
lib/bukkit/website.rb

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Plugin

Returns a new instance of Plugin.



23
24
25
26
# File 'lib/bukkit.rb', line 23

def initialize(name)
  @name = name.downcase
  @plugin_api = JSON.parse(open("http://api.bukget.org/3/plugins/bukkit/#{@name}").read)
end

Instance Method Details

#installObject

Install a new plugin.



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
44
45
46
47
# File 'lib/bukkit/install.rb', line 8

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

#view_websiteObject

Open website in default browser.



12
13
14
15
16
17
18
# File 'lib/bukkit/website.rb', line 12

def view_website
    Launchy.open(website)
    puts "Opening #{@name}'s Website...".light_green
    puts "    Website: ".yellow + website
    sleep 1.5
    return website
end

#websiteObject

Return the plugin’s website URL.



6
7
8
# File 'lib/bukkit/website.rb', line 6

def website
    @website = @plugin_api["website"]
end