Compare commits

..

7 Commits

Author SHA1 Message Date
Auxilor
c69bb6904f Minor fixes 2022-04-20 11:31:37 +01:00
Auxilor
9f193b7206 Fixed val using annotations 2022-04-20 11:28:55 +01:00
Auxilor
6fce2c13fe Updated to 6.34.0 2022-04-20 11:25:19 +01:00
Auxilor
02342c11a6 Added utility methods for base NBT 2022-04-20 11:25:00 +01:00
Auxilor
2fde56df0d Added ability to modify full item NBT via PersistentDataContainers and FastItemStack 2022-04-20 11:19:24 +01:00
Auxilor
cb64dedd74 Updated to kotlin 1.6.21 2022-04-20 10:57:27 +01:00
Auxilor
a7c489413e Moved IridiumSkyblock to use jar 2022-04-20 10:56:47 +01:00
13 changed files with 273 additions and 72 deletions

View File

@@ -4,7 +4,7 @@ buildscript {
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21")
}
}
@@ -13,7 +13,7 @@ plugins {
id("com.github.johnrengelman.shadow") version "7.1.2"
id("maven-publish")
id("java")
kotlin("jvm") version "1.6.10"
kotlin("jvm") version "1.6.21"
}
dependencies {
@@ -71,9 +71,6 @@ allprojects {
// CombatLogX
maven("https://nexus.sirblobman.xyz/repository/public/")
// IridiumSkyblock
maven("https://nexus.iridiumdevelopment.net/repository/maven-releases/")
// MythicMobs
maven("https://mvn.lumine.io/repository/maven-public/")
@@ -103,7 +100,7 @@ allprojects {
// Other
implementation("com.github.ben-manes.caffeine:caffeine:3.0.6")
implementation("org.apache.maven:maven-artifact:3.8.4")
implementation(kotlin("stdlib", version = "1.6.10"))
implementation(kotlin("stdlib", version = "1.6.21"))
}
tasks.withType<JavaCompile> {

View File

@@ -6,6 +6,7 @@ import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataHolder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -47,6 +48,7 @@ public interface FastItemStack extends PersistentDataHolder {
* @param checkStored If stored enchantments should be accounted for.
* @return A map of all enchantments.
*/
@NotNull
Map<Enchantment, Integer> getEnchants(boolean checkStored);
/**
@@ -54,9 +56,11 @@ public interface FastItemStack extends PersistentDataHolder {
*
* @param enchantment The enchantment.
* @return The enchantment level, or 0 if not found.
* @deprecated Poorly named method. Use getEnchantmentLevel instead.
*/
@Deprecated(since = "6.34.0", forRemoval = true)
default int getLevelOnItem(@NotNull Enchantment enchantment) {
return getLevelOnItem(enchantment, false);
return getEnchantmentLevel(enchantment, false);
}
/**
@@ -65,9 +69,33 @@ public interface FastItemStack extends PersistentDataHolder {
* @param enchantment The enchantment.
* @param checkStored If the stored NBT should also be checked.
* @return The enchantment level, or 0 if not found.
* @deprecated Poorly named method. Use getEnchantmentLevel instead.
*/
int getLevelOnItem(@NotNull Enchantment enchantment,
boolean checkStored);
@Deprecated(since = "6.34.0", forRemoval = true)
default int getLevelOnItem(@NotNull Enchantment enchantment,
boolean checkStored) {
return getEnchantmentLevel(enchantment, checkStored);
}
/**
* Get the level of an enchantment.
*
* @param enchantment The enchantment.
* @return The enchantment level, or 0 if not found.
*/
default int getEnchantmentLevel(@NotNull Enchantment enchantment) {
return getLevelOnItem(enchantment, false);
}
/**
* Get the level of an enchantment.
*
* @param enchantment The enchantment.
* @param checkStored If the stored NBT should also be checked.
* @return The enchantment level, or 0 if not found.
*/
int getEnchantmentLevel(@NotNull Enchantment enchantment,
boolean checkStored);
/**
* Set the item lore.
@@ -134,7 +162,6 @@ public interface FastItemStack extends PersistentDataHolder {
/**
* Get the rework penalty.
* .
*
* @return The rework penalty found on the item.
*/
@@ -169,11 +196,28 @@ public interface FastItemStack extends PersistentDataHolder {
*/
boolean hasItemFlag(@NotNull ItemFlag flag);
/**
* Get the base NBT tag (Not PublicBukkitValues, the base) as a PersistentDataContainer.
* <p>
* The returned PersistentDataContainer will not modify the item until the tag is set.
*
* @return The base NBT tag.
*/
PersistentDataContainer getBaseTag();
/**
* Set the base NBT tag (Not PublicBukkitValues, the base) from a PersistentDataContainer.
*
* @param container The PersistentDataContainer.
*/
void setBaseTag(@Nullable PersistentDataContainer container);
/**
* Get the Bukkit ItemStack again.
*
* @return The ItemStack.
*/
@NotNull
ItemStack unwrap();
/**

View File

@@ -2,6 +2,7 @@ package com.willfp.eco.core.items;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.willfp.eco.core.fast.FastItemStack;
import com.willfp.eco.core.items.args.LookupArgParser;
import com.willfp.eco.core.items.provider.ItemProvider;
import com.willfp.eco.core.recipe.parts.EmptyTestableItem;
@@ -16,6 +17,7 @@ import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -489,6 +491,32 @@ public final class Items {
return to;
}
/**
* Get the base NBT tag on an item.
*
* @param itemStack The ItemStack.
* @return The base NBT.
*/
@NotNull
public static PersistentDataContainer getBaseNBT(@NotNull final ItemStack itemStack) {
return FastItemStack.wrap(itemStack).getBaseTag();
}
/**
* Set the base NBT tag on an item.
*
* @param itemStack The ItemStack.
* @param container The base NBT tag.
* @return The ItemStack, modified. Not required to use, as this modifies the instance.¬
*/
@NotNull
public static ItemStack setBaseNBT(@NotNull final ItemStack itemStack,
@Nullable final PersistentDataContainer container) {
FastItemStack fis = FastItemStack.wrap(itemStack);
fis.setBaseTag(container);
return fis.unwrap();
}
private Items() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

View File

@@ -4,6 +4,7 @@ package com.willfp.eco.core.items
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.ItemMeta
import org.bukkit.persistence.PersistentDataContainer
/**
* @see Items.toLookupString
@@ -22,3 +23,19 @@ fun ItemStack.mergeFrom(other: ItemStack): ItemStack =
*/
fun ItemMeta.mergeFrom(other: ItemMeta): ItemMeta =
Items.mergeFrom(other, this)
/**
* @see Items.getBaseNBT
* @see Items.setBaseNBT
*/
var ItemStack.baseNBT: PersistentDataContainer
get() = Items.getBaseNBT(this)
set(value) {
Items.setBaseNBT(this, value)
}
/**
* @see Items.setBaseNBT
*/
fun ItemStack.clearNBT() =
Items.setBaseNBT(this, null)

View File

@@ -52,18 +52,18 @@ fun Material.toItem(): Item =
.orElseThrow { IllegalArgumentException("Material is not item!") }
}
fun CompoundTag.makePdc(): PersistentDataContainer =
impl.makePdc(this)
fun CompoundTag.makePdc(base: Boolean = false): PersistentDataContainer =
impl.makePdc(this, base)
fun CompoundTag.setPdc(pdc: PersistentDataContainer) =
impl.setPdc(this, pdc)
fun CompoundTag.setPdc(pdc: PersistentDataContainer?, item: net.minecraft.world.item.ItemStack? = null) =
impl.setPdc(this, pdc, item)
interface CommonsProvider {
val nbtTagString: Int
fun makePdc(tag: CompoundTag): PersistentDataContainer
fun makePdc(tag: CompoundTag, base: Boolean): PersistentDataContainer
fun setPdc(tag: CompoundTag, pdc: PersistentDataContainer)
fun setPdc(tag: CompoundTag, pdc: PersistentDataContainer?, item: net.minecraft.world.item.ItemStack? = null)
fun toPathfinderMob(mob: Mob): PathfinderMob?

View File

@@ -50,7 +50,7 @@ class EcoFastItemStack(
return foundEnchantments
}
override fun getLevelOnItem(
override fun getEnchantmentLevel(
enchantment: Enchantment,
checkStored: Boolean
): Int {
@@ -183,6 +183,14 @@ class EcoFastItemStack(
return this.flagBits and bitModifier == bitModifier
}
override fun getBaseTag(): PersistentDataContainer =
(if (handle.hasTag()) handle.getTag()!! else CompoundTag()).makePdc(base = true)
override fun setBaseTag(container: PersistentDataContainer?) {
(if (handle.hasTag()) handle.getTag()!! else CompoundTag()).setPdc(container, item = handle)
apply()
}
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
private var flagBits: Int
get() =

View File

@@ -32,9 +32,10 @@ class CommonsInitializer : CommonsInitializerProxy {
isAccessible = true
}
private val pdcRegsitry: Field = Class.forName("org.bukkit.craftbukkit.v1_17_R1.inventory.CraftMetaItem")
private val pdcRegsitry = Class.forName("org.bukkit.craftbukkit.v1_17_R1.inventory.CraftMetaItem")
.getDeclaredField("DATA_TYPE_REGISTRY")
.apply { isAccessible = true }
.get(null) as CraftPersistentDataTypeRegistry
override val nbtTagString = CraftMagicNumbers.NBT.TAG_STRING
@@ -67,29 +68,64 @@ class CommonsInitializer : CommonsInitializerProxy {
override fun toBukkitEntity(entity: net.minecraft.world.entity.LivingEntity): LivingEntity? =
CraftEntity.getEntity(Bukkit.getServer() as CraftServer, entity) as? LivingEntity
override fun makePdc(tag: CompoundTag): PersistentDataContainer {
val pdc = CraftPersistentDataContainer(pdcRegsitry.get(null) as CraftPersistentDataTypeRegistry)
if (tag.contains("PublicBukkitValues")) {
val compound = tag.getCompound("PublicBukkitValues")
val keys = compound.allKeys
override fun makePdc(tag: CompoundTag, base: Boolean): PersistentDataContainer {
fun emptyPdc(): CraftPersistentDataContainer = CraftPersistentDataContainer(pdcRegsitry)
fun CompoundTag?.toPdc(): PersistentDataContainer {
val pdc = emptyPdc()
this ?: return pdc
val keys = this.allKeys
for (key in keys) {
pdc.put(key, compound[key])
pdc.put(key, this[key])
}
return pdc
}
return pdc
return if (base) {
tag.toPdc()
} else {
if (tag.contains("PublicBukkitValues")) {
tag.getCompound("PublicBukkitValues").toPdc()
} else {
emptyPdc()
}
}
}
override fun setPdc(tag: CompoundTag, pdc: PersistentDataContainer) {
pdc as CraftPersistentDataContainer
if (!pdc.isEmpty) {
val bukkitCustomCompound = CompoundTag()
val rawPublicMap: Map<String, Tag> = pdc.raw
override fun setPdc(
tag: CompoundTag,
pdc: PersistentDataContainer?,
item: net.minecraft.world.item.ItemStack?
) {
fun CraftPersistentDataContainer.toTag(): CompoundTag {
val compound = CompoundTag()
val rawPublicMap: Map<String, Tag> = this.raw
for ((key, value) in rawPublicMap) {
bukkitCustomCompound.put(key, value)
compound.put(key, value)
}
return compound
}
pdc as CraftPersistentDataContainer?
if (item != null) {
if (pdc != null && !pdc.isEmpty) {
for (key in tag.allKeys.toSet()) {
tag.remove(key)
}
tag.merge(pdc.toTag())
} else {
item.setTag(null)
}
} else {
if (pdc != null && !pdc.isEmpty) {
tag.put("PublicBukkitValues", pdc.toTag())
} else {
tag.remove("PublicBukkitValues")
}
tag.put("PublicBukkitValues", bukkitCustomCompound)
}
}
}

View File

@@ -32,9 +32,10 @@ class CommonsInitializer : CommonsInitializerProxy {
isAccessible = true
}
private val pdcRegsitry: Field = Class.forName("org.bukkit.craftbukkit.v1_18_R1.inventory.CraftMetaItem")
private val pdcRegsitry = Class.forName("org.bukkit.craftbukkit.v1_18_R1.inventory.CraftMetaItem")
.getDeclaredField("DATA_TYPE_REGISTRY")
.apply { isAccessible = true }
.get(null) as CraftPersistentDataTypeRegistry
override val nbtTagString = CraftMagicNumbers.NBT.TAG_STRING
@@ -67,29 +68,64 @@ class CommonsInitializer : CommonsInitializerProxy {
override fun toBukkitEntity(entity: net.minecraft.world.entity.LivingEntity): LivingEntity? =
CraftEntity.getEntity(Bukkit.getServer() as CraftServer, entity) as? LivingEntity
override fun makePdc(tag: CompoundTag): PersistentDataContainer {
val pdc = CraftPersistentDataContainer(pdcRegsitry.get(null) as CraftPersistentDataTypeRegistry)
if (tag.contains("PublicBukkitValues")) {
val compound = tag.getCompound("PublicBukkitValues")
val keys = compound.allKeys
override fun makePdc(tag: CompoundTag, base: Boolean): PersistentDataContainer {
fun emptyPdc(): CraftPersistentDataContainer = CraftPersistentDataContainer(pdcRegsitry)
fun CompoundTag?.toPdc(): PersistentDataContainer {
val pdc = emptyPdc()
this ?: return pdc
val keys = this.allKeys
for (key in keys) {
pdc.put(key, compound[key])
pdc.put(key, this[key])
}
return pdc
}
return pdc
return if (base) {
tag.toPdc()
} else {
if (tag.contains("PublicBukkitValues")) {
tag.getCompound("PublicBukkitValues").toPdc()
} else {
emptyPdc()
}
}
}
override fun setPdc(tag: CompoundTag, pdc: PersistentDataContainer) {
pdc as CraftPersistentDataContainer
if (!pdc.isEmpty) {
val bukkitCustomCompound = CompoundTag()
val rawPublicMap: Map<String, Tag> = pdc.raw
override fun setPdc(
tag: CompoundTag,
pdc: PersistentDataContainer?,
item: net.minecraft.world.item.ItemStack?
) {
fun CraftPersistentDataContainer.toTag(): CompoundTag {
val compound = CompoundTag()
val rawPublicMap: Map<String, Tag> = this.raw
for ((key, value) in rawPublicMap) {
bukkitCustomCompound.put(key, value)
compound.put(key, value)
}
return compound
}
pdc as CraftPersistentDataContainer?
if (item != null) {
if (pdc != null && !pdc.isEmpty) {
for (key in tag.allKeys.toSet()) {
tag.remove(key)
}
tag.merge(pdc.toTag())
} else {
item.setTag(null)
}
} else {
if (pdc != null && !pdc.isEmpty) {
tag.put("PublicBukkitValues", pdc.toTag())
} else {
tag.remove("PublicBukkitValues")
}
tag.put("PublicBukkitValues", bukkitCustomCompound)
}
}
}

View File

@@ -32,9 +32,10 @@ class CommonsInitializer : CommonsInitializerProxy {
isAccessible = true
}
private val pdcRegsitry: Field = Class.forName("org.bukkit.craftbukkit.v1_18_R2.inventory.CraftMetaItem")
private val pdcRegsitry = Class.forName("org.bukkit.craftbukkit.v1_18_R2.inventory.CraftMetaItem")
.getDeclaredField("DATA_TYPE_REGISTRY")
.apply { isAccessible = true }
.get(null) as CraftPersistentDataTypeRegistry
override val nbtTagString = CraftMagicNumbers.NBT.TAG_STRING
@@ -67,29 +68,64 @@ class CommonsInitializer : CommonsInitializerProxy {
override fun toBukkitEntity(entity: net.minecraft.world.entity.LivingEntity): LivingEntity? =
CraftEntity.getEntity(Bukkit.getServer() as CraftServer, entity) as? LivingEntity
override fun makePdc(tag: CompoundTag): PersistentDataContainer {
val pdc = CraftPersistentDataContainer(pdcRegsitry.get(null) as CraftPersistentDataTypeRegistry)
if (tag.contains("PublicBukkitValues")) {
val compound = tag.getCompound("PublicBukkitValues")
val keys = compound.allKeys
override fun makePdc(tag: CompoundTag, base: Boolean): PersistentDataContainer {
fun emptyPdc(): CraftPersistentDataContainer = CraftPersistentDataContainer(pdcRegsitry)
fun CompoundTag?.toPdc(): PersistentDataContainer {
val pdc = emptyPdc()
this ?: return pdc
val keys = this.allKeys
for (key in keys) {
pdc.put(key, compound[key])
pdc.put(key, this[key])
}
return pdc
}
return pdc
return if (base) {
tag.toPdc()
} else {
if (tag.contains("PublicBukkitValues")) {
tag.getCompound("PublicBukkitValues").toPdc()
} else {
emptyPdc()
}
}
}
override fun setPdc(tag: CompoundTag, pdc: PersistentDataContainer) {
pdc as CraftPersistentDataContainer
if (!pdc.isEmpty) {
val bukkitCustomCompound = CompoundTag()
val rawPublicMap: Map<String, Tag> = pdc.raw
override fun setPdc(
tag: CompoundTag,
pdc: PersistentDataContainer?,
item: net.minecraft.world.item.ItemStack?
) {
fun CraftPersistentDataContainer.toTag(): CompoundTag {
val compound = CompoundTag()
val rawPublicMap: Map<String, Tag> = this.raw
for ((key, value) in rawPublicMap) {
bukkitCustomCompound.put(key, value)
compound.put(key, value)
}
return compound
}
pdc as CraftPersistentDataContainer?
if (item != null) {
if (pdc != null && !pdc.isEmpty) {
for (key in tag.allKeys.toSet()) {
tag.remove(key)
}
tag.merge(pdc.toTag())
} else {
item.setTag(null)
}
} else {
if (pdc != null && !pdc.isEmpty) {
tag.put("PublicBukkitValues", pdc.toTag())
} else {
tag.remove("PublicBukkitValues")
}
tag.put("PublicBukkitValues", bukkitCustomCompound)
}
}
}

View File

@@ -40,7 +40,6 @@ dependencies {
compileOnly 'com.github.EssentialsX:Essentials:2.18.2'
compileOnly 'com.bgsoftware:SuperiorSkyblockAPI:1.8.3'
compileOnly 'com.github.MilkBowl:VaultAPI:1.7'
compileOnly 'com.iridium:IridiumSkyblock:3.1.2'
compileOnly 'com.github.WhipDevelopment:CrashClaim:f9cd7d92eb'
compileOnly 'com.wolfyscript.wolfyutilities:wolfyutilities:3.16.0.0'
compileOnly 'com.github.decentsoftware-eu:decentholograms:2.1.2'

View File

@@ -13,7 +13,7 @@ class AntigriefIridiumSkyblock : AntigriefWrapper {
player: Player,
block: Block
): Boolean {
val api = IridiumSkyblockAPI.getInstance() ?: return true
val api = IridiumSkyblockAPI.getInstance()
return api.getIslandPermission(api.getIslandViaLocation(block.location).orElse(null) ?: return true, api.getUser(player), PermissionType.BLOCK_BREAK)
}
@@ -22,7 +22,7 @@ class AntigriefIridiumSkyblock : AntigriefWrapper {
player: Player,
location: Location
): Boolean {
val api = IridiumSkyblockAPI.getInstance() ?: return true
val api = IridiumSkyblockAPI.getInstance()
return api.getIslandPermission(api.getIslandViaLocation(location).orElse(null) ?: return true, api.getUser(player), PermissionType.BLOCK_BREAK)
}
@@ -31,7 +31,7 @@ class AntigriefIridiumSkyblock : AntigriefWrapper {
player: Player,
block: Block
): Boolean {
val api = IridiumSkyblockAPI.getInstance() ?: return true
val api = IridiumSkyblockAPI.getInstance()
return api.getIslandPermission(api.getIslandViaLocation(block.location).orElse(null) ?: return true, api.getUser(player), PermissionType.BLOCK_PLACE)
}
@@ -40,7 +40,7 @@ class AntigriefIridiumSkyblock : AntigriefWrapper {
player: Player,
victim: LivingEntity
): Boolean {
val api = IridiumSkyblockAPI.getInstance() ?: return true
val api = IridiumSkyblockAPI.getInstance()
return when (victim) {
is Player -> api.getIslandViaLocation(victim.location).orElse(null) != null
@@ -49,7 +49,7 @@ class AntigriefIridiumSkyblock : AntigriefWrapper {
}
override fun canPickupItem(player: Player, location: Location): Boolean {
val api = IridiumSkyblockAPI.getInstance() ?: return true
val api = IridiumSkyblockAPI.getInstance()
return api.getIslandPermission(api.getIslandViaLocation(location).orElse(null) ?: return true, api.getUser(player), PermissionType.PICKUP_ITEMS)
}

View File

@@ -1,3 +1,3 @@
version = 6.33.0
version = 6.34.0
plugin-name = eco
kotlin.code.style = official

Binary file not shown.