Special case for 1.21+ crops, fixes #2256

This commit is contained in:
PikaMug 2024-07-23 22:27:45 -04:00
parent ba078ea7f8
commit 70119ad4ab
5 changed files with 55 additions and 18 deletions

View File

@ -170,8 +170,8 @@
</dependency>
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api-plugin</artifactId>
<version>2.12.4</version>
<artifactId>item-nbt-api</artifactId>
<version>2.13.1</version>
</dependency>
<dependency>
<groupId>xyz.upperlevel.spigot.book</groupId>
@ -265,7 +265,7 @@
<includes>
<include>me.*</include>
<include>com.github.PikaMug:LocaleLib</include>
<include>de.tr7zw:item-nbt-api-plugin</include>
<include>de.tr7zw:item-nbt-api</include>
<include>org.slf4j:slf4j-simple</include>
<include>org.slf4j:slf4j-api</include>
<include>xyz.upperlevel.spigot.book:spigot-book-api</include>
@ -285,12 +285,6 @@
<exclude>plugin.yml</exclude>
</excludes>
</filter>
<filter>
<artifact>de.tr7zw:item-nbt-api-plugin</artifact>
<excludes>
<exclude>plugin.yml</exclude>
</excludes>
</filter>
</filters>
<relocations>
<relocation>
@ -298,7 +292,7 @@
<shadedPattern>me.pikamug.quests.libs.localelib</shadedPattern>
</relocation>
<relocation>
<pattern>de.tr7zw</pattern>
<pattern>de.tr7zw.changeme.nbtapi</pattern>
<shadedPattern>me.pikamug.quests.libs.nbtapi</shadedPattern>
</relocation>
<relocation>

View File

@ -10,6 +10,7 @@
package me.pikamug.quests;
import de.tr7zw.changeme.nbtapi.NBT;
import me.pikamug.localelib.LocaleManager;
import me.pikamug.quests.actions.Action;
import me.pikamug.quests.actions.BukkitActionFactory;
@ -22,10 +23,17 @@ import me.pikamug.quests.convo.misc.QuestAcceptPrompt;
import me.pikamug.quests.dependencies.BukkitDenizenTrigger;
import me.pikamug.quests.dependencies.BukkitDependencies;
import me.pikamug.quests.interfaces.ReloadCallback;
import me.pikamug.quests.listeners.*;
import me.pikamug.quests.listeners.BukkitBlockListener;
import me.pikamug.quests.listeners.BukkitCitizensListener;
import me.pikamug.quests.listeners.BukkitCommandManager;
import me.pikamug.quests.listeners.BukkitConvoListener;
import me.pikamug.quests.listeners.BukkitItemListener;
import me.pikamug.quests.listeners.BukkitPartiesListener;
import me.pikamug.quests.listeners.BukkitPlayerListener;
import me.pikamug.quests.listeners.BukkitUniteListener;
import me.pikamug.quests.listeners.BukkitZnpcsApiListener;
import me.pikamug.quests.listeners.BukkitZnpcsListener;
import me.pikamug.quests.logging.BukkitQuestsLog4JFilter;
import me.pikamug.quests.storage.implementation.jar.BukkitModuleJarStorage;
import me.pikamug.quests.storage.implementation.ModuleStorageImpl;
import me.pikamug.quests.module.CustomObjective;
import me.pikamug.quests.module.CustomRequirement;
import me.pikamug.quests.module.CustomReward;
@ -36,9 +44,11 @@ import me.pikamug.quests.quests.Quest;
import me.pikamug.quests.statistics.BukkitMetrics;
import me.pikamug.quests.storage.BukkitStorageFactory;
import me.pikamug.quests.storage.QuesterStorage;
import me.pikamug.quests.storage.implementation.ModuleStorageImpl;
import me.pikamug.quests.storage.implementation.file.BukkitActionYamlStorage;
import me.pikamug.quests.storage.implementation.file.BukkitConditionYamlStorage;
import me.pikamug.quests.storage.implementation.file.BukkitQuestYamlStorage;
import me.pikamug.quests.storage.implementation.jar.BukkitModuleJarStorage;
import me.pikamug.quests.tasks.BukkitNpcEffectThread;
import me.pikamug.quests.tasks.BukkitPlayerMoveThread;
import me.pikamug.quests.util.BukkitLang;
@ -152,6 +162,9 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
conditionFactory = new BukkitConditionFactory(this);
depends = new BukkitDependencies(this);
trigger = new BukkitDenizenTrigger(this);
if (!NBT.preloadApi()) {
getLogger().warning("NBT-API wasn't initialized properly");
}
// 3 - Load main config
configSettings.init();
@ -588,7 +601,7 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
*
* @param resourcePath jar file location starting from resource folder, i.e. "lang/el-GR/strings.yml"
* @param outputPath file destination starting from Quests folder, i.e. "lang/el-GR/strings.yml"
* @param replace whether or not to replace the destination file
* @param replace whether to replace the destination file
*/
@Override
public void saveResourceAs(String resourcePath, final String outputPath, final boolean replace) {

View File

@ -10,6 +10,7 @@
package me.pikamug.quests.listeners;
import de.tr7zw.changeme.nbtapi.NBT;
import me.pikamug.quests.BukkitQuestsPlugin;
import me.pikamug.quests.enums.ObjectiveType;
import me.pikamug.quests.events.quester.BukkitQuesterPostUpdateObjectiveEvent;
@ -26,6 +27,7 @@ import me.pikamug.quests.util.BukkitLang;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.Ageable;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -403,7 +405,14 @@ public class BukkitBlockListener implements Listener {
// https://github.com/PikaMug/Quests/issues/2243
}
try {
return new ItemStack(block.getBlockData().getPlacementMaterial(), 1, durability);
// Should only happen on Paper 1.21+
final ItemStack item = new ItemStack(block.getBlockData().getPlacementMaterial());
if (block.getBlockData() instanceof Ageable) {
NBT.modify(item, nbt -> {
nbt.setShort("quests_age", (short) ((Ageable)block.getBlockData()).getAge());
});
}
return item;
} catch (Exception e) {
// https://github.com/PikaMug/Quests/issues/2256
}

View File

@ -14,6 +14,7 @@ import com.alessiodp.parties.api.interfaces.Party;
import com.alessiodp.parties.api.interfaces.PartyPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.util.player.UserManager;
import de.tr7zw.changeme.nbtapi.NBT;
import io.github.znetworkw.znpcservers.npc.NPC;
import lol.pyr.znpcsplus.api.npc.Npc;
import me.clip.placeholderapi.PlaceholderAPI;
@ -1827,6 +1828,19 @@ public class BukkitQuester implements Quester {
// Age toBreak unspecified so ignore durability
goal = toBreak;
}
} else if (Material.getMaterial("CRAFTER") != null && broken.getType().isEdible()) {
// Paper 1.21+ is special case
final short toBreakAge = NBT.get(toBreak, nbt -> (short) nbt.getShort("quests_age"));
final short brokenAge = NBT.get(broken, nbt -> (short) nbt.getShort("quests_age"));
if (toBreakAge > 0) {
// Age toBreak specified so check for durability
if (brokenAge == toBreakAge) {
goal = toBreak;
}
} else {
// Age toBreak unspecified so ignore durability
goal = toBreak;
}
} else if (broken.getType().name().equals("RED_ROSE")) {
// Flowers are unique so check for durability
if (broken.getDurability() == toBreak.getDurability()) {
@ -3820,7 +3834,7 @@ public class BukkitQuester implements Quester {
final Stage stage = getCurrentStage(quest);
if (stage != null) {
quest.updateCompass(this, stage);
// TODO - decide whether or not to handle this
// TODO - decide whether to handle this
/*if (q.equals(quest) == false) {
if (getPlayer() != null && getPlayer().isOnline()) {
quitQuest(quest, ChatColor.GOLD + Lang.get("questModified")

View File

@ -10,6 +10,7 @@
package me.pikamug.quests.util;
import de.tr7zw.changeme.nbtapi.NBT;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
@ -227,11 +228,17 @@ public class BukkitItemUtil {
if (mat == null) {
return null;
}
ItemStack item;
if (mat.isBlock() && Material.getMaterial("CRAFTER") != null) {
// Paper 1.21+ does not allow ItemStack from unobtainable blocks (i.e. CARROTS block)
mat = mat.createBlockData().getPlacementMaterial();
item = new ItemStack(mat.createBlockData().getPlacementMaterial(), amount);
NBT.modify(item, nbt -> {
nbt.setShort("quests_age", durability);
});
} else {
item = new ItemStack(mat, amount, durability);
}
return new ItemStack(mat, amount, durability);
return item;
} catch (final Exception e) {
try {
Bukkit.getLogger().warning(material + " x " + amount