Skip to content

Commit a7619a6

Browse files
v3.1.1
- Fixed a bug which caused problems with deleted/invalid particle effect IDs on Entities
1 parent 4b6b803 commit a7619a6

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ if (!isJitpack) {
2828
apply plugin: "net.minecraftforge.gradle.forge"
2929

3030
group "de.randombyte"
31-
version "3.1.0"
31+
version "3.1.1"
3232

3333
minecraft {
3434
version = "1.12.2-14.23.5.2768"
@@ -53,7 +53,7 @@ dependencies {
5353
kapt "org.spongepowered:spongeapi:7.0.0"
5454
shadow("com.github.randombyte-developer.kosp:kosp:v2.2.3") { transitive = false }
5555
shadow "org.bstats:bstats-sponge:1.2"
56-
compile files("libs/Pixelmon-1.12.2-7.0.1-server.jar")
56+
compile files("libs/Pixelmon-1.12.2-7.0.3.jar")
5757
}
5858

5959
shadowJar {

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

+22-8
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class EntityParticles @Inject constructor(
6969
internal companion object {
7070
const val ID = "entity-particles"
7171
const val NAME = "EntityParticles"
72-
const val VERSION = "3.1.0"
72+
const val VERSION = "3.1.1"
7373
const val AUTHOR = "RandomByte"
7474

7575
const val ROOT_PERMISSION = ID
@@ -79,6 +79,9 @@ class EntityParticles @Inject constructor(
7979

8080
const val PIXELMON_ID = "pixelmon"
8181
const val PIXELMON_PARTICLE_TAG_KEY = "$ID:particle"
82+
83+
private val _INSTANCE = lazy { Sponge.getPluginManager().getPlugin(EntityParticles.ID).get().instance.get() as EntityParticles }
84+
val INSTANCE: EntityParticles get() = _INSTANCE.value
8285
}
8386

8487
private val configManager = ConfigManager(
@@ -141,16 +144,21 @@ class EntityParticles @Inject constructor(
141144
fun onLoadEntity(event: SpawnEntityEvent) {
142145
event.entities
143146
.filter { it.particleId != null }
144-
.forEach {
145-
val worldUuid = it.location.extent.uniqueId
146-
val entities = trackedEntities.getOrPut(worldUuid) { mutableMapOf() }
147-
entities += it.uniqueId to it.particleId!!
148-
}
147+
.forEach { addTrackedEntity(it) }
149148
}
150149

151150
@Listener
152151
fun onUnloadEntity(event: DestructEntityEvent) {
153-
trackedEntities[event.targetEntity.location.extent.uniqueId]?.remove(event.targetEntity.uniqueId)
152+
removeTrackedEntity(event.targetEntity)
153+
}
154+
155+
fun addTrackedEntity(entity: Entity) {
156+
val trackedEntities = trackedEntities.getOrPut(entity.location.extent.uniqueId) { mutableMapOf() }
157+
trackedEntities += entity.uniqueId to entity.particleId!!
158+
}
159+
160+
fun removeTrackedEntity(entity: Entity) {
161+
trackedEntities[entity.location.extent.uniqueId]?.remove(entity.uniqueId)
154162
}
155163

156164
private fun loadConfig() {
@@ -260,7 +268,13 @@ class EntityParticles @Inject constructor(
260268
entity to id
261269
}
262270
.forEach entityLoop@ { (entity, id) ->
263-
val particleConfig = config.particles.getValue(id)
271+
val particleConfig = config.particles[id]
272+
if (particleConfig == null) {
273+
entity.particleId = null
274+
removeTrackedEntity(entity)
275+
276+
return@entityLoop
277+
}
264278
particleConfig.effects.forEach { effect ->
265279
val doEffectThisTick = Sponge.getServer().runningTimeTicks % effect.interval == 0
266280
if (doEffectThisTick) {

src/main/kotlin/de/randombyte/entityparticles/commands/SetParticleCommand.kt

+2-5
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,11 @@ internal class SetParticleCommand(
3434
val entity = (world.getEntity(entityUuidString.toUUID()).orNull()
3535
?: throw CommandException("Entity '$entityUuidString' in world '$world' is not available!".toText()))
3636

37-
val entityParticles = Sponge.getPluginManager().getPlugin(EntityParticles.ID).get().instance.get() as EntityParticles
38-
val trackedEntities = entityParticles.trackedEntities.getOrPut(entity.location.extent.uniqueId) { mutableMapOf() }
39-
4037
if (particleId == "nothing") {
4138
entity.particleId = null
4239
entity.offer(Keys.GLOWING, false)
4340

44-
trackedEntities -= (entity.uniqueId)
41+
EntityParticles.INSTANCE.removeTrackedEntity(entity)
4542

4643
return CommandResult.success()
4744
}
@@ -55,7 +52,7 @@ internal class SetParticleCommand(
5552
entity.offer(Keys.GLOWING, true)
5653
}
5754

58-
trackedEntities += entity.uniqueId to particleId
55+
EntityParticles.INSTANCE.addTrackedEntity(entity)
5956

6057
return CommandResult.success()
6158
}

0 commit comments

Comments
 (0)