Skip to content

Commit 05cf285

Browse files
committed
Changes synced with 1.14.4 branch.
Signed-off-by: Pavel Erokhin (MairwunNx) <MairwunNx@gmail.com>
1 parent 773bbd7 commit 05cf285

File tree

14 files changed

+393
-133
lines changed

14 files changed

+393
-133
lines changed

build.gradle

Lines changed: 84 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,25 @@ buildscript {
1919
classpath(
2020
"org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
2121
)
22+
classpath(
23+
"org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
24+
)
2225
}
2326
}
2427

28+
plugins {
29+
id "maven-publish"
30+
id "java-library"
31+
id "maven"
32+
}
33+
34+
apply(plugin: "org.jetbrains.dokka")
2535
apply(plugin: "net.minecraftforge.gradle")
2636
apply(plugin: "kotlin")
2737
apply(plugin: "kotlinx-serialization")
2838

39+
String packagesToken = new String(package_public_token.decodeBase64())
40+
2941
version = module_version
3042
group = "com.mairwunnx.$module_id"
3143
archivesBaseName = module_name
@@ -68,41 +80,61 @@ minecraft {
6880
repositories {
6981
jcenter()
7082
mavenCentral()
71-
maven { url("https://minecraft.curseforge.com/api/maven/") }
7283
maven { url("https://libraries.minecraft.net") }
73-
maven { url("https://jitpack.io") }
84+
maven { url "https://jitpack.io" }
85+
maven {
86+
name = "GitHubPackages"
87+
url = uri "https://maven.pkg.github.com/projectessentials/projectessentials-core"
88+
credentials {
89+
username = "MairwunNx@gmail.com"
90+
password = packagesToken
91+
}
92+
}
93+
maven {
94+
name = "GitHubPackages"
95+
url = uri "https://maven.pkg.github.com/projectessentials/projectessentials-permissions"
96+
credentials {
97+
username = "MairwunNx@gmail.com"
98+
password = packagesToken
99+
}
100+
}
101+
maven {
102+
name = "GitHubPackages"
103+
url = uri "https://maven.pkg.github.com/ProjectEssentials/ProjectEssentials-Cooldown"
104+
credentials {
105+
username = "MairwunNx@gmail.com"
106+
password = packagesToken
107+
}
108+
}
74109
}
75110

76111
dependencies {
77112
minecraft(group: "net.minecraftforge", name: "forge", version: forge_version)
78-
compile(group: "com.mojang", name: "brigadier", version: brigadier_version)
79-
compile(
113+
114+
implementation 'com.mairwunnx.project_essentials_core:ProjectEssentials-Core:1.15.2-1.1.0'
115+
implementation 'com.mairwunnx.project_essentials_permissions:ProjectEssentials-Permissions:1.15.2-1.0.1'
116+
implementation 'com.mairwunnx.project_essentials_cooldown:ProjectEssentials-Cooldown:1.15.2-1.0.1'
117+
118+
implementation(group: "com.mojang", name: "brigadier", version: brigadier_version)
119+
implementation(
80120
group: "org.jetbrains.kotlinx",
81121
name: "kotlinx-serialization-runtime",
82122
version: kotlinx_serialization_version
83123
)
84-
compile(
124+
implementation(
85125
group: "org.jetbrains.kotlin",
86126
name: "kotlin-stdlib-$kotlin_jdk_version_target",
87127
version: kotlin_version
88128
)
89-
compile(
90-
group: "com.github.projectessentials",
91-
name: "ProjectEssentials-Permissions",
92-
version: ess_perm_version
93-
)
94-
compile(
95-
group: "com.github.projectessentials",
96-
name: "ProjectEssentials-Core",
97-
version: ess_core_version
98-
)
99-
compile(
100-
group: "com.github.projectessentials",
101-
name: "ProjectEssentials-Cooldown",
102-
version: ess_cooldown_version
103-
)
104129
}
105130

131+
dokka {
132+
outputFormat = 'html'
133+
outputDirectory = "$buildDir/libs/docs"
134+
}
135+
136+
project.tasks["jar"].dependsOn(project.tasks["dokka"])
137+
106138
jar {
107139
manifest {
108140
attributes([
@@ -123,3 +155,35 @@ sourceCompatibility = targetCompatibility =
123155

124156
compileKotlin.kotlinOptions.jvmTarget =
125157
compileTestKotlin.kotlinOptions.jvmTarget = project_jvm_version_target
158+
159+
task sourcesJar(type: Jar) {
160+
classifier = 'sources'
161+
from sourceSets.main.allSource
162+
}
163+
164+
task dokkaJar(type: Jar) {
165+
group = JavaBasePlugin.DOCUMENTATION_GROUP
166+
description = "Assembles Kotlin docs with Dokka"
167+
classifier = "javadoc"
168+
from tasks.dokka as Object
169+
}
170+
171+
publishing {
172+
repositories {
173+
maven {
174+
name = "GitHubPackages"
175+
url = uri "https://maven.pkg.github.com/projectessentials/projectessentials-home"
176+
credentials {
177+
username = System.getenv("GradleUser")
178+
password = System.getenv("GradlePass")
179+
}
180+
}
181+
}
182+
publications {
183+
gpr(MavenPublication) {
184+
from components.java
185+
artifact sourcesJar
186+
artifact dokkaJar
187+
}
188+
}
189+
}

changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [1.15.2-1.1.0] - 2020-03-17
10+
11+
### Added
12+
13+
### Changed
14+
15+
### Removed
16+
917
## [1.15.2-1.0.0] - 2020-02-08
1018

1119
### Added

gradle.properties

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ forge_mappings_channel_version=20190719-1.14.3
1111
brigadier_version=1.0.17
1212
kotlin_jdk_version_target=jdk8
1313
project_jvm_version_target=1.8
14-
kotlin_version=1.3.61
15-
kotlinx_serialization_version=0.14.0
16-
ess_core_version=v1.15.2-1.+
17-
ess_perm_version=v1.15.2-1.+
18-
ess_cooldown_version=v1.15.2-1.+
19-
module_version=1.15.2-1.0.0
14+
kotlin_version=1.3.70
15+
kotlinx_serialization_version=0.20.0
16+
dokka_version=0.10.1
17+
module_version=1.15.2-1.1.0
2018
module_name=Project Essentials Home
2119
module_id=project_essentials_home
2220
module_vendor=MairwunNx (Pavel Erokhin)
21+
package_public_token=ZDhjMjgyNjlhM2E0ZTQ0MmM2Mjk5ZWI4YmMyZjI0YzNjOTNkMDVkZA==

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### Explore
66

7-
#### [Download mod](https://github.com/ProjectEssentials/ProjectEssentials-Home/releases/download/v1.15.2-1.0.0/Project.Essentials.Home-1.15.2-1.0.0.jar) · [How to install](https://mairwunnx.gitbook.io/project-essentials/project-essentials-home#how-to-install) · [Commands](https://mairwunnx.gitbook.io/project-essentials/project-essentials-home#commands-and-permissions) · [Configuration](https://mairwunnx.gitbook.io/project-essentials/project-essentials-home#configuration) · [Troubleshooting](https://github.com/ProjectEssentials/ProjectEssentials-Home/issues/new/choose) · [CurseForge](https://www.curseforge.com/minecraft/mc-mods/ProjectEssentials-Home) · [Change log](changelog.md)
7+
#### [Download mod](https://github.com/ProjectEssentials/ProjectEssentials-Home/releases/download/v1.15.2-1.1.0/Project.Essentials.Home-1.15.2-1.1.0.jar) · [How to install](https://mairwunnx.gitbook.io/project-essentials/project-essentials-home#how-to-install) · [Commands](https://mairwunnx.gitbook.io/project-essentials/project-essentials-home#commands-and-permissions) · [Configuration](https://mairwunnx.gitbook.io/project-essentials/project-essentials-home#configuration) · [Troubleshooting](https://github.com/ProjectEssentials/ProjectEssentials-Home/issues/new/choose) · [CurseForge](https://www.curseforge.com/minecraft/mc-mods/ProjectEssentials-Home) · [Change log](changelog.md)
88

99
### Compatibility
1010

src/main/kotlin/com/mairwunnx/projectessentials/home/EntryPoint.kt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.mairwunnx.projectessentials.home
22

33
import com.mairwunnx.projectessentials.core.EssBase
4+
import com.mairwunnx.projectessentials.core.configuration.localization.LocalizationConfigurationUtils
5+
import com.mairwunnx.projectessentials.core.localization.processLocalizations
46
import com.mairwunnx.projectessentials.home.commands.DelHomeCommand
57
import com.mairwunnx.projectessentials.home.commands.HomeCommand
68
import com.mairwunnx.projectessentials.home.commands.SetHomeCommand
@@ -18,16 +20,29 @@ import org.apache.logging.log4j.LogManager
1820

1921
@Suppress("unused")
2022
@Mod("project_essentials_home")
21-
class EntryPoint : EssBase() {
23+
internal class EntryPoint : EssBase() {
2224
private val logger = LogManager.getLogger()
2325

2426
init {
2527
modInstance = this
26-
modVersion = "1.15.2-1.0.0"
28+
modVersion = "1.15.2-1.1.0"
2729
logBaseInfo()
2830
validateForgeVersion()
2931
MinecraftForge.EVENT_BUS.register(this)
3032
StorageBase.loadUserData()
33+
loadLocalization()
34+
}
35+
36+
private fun loadLocalization() {
37+
if (LocalizationConfigurationUtils.getConfig().enabled) {
38+
processLocalizations(
39+
EntryPoint::class.java, listOf(
40+
"/assets/projectessentialshome/lang/en_us.json",
41+
"/assets/projectessentialshome/lang/ru_ru.json",
42+
"/assets/projectessentialshome/lang/de_de.json"
43+
)
44+
)
45+
}
3146
}
3247

3348
@SubscribeEvent
@@ -47,7 +62,7 @@ class EntryPoint : EssBase() {
4762
@Suppress("UNUSED_PARAMETER")
4863
@SubscribeEvent
4964
fun onServerStopping(it: FMLServerStoppingEvent) {
50-
StorageBase.saveUserData()
65+
HomeAPI.save()
5166
}
5267

5368
private fun loadAdditionalModules() {
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
package com.mairwunnx.projectessentials.home
2+
3+
import com.mairwunnx.projectessentials.home.models.HomeModel
4+
import com.mairwunnx.projectessentials.home.storage.StorageBase
5+
import net.minecraft.entity.player.ServerPlayerEntity
6+
7+
/**
8+
* Home API base class. Contains all
9+
* methods for interaction with player homes.
10+
*
11+
* @since 1.14.4-1.2.0
12+
*/
13+
object HomeAPI {
14+
/**
15+
* Create home for target player with specified name.
16+
*
17+
* @param owner ServerPlayerEntity class instance,
18+
* target home owner.
19+
* @param name new home name with default value `home`.
20+
* @param override if true then if world existing with same
21+
* name then it world will be replaced with new home record,
22+
* default value is `false`.
23+
*
24+
* @return true if home creating successful otherwise false.
25+
*
26+
* @since 1.14.4-1.2.0
27+
*/
28+
fun create(
29+
owner: ServerPlayerEntity,
30+
name: String = "home",
31+
override: Boolean = false
32+
): Boolean {
33+
val playerUUID = owner.uniqueID.toString()
34+
val clientWorld = owner.commandSource.world.worldInfo.worldName
35+
val worldId = owner.commandSource.world.worldType.id
36+
val xPos = owner.positionVec.x.toInt()
37+
val yPos = owner.positionVec.y.toInt()
38+
val zPos = owner.positionVec.z.toInt()
39+
val yaw = owner.rotationYaw
40+
val pitch = owner.rotationPitch
41+
val homes = takeAll(owner)
42+
43+
if (override) {
44+
homes.removeAll {
45+
it.home == name
46+
}
47+
} else {
48+
if (contains(
49+
homes,
50+
name
51+
)
52+
) return false
53+
}
54+
55+
homes.add(
56+
HomeModel.Home(
57+
name, clientWorld, worldId, xPos, yPos, zPos, yaw, pitch
58+
)
59+
)
60+
StorageBase.setData(playerUUID, HomeModel(homes))
61+
return true
62+
}
63+
64+
/**
65+
* Remove home for target player with specified name.
66+
*
67+
* @param owner ServerPlayerEntity class instance,
68+
* target home owner.
69+
* @param name home name to remove with default value `home`.
70+
*
71+
* @return true if home removing successful otherwise false.
72+
*
73+
* @since 1.14.4-1.2.0
74+
*/
75+
fun remove(
76+
owner: ServerPlayerEntity,
77+
name: String = "home"
78+
): Boolean {
79+
val playerUUID = owner.uniqueID.toString()
80+
val homes = takeAll(owner)
81+
82+
take(owner, name)?.let {
83+
homes.remove(it)
84+
StorageBase.setData(playerUUID, HomeModel(homes))
85+
return true
86+
}
87+
return false
88+
}
89+
90+
/**
91+
* @param owner ServerPlayerEntity class instance,
92+
* target home owner.
93+
*
94+
* @return all player registered homes.
95+
*
96+
* @since 1.14.4-1.2.0
97+
*/
98+
fun takeAll(owner: ServerPlayerEntity): MutableList<HomeModel.Home> =
99+
StorageBase.getData(owner.uniqueID.toString()).homes
100+
101+
/**
102+
* @param owner ServerPlayerEntity class instance,
103+
* target home owner.
104+
* @param name home name with default value `home`.
105+
*
106+
* @return null if home not exist otherwise home instance.
107+
*
108+
* @since 1.14.4-1.2.0
109+
*/
110+
fun take(
111+
owner: ServerPlayerEntity,
112+
name: String = "home"
113+
): HomeModel.Home? {
114+
val homes = takeAll(owner)
115+
homes.forEach {
116+
if (it.home == name) return it
117+
}
118+
return null
119+
}
120+
121+
/**
122+
* @param homeCollection player home collection. Can
123+
* be taken with `takeAll` method.
124+
* @param name home name.
125+
*
126+
* @return true if home exist otherwise false.
127+
*
128+
* @see takeAll
129+
*
130+
* @since 1.14.4-1.2.0
131+
*/
132+
fun contains(
133+
homeCollection: List<HomeModel.Home>,
134+
name: String
135+
): Boolean {
136+
homeCollection.forEach {
137+
if (it.home == name) return true
138+
}
139+
return false
140+
}
141+
142+
/**
143+
* Saves user data to local storage, to json file.
144+
*/
145+
fun save() = StorageBase.saveUserData()
146+
147+
/**
148+
* Reloading configuration from local storage,
149+
* with saving if argument `withSaving` true.
150+
*
151+
* @param withSaving if true then configuration
152+
* will be saved before reloading. Default values
153+
* is true.
154+
*/
155+
fun reload(withSaving: Boolean = true) {
156+
if (withSaving) save()
157+
StorageBase.loadUserData()
158+
}
159+
}

0 commit comments

Comments
 (0)