This commit is contained in:
Indyuce 2020-01-18 18:14:01 +01:00
commit 69027e83f2
10 changed files with 153 additions and 105 deletions

View File

@ -1,14 +1,5 @@
package net.Indyuce.mmoitems.api.interaction;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.ItemTier;
@ -23,7 +14,17 @@ import net.Indyuce.mmoitems.stat.Upgrade_Stat.UpgradeData;
import net.Indyuce.mmoitems.stat.data.EffectListData;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.item.ItemTag;
import net.mmogroup.mmolib.api.item.NBTItem;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.List;
public class Consumable extends UseItem {
public Consumable(Player player, NBTItem item, Type type) {
@ -215,27 +216,29 @@ public class Consumable extends UseItem {
}
public boolean useWithoutItem(boolean consume) {
if (getNBTItem().getBoolean("MMOITEMS_INEDIBLE"))
NBTItem nbtItem = getNBTItem();
if (nbtItem.getBoolean("MMOITEMS_INEDIBLE"))
return false;
double health = getNBTItem().getStat("RESTORE_HEALTH");
double health = nbtItem.getStat("RESTORE_HEALTH");
if (health > 0)
MMOUtils.heal(player, health);
double food = getNBTItem().getStat("RESTORE_FOOD");
double food = nbtItem.getStat("RESTORE_FOOD");
if (food > 0)
MMOUtils.feed(player, (int) food);
double saturation = getNBTItem().getStat("RESTORE_SATURATION");
double saturation = nbtItem.getStat("RESTORE_SATURATION");
saturation = saturation == 0 ? 6 : saturation;
if (saturation > 0)
MMOUtils.saturate(player, (float) saturation);
double mana = getNBTItem().getStat("RESTORE_MANA");
double mana = nbtItem.getStat("RESTORE_MANA");
if (mana > 0)
playerData.getRPG().giveMana(mana);
double stamina = getNBTItem().getStat("RESTORE_STAMINA");
double stamina = nbtItem.getStat("RESTORE_STAMINA");
if (stamina > 0)
playerData.getRPG().giveStamina(stamina);
@ -246,7 +249,46 @@ public class Consumable extends UseItem {
player.addPotionEffect(effect.toEffect());
});
return consume && !getNBTItem().getBoolean("MMOITEMS_DISABLE_RIGHT_CLICK_CONSUME");
int maxConsume = (int) nbtItem.getStat("MAX_CONSUME");
if(maxConsume > 1) {
ItemStack item = nbtItem.toItem().clone();
String configMaxConsumeLore = ChatColor.translateAlternateColorCodes('&', MMOItems.plugin.getLanguage().getStatFormat("max-consume"));
String maxConsumeLore = configMaxConsumeLore.replace("#", Integer.toString(maxConsume));
maxConsume -= 1;
nbtItem.removeTag("MMOITEMS_MAX_CONSUME");
nbtItem.addTag(new ItemTag("MMOITEMS_MAX_CONSUME", maxConsume));
ItemStack usedItem = nbtItem.toItem().clone();
usedItem.setAmount(1);
ItemMeta usedItemMeta = usedItem.getItemMeta();
List<String> itemLores = usedItemMeta.getLore();
for(int i = 0; i < itemLores.size() ; i++) {
if(itemLores.get(i).equals(maxConsumeLore)) {
maxConsumeLore = configMaxConsumeLore.replace("#", Integer.toString(maxConsume));
itemLores.set(i, maxConsumeLore);
usedItemMeta.setLore(itemLores);
usedItem.setItemMeta(usedItemMeta);
break;
}
}
player.getInventory().setItemInMainHand(usedItem);
if(item.getAmount() > 1) {
item.setAmount(item.getAmount() - 1);
MMOUtils.giveOrDrop(player, item);
}
return false;
}
return consume && !nbtItem.getBoolean("MMOITEMS_DISABLE_RIGHT_CLICK_CONSUME");
}
public boolean hasVanillaEating() {

View File

@ -1,13 +1,23 @@
package net.Indyuce.mmoitems.api.util;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import net.mmogroup.mmolib.version.VersionMaterial;
public class IsSimilar {
public static boolean check(ItemStack i1, ItemStack i2) {
if(i1.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
return i1.toString().equals(i2.toString());
/**
* Not the most optimal code,
* but it works for now.
*/
if(i1.getType() == VersionMaterial.PLAYER_HEAD.toMaterial() &&
i2.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
ItemMeta meta1 = i1.getItemMeta();
ItemMeta meta2 = i2.getItemMeta();
if(meta1.hasDisplayName() && meta2.hasDisplayName())
return meta1.getDisplayName().equalsIgnoreCase(meta2.getDisplayName());
}
return i1.isSimilar(i2);

View File

@ -50,7 +50,7 @@ public class GetMMOItemObjective extends Objective {
if (player.equals(getQuestProgress().getPlayer().getPlayer()) && event.getNPC().getId() == npcId && player.getInventory().getItemInMainHand() != null) {
NBTItem item = NBTItem.get(player.getInventory().getItemInMainHand());
int amount;
if (item.getString("MMOITEMS_ITEM_TYPE").equals(type.getId()) && item.getString("MMOITEMS_ITEM_ID").equals(id) && (amount = player.getInventory().getItemInMainHand().getAmount()) >= amount) {
if (item.getString("MMOITEMS_ITEM_TYPE").equals(type.getId()) && item.getString("MMOITEMS_ITEM_ID").equals(id) && (amount = player.getInventory().getItemInMainHand().getAmount()) >= required) {
if (amount <= required)
player.getInventory().setItemInMainHand(null);
else

View File

@ -17,6 +17,7 @@ import net.Indyuce.mmoitems.api.AdvancedRecipe;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.plugin.ConfigItem;
import net.Indyuce.mmoitems.api.util.AltChar;
import net.Indyuce.mmoitems.api.util.IsSimilar;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.mmogroup.mmolib.api.item.ItemTag;
import net.mmogroup.mmolib.api.item.NBTItem;
@ -71,15 +72,15 @@ public class AdvancedRecipeList extends PluginInventory {
return;
if (MMOUtils.isPluginItem(item, false)) {
if (item.equals(ConfigItem.BACK.getItem()))
if (IsSimilar.check(item, ConfigItem.BACK.getItem()))
new AdvancedRecipeTypeList(player).open();
if (item.equals(ConfigItem.NEXT_PAGE.getItem())) {
if (IsSimilar.check(item, ConfigItem.NEXT_PAGE.getItem())) {
page++;
open();
}
if (item.equals(ConfigItem.PREVIOUS_PAGE.getItem()) && page > 1) {
if (IsSimilar.check(item, ConfigItem.PREVIOUS_PAGE.getItem()) && page > 1) {
page--;
open();
}

View File

@ -14,6 +14,7 @@ import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.AdvancedRecipe;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.plugin.ConfigItem;
import net.Indyuce.mmoitems.api.util.IsSimilar;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.mmogroup.mmolib.version.VersionMaterial;
@ -79,7 +80,7 @@ public class AdvancedRecipePreview extends EditionInventory {
event.setCancelled(true);
if (MMOUtils.isPluginItem(item, false))
if (item.equals(ConfigItem.BACK.getItem()))
if (IsSimilar.check(item, ConfigItem.BACK.getItem()))
new AdvancedRecipeList(player, type).open();
}
}

View File

@ -15,6 +15,7 @@ import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.plugin.ConfigItem;
import net.Indyuce.mmoitems.api.util.IsSimilar;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.mmogroup.mmolib.api.item.ItemTag;
import net.mmogroup.mmolib.api.item.NBTItem;
@ -71,15 +72,15 @@ public class AdvancedRecipeTypeList extends PluginInventory {
return;
if (MMOUtils.isPluginItem(item, false)) {
if (item.equals(ConfigItem.BACK.getItem()))
if (IsSimilar.check(item, ConfigItem.BACK.getItem()))
new AdvancedWorkbench(player).open();
if (item.equals(ConfigItem.NEXT_PAGE.getItem())) {
if (IsSimilar.check(item, ConfigItem.NEXT_PAGE.getItem())) {
page++;
open();
}
if (item.equals(ConfigItem.PREVIOUS_PAGE.getItem()) && page > 1) {
if (IsSimilar.check(item, ConfigItem.PREVIOUS_PAGE.getItem()) && page > 1) {
page--;
open();
}

View File

@ -6,17 +6,20 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.FurnaceSmeltEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmoitems.MMOItems;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.item.NBTItem;
public class DisableInteractions implements Listener {
@ -33,9 +36,24 @@ public class DisableInteractions implements Listener {
event.setCancelled(true);
}
// grindstone
@EventHandler
public void b(InventoryClickEvent event) {
if (MMOLib.plugin.getVersion().isBelowOrEqual(1, 13))
return;
Inventory inv = event.getClickedInventory();
if (inv == null || inv.getType() != InventoryType.GRINDSTONE || event.getSlot() != 2)
return;
NBTItem item = NBTItem.get(event.getCurrentItem());
if (item.hasType() && (MMOItems.plugin.getConfig().getBoolean("disable-interactions.repair") || item.getBoolean("MMOITEMS_DISABLE_REPAIRING")))
event.setCancelled(true);
}
// enchanting tables
@EventHandler
public void b(EnchantItemEvent event) {
public void c(EnchantItemEvent event) {
NBTItem item = NBTItem.get(event.getItem());
if (item.hasType() && (MMOItems.plugin.getConfig().getBoolean("disable-interactions.enchant") || item.getBoolean("MMOITEMS_DISABLE_ENCHANTING")))
event.setCancelled(true);
@ -43,7 +61,7 @@ public class DisableInteractions implements Listener {
// smelting
@EventHandler
public void c(FurnaceSmeltEvent event) {
public void d(FurnaceSmeltEvent event) {
NBTItem item = NBTItem.get(event.getSource());
if (item.hasType() && (MMOItems.plugin.getConfig().getBoolean("disable-interactions.smelt") || item.getBoolean("MMOITEMS_DISABLE_SMELTING")))
event.setCancelled(true);
@ -51,7 +69,7 @@ public class DisableInteractions implements Listener {
// interaction
@EventHandler
public void d(PlayerInteractEvent event) {
public void e(PlayerInteractEvent event) {
if (!event.hasItem())
return;
@ -60,20 +78,35 @@ public class DisableInteractions implements Listener {
event.setCancelled(true);
}
// interaction
@EventHandler
public void g(PlayerInteractEntityEvent event) {
if (event.getRightClicked() instanceof ArmorStand)
return;
// interaction (entity)
@EventHandler
public void f(PlayerInteractEntityEvent event) {
if (event.getRightClicked() instanceof ArmorStand)
return;
NBTItem item = NBTItem.get(event.getHand() == EquipmentSlot.OFF_HAND ? event.getPlayer().getInventory().getItemInOffHand() : event.getPlayer().getInventory().getItemInMainHand());
if (item.getBoolean("MMOITEMS_DISABLE_INTERACTION"))
event.setCancelled(true);
}
NBTItem item = NBTItem.get(event.getHand() == EquipmentSlot.OFF_HAND ? event.getPlayer().getInventory().getItemInOffHand() : event.getPlayer().getInventory().getItemInMainHand());
if (item.getBoolean("MMOITEMS_DISABLE_INTERACTION"))
event.setCancelled(true);
}
// interaction (consume)
@EventHandler
public void g(PlayerItemConsumeEvent event) {
NBTItem item = NBTItem.get(event.getItem());
if (item.getBoolean("MMOITEMS_DISABLE_INTERACTION"))
event.setCancelled(true);
}
// TODO Cancel for launch event for Ender pearls etc
// interaction (launch)
// @EventHandler
// public void h(ProjectileLaunchEvent event) {
// }
// workbench
@EventHandler
public void e(CraftItemEvent event) {
public void i(CraftItemEvent event) {
boolean disableCrafting = MMOItems.plugin.getConfig().getBoolean("disable-interactions.craft");
for (ItemStack item : event.getInventory().getMatrix()) {
NBTItem nbtItem = NBTItem.get(item);
@ -88,7 +121,7 @@ public class DisableInteractions implements Listener {
// preventing the player from shooting the arrow
@EventHandler
public void f(EntityShootBowEvent event) {
public void j(EntityShootBowEvent event) {
if (!(event.getEntity() instanceof Player))
return;
@ -121,4 +154,16 @@ public class DisableInteractions implements Listener {
}
return -1;
}
@EventHandler
public void projectileLaunchCheck(ProjectileLaunchEvent event) {
if(!(event.getEntity().getShooter() instanceof Player))
return;
Player player = (Player) event.getEntity().getShooter();
NBTItem item = NBTItem.get(player.getInventory().getItemInMainHand());
if(item.getBoolean("MMOITEMS_DISABLE_INTERACTION"))
return;
}
}

View File

@ -1,81 +1,26 @@
package net.Indyuce.mmoitems.stat.type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.ConfigFile;
import net.Indyuce.mmoitems.api.item.MMOItem;
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.Abilities;
import net.Indyuce.mmoitems.stat.Advanced_Crafting_Recipe;
import net.Indyuce.mmoitems.stat.Advanced_Crafting_Recipe_Permission;
import net.Indyuce.mmoitems.stat.Armor;
import net.Indyuce.mmoitems.stat.Armor_Toughness;
import net.Indyuce.mmoitems.stat.Arrow_Particles;
import net.Indyuce.mmoitems.stat.Attack_Damage;
import net.Indyuce.mmoitems.stat.Attack_Speed;
import net.Indyuce.mmoitems.stat.Commands;
import net.Indyuce.mmoitems.stat.Compatible_Types;
import net.Indyuce.mmoitems.stat.Crafting_Recipe;
import net.Indyuce.mmoitems.stat.CustomSounds;
import net.Indyuce.mmoitems.stat.Custom_Model_Data;
import net.Indyuce.mmoitems.stat.Disable_AdvancedEnchantments;
import net.Indyuce.mmoitems.stat.Display_Name;
import net.Indyuce.mmoitems.stat.Dye_Color;
import net.Indyuce.mmoitems.stat.Effects;
import net.Indyuce.mmoitems.stat.Elements;
import net.Indyuce.mmoitems.stat.Enchants;
import net.Indyuce.mmoitems.stat.Furnace_Recipe;
import net.Indyuce.mmoitems.stat.Gem_Color;
import net.Indyuce.mmoitems.stat.Gem_Sockets;
import net.Indyuce.mmoitems.stat.Hide_Enchants;
import net.Indyuce.mmoitems.stat.Hide_Potion_Effects;
import net.Indyuce.mmoitems.stat.Inedible;
import net.Indyuce.mmoitems.stat.Item_Particles;
import net.Indyuce.mmoitems.stat.Item_Set;
import net.Indyuce.mmoitems.stat.Item_Tier;
import net.Indyuce.mmoitems.stat.Item_Type_Restriction;
import net.Indyuce.mmoitems.stat.Knockback_Resistance;
import net.Indyuce.mmoitems.stat.Lore;
import net.Indyuce.mmoitems.stat.Lute_Attack_Effect;
import net.Indyuce.mmoitems.stat.Lute_Attack_Sound;
import net.Indyuce.mmoitems.stat.MaterialStat;
import net.Indyuce.mmoitems.stat.Max_Custom_Durability;
import net.Indyuce.mmoitems.stat.Max_Health;
import net.Indyuce.mmoitems.stat.Movement_Speed;
import net.Indyuce.mmoitems.stat.Perm_Effects;
import net.Indyuce.mmoitems.stat.Permission;
import net.Indyuce.mmoitems.stat.Pickaxe_Power;
import net.Indyuce.mmoitems.stat.Potion_Color;
import net.Indyuce.mmoitems.stat.Potion_Effects;
import net.Indyuce.mmoitems.stat.Required_Class;
import net.Indyuce.mmoitems.stat.Required_Level;
import net.Indyuce.mmoitems.stat.Restore;
import net.Indyuce.mmoitems.stat.Shapeless_Recipe;
import net.Indyuce.mmoitems.stat.Shield_Pattern;
import net.Indyuce.mmoitems.stat.Skull_Texture;
import net.Indyuce.mmoitems.stat.Soulbound;
import net.Indyuce.mmoitems.stat.Soulbound_Level;
import net.Indyuce.mmoitems.stat.Staff_Spirit;
import net.Indyuce.mmoitems.stat.Unbreakable;
import net.Indyuce.mmoitems.stat.Upgrade_Stat;
import net.Indyuce.mmoitems.stat.Vanilla_Eating_Animation;
import net.Indyuce.mmoitems.stat.Will_Break;
import net.Indyuce.mmoitems.stat.*;
import net.Indyuce.mmoitems.stat.data.StatData;
import net.Indyuce.mmoitems.version.durability.stat.DefaultDurability;
import net.Indyuce.mmoitems.version.durability.stat.LegacyDurability;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.item.NBTItem;
import net.mmogroup.mmolib.version.VersionMaterial;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public abstract class ItemStat {
public static final ItemStat MATERIAL = new MaterialStat(), DURABILITY = MMOLib.plugin.getVersion().isBelowOrEqual(1, 12) ? new LegacyDurability() : new DefaultDurability(), CUSTOM_MODEL_DATA = new Custom_Model_Data(), MAX_CUSTOM_DURABILITY = new Max_Custom_Durability(), WILL_BREAK = new Will_Break();
@ -139,6 +84,7 @@ public abstract class ItemStat {
public static final ItemStat ITEM_COOLDOWN = new DoubleStat(new ItemStack(Material.COOKED_CHICKEN), "Item Cooldown", new String[] { "This cooldown applies for consumables", "as well as for item commands." }, "item-cooldown", new String[] { "!armor", "!gem_stone", "all" });
public static final ItemStat DISABLE_RIGHT_CLICK_CONSUME = new DisableStat(Material.BARRIER, "right-click-consume", "Disable Right Click Consume", new String[] { "consumable" }, "This item will not be consumed", "when eaten by players.");
public static final ItemStat VANILLA_EATING_ANIMATION = new Vanilla_Eating_Animation(), INEDIBLE = new Inedible(), GEM_COLOR = new Gem_Color(), ITEM_TYPE_RESTRICTION = new Item_Type_Restriction();
public static final ItemStat MAX_CONSUME = new DoubleStat(new ItemStack(Material.BLAZE_POWDER), "Max Consume", new String[] {"Max amount of usage before", "item disappears."}, "max-consume", new String[] {"consumable"});
public static final ItemStat SUCCESS_RATE = new DoubleStat(new ItemStack(Material.EMERALD), "Success Rate", new String[] { "The chance of your gem to successfully", "apply onto an item. This value is 100%", "by default. If it is not successfully", "applied, the gem stone will be lost." }, "success-rate", new String[] { "gem_stone", "skin" });
public static final ItemStat COMPATIBLE_TYPES = new Compatible_Types();

View File

@ -85,6 +85,7 @@ lore-format:
- '#skill-cooldown-reduction#'
- '#mana-cost#'
- '#stamina-cost#'
- '#max-consume#'
# - '{bar}&8&m--------&2&l &nElements&8 &m--------------'
- '{bar}'
- '#fire-damage#'

View File

@ -74,6 +74,7 @@ repair: '&7■ Repair: &f#'
can-identify: '&7■ Can identify items.'
can-deconstruct: '&7■ Can deconstruct tiered items.'
success-rate: '&7■ Success Rate: &a&l#%'
max-consume: '&7■ Max Consume: &f# &7uses'
# Gem Stones
empty-gem-socket: '&a◆ Empty # Gem Socket'