1
+ [string ] $updated = " 02-12-2020"
2
+ [string ] $version = " 1.0.0"
3
+ [string ] $mcVersion = " 1.14.4"
4
+ [string ] $downloadDir = " temp"
5
+ [string ] $outDir = " out"
6
+ [string ] $urlBase = " https://github.com/ProjectEssentials"
7
+ [array ] $modules = (" core" , " cooldown" , " permissions" , " essentials" , " chat" , " spawn" , " home" , " warps" , " backup" )
8
+ [array ] $localizations = (" en_us" , " ru_ru" , " de_de" )
9
+
10
+ Write-Output " Project Essentials resource-pack builder $version updated $updated ."
11
+ Write-Output " Building resource pack is starting ..."
12
+
13
+ if ($modules.Count -eq 0 ) {
14
+ Write-Warning " Modules whose resources should be bundled in resource-pack are not specified, by default all modules will be used."
15
+ $modules = (" core" , " cooldown" , " permissions" , " essentials" , " chat" , " spawn" , " home" , " warps" , " backup" )
16
+ }
17
+
18
+ function PurgeTempFiles {
19
+ if (Test-Path - Path $downloadDir - PathType Container) {
20
+ Remove-Item " $downloadDir \*" - Recurse - Force
21
+ }
22
+ }
23
+
24
+ function DownloadLocalization {
25
+ param (
26
+ [string ] $module
27
+ )
28
+
29
+ Write-Output " Starting proccessing resources for $module of version $mcVersion "
30
+
31
+ $moduleVersion
32
+ if ($mcVersion -eq " 1.14.4" ) {
33
+ if ($module -eq " permissions" ) {
34
+ $moduleVersion = " 1.14.X"
35
+ }
36
+ else {
37
+ $moduleVersion = " 1.14.4"
38
+ }
39
+ }
40
+
41
+ $link
42
+ if ($module -eq " essentials" ) {
43
+ $link = " $urlBase /ProjectEssentials/raw/MC-$mcVersion /src/main/resources/assets/projectessentials/lang"
44
+ }
45
+ else {
46
+ $link = " $urlBase /ProjectEssentials-$module /raw/MC-$moduleVersion /src/main/resources/assets/projectessentials$module /lang"
47
+ }
48
+
49
+ [array ] $downloaded -join ' , '
50
+
51
+ ForEach ($localization in $localizations ) {
52
+ try {
53
+ if ($module -eq " essentials" ) {
54
+ [system.io.directory ]::CreateDirectory(" $downloadDir \assets\projectessentials\lang" )
55
+ }
56
+ else {
57
+ [system.io.directory ]::CreateDirectory(" $downloadDir \assets\projectessentials$module \lang" )
58
+ }
59
+
60
+ if ($module -eq " essentials" ) {
61
+ (New-Object System.Net.WebClient).DownloadFile(" $link /$localization .json" , " $downloadDir \assets\projectessentials\lang\$localization .json" )
62
+ }
63
+ else {
64
+ (New-Object System.Net.WebClient).DownloadFile(" $link /$localization .json" , " $downloadDir \assets\projectessentials$module \lang\$localization .json" )
65
+ }
66
+
67
+ $downloaded += $localization
68
+ }
69
+ catch {
70
+ Write-Warning " $localization not found in $module , will be skiped."
71
+ }
72
+ finally {
73
+ Write-Output " Downloaded: $downloaded localizations for module $module "
74
+ $downloaded = (" " )
75
+ }
76
+ }
77
+ }
78
+
79
+
80
+ function Pack {
81
+ param (
82
+ [string ] $module
83
+ )
84
+
85
+ Write-Output " Packing resource-pack for $module ..."
86
+
87
+ [system.io.directory ]::CreateDirectory($outDir )
88
+
89
+ $source
90
+ if ($module -eq " essentials" ) {
91
+ $source = " $downloadDir \assets\projectessentials"
92
+ }
93
+ else {
94
+ $source = " $downloadDir \assets\projectessentials$module "
95
+ }
96
+
97
+ $destination = " $outDir \ProjectEssentials-Localization-$mcVersion -$module .zip"
98
+
99
+ If (Test-path $destination ) { Remove-item $destination }
100
+
101
+ Compress-Archive - Path $source - DestinationPath " $destination "
102
+ Compress-Archive - Path " pack\$mcVersion \pack.mcmeta" - Update - DestinationPath " $destination "
103
+ }
104
+
105
+ function PackAll {
106
+ Write-Output " Packing generic resource-pack ..."
107
+
108
+ $source = " $downloadDir \assets"
109
+ $destination = " $outDir \ProjectEssentials-Localization-$mcVersion -all.zip"
110
+
111
+ If (Test-path $destination ) { Remove-item $destination }
112
+
113
+ Compress-Archive - Path $source - DestinationPath " $destination "
114
+ Compress-Archive - Path " pack\$mcVersion \pack.mcmeta" - Update - DestinationPath " $destination "
115
+ }
116
+
117
+
118
+ PurgeTempFiles
119
+ ForEach ($module in $modules ) {
120
+ DownloadLocalization($module )
121
+ Pack($module )
122
+ }
123
+
124
+ PackAll
125
+
126
+ Write-Output " Resource-packs generated! Done!"
127
+
128
+ Pause
0 commit comments