Fix default advancement message being bad on non-Paper. Changed the default award format to say "advancement" instead of "achievement"

This commit is contained in:
Vankka 2023-07-01 17:29:59 +03:00
parent 0e4d04c59c
commit 97dbd3501e
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
2 changed files with 5 additions and 13 deletions

View File

@ -52,11 +52,11 @@ public class BukkitAdvancementListener extends AbstractBukkitAwardListener {
|| version.startsWith("v1_2")) {
// 1.19.4+
nms = new NMS("org.bukkit.craftbukkit." + version + ".advancement.CraftAdvancement",
"k", "d", "i", "a");
"d", "i", "a");
} else {
// <1.19.4
nms = new NMS("org.bukkit.craftbukkit." + version + ".advancement.CraftAdvancement",
"j", "c", "i", "a");
"c", "i", "a");
}
} catch (Throwable t) {
logger.error("Could not get NMS methods for advancements.");
@ -80,8 +80,8 @@ public class BukkitAdvancementListener extends AbstractBukkitAwardListener {
forwarder.publishEvent(
event,
event.getPlayer(),
data.nameJson != null ? ComponentUtil.toAPI(BukkitComponentSerializer.gson().deserialize(data.nameJson)) : null,
data.titleJson != null ? ComponentUtil.toAPI(BukkitComponentSerializer.gson().deserialize(data.titleJson)) : null,
null,
false);
} catch (ReflectiveOperationException e) {
logger.debug("Failed to get advancement data", e);
@ -91,7 +91,6 @@ public class BukkitAdvancementListener extends AbstractBukkitAwardListener {
private static class NMS {
private final Method handleMethod;
private final Method advancementNameMethod;
private final Method advancementDisplayMethod;
private final Method broadcastToChatMethod;
private final Method titleMethod;
@ -99,7 +98,6 @@ public class BukkitAdvancementListener extends AbstractBukkitAwardListener {
public NMS(
String craftAdvancementClassName,
String nameMethodName,
String displayMethodName,
String broadcastToChatMethodName,
String titleMethodName
@ -107,7 +105,6 @@ public class BukkitAdvancementListener extends AbstractBukkitAwardListener {
Class<?> clazz = Class.forName(craftAdvancementClassName);
handleMethod = clazz.getDeclaredMethod("getHandle");
Class<?> nmsClass = handleMethod.getReturnType();
advancementNameMethod = nmsClass.getDeclaredMethod(nameMethodName);
advancementDisplayMethod = nmsClass.getDeclaredMethod(displayMethodName);
Class<?> displayClass = advancementDisplayMethod.getReturnType();
broadcastToChatMethod = displayClass.getDeclaredMethod(broadcastToChatMethodName);
@ -133,11 +130,8 @@ public class BukkitAdvancementListener extends AbstractBukkitAwardListener {
return null;
}
Object nameChat = advancementNameMethod.invoke(nms);
Object titleChat = titleMethod.invoke(display);
return new ReturnData(
toJson(nameChat),
toJson(titleChat)
);
}
@ -149,11 +143,9 @@ public class BukkitAdvancementListener extends AbstractBukkitAwardListener {
private static class ReturnData {
private final String nameJson;
private final String titleJson;
public ReturnData(String nameJson, String titleJson) {
this.nameJson = nameJson;
public ReturnData(String titleJson) {
this.titleJson = titleJson;
}
}

View File

@ -34,7 +34,7 @@ public class AwardMessageConfig implements IMessageConfig {
.addEmbed(
DiscordMessageEmbed.builder()
.setAuthor(
"%award_title|text:'{player_name} made the achievement {award_name}'%",
"%award_title|text:'{player_name} made the advancement {award_name}'%",
null,
"%player_avatar_url%"
)