diff --git a/build.gradle.kts b/build.gradle.kts index 29ac5b1..a104f44 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } group = "net.azisaba" -version = "1.15.2+6.17.3" +version = "6.17.4+1.15.2" java { toolchain.languageVersion.set(JavaLanguageVersion.of(8)) @@ -63,6 +63,7 @@ dependencies { implementation("org.mariadb.jdbc:mariadb-java-client:3.0.6") implementation("org.yaml:snakeyaml:2.0") 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") diff --git a/src/main/java/com/github/mori01231/lifecore/gui/DropProtectScreen.java b/src/main/java/com/github/mori01231/lifecore/gui/DropProtectScreen.java index f59cc55..9b7a410 100644 --- a/src/main/java/com/github/mori01231/lifecore/gui/DropProtectScreen.java +++ b/src/main/java/com/github/mori01231/lifecore/gui/DropProtectScreen.java @@ -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; @@ -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 @@ -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; } diff --git a/src/main/java/com/github/mori01231/lifecore/gui/TrashProtectScreen.java b/src/main/java/com/github/mori01231/lifecore/gui/TrashProtectScreen.java index b67f972..1598171 100644 --- a/src/main/java/com/github/mori01231/lifecore/gui/TrashProtectScreen.java +++ b/src/main/java/com/github/mori01231/lifecore/gui/TrashProtectScreen.java @@ -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; @@ -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) { @@ -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 + "閉じる"); @@ -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; } diff --git a/src/main/java/com/github/mori01231/lifecore/listener/DropProtectListener.java b/src/main/java/com/github/mori01231/lifecore/listener/DropProtectListener.java index e281db1..df6c8ef 100644 --- a/src/main/java/com/github/mori01231/lifecore/listener/DropProtectListener.java +++ b/src/main/java/com/github/mori01231/lifecore/listener/DropProtectListener.java @@ -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; @@ -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(); @@ -59,7 +64,7 @@ public void onDrop(PlayerDropItemEvent e) { entityItem.getDataWatcher().set(itemStackDataWatcherObject, new net.minecraft.server.v1_15_R1.ItemStack(Items.AIR)); entityItem.getDataWatcher().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); diff --git a/src/main/java/com/github/mori01231/lifecore/listener/TrashListener.kt b/src/main/java/com/github/mori01231/lifecore/listener/TrashListener.kt index e292cc7..ab2d41f 100644 --- a/src/main/java/com/github/mori01231/lifecore/listener/TrashListener.kt +++ b/src/main/java/com/github/mori01231/lifecore/listener/TrashListener.kt @@ -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 @@ -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) ->