Use block placement material on 1.21+, fixes #2256

This commit is contained in:
PikaMug 2024-07-22 18:29:07 -04:00
parent f5b3dc8614
commit ba078ea7f8
4 changed files with 29 additions and 6 deletions

View File

@ -76,7 +76,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<version>1.19.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -166,7 +166,7 @@
<dependency>
<groupId>com.github.PikaMug</groupId>
<artifactId>LocaleLib</artifactId>
<version>3.9</version>
<version>60b38e1fbe</version>
</dependency>
<dependency>
<groupId>de.tr7zw</groupId>
@ -285,6 +285,12 @@
<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>

View File

@ -402,6 +402,11 @@ public class BukkitBlockListener implements Listener {
} catch (final IllegalArgumentException e) {
// https://github.com/PikaMug/Quests/issues/2243
}
try {
return new ItemStack(block.getBlockData().getPlacementMaterial(), 1, durability);
} catch (Exception e) {
// https://github.com/PikaMug/Quests/issues/2256
}
return null;
}
}

View File

@ -223,10 +223,14 @@ public class BukkitItemUtil {
return null;
}
try {
final Material mat = Material.getMaterial(material.toUpperCase());
Material mat = Material.getMaterial(material.toUpperCase());
if (mat == null) {
return null;
}
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();
}
return new ItemStack(mat, amount, durability);
} catch (final Exception e) {
try {

View File

@ -10,8 +10,8 @@
package me.pikamug.quests.util;
import me.pikamug.quests.Quests;
import me.clip.placeholderapi.PlaceholderAPI;
import me.pikamug.quests.Quests;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@ -25,6 +25,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
@ -59,7 +60,6 @@ public class BukkitLang {
* @param key label as it appears in lang file, such as "journalNoQuests"
* @return formatted string, plus processing through PlaceholderAPI by clip
*/
@SuppressWarnings("deprecation")
public static String get(final Player player, final String key) {
if (key == null) {
return null;
@ -71,7 +71,15 @@ public class BukkitLang {
try {
locale = player.getLocale();
} catch (final NoSuchMethodError e) {
locale = player.spigot().getLocale();
try {
final Method m = player.spigot().getClass().getDeclaredMethod("getLocale");
m.setAccessible(true);
locale = (String) m.invoke(player.spigot());
} catch (final Exception e2) {
plugin.getPluginLogger().severe("Legacy player locale reflection failed, defaulting to en_US");
e2.printStackTrace();
locale = "en_US";
}
}
final int separator = locale.indexOf("_");
if (separator == -1) {