Advertisement
Guest User

Untitled

a guest
Mar 29th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.06 KB | None | 0 0
  1. #!/usr/bin/python
  2. from datetime import datetime, timedelta
  3. import time
  4. import sys
  5. import pexpect
  6. import time
  7. import os
  8.  
  9. # SETTINGS
  10. playername='brantje' # set this to your minecraft username
  11. minX=-5000  #Minimal x axis
  12. maxX=5000   #Maximal x axis
  13. minY=-5000  #Minimal y axis
  14. maxY=5000   #Maximal y axis
  15. timeout=1   # Time between teleports. Smaller value means more stress for the server.
  16.  
  17.  
  18.  
  19. diff1=maxX-minX
  20. diff2=maxY-minY
  21.  
  22. total=diff1+diff2
  23.  
  24.  
  25. # Print iterations progress
  26. def printProgress (iteration, total, prefix = '', suffix = '', decimals = 2, barLength = 100, to = 0):
  27.     """
  28.    Call in a loop to create terminal progress bar
  29.    @params:
  30.        iterations  - Required  : current iteration (Int)
  31.        total       - Required  : total iterations (Int)
  32.        prefix      - Optional  : prefix string (Str)
  33.        suffix      - Optional  : suffix string (Str)
  34.    """
  35.     filledLength    = int(round(barLength * iteration / float(total)))
  36.     percents        = round(100.00 * (iteration / float(total)), decimals)
  37.     bar             = '#' * filledLength + '-' * (barLength - filledLength)
  38.     remainingTime = (total-iteration)*to
  39.     m, s = divmod(remainingTime, 60)
  40.     h, m = divmod(m, 60)
  41.  
  42.     x = datetime.now() + timedelta(seconds=remainingTime)
  43.    
  44.     sys.stdout.write('%s [%s] %s%s %s\r' % (prefix, bar, percents, '%', suffix)),
  45.     sys.stdout.write("\n %s of %s total\n" % (iteration, total)),
  46.     sys.stdout.write("Remaining %02d:%02d:%02d " % (h, m, s)),
  47.     sys.stdout.write("ETA: "+ x.strftime("%Y-%m-%d %H:%M") +"\n"),
  48.     sys.stdout.flush()
  49.     if iteration == total:
  50.         print("\n")
  51.  
  52. def deleteContent(pfile):
  53.     pfile.seek(0)
  54.     pfile.truncate()
  55.  
  56. print "A total of "+ str(total) +" teleports \n"
  57. counter=0;
  58.  
  59. child = pexpect.spawn('java -Xms3048M -Xmx3048M -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:-UseAdaptiveSizePolicy -Xmn128M -jar minecraft_server.jar nogui')
  60. child.timeout=6000
  61.  
  62.  
  63. f=open('status','r')
  64. lastResult=f.readline()
  65. coords=lastResult.split('|');
  66. lastX=float(coords[0])
  67. lastY=float(coords[1])
  68. f.close()
  69. print "Last X: "+ str(lastX) + " Last Y: "+ str(lastY)
  70.  
  71. child.logfile = sys.stdout
  72. child.expect('%s joined the game' % playername)
  73. child.sendline('gamemode 1 %s' % playername)
  74.  
  75.  
  76. for xcoord in range(minX, maxX, 16):
  77.     x = float(xcoord)
  78.     if lastX > x:
  79.         continue
  80.  
  81.     for ycoord in range(minY, maxY, 16):
  82.         y = float(ycoord)
  83.         if lastY > y:
  84.             counter=counter+1
  85.             continue
  86.  
  87.         printProgress(counter, total, prefix = 'teleports', suffix='', barLength = 100)
  88.         val=child.sendline('tp %s %i 255 %i' % (playername, xcoord, ycoord))
  89.         os.system('clear')
  90.         printProgress(counter, total, prefix = 'teleports', suffix='', barLength = 100, to = timeout)
  91.        
  92.         child.expect('Teleported %s' % playername)
  93.  
  94.         txt=str(xcoord) + '|' + str(ycoord)
  95.         f = open("status", "w")
  96.         f.write(txt)
  97.         f.close()
  98.         counter=counter+1
  99.         time.sleep(timeout)
  100. child.sendline('say all done!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement