mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-03 23:18:04 +01:00
Add provider to use new Paper advancement API (#4588)
Paper added in PaperMC/Paper@40ee634
This commit is contained in:
parent
70045c30f3
commit
2ed94f1048
EssentialsDiscord/src/main/java/net/essentialsx/discord
providers/PaperProvider
@ -21,6 +21,7 @@ import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.dv8tion.jda.api.utils.cache.CacheFlag;
|
||||
import net.ess3.nms.refl.providers.AchievementListenerProvider;
|
||||
import net.ess3.nms.refl.providers.AdvancementListenerProvider;
|
||||
import net.ess3.provider.providers.PaperAdvancementListenerProvider;
|
||||
import net.essentialsx.api.v2.events.discord.DiscordMessageEvent;
|
||||
import net.essentialsx.api.v2.services.discord.DiscordService;
|
||||
import net.essentialsx.api.v2.services.discord.InteractionController;
|
||||
@ -207,7 +208,12 @@ public class JDADiscordService implements DiscordService, IEssentialsModule {
|
||||
|
||||
try {
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_12_0_R01)) {
|
||||
Bukkit.getPluginManager().registerEvents(new AdvancementListenerProvider(), plugin);
|
||||
try {
|
||||
Class.forName("io.papermc.paper.advancement.AdvancementDisplay");
|
||||
Bukkit.getPluginManager().registerEvents(new PaperAdvancementListenerProvider(), plugin);
|
||||
} catch (ClassNotFoundException e) {
|
||||
Bukkit.getPluginManager().registerEvents(new AdvancementListenerProvider(), plugin);
|
||||
}
|
||||
} else {
|
||||
Bukkit.getPluginManager().registerEvents(new AchievementListenerProvider(), plugin);
|
||||
}
|
||||
|
@ -2,10 +2,14 @@ plugins {
|
||||
id("essentials.base-conventions")
|
||||
}
|
||||
|
||||
java {
|
||||
disableAutoTargetJvm()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(':providers:BaseProviders')
|
||||
compileOnly 'com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT'
|
||||
compileOnly 'com.destroystokyo.paper:paper-mojangapi:1.16.5-R0.1-SNAPSHOT'
|
||||
compileOnly 'io.papermc.paper:paper-api:1.17.1-R0.1-SNAPSHOT'
|
||||
compileOnly 'io.papermc.paper:paper-mojangapi:1.17.1-R0.1-SNAPSHOT'
|
||||
}
|
||||
|
||||
essentials {
|
||||
|
@ -0,0 +1,20 @@
|
||||
package net.ess3.provider.providers;
|
||||
|
||||
import io.papermc.paper.advancement.AdvancementDisplay;
|
||||
import net.ess3.provider.AbstractAchievementEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerAdvancementDoneEvent;
|
||||
|
||||
public class PaperAdvancementListenerProvider implements Listener {
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onAdvancement(final PlayerAdvancementDoneEvent event) {
|
||||
final AdvancementDisplay display = event.getAdvancement().getDisplay();
|
||||
if (display != null && display.doesAnnounceToChat()) {
|
||||
//noinspection deprecation
|
||||
Bukkit.getPluginManager().callEvent(new AbstractAchievementEvent(event.getPlayer(), Bukkit.getUnsafe().plainComponentSerializer().serialize(display.title())));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user