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.
-
.start(options = {}) ⇒ Object
Start the server.
-
.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.
-
#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 |
.start(options = {}) ⇒ Object
Start the server.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/bukkit/start.rb', line 4 def self.start( = {}) if File.exists?("craftbukkit.jar") ram = [:ram] puts "Starting your CraftBukkit server...".green if ram.nil? system 'java -jar craftbukkit.jar' else system 'java -Xmx#{ram}M -Xms#{ram}M -jar craftbukkit.jar' end else abort "You're not in your server's root directory.".red end 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 29 30 31 |
# 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-#{[:build].to_s}/craftbukkit.jar") # Give some friendly output. puts "New server build at: ".blue + "#{Dir.pwd}/".light_blue end |