Skip to content

Commit

Permalink
#35,#53,#54,#55 Adedd new language file format, added keep inventory …
Browse files Browse the repository at this point in the history
…flag.
  • Loading branch information
Shynixn committed Nov 8, 2024
1 parent 82b0dd4 commit b67e5b2
Show file tree
Hide file tree
Showing 48 changed files with 623 additions and 483 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# These are supported funding model platforms
patreon: Shynixn
31 changes: 16 additions & 15 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repositories {
}

tasks.register("printVersion") {
println(version)
println(version)
}

dependencies {
Expand All @@ -38,7 +38,7 @@ dependencies {
implementation("com.google.code.gson:gson:2.8.6")

// Custom dependencies
implementation("com.github.shynixn.mcutils:common:2024.25")
implementation("com.github.shynixn.mcutils:common:2024.36")
implementation("com.github.shynixn.mcutils:packet:2024.42")
implementation("com.github.shynixn.mcutils:sign:2024.3")
implementation("com.github.shynixn.mcutils:guice:2024.2")
Expand Down Expand Up @@ -196,26 +196,27 @@ tasks.register("pluginJarLegacy", com.github.jengelman.gradle.plugins.shadow.tas

tasks.register("languageFile") {
val kotlinSrcFolder = project.sourceSets.toList()[0].allJava.srcDirs.first { e -> e.endsWith("kotlin") }
val languageKotlinFile = kotlinSrcFolder.resolve("com/github/shynixn/mctennis/MCTennisLanguage.kt")
val resourceFile = kotlinSrcFolder.parentFile.resolve("resources").resolve("lang").resolve("en_us.properties")
val bundle = FileInputStream(resourceFile).use { stream ->
PropertyResourceBundle(stream)
}
val contractFile = kotlinSrcFolder.resolve("com/github/shynixn/mctennis/contract/Language.kt")
val resourceFile = kotlinSrcFolder.parentFile.resolve("resources").resolve("lang").resolve("en_us.yaml")
val lines = resourceFile.readLines()

val contents = ArrayList<String>()
contents.add("package com.github.shynixn.mctennis")
contents.add("package com.github.shynixn.mctennis.contract")
contents.add("")
contents.add("import com.github.shynixn.mcutils.common.language.LanguageItem")
contents.add("import com.github.shynixn.mcutils.common.language.LanguageProvider")
contents.add("")
contents.add("object MCTennisLanguage {")
for (key in bundle.keys) {
val value = bundle.getString(key)
contents.add(" /** $value **/")
contents.add(" var ${key} : String = \"$value\"")
contents.add("")
contents.add("interface Language : LanguageProvider {")
for (key in lines) {
if (key.toCharArray()[0].isLetter()) {
contents.add(" var ${key} LanguageItem")
contents.add("")
}
}
contents.removeLast()
contents.add("}")

languageKotlinFile.printWriter().use { out ->
contractFile.printWriter().use { out ->
for (line in contents) {
out.println(line)
}
Expand Down
2 changes: 1 addition & 1 deletion docs/wiki/docs/placeholders.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ The following placeholders are available in MCTennis and can also be used via Pl

| Player PlaceHolders | Description |
|----------------------------|-------------------------------------------------|
| %mctennis_player_name% | Name of the player during an event e.g. |
| %mctennis_player_isInGame% | true if the player is in the game, false if not |
| %mctennis_player_name% | Name of the player |

| Game and Player PlaceHolders | Description |
|----------------------------------|--------------------------------------------------|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package com.github.shynixn.mctennis

import com.fasterxml.jackson.core.type.TypeReference
import com.github.shynixn.mccoroutine.bukkit.launch
import com.github.shynixn.mctennis.contract.BedrockService
import com.github.shynixn.mctennis.contract.GameService
import com.github.shynixn.mctennis.contract.PlaceHolderService
import com.github.shynixn.mctennis.contract.TennisBallFactory
import com.github.shynixn.mctennis.contract.*
import com.github.shynixn.mctennis.entity.TennisArena
import com.github.shynixn.mctennis.enumeration.PluginDependency
import com.github.shynixn.mctennis.impl.service.*
Expand Down Expand Up @@ -54,6 +51,14 @@ class MCTennisDependencyInjectionModule(private val plugin: Plugin) : Dependency
override fun configure() {
// Common
addService<Plugin>(plugin)
addService<Language> {
val chatMessageService = getService<ChatMessageService>()
val language = MCTennisLanguageImpl()
language.chatMessageService = chatMessageService
language.placeHolderFun =
{ text, player -> getService<PlaceHolderService>().replacePlaceHolders(text, player) }
language
}

// Repositories
val tennisArenaRepository = YamlFileRepositoryImpl<TennisArena>(plugin,
Expand All @@ -67,7 +72,7 @@ class MCTennisDependencyInjectionModule(private val plugin: Plugin) : Dependency

// Services
addService<SignService> {
SignServiceImpl(plugin, getService(), MCTennisLanguage.noPermissionMessage)
SignServiceImpl(plugin, getService(), getService<Language>().noPermissionMessage.text)
}
addService<PhysicObjectService> {
PhysicObjectServiceImpl(plugin, getService())
Expand Down
186 changes: 0 additions & 186 deletions src/main/kotlin/com/github/shynixn/mctennis/MCTennisLanguage.kt

This file was deleted.

Loading

0 comments on commit b67e5b2

Please sign in to comment.