mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-11-25 12:25:15 +01:00
Add spigot listener for advancements
This commit is contained in:
parent
91fa61542d
commit
273f3d9a19
@ -38,7 +38,7 @@ dependencies {
|
||||
annotationProcessor project(':api')
|
||||
|
||||
// Platform
|
||||
compileOnly(libs.spigotapi)
|
||||
compileOnly(libs.bukkit)
|
||||
|
||||
// Common
|
||||
compileOnly project(':common')
|
||||
@ -47,6 +47,7 @@ dependencies {
|
||||
// Folia, modern bukkit
|
||||
api project(':bukkit:bukkit-folia')
|
||||
api project(':bukkit:bukkit-paper')
|
||||
api project(':bukkit:bukkit-spigot')
|
||||
api project(':bukkit:bukkit-bukkit1_12')
|
||||
|
||||
// DependencyDownload
|
||||
@ -72,6 +73,7 @@ dependencies {
|
||||
compileOnly(libs.chatty)
|
||||
compileOnly(libs.griefprevention)
|
||||
compileOnly(libs.lunachat)
|
||||
compileOnly(libs.bungeecord.chat) // Required for LunaChatIntegration
|
||||
compileOnly(libs.mcmmo)
|
||||
compileOnly(libs.townychat)
|
||||
compileOnly(libs.venturechat)
|
||||
|
@ -30,6 +30,9 @@ import org.bukkit.event.player.PlayerAdvancementDoneEvent;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Used for Spigot and Paper in versions before they added advancement apis.
|
||||
*/
|
||||
public class BukkitAdvancementListener extends AbstractBukkitAwardListener {
|
||||
|
||||
private final NMS nms;
|
||||
@ -37,19 +40,12 @@ public class BukkitAdvancementListener extends AbstractBukkitAwardListener {
|
||||
public BukkitAdvancementListener(DiscordSRV discordSRV, IBukkitAwardForwarder forwarder) {
|
||||
super(discordSRV, forwarder);
|
||||
|
||||
String className = Bukkit.getServer().getClass().getName();
|
||||
String[] packageParts = className.split("\\.");
|
||||
if (packageParts.length != 5) {
|
||||
this.nms = null;
|
||||
logger.error("Server does not have NMS, incompatible with advancements.");
|
||||
return;
|
||||
}
|
||||
String version = Bukkit.getServer().getBukkitVersion().split("-", 2)[0];
|
||||
|
||||
String version = packageParts[3];
|
||||
NMS nms = null;
|
||||
try {
|
||||
if ((version.startsWith("v1_19") && !version.startsWith("v1_19_R1") && !version.startsWith("v1_19_R2"))
|
||||
|| version.startsWith("v1_2")) {
|
||||
if ((version.startsWith("1.19") && !version.matches("1.19.[1-3].*"))
|
||||
|| version.startsWith("1.2")) {
|
||||
// 1.19.4+
|
||||
nms = new NMS("org.bukkit.craftbukkit." + version + ".advancement.CraftAdvancement",
|
||||
"d", "i", "a");
|
||||
|
11
bukkit/spigot/build.gradle
Normal file
11
bukkit/spigot/build.gradle
Normal file
@ -0,0 +1,11 @@
|
||||
dependencies {
|
||||
// Platform
|
||||
compileOnly(libs.spigotapi)
|
||||
|
||||
// Adventure (runtime downloaded by :bukkit)
|
||||
compileOnly(libs.adventure.platform.bukkit)
|
||||
|
||||
// Common
|
||||
compileOnly project(':bukkit:bukkit-bukkit1_12')
|
||||
compileOnly project(':common')
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.discordsrv.bukkit.listener.award;
|
||||
|
||||
import com.discordsrv.api.component.MinecraftComponent;
|
||||
import com.discordsrv.common.DiscordSRV;
|
||||
import com.discordsrv.common.component.util.ComponentUtil;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer;
|
||||
import org.bukkit.advancement.Advancement;
|
||||
import org.bukkit.advancement.AdvancementDisplay;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerAdvancementDoneEvent;
|
||||
|
||||
public class SpigotModernAdvancementListener extends AbstractBukkitAwardListener {
|
||||
|
||||
public SpigotModernAdvancementListener(DiscordSRV discordSRV, IBukkitAwardForwarder forwarder) {
|
||||
super(discordSRV, forwarder);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerAdvancementDone(PlayerAdvancementDoneEvent event) {
|
||||
Advancement advancement = event.getAdvancement();
|
||||
AdvancementDisplay display = advancement.getDisplay();
|
||||
if (display == null || !display.shouldAnnounceChat()) {
|
||||
logger.trace("Skipping advancement display of \"" + advancement.getKey().getKey() + "\" for "
|
||||
+ event.getPlayer() + ": advancement display == null or does not broadcast to chat");
|
||||
return;
|
||||
}
|
||||
|
||||
MinecraftComponent title = ComponentUtil.toAPI(BukkitComponentSerializer.legacy().deserialize(display.getTitle())) ;
|
||||
forwarder.publishEvent(event, event.getPlayer(), title, null, false);
|
||||
}
|
||||
}
|
@ -24,21 +24,39 @@ import com.discordsrv.bukkit.BukkitDiscordSRV;
|
||||
import com.discordsrv.common.player.IPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.intellij.lang.annotations.Language;
|
||||
|
||||
public class BukkitAwardForwarder implements IBukkitAwardForwarder {
|
||||
|
||||
public static Listener get(BukkitDiscordSRV discordSRV) {
|
||||
try {
|
||||
Class.forName("org.bukkit.event.player.PlayerAdvancementDoneEvent");
|
||||
try {
|
||||
Class.forName("io.papermc.paper.advancement.AdvancementDisplay");
|
||||
BukkitAwardForwarder forwarder = new BukkitAwardForwarder(discordSRV);
|
||||
|
||||
return new PaperModernAdvancementListener(discordSRV, new BukkitAwardForwarder(discordSRV));
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
return new BukkitAdvancementListener(discordSRV, new BukkitAwardForwarder(discordSRV));
|
||||
if (exists("org.bukkit.event.player.PlayerAdvancementDoneEvent")) {
|
||||
// Advancement
|
||||
if (exists("io.papermc.paper.advancement.AdvancementDisplay")) {
|
||||
// Paper
|
||||
return new PaperModernAdvancementListener(discordSRV, forwarder);
|
||||
} else if (exists("org.bukkit.advancement.AdvancementDisplay")) {
|
||||
// Spigot
|
||||
return new SpigotModernAdvancementListener(discordSRV, forwarder);
|
||||
} else {
|
||||
// Generic
|
||||
return new BukkitAdvancementListener(discordSRV, forwarder);
|
||||
}
|
||||
} else {
|
||||
// Achievement
|
||||
return new BukkitAchievementListener(discordSRV, forwarder);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean exists(
|
||||
@Language(value = "JAVA", prefix = "class X{static{Class.forName(\"", suffix = "\")}}") String className
|
||||
) {
|
||||
try {
|
||||
Class.forName(className);
|
||||
return true;
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
return new BukkitAchievementListener(discordSRV, new BukkitAwardForwarder(discordSRV));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,14 +19,18 @@
|
||||
package com.discordsrv.common.config.connection;
|
||||
|
||||
import com.discordsrv.common.config.Config;
|
||||
import com.discordsrv.common.config.configurate.annotation.Constants;
|
||||
import com.discordsrv.common.config.main.MainConfig;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
|
||||
@ConfigSerializable
|
||||
public class ConnectionConfig implements Config {
|
||||
|
||||
public static final String FILE_NAME = "connections.yaml";
|
||||
|
||||
@Constants(MainConfig.FILE_NAME)
|
||||
public static final String HEADER = "DiscordSRV's configuration file for connections to different external services.\n"
|
||||
+ "This file is intended to contain connection details to services in order to keep them out of the config.yml\n"
|
||||
+ "This file is intended to contain connection details to services in order to keep them out of the %1\n"
|
||||
+ "and to serve as a easy way to identify and control what external connections are being used.\n"
|
||||
+ "\n"
|
||||
+ "All domains listed as \"Requires a connection to\" require port 443 (https/wss) unless otherwise specified\n"
|
||||
|
@ -21,7 +21,8 @@ dependencyResolutionManagement {
|
||||
version('bukkit_latest', '1.20.1-R0.1-SNAPSHOT')
|
||||
version('folia', '1.20.1-R0.1-SNAPSHOT')
|
||||
library('paperapi', 'io.papermc.paper', 'paper-api').versionRef('bukkit_latest')
|
||||
library('spigotapi', 'org.spigotmc', 'spigot-api').versionRef('bukkit_minimum')
|
||||
library('spigotapi', 'org.spigotmc', 'spigot-api').versionRef('bukkit_latest')
|
||||
library('bukkit', 'org.bukkit', 'bukkit').versionRef('bukkit_minimum')
|
||||
library('spigotapi-onetwelve', 'org.spigotmc', 'spigot-api').versionRef('bukkit1_12')
|
||||
library('folia', 'dev.folia', 'folia-api').versionRef('folia')
|
||||
|
||||
@ -107,6 +108,7 @@ dependencyResolutionManagement {
|
||||
library('venturechat', 'mineverse.aust1n46', 'venturechat').version('3.5.0')
|
||||
library('chatty', 'ru.mrbrikster', 'chatty-api').version('2.19.13')
|
||||
library('lunachat', 'com.github.ucchyocean.lc', 'LunaChat').version('3.0.16')
|
||||
library('bungeecord-chat', 'net.md-5', 'bungeecord-chat').version('1.12-SNAPSHOT')
|
||||
library('mcmmo', 'com.gmail.nossr50', 'mcmmo').version('2.1.220')
|
||||
library('griefprevention', 'me.ryanhamshire', 'GriefPrevention').version('16.18.1')
|
||||
|
||||
@ -149,7 +151,7 @@ rootProject.name = 'DiscordSRV-Ascension'
|
||||
'common', 'common:api', 'common:unrelocate',
|
||||
'i18n',
|
||||
'api',
|
||||
'bukkit', 'bukkit:loader', 'bukkit:folia', 'bukkit:paper', 'bukkit:bukkit1_12',
|
||||
'bukkit', 'bukkit:loader', 'bukkit:folia', 'bukkit:spigot', 'bukkit:paper', 'bukkit:bukkit1_12',
|
||||
'bungee', 'bungee:loader',
|
||||
'sponge', 'sponge:loader',
|
||||
'velocity'
|
||||
|
Loading…
Reference in New Issue
Block a user