1.13.2 related bugfixes for the new item tracking

This commit is contained in:
nossr50 2020-08-18 20:24:45 -07:00
parent 557cfe3944
commit e5f1738168
8 changed files with 73 additions and 42 deletions

View File

@ -687,7 +687,7 @@ public class BlockListener implements Listener {
} }
} else { } else {
if ((mcMMOPlayer.getAbilityMode(SuperAbilityType.SUPER_BREAKER) && !BlockUtils.affectedBySuperBreaker(blockState)) || (mcMMOPlayer.getAbilityMode(SuperAbilityType.GIGA_DRILL_BREAKER) && !BlockUtils.affectedByGigaDrillBreaker(blockState))) { if ((mcMMOPlayer.getAbilityMode(SuperAbilityType.SUPER_BREAKER) && !BlockUtils.affectedBySuperBreaker(blockState)) || (mcMMOPlayer.getAbilityMode(SuperAbilityType.GIGA_DRILL_BREAKER) && !BlockUtils.affectedByGigaDrillBreaker(blockState))) {
SkillUtils.handleAbilitySpeedDecrease(player); SkillUtils.removeAbilityBoostsFromInventory(player);
} }
} }
} }

View File

@ -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 // Make sure the player knows what he's doing when trying to salvage an enchanted item
if (salvageManager.checkConfirmation(true)) { if (salvageManager.checkConfirmation(true)) {
SkillUtils.handleAbilitySpeedDecrease(player); SkillUtils.removeAbilityBoostsFromInventory(player);
salvageManager.handleSalvage(clickedBlock.getLocation(), heldItem); salvageManager.handleSalvage(clickedBlock.getLocation(), heldItem);
player.updateInventory(); player.updateInventory();
} }

View File

@ -37,7 +37,7 @@ public class AbilityDisableTask extends BukkitRunnable {
switch (ability) { switch (ability) {
case SUPER_BREAKER: case SUPER_BREAKER:
case GIGA_DRILL_BREAKER: case GIGA_DRILL_BREAKER:
SkillUtils.handleAbilitySpeedDecrease(player); SkillUtils.removeAbilityBoostsFromInventory(player);
// Fallthrough // Fallthrough
case BERSERK: case BERSERK:

View File

@ -13,6 +13,7 @@ import org.bukkit.inventory.FurnaceRecipe;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe; import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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")); 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(); ItemMeta itemMeta = itemStack.getItemMeta();
List<String> itemLore = new ArrayList<>(); List<String> itemLore = new ArrayList<>();
@ -502,7 +503,7 @@ public final class ItemUtils {
itemStack.setItemMeta(itemMeta); itemStack.setItemMeta(itemMeta);
} }
public static void removeAbilityLore(ItemStack itemStack) { public static void removeAbilityLore(@NotNull ItemStack itemStack) {
ItemMeta itemMeta = itemStack.getItemMeta(); ItemMeta itemMeta = itemStack.getItemMeta();
if(itemMeta == null) 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(); ItemMeta itemMeta = itemStack.getItemMeta();
if(itemMeta == null) if(itemMeta == null)
@ -530,4 +531,8 @@ public final class ItemUtils {
itemMeta.addEnchant(Enchantment.DIG_SPEED, existingEnchantLevel + AdvancedConfig.getInstance().getEnchantBuff(), true); itemMeta.addEnchant(Enchantment.DIG_SPEED, existingEnchantLevel + AdvancedConfig.getInstance().getEnchantBuff(), true);
itemStack.setItemMeta(itemMeta); itemStack.setItemMeta(itemMeta);
} }
public static boolean canBeSuperAbilityDigBoosted(@NotNull ItemStack itemStack) {
return isShovel(itemStack) || isPickaxe(itemStack);
}
} }

View File

@ -1,29 +1,39 @@
package com.gmail.nossr50.util.compat.layers.persistentdata; package com.gmail.nossr50.util.compat.layers.persistentdata;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.compat.layers.AbstractCompatibilityLayer; import com.gmail.nossr50.util.compat.layers.AbstractCompatibilityLayer;
import org.bukkit.NamespacedKey;
import org.bukkit.block.Furnace; import org.bukkit.block.Furnace;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.UUID; import java.util.UUID;
public abstract class AbstractPersistentDataLayer extends AbstractCompatibilityLayer { public abstract class AbstractPersistentDataLayer extends AbstractCompatibilityLayer {
public final NamespacedKey superAbilityBoosted;
public final String SUPER_ABILITY_BOOSTED = "super_ability_boosted";
public AbstractPersistentDataLayer() { public AbstractPersistentDataLayer() {
superAbilityBoosted = getNamespacedKey(SUPER_ABILITY_BOOSTED);
initializeLayer(); 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);
} }

View File

@ -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_MOST_SIG = "furnace_uuid_most_sig";
public static final String FURNACE_UUID_LEAST_SIG = "furnace_uuid_least_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_MostSig_Key;
private NamespacedKey furnaceOwner_LeastSig_Key; private NamespacedKey furnaceOwner_LeastSig_Key;
private NamespacedKey superAbilityBoosted;
@Override @Override
public boolean initializeLayer() { public boolean initializeLayer() {
@ -37,16 +34,10 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer {
private void initNamespacedKeys() { private void initNamespacedKeys() {
furnaceOwner_MostSig_Key = getNamespacedKey(FURNACE_UUID_MOST_SIG); furnaceOwner_MostSig_Key = getNamespacedKey(FURNACE_UUID_MOST_SIG);
furnaceOwner_LeastSig_Key = getNamespacedKey(FURNACE_UUID_LEAST_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 @Override
public @Nullable UUID getFurnaceOwner(Furnace furnace) { public @Nullable UUID getFurnaceOwner(@NotNull Furnace furnace) {
//Get container from entity //Get container from entity
PersistentDataContainer dataContainer = ((PersistentDataHolder) furnace).getPersistentDataContainer(); PersistentDataContainer dataContainer = ((PersistentDataHolder) furnace).getPersistentDataContainer();
@ -62,7 +53,7 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer {
} }
@Override @Override
public void setFurnaceOwner(Furnace furnace, UUID uuid) { public void setFurnaceOwner(@NotNull Furnace furnace, @NotNull UUID uuid) {
PersistentDataContainer dataContainer = ((PersistentDataHolder) furnace).getPersistentDataContainer(); PersistentDataContainer dataContainer = ((PersistentDataHolder) furnace).getPersistentDataContainer();
dataContainer.set(furnaceOwner_MostSig_Key, PersistentDataType.LONG, uuid.getMostSignificantBits()); dataContainer.set(furnaceOwner_MostSig_Key, PersistentDataType.LONG, uuid.getMostSignificantBits());
@ -72,7 +63,7 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer {
} }
@Override @Override
public void setSuperAbilityBoostedItem(ItemStack itemStack, int originalDigSpeed) { public void setSuperAbilityBoostedItem(@NotNull ItemStack itemStack, int originalDigSpeed) {
if(itemStack.getItemMeta() == null) { if(itemStack.getItemMeta() == null) {
mcMMO.p.getLogger().severe("Can not assign persistent data to an item with null item metadata"); mcMMO.p.getLogger().severe("Can not assign persistent data to an item with null item metadata");
return; return;
@ -87,7 +78,7 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer {
} }
@Override @Override
public boolean isSuperAbilityBoosted(ItemStack itemStack) { public boolean isSuperAbilityBoosted(@NotNull ItemStack itemStack) {
if(itemStack.getItemMeta() == null) if(itemStack.getItemMeta() == null)
return false; return false;

View File

@ -5,8 +5,11 @@ import com.gmail.nossr50.datatypes.meta.UUIDMeta;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import org.bukkit.block.Furnace; import org.bukkit.block.Furnace;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; 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.bukkit.metadata.Metadatable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -26,7 +29,7 @@ public class SpigotTemporaryDataLayer extends AbstractPersistentDataLayer {
} }
@Override @Override
public UUID getFurnaceOwner(Furnace furnace) { public UUID getFurnaceOwner(@NotNull Furnace furnace) {
Metadatable metadatable = (Metadatable) furnace; Metadatable metadatable = (Metadatable) furnace;
if(metadatable.getMetadata(FURNACE_OWNER_METADATA_KEY).size() > 0) { if(metadatable.getMetadata(FURNACE_OWNER_METADATA_KEY).size() > 0) {
@ -38,7 +41,7 @@ public class SpigotTemporaryDataLayer extends AbstractPersistentDataLayer {
} }
@Override @Override
public void setFurnaceOwner(@NotNull Furnace furnace, UUID uuid) { public void setFurnaceOwner(@NotNull Furnace furnace, @NotNull UUID uuid) {
Metadatable metadatable = (Metadatable) furnace; Metadatable metadatable = (Metadatable) furnace;
if(metadatable.getMetadata(FURNACE_OWNER_METADATA_KEY).size() > 0) { 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) { public void setSuperAbilityBoostedItem(@NotNull ItemStack itemStack, int originalDigSpeed) {
Metadatable metadatable = getMetadatable(itemStack); Metadatable metadatable = getMetadatable(itemStack);
metadatable.setMetadata(ABILITY_TOOL_METADATA_KEY, new SuperAbilityToolMeta(originalDigSpeed, mcMMO.p)); 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) { private Metadatable getMetadatable(@NotNull ItemStack itemStack) {
@ -60,19 +74,27 @@ public class SpigotTemporaryDataLayer extends AbstractPersistentDataLayer {
@Override @Override
public boolean isSuperAbilityBoosted(@NotNull ItemStack itemStack) { public boolean isSuperAbilityBoosted(@NotNull ItemStack itemStack) {
Metadatable metadatable = getMetadatable(itemStack); ItemMeta itemMeta = itemStack.getItemMeta();
return metadatable.getMetadata(ABILITY_TOOL_METADATA_KEY).size() > 0;
if(itemMeta == null)
return false;
CustomItemTagContainer tagContainer = itemMeta.getCustomTagContainer();
return tagContainer.hasCustomTag(superAbilityBoosted, ItemTagType.INTEGER);
} }
@Override @Override
public int getSuperAbilityToolOriginalDigSpeed(@NotNull ItemStack itemStack) { public int getSuperAbilityToolOriginalDigSpeed(@NotNull ItemStack itemStack) {
Metadatable metadatable = getMetadatable(itemStack); ItemMeta itemMeta = itemStack.getItemMeta();
if(metadatable.getMetadata(ABILITY_TOOL_METADATA_KEY).size() > 0) { if(itemMeta == null)
SuperAbilityToolMeta toolMeta = (SuperAbilityToolMeta) metadatable.getMetadata(ABILITY_TOOL_METADATA_KEY).get(0); return 0;
return toolMeta.asInt();
CustomItemTagContainer tagContainer = itemMeta.getCustomTagContainer();
if(tagContainer.hasCustomTag(superAbilityBoosted , ItemTagType.INTEGER)) {
return tagContainer.getCustomTag(superAbilityBoosted, ItemTagType.INTEGER);
} else { } 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; return 0;
} }
} }
@ -82,6 +104,9 @@ public class SpigotTemporaryDataLayer extends AbstractPersistentDataLayer {
int originalSpeed = getSuperAbilityToolOriginalDigSpeed(itemStack); int originalSpeed = getSuperAbilityToolOriginalDigSpeed(itemStack);
ItemMeta itemMeta = itemStack.getItemMeta(); ItemMeta itemMeta = itemStack.getItemMeta();
if(itemMeta == null)
return;
if(itemMeta.hasEnchant(Enchantment.DIG_SPEED)) { if(itemMeta.hasEnchant(Enchantment.DIG_SPEED)) {
itemMeta.removeEnchant(Enchantment.DIG_SPEED); itemMeta.removeEnchant(Enchantment.DIG_SPEED);
} }

View File

@ -26,6 +26,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.*; import org.bukkit.inventory.*;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import java.util.Iterator; import java.util.Iterator;
@ -131,7 +132,7 @@ public class SkillUtils {
if (HiddenConfig.getInstance().useEnchantmentBuffs()) { if (HiddenConfig.getInstance().useEnchantmentBuffs()) {
ItemStack heldItem = player.getInventory().getItemInMainHand(); ItemStack heldItem = player.getInventory().getItemInMainHand();
if (heldItem == null || heldItem.getType() == Material.AIR) { if (!ItemUtils.canBeSuperAbilityDigBoosted(heldItem)) {
return; 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()) { if (!HiddenConfig.getInstance().useEnchantmentBuffs()) {
return; return;
} }
for (ItemStack item : player.getInventory().getContents()) { for (ItemStack itemStack : player.getInventory().getContents()) {
removeAbilityBuff(item); removeAbilityBuff(itemStack);
} }
} }
public static void removeAbilityBuff(ItemStack itemStack) { public static void removeAbilityBuff(@NotNull ItemStack itemStack) {
if (itemStack == null || itemStack.getType() == Material.AIR) { if(!ItemUtils.canBeSuperAbilityDigBoosted(itemStack))
return; return;
}
//Take the lore off //Take the lore off
ItemUtils.removeAbilityLore(itemStack); ItemUtils.removeAbilityLore(itemStack);