Class: Bukkit::Server
- Inherits:
-
Object
- Object
- Bukkit::Server
- Defined in:
- lib/bukkit.rb,
lib/bukkit/start.rb,
lib/bukkit/create.rb,
lib/bukkit/update.rb,
lib/bukkit/download.rb
Class Method Summary collapse
-
.download(uri, options = {}) ⇒ Object
Download a file from a URI.
-
.update(options = { :build => :rb }) ⇒ Object
Download a new version of bukkit.
Instance Method Summary collapse
-
#create(options = {}) ⇒ Object
Create a new server.
-
#initialize(name) ⇒ Server
constructor
A new instance of Server.
-
#start ⇒ Object
Start the server.
-
#update(options = { :build => :rb }) ⇒ Object
Download a new version of bukkit.
Constructor Details
#initialize(name) ⇒ Server
Returns a new instance of Server.
17 18 19 |
# File 'lib/bukkit.rb', line 17 def initialize(name) @name = name end |
Class Method Details
.download(uri, options = {}) ⇒ Object
Download a file from a URI.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bukkit/download.rb', line 6 def self.download(uri, = {}) # Options: { :filename => "filename.ext" } # Get the filename. If it isn't defined, derive it from the URI. if [:filename] filename = [:filename] else filename = uri.split("\/").last end # Give some friendly output. puts "Downloading: ".yellow + filename puts " From: ".yellow + uri puts "(This may take a while depending on your internet connection.)".light_yellow # Download the file. data = RestClient.get(uri) File.open(filename, "wb") do |file| file.write(data) end # => filename.ext puts filename.light_green + " successfully downloaded!".green end |
.update(options = { :build => :rb }) ⇒ Object
Download a new version of bukkit.
4 5 6 |
# File 'lib/bukkit/update.rb', line 4 def self.update( = { :build => :rb }) # Options: { :build => :rb/:beta/:dev } Bukkit::Server.download("http://dl.bukkit.org/latest-#{options[:build].to_s}/craftbukkit.jar") end |
Instance Method Details
#create(options = {}) ⇒ Object
Create a new server.
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 |
# File 'lib/bukkit/create.rb', line 4 def create( = {}) # Options: { :build => :rb/:beta/:dev, :force => false/true } force = [:force] # If the dir already exists, fail gracefully. if Dir.exists?(@name) && force == false puts "'#{@name}' already exists.".red names = %w{ minecraftyness mine-opolis mineville minetown bukkits-o-fun } abort "Try ".yellow + "`bukkit new #{names.sample}` ".light_yellow + "or".yellow + " `bukkit new #{@name} --force`".light_blue end # Let the dark side of the force flow through you... if force == true puts "Overwriting: ".light_red + "#{@name}/" FileUtils.rm_rf(@name) end # Create the server directory and cd into it. Dir.mkdir(@name) puts " Create: ".green + "#{@name}/" Dir.chdir(@name) # Download build. Bukkit::Server.download("http://dl.bukkit.org/latest-#{options[:build].to_s}/craftbukkit.jar") end |
#start ⇒ Object
Start the server.
4 5 6 7 |
# File 'lib/bukkit/start.rb', line 4 def start puts "Starting your CraftBukkit server.".green system 'java -jar craftbukkit.jar' end |
#update(options = { :build => :rb }) ⇒ Object
Download a new version of bukkit.
9 10 11 |
# File 'lib/bukkit/update.rb', line 9 def update( = { :build => :rb }) # Options: { :build => :rb/:beta/:dev } Bukkit::Server.download("http://dl.bukkit.org/latest-#{options[:build].to_s}/craftbukkit.jar") end |