Compare commits

...

11 Commits

Author SHA1 Message Date
Auxilor
5d18b424d7 Added ColorArgParser 2021-12-04 15:37:29 +00:00
Auxilor
7be9a1bd10 Fixed EcoYamlConfigWrapper cast issues 2021-12-03 20:59:07 +00:00
Auxilor
97c39b56dd Updated to 6.15.0 2021-12-03 20:23:25 +00:00
Auxilor
1e5955f249 Codestyle fixes 2021-12-03 16:21:47 +00:00
Auxilor
bad076bbe9 Added kotlin.code.style = official 2021-12-03 16:18:53 +00:00
Auxilor
e219b2f33c Config additions 2021-12-03 16:13:37 +00:00
Auxilor
2f7603409e Generic variance 2021-12-03 15:58:41 +00:00
Auxilor
28cdb65176 Added Config#getSubsections 2021-12-03 15:49:00 +00:00
Auxilor
2d074bc186 Updated to 6.14.1 2021-12-02 14:50:31 +00:00
Auxilor
7e4422f6e2 Fixed ShapedCraftingRecipe on 1.18 2021-12-02 14:50:04 +00:00
Auxilor
5b29c90457 Added PacketHeldWindowItems to hopefully fix display 2021-12-02 14:49:29 +00:00
13 changed files with 171 additions and 16 deletions

View File

@@ -524,6 +524,25 @@ public interface Config extends Cloneable {
@Nullable @Nullable
List<Double> getDoublesOrNull(@NotNull String path); List<Double> getDoublesOrNull(@NotNull String path);
/**
* Get a list of subsections from config.
*
* @param path The key to fetch the value from.
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
*/
@NotNull
List<? extends Config> getSubsections(@NotNull String path);
/**
* Get a list of subsections from config.
*
* @param path The key to fetch the value from.
* @return The found value, or null if not found.
*/
@Nullable
List<? extends Config> getSubsectionsOrNull(@NotNull String path);
/** /**
* Clone the config. * Clone the config.
* *

View File

@@ -173,6 +173,16 @@ public abstract class ConfigWrapper<T extends Config> implements Config {
return handle.getDoublesOrNull(path); return handle.getDoublesOrNull(path);
} }
@Override
public @NotNull List<? extends Config> getSubsections(@NotNull final String path) {
return handle.getSubsections(path);
}
@Override
public @Nullable List<? extends Config> getSubsectionsOrNull(@NotNull final String path) {
return handle.getSubsectionsOrNull(path);
}
@Override @Override
public Config clone() { public Config clone() {
return handle.clone(); return handle.clone();

View File

@@ -0,0 +1,65 @@
package com.willfp.eco.core.items.args;
import org.bukkit.Color;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.function.Predicate;
/**
* Parse leather armor colors.
*/
public class ColorArgParser implements LookupArgParser {
@Override
public @Nullable Predicate<ItemStack> parseArguments(@NotNull final String[] args,
@NotNull final ItemMeta meta) {
if (!(meta instanceof LeatherArmorMeta armorMeta)) {
return null;
}
String color = null;
for (String arg : args) {
String[] argSplit = arg.split(":");
if (!argSplit[0].equalsIgnoreCase("color")) {
continue;
}
if (argSplit.length < 2) {
continue;
}
color = argSplit[1];
}
if (color == null) {
return null;
}
armorMeta.setColor(Color.fromRGB(Integer.parseInt(color, 16)));
String finalColor = color;
return test -> {
if (!test.hasItemMeta()) {
return false;
}
ItemMeta testMeta = test.getItemMeta();
assert testMeta != null;
if (testMeta instanceof LeatherArmorMeta cast) {
return finalColor.equalsIgnoreCase(
Integer.toHexString(cast.getColor().getRed())
+ Integer.toHexString(cast.getColor().getGreen())
+ Integer.toHexString(cast.getColor().getBlue())
);
}
return true;
};
}
}

View File

@@ -113,7 +113,7 @@ public final class ShapedCraftingRecipe extends PluginDependent<EcoPlugin> imple
displayedRecipe.setIngredient(character, new RecipeChoice.ExactChoice(item)); displayedRecipe.setIngredient(character, new RecipeChoice.ExactChoice(item));
} }
if (Prerequisite.HAS_1_18.isMet()) { if (Prerequisite.HAS_1_18.isMet() && !Prerequisite.HAS_PAPER.isMet()) {
if (Bukkit.getServer().getRecipe(this.getKey()) != null) { if (Bukkit.getServer().getRecipe(this.getKey()) != null) {
return; return;
} }

View File

@@ -1,7 +1,6 @@
package com.willfp.eco.util; package com.willfp.eco.util;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@@ -21,8 +20,8 @@ public final class ListUtils {
* @return The list, filled will null objects. * @return The list, filled will null objects.
*/ */
@NotNull @NotNull
public static <@Nullable T> List<List<T>> create2DList(final int rows, public static <T> List<List<T>> create2DList(final int rows,
final int columns) { final int columns) {
List<List<T>> list = new ArrayList<>(rows); List<List<T>> list = new ArrayList<>(rows);
while (list.size() < rows) { while (list.size() < rows) {
List<T> row = new ArrayList<>(columns); List<T> row = new ArrayList<>(columns);

View File

@@ -5,12 +5,11 @@ import com.willfp.eco.util.StringUtils
import org.bukkit.configuration.ConfigurationSection import org.bukkit.configuration.ConfigurationSection
import org.bukkit.configuration.file.YamlConfiguration import org.bukkit.configuration.file.YamlConfiguration
import java.io.StringReader import java.io.StringReader
import java.util.concurrent.ConcurrentHashMap
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
open class EcoYamlConfigWrapper<T : ConfigurationSection> : Config { open class EcoYamlConfigWrapper<T : ConfigurationSection> : Config {
lateinit var handle: T lateinit var handle: T
private val cache = ConcurrentHashMap<String, Any?>() private val cache = mutableMapOf<String, Any?>()
protected fun init(config: T): Config { protected fun init(config: T): Config {
handle = config handle = config
@@ -70,9 +69,9 @@ open class EcoYamlConfigWrapper<T : ConfigurationSection> : Config {
override fun getInt(path: String): Int { override fun getInt(path: String): Int {
return if (cache.containsKey(path)) { return if (cache.containsKey(path)) {
cache[path] as Int (cache[path] as Number).toInt()
} else { } else {
cache[path] = handle.getInt(path, 0) cache[path] = handle.getDouble(path, 0.0).toInt()
getInt(path) getInt(path)
} }
} }
@@ -90,9 +89,9 @@ open class EcoYamlConfigWrapper<T : ConfigurationSection> : Config {
def: Int def: Int
): Int { ): Int {
return if (cache.containsKey(path)) { return if (cache.containsKey(path)) {
cache[path] as Int (cache[path] as Number).toInt()
} else { } else {
cache[path] = handle.getInt(path, def) cache[path] = handle.getDouble(path, def.toDouble()).toInt()
getInt(path) getInt(path)
} }
} }
@@ -262,6 +261,31 @@ open class EcoYamlConfigWrapper<T : ConfigurationSection> : Config {
} }
} }
override fun getSubsections(path: String): MutableList<out Config> {
return if (cache.containsKey(path)) {
(cache[path] as MutableList<Config>).toMutableList()
} else {
val mapList = ArrayList(handle.getMapList(path)) as List<Map<String, Any?>>
val configList = mutableListOf<Config>()
for (map in mapList) {
val temp = YamlConfiguration.loadConfiguration(StringReader(""))
temp.createSection("a", map)
configList.add(EcoYamlConfigSection(temp.getConfigurationSection("a")!!))
}
cache[path] = if (has(path)) configList else emptyList()
getSubsections(path)
}
}
override fun getSubsectionsOrNull(path: String): MutableList<out Config>? {
return if (has(path)) {
getSubsections(path)
} else {
null
}
}
override fun clone(): Config { override fun clone(): Config {
return EcoYamlConfigSection( return EcoYamlConfigSection(
YamlConfiguration.loadConfiguration( YamlConfiguration.loadConfiguration(

View File

@@ -15,6 +15,6 @@ class RequirementPlaceholderGreaterThan : Requirement() {
val placeholder = args[0] val placeholder = args[0]
val equals = args[1].toDoubleOrNull() ?: return false val equals = args[1].toDoubleOrNull() ?: return false
return PlaceholderManager.translatePlaceholders(placeholder, player).toDoubleOrNull() ?: 0.0 >= equals return (PlaceholderManager.translatePlaceholders(placeholder, player).toDoubleOrNull() ?: 0.0) >= equals
} }
} }

View File

@@ -15,6 +15,6 @@ class RequirementPlaceholderLessThan : Requirement() {
val placeholder = args[0] val placeholder = args[0]
val equals = args[1].toDoubleOrNull() ?: return false val equals = args[1].toDoubleOrNull() ?: return false
return PlaceholderManager.translatePlaceholders(placeholder, player).toDoubleOrNull() ?: 0.0 < equals return (PlaceholderManager.translatePlaceholders(placeholder, player).toDoubleOrNull() ?: 0.0) < equals
} }
} }

View File

@@ -165,7 +165,7 @@ class NMSFastItemStack(itemStack: org.bukkit.inventory.ItemStack) : EcoFastItemS
} }
override fun hashCode(): Int { override fun hashCode(): Int {
return handle.tag?.hashCode() ?: 0b00010101 * 31 + Item.getId(handle.item) return handle.tag?.hashCode() ?: (0b00010101 * 31 + Item.getId(handle.item))
} }
private fun apply() { private fun apply() {

View File

@@ -180,7 +180,7 @@ class NMSFastItemStack(itemStack: org.bukkit.inventory.ItemStack) : EcoFastItemS
} }
override fun hashCode(): Int { override fun hashCode(): Int {
return handle.tag?.hashCode() ?: 0b00010101 * 31 + Item.getId(handle.item) return handle.tag?.hashCode() ?: (0b00010101 * 31 + Item.getId(handle.item))
} }
private fun apply() { private fun apply() {

View File

@@ -15,6 +15,7 @@ import com.willfp.eco.core.integrations.hologram.HologramManager
import com.willfp.eco.core.integrations.mcmmo.McmmoManager import com.willfp.eco.core.integrations.mcmmo.McmmoManager
import com.willfp.eco.core.integrations.shop.ShopManager import com.willfp.eco.core.integrations.shop.ShopManager
import com.willfp.eco.core.items.Items import com.willfp.eco.core.items.Items
import com.willfp.eco.core.items.args.ColorArgParser
import com.willfp.eco.core.items.args.CustomModelDataArgParser import com.willfp.eco.core.items.args.CustomModelDataArgParser
import com.willfp.eco.core.items.args.EnchantmentArgParser import com.willfp.eco.core.items.args.EnchantmentArgParser
import com.willfp.eco.core.items.args.TextureArgParser import com.willfp.eco.core.items.args.TextureArgParser
@@ -26,6 +27,7 @@ import com.willfp.eco.internal.spigot.data.PlayerBlockListener
import com.willfp.eco.internal.spigot.data.storage.ProfileSaver import com.willfp.eco.internal.spigot.data.storage.ProfileSaver
import com.willfp.eco.internal.spigot.display.PacketAutoRecipe import com.willfp.eco.internal.spigot.display.PacketAutoRecipe
import com.willfp.eco.internal.spigot.display.PacketChat import com.willfp.eco.internal.spigot.display.PacketChat
import com.willfp.eco.internal.spigot.display.PacketHeldWindowItems
import com.willfp.eco.internal.spigot.display.PacketOpenWindowMerchant import com.willfp.eco.internal.spigot.display.PacketOpenWindowMerchant
import com.willfp.eco.internal.spigot.display.PacketSetCreativeSlot import com.willfp.eco.internal.spigot.display.PacketSetCreativeSlot
import com.willfp.eco.internal.spigot.display.PacketSetSlot import com.willfp.eco.internal.spigot.display.PacketSetSlot
@@ -93,6 +95,7 @@ abstract class EcoSpigotPlugin : EcoPlugin(
Items.registerArgParser(EnchantmentArgParser()) Items.registerArgParser(EnchantmentArgParser())
Items.registerArgParser(TextureArgParser()) Items.registerArgParser(TextureArgParser())
Items.registerArgParser(CustomModelDataArgParser()) Items.registerArgParser(CustomModelDataArgParser())
Items.registerArgParser(ColorArgParser())
val skullProxy = getProxy(SkullProxy::class.java) val skullProxy = getProxy(SkullProxy::class.java)
SkullUtils.initialize( SkullUtils.initialize(
@@ -240,6 +243,7 @@ abstract class EcoSpigotPlugin : EcoPlugin(
PacketSetCreativeSlot(this), PacketSetCreativeSlot(this),
PacketSetSlot(this), PacketSetSlot(this),
PacketWindowItems(this), PacketWindowItems(this),
PacketHeldWindowItems(this),
PacketOpenWindowMerchant(this) PacketOpenWindowMerchant(this)
) )
} }

View File

@@ -0,0 +1,33 @@
package com.willfp.eco.internal.spigot.display
import com.comphenix.protocol.PacketType
import com.comphenix.protocol.events.PacketContainer
import com.comphenix.protocol.events.PacketEvent
import com.willfp.eco.core.AbstractPacketAdapter
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.Prerequisite
import com.willfp.eco.core.display.Display
import com.willfp.eco.internal.spigot.display.frame.DisplayFrame
import com.willfp.eco.internal.spigot.display.frame.lastDisplayFrame
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
class PacketHeldWindowItems(plugin: EcoPlugin) : AbstractPacketAdapter(plugin, PacketType.Play.Server.WINDOW_ITEMS, false) {
override fun onSend(
packet: PacketContainer,
player: Player,
event: PacketEvent
) {
if (!Prerequisite.HAS_1_17.isMet) {
return
}
packet.itemModifier.modify(0) { item: ItemStack? ->
Display.display(
item!!, player
)
}
player.lastDisplayFrame = DisplayFrame.EMPTY
}
}

View File

@@ -1,2 +1,3 @@
version = 6.14.0 version = 6.15.0
plugin-name = eco plugin-name = eco
kotlin.code.style = official