Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f01e18950c | ||
|
|
d4a6bf105b |
@@ -6,7 +6,6 @@ import com.willfp.eco.core.Eco;
|
|||||||
import com.willfp.eco.core.fast.FastItemStack;
|
import com.willfp.eco.core.fast.FastItemStack;
|
||||||
import com.willfp.eco.core.items.args.LookupArgParser;
|
import com.willfp.eco.core.items.args.LookupArgParser;
|
||||||
import com.willfp.eco.core.items.provider.ItemProvider;
|
import com.willfp.eco.core.items.provider.ItemProvider;
|
||||||
import com.willfp.eco.core.items.tag.ItemTag;
|
|
||||||
import com.willfp.eco.core.recipe.parts.EmptyTestableItem;
|
import com.willfp.eco.core.recipe.parts.EmptyTestableItem;
|
||||||
import com.willfp.eco.core.recipe.parts.MaterialTestableItem;
|
import com.willfp.eco.core.recipe.parts.MaterialTestableItem;
|
||||||
import com.willfp.eco.core.recipe.parts.ModifiedTestableItem;
|
import com.willfp.eco.core.recipe.parts.ModifiedTestableItem;
|
||||||
@@ -14,6 +13,7 @@ import com.willfp.eco.core.recipe.parts.TestableStack;
|
|||||||
import com.willfp.eco.core.recipe.parts.UnrestrictedMaterialTestableItem;
|
import com.willfp.eco.core.recipe.parts.UnrestrictedMaterialTestableItem;
|
||||||
import com.willfp.eco.util.NamespacedKeyUtils;
|
import com.willfp.eco.util.NamespacedKeyUtils;
|
||||||
import com.willfp.eco.util.NumberUtils;
|
import com.willfp.eco.util.NumberUtils;
|
||||||
|
import kotlin.Suppress;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
@@ -93,11 +93,6 @@ public final class Items {
|
|||||||
*/
|
*/
|
||||||
private static final Map<String, Material> FRIENDLY_MATERIAL_NAMES = new HashMap<>();
|
private static final Map<String, Material> FRIENDLY_MATERIAL_NAMES = new HashMap<>();
|
||||||
|
|
||||||
/**
|
|
||||||
* All tags.
|
|
||||||
*/
|
|
||||||
private static final Map<String, ItemTag> TAGS = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a new custom item.
|
* Register a new custom item.
|
||||||
*
|
*
|
||||||
@@ -222,20 +217,7 @@ public final class Items {
|
|||||||
|
|
||||||
String[] split = args[0].toLowerCase().split(":");
|
String[] split = args[0].toLowerCase().split(":");
|
||||||
|
|
||||||
String base = split[0];
|
if (split.length == 1) {
|
||||||
boolean isTag = base.startsWith("#");
|
|
||||||
|
|
||||||
if (isTag) {
|
|
||||||
String tag = base.substring(1);
|
|
||||||
ItemTag itemTag = TAGS.get(tag);
|
|
||||||
|
|
||||||
if (itemTag == null) {
|
|
||||||
return new EmptyTestableItem();
|
|
||||||
}
|
|
||||||
item = itemTag.toTestableItem();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (split.length == 1 && !isTag) {
|
|
||||||
String itemType = args[0];
|
String itemType = args[0];
|
||||||
boolean isWildcard = itemType.startsWith("*");
|
boolean isWildcard = itemType.startsWith("*");
|
||||||
if (isWildcard) {
|
if (isWildcard) {
|
||||||
@@ -248,7 +230,7 @@ public final class Items {
|
|||||||
item = isWildcard ? new UnrestrictedMaterialTestableItem(material) : new MaterialTestableItem(material);
|
item = isWildcard ? new UnrestrictedMaterialTestableItem(material) : new MaterialTestableItem(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (split.length == 2 && !isTag) {
|
if (split.length == 2) {
|
||||||
String namespace = split[0];
|
String namespace = split[0];
|
||||||
String keyID = split[1];
|
String keyID = split[1];
|
||||||
NamespacedKey namespacedKey = NamespacedKeyUtils.create(namespace, keyID);
|
NamespacedKey namespacedKey = NamespacedKeyUtils.create(namespace, keyID);
|
||||||
@@ -292,7 +274,7 @@ public final class Items {
|
|||||||
Legacy namespace:id:amount format
|
Legacy namespace:id:amount format
|
||||||
This has been superseded by namespace:id amount
|
This has been superseded by namespace:id amount
|
||||||
*/
|
*/
|
||||||
if (split.length == 3 && !isTag) {
|
if (split.length == 3) {
|
||||||
TestableItem part = REGISTRY.get(NamespacedKeyUtils.create(split[0], split[1]));
|
TestableItem part = REGISTRY.get(NamespacedKeyUtils.create(split[0], split[1]));
|
||||||
if (part == null) {
|
if (part == null) {
|
||||||
return new EmptyTestableItem();
|
return new EmptyTestableItem();
|
||||||
@@ -324,8 +306,7 @@ public final class Items {
|
|||||||
|
|
||||||
List<Predicate<ItemStack>> predicates = new ArrayList<>();
|
List<Predicate<ItemStack>> predicates = new ArrayList<>();
|
||||||
|
|
||||||
for (
|
for (LookupArgParser argParser : ARG_PARSERS) {
|
||||||
LookupArgParser argParser : ARG_PARSERS) {
|
|
||||||
Predicate<ItemStack> predicate = argParser.parseArguments(modifierArgs, meta);
|
Predicate<ItemStack> predicate = argParser.parseArguments(modifierArgs, meta);
|
||||||
if (predicate != null) {
|
if (predicate != null) {
|
||||||
predicates.add(argParser.parseArguments(modifierArgs, meta));
|
predicates.add(argParser.parseArguments(modifierArgs, meta));
|
||||||
@@ -630,24 +611,6 @@ public final class Items {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a new item tag.
|
|
||||||
*
|
|
||||||
* @param tag The tag.
|
|
||||||
*/
|
|
||||||
public static void registerTag(@NotNull final ItemTag tag) {
|
|
||||||
TAGS.put(tag.getIdentifier(), tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all tags.
|
|
||||||
*
|
|
||||||
* @return All tags.
|
|
||||||
*/
|
|
||||||
public static Collection<ItemTag> getTags() {
|
|
||||||
return TAGS.values();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Items() {
|
private Items() {
|
||||||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
package com.willfp.eco.core.items.tag;
|
|
||||||
|
|
||||||
import org.bukkit.NamespacedKey;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A custom item tag.
|
|
||||||
*/
|
|
||||||
public abstract class CustomItemTag implements ItemTag {
|
|
||||||
/**
|
|
||||||
* The key.
|
|
||||||
*/
|
|
||||||
private final NamespacedKey key;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new custom item tag.
|
|
||||||
*
|
|
||||||
* @param key The key.
|
|
||||||
*/
|
|
||||||
public CustomItemTag(@NotNull final NamespacedKey key) {
|
|
||||||
this.key = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public String getIdentifier() {
|
|
||||||
return key.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
package com.willfp.eco.core.items.tag;
|
|
||||||
|
|
||||||
import com.willfp.eco.core.items.TestableItem;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A group of items that share a common trait.
|
|
||||||
*/
|
|
||||||
public interface ItemTag {
|
|
||||||
/**
|
|
||||||
* Get the identifier of the tag.
|
|
||||||
*
|
|
||||||
* @return The identifier.
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
String getIdentifier();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if an item matches the tag.
|
|
||||||
*
|
|
||||||
* @param itemStack The item to check.
|
|
||||||
* @return If the item matches the tag.
|
|
||||||
*/
|
|
||||||
boolean matches(@NotNull ItemStack itemStack);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an example item.
|
|
||||||
*
|
|
||||||
* @return The example item.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
default ItemStack getExampleItem() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert this tag to a testable item.
|
|
||||||
*
|
|
||||||
* @return The testable item.
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
default TestableItem toTestableItem() {
|
|
||||||
return new TestableItem() {
|
|
||||||
@Override
|
|
||||||
public boolean matches(@Nullable final ItemStack itemStack) {
|
|
||||||
return itemStack != null && ItemTag.this.matches(itemStack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull ItemStack getItem() {
|
|
||||||
ItemStack example = ItemTag.this.getExampleItem();
|
|
||||||
return example == null ? new ItemStack(Material.STONE) : example;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ItemTagTestableItem{" +
|
|
||||||
"tag=" + ItemTag.this.getIdentifier() +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
package com.willfp.eco.core.items.tag;
|
|
||||||
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.Tag;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A vanilla item tag.
|
|
||||||
*/
|
|
||||||
public final class VanillaItemTag implements ItemTag {
|
|
||||||
/**
|
|
||||||
* The identifier.
|
|
||||||
*/
|
|
||||||
private final String identifier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The tag.
|
|
||||||
*/
|
|
||||||
private final Tag<Material> tag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new vanilla item tag.
|
|
||||||
*
|
|
||||||
* @param identifier The identifier.
|
|
||||||
* @param tag The tag.
|
|
||||||
*/
|
|
||||||
public VanillaItemTag(@NotNull final String identifier,
|
|
||||||
@NotNull final Tag<Material> tag) {
|
|
||||||
this.identifier = identifier;
|
|
||||||
this.tag = tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the tag.
|
|
||||||
*
|
|
||||||
* @return The tag.
|
|
||||||
*/
|
|
||||||
public Tag<Material> getTag() {
|
|
||||||
return tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public String getIdentifier() {
|
|
||||||
return identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matches(@NotNull final ItemStack itemStack) {
|
|
||||||
return tag.isTagged(itemStack.getType());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull ItemStack getExampleItem() {
|
|
||||||
return new ItemStack(tag.getValues().stream().findFirst().orElse(Material.STONE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,12 +7,20 @@ import java.util.function.Predicate
|
|||||||
|
|
||||||
object ArgParserCustomModelData : LookupArgParser {
|
object ArgParserCustomModelData : LookupArgParser {
|
||||||
override fun parseArguments(args: Array<out String>, meta: ItemMeta): Predicate<ItemStack>? {
|
override fun parseArguments(args: Array<out String>, meta: ItemMeta): Predicate<ItemStack>? {
|
||||||
val arg = args.firstOrNull {
|
var modelData: Int? = null
|
||||||
it.startsWith("custom-model-data:", ignoreCase = true)
|
|
||||||
|| it.startsWith("custom_model_data:", ignoreCase = true)
|
|
||||||
} ?: return null
|
|
||||||
|
|
||||||
val modelData = arg.split(":")[1].toIntOrNull() ?: return null
|
for (arg in args) {
|
||||||
|
val argSplit = arg.split(":")
|
||||||
|
if (!argSplit[0].equals("custom-model-data", ignoreCase = true)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (argSplit.size < 2) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
modelData = argSplit[1].toIntOrNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
modelData ?: return null
|
||||||
|
|
||||||
meta.setCustomModelData(modelData)
|
meta.setCustomModelData(modelData)
|
||||||
|
|
||||||
@@ -32,6 +40,6 @@ object ArgParserCustomModelData : LookupArgParser {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return "custom_model_data:${meta.customModelData}"
|
return "custom-model-data:${meta.customModelData}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.willfp.eco.internal.items
|
|||||||
|
|
||||||
import com.willfp.eco.core.fast.fast
|
import com.willfp.eco.core.fast.fast
|
||||||
import com.willfp.eco.core.items.args.LookupArgParser
|
import com.willfp.eco.core.items.args.LookupArgParser
|
||||||
import org.bukkit.NamespacedKey
|
import com.willfp.eco.util.NamespacedKeyUtils
|
||||||
import org.bukkit.enchantments.Enchantment
|
import org.bukkit.enchantments.Enchantment
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta
|
import org.bukkit.inventory.meta.EnchantmentStorageMeta
|
||||||
@@ -16,11 +16,18 @@ object ArgParserEnchantment : LookupArgParser {
|
|||||||
for (arg in args) {
|
for (arg in args) {
|
||||||
val argSplit = arg.split(":")
|
val argSplit = arg.split(":")
|
||||||
|
|
||||||
val enchant = Enchantment.getByKey(NamespacedKey.minecraft(argSplit[0].lowercase())) ?: continue
|
if (argSplit.size < 2) {
|
||||||
val level = argSplit.getOrNull(1)?.toIntOrNull() ?: enchant.maxLevel
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
val enchant = Enchantment.getByKey(NamespacedKeyUtils.create("minecraft", argSplit[0]))
|
||||||
|
val level = argSplit[1].toIntOrNull()
|
||||||
|
|
||||||
|
if (enchant != null && level != null) {
|
||||||
enchants[enchant] = level
|
enchants[enchant] = level
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (enchants.isEmpty()) {
|
if (enchants.isEmpty()) {
|
||||||
return null
|
return null
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
package com.willfp.eco.internal.items.tags
|
|
||||||
|
|
||||||
import com.willfp.eco.core.items.Items
|
|
||||||
import com.willfp.eco.core.items.tag.VanillaItemTag
|
|
||||||
import org.bukkit.Keyed
|
|
||||||
import org.bukkit.Material
|
|
||||||
import org.bukkit.Tag
|
|
||||||
|
|
||||||
object VanillaItemTags {
|
|
||||||
fun register() {
|
|
||||||
// Get all tags
|
|
||||||
val allTags = Tag::class.java.declaredFields
|
|
||||||
.filter { it.type == Tag::class.java }
|
|
||||||
.mapNotNull {
|
|
||||||
val tag = it.get(null) as? Tag<*>
|
|
||||||
if (tag == null) {
|
|
||||||
null
|
|
||||||
} else {
|
|
||||||
NamedTag(it.name.lowercase(), tag)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register all tags
|
|
||||||
for (tag in allTags) {
|
|
||||||
if (tag.isMaterial) {
|
|
||||||
Items.registerTag(
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
VanillaItemTag(tag.name, tag.tag as Tag<Material>)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private data class NamedTag<T : Keyed>(val name: String, val tag: Tag<T>) {
|
|
||||||
// Check if tag is material
|
|
||||||
val isMaterial: Boolean
|
|
||||||
get() = tag.values.firstOrNull() is Material
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,7 +12,7 @@ object ParticleFactoryRGB : ParticleFactory {
|
|||||||
if (Prerequisite.HAS_1_20_5.isMet) {
|
if (Prerequisite.HAS_1_20_5.isMet) {
|
||||||
Particle.valueOf("DUST")
|
Particle.valueOf("DUST")
|
||||||
} else {
|
} else {
|
||||||
Particle.valueOf("REDSTONE_DUST")
|
Particle.valueOf("REDSTONE")
|
||||||
}
|
}
|
||||||
}.getOrNull()
|
}.getOrNull()
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import com.willfp.eco.core.integrations.mcmmo.McmmoManager
|
|||||||
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager
|
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager
|
||||||
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.tag.VanillaItemTag
|
|
||||||
import com.willfp.eco.core.packet.PacketListener
|
import com.willfp.eco.core.packet.PacketListener
|
||||||
import com.willfp.eco.core.particle.Particles
|
import com.willfp.eco.core.particle.Particles
|
||||||
import com.willfp.eco.core.price.Prices
|
import com.willfp.eco.core.price.Prices
|
||||||
@@ -53,7 +52,6 @@ import com.willfp.eco.internal.items.ArgParserName
|
|||||||
import com.willfp.eco.internal.items.ArgParserTexture
|
import com.willfp.eco.internal.items.ArgParserTexture
|
||||||
import com.willfp.eco.internal.items.ArgParserUnbreakable
|
import com.willfp.eco.internal.items.ArgParserUnbreakable
|
||||||
import com.willfp.eco.internal.items.ModernItemArgParsers
|
import com.willfp.eco.internal.items.ModernItemArgParsers
|
||||||
import com.willfp.eco.internal.items.tags.VanillaItemTags
|
|
||||||
import com.willfp.eco.internal.lookup.SegmentParserGroup
|
import com.willfp.eco.internal.lookup.SegmentParserGroup
|
||||||
import com.willfp.eco.internal.lookup.SegmentParserUseIfPresent
|
import com.willfp.eco.internal.lookup.SegmentParserUseIfPresent
|
||||||
import com.willfp.eco.internal.particle.ParticleFactoryRGB
|
import com.willfp.eco.internal.particle.ParticleFactoryRGB
|
||||||
@@ -266,9 +264,6 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
|
|||||||
if (!Prerequisite.HAS_PAPER.isMet) {
|
if (!Prerequisite.HAS_PAPER.isMet) {
|
||||||
bukkitAudiences = BukkitAudiences.create(this)
|
bukkitAudiences = BukkitAudiences.create(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init vanilla item tags
|
|
||||||
VanillaItemTags.register()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handleDisable() {
|
override fun handleDisable() {
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
version = 6.73.1
|
version = 6.72.0
|
||||||
kotlin.incremental.useClasspathSnapshot=false
|
kotlin.incremental.useClasspathSnapshot=false
|
||||||
Reference in New Issue
Block a user