Skip to content

Commit

Permalink
#575,#574 Added spam click protection and new language file format.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shynixn committed Nov 29, 2024
1 parent 8cb1a8a commit 95c5370
Show file tree
Hide file tree
Showing 24 changed files with 1,120 additions and 1,043 deletions.
99 changes: 56 additions & 43 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2")

// Custom dependencies
implementation("com.github.shynixn.mcutils:common:2024.25")
implementation("com.github.shynixn.mcutils:packet:2024.47")
implementation("com.github.shynixn.mcutils:common:2024.38")
implementation("com.github.shynixn.mcutils:packet:2024.49")
implementation("com.github.shynixn.mcutils:database:2024.8")
implementation("com.github.shynixn.mcutils:sign:2024.3")
implementation("com.github.shynixn.mcutils:guice:2024.2")
Expand Down Expand Up @@ -208,57 +208,70 @@ tasks.register("pluginJarLegacy", ShadowJar::class.java) {

tasks.register("languageFile") {
val kotlinSrcFolder = project.sourceSets.toList()[0].allJava.srcDirs.first { e -> e.endsWith("java") }
val contractFile = kotlinSrcFolder.resolve("com/github/shynixn/blockball/contract/Language.kt")
val resourceFile = kotlinSrcFolder.parentFile.resolve("resources").resolve("lang").resolve("en_us.yml")
val lines = resourceFile.readLines()

// Contract file
var languageKotlinFile = kotlinSrcFolder.resolve("com/github/shynixn/blockball/contract/BlockBallLanguage.kt")
var resourceFile = kotlinSrcFolder.parentFile.resolve("resources").resolve("lang").resolve("en_us.properties")
var bundle = FileInputStream(resourceFile).use { stream ->
PropertyResourceBundle(stream)
}

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

languageKotlinFile.printWriter().use { out ->
for (line in contents) {
contractFile.printWriter().use { out ->
for (line in contractContents) {
out.println(line)
}
}

// Impl File
languageKotlinFile = kotlinSrcFolder.resolve("com/github/shynixn/blockball/BlockBallLanguageImpl.kt")
resourceFile = kotlinSrcFolder.parentFile.resolve("resources").resolve("lang").resolve("en_us.properties")
bundle = FileInputStream(resourceFile).use { stream ->
PropertyResourceBundle(stream)
}
val implFile = kotlinSrcFolder.resolve("com/github/shynixn/blockball/BlockBallLanguageImpl.kt")
val implContents = ArrayList<String>()
implContents.add("package com.github.shynixn.blockball")
implContents.add("")
implContents.add("import com.github.shynixn.mcutils.common.language.LanguageItem")
implContents.add("import com.github.shynixn.mcutils.common.language.LanguageProviderImpl")
implContents.add("import com.github.shynixn.blockball.contract.Language")
implContents.add("")
implContents.add("class BlockBallLanguageImpl : Language, LanguageProviderImpl() {")
implContents.add(" override val names: List<String>\n" +
" get() = listOf(\"en_us\", \"es_es\")")

contents = ArrayList<String>()
contents.add("package com.github.shynixn.blockball")
contents.add("")
contents.add("import com.github.shynixn.blockball.contract.BlockBallLanguage")
contents.add("")
contents.add("object BlockBallLanguageImpl : BlockBallLanguage {")
for (key in bundle.keys) {
val value = bundle.getString(key)
contents.add(" /** $value **/")
contents.add(" override var ${key} : String = \"$value\"")
contents.add("")
for (i in 0 until lines.size) {
val key = lines[i]

if (key.toCharArray()[0].isLetter()) {
var text = ""
println(">" + lines[i])

println("_")
var j = i
while (true){
if(lines[j].contains("text:")){
text = lines[j]
break
}
j++
}

implContents.add(" override var ${key.replace(":","")} = LanguageItem(${text.replace(" text: ","")})")
implContents.add("")
}
}
contents.removeLast()
contents.add("}")
implContents.removeLast()
implContents.add("}")

languageKotlinFile.printWriter().use { out ->
for (line in contents) {
implFile.printWriter().use { out ->
for (line in implContents) {
out.println(line)
}
}
Expand Down
18 changes: 9 additions & 9 deletions docs/wiki/docs/permission.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ The following permissions are available in BlockBall.

### All Permissions

| Permission | Level | Description |
|--------------------------|------------|------------------------------------------------------------------------------------------------------|
| blockball.command | User | Allows to use the /blockball command. |
| blockball.join.* | User | Allows to join all games. The **blockball.command** permission is also required. |
| blockball.join.[name] | User | Allows to join a specific game. The **blockball.command** permission is also required. |
| blockball.command.staff | Admin/User | Allows to execute commands while ingame. This permission will be replaced in the future. |
| blockball.game.inventory | Admin/User | Allows open and click in inventories while ingame. This permission will be replaced in the future. |
| blockball.edit | Admin | Allows to create, edit and delete games. |
| blockball.referee.join | Admin | Allows to manipulate games using /blockball referee commands |
| Permission | Level | Description |
|---------------------------|------------|------------------------------------------------------------------------------------------------------|
| blockball.command | User | Allows to use the /blockball command. |
| blockball.join.* | User | Allows to join all games. The **blockball.command** permission is also required. |
| blockball.join.[name] | User | Allows to join a specific game. The **blockball.command** permission is also required. |
| blockball.command.staff | Admin/User | Allows to execute commands while ingame. This permission will be replaced in the future. |
| blockball.game.inventory | Admin/User | Allows open and click in inventories while ingame. This permission will be replaced in the future. |
| blockball.edit | Admin | Allows to create, edit and delete games. |
| blockball.referee.join | Admin | Allows to manipulate games using /blockball referee commands |
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ import org.bukkit.plugin.Plugin
import java.util.logging.Level

class BlockBallDependencyInjectionModule(
private val plugin: BlockBallPlugin
private val plugin: BlockBallPlugin,
private val language: Language
) : DependencyInjectionModule() {
companion object {
val areLegacyVersionsIncluded: Boolean by lazy {
Expand All @@ -60,6 +61,7 @@ class BlockBallDependencyInjectionModule(
*/
override fun configure() {
addService<Plugin>(plugin)
addService<Language>(language)

// Repositories
val arenaRepository = YamlFileRepositoryImpl<SoccerArena>(plugin, "arena",
Expand All @@ -84,9 +86,8 @@ class BlockBallDependencyInjectionModule(
)
addService<PlayerDataRepository<PlayerInformation>>(playerDataRepository)
addService<CachePlayerRepository<PlayerInformation>>(playerDataRepository)
addService<BlockBallLanguage>(BlockBallLanguageImpl)
addService<SignService> {
SignServiceImpl(plugin, getService(), BlockBallLanguageImpl.noPermissionMessage)
SignServiceImpl(plugin, getService(),language.noPermissionMessage.text)
}

// Services
Expand Down
Loading

0 comments on commit 95c5370

Please sign in to comment.