Created
January 29, 2013 10:45
-
-
Save xanthalas/4663420 to your computer and use it in GitHub Desktop.
Ruby script to allow the user to choose the world they wish to use with their Minecraft server. It will update the server.properties file accordingly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ############################################################################# | |
| # Minecraft server world selector. # | |
| # Author: Xanthalas Date: May 2011 # | |
| ############################################################################# | |
| puts "Minecraft server world selector" | |
| puts "" | |
| puts "Available worlds:" | |
| puts "" | |
| worlds = Array.new | |
| counter = 0 | |
| Dir.foreach('.') do |item| | |
| next if item == '.' or item == '..' | |
| if File::directory?(item) | |
| counter += 1 | |
| puts " #{counter}: #{item}" | |
| worlds.push item | |
| end | |
| end | |
| if counter == 0 | |
| puts "No worlds found." | |
| exit | |
| end | |
| puts "" | |
| puts "Which world do you want to visit?" | |
| worldnumber = gets | |
| worldnumber = worldnumber.to_i - 1 | |
| if worldnumber < 0 || worldnumber >= worlds.length | |
| puts "That world doesn't exist" | |
| gets | |
| exit | |
| end | |
| puts "" | |
| puts "Selecting #{worlds[worldnumber]}" | |
| File.rename("server.properties", "server.properties.previous") | |
| outfile = File.new("server.properties", "w") | |
| IO.foreach("server.properties.previous"){|line| | |
| line = "level-name=#{worlds[worldnumber]}" if line =~ /^level-name/ | |
| outfile.puts(line) | |
| } | |
| outfile.close | |
| File.delete("server.properties.previous") | |
| puts "" | |
| puts "World selection complete. Enjoy your game!" | |
| puts "" | |
| gets |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment