class Pigman::Server
Public Class Methods
new()
click to toggle source
# File lib/pigman.rb, line 8 def initialize @config = nil end
Public Instance Methods
start()
click to toggle source
# File lib/pigman.rb, line 12 def start puts 'Loading config...' # Load config from pigman.yml @config = YAML.load_file 'pigman.yml' if @config == false @config = {} end # Apply server settings from config memory = @config['memory'] if memory != nil @memory_max = memory['max'] @memory_min = memory['min'] end address = @config['address'] if address != nil @host = address['host'] @port = address['port'] end @eula = @config['eula'] == true @level_name = @config['level-name'] @bonus_chest = @config['bonus-chest'] # Run system commands required to start server with the given # settings, i.e. auto-update, start_ram, max_ram, etc. command = ['java'] # Memory settings if @memory_max.is_a?(String) || @memory_max.is_a?(Numeric) command << "-Xmx#{@memory_max}" end if @memory_min.is_a?(String) || @memory_min.is_a?(Numeric) command << "-Xms#{@memory_min}" end # Eula if @eula == true command << "-Dcom.mojang.eula.agree=#{@eula}" end # Jar command << '-jar' command << 'spigot-1.14.4.jar' # Universe and world if @universe.is_a? String command << '--universe' command << @universe end if @world.is_a? String command << '--world' command << @world end # Network settings if @host.is_a? String command << '--serverId' command << @host end if @port.is_a?(String) || @port.is_a?(Numeric) command << '--port' command << "#{@port}" end # Misc. options if @bonus_chest command << '--bonusChest' end # Start the server puts "Starting server..." system(*command) end