Class: Bukkit::Server

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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 = {}) # Options: { :filename => "filename.ext" }
	# Get the filename. If it isn't defined, derive it from the URI.
	if options[:filename]
		filename = options[: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(options = {})
	if File.exists?("craftbukkit.jar")
		ram = options[: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

.update(options = { :build => :rb }) ⇒ Object

Download a new version of bukkit.



4
5
6
# File 'lib/bukkit/update.rb', line 4

def self.update(options = { :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
29
30
31
# File 'lib/bukkit/create.rb', line 4

def create(options = {}) # Options: { :build => :rb/:beta/:dev, :force => false/true }
	force = options[: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")

	# Give some friendly output.
	puts "New server build at: ".blue + "#{Dir.pwd}/".light_blue
end

#update(options = { :build => :rb }) ⇒ Object

Download a new version of bukkit.



9
10
11
# File 'lib/bukkit/update.rb', line 9

def update(options = { :build => :rb }) # Options: { :build => :rb/:beta/:dev }
	Bukkit::Server.download("http://dl.bukkit.org/latest-#{options[:build].to_s}/craftbukkit.jar")
end