Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt
#	eco-core/core-plugin/src/main/resources/config.yml
  • Loading branch information
0ft3n committed Jul 30, 2023
2 parents d3c831c + 22d9dbd commit 620e1d3
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ open class EcoConfig(
private val values = ConcurrentHashMap<String, Any?>()

@Transient
var injections = ConcurrentHashMap<String, InjectablePlaceholder>()
private val injections = mutableMapOf<String, InjectablePlaceholder>()

fun init(values: Map<String, Any?>) {
@Transient
private var injectionHash = 0

fun init(values: Map<String, Any?>, injections: Map<String, InjectablePlaceholder>) {
this.values.clear()
this.values.putAll(values.normalizeToConfig(this.type))

this.addInjectablePlaceholder(injections.values)
}

override fun toPlaintext(): String {
Expand Down Expand Up @@ -179,6 +184,7 @@ open class EcoConfig(
override fun addInjectablePlaceholder(placeholders: Iterable<InjectablePlaceholder>) {
for (placeholder in placeholders) {
injections[placeholder.pattern.pattern()] = placeholder
injectionHash = injectionHash xor placeholder.hashCode()
}
}

Expand All @@ -188,6 +194,7 @@ open class EcoConfig(

override fun clearInjectedPlaceholders() {
injections.clear()
injectionHash = 0 // Reset the hash
}

override fun toMap(): MutableMap<String, Any?> {
Expand Down Expand Up @@ -239,18 +246,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class EcoConfigSection(
injections: Map<String, InjectablePlaceholder> = emptyMap()
) : EcoConfig(type) {
init {
this.init(values)
this.injections = ConcurrentHashMap(injections)
this.init(values, injections)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
override fun loadListeners(): List<Listener> {
val listeners = mutableListOf(
ArmorListener(),
EntityDeathByEntityListeners(this),
EntityDeathByEntityListeners,
CraftingRecipeListener(this),
StackedRecipeListener(this),
GUIListener(this),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
)
)
}
}

This file was deleted.

7 changes: 6 additions & 1 deletion eco-core/core-plugin/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ math-cache-ttl: 200
# 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

# If eco should make sure its recipes are not affected by other plugins on PrepareCraftItemEvent
# Turn this on if you use ItemsAdder/Oraxen/Other 3d party plugins custom items in eco recipes
# And having issues with the item being invisible when you are trying to craft ir.
enforce-preparing-recipes: false
enforce-preparing-recipes: false
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version = 6.65.1
version = 6.65.3
plugin-name = eco
kotlin.code.style = official

0 comments on commit 620e1d3

Please sign in to comment.