mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-22 17:18:37 +01:00
Use futureproof Paper component serializer when available (#4706)
#plainSerializer will be removed when adventure 5.0.0 releases. This PR prevents this from breaking in the future. Closes #4705
This commit is contained in:
parent
c4e62ae22b
commit
685084219e
@ -8,8 +8,8 @@ java {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(':providers:BaseProviders')
|
implementation project(':providers:BaseProviders')
|
||||||
compileOnly 'io.papermc.paper:paper-api:1.17.1-R0.1-SNAPSHOT'
|
compileOnly 'io.papermc.paper:paper-api:1.18.1-R0.1-SNAPSHOT'
|
||||||
compileOnly 'io.papermc.paper:paper-mojangapi:1.17.1-R0.1-SNAPSHOT'
|
compileOnly 'io.papermc.paper:paper-mojangapi:1.18.1-R0.1-SNAPSHOT'
|
||||||
}
|
}
|
||||||
|
|
||||||
essentials {
|
essentials {
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
package net.ess3.provider.providers;
|
package net.ess3.provider.providers;
|
||||||
|
|
||||||
import io.papermc.paper.advancement.AdvancementDisplay;
|
import io.papermc.paper.advancement.AdvancementDisplay;
|
||||||
|
import io.papermc.paper.text.PaperComponents;
|
||||||
import net.ess3.provider.AbstractAchievementEvent;
|
import net.ess3.provider.AbstractAchievementEvent;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.TextComponent;
|
||||||
|
import net.kyori.adventure.text.serializer.ComponentSerializer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -9,12 +13,25 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.player.PlayerAdvancementDoneEvent;
|
import org.bukkit.event.player.PlayerAdvancementDoneEvent;
|
||||||
|
|
||||||
public class PaperAdvancementListenerProvider implements Listener {
|
public class PaperAdvancementListenerProvider implements Listener {
|
||||||
|
private final ComponentSerializer<Component, TextComponent, String> serializer;
|
||||||
|
|
||||||
|
public PaperAdvancementListenerProvider() {
|
||||||
|
ComponentSerializer<Component, TextComponent, String> yeOldSerializer;
|
||||||
|
try {
|
||||||
|
// This method is only available in Paper 1.18.1+ and replaces the old deprecated method below.
|
||||||
|
yeOldSerializer = PaperComponents.plainTextSerializer();
|
||||||
|
} catch (NoSuchMethodError e) {
|
||||||
|
//noinspection deprecation
|
||||||
|
yeOldSerializer = PaperComponents.plainSerializer();
|
||||||
|
}
|
||||||
|
this.serializer = yeOldSerializer;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onAdvancement(final PlayerAdvancementDoneEvent event) {
|
public void onAdvancement(final PlayerAdvancementDoneEvent event) {
|
||||||
final AdvancementDisplay display = event.getAdvancement().getDisplay();
|
final AdvancementDisplay display = event.getAdvancement().getDisplay();
|
||||||
if (display != null && display.doesAnnounceToChat()) {
|
if (display != null && display.doesAnnounceToChat()) {
|
||||||
//noinspection deprecation
|
Bukkit.getPluginManager().callEvent(new AbstractAchievementEvent(event.getPlayer(), serializer.serialize(display.title())));
|
||||||
Bukkit.getPluginManager().callEvent(new AbstractAchievementEvent(event.getPlayer(), Bukkit.getUnsafe().plainComponentSerializer().serialize(display.title())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user