Skip to content

Commit

Permalink
Improve dropprotect and trashprotect
Browse files Browse the repository at this point in the history
with lifepvelevel plugin, you can now prevent accidental drops/trashes of items that has pve level set
  • Loading branch information
acrylic-style committed Nov 5, 2024
1 parent 6d65c09 commit fea52ca
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 93 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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")
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.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);
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

0 comments on commit fea52ca

Please sign in to comment.