!ItemUse refactor

now uses VolatileMMOItem instead of LiveMMOItem. Hopefully this will
reduce the lag caused by multi-block breaks, etc.
This commit is contained in:
ASangarin 2020-09-22 20:34:14 +02:00
parent 534ee455c0
commit fdbd2cf344
12 changed files with 50 additions and 43 deletions

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.Indyuce</groupId>
<artifactId>MMOItems</artifactId>
<version>6.1.3</version>
<version>6.2.0</version>
<name>MMOItems</name>
<description>A great item solution for your RPG server.</description>

View File

@ -4,12 +4,14 @@ import org.bukkit.event.HandlerList;
import net.Indyuce.mmoitems.api.event.PlayerDataEvent;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
import net.Indyuce.mmoitems.api.player.PlayerData;
public class ApplyGemStoneEvent extends PlayerDataEvent {
private static final HandlerList handlers = new HandlerList();
private final MMOItem gemStone, targetItem;
private final VolatileMMOItem gemStone;
private final MMOItem targetItem;
/**
* Called when a player tries to apply a gem stone onto an item
@ -21,14 +23,14 @@ public class ApplyGemStoneEvent extends PlayerDataEvent {
* @param target
* Item on which the gem is being applied
*/
public ApplyGemStoneEvent(PlayerData playerData, MMOItem gemStone, MMOItem targetItem) {
public ApplyGemStoneEvent(PlayerData playerData, VolatileMMOItem gemStone, MMOItem targetItem) {
super(playerData);
this.gemStone = gemStone;
this.targetItem = targetItem;
}
public MMOItem getGemStone() {
public VolatileMMOItem getGemStone() {
return gemStone;
}

View File

@ -3,14 +3,14 @@ package net.Indyuce.mmoitems.api.event.item;
import org.bukkit.event.HandlerList;
import net.Indyuce.mmoitems.api.event.PlayerDataEvent;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.mmogroup.mmolib.api.item.NBTItem;
public class ApplySoulboundEvent extends PlayerDataEvent {
private static final HandlerList handlers = new HandlerList();
private final MMOItem consumable;
private final VolatileMMOItem consumable;
private final NBTItem target;
/**
@ -23,14 +23,14 @@ public class ApplySoulboundEvent extends PlayerDataEvent {
* @param target
* Item being soulbound
*/
public ApplySoulboundEvent(PlayerData playerData, MMOItem consumable, NBTItem target) {
public ApplySoulboundEvent(PlayerData playerData, VolatileMMOItem consumable, NBTItem target) {
super(playerData);
this.consumable = consumable;
this.target = target;
}
public MMOItem getConsumable() {
public VolatileMMOItem getConsumable() {
return consumable;
}

View File

@ -3,14 +3,14 @@ package net.Indyuce.mmoitems.api.event.item;
import org.bukkit.event.HandlerList;
import net.Indyuce.mmoitems.api.event.PlayerDataEvent;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.mmogroup.mmolib.api.item.NBTItem;
public class BreakSoulboundEvent extends PlayerDataEvent {
private static final HandlerList handlers = new HandlerList();
private final MMOItem consumable;
private final VolatileMMOItem consumable;
private final NBTItem target;
/**
@ -23,14 +23,14 @@ public class BreakSoulboundEvent extends PlayerDataEvent {
* @param target
* Item with soulbound
*/
public BreakSoulboundEvent(PlayerData playerData, MMOItem consumable, NBTItem target) {
public BreakSoulboundEvent(PlayerData playerData, VolatileMMOItem consumable, NBTItem target) {
super(playerData);
this.consumable = consumable;
this.target = target;
}
public MMOItem getConsumable() {
public VolatileMMOItem getConsumable() {
return consumable;
}

View File

@ -6,14 +6,14 @@ import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmoitems.api.event.PlayerDataEvent;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.mmogroup.mmolib.api.item.NBTItem;
public class DeconstructItemEvent extends PlayerDataEvent {
private static final HandlerList handlers = new HandlerList();
private final MMOItem consumable;
private final VolatileMMOItem consumable;
private final NBTItem deconstructed;
private final List<ItemStack> loot;
@ -30,7 +30,7 @@ public class DeconstructItemEvent extends PlayerDataEvent {
* Items which will be given to the player if the item is
* successfully deconstructed
*/
public DeconstructItemEvent(PlayerData playerData, MMOItem consumable, NBTItem deconstructed, List<ItemStack> loot) {
public DeconstructItemEvent(PlayerData playerData, VolatileMMOItem consumable, NBTItem deconstructed, List<ItemStack> loot) {
super(playerData);
this.consumable = consumable;
@ -38,7 +38,7 @@ public class DeconstructItemEvent extends PlayerDataEvent {
this.loot = loot;
}
public MMOItem getConsumable() {
public VolatileMMOItem getConsumable() {
return consumable;
}

View File

@ -3,14 +3,14 @@ package net.Indyuce.mmoitems.api.event.item;
import org.bukkit.event.HandlerList;
import net.Indyuce.mmoitems.api.event.PlayerDataEvent;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.mmogroup.mmolib.api.item.NBTItem;
public class IdentifyItemEvent extends PlayerDataEvent {
private static final HandlerList handlers = new HandlerList();
private final MMOItem consumable;
private final VolatileMMOItem consumable;
private final NBTItem unidentified;
/**
@ -23,14 +23,14 @@ public class IdentifyItemEvent extends PlayerDataEvent {
* @param unidentified
* Item being identified
*/
public IdentifyItemEvent(PlayerData playerData, MMOItem consumable, NBTItem unidentified) {
public IdentifyItemEvent(PlayerData playerData, VolatileMMOItem consumable, NBTItem unidentified) {
super(playerData);
this.consumable = consumable;
this.unidentified = unidentified;
}
public MMOItem getConsumable() {
public VolatileMMOItem getConsumable() {
return consumable;
}

View File

@ -3,14 +3,14 @@ package net.Indyuce.mmoitems.api.event.item;
import org.bukkit.event.HandlerList;
import net.Indyuce.mmoitems.api.event.PlayerDataEvent;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.mmogroup.mmolib.api.item.NBTItem;
public class RepairItemEvent extends PlayerDataEvent {
private static final HandlerList handlers = new HandlerList();
private final MMOItem consumable;
private final VolatileMMOItem consumable;
private final NBTItem target;
private int repaired;
@ -27,7 +27,7 @@ public class RepairItemEvent extends PlayerDataEvent {
* @param repaired
* Amount of durability being repaired
*/
public RepairItemEvent(PlayerData playerData, MMOItem consumable, NBTItem target, int repaired) {
public RepairItemEvent(PlayerData playerData, VolatileMMOItem consumable, NBTItem target, int repaired) {
super(playerData);
this.consumable = consumable;
@ -35,7 +35,7 @@ public class RepairItemEvent extends PlayerDataEvent {
this.repaired = repaired;
}
public MMOItem getConsumable() {
public VolatileMMOItem getConsumable() {
return consumable;
}

View File

@ -4,13 +4,15 @@ import org.bukkit.event.HandlerList;
import net.Indyuce.mmoitems.api.event.PlayerDataEvent;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.stat.data.UpgradeData;
public class UpgradeItemEvent extends PlayerDataEvent {
private static final HandlerList handlers = new HandlerList();
private final MMOItem consumable, target;
private final VolatileMMOItem consumable;
private final MMOItem target;
private final UpgradeData consumableData, targetData;
/**
@ -27,7 +29,7 @@ public class UpgradeItemEvent extends PlayerDataEvent {
* @param targetData
* Upgrade info about the target item
*/
public UpgradeItemEvent(PlayerData playerData, MMOItem consumable, MMOItem target, UpgradeData consumableData, UpgradeData targetData) {
public UpgradeItemEvent(PlayerData playerData, VolatileMMOItem consumable, MMOItem target, UpgradeData consumableData, UpgradeData targetData) {
super(playerData);
this.consumable = consumable;
@ -36,7 +38,7 @@ public class UpgradeItemEvent extends PlayerDataEvent {
this.targetData = targetData;
}
public MMOItem getConsumable() {
public VolatileMMOItem getConsumable() {
return consumable;
}

View File

@ -110,7 +110,7 @@ public class Consumable extends UseItem {
* Upgrading an item, it is sbetter not to repair an item while
* upgrading it.
*/
if (getNBTItem().hasTag("MMOITEMS_UPGRADE") && target.hasTag("MMOITEMS_UPGRADE")) {
if (mmoitem.hasData(ItemStat.UPGRADE) && target.hasTag("MMOITEMS_UPGRADE")) {
if (target.getItem().getAmount() > 1) {
Message.CANT_UPGRADED_STACK.format(ChatColor.RED).send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2);

View File

@ -71,20 +71,21 @@ public class GemStone extends UseItem {
* permanent effects. also REGISTER gem stone in the item gem stone
* list.
*/
GemstoneData gemData = new GemstoneData(mmoitem);
LiveMMOItem mmo = new LiveMMOItem(nbt);
GemstoneData gemData = new GemstoneData(mmo);
sockets.apply(gemType, gemData);
/*
* Only applies NON PROPER and MERGEABLE item stats
*/
for (ItemStat stat : mmoitem.getStats())
for (ItemStat stat : mmo.getStats())
if (!(stat instanceof GemStoneStat)) {
StatData data = mmoitem.getData(stat);
StatData data = mmo.getData(stat);
if (data instanceof Mergeable) {
if (targetMMO.hasData(stat))
((Mergeable) targetMMO.getData(stat)).merge(mmoitem.getData(stat));
((Mergeable) targetMMO.getData(stat)).merge(mmo.getData(stat));
else
targetMMO.setData(stat, mmoitem.getData(stat));
targetMMO.setData(stat, mmo.getData(stat));
}
}

View File

@ -28,7 +28,7 @@ public class Tool extends UseItem {
public boolean miningEffects(Block block) {
boolean cancel = false;
if (mmoitem.getNBT().getBoolean("MMOITEMS_AUTOSMELT"))
if (nbt.getBoolean("MMOITEMS_AUTOSMELT"))
if (block.getType() == Material.IRON_ORE || block.getType() == Material.GOLD_ORE) {
ItemStack item = new ItemStack(Material.valueOf(block.getType().name().replace("_ORE", "") + "_INGOT"));
@ -39,7 +39,7 @@ public class Tool extends UseItem {
cancel = true;
}
if (mmoitem.getNBT().getBoolean("MMOITEMS_BOUNCING_CRACK"))
if (nbt.getBoolean("MMOITEMS_BOUNCING_CRACK"))
new BukkitRunnable() {
Vector v = player.getEyeLocation().getDirection().multiply(.5);
Location loc = block.getLocation().clone().add(.5, .5, .5);
@ -60,8 +60,8 @@ public class Tool extends UseItem {
}
}.runTaskTimer(MMOItems.plugin, 0, 1);
if (mmoitem.getNBT().hasTag("MMOITEMS_BREAK_SIZE")) {
int breakSize = mmoitem.getNBT().getInteger("MMOITEMS_BREAK_SIZE");
if (nbt.hasTag("MMOITEMS_BREAK_SIZE")) {
int breakSize = nbt.getInteger("MMOITEMS_BREAK_SIZE");
if(breakSize % 2 != 0) {
BlockFace face = player.getFacing();
System.out.println("Debug: Facing - " + face);

View File

@ -15,8 +15,8 @@ import net.Indyuce.mmoitems.api.interaction.weapon.untargeted.Lute;
import net.Indyuce.mmoitems.api.interaction.weapon.untargeted.Musket;
import net.Indyuce.mmoitems.api.interaction.weapon.untargeted.Staff;
import net.Indyuce.mmoitems.api.interaction.weapon.untargeted.Whip;
import net.Indyuce.mmoitems.api.item.mmoitem.LiveMMOItem;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.comp.flags.FlagPlugin.CustomFlag;
import net.Indyuce.mmoitems.stat.data.CommandData;
@ -27,7 +27,8 @@ import net.mmogroup.mmolib.api.item.NBTItem;
public class UseItem {
protected final Player player;
protected final PlayerData playerData;
protected final LiveMMOItem mmoitem;
protected final VolatileMMOItem mmoitem;
protected final NBTItem nbt;
protected static final Random random = new Random();
@ -38,7 +39,8 @@ public class UseItem {
public UseItem(PlayerData playerData, NBTItem nbtItem) {
this.player = playerData.getPlayer();
this.playerData = playerData;
this.mmoitem = new LiveMMOItem(nbtItem);
this.mmoitem = new VolatileMMOItem(nbtItem);
this.nbt = nbtItem;
}
public Player getPlayer() {
@ -54,15 +56,15 @@ public class UseItem {
}
public NBTItem getNBTItem() {
return mmoitem.getNBT();
return nbt;
}
public ItemStack getItem() {
return mmoitem.getNBT().getItem();
return nbt.getItem();
}
public boolean canBeUsed() {
return playerData.getRPG().canUse(mmoitem.getNBT(), true);
return playerData.getRPG().canUse(nbt, true);
}
public void executeCommands() {