Skip to content

Commit

Permalink
work for 1.20.6
Browse files Browse the repository at this point in the history
  • Loading branch information
acrylic-style committed Jul 17, 2024
1 parent 68c7c08 commit ddb906d
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 93 deletions.
9 changes: 6 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ plugins {
kotlin("jvm") version "1.9.22"
kotlin("plugin.serialization") version "1.9.22"
id("com.github.johnrengelman.shadow") version "7.0.0"
id("io.papermc.paperweight.userdev") version "1.7.1"
java
`maven-publish`
}

group = "net.azisaba"
version = "1.19.4+6.12.2"
version = "1.20.6+6.12.2"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
toolchain.languageVersion.set(JavaLanguageVersion.of(21))

withJavadocJar()
withSourcesJar()
Expand Down Expand Up @@ -70,7 +71,6 @@ dependencies {
compileOnly("net.azisaba:ItemStash:1.0.0-SNAPSHOT")
//noinspection VulnerableLibrariesLocal
compileOnly("com.destroystokyo.paper:paper-api:1.15.2-R0.1-SNAPSHOT")
compileOnly("org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT")
compileOnly("io.lumine:Mythic-Dist:5.2.1")
compileOnly("com.github.MilkBowl:VaultAPI:1.7")
compileOnly("com.github.MyPetORG.MyPet:mypet-api:5c8ceeac6a")
Expand All @@ -80,8 +80,11 @@ dependencies {
exclude("nl.lolmewn.stats", "Stats")
exclude("me.staartvin", "PluginLibrary")
}
paperweight.paperDevBundle("1.20.6-R0.1-SNAPSHOT")
}

paperweight.reobfArtifactConfiguration = io.papermc.paperweight.userdev.ReobfArtifactConfiguration.MOJANG_PRODUCTION

publishing {
repositories {
maven {
Expand Down
169 changes: 87 additions & 82 deletions src/main/java/com/github/mori01231/lifecore/util/ItemUtil.kt
Original file line number Diff line number Diff line change
@@ -1,112 +1,117 @@
package com.github.mori01231.lifecore.util;
package com.github.mori01231.lifecore.util

import net.azisaba.itemstash.ItemStash;
import net.minecraft.nbt.NBTTagCompound;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import net.azisaba.itemstash.ItemStash
import net.minecraft.core.component.DataComponents
import net.minecraft.world.item.component.CustomData
import org.bukkit.Material
import org.bukkit.attribute.Attribute
import org.bukkit.attribute.AttributeModifier
import org.bukkit.craftbukkit.inventory.CraftItemStack
import org.bukkit.enchantments.Enchantment
import org.bukkit.entity.Player
import org.bukkit.inventory.EquipmentSlot
import org.bukkit.inventory.ItemStack
import org.jetbrains.annotations.Contract
import java.util.*
import java.util.function.Consumer

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.function.Consumer;

public class ItemUtil {
object ItemUtil {
@JvmStatic
@Contract("null -> false")
public static boolean isProbablyAdminSword(@Nullable ItemStack stack) {
fun isProbablyAdminSword(stack: ItemStack?): Boolean {
if (stack == null ||
stack.getType().isAir() ||
!stack.hasItemMeta() ||
!stack.getItemMeta().hasAttributeModifiers()) return false;
return Objects.requireNonNull(stack.getItemMeta().getAttributeModifiers())
.get(Attribute.GENERIC_ATTACK_DAMAGE)
.stream()
.anyMatch(mod -> mod.getAmount() >= 9999);
stack.type.isAir ||
!stack.hasItemMeta() ||
!stack.itemMeta.hasAttributeModifiers()
) return false
return stack.itemMeta.attributeModifiers!![Attribute.GENERIC_ATTACK_DAMAGE]
.stream()
.anyMatch { mod: AttributeModifier -> mod.amount >= 9999 }
}

@JvmStatic
@Contract("null -> null")
public static @Nullable String getMythicType(@Nullable ItemStack stack) {
if (stack == null || stack.getType().isAir()) return null;
NBTTagCompound tag = CraftItemStack.asNMSCopy(stack).u(); // getTag
if (tag == null) return null;
String type = tag.l("MYTHIC_TYPE"); // getString
if (type == null || type.isEmpty()) return null;
return type;
fun getCustomData(stack: ItemStack?): CustomData? {
if (stack == null || stack.type.isAir) return null
return CraftItemStack.asNMSCopy(stack).components[DataComponents.CUSTOM_DATA]
}

@Contract("null, _ -> null")
public static @Nullable String getStringTag(@Nullable ItemStack stack, @NotNull String key) {
if (stack == null || stack.getType().isAir()) return null;
NBTTagCompound tag = CraftItemStack.asNMSCopy(stack).u(); // getTag
if (tag == null) return null;
return tag.l(key); // getString
@JvmStatic
@Contract("null -> null")
fun getMythicType(stack: ItemStack?): String? {
val data = getCustomData(stack) ?: return null
if (!data.contains("MYTHIC_TYPE")) return null
val type = data.copyTag().getString("MYTHIC_TYPE")
if (type.isEmpty()) return null
return type
}

public static @NotNull String toString(@NotNull ItemStack stack) {
List<String> props = new ArrayList<>();
props.add("[Type: " + stack.getType().name() + "]");
props.add("[Amount: " + stack.getAmount() + "]");
ItemMeta meta = stack.getItemMeta();
@JvmStatic
@Contract("null, _ -> null")
fun getStringTag(stack: ItemStack?, key: String): String? =
getCustomData(stack)?.copyTag()?.getString(key)

@JvmStatic
fun toString(stack: ItemStack): String {
val props: MutableList<String> = ArrayList()
props.add("[Type: " + stack.type.name + "]")
props.add("[Amount: " + stack.amount + "]")
val meta = stack.itemMeta
if (meta != null) {
if (meta.hasDisplayName()) props.add("[Name: " + meta.getDisplayName() + "]");
if (meta.hasLore()) props.add("[Lore: " + Objects.requireNonNull(meta.getLore()).size() + " entries]");
if (meta.hasCustomModelData()) props.add("[CustomModelData: " + meta.getCustomModelData() + "]");
if (getMythicType(stack) != null) props.add("[MMID: " + getMythicType(stack) + "]");
if (meta.hasEnchants()) meta.getEnchants().forEach((enchant, level) -> props.add("[Enchant: " + enchant.getKey() + " " + level + "]"));
if (meta.hasDisplayName()) props.add("[Name: " + meta.displayName + "]")
if (meta.hasLore()) props.add("[Lore: " + Objects.requireNonNull(meta.lore).size + " entries]")
if (meta.hasCustomModelData()) props.add("[CustomModelData: " + meta.customModelData + "]")
if (getMythicType(stack) != null) props.add("[MMID: " + getMythicType(stack) + "]")
if (meta.hasEnchants()) meta.enchants.forEach { (enchant: Enchantment, level: Int) -> props.add("[Enchant: " + enchant.key + " " + level + "]") }
}
return String.join("", props);
return java.lang.String.join("", props)
}

public static @NotNull ItemStack createItemStack(@NotNull Material material, int amount, @NotNull Consumer<ItemStack> action) {
ItemStack stack = new ItemStack(material, amount);
action.accept(stack);
return stack;
@JvmStatic
fun createItemStack(material: Material, amount: Int, action: Consumer<ItemStack>): ItemStack {
val stack = ItemStack(material, amount)
action.accept(stack)
return stack
}

public static @NotNull ItemStack createItemStack(@NotNull Material material, @NotNull String displayName, @NotNull List<String> lore) {
return createItemStack(material, 1, item -> {
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(displayName);
if (!lore.isEmpty()) {
meta.setLore(lore);
@JvmStatic
fun createItemStack(material: Material, displayName: String, lore: List<String?>): ItemStack {
return createItemStack(material, 1) { item: ItemStack ->
val meta = item.itemMeta
meta.setDisplayName(displayName)
if (lore.isNotEmpty()) {
meta.lore = lore
}
item.setItemMeta(meta);
});
item.setItemMeta(meta)
}
}

public static boolean addToStashIfEnabled(@NotNull UUID uuid, @NotNull ItemStack item) {
@JvmStatic
fun addToStashIfEnabled(uuid: UUID, item: ItemStack): Boolean {
try {
Class.forName("net.azisaba.itemstash.ItemStash");
ItemStash.getInstance().addItemToStash(uuid, item);
return true;
} catch (ClassNotFoundException ignored) {
return false;
Class.forName("net.azisaba.itemstash.ItemStash")
ItemStash.getInstance().addItemToStash(uuid, item)
return true
} catch (ignored: ClassNotFoundException) {
return false
}
}

@SuppressWarnings("ConstantValue")
public static boolean isEquippedInAnySlot(@NotNull Player player, @NotNull ItemStack stack) {
PlayerInventory inventory = player.getInventory();
for (EquipmentSlot slot : EquipmentSlot.values()) {
if (inventory.getItem(slot) != null && inventory.getItem(slot).equals(stack)) return true;
@JvmStatic
fun isEquippedInAnySlot(player: Player, stack: ItemStack): Boolean {
val inventory = player.inventory
for (slot in EquipmentSlot.entries) {
if (inventory.getItem(slot) != null && inventory.getItem(slot) == stack) return true
}
return false;
return false
}

public static boolean isEquippedInAnySlot(@NotNull Player player, @NotNull String mythicType) {
PlayerInventory inventory = player.getInventory();
for (EquipmentSlot slot : EquipmentSlot.values()) {
if (mythicType.equals(getMythicType(inventory.getItem(slot)))) return true;
@JvmStatic
fun isEquippedInAnySlot(player: Player, mythicType: String): Boolean {
val inventory = player.inventory
for (slot in EquipmentSlot.entries) {
if (mythicType == getMythicType(inventory.getItem(slot))) return true
}
return false;
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import com.github.mori01231.lifecore.LifeCore;
import com.github.mori01231.lifecore.TableKey;
import io.netty.channel.Channel;
import net.minecraft.network.NetworkManager;
import net.minecraft.server.network.PlayerConnection;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/github/mori01231/lifecore/util/PromptSign.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.github.mori01231.lifecore.util

import com.github.mori01231.lifecore.LifeCore
import net.minecraft.core.BlockPosition
import net.minecraft.network.protocol.game.PacketPlayOutOpenSignEditor
import net.minecraft.core.BlockPos
import net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer
import org.bukkit.craftbukkit.entity.CraftPlayer
import org.bukkit.entity.Player
import org.bukkit.plugin.java.JavaPlugin
import java.util.*
Expand All @@ -26,8 +26,8 @@ object PromptSign {
player.sendBlockChange(loc0, origBlockData)
action.accept(it)
}
(player as CraftPlayer).handle.b
.a(PacketPlayOutOpenSignEditor(BlockPosition(loc0.blockX, loc0.blockY, loc0.blockZ)))
(player as CraftPlayer).handle.connection
.sendPacket(ClientboundOpenSignEditorPacket(BlockPos(loc0.blockX, loc0.blockY, loc0.blockZ), true))
})
}
}

0 comments on commit ddb906d

Please sign in to comment.