Skip to content

Commit

Permalink
Changes synced with 1.14.4 branch.
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Erokhin (MairwunNx) <MairwunNx@gmail.com>
  • Loading branch information
MairwunNx committed Mar 17, 2020
1 parent 773bbd7 commit 05cf285
Show file tree
Hide file tree
Showing 14 changed files with 393 additions and 133 deletions.
104 changes: 84 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,25 @@ buildscript {
classpath(
"org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
)
classpath(
"org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
)
}
}

plugins {
id "maven-publish"
id "java-library"
id "maven"
}

apply(plugin: "org.jetbrains.dokka")
apply(plugin: "net.minecraftforge.gradle")
apply(plugin: "kotlin")
apply(plugin: "kotlinx-serialization")

String packagesToken = new String(package_public_token.decodeBase64())

version = module_version
group = "com.mairwunnx.$module_id"
archivesBaseName = module_name
Expand Down Expand Up @@ -68,41 +80,61 @@ minecraft {
repositories {
jcenter()
mavenCentral()
maven { url("https://minecraft.curseforge.com/api/maven/") }
maven { url("https://libraries.minecraft.net") }
maven { url("https://jitpack.io") }
maven { url "https://jitpack.io" }
maven {
name = "GitHubPackages"
url = uri "https://maven.pkg.github.com/projectessentials/projectessentials-core"
credentials {
username = "MairwunNx@gmail.com"
password = packagesToken
}
}
maven {
name = "GitHubPackages"
url = uri "https://maven.pkg.github.com/projectessentials/projectessentials-permissions"
credentials {
username = "MairwunNx@gmail.com"
password = packagesToken
}
}
maven {
name = "GitHubPackages"
url = uri "https://maven.pkg.github.com/ProjectEssentials/ProjectEssentials-Cooldown"
credentials {
username = "MairwunNx@gmail.com"
password = packagesToken
}
}
}

dependencies {
minecraft(group: "net.minecraftforge", name: "forge", version: forge_version)
compile(group: "com.mojang", name: "brigadier", version: brigadier_version)
compile(

implementation 'com.mairwunnx.project_essentials_core:ProjectEssentials-Core:1.15.2-1.1.0'
implementation 'com.mairwunnx.project_essentials_permissions:ProjectEssentials-Permissions:1.15.2-1.0.1'
implementation 'com.mairwunnx.project_essentials_cooldown:ProjectEssentials-Cooldown:1.15.2-1.0.1'

implementation(group: "com.mojang", name: "brigadier", version: brigadier_version)
implementation(
group: "org.jetbrains.kotlinx",
name: "kotlinx-serialization-runtime",
version: kotlinx_serialization_version
)
compile(
implementation(
group: "org.jetbrains.kotlin",
name: "kotlin-stdlib-$kotlin_jdk_version_target",
version: kotlin_version
)
compile(
group: "com.github.projectessentials",
name: "ProjectEssentials-Permissions",
version: ess_perm_version
)
compile(
group: "com.github.projectessentials",
name: "ProjectEssentials-Core",
version: ess_core_version
)
compile(
group: "com.github.projectessentials",
name: "ProjectEssentials-Cooldown",
version: ess_cooldown_version
)
}

dokka {
outputFormat = 'html'
outputDirectory = "$buildDir/libs/docs"
}

project.tasks["jar"].dependsOn(project.tasks["dokka"])

jar {
manifest {
attributes([
Expand All @@ -123,3 +155,35 @@ sourceCompatibility = targetCompatibility =

compileKotlin.kotlinOptions.jvmTarget =
compileTestKotlin.kotlinOptions.jvmTarget = project_jvm_version_target

task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}

task dokkaJar(type: Jar) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles Kotlin docs with Dokka"
classifier = "javadoc"
from tasks.dokka as Object
}

publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri "https://maven.pkg.github.com/projectessentials/projectessentials-home"
credentials {
username = System.getenv("GradleUser")
password = System.getenv("GradlePass")
}
}
}
publications {
gpr(MavenPublication) {
from components.java
artifact sourcesJar
artifact dokkaJar
}
}
}
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.15.2-1.1.0] - 2020-03-17

### Added

### Changed

### Removed

## [1.15.2-1.0.0] - 2020-02-08

### Added
Expand Down
11 changes: 5 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ forge_mappings_channel_version=20190719-1.14.3
brigadier_version=1.0.17
kotlin_jdk_version_target=jdk8
project_jvm_version_target=1.8
kotlin_version=1.3.61
kotlinx_serialization_version=0.14.0
ess_core_version=v1.15.2-1.+
ess_perm_version=v1.15.2-1.+
ess_cooldown_version=v1.15.2-1.+
module_version=1.15.2-1.0.0
kotlin_version=1.3.70
kotlinx_serialization_version=0.20.0
dokka_version=0.10.1
module_version=1.15.2-1.1.0
module_name=Project Essentials Home
module_id=project_essentials_home
module_vendor=MairwunNx (Pavel Erokhin)
package_public_token=ZDhjMjgyNjlhM2E0ZTQ0MmM2Mjk5ZWI4YmMyZjI0YzNjOTNkMDVkZA==
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Explore

#### [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)
#### [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)

### Compatibility

Expand Down
21 changes: 18 additions & 3 deletions src/main/kotlin/com/mairwunnx/projectessentials/home/EntryPoint.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.mairwunnx.projectessentials.home

import com.mairwunnx.projectessentials.core.EssBase
import com.mairwunnx.projectessentials.core.configuration.localization.LocalizationConfigurationUtils
import com.mairwunnx.projectessentials.core.localization.processLocalizations
import com.mairwunnx.projectessentials.home.commands.DelHomeCommand
import com.mairwunnx.projectessentials.home.commands.HomeCommand
import com.mairwunnx.projectessentials.home.commands.SetHomeCommand
Expand All @@ -18,16 +20,29 @@ import org.apache.logging.log4j.LogManager

@Suppress("unused")
@Mod("project_essentials_home")
class EntryPoint : EssBase() {
internal class EntryPoint : EssBase() {
private val logger = LogManager.getLogger()

init {
modInstance = this
modVersion = "1.15.2-1.0.0"
modVersion = "1.15.2-1.1.0"
logBaseInfo()
validateForgeVersion()
MinecraftForge.EVENT_BUS.register(this)
StorageBase.loadUserData()
loadLocalization()
}

private fun loadLocalization() {
if (LocalizationConfigurationUtils.getConfig().enabled) {
processLocalizations(
EntryPoint::class.java, listOf(
"/assets/projectessentialshome/lang/en_us.json",
"/assets/projectessentialshome/lang/ru_ru.json",
"/assets/projectessentialshome/lang/de_de.json"
)
)
}
}

@SubscribeEvent
Expand All @@ -47,7 +62,7 @@ class EntryPoint : EssBase() {
@Suppress("UNUSED_PARAMETER")
@SubscribeEvent
fun onServerStopping(it: FMLServerStoppingEvent) {
StorageBase.saveUserData()
HomeAPI.save()
}

private fun loadAdditionalModules() {
Expand Down
159 changes: 159 additions & 0 deletions src/main/kotlin/com/mairwunnx/projectessentials/home/HomeAPI.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package com.mairwunnx.projectessentials.home

import com.mairwunnx.projectessentials.home.models.HomeModel
import com.mairwunnx.projectessentials.home.storage.StorageBase
import net.minecraft.entity.player.ServerPlayerEntity

/**
* Home API base class. Contains all
* methods for interaction with player homes.
*
* @since 1.14.4-1.2.0
*/
object HomeAPI {
/**
* Create home for target player with specified name.
*
* @param owner ServerPlayerEntity class instance,
* target home owner.
* @param name new home name with default value `home`.
* @param override if true then if world existing with same
* name then it world will be replaced with new home record,
* default value is `false`.
*
* @return true if home creating successful otherwise false.
*
* @since 1.14.4-1.2.0
*/
fun create(
owner: ServerPlayerEntity,
name: String = "home",
override: Boolean = false
): Boolean {
val playerUUID = owner.uniqueID.toString()
val clientWorld = owner.commandSource.world.worldInfo.worldName
val worldId = owner.commandSource.world.worldType.id
val xPos = owner.positionVec.x.toInt()
val yPos = owner.positionVec.y.toInt()
val zPos = owner.positionVec.z.toInt()
val yaw = owner.rotationYaw
val pitch = owner.rotationPitch
val homes = takeAll(owner)

if (override) {
homes.removeAll {
it.home == name
}
} else {
if (contains(
homes,
name
)
) return false
}

homes.add(
HomeModel.Home(
name, clientWorld, worldId, xPos, yPos, zPos, yaw, pitch
)
)
StorageBase.setData(playerUUID, HomeModel(homes))
return true
}

/**
* Remove home for target player with specified name.
*
* @param owner ServerPlayerEntity class instance,
* target home owner.
* @param name home name to remove with default value `home`.
*
* @return true if home removing successful otherwise false.
*
* @since 1.14.4-1.2.0
*/
fun remove(
owner: ServerPlayerEntity,
name: String = "home"
): Boolean {
val playerUUID = owner.uniqueID.toString()
val homes = takeAll(owner)

take(owner, name)?.let {
homes.remove(it)
StorageBase.setData(playerUUID, HomeModel(homes))
return true
}
return false
}

/**
* @param owner ServerPlayerEntity class instance,
* target home owner.
*
* @return all player registered homes.
*
* @since 1.14.4-1.2.0
*/
fun takeAll(owner: ServerPlayerEntity): MutableList<HomeModel.Home> =
StorageBase.getData(owner.uniqueID.toString()).homes

/**
* @param owner ServerPlayerEntity class instance,
* target home owner.
* @param name home name with default value `home`.
*
* @return null if home not exist otherwise home instance.
*
* @since 1.14.4-1.2.0
*/
fun take(
owner: ServerPlayerEntity,
name: String = "home"
): HomeModel.Home? {
val homes = takeAll(owner)
homes.forEach {
if (it.home == name) return it
}
return null
}

/**
* @param homeCollection player home collection. Can
* be taken with `takeAll` method.
* @param name home name.
*
* @return true if home exist otherwise false.
*
* @see takeAll
*
* @since 1.14.4-1.2.0
*/
fun contains(
homeCollection: List<HomeModel.Home>,
name: String
): Boolean {
homeCollection.forEach {
if (it.home == name) return true
}
return false
}

/**
* Saves user data to local storage, to json file.
*/
fun save() = StorageBase.saveUserData()

/**
* Reloading configuration from local storage,
* with saving if argument `withSaving` true.
*
* @param withSaving if true then configuration
* will be saved before reloading. Default values
* is true.
*/
fun reload(withSaving: Boolean = true) {
if (withSaving) save()
StorageBase.loadUserData()
}
}
Loading

0 comments on commit 05cf285

Please sign in to comment.