-
Notifications
You must be signed in to change notification settings - Fork 2
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
0 parents
commit 64bb6f5
Showing
109 changed files
with
4,844 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.architectury-transformer/ | ||
build/ | ||
*.ipr | ||
run/ | ||
*.iws | ||
out/ | ||
*.iml | ||
.gradle/ | ||
output/ | ||
bin/ | ||
libs/ | ||
|
||
.classpath | ||
.project | ||
.idea/ | ||
classes/ | ||
.metadata | ||
.vscode | ||
.settings | ||
*.launch | ||
*_key.txt |
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,85 @@ | ||
## Maven repository | ||
```kotlin | ||
repositories { | ||
maven("https://repo.plasmoverse.com/snapshots") | ||
} | ||
``` | ||
|
||
|
||
## API | ||
|
||
### Common | ||
Shared API for server and proxy | ||
```kotlin | ||
implementation("su.plo.crosslib:api-common:$libVersion") | ||
``` | ||
|
||
### Server | ||
API for server platforms: Spigot/Fabric/Forge | ||
```kotlin | ||
implementation("su.plo.crosslib:api-server:$libVersion") | ||
``` | ||
|
||
#### Proxy | ||
API for proxy platforms: Velocity/BungeeCord | ||
```kotlin | ||
implementation("su.plo.crosslib:api-proxy:$libVersion") | ||
``` | ||
|
||
## Platforms | ||
|
||
### Fabric | ||
```kotlin | ||
modImplementation(include("su.plo.crosslib:fabric-$mcVersion:$libVersion")!!) | ||
``` | ||
|
||
### Forge | ||
```kotlin | ||
implementation("su.plo.crosslib:forge-$mcVersion:$libVersion") | ||
``` | ||
|
||
### Spigot | ||
```kotlin | ||
implementation("su.plo.crosslib:spigot:$libVersion") | ||
``` | ||
|
||
### BungeeCord | ||
```kotlin | ||
implementation("su.plo.crosslib:bungee:$libVersion") | ||
``` | ||
|
||
### Velocity | ||
```kotlin | ||
implementation("su.plo.crosslib:velocity:$libVersion") | ||
``` | ||
|
||
|
||
## Version | ||
|
||
### Fabric/Forge minecraft versions | ||
There is not all minecraft versions for Fabric/Forge platforms, so you need to use older/newer supported minecraft version | ||
<table> | ||
<tbody> | ||
<tr> | ||
<th>Lib minecraft version</th> | ||
<th>Supported minecraft versions</th> | ||
</tr> | ||
<tr> | ||
<td>1.16.5</td> | ||
<td>1.16.5</td> | ||
</tr> | ||
<tr> | ||
<td>1.17.1</td> | ||
<td>[1.17.1 - 1.18.2]</td> | ||
</tr> | ||
<tr> | ||
<td>1.19.3</td> | ||
<td>1.19.2+</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
For instanc, with minecraft 1.20 you need to use 1.19.3: | ||
```kotlin | ||
implementation("su.plo.crosslib:$platform-1.19.3:$libVersion") | ||
```` |
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,5 @@ | ||
Modules: | ||
- for everything -> common | ||
- for spigot + modded -> server | ||
- for bungee/velocity -> proxy | ||
|
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,48 @@ | ||
package su.plo.slib.api | ||
|
||
import su.plo.slib.api.chat.component.McTextComponent | ||
import su.plo.slib.api.chat.component.McTranslatableText | ||
import su.plo.slib.api.chat.converter.ServerTextConverter | ||
import su.plo.slib.api.command.McCommandManager | ||
import su.plo.slib.api.language.ServerLanguages | ||
import su.plo.slib.api.permission.PermissionsManager | ||
|
||
/** | ||
* Represents a Minecraft server | ||
* | ||
* Use it when you are using ONLY common module | ||
* | ||
* For proxy use MinecraftServerLib | ||
* For server use MinecraftProxyLib | ||
*/ | ||
interface McLib { | ||
|
||
/** | ||
* Gets server languages | ||
* | ||
* @see ServerLanguages | ||
*/ | ||
val languages: ServerLanguages | ||
|
||
/** | ||
* Gets the text converter | ||
* | ||
* Text converter used to convert [McTextComponent] to server's specific text component | ||
* | ||
* [ServerTextConverter] can translate [McTranslatableText] by using | ||
* [ServerLanguages] ([ServerTextConverter.convert]) | ||
* | ||
* @return [ServerTextConverter] | ||
*/ | ||
val textConverter: ServerTextConverter<*> | ||
|
||
/** | ||
* @see McCommandManager | ||
*/ | ||
val commandManager: McCommandManager<*> | ||
|
||
/** | ||
* @see PermissionsManager | ||
*/ | ||
val permissionsManager: PermissionsManager | ||
} |
13 changes: 13 additions & 0 deletions
13
api/common/src/main/kotlin/su/plo/slib/api/chat/component/McLiteralText.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,13 @@ | ||
package su.plo.slib.api.chat.component | ||
|
||
/** | ||
* Text component contains plain text | ||
*/ | ||
class McLiteralText( | ||
val text: String | ||
) : McTextComponent() { | ||
|
||
override fun toString(): String { | ||
return text | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
api/common/src/main/kotlin/su/plo/slib/api/chat/component/McTextComponent.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,67 @@ | ||
package su.plo.slib.api.chat.component | ||
|
||
import su.plo.slib.api.chat.style.McTextClickEvent | ||
import su.plo.slib.api.chat.style.McTextHoverEvent | ||
import su.plo.slib.api.chat.style.McTextStyle | ||
import java.util.* | ||
|
||
abstract class McTextComponent { | ||
|
||
val styles: MutableList<McTextStyle> = ArrayList() | ||
val siblings: MutableList<McTextComponent> = ArrayList() | ||
|
||
var clickEvent: McTextClickEvent? = null | ||
var hoverEvent: McTextHoverEvent? = null | ||
|
||
fun append(vararg components: McTextComponent): McTextComponent { | ||
Collections.addAll(siblings, *components) | ||
return this | ||
} | ||
|
||
fun append(components: Collection<McTextComponent>): McTextComponent { | ||
siblings.addAll(components) | ||
return this | ||
} | ||
|
||
fun withStyle(style: McTextStyle): McTextComponent { | ||
styles.add(style) | ||
return this | ||
} | ||
|
||
fun withStyle(vararg styles: McTextStyle): McTextComponent { | ||
this.styles.addAll(Arrays.asList(*styles)) | ||
return this | ||
} | ||
|
||
fun clickEvent(clickEvent: McTextClickEvent?): McTextComponent { | ||
this.clickEvent = clickEvent | ||
return this | ||
} | ||
|
||
fun hoverEvent(hoverEvent: McTextHoverEvent?): McTextComponent { | ||
this.hoverEvent = hoverEvent | ||
return this | ||
} | ||
|
||
fun mergeWith(component: McTextComponent): McTextComponent { | ||
return withStyle(*component.styles.toTypedArray()) | ||
.append(component.siblings) | ||
.clickEvent(component.clickEvent) | ||
.hoverEvent(component.hoverEvent) | ||
} | ||
|
||
companion object { | ||
fun literal(text: String): McLiteralText { | ||
return McLiteralText(text) | ||
} | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
fun translatable(key: String, vararg args: Any): McTranslatableText { | ||
return McTranslatableText(key, args as Array<Any>) | ||
} | ||
|
||
fun empty(): McTextComponent { | ||
return McLiteralText("") | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
api/common/src/main/kotlin/su/plo/slib/api/chat/component/McTranslatableText.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,11 @@ | ||
package su.plo.slib.api.chat.component | ||
|
||
class McTranslatableText( | ||
val key: String, | ||
val args: Array<Any> | ||
) : McTextComponent() { | ||
|
||
override fun toString(): String { | ||
return key | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
api/common/src/main/kotlin/su/plo/slib/api/chat/converter/McTextConverter.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,23 @@ | ||
package su.plo.slib.api.chat.converter | ||
|
||
import su.plo.slib.api.chat.component.McTextComponent | ||
import java.util.stream.Collectors | ||
|
||
interface McTextConverter<T> { | ||
|
||
fun convertToJson(text: T): String | ||
|
||
fun convertToJson(text: McTextComponent): String { | ||
return convertToJson(convert(text)) | ||
} | ||
|
||
fun convertFromJson(json: String): T | ||
|
||
fun convert(text: McTextComponent): T | ||
|
||
fun convert(list: List<McTextComponent>): List<T>? { | ||
return list.stream() | ||
.map { text: McTextComponent -> this.convert(text) } | ||
.collect(Collectors.toList()) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
api/common/src/main/kotlin/su/plo/slib/api/chat/converter/ServerTextConverter.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,43 @@ | ||
package su.plo.slib.api.chat.converter | ||
|
||
import su.plo.slib.api.chat.component.McTextComponent | ||
import su.plo.slib.api.chat.component.McTranslatableText | ||
import su.plo.slib.api.command.McCommandSource | ||
import su.plo.slib.api.language.ServerLanguages | ||
|
||
abstract class ServerTextConverter<T>( | ||
private val languages: ServerLanguages | ||
) : TranslatableTextConverter<T>() { | ||
|
||
fun convertToJson(source: McCommandSource, text: McTextComponent): String { | ||
val language = languages.getServerLanguage(source) | ||
|
||
val convertedText = translateInner(language, text) | ||
if (convertedText !is McTranslatableText) | ||
return convertToJson(text) | ||
|
||
if (!language.containsKey(convertedText.key)) | ||
return convertToJson(text) | ||
|
||
return convertToJson(translate( | ||
language, | ||
convertedText | ||
)) | ||
} | ||
|
||
fun convert(source: McCommandSource, text: McTextComponent): T { | ||
val language = languages.getServerLanguage(source) | ||
|
||
val convertedText = translateInner(language, text) | ||
if (convertedText !is McTranslatableText) | ||
return convert(text) | ||
|
||
if (!language.containsKey(convertedText.key)) | ||
return convert(text) | ||
|
||
return convert(translate( | ||
language, | ||
convertedText | ||
)) | ||
} | ||
} |
Oops, something went wrong.