From 7e5e5162c3eaf8c0b8104ff0eb19314d931a0c52 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 18 Jun 2023 22:03:48 +0200 Subject: [PATCH 1/9] LazyPlaceholderTranslationExpressionHandler now uses a regular map rather than a caffeine cache --- .../eco/internal/spigot/math/ExpressionHandlers.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/math/ExpressionHandlers.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/math/ExpressionHandlers.kt index 6f26c5ee0..a5241aab9 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/math/ExpressionHandlers.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/math/ExpressionHandlers.kt @@ -94,8 +94,7 @@ class ImmediatePlaceholderTranslationExpressionHandler( class LazyPlaceholderTranslationExpressionHandler( private val placeholderParser: PlaceholderParser ) : ExpressionHandler { - private val cache: Cache = Caffeine.newBuilder() - .build() + private val cache = mutableMapOf() override fun evaluate(expression: String, context: PlaceholderContext): Double? { val placeholders = PlaceholderManager.findPlaceholdersIn(expression) @@ -104,10 +103,11 @@ class LazyPlaceholderTranslationExpressionHandler( .map { it.fastToDoubleOrNull() ?: 0.0 } .toDoubleArray() - val compiled = cache.get(expression) { - val env = EvaluationEnvironment() - env.setVariableNames(*placeholders.toTypedArray()) - env.addFunctions(min, max) + val compiled = cache.getOrPut(expression) { + val env = EvaluationEnvironment().apply { + setVariableNames(*placeholders.toTypedArray()) + addFunctions(min, max) + } runCatching { Crunch.compileExpression(expression, env) }.getOrNull() } From 739d9cfffb38c3f771af3dc2a140ae49bb17acf1 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 6 Jul 2023 17:35:52 +0100 Subject: [PATCH 2/9] Optimised Config#getDoubleFromExpression for constant values --- .../java/com/willfp/eco/core/config/interfaces/Config.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/eco-api/src/main/java/com/willfp/eco/core/config/interfaces/Config.java b/eco-api/src/main/java/com/willfp/eco/core/config/interfaces/Config.java index bc32f8aad..8fc897485 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/config/interfaces/Config.java +++ b/eco-api/src/main/java/com/willfp/eco/core/config/interfaces/Config.java @@ -597,7 +597,10 @@ default double getDoubleFromExpression(@NotNull String path, */ default double getDoubleFromExpression(@NotNull String path, @NotNull PlaceholderContext context) { - return NumberUtils.evaluateExpression(this.getString(path), context.withInjectableContext(this)); + return Objects.requireNonNullElseGet( + getDoubleOrNull(path), + () -> NumberUtils.evaluateExpression(this.getString(path), context.withInjectableContext(this)) + ); } /** From 134859fea0f663a51e932a19840d1bf842d0ab59 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 13 Jul 2023 15:16:23 +0100 Subject: [PATCH 3/9] Extremely obvious optimisation to expression parsing --- .../java/com/willfp/eco/core/config/interfaces/Config.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/eco-api/src/main/java/com/willfp/eco/core/config/interfaces/Config.java b/eco-api/src/main/java/com/willfp/eco/core/config/interfaces/Config.java index bc32f8aad..1fe348f94 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/config/interfaces/Config.java +++ b/eco-api/src/main/java/com/willfp/eco/core/config/interfaces/Config.java @@ -597,7 +597,10 @@ default double getDoubleFromExpression(@NotNull String path, */ default double getDoubleFromExpression(@NotNull String path, @NotNull PlaceholderContext context) { - return NumberUtils.evaluateExpression(this.getString(path), context.withInjectableContext(this)); + return Objects.requireNonNullElseGet( + this.getDoubleOrNull(path), + () -> NumberUtils.evaluateExpression(this.getString(path), context.withInjectableContext(this)) + ); } /** From f1bef380463f513efb870294b3932b8ed1db2211 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 16 Jul 2023 13:03:50 +0100 Subject: [PATCH 4/9] Updated to 6.65.2 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 6bb34fd06..1a65f0b11 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ -version = 6.65.1 +version = 6.65.2 plugin-name = eco kotlin.code.style = official \ No newline at end of file From 27da03e8db19e44a6f22893d10d290af80a13cc7 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 20 Jul 2023 12:19:10 +0100 Subject: [PATCH 5/9] Optimised config hashing --- .../willfp/eco/internal/config/EcoConfig.kt | 22 +++++++------------ .../eco/internal/config/EcoConfigSection.kt | 3 +-- .../eco/internal/config/EcoLoadableConfig.kt | 2 +- .../eco/internal/config/EcoUpdatableConfig.kt | 2 +- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoConfig.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoConfig.kt index 520329652..1ec4de74a 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoConfig.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoConfig.kt @@ -16,11 +16,16 @@ open class EcoConfig( private val values = ConcurrentHashMap() @Transient - var injections = ConcurrentHashMap() + private val injections = mutableMapOf() - fun init(values: Map) { + @Transient + private var injectionHash = 0 + + fun init(values: Map, injections: Map) { this.values.clear() this.values.putAll(values.normalizeToConfig(this.type)) + + this.addInjectablePlaceholder(injections.values) } override fun toPlaintext(): String { @@ -179,6 +184,7 @@ open class EcoConfig( override fun addInjectablePlaceholder(placeholders: Iterable) { for (placeholder in placeholders) { injections[placeholder.pattern.pattern()] = placeholder + injectionHash = injectionHash xor placeholder.hashCode() } } @@ -239,18 +245,6 @@ open class EcoConfig( } override fun hashCode(): Int { - /* - The keys are completely redundant, as they are only used to prevent - duplicate keys in the map. Therefore, we can ignore them and just - hash the actual placeholder values. - */ - - var injectionHash = 0 - - injections.forEachValue(5) { - injectionHash = injectionHash xor (it.hashCode() shl 5) - } - // hashCode() has to compute extremely quickly, so we're using bitwise, because why not? // Fucking filthy to use identityHashCode here, but it should be extremely fast val identityHash = System.identityHashCode(this) diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoConfigSection.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoConfigSection.kt index e0b4c76fe..f6c24e193 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoConfigSection.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoConfigSection.kt @@ -10,7 +10,6 @@ class EcoConfigSection( injections: Map = emptyMap() ) : EcoConfig(type) { init { - this.init(values) - this.injections = ConcurrentHashMap(injections) + this.init(values, injections) } } diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoLoadableConfig.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoLoadableConfig.kt index 9809e7ae5..eabe3e614 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoLoadableConfig.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoLoadableConfig.kt @@ -91,7 +91,7 @@ open class EcoLoadableConfig( protected fun init(reader: Reader) { val string = reader.readToString() makeHeader(string) - super.init(type.toMap(string)) + super.init(type.toMap(string), emptyMap()) } fun init(file: File) { diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoUpdatableConfig.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoUpdatableConfig.kt index 463632a5e..d31c45733 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoUpdatableConfig.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoUpdatableConfig.kt @@ -50,7 +50,7 @@ open class EcoUpdatableConfig( val reader = BufferedReader(InputStreamReader(newIn, StandardCharsets.UTF_8)) val config = EcoConfigSection(type, emptyMap()) - config.init(type.toMap(reader.readToString())) + config.init(type.toMap(reader.readToString()), emptyMap()) return config } From 7ff578f89b83030f1b6c0c6be84935104950eb82 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 20 Jul 2023 12:36:41 +0100 Subject: [PATCH 6/9] Fixed clearInjectedPlaceholders --- .../src/main/kotlin/com/willfp/eco/internal/config/EcoConfig.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoConfig.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoConfig.kt index 1ec4de74a..2e163f66d 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoConfig.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoConfig.kt @@ -194,6 +194,7 @@ open class EcoConfig( override fun clearInjectedPlaceholders() { injections.clear() + injectionHash = 0 // Reset the hash } override fun toMap(): MutableMap { From ff61527939e534d286774c4a9c47a547575124ac Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 20 Jul 2023 13:01:19 +0100 Subject: [PATCH 7/9] Updated to 6.65.3 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 1a65f0b11..1ca27dc8e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ -version = 6.65.2 +version = 6.65.3 plugin-name = eco kotlin.code.style = official \ No newline at end of file From 5cfb87e03cb3fccac92b56fcd752f74990693d56 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 22 Jul 2023 14:16:34 +0100 Subject: [PATCH 8/9] Reworked EntityDamageByEntityEvent, finally --- .../eco/internal/spigot/EcoSpigotPlugin.kt | 4 +- .../EntityDeathByEntityBuilder.kt | 21 ------ .../EntityDeathByEntityListener.kt | 27 ++++++++ .../EntityDeathByEntityListeners.kt | 64 ------------------- 4 files changed, 29 insertions(+), 87 deletions(-) delete mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/eventlisteners/EntityDeathByEntityBuilder.kt create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/eventlisteners/EntityDeathByEntityListener.kt delete mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/eventlisteners/EntityDeathByEntityListeners.kt diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt index 3dd1ef794..e7acda280 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt @@ -62,7 +62,7 @@ import com.willfp.eco.internal.spigot.data.PlayerBlockListener import com.willfp.eco.internal.spigot.data.ProfileHandler import com.willfp.eco.internal.spigot.data.storage.ProfileSaver import com.willfp.eco.internal.spigot.drops.CollatedRunnable -import com.willfp.eco.internal.spigot.eventlisteners.EntityDeathByEntityListeners +import com.willfp.eco.internal.spigot.eventlisteners.EntityDeathByEntityListener import com.willfp.eco.internal.spigot.eventlisteners.NaturalExpGainListenersPaper import com.willfp.eco.internal.spigot.eventlisteners.NaturalExpGainListenersSpigot import com.willfp.eco.internal.spigot.eventlisteners.PlayerJumpListenersPaper @@ -389,7 +389,7 @@ abstract class EcoSpigotPlugin : EcoPlugin() { override fun loadListeners(): List { val listeners = mutableListOf( ArmorListener(), - EntityDeathByEntityListeners(this), + EntityDeathByEntityListener, CraftingRecipeListener(), StackedRecipeListener(this), GUIListener(this), diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/eventlisteners/EntityDeathByEntityBuilder.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/eventlisteners/EntityDeathByEntityBuilder.kt deleted file mode 100644 index 7d5640254..000000000 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/eventlisteners/EntityDeathByEntityBuilder.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.willfp.eco.internal.spigot.eventlisteners - -import com.willfp.eco.core.events.EntityDeathByEntityEvent -import org.bukkit.Bukkit -import org.bukkit.entity.Entity -import org.bukkit.entity.LivingEntity -import org.bukkit.event.entity.EntityDeathEvent -import org.bukkit.inventory.ItemStack - -internal class EntityDeathByEntityBuilder { - var victim: LivingEntity? = null - var damager: Entity? = null - var deathEvent: EntityDeathEvent? = null - var drops: List? = null - var xp = 0 - - fun push() { - val event = EntityDeathByEntityEvent(victim!!, damager!!, drops!!, xp, deathEvent!!) - Bukkit.getPluginManager().callEvent(event) - } -} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/eventlisteners/EntityDeathByEntityListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/eventlisteners/EntityDeathByEntityListener.kt new file mode 100644 index 000000000..0d6289992 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/eventlisteners/EntityDeathByEntityListener.kt @@ -0,0 +1,27 @@ +package com.willfp.eco.internal.spigot.eventlisteners + +import com.willfp.eco.core.events.EntityDeathByEntityEvent +import org.bukkit.Bukkit +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageByEntityEvent +import org.bukkit.event.entity.EntityDeathEvent + +object EntityDeathByEntityListener: Listener { + @EventHandler(priority = EventPriority.HIGH) + fun onEntityDeath(event: EntityDeathEvent) { + val damageEvent = event.entity.lastDamageCause as? EntityDamageByEntityEvent ?: return + val killer = damageEvent.damager + + Bukkit.getPluginManager().callEvent( + EntityDeathByEntityEvent( + event.entity, + killer, + event.drops, + event.droppedExp, + event + ) + ) + } +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/eventlisteners/EntityDeathByEntityListeners.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/eventlisteners/EntityDeathByEntityListeners.kt deleted file mode 100644 index a1e9b6bcd..000000000 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/eventlisteners/EntityDeathByEntityListeners.kt +++ /dev/null @@ -1,64 +0,0 @@ -package com.willfp.eco.internal.spigot.eventlisteners - -import com.willfp.eco.core.EcoPlugin -import org.bukkit.entity.LivingEntity -import org.bukkit.event.EventHandler -import org.bukkit.event.EventPriority -import org.bukkit.event.Listener -import org.bukkit.event.entity.EntityDamageByEntityEvent -import org.bukkit.event.entity.EntityDeathEvent - -class EntityDeathByEntityListeners( - private val plugin: EcoPlugin -) : Listener { - private val events = mutableSetOf() - - @EventHandler(priority = EventPriority.HIGH) - fun onEntityDamage(event: EntityDamageByEntityEvent) { - if ((event.entity !is LivingEntity)) { - return - } - - val victim = event.entity as LivingEntity - - if (victim.health > event.finalDamage) { - return - } - - val builtEvent = EntityDeathByEntityBuilder() - builtEvent.victim = victim - builtEvent.damager = event.damager - - events += builtEvent - - this.plugin.scheduler.runLater(5) { // Fixes conflicts with WildStacker - events.remove(builtEvent) - } - } - - @EventHandler(priority = EventPriority.HIGH) - fun onEntityDeath(event: EntityDeathEvent) { - val victim = event.entity - val drops = event.drops - val xp = event.droppedExp - - var builtEvent: EntityDeathByEntityBuilder? = null - - for (builder in events) { - if (builder.victim == victim) { - builtEvent = builder - } - } - - if (builtEvent == null) { - return - } - - events.remove(builtEvent) - builtEvent.drops = drops - builtEvent.xp = xp - builtEvent.deathEvent = event - - builtEvent.push() - } -} From 22d9dbdf66f9d3d59f0327c2040095b1c819c63d Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 22 Jul 2023 16:13:31 +0100 Subject: [PATCH 9/9] Added display-without-meta option --- .../src/main/java/com/willfp/eco/core/display/Display.java | 7 +++++-- eco-core/core-plugin/src/main/resources/config.yml | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/eco-api/src/main/java/com/willfp/eco/core/display/Display.java b/eco-api/src/main/java/com/willfp/eco/core/display/Display.java index 2b6230c79..a6d2feb69 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/display/Display.java +++ b/eco-api/src/main/java/com/willfp/eco/core/display/Display.java @@ -1,5 +1,6 @@ package com.willfp.eco.core.display; +import com.willfp.eco.core.Eco; import com.willfp.eco.core.fast.FastItemStack; import com.willfp.eco.core.integrations.guidetection.GUIDetectionManager; import com.willfp.eco.util.NamespacedKeyUtils; @@ -68,8 +69,10 @@ public static ItemStack display(@NotNull final ItemStack itemStack, Display.revert(itemStack); - if (!itemStack.hasItemMeta()) { - return itemStack; + if (!Eco.get().getEcoPlugin().getConfigYml().getBool("display-without-meta")) { + if (!itemStack.hasItemMeta()) { + return itemStack; + } } ItemStack original = itemStack.clone(); diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index 716ad9888..9ddf34918 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -97,3 +97,8 @@ math-cache-ttl: 200 # counts. This is completely anonymous and no personal information is logged. This data # is primarily used for optimisation and server insights. playerflow: true + +# If the packet display system should activate on items that have no meta. This is disabled +# by default for performance reasons, but if you want to use the packet display system on +# items that have no meta, then you can enable this option. +display-without-meta: false \ No newline at end of file