Switched from DisplayPriority to weight
This commit is contained in:
@@ -14,7 +14,7 @@ public abstract class DisplayModule extends PluginDependent<EcoPlugin> {
|
|||||||
/**
|
/**
|
||||||
* The priority of the module.
|
* The priority of the module.
|
||||||
*/
|
*/
|
||||||
private final DisplayPriority priority;
|
private final int weight;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new display module.
|
* Create a new display module.
|
||||||
@@ -25,7 +25,19 @@ public abstract class DisplayModule extends PluginDependent<EcoPlugin> {
|
|||||||
protected DisplayModule(@NotNull final EcoPlugin plugin,
|
protected DisplayModule(@NotNull final EcoPlugin plugin,
|
||||||
@NotNull final DisplayPriority priority) {
|
@NotNull final DisplayPriority priority) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
this.priority = priority;
|
this.weight = priority.getWeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new display module.
|
||||||
|
*
|
||||||
|
* @param plugin The plugin that the display is for.
|
||||||
|
* @param weight The weight/priority of the module.
|
||||||
|
*/
|
||||||
|
protected DisplayModule(@NotNull final EcoPlugin plugin,
|
||||||
|
final int weight) {
|
||||||
|
super(plugin);
|
||||||
|
this.weight = weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,8 +96,25 @@ public abstract class DisplayModule extends PluginDependent<EcoPlugin> {
|
|||||||
* Get the display priority.
|
* Get the display priority.
|
||||||
*
|
*
|
||||||
* @return The priority.
|
* @return The priority.
|
||||||
|
* @deprecated Use getWeight instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(since = "6.35.0", forRemoval = true)
|
||||||
public DisplayPriority getPriority() {
|
public DisplayPriority getPriority() {
|
||||||
return this.priority;
|
return switch (this.weight) {
|
||||||
|
case 100 -> DisplayPriority.LOWEST;
|
||||||
|
case 200 -> DisplayPriority.LOW;
|
||||||
|
case 300 -> DisplayPriority.HIGH;
|
||||||
|
case 400 -> DisplayPriority.HIGHEST;
|
||||||
|
default -> DisplayPriority.CUSTOM;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the display weight.
|
||||||
|
*
|
||||||
|
* @return The weight.
|
||||||
|
*/
|
||||||
|
public int getWeight() {
|
||||||
|
return this.weight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,23 +4,51 @@ package com.willfp.eco.core.display;
|
|||||||
* The priority (order) of display modules.
|
* The priority (order) of display modules.
|
||||||
*/
|
*/
|
||||||
public enum DisplayPriority {
|
public enum DisplayPriority {
|
||||||
|
/**
|
||||||
|
* Custom weight.
|
||||||
|
*/
|
||||||
|
CUSTOM(250),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ran first.
|
* Ran first.
|
||||||
*/
|
*/
|
||||||
LOWEST,
|
LOWEST(100),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ran second.
|
* Ran second.
|
||||||
*/
|
*/
|
||||||
LOW,
|
LOW(200),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ran third.
|
* Ran third.
|
||||||
*/
|
*/
|
||||||
HIGH,
|
HIGH(300),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ran last.
|
* Ran last.
|
||||||
*/
|
*/
|
||||||
HIGHEST
|
HIGHEST(400);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The display priority weight.
|
||||||
|
*/
|
||||||
|
private final int weight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new display priority.
|
||||||
|
*
|
||||||
|
* @param weight The weight.
|
||||||
|
*/
|
||||||
|
DisplayPriority(final int weight) {
|
||||||
|
this.weight = weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the weight.
|
||||||
|
*
|
||||||
|
* @return The weight.
|
||||||
|
*/
|
||||||
|
public int getWeight() {
|
||||||
|
return weight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.willfp.eco.core.EcoPlugin
|
|||||||
import com.willfp.eco.core.display.Display
|
import com.willfp.eco.core.display.Display
|
||||||
import com.willfp.eco.core.display.DisplayHandler
|
import com.willfp.eco.core.display.DisplayHandler
|
||||||
import com.willfp.eco.core.display.DisplayModule
|
import com.willfp.eco.core.display.DisplayModule
|
||||||
import com.willfp.eco.core.display.DisplayPriority
|
|
||||||
import com.willfp.eco.core.fast.fast
|
import com.willfp.eco.core.fast.fast
|
||||||
import org.bukkit.NamespacedKey
|
import org.bukkit.NamespacedKey
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
@@ -12,42 +11,36 @@ import org.bukkit.inventory.ItemStack
|
|||||||
import org.bukkit.persistence.PersistentDataType
|
import org.bukkit.persistence.PersistentDataType
|
||||||
|
|
||||||
class EcoDisplayHandler(plugin: EcoPlugin) : DisplayHandler {
|
class EcoDisplayHandler(plugin: EcoPlugin) : DisplayHandler {
|
||||||
private val registeredModules = mutableMapOf<DisplayPriority, MutableList<DisplayModule>>()
|
private val registeredModules = sortedMapOf<Int, MutableList<DisplayModule>>()
|
||||||
private val finalizeKey: NamespacedKey = plugin.namespacedKeyFactory.create("finalized")
|
private val finalizeKey: NamespacedKey = plugin.namespacedKeyFactory.create("finalized")
|
||||||
|
|
||||||
init {
|
|
||||||
for (priority in DisplayPriority.values()) {
|
|
||||||
registeredModules[priority] = mutableListOf()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun registerDisplayModule(module: DisplayModule) {
|
override fun registerDisplayModule(module: DisplayModule) {
|
||||||
val modules = registeredModules[module.priority] ?: return
|
val modules = registeredModules[module.weight] ?: mutableListOf()
|
||||||
modules.removeIf { module1: DisplayModule ->
|
modules.removeIf {
|
||||||
module1.pluginName.equals(module.pluginName, ignoreCase = true)
|
it.pluginName.equals(module.pluginName, ignoreCase = true)
|
||||||
}
|
}
|
||||||
modules.add(module)
|
modules.add(module)
|
||||||
registeredModules[module.priority] = modules
|
registeredModules[module.weight] = modules
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun display(itemStack: ItemStack, player: Player?): ItemStack {
|
override fun display(itemStack: ItemStack, player: Player?): ItemStack {
|
||||||
val pluginVarArgs = mutableMapOf<String, Array<Any>>()
|
val pluginVarArgs = mutableMapOf<String, Array<Any>>()
|
||||||
|
|
||||||
for (priority in DisplayPriority.values()) {
|
for ((_, modules) in registeredModules) {
|
||||||
val modules = registeredModules[priority] ?: continue
|
|
||||||
for (module in modules) {
|
for (module in modules) {
|
||||||
pluginVarArgs[module.pluginName] = module.generateVarArgs(itemStack)
|
pluginVarArgs[module.pluginName] = module.generateVarArgs(itemStack)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Display.revert(itemStack)
|
Display.revert(itemStack)
|
||||||
|
|
||||||
if (!itemStack.hasItemMeta()) {
|
if (!itemStack.hasItemMeta()) {
|
||||||
return itemStack
|
return itemStack
|
||||||
}
|
}
|
||||||
|
|
||||||
for (priority in DisplayPriority.values()) {
|
|
||||||
val modules = registeredModules[priority] ?: continue
|
for ((_, modules) in registeredModules) {
|
||||||
for (module in modules) {
|
for (module in modules) {
|
||||||
val varargs = pluginVarArgs[module.pluginName] ?: continue
|
val varargs = pluginVarArgs[module.pluginName] ?: continue
|
||||||
Display.callDisplayModule(module, itemStack, player, *varargs)
|
Display.callDisplayModule(module, itemStack, player, *varargs)
|
||||||
@@ -73,8 +66,7 @@ class EcoDisplayHandler(plugin: EcoPlugin) : DisplayHandler {
|
|||||||
fast.lore = lore
|
fast.lore = lore
|
||||||
}
|
}
|
||||||
|
|
||||||
for (priority in DisplayPriority.values()) {
|
for ((_, modules) in registeredModules) {
|
||||||
val modules = registeredModules[priority] ?: continue
|
|
||||||
for (module in modules) {
|
for (module in modules) {
|
||||||
module.revert(itemStack)
|
module.revert(itemStack)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user