mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 07:06:45 +01:00
1.13.2 related bugfixes for the new item tracking
This commit is contained in:
parent
557cfe3944
commit
e5f1738168
@ -687,7 +687,7 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
} else {
|
||||
if ((mcMMOPlayer.getAbilityMode(SuperAbilityType.SUPER_BREAKER) && !BlockUtils.affectedBySuperBreaker(blockState)) || (mcMMOPlayer.getAbilityMode(SuperAbilityType.GIGA_DRILL_BREAKER) && !BlockUtils.affectedByGigaDrillBreaker(blockState))) {
|
||||
SkillUtils.handleAbilitySpeedDecrease(player);
|
||||
SkillUtils.removeAbilityBoostsFromInventory(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -654,7 +654,7 @@ public class PlayerListener implements Listener {
|
||||
|
||||
// Make sure the player knows what he's doing when trying to salvage an enchanted item
|
||||
if (salvageManager.checkConfirmation(true)) {
|
||||
SkillUtils.handleAbilitySpeedDecrease(player);
|
||||
SkillUtils.removeAbilityBoostsFromInventory(player);
|
||||
salvageManager.handleSalvage(clickedBlock.getLocation(), heldItem);
|
||||
player.updateInventory();
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class AbilityDisableTask extends BukkitRunnable {
|
||||
switch (ability) {
|
||||
case SUPER_BREAKER:
|
||||
case GIGA_DRILL_BREAKER:
|
||||
SkillUtils.handleAbilitySpeedDecrease(player);
|
||||
SkillUtils.removeAbilityBoostsFromInventory(player);
|
||||
// Fallthrough
|
||||
|
||||
case BERSERK:
|
||||
|
@ -13,6 +13,7 @@ import org.bukkit.inventory.FurnaceRecipe;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -485,7 +486,7 @@ public final class ItemUtils {
|
||||
return itemMeta.hasDisplayName() && itemMeta.getDisplayName().equals(ChatColor.GOLD + LocaleLoader.getString("Item.ChimaeraWing.Name"));
|
||||
}
|
||||
|
||||
public static void addAbilityLore(ItemStack itemStack) {
|
||||
public static void addAbilityLore(@NotNull ItemStack itemStack) {
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
List<String> itemLore = new ArrayList<>();
|
||||
|
||||
@ -502,7 +503,7 @@ public final class ItemUtils {
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
}
|
||||
|
||||
public static void removeAbilityLore(ItemStack itemStack) {
|
||||
public static void removeAbilityLore(@NotNull ItemStack itemStack) {
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
if(itemMeta == null)
|
||||
@ -521,7 +522,7 @@ public final class ItemUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void addDigSpeedToItem(ItemStack itemStack, int existingEnchantLevel) {
|
||||
public static void addDigSpeedToItem(@NotNull ItemStack itemStack, int existingEnchantLevel) {
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
if(itemMeta == null)
|
||||
@ -530,4 +531,8 @@ public final class ItemUtils {
|
||||
itemMeta.addEnchant(Enchantment.DIG_SPEED, existingEnchantLevel + AdvancedConfig.getInstance().getEnchantBuff(), true);
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
}
|
||||
|
||||
public static boolean canBeSuperAbilityDigBoosted(@NotNull ItemStack itemStack) {
|
||||
return isShovel(itemStack) || isPickaxe(itemStack);
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,39 @@
|
||||
package com.gmail.nossr50.util.compat.layers.persistentdata;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.compat.layers.AbstractCompatibilityLayer;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.Furnace;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class AbstractPersistentDataLayer extends AbstractCompatibilityLayer {
|
||||
|
||||
public final NamespacedKey superAbilityBoosted;
|
||||
public final String SUPER_ABILITY_BOOSTED = "super_ability_boosted";
|
||||
|
||||
public AbstractPersistentDataLayer() {
|
||||
superAbilityBoosted = getNamespacedKey(SUPER_ABILITY_BOOSTED);
|
||||
initializeLayer();
|
||||
}
|
||||
|
||||
public abstract @Nullable UUID getFurnaceOwner(Furnace furnace);
|
||||
public @NotNull NamespacedKey getNamespacedKey(@NotNull String key) {
|
||||
return new NamespacedKey(mcMMO.p, key);
|
||||
}
|
||||
|
||||
public abstract void setFurnaceOwner(Furnace furnace, UUID uuid);
|
||||
public abstract @Nullable UUID getFurnaceOwner(@NotNull Furnace furnace);
|
||||
|
||||
public abstract void setSuperAbilityBoostedItem(ItemStack itemStack, int originalDigSpeed);
|
||||
public abstract void setFurnaceOwner(@NotNull Furnace furnace, @NotNull UUID uuid);
|
||||
|
||||
public abstract boolean isSuperAbilityBoosted(ItemStack itemStack);
|
||||
public abstract void setSuperAbilityBoostedItem(@NotNull ItemStack itemStack, int originalDigSpeed);
|
||||
|
||||
public abstract int getSuperAbilityToolOriginalDigSpeed(ItemStack itemStack);
|
||||
public abstract boolean isSuperAbilityBoosted(@NotNull ItemStack itemStack);
|
||||
|
||||
public abstract void removeBonusDigSpeedOnSuperAbilityTool(ItemStack itemStack);
|
||||
public abstract int getSuperAbilityToolOriginalDigSpeed(@NotNull ItemStack itemStack);
|
||||
|
||||
public abstract void removeBonusDigSpeedOnSuperAbilityTool(@NotNull ItemStack itemStack);
|
||||
|
||||
}
|
||||
|
@ -21,12 +21,9 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer {
|
||||
*/
|
||||
public static final String FURNACE_UUID_MOST_SIG = "furnace_uuid_most_sig";
|
||||
public static final String FURNACE_UUID_LEAST_SIG = "furnace_uuid_least_sig";
|
||||
public static final String SUPER_ABILITY_BOOSTED = "super_ability_boosted";
|
||||
|
||||
private NamespacedKey furnaceOwner_MostSig_Key;
|
||||
private NamespacedKey furnaceOwner_LeastSig_Key;
|
||||
private NamespacedKey superAbilityBoosted;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean initializeLayer() {
|
||||
@ -37,16 +34,10 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer {
|
||||
private void initNamespacedKeys() {
|
||||
furnaceOwner_MostSig_Key = getNamespacedKey(FURNACE_UUID_MOST_SIG);
|
||||
furnaceOwner_LeastSig_Key = getNamespacedKey(FURNACE_UUID_LEAST_SIG);
|
||||
superAbilityBoosted = getNamespacedKey(SUPER_ABILITY_BOOSTED);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public NamespacedKey getNamespacedKey(String key) {
|
||||
return new NamespacedKey(mcMMO.p, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable UUID getFurnaceOwner(Furnace furnace) {
|
||||
public @Nullable UUID getFurnaceOwner(@NotNull Furnace furnace) {
|
||||
//Get container from entity
|
||||
PersistentDataContainer dataContainer = ((PersistentDataHolder) furnace).getPersistentDataContainer();
|
||||
|
||||
@ -62,7 +53,7 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFurnaceOwner(Furnace furnace, UUID uuid) {
|
||||
public void setFurnaceOwner(@NotNull Furnace furnace, @NotNull UUID uuid) {
|
||||
PersistentDataContainer dataContainer = ((PersistentDataHolder) furnace).getPersistentDataContainer();
|
||||
|
||||
dataContainer.set(furnaceOwner_MostSig_Key, PersistentDataType.LONG, uuid.getMostSignificantBits());
|
||||
@ -72,7 +63,7 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSuperAbilityBoostedItem(ItemStack itemStack, int originalDigSpeed) {
|
||||
public void setSuperAbilityBoostedItem(@NotNull ItemStack itemStack, int originalDigSpeed) {
|
||||
if(itemStack.getItemMeta() == null) {
|
||||
mcMMO.p.getLogger().severe("Can not assign persistent data to an item with null item metadata");
|
||||
return;
|
||||
@ -87,7 +78,7 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuperAbilityBoosted(ItemStack itemStack) {
|
||||
public boolean isSuperAbilityBoosted(@NotNull ItemStack itemStack) {
|
||||
if(itemStack.getItemMeta() == null)
|
||||
return false;
|
||||
|
||||
|
@ -5,8 +5,11 @@ import com.gmail.nossr50.datatypes.meta.UUIDMeta;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import org.bukkit.block.Furnace;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.tags.CustomItemTagContainer;
|
||||
import org.bukkit.inventory.meta.tags.ItemTagType;
|
||||
import org.bukkit.metadata.Metadatable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -26,7 +29,7 @@ public class SpigotTemporaryDataLayer extends AbstractPersistentDataLayer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getFurnaceOwner(Furnace furnace) {
|
||||
public UUID getFurnaceOwner(@NotNull Furnace furnace) {
|
||||
Metadatable metadatable = (Metadatable) furnace;
|
||||
|
||||
if(metadatable.getMetadata(FURNACE_OWNER_METADATA_KEY).size() > 0) {
|
||||
@ -38,7 +41,7 @@ public class SpigotTemporaryDataLayer extends AbstractPersistentDataLayer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFurnaceOwner(@NotNull Furnace furnace, UUID uuid) {
|
||||
public void setFurnaceOwner(@NotNull Furnace furnace, @NotNull UUID uuid) {
|
||||
Metadatable metadatable = (Metadatable) furnace;
|
||||
|
||||
if(metadatable.getMetadata(FURNACE_OWNER_METADATA_KEY).size() > 0) {
|
||||
@ -52,6 +55,17 @@ public class SpigotTemporaryDataLayer extends AbstractPersistentDataLayer {
|
||||
public void setSuperAbilityBoostedItem(@NotNull ItemStack itemStack, int originalDigSpeed) {
|
||||
Metadatable metadatable = getMetadatable(itemStack);
|
||||
metadatable.setMetadata(ABILITY_TOOL_METADATA_KEY, new SuperAbilityToolMeta(originalDigSpeed, mcMMO.p));
|
||||
|
||||
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
if(itemMeta == null) {
|
||||
mcMMO.p.getLogger().severe("Item meta should never be null for a super boosted item!");
|
||||
return;
|
||||
}
|
||||
|
||||
itemMeta.getCustomTagContainer().setCustomTag(superAbilityBoosted, ItemTagType.INTEGER, originalDigSpeed);
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
}
|
||||
|
||||
private Metadatable getMetadatable(@NotNull ItemStack itemStack) {
|
||||
@ -60,19 +74,27 @@ public class SpigotTemporaryDataLayer extends AbstractPersistentDataLayer {
|
||||
|
||||
@Override
|
||||
public boolean isSuperAbilityBoosted(@NotNull ItemStack itemStack) {
|
||||
Metadatable metadatable = getMetadatable(itemStack);
|
||||
return metadatable.getMetadata(ABILITY_TOOL_METADATA_KEY).size() > 0;
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
if(itemMeta == null)
|
||||
return false;
|
||||
|
||||
CustomItemTagContainer tagContainer = itemMeta.getCustomTagContainer();
|
||||
return tagContainer.hasCustomTag(superAbilityBoosted, ItemTagType.INTEGER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSuperAbilityToolOriginalDigSpeed(@NotNull ItemStack itemStack) {
|
||||
Metadatable metadatable = getMetadatable(itemStack);
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
if(metadatable.getMetadata(ABILITY_TOOL_METADATA_KEY).size() > 0) {
|
||||
SuperAbilityToolMeta toolMeta = (SuperAbilityToolMeta) metadatable.getMetadata(ABILITY_TOOL_METADATA_KEY).get(0);
|
||||
return toolMeta.asInt();
|
||||
if(itemMeta == null)
|
||||
return 0;
|
||||
|
||||
CustomItemTagContainer tagContainer = itemMeta.getCustomTagContainer();
|
||||
|
||||
if(tagContainer.hasCustomTag(superAbilityBoosted , ItemTagType.INTEGER)) {
|
||||
return tagContainer.getCustomTag(superAbilityBoosted, ItemTagType.INTEGER);
|
||||
} else {
|
||||
// mcMMO.p.getLogger().info("Original dig enchant speed could not be found on item! Most likely it was lost from a server restart.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -82,6 +104,9 @@ public class SpigotTemporaryDataLayer extends AbstractPersistentDataLayer {
|
||||
int originalSpeed = getSuperAbilityToolOriginalDigSpeed(itemStack);
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
if(itemMeta == null)
|
||||
return;
|
||||
|
||||
if(itemMeta.hasEnchant(Enchantment.DIG_SPEED)) {
|
||||
itemMeta.removeEnchant(Enchantment.DIG_SPEED);
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.*;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
@ -131,7 +132,7 @@ public class SkillUtils {
|
||||
if (HiddenConfig.getInstance().useEnchantmentBuffs()) {
|
||||
ItemStack heldItem = player.getInventory().getItemInMainHand();
|
||||
|
||||
if (heldItem == null || heldItem.getType() == Material.AIR) {
|
||||
if (!ItemUtils.canBeSuperAbilityDigBoosted(heldItem)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -186,20 +187,19 @@ public class SkillUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleAbilitySpeedDecrease(Player player) {
|
||||
public static void removeAbilityBoostsFromInventory(@NotNull Player player) {
|
||||
if (!HiddenConfig.getInstance().useEnchantmentBuffs()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ItemStack item : player.getInventory().getContents()) {
|
||||
removeAbilityBuff(item);
|
||||
for (ItemStack itemStack : player.getInventory().getContents()) {
|
||||
removeAbilityBuff(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeAbilityBuff(ItemStack itemStack) {
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
||||
public static void removeAbilityBuff(@NotNull ItemStack itemStack) {
|
||||
if(!ItemUtils.canBeSuperAbilityDigBoosted(itemStack))
|
||||
return;
|
||||
}
|
||||
|
||||
//Take the lore off
|
||||
ItemUtils.removeAbilityLore(itemStack);
|
||||
|
Loading…
Reference in New Issue
Block a user