mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-22 04:37:42 +01:00
Fixed an issue with 'disable-removed-items'
This commit is contained in:
parent
cc403091a7
commit
cb11502189
@ -4,16 +4,17 @@ import io.lumine.mythic.lib.api.item.NBTItem;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.util.message.Message;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemRestriction;
|
||||
import net.Indyuce.mmoitems.util.MMOUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Interface class between RPG core plugins like Heroes, MythicCore, SkillAPI
|
||||
* and MMOItems
|
||||
* Interface class between RPG core plugins like
|
||||
* Heroes, MythicCore, SkillAPI, MMOCore and MMOItems
|
||||
*
|
||||
* @author indyuce
|
||||
* @author Jules
|
||||
*/
|
||||
public abstract class RPGPlayer {
|
||||
private final PlayerData playerData;
|
||||
@ -106,7 +107,9 @@ public abstract class RPGPlayer {
|
||||
* if it fails (returning true even if it is not met).
|
||||
* @see ItemRestriction#isDynamic()
|
||||
*/
|
||||
public boolean canUse(NBTItem item, boolean message, boolean allowDynamic) {
|
||||
public boolean canUse(@NotNull NBTItem item, boolean message, boolean allowDynamic) {
|
||||
|
||||
// Unidentification
|
||||
if (item.hasTag("MMOITEMS_UNIDENTIFIED_ITEM")) {
|
||||
if (message) {
|
||||
Message.UNIDENTIFIED_ITEM.format(ChatColor.RED).send(player.getPlayer());
|
||||
@ -115,13 +118,13 @@ public abstract class RPGPlayer {
|
||||
return false;
|
||||
}
|
||||
|
||||
//REQ//MMOItems. Log("Checking REQS");
|
||||
for (ItemRestriction condition : MMOItems.plugin.getStats().getItemRestrictionStats())
|
||||
if (!condition.isDynamic() || !allowDynamic)
|
||||
if (!condition.canUse(this, item, message))
|
||||
return false;
|
||||
// Item has been disabled
|
||||
if (MMOItems.plugin.getLanguage().disableRemovedItems && MMOUtils.hasBeenRemoved(item)) return false;
|
||||
|
||||
// Stat-based requirements
|
||||
for (ItemRestriction condition : MMOItems.plugin.getStats().getItemRestrictionStats())
|
||||
if (!condition.isDynamic() || !allowDynamic) if (!condition.canUse(this, item, message)) return false;
|
||||
|
||||
//REQ//MMOItems. Log(" \u00a7a> Success use");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public class ConfigManager implements Reloadable {
|
||||
private final Map<PotionEffectType, String> potionNames = new HashMap<>();
|
||||
|
||||
// Cached config options
|
||||
public boolean replaceMushroomDrops, worldGenEnabled, upgradeRequirementsCheck, keepSoulboundOnDeath, rerollOnItemUpdate, opStatsEnabled;
|
||||
public boolean replaceMushroomDrops, worldGenEnabled, upgradeRequirementsCheck, keepSoulboundOnDeath, rerollOnItemUpdate, opStatsEnabled, disableRemovedItems;
|
||||
public String abilitySplitter;
|
||||
public double soulboundBaseDamage, soulboundPerLvlDamage, levelSpread;
|
||||
public NumericStatFormula defaultItemCapacity;
|
||||
@ -174,6 +174,7 @@ public class ConfigManager implements Reloadable {
|
||||
keepSoulboundOnDeath = MMOItems.plugin.getConfig().getBoolean("soulbound.keep-on-death");
|
||||
rerollOnItemUpdate = MMOItems.plugin.getConfig().getBoolean("item-revision.reroll-when-updated");
|
||||
levelSpread = MMOItems.plugin.getConfig().getDouble("item-level-spread");
|
||||
disableRemovedItems = MMOItems.plugin.getConfig().getBoolean("disable-removed-items");
|
||||
|
||||
opStatsEnabled = MMOItems.plugin.getConfig().getBoolean("op-item-stats.enabled");
|
||||
opStats.clear();
|
||||
|
@ -38,6 +38,21 @@ public class MMOUtils {
|
||||
return particle.getDataType() == Particle.DustOptions.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should cancel interaction if one of the two cases:
|
||||
* - the item type no longer exists
|
||||
* - no template with the given (type, id) pair can be found
|
||||
*
|
||||
* @param item Target item
|
||||
* @return If the item USED to exist, but no longer does
|
||||
*/
|
||||
public static boolean hasBeenRemoved(@NotNull NBTItem item) {
|
||||
if (!item.hasType()) return false;
|
||||
|
||||
final @Nullable String type = item.getType();
|
||||
return MMOUtils.isNonEmpty(type) && (!Type.isValid(type) || !MMOItems.plugin.getTemplates().hasTemplate(Type.get(type), item.getString("MMOITEMS_ITEM_ID")));
|
||||
}
|
||||
|
||||
public static boolean isNonEmpty(@Nullable String str) {
|
||||
return str != null && !str.isEmpty();
|
||||
}
|
||||
|
@ -28,7 +28,8 @@ public class MMOItemsBukkit {
|
||||
|
||||
if (plugin.getConfig().getBoolean("dropped-items.tier-glow") || plugin.getConfig().getBoolean("dropped-items.hints"))
|
||||
Bukkit.getPluginManager().registerEvents(new DroppedItems(plugin.getConfig().getConfigurationSection("dropped-items")), plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new DisabledItemsListener(plugin), plugin);
|
||||
if (plugin.getLanguage().disableRemovedItems)
|
||||
Bukkit.getPluginManager().registerEvents(new DisabledItemsListener(plugin), plugin);
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(plugin, () -> Bukkit.getOnlinePlayers().forEach(player -> PlayerData.get(player).updateStats()), 100, 20);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import io.lumine.mythic.lib.api.item.NBTItem;
|
||||
import io.lumine.mythic.lib.damage.MeleeAttackMetadata;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import net.Indyuce.mmoitems.util.MMOUtils;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
@ -21,6 +22,8 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* mmoitems
|
||||
@ -41,7 +44,7 @@ public class DisabledItemsListener implements Listener {
|
||||
if (!event.hasItem())
|
||||
return;
|
||||
NBTItem item = MythicLib.plugin.getVersion().getWrapper().getNBTItem(event.getItem());
|
||||
if (this.shouldCancel(item))
|
||||
if (MMOUtils.hasBeenRemoved(item))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@ -51,7 +54,7 @@ public class DisabledItemsListener implements Listener {
|
||||
return;
|
||||
ItemStack weaponUsed = event.getPlayer().getInventory().getItem(((MeleeAttackMetadata) event.getAttack()).getHand().toBukkit());
|
||||
NBTItem item = MythicLib.plugin.getVersion().getWrapper().getNBTItem(weaponUsed);
|
||||
if (this.shouldCancel(item))
|
||||
if (MMOUtils.hasBeenRemoved(item))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@ -62,7 +65,7 @@ public class DisabledItemsListener implements Listener {
|
||||
return;
|
||||
|
||||
final NBTItem item = MythicLib.plugin.getVersion().getWrapper().getNBTItem(player.getInventory().getItemInMainHand());
|
||||
if (this.shouldCancel(item))
|
||||
if (MMOUtils.hasBeenRemoved(item))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@ -73,7 +76,7 @@ public class DisabledItemsListener implements Listener {
|
||||
return;
|
||||
|
||||
NBTItem item = MythicLib.plugin.getVersion().getWrapper().getNBTItem(player.getInventory().getItemInMainHand());
|
||||
if (this.shouldCancel(item))
|
||||
if (MMOUtils.hasBeenRemoved(item))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@ -84,7 +87,7 @@ public class DisabledItemsListener implements Listener {
|
||||
return;
|
||||
|
||||
NBTItem item = MythicLib.plugin.getVersion().getWrapper().getNBTItem(event.getCursor());
|
||||
if (this.shouldCancel(item))
|
||||
if (MMOUtils.hasBeenRemoved(item))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@ -94,21 +97,14 @@ public class DisabledItemsListener implements Listener {
|
||||
return;
|
||||
|
||||
final NBTItem item = NBTItem.get(event.getBow());
|
||||
if (shouldCancel(item))
|
||||
if (MMOUtils.hasBeenRemoved(item))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void handleVanillaEatenConsumables(PlayerItemConsumeEvent event) {
|
||||
NBTItem item = MythicLib.plugin.getVersion().getWrapper().getNBTItem(event.getItem());
|
||||
if (shouldCancel(item))
|
||||
if (MMOUtils.hasBeenRemoved(item))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
private boolean shouldCancel(NBTItem item) {
|
||||
if (!item.hasType() || !plugin.getConfig().getBoolean("disable-removed-items", true))
|
||||
return false;
|
||||
return !Type.isValid(item.getType());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user