@@ -69,7 +69,7 @@ class EntityParticles @Inject constructor(
69
69
internal companion object {
70
70
const val ID = " entity-particles"
71
71
const val NAME = " EntityParticles"
72
- const val VERSION = " 3.1.0 "
72
+ const val VERSION = " 3.1.1 "
73
73
const val AUTHOR = " RandomByte"
74
74
75
75
const val ROOT_PERMISSION = ID
@@ -79,6 +79,9 @@ class EntityParticles @Inject constructor(
79
79
80
80
const val PIXELMON_ID = " pixelmon"
81
81
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
82
85
}
83
86
84
87
private val configManager = ConfigManager (
@@ -141,16 +144,21 @@ class EntityParticles @Inject constructor(
141
144
fun onLoadEntity (event : SpawnEntityEvent ) {
142
145
event.entities
143
146
.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) }
149
148
}
150
149
151
150
@Listener
152
151
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)
154
162
}
155
163
156
164
private fun loadConfig () {
@@ -260,7 +268,13 @@ class EntityParticles @Inject constructor(
260
268
entity to id
261
269
}
262
270
.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
+ }
264
278
particleConfig.effects.forEach { effect ->
265
279
val doEffectThisTick = Sponge .getServer().runningTimeTicks % effect.interval == 0
266
280
if (doEffectThisTick) {
0 commit comments