-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5832266
commit 8ca91d2
Showing
16 changed files
with
104 additions
and
45 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
53 changes: 53 additions & 0 deletions
53
dist/src/main/kotlin/kr/toxicity/healthbar/manager/EncodeManager.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package kr.toxicity.healthbar.manager | ||
|
||
import kr.toxicity.healthbar.pack.PackResource | ||
import java.util.* | ||
|
||
object EncodeManager : BetterHealthBerManager { | ||
|
||
private val encodeMap = EnumMap<EncodeNamespace, MutableMap<String, Int>>(EncodeNamespace::class.java) | ||
|
||
override fun reload(resource: PackResource) { | ||
|
||
} | ||
|
||
override fun postReload() { | ||
encodeMap.clear() | ||
} | ||
enum class EncodeNamespace { | ||
FONT, | ||
TEXTURES | ||
} | ||
fun generateKey(namespace: EncodeNamespace, name: String): String { | ||
val map = synchronized(encodeMap) { | ||
encodeMap.computeIfAbsent(namespace) { | ||
mutableMapOf() | ||
} | ||
} | ||
return synchronized(map) { | ||
map.computeIfAbsent(name) { | ||
map.size | ||
}.encode() | ||
} | ||
} | ||
|
||
private fun Int.encode(): String { | ||
var i = this | ||
val size = chars.size | ||
return buildString { | ||
while (i >= size) { | ||
append(chars.first()) | ||
i -= size | ||
} | ||
append(chars[i]) | ||
} | ||
} | ||
|
||
private val chars = listOf( | ||
'a', 'b', 'c', 'd', 'e', 'f', 'g', | ||
'h', 'i', 'j', 'k', 'm', 'n', 'l', 'o', 'p', | ||
'q', 'r', 's', 't', 'u', 'v', | ||
'w', 'x', 'y', 'z', | ||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9' | ||
) | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
15 changes: 15 additions & 0 deletions
15
dist/src/main/kotlin/kr/toxicity/healthbar/util/Encodes.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package kr.toxicity.healthbar.util | ||
|
||
import kr.toxicity.healthbar.manager.ConfigManagerImpl | ||
import kr.toxicity.healthbar.manager.EncodeManager | ||
import net.kyori.adventure.key.Key | ||
|
||
fun String.encodeFile(path: EncodeManager.EncodeNamespace): String { | ||
val split = split('.') | ||
if (split.size != 2) throw RuntimeException("Invaild file name: $this") | ||
return "${encodeKey(path, split[0])}.${split[1]}" | ||
} | ||
|
||
fun encodeKey(path: EncodeManager.EncodeNamespace, name: String) = if (ConfigManagerImpl.resourcePackObfuscation()) EncodeManager.generateKey(path, name) else name | ||
|
||
fun createAdventureKey(path: String) = Key.key(NAMESPACE, path) |
This file contains 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