Skip to content

Commit dca9aa0

Browse files
Updated kosp and kotlin
1 parent f2505bd commit dca9aa0

File tree

4 files changed

+24
-41
lines changed

4 files changed

+24
-41
lines changed

build.gradle

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
plugins {
22
id "maven"
3-
id "org.jetbrains.kotlin.jvm" version "1.2.41"
4-
id "org.jetbrains.kotlin.kapt" version "1.2.41"
5-
id "com.github.johnrengelman.shadow" version "1.2.4"
3+
id "org.jetbrains.kotlin.jvm" version "1.2.51"
4+
id "org.jetbrains.kotlin.kapt" version "1.2.51"
5+
id "com.github.johnrengelman.shadow" version "2.0.4"
66
id "flavor.pie.promptsign" version "1.0.2" apply false
77
}
88

@@ -28,11 +28,10 @@ configurations {
2828
}
2929

3030
dependencies {
31-
shadow "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.41"
31+
shadow "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.51"
3232
kapt "org.spongepowered:spongeapi:7.0.0"
33-
shadow("com.github.randombyte-developer.kosp:kosp:v1.9.2") { transitive = false }
33+
shadow("com.github.randombyte-developer.kosp:kosp:v2.2.3") { transitive = false }
3434
shadow "org.bstats:bstats-sponge:1.2"
35-
compile "com.github.randombyte-developer:byte-items:v2.2"
3635
}
3736

3837
shadowJar {

src/main/kotlin/de/randombyte/entityparticles/Config.kt

+12-11
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package de.randombyte.entityparticles
33
import com.flowpowered.math.vector.Vector3d
44
import com.flowpowered.math.vector.Vector3i
55
import de.randombyte.entityparticles.Config.Particle.Effect
6+
import de.randombyte.kosp.extensions.deserialize
67
import de.randombyte.kosp.extensions.red
7-
import de.randombyte.kosp.extensions.toText
8+
import de.randombyte.kosp.extensions.serialize
9+
import de.randombyte.kosp.extensions.tryAsByteItem
810
import ninja.leaping.configurate.objectmapping.Setting
911
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable
1012
import org.spongepowered.api.data.key.Keys
@@ -15,7 +17,6 @@ import org.spongepowered.api.entity.EntityTypes
1517
import org.spongepowered.api.item.enchantment.Enchantment
1618
import org.spongepowered.api.item.enchantment.EnchantmentTypes
1719
import org.spongepowered.api.item.inventory.ItemStack
18-
import org.spongepowered.api.text.Text
1920

2021
@ConfigSerializable
2122
internal data class Config(
@@ -26,8 +27,8 @@ internal data class Config(
2627
@ConfigSerializable
2728
internal data class Particle(
2829
@Setting("item") val item: String = "",
29-
@Setting("display-name") val displayName: Text = Text.EMPTY,
30-
@Setting("item-description") val itemDescription: Text = Text.EMPTY,
30+
@Setting("display-name") val displayName: String = "",
31+
@Setting("item-description") val itemDescription: String = "",
3132
@Setting("item-enchanted") val itemEnchanted: Boolean = false,
3233
@Setting("glowing") val glowing: Boolean = false,
3334
@Setting("effects") val effects: List<Effect> = emptyList()
@@ -44,32 +45,32 @@ internal data class Config(
4445
)
4546

4647
fun createItemStack() = ItemStack.builder()
47-
.fromSnapshot(resolveByteItems(item))
48+
.fromSnapshot(item.tryAsByteItem())
4849
.quantity(1) // force single item
4950
.apply {
5051
if (itemEnchanted) {
5152
add(Keys.ITEM_ENCHANTMENTS, listOf(Enchantment.of(EnchantmentTypes.LUCK_OF_THE_SEA, 0)))
5253
add(Keys.HIDE_ENCHANTMENTS, true)
5354
}
5455
}
55-
.add(Keys.DISPLAY_NAME, displayName)
56-
.add(Keys.ITEM_LORE, listOf(itemDescription))
56+
.add(Keys.DISPLAY_NAME, displayName.deserialize())
57+
.add(Keys.ITEM_LORE, listOf(itemDescription.deserialize()))
5758
.build()
5859
}
5960

6061
constructor() : this(
6162
blockedEntities = listOf(EntityTypes.PLAYER),
6263
removerItem = Particle(
6364
item = "minecraft:bone",
64-
displayName = "Particles remover".toText(),
65-
itemDescription = Text.EMPTY,
65+
displayName = "Particles remover",
66+
itemDescription = "",
6667
itemEnchanted = true
6768
),
6869
particles = mapOf(
6970
"love" to Particle(
7071
item = "minecraft:blaze_rod",
71-
displayName = "Love".red(),
72-
itemDescription = "Right click an entity to apply this effect".toText(),
72+
displayName = "Love".red().serialize(),
73+
itemDescription = "Right click an entity to apply this effect",
7374
itemEnchanted = true,
7475
glowing = false,
7576
effects = listOf(Effect(

src/main/kotlin/de/randombyte/entityparticles/EntityParticles.kt

+6-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import de.randombyte.entityparticles.data.EntityParticlesKeys.PARTICLE_ID
1414
import de.randombyte.entityparticles.data.ParticleData
1515
import de.randombyte.entityparticles.data.RemoverItemData
1616
import de.randombyte.kosp.config.ConfigManager
17-
import de.randombyte.kosp.executeAsConsole
17+
import de.randombyte.kosp.extensions.executeAsConsole
1818
import de.randombyte.kosp.extensions.orNull
1919
import de.randombyte.kosp.extensions.red
2020
import de.randombyte.kosp.extensions.toText
@@ -79,9 +79,8 @@ class EntityParticles @Inject constructor(
7979

8080
private val configManager = ConfigManager(
8181
configLoader = configLoader,
82-
clazz = Config::class.java,
83-
simpleTextSerialization = true,
84-
simpleTextTemplateSerialization = true)
82+
clazz = Config::class.java
83+
)
8584

8685
private lateinit var config: Config
8786

@@ -151,7 +150,7 @@ class EntityParticles @Inject constructor(
151150
}
152151

153152
private fun loadConfig() {
154-
config = configManager.get()
153+
config = configManager.load()
155154
saveConfig() // generate config
156155
}
157156

@@ -170,12 +169,12 @@ class EntityParticles @Inject constructor(
170169
when {
171170
particleId != null -> {
172171
player.setItemInHand(HandTypes.MAIN_HAND, itemInHand.setAmount(itemInHand.quantity - 1))
173-
executeAsConsole("entityParticles set ${targetEntity.location.extent.uniqueId} ${targetEntity.uniqueId} $particleId")
172+
("entityParticles set ${targetEntity.location.extent.uniqueId} ${targetEntity.uniqueId} $particleId").executeAsConsole()
174173
}
175174
isRemover -> {
176175
if (!targetEntity.get(EntityParticlesKeys.PARTICLE_ID).isPresent) return
177176
player.setItemInHand(HandTypes.MAIN_HAND, itemInHand.setAmount(itemInHand.quantity - 1))
178-
executeAsConsole("entityParticles set ${targetEntity.location.extent.uniqueId} ${targetEntity.uniqueId} nothing")
177+
("entityParticles set ${targetEntity.location.extent.uniqueId} ${targetEntity.uniqueId} nothing").executeAsConsole()
179178
}
180179
else -> return // nothing, no EntityParticle item, prevent cancelling the event
181180
}
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
package de.randombyte.entityparticles
22

3-
import de.randombyte.byteitems.ByteItemsApi
4-
import de.randombyte.kosp.getServiceOrFail
5-
import org.spongepowered.api.Sponge
6-
import org.spongepowered.api.item.ItemType
73
import org.spongepowered.api.item.inventory.ItemStack
8-
import org.spongepowered.api.item.inventory.ItemStackSnapshot
94

10-
internal fun ItemStack.singleCopy() = copy().apply { quantity = 1 }
11-
12-
internal fun resolveByteItems(item: String): ItemStackSnapshot? {
13-
return if (Sponge.getPluginManager().getPlugin("byte-items").isPresent) {
14-
getServiceOrFail(ByteItemsApi::class).getItemSafely(item)
15-
} else {
16-
val itemType = Sponge.getRegistry().getType(ItemType::class.java, item).orElseThrow {
17-
IllegalArgumentException("Couldn't find ItemType '$item'!")
18-
}
19-
ItemStack.of(itemType, 1).createSnapshot()
20-
}
21-
}
5+
internal fun ItemStack.singleCopy() = copy().apply { quantity = 1 }

0 commit comments

Comments
 (0)