Advertisement
Guest User

Minecraft 1.13 Updater

a guest
Nov 16th, 2017
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 11.00 KB | None | 0 0
  1. #include<File.au3>
  2. #include <GUIConstantsEx.au3>
  3. #include <FileConstants.au3>
  4. #include <File.au3>
  5. $gui = GUICreate("Minecraft Updater", 430, 150)
  6. global $path = @AppDataDir &"\.minecraft\saves\world\"
  7. $box1 = GUICtrlCreateInput($path,15,10, 400)
  8. $search = GUICtrlCreateButton("Update",175,100,80)
  9. GUISetState(@SW_SHOW, $gui)
  10.  
  11. global $commands = 33
  12. global $tags = 8
  13. global $lib[$commands][2][$tags] = [ _
  14.    [["scoreboard", "players","tag","","add","","",""],["","","tag","*","add","*","*","*"]], _
  15.    [["scoreboard", "players","tag","","remove","","",""],["","","tag","*","remove","*","*","*"]], _
  16.    [["scoreboard", "teams","","","","","",""],["team","","*","*","*","*","*","*"]], _
  17.    [["gamemode","0","","","","","",""],["gamemode","survival","*","*","*","*","*","*"]], _
  18.    [["gamemode","1","","","","","",""],["gamemode","creative","*","*","*","*","*","*"]], _
  19.    [["gamemode","2","","","","","",""],["gamemode","adventure","*","","","","*","*"]], _
  20.    [["gamemode","3","","","","","",""],["gamemode","spectator","*","","","","*","*"]], _
  21.    [["gamemode","s","","","","","",""],["gamemode","survival","*","*","*","*","*","*"]], _
  22.    [["gamemode","c","","","","","",""],["gamemode","creative","*","*","*","*","*","*"]], _
  23.    [["gamemode","a","","","","","",""],["gamemode","adventure","*","","","","*","*"]], _
  24.    [["gamemode","s","","","","","",""],["gamemode","spectator","*","","","","*","*"]], _
  25.    [["effect","","clear","","","","",""],["effect clear","*","","","","","*","*"]], _
  26.    [["effect","","","","","","",""],["effect give","*","*","*","*","*","*","*"]], _
  27.    [["execute","","","","","function","",""],["execute","*","*","*","*","run function","*","*"]], _
  28.    [["execute","","","","","say","",""],["execute","*","*","*","*","run say","*","*"]], _
  29.    [["execute","","","","","scoreboard","",""],["execute","*","*","*","*","run scoreboard","*","*"]], _
  30.    [["execute","","","","","gamemode","",""],["execute","*","*","*","*","run gamemode","*","*"]], _
  31.    [["execute","","","","","execute","",""],["execute","*","*","*","*","run execute","*","*"]], _
  32.    [["execute","","","","","fill","",""],["execute","*","*","*","*","run fill","*","*"]], _
  33.    [["execute","","","","","playsound","",""],["execute","*","*","*","*","run playsound","*","*"]], _
  34.    [["execute","","","","","replaceitem","",""],["execute","*","*","*","*","run replaceitem","*","*"]], _
  35.    [["execute","","","","","tag","",""],["execute","*","*","*","*","run tag","*","*"]], _
  36.    [["execute","","","","","team","",""],["execute","*","*","*","*","run tp","*","*"]], _
  37.    [["execute","","","","","tp","",""],["execute","*","*","*","*","run tp","*","*"]], _
  38.    [["execute","","","","","effect","",""],["execute","*","*","*","*","run effect","*","*"]], _
  39.    [["execute","","","","","clone","",""],["execute","*","*","*","*","run clone","*","*"]], _
  40.    [["execute","","","","","entitydata","",""],["execute","*","*","*","*","run entitydata","*","*"]], _
  41.    [["execute","","","","","give","",""],["execute","*","*","*","*","run give","*","*"]], _
  42.    [["execute","","~","~","~","","",""],["execute as","*","at @s","","","*","*","*"]], _
  43.    [["detect","","","","","-1","",""],["detect","*","*","*","*","","*","*"]], _
  44.    [["detect","","","","","","function",""],["detect","*","*","*","*","*","run function","*"]], _
  45.    [["detect","","","","","","",""],["if block","*","*","*","*","*","*","*"]], _
  46.    [["xp","","","","","","",""],["experience add","*","*","*","*","*","*","*"]] _
  47.    ]
  48.  
  49. global $short = 9
  50. global $shortlib[$short][2] = [ _
  51.    ["m=","gamemode="], _
  52.    ["l=","level="], _
  53.    ["lm=","level="], _
  54.    ["r=","distance="], _
  55.    ["rx=","x_rotation"], _
  56.    ["ry=","y_rotation"], _
  57.    ["c=","limit="], _
  58.    ["m=","gamemode="], _
  59.    ["entitydata","data merge entity"] _
  60.    ]
  61.  
  62. global $clean = 6
  63. global $cleanlib[$clean][2] = [ _
  64.    ["as as","as"], _
  65.    ["at at","at"], _
  66.    ["@s[]","@s"], _
  67.    ["@a[]","@a"], _
  68.    ["@e[]","@e"], _
  69.    ["@p[]","@p"] _
  70.    ]
  71.  
  72. main()
  73. Func main()
  74.  While 1
  75.    Switch GUIGetMsg()
  76.       case $GUI_EVENT_CLOSE, $idOK
  77.          ExitLoop
  78.       case $search
  79.          global $path = GUICtrlRead($box1)
  80.          program($path)
  81.    EndSwitch
  82.    WEnd
  83. EndFunc
  84.  
  85. func program($path)
  86.    $path = fileupdate()
  87.    ConsoleWrite($path&@CRLF)
  88.    $filelist = _FileListToArrayRec($path,"*",1,1,0,2)
  89.    if not @error then
  90.       for $file = 1 to $filelist[0]
  91.          ConsoleWrite($filelist[$file]&@crlf)
  92.          global $linelist
  93.          _FileReadToArray($filelist[$file],$linelist)
  94.          if not @error and $linelist[0] > 0  then
  95.             for $o = 1 to $linelist[0]
  96.    ;~           ConsoleWrite(@CRLF&$linelist[$o])
  97.                replace($linelist[$o])
  98.                $string = shortreplace($string)
  99.                $string = score($string)
  100.                $string = clean($string)
  101.                _FileWriteToLine($filelist[$file], $o, "" & $string, true)
  102.             Next
  103.          EndIf
  104.       next
  105.    EndIf
  106.    exit
  107. EndFunc
  108.  
  109. func fileupdate()
  110.    $exists = _FileListToArray($path&"\datapacks\","*",2,true)
  111.    if $exists >= 1 Then
  112.       $path = $path&"\datapacks\"
  113.    Else
  114.       DirCreate($path & "datapacks\auto_update\data\auto_update\functions")
  115.       _FileCreate($path & "\datapacks\auto_update\pack.mcmeta")
  116.       FileWrite($path & "\datapacks\auto_update\pack.mcmeta",'{"pack": {"pack_format": 3, "description": " "}}')
  117.       DirCopy($path&"\data\functions",$path & "\datapacks\auto_update\data\auto_update\functions")
  118.       ConsoleWrite($path & "\datapacks\auto_update\pack.mcmeta"&@CRLF)
  119.       $path = $path&"\datapacks\"
  120.    EndIf
  121.    return $path
  122. EndFunc
  123.  
  124. func replace($line)
  125.    global $string = ""
  126.    $line = StringReplace($line," /"," ")
  127.    $words = StringSplit($line," ")
  128.    if $words[0] == 0 Then
  129.       return 0
  130.    endif
  131.  
  132. ;~    consolewrite($line&@crlf)
  133.    for $position = 1 to $words[0]
  134.       for $command = 0 to $commands -1
  135.          $index = 0
  136.          $length = $tags
  137.          if $length < $words[0] - $position then
  138.             $length = $words[0] - $position
  139.          endif
  140.  
  141.             while ($index < $tags and $lib[$command][0][$index] == "") or (($index < $tags) and (($position + $index <= $words[0]) and ($words[$position+$index] == $lib[$command][0][$index]))) ;tags match / search tag blank ("")
  142. ;~             consolewrite($index & @crlf)
  143.                $index += 1
  144. ;~             consolewrite($lib[$command][0][$index-1] &" matching "&$index-1&@CRLF)
  145.             WEnd
  146. ;~          consolewrite("POSITION"& $position & @crlf)
  147.             if $index == $tags Then
  148. ;~             consolewrite("TRIGGERED "&$line & @crlf)
  149.                for $cnt = 0 to $tags - 1
  150.  
  151.                   if $lib[$command][1][$cnt] <> "*" and $position+$cnt<=$words[0] then
  152. ;~                   ConsoleWrite($words[$position+$cnt]& " -> ")
  153.                      $words[$position+$cnt] = $lib[$command][1][$cnt]
  154. ;~                   ConsoleWrite($words[$position+$cnt]&@crlf)
  155.                   endif
  156.                Next
  157. ;~             consolewrite("POSITION"& $position & @crlf)
  158.             endif
  159. ;~       next
  160.       Next
  161.    next
  162.    for $m = 1 to $words[0]
  163. ;~  ConsoleWrite(@CRLF&""& $wordlist[$m])
  164.       if $words[$m] <> "" Then
  165.          if $string <> "" then
  166.             $string = $string & " "
  167.          endif
  168.          $string = $string & $words[$m]
  169.       EndIf
  170.    next
  171.    if $string = "" Then
  172.       $string = " "
  173.    EndIf
  174. EndFunc
  175.  
  176. func shortreplace($string)
  177.    for $i = 0 to $short -1
  178. ;~        ConsoleWrite($shortlib[$i][0]&@CRLF)
  179. ;~    ConsoleWrite($shortlib[$i][1]&@CRLF)
  180. ;~    ConsoleWrite($i&@CRLF)
  181.       $search = "[" & $shortlib[$i][0]
  182.       $replace = "[" & $shortlib[$i][1]
  183.       $string = StringReplace($string,$search,$replace)
  184.       $search = ","&$shortlib[$i][0]
  185.       $replace = ","&$shortlib[$i][1]
  186.       $string = StringReplace($string,$search,$replace)
  187.    next
  188.    return $string
  189. EndFunc
  190.  
  191. func clean($string)
  192.    for $i = 0 to $clean -1
  193.       $search = $cleanlib[$i][0]
  194.       $replace = $cleanlib[$i][1]
  195.       $string = StringReplace($string,$search,$replace)
  196. ;~    ConsoleWrite($search&@CRLF)
  197.       $search = $cleanlib[$i][0]
  198.       $replace = $cleanlib[$i][1]
  199.       $string = StringReplace($string,$search,$replace)
  200.    next
  201.    return $string
  202. EndFunc
  203.  
  204. func score($string)
  205.    $words = StringSplit($string," ")
  206.    $return = ""
  207.    $ret = ""
  208.    local $scores[100][3]    ; name, min, max
  209.  
  210.    $scoreindex = 0
  211. ;~    $selector = $subwords[0] & "["
  212.    if $words[0] >= 1 then
  213.       for $i=1 to $words[0]
  214.          for $p = 0 to 99
  215.             $scores[$p][0] = ""
  216.             $scores[$p][1] = null
  217.             $scores[$p][2] = null
  218.          next
  219.          $ret = ""
  220.          if StringInStr(StringTrimRight($words[$i],stringlen($words[$i])-3),"@") then
  221.             $subwords = StringSplit($words[$i]," ,[]")
  222.             $ret &= $subwords[1] & "["
  223.  
  224. ;~          ######datatags########
  225.             if ($i >= 2 and $words[$i-1] == "tag") or ($i>=4 and $words[$i-3] == "scoreboard") Then
  226.                if $i+3 <= $words[0] and StringInStr($words[$i+3],"{") <> 0 Then
  227.                   $ret &= "nbt=" & $words[$i+3]
  228.                   $words[$i+3] = ""
  229.                EndIf
  230.             EndIf
  231. ;~          ######datatags########
  232.             for $m = 1 to $subwords[0]
  233.                if StringInStr($subwords[$m],"score_") then
  234.                   $subwords[$m] = StringTrimLeft($subwords[$m],6)
  235.                   $pos = StringInStr($subwords[$m],"_min=")
  236.                   if ($pos) >= 1 then
  237.                      $scores[$scoreindex][1] = StringTrimLeft($subwords[$m],$pos+4) ; trim until only score is left
  238. ;~                   consolewrite($scores[$scoreindex][1]& @crlf)
  239.                   Else
  240.                      $pos = StringInStr($subwords[$m],"=")
  241.                      $scores[$scoreindex][2] = StringTrimLeft($subwords[$m],$pos)       ; trim until only score is left
  242. ;~                   consolewrite($scores[$scoreindex][2]& @crlf)
  243.                   EndIf
  244. ;~                ConsoleWrite($pos&"###"&$subwords[$m]& " "& stringlen($subwords[$m]) - $pos&@CRLF)
  245.                   $scores[$scoreindex][0] = StringTrimRight($subwords[$m],(stringlen($subwords[$m]) - ($pos-1)))        ; trim until only name left
  246. ;~                ConsoleWrite($scores[$scoreindex][0]&@crlf)
  247.                   $scoreindex +=1
  248.                   $subwords[$m] = ""
  249.                Else
  250.                   if $m >= 2 and $subwords[$m] <> "" then
  251.                      $ret &= $subwords[$m] & ","
  252.                   endif
  253.                endif
  254.  
  255.             next
  256.             $scr = sort($scores)
  257.             if $scr <> null Then
  258.                $ret &= $scr&","
  259.             EndIf
  260.             if (StringTrimLeft($ret,stringlen($ret)-1) == ",") Then
  261.                $ret = StringTrimRight($ret,1)
  262.             EndIf
  263.             $ret &= "] "
  264.          Else
  265.             $ret &= $words[$i] & " "
  266.          EndIf
  267.          $return &= $ret
  268.       next
  269.    EndIf
  270.    return($return)
  271. ;~    consolewrite($ret& @crlf)
  272. EndFunc
  273.  
  274.  
  275. func sort($arr)
  276.    $index = 0
  277. ;~    consolewrite($arr[1][2]& @crlf)
  278.    $return = "scores={"
  279.    while $arr[$index][0] <> "" and $index <100
  280. ;~    consolewrite($arr[$index][0]& @crlf)
  281.       for $i= $index to 99
  282.  
  283.          if $arr[$index][0] == $arr[$i][0] and $i<> $index Then
  284.             $arr[$index][1] += $arr[$i][1]
  285.             $arr[$index][2] += $arr[$i][2]
  286.             $arr[$i][0] = ""
  287.             $arr[$i][1] = 0
  288.             $arr[$i][2] = 0
  289. ;~          ConsoleWrite($arr[$index][0]&" "&$arr[$index][1]&" "&$arr[$index][2] & @crlf)
  290.          EndIf
  291.       Next
  292.       $index += 1
  293.    wend
  294.    for $index= 0 to 99
  295.       if $arr[$index][0] <> "" Then
  296.          if $return <> "scores={" Then
  297.             $return &= ","
  298.          endif
  299.          $return &= $arr[$index][0]
  300.          $return &= "="
  301.          $return &= $arr[$index][1]
  302.          $return &= ".."
  303.          $return &= $arr[$index][2]
  304. ;~       ConsoleWrite($arr[$index][0]&" "&$arr[$index][1]&" "&$arr[$index][2] & @crlf)
  305.       endif
  306.    next
  307.    StringTrimRight($return,1)   ; remove the last ","
  308.    $return &= "}"
  309.    if $return == "scores={}" Then
  310.       $return = null
  311.    EndIf
  312. ;~    consolewrite($return& @crlf)
  313.    return $return
  314. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement