Skip to content

Commit

Permalink
v1.3 - Fix inventory full not drop. Add support grief prevention, cus…
Browse files Browse the repository at this point in the history
…tom model data, configs yaml.
  • Loading branch information
adi-itgg committed May 15, 2022
1 parent edf54c2 commit c226cbe
Show file tree
Hide file tree
Showing 18 changed files with 1,046 additions and 738 deletions.
14 changes: 12 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
plugins {
id 'idea'
id 'org.jetbrains.kotlin.jvm' version '1.6.10'
id 'org.jetbrains.kotlin.jvm' version '1.6.21'
id 'org.jetbrains.kotlin.kapt' version '1.5.31'
id 'java'
id 'kr.entree.spigradle' version '2.3.4'
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.4.20'
}

group 'me.phantomx.fjetpackreloaded'
version '1.2'
version '1.3'

repositories {
mavenCentral()
Expand All @@ -23,6 +24,7 @@ repositories {
maven { url = 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url = 'https://oss.sonatype.org/content/repositories/central' }
maven { url 'https://hub.spigotmc.org/nexus/content/repositories/public/' }
maven { url 'https://jitpack.io' }
}

def urlFile = { url, name ->
Expand All @@ -41,11 +43,17 @@ def urlFile = { url, name ->
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0"
implementation "org.jetbrains.kotlin:kotlin-reflect:1.6.21"

implementation 'com.google.code.gson:gson:2.9.0'
implementation 'org.json:json:20211205'
implementation 'org.bstats:bstats-bukkit:3.0.0'

//implementation "com.charleskorn.kaml:kaml:0.43.0"
implementation "net.mamoe.yamlkt:yamlkt:0.11.0"

compileOnly 'com.github.TechFortress:GriefPrevention:16.18'

// Pick only one of these and read the comment in the repositories block.
compileOnly 'org.spigotmc:spigot-api:1.18.1-R0.1-SNAPSHOT' // The Spigot API with no shadowing. Requires the OSS repo.
//compileOnly 'org.spigotmc:spigot:1.18.2-R0.1-SNAPSHOT' // The full Spigot server with no shadowing. Requires mavenLocal.
Expand Down Expand Up @@ -74,6 +82,8 @@ spigot {
description = 'Lightweight, Fuel System and Customizable a Jetpack Plugin'
authors = ['PhantomX']
depends = []
softDepends = ['GriefPrevention']
libraries = ['org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0']
apiVersion = '1.13'
load = POSTWORLD //STARTUP
commands {
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/me/phantomx/fjetpackreloaded/FJetpackReloaded.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.bukkit.Material
import org.bukkit.inventory.ItemStack
import kotlin.coroutines.CoroutineContext


class FJetpackReloaded : FJRCommands() {

override val coroutineContext: CoroutineContext
Expand Down Expand Up @@ -64,8 +65,8 @@ class FJetpackReloaded : FJRCommands() {
return@launch
}
console.checkUpdatePlugin(loginEvent = false)
main {
server.pluginManager.registerEvents(EventListener(), plugin)
server.main {
pluginManager.registerEvents(EventListener(), plugin)
}
}
Metrics(this, id)
Expand All @@ -74,10 +75,9 @@ class FJetpackReloaded : FJRCommands() {
override fun onDisable() {
if (mainContext.isActive) mainContext.cancel(CancellationException("Plugin is disabled"))
val players = listPlayerUse.entries.iterator()
while (players.hasNext()) {
val player = players.next()
player.key.player.turnOff()
listPlayerUse.remove(player.key)
while (players.hasNext()) players.next().withSafe {
key.player.turnOff()
listPlayerUse.remove(key)
}
jetpacks.clear()
customFuel.clear()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.phantomx.fjetpackreloaded.abstracts

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import kotlinx.coroutines.Job
import me.phantomx.fjetpackreloaded.FJetpackReloaded
import me.phantomx.fjetpackreloaded.data.*
Expand All @@ -15,7 +16,7 @@ abstract class Plugin {
val mainContext: CoroutineContext = Job()
lateinit var plugin: FJetpackReloaded
val stringEmpty = StringBuilder().toString()
val gson = Gson()
val gson: Gson = GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create()

var nmsAPIVersion = "UNKNOWN"
var serverVersion = 0
Expand All @@ -39,6 +40,10 @@ abstract class Plugin {
val jetpackFuelPlaceholder = "{#fuel}"
val jetpackFuelValuePlaceholder = "{#fuel_value}"

val jetpacksYaml = "configs/Jetpacks.yml"
val customFuelsYaml = "configs/CustomFuels.yml"
val messagesYaml = "configs/Messages.yml"


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package me.phantomx.fjetpackreloaded.annotations

/**
* Don't modify value, like put 'field' or "field"
*/
@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY)
annotation class Pure
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class FJRCommands : JavaPlugin(), CoroutineScope, TabCompleter {
command: Command,
label: String,
args: Array<out String>
): Boolean = sender.run {
): Boolean = sender.safeRun {
if (!label.equals(idJetpack, ignoreCase = true) && label.lowercase() != "fjr") return false

var notContainsCmd = true
Expand All @@ -58,7 +58,7 @@ abstract class FJRCommands : JavaPlugin(), CoroutineScope, TabCompleter {
stream.use {
Scanner(it).use { s ->
while (s.hasNextLine())
s.nextLine().replace("#{version}", description.version).send(this, true)
s.nextLine().replace("#{version}", description.version).send(this)
}
}
} else
Expand Down Expand Up @@ -133,7 +133,7 @@ abstract class FJRCommands : JavaPlugin(), CoroutineScope, TabCompleter {
messages.noPerms.send(this)
return true
}
try {
withSafe {
if (args.size > 1)
Bukkit.getPlayerExact(args[1])?.let {
if (args.size > 2)
Expand All @@ -142,18 +142,16 @@ abstract class FJRCommands : JavaPlugin(), CoroutineScope, TabCompleter {
return true
}
} ?: also {
if (this !is Player) {
if (it !is Player) {
"&cYou can't run this command from Console!".send(this)
return true
}
jetpacks[args[1]]?.apply {
giveJetpack(this@run, this, if (args.size == 3) args[2].toLongSafe() else 1)
jetpacks[args[1]]?.withSafe {
giveJetpack(it, this, if (args.size == 3) args[2].toLongSafe() else 0)
return true
}
}

} catch (e: Exception) {
e.printStackTrace()
}
"&bUsage: &3/fjr get (Player) &b${jetpacks.keys}&3 <Fuel>".send(this)
return true
Expand Down Expand Up @@ -200,7 +198,7 @@ abstract class FJRCommands : JavaPlugin(), CoroutineScope, TabCompleter {
messages.noPerms.send(this)
return true
}
try {
withSafe {
if (args.size > 1)
Bukkit.getPlayerExact(args[1])?.let {
if (args.size > 2)
Expand All @@ -209,24 +207,21 @@ abstract class FJRCommands : JavaPlugin(), CoroutineScope, TabCompleter {
return true
}
} ?: also {
if (this !is Player) {
if (it !is Player) {
"&cYou can't run this command from Console!".send(this)
return true
}
customFuel[args[1]]?.apply {
giveCustomFuel(this@run, this, if (args.size == 3) args[2].toIntSafe(1) else 1)
giveCustomFuel(it, this, if (args.size == 3) args[2].toIntSafe(1) else 1)
return true
}
}
} catch (e: Exception) {
e.printStackTrace()
}
"&8&l- &3/fjr GetFuel (Player) &b${customFuel.keys} &3<Amount>".send(this)
return true
}

return false
}
false
} ?: false

override fun onTabComplete(
sender: CommandSender,
Expand Down
10 changes: 9 additions & 1 deletion src/main/kotlin/me/phantomx/fjetpackreloaded/data/Config.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package me.phantomx.fjetpackreloaded.data

import kotlinx.serialization.Serializable
import net.mamoe.yamlkt.Comment

@Serializable
data class Config(
@Comment("The configs version")
val version: Int = 1,
val updateNotification: Boolean = true
@Comment("Enable/Disable Update Notification")
val updateNotification: Boolean = true,
@Comment("Set all format configs to yaml")
val configsYaml: Boolean = true
)
36 changes: 29 additions & 7 deletions src/main/kotlin/me/phantomx/fjetpackreloaded/data/CustomFuel.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
package me.phantomx.fjetpackreloaded.data

import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import me.phantomx.fjetpackreloaded.annotations.Pure
import net.mamoe.yamlkt.Comment

@Serializable
data class CustomFuel(
var id: String,
var customDisplay: String,
var displayName: String,
var lore: List<String>,
var item: String,
var permission: String,
var glowing: Boolean
@Pure
@Transient
var id: String = "CVIP",
@Comment("""
Custom display name the fuel in jetpack placdeholder {#fuel}
Leave empty, will using DisplayName
""")
var customDisplay: String = "&6&lPertamax",
@Comment("Display Name item")
var displayName: String = "&b&lC&6&lVIP",
@Comment("The lore of item")
var lore: MutableList<String> = mutableListOf(
"",
"&eFuel for &l&6VIP!",
"",
"&6&lPremium &efuel"
),
@Comment("Item minecraft item id")
var item: String = "GOLD_INGOT",
@Comment("Permission to use this fuel")
var permission: String = "fjetpackreloaded.fuel.#id",
@Comment("Glow this item")
var glowing: Boolean = true
)
Loading

0 comments on commit c226cbe

Please sign in to comment.