Advertisement
Guest User

Minecraft world switcher in Bash

a guest
Nov 25th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.99 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. # Take your world directory name as an argument
  4. world=$1
  5.  
  6. # Set homedir (in case you run your server from somewhere else)
  7. homedir="/home/minecraft"
  8.  
  9. # If no world name passed, then set to default "world"
  10. if [ -z "$world" ];then
  11.   world="world"
  12. fi
  13.  
  14. # Does the world directory even exist?
  15. if [ -e "$homedir/$world" ]
  16.   then
  17. # Swap the "level-name=" value with the pased name
  18.     cat "$homedir"/server.properties | sed 's\level-name=.*$\level-name='$world'\g'> /tmp/serverprops.temp
  19.  
  20. # Write to a temp file, then swap it to the main file (to avoid read/write clashes; I read that somewhere...
  21.     mv /tmp/serverprops.temp "$homedir"/server.properties
  22.  
  23. # Start the server so we don't have to type in the cryptic command line every.damn.time
  24.     java -jar -Xms1024M -Xmx1024M /usr/lib/minecraft/minecraft_server.1.8.1-pre5.jar nogui
  25. # ..and if the world DOESN'T exist... complain
  26.   else
  27.     printf "Error - world \"$world\" not found\n"
  28.     exit 1
  29. fi
  30.  
  31. # All done
  32. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement