Skip to content

Commit

Permalink
Merge branch 'master' into ver/1.21.1
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle.kts
#	src/main/java/com/github/mori01231/lifecore/util/ItemUtil.java
  • Loading branch information
acrylic-style committed Nov 5, 2024
2 parents 6771e3a + 7ff4536 commit 75c7e28
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 98 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
}

group = "net.azisaba"
version = "1.21.1+6.17.2"
version = "6.17.4+1.21.1"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
Expand Down Expand Up @@ -64,6 +64,7 @@ dependencies {
implementation("org.mariadb.jdbc:mariadb-java-client:3.5.0")
implementation("org.yaml:snakeyaml:2.3")
implementation("xyz.acrylicstyle.java-util:expression:2.0.0-SNAPSHOT")
implementation("net.azisaba:lifepvelevel:1.3.0")
compileOnly("net.azisaba:JoinFilter:1.0.0")
compileOnly("net.azisaba.ballotbox:receiver:1.0.1")
compileOnly("net.azisaba.azipluginmessaging:api:4.0.3")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
package com.github.mori01231.lifecore.gui;

import com.github.mori01231.lifecore.LifeCore;
import com.github.mori01231.lifecore.util.ItemUtil;
import net.azisaba.rarity.api.RarityAPIProvider;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;

public class DropProtectScreen implements InventoryHolder {
private final Inventory inventory = Bukkit.createInventory(this, 9, "DropProtect");
private final Inventory inventory = Bukkit.createInventory(this, 18, "DropProtect");
private final LifeCore plugin;
private final Player player;

Expand All @@ -44,77 +39,8 @@ public void reset() {
String mythicLore = plugin.getDropProtectConfig().contains(player.getUniqueId(), "mythic") ? ChatColor.GREEN + "有効" : ChatColor.RED + "無効";
String specialName = RarityAPIProvider.get().getRarityById("special").getDisplayName(player);
String specialLore = plugin.getDropProtectConfig().contains(player.getUniqueId(), "special") ? ChatColor.GREEN + "有効" : ChatColor.RED + "無効";
inventory.setItem(0, ItemUtil.createItemStack(Material.PAPER, 1, item -> {
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setDisplayName(ChatColor.WHITE + "レア度が付与されていないアイテム");
meta.setLore(Collections.singletonList(noRarityLore));
item.setItemMeta(meta);
}
}));
inventory.setItem(1, ItemUtil.createItemStack(Material.COBBLESTONE, 1, item -> {
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', commonName));
meta.setLore(Collections.singletonList(commonLore));
item.setItemMeta(meta);
}
}));
inventory.setItem(2, ItemUtil.createItemStack(Material.IRON_BLOCK, 1, item -> {
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', uncommonName));
meta.setLore(Collections.singletonList(uncommonLore));
item.setItemMeta(meta);
}
}));
inventory.setItem(3, ItemUtil.createItemStack(Material.GOLD_BLOCK, 1, item -> {
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', rareName));
meta.setLore(Collections.singletonList(rareLore));
item.setItemMeta(meta);
}
}));
inventory.setItem(4, ItemUtil.createItemStack(Material.EMERALD_BLOCK, 1, item -> {
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', epicName));
meta.setLore(Collections.singletonList(epicLore));
item.setItemMeta(meta);
}
}));
inventory.setItem(5, ItemUtil.createItemStack(Material.DIAMOND_BLOCK, 1, item -> {
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', legendaryName));
meta.setLore(Collections.singletonList(legendaryLore));
item.setItemMeta(meta);
}
}));
inventory.setItem(6, ItemUtil.createItemStack(Material.ENCHANTED_GOLDEN_APPLE, 1, item -> {
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', mythicName));
meta.setLore(Collections.singletonList(mythicLore));
item.setItemMeta(meta);
}
}));
inventory.setItem(7, ItemUtil.createItemStack(Material.NETHER_STAR, 1, item -> {
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', specialName));
meta.setLore(Collections.singletonList(specialLore));
item.setItemMeta(meta);
}
}));
inventory.setItem(8, ItemUtil.createItemStack(Material.BARRIER, 1, item -> {
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setDisplayName(ChatColor.RED + "閉じる");
item.setItemMeta(meta);
}
}));
String hasPvELevelLore = plugin.getDropProtectConfig().contains(player.getUniqueId(), "has_pve_level") ? ChatColor.GREEN + "有効" : ChatColor.RED + "無効";
TrashProtectScreen.setItems(noRarityLore, commonName, commonLore, uncommonName, uncommonLore, rareName, rareLore, epicName, epicLore, legendaryName, legendaryLore, mythicName, mythicLore, specialName, specialLore, hasPvELevelLore, inventory);
}

@NotNull
Expand Down Expand Up @@ -174,6 +100,10 @@ public void onClick(InventoryClickEvent e) {
break;
}
case 8: {
plugin.getDropProtectConfig().toggle(screen.player.getUniqueId(), "has_pve_level");
break;
}
case 17: {
screen.player.closeInventory();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.Collections;

public class TrashProtectScreen implements InventoryHolder {
private final Inventory inventory = Bukkit.createInventory(this, 9, "TrashProtect");
private final Inventory inventory = Bukkit.createInventory(this, 18, "TrashProtect");
private final LifeCore plugin;
private final Player player;

Expand All @@ -44,6 +44,11 @@ public void reset() {
String mythicLore = plugin.getTrashProtectConfig().contains(player.getUniqueId(), "mythic") ? ChatColor.GREEN + "有効" : ChatColor.RED + "無効";
String specialName = RarityAPIProvider.get().getRarityById("special").getDisplayName(player);
String specialLore = plugin.getTrashProtectConfig().contains(player.getUniqueId(), "special") ? ChatColor.GREEN + "有効" : ChatColor.RED + "無効";
String hasPvELevelLore = plugin.getTrashProtectConfig().contains(player.getUniqueId(), "has_pve_level") ? ChatColor.GREEN + "有効" : ChatColor.RED + "無効";
setItems(noRarityLore, commonName, commonLore, uncommonName, uncommonLore, rareName, rareLore, epicName, epicLore, legendaryName, legendaryLore, mythicName, mythicLore, specialName, specialLore, hasPvELevelLore, inventory);
}

static void setItems(String noRarityLore, String commonName, String commonLore, String uncommonName, String uncommonLore, String rareName, String rareLore, String epicName, String epicLore, String legendaryName, String legendaryLore, String mythicName, String mythicLore, String specialName, String specialLore, String hasPvELevelLore, Inventory inventory) {
inventory.setItem(0, ItemUtil.createItemStack(Material.PAPER, 1, item -> {
ItemMeta meta = item.getItemMeta();
if (meta != null) {
Expand Down Expand Up @@ -108,7 +113,15 @@ public void reset() {
item.setItemMeta(meta);
}
}));
inventory.setItem(8, ItemUtil.createItemStack(Material.BARRIER, 1, item -> {
inventory.setItem(8, ItemUtil.createItemStack(Material.MAP, 1, item -> {
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setDisplayName(ChatColor.YELLOW + "PvEレベルが付与されているアイテム");
meta.setLore(Collections.singletonList(hasPvELevelLore));
item.setItemMeta(meta);
}
}));
inventory.setItem(17, ItemUtil.createItemStack(Material.BARRIER, 1, item -> {
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setDisplayName(ChatColor.RED + "閉じる");
Expand Down Expand Up @@ -174,6 +187,10 @@ public void onClick(InventoryClickEvent e) {
break;
}
case 8: {
plugin.getTrashProtectConfig().toggle(screen.player.getUniqueId(), "has_pve_level");
break;
}
case 17: {
screen.player.closeInventory();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.mori01231.lifecore.LifeCore;
import net.azisaba.itemstash.ItemStash;
import net.azisaba.lifepvelevel.util.Util;
import net.azisaba.rarity.api.Rarity;
import net.azisaba.rarity.api.RarityAPI;
import net.azisaba.rarity.api.RarityAPIProvider;
Expand Down Expand Up @@ -32,14 +33,18 @@ public DropProtectListener(@NotNull LifeCore plugin) {
public void onDrop(PlayerDropItemEvent e) {
Rarity rarity = rarityAPI.getRarityByItemStack(e.getItemDrop().getItemStack());
boolean shouldCancel;
if (rarity == null) {
if (plugin.getDropProtectConfig().contains(e.getPlayer().getUniqueId(), "no_rarity")) {
shouldCancel = true;
if (plugin.getDropProtectConfig().contains(e.getPlayer().getUniqueId(), "has_pve_level") && Util.getRequiredLevel(e.getItemDrop().getItemStack()) > 0) {
shouldCancel = true;
} else {
if (rarity == null) {
if (plugin.getDropProtectConfig().contains(e.getPlayer().getUniqueId(), "no_rarity")) {
shouldCancel = true;
} else {
return;
}
} else {
return;
shouldCancel = plugin.getDropProtectConfig().contains(e.getPlayer().getUniqueId(), rarity.getId());
}
} else {
shouldCancel = plugin.getDropProtectConfig().contains(e.getPlayer().getUniqueId(), rarity.getId());
}
if (shouldCancel) {
ItemStack stack = e.getItemDrop().getItemStack();
Expand All @@ -59,7 +64,7 @@ public void onDrop(PlayerDropItemEvent e) {
entityItem.getEntityData().set(itemStackDataWatcherObject, new net.minecraft.world.item.ItemStack(Items.AIR));
entityItem.getEntityData().markDirty(itemStackDataWatcherObject);

e.getPlayer().sendMessage(ChatColor.RED + "このレア度のアイテムはドロップできません。");
e.getPlayer().sendMessage(ChatColor.RED + "このアイテムはドロップできません。");
e.getPlayer().sendMessage(ChatColor.AQUA + "/dropprotect" + ChatColor.GOLD + "で設定を変更できます。");
e.getPlayer().getInventory().addItem(stack).forEach((i, s) -> {
itemStash.addItemToStash(e.getPlayer().getUniqueId(), s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.github.mori01231.lifecore.LifeCore
import com.github.mori01231.lifecore.TrashInventory
import com.github.mori01231.lifecore.util.ItemUtil
import net.azisaba.itemstash.ItemStash
import net.azisaba.lifepvelevel.util.Util
import net.azisaba.rarity.api.Rarity
import net.azisaba.rarity.api.RarityAPIProvider
import org.bukkit.Bukkit
Expand All @@ -26,15 +27,20 @@ class TrashListener(private val plugin: LifeCore) : Listener {
for (i in 0..<e.inventory.size) {
val item = e.inventory.getItem(i) ?: continue
val rarity: Rarity? = RarityAPIProvider.get().getRarityByItemStack(item)
val shouldCancel = if (rarity == null) {
if (plugin.trashProtectConfig.contains(e.whoClicked.uniqueId, "no_rarity")) {
val shouldCancel =
if (plugin.trashProtectConfig.contains(e.whoClicked.uniqueId, "has_pve_level") && Util.getRequiredLevel(item) > 0) {
true
} else {
continue
if (rarity == null) {
if (plugin.trashProtectConfig.contains(e.whoClicked.uniqueId, "no_rarity")) {
true
} else {
continue
}
} else {
plugin.trashProtectConfig.contains(e.whoClicked.uniqueId, rarity.id)
}
}
} else {
plugin.trashProtectConfig.contains(e.whoClicked.uniqueId, rarity.id)
}
if (shouldCancel) {
e.inventory.setItem(i, null)
e.whoClicked.inventory.addItem(item).forEach { (_, s) ->
Expand Down
32 changes: 27 additions & 5 deletions src/main/java/com/github/mori01231/lifecore/util/ItemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

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

public class ItemUtil {
Expand Down Expand Up @@ -52,13 +49,28 @@ public static boolean isProbablyAdminSword(@Nullable ItemStack stack) {
return type;
}

@Contract("null, _ -> null")
public static @Nullable NBTBase getTag(@Nullable ItemStack stack, @NotNull String key) {
if (stack == null || stack.getType().isAir()) return null;
NBTTagCompound tag = CraftItemStack.asNMSCopy(stack).getTag();
if (tag == null) return null;
return tag.get(key);
}

@Contract("null, _ -> null")
public static @Nullable String getStringTag(@Nullable ItemStack stack, @NotNull String key) {
CompoundTag tag = getCustomData(stack);
if (tag == null) return null;
return tag.getString(key);
}

public static int getIntTag(@Nullable ItemStack stack, @NotNull String key) {
if (stack == null || stack.getType().isAir()) return 0;
NBTTagCompound tag = CraftItemStack.asNMSCopy(stack).getTag();
if (tag == null) return 0;
return tag.getInt(key);
}

@Contract("null, _ -> null")
public static @Nullable byte[] getByteArrayTag(@Nullable ItemStack stack, @NotNull String key) {
CompoundTag tag = getCustomData(stack);
Expand Down Expand Up @@ -170,13 +182,23 @@ public static ItemStack backupTag(@Nullable ItemStack stack) {
return setTag(stack, "backup", tag);
}

private static final Set<String> RESTORE_BYPASS_SET = new HashSet<>(Collections.singletonList("Damage"));

@Contract("null -> null")
public static ItemStack restoreTag(@Nullable ItemStack stack) {
CompoundTag tag = getCustomData(stack);
if (tag == null) return stack;
CompoundTag backup = tag.getCompound("backup");
if (backup.isEmpty()) return stack;
return setTag(stack, null, backup);
ItemStack newStack = setTag(stack, null, backup);
for (String bypassTag : RESTORE_BYPASS_SET) {
if (containsTag(stack, bypassTag)) {
NBTBase value = getTag(stack, bypassTag);
assert value != null;
newStack = setTag(newStack, bypassTag, value);
}
}
return newStack;
}

public static boolean containsTag(@Nullable ItemStack stack, @NotNull String key) {
Expand Down

0 comments on commit 75c7e28

Please sign in to comment.