PAPI support WIP

This commit is contained in:
FeuSalamander 2023-04-10 16:23:18 +02:00
parent d820c202c9
commit c093c1d747
4 changed files with 42 additions and 19 deletions

View File

@ -151,6 +151,10 @@
<id>papermc-repo</id> <id>papermc-repo</id>
<url>https://repo.papermc.io/repository/maven-public/</url> <url>https://repo.papermc.io/repository/maven-public/</url>
</repository> </repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -166,5 +170,10 @@
<version>5.4</version> <version>5.4</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>net.william278</groupId>
<artifactId>PAPIProxyBridge</artifactId>
<version>1.0</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,10 +1,8 @@
package me.feusalamander.vmessage; package me.feusalamander.vmessage;
import com.google.common.annotations.Beta;
import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.connection.DisconnectEvent;
import com.velocitypowered.api.event.player.PlayerChatEvent; import com.velocitypowered.api.event.player.PlayerChatEvent;
import com.velocitypowered.api.event.player.ServerConnectedEvent;
import com.velocitypowered.api.event.player.ServerPostConnectEvent; import com.velocitypowered.api.event.player.ServerPostConnectEvent;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
@ -16,16 +14,14 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.LuckPerms; import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider; import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.cacheddata.CachedMetaData; import net.luckperms.api.cacheddata.CachedMetaData;
import net.luckperms.api.context.Context; import net.william278.papiproxybridge.api.PlaceholderAPI;
import net.luckperms.api.context.ContextManager; import net.william278.papiproxybridge.user.OnlineUser;
import net.luckperms.api.model.user.User;
import java.net.ProtocolException;
import java.security.SignatureException;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.SortedMap; import java.util.UUID;
import java.util.concurrent.CompletionException; import java.util.concurrent.atomic.AtomicReference;
@SuppressWarnings({"UnstableApiUsage", "deprecation"}) @SuppressWarnings({"UnstableApiUsage", "deprecation"})
public final class Listeners { public final class Listeners {
public static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.builder() public static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.builder()
@ -34,6 +30,7 @@ public final class Listeners {
.build(); .build();
public static final MiniMessage mm = MiniMessage.miniMessage(); public static final MiniMessage mm = MiniMessage.miniMessage();
private LuckPerms luckPermsAPI; private LuckPerms luckPermsAPI;
private PlaceholderAPI placeholderAPI;
private final Configuration configuration; private final Configuration configuration;
private final ProxyServer proxyServer; private final ProxyServer proxyServer;
@ -41,10 +38,12 @@ public final class Listeners {
if (proxyServer.getPluginManager().getPlugin("luckperms").isPresent()) { if (proxyServer.getPluginManager().getPlugin("luckperms").isPresent()) {
this.luckPermsAPI = LuckPermsProvider.get(); this.luckPermsAPI = LuckPermsProvider.get();
} }
if (proxyServer.getPluginManager().getPlugin("papiproxybridge").isPresent()) {
this.placeholderAPI = PlaceholderAPI.getInstance();
}
this.configuration = configuration; this.configuration = configuration;
this.proxyServer = proxyServer; this.proxyServer = proxyServer;
} }
@Subscribe @Subscribe
private void onMessage(final PlayerChatEvent e) { private void onMessage(final PlayerChatEvent e) {
if (!configuration.isMessageEnabled()) { if (!configuration.isMessageEnabled()) {
@ -55,7 +54,6 @@ public final class Listeners {
} }
message(e.getPlayer(), e.getMessage()); message(e.getPlayer(), e.getMessage());
} }
@Subscribe @Subscribe
private void onLeave(final DisconnectEvent e) { private void onLeave(final DisconnectEvent e) {
if (!configuration.isLeaveEnabled()) { if (!configuration.isLeaveEnabled()) {
@ -66,7 +64,9 @@ public final class Listeners {
if (server.isEmpty()) { if (server.isEmpty()) {
return; return;
} }
String message = configuration.getLeaveFormat() String message = configuration.getLeaveFormat();
message = placeholder(message, p);
message = message
.replace("#player#", p.getUsername()) .replace("#player#", p.getUsername())
.replace("#oldserver#", server.get().getServerInfo().getName()); .replace("#oldserver#", server.get().getServerInfo().getName());
if (luckPermsAPI != null) { if (luckPermsAPI != null) {
@ -79,7 +79,6 @@ public final class Listeners {
} }
} }
@Subscribe @Subscribe
private void onChange(final ServerPostConnectEvent e) { private void onChange(final ServerPostConnectEvent e) {
if (!configuration.isChangeEnabled() && !configuration.isJoinEnabled()) { if (!configuration.isChangeEnabled() && !configuration.isJoinEnabled()) {
@ -93,7 +92,9 @@ public final class Listeners {
return; return;
} }
final ServerConnection actual = serverConnection.get(); final ServerConnection actual = serverConnection.get();
String message = configuration.getChangeFormat() String message = configuration.getChangeFormat();
message = placeholder(message, p);
message = message
.replace("#player#", p.getUsername()) .replace("#player#", p.getUsername())
.replace("#oldserver#", pre.getServerInfo().getName()) .replace("#oldserver#", pre.getServerInfo().getName())
.replace("#server#", actual.getServerInfo().getName()); .replace("#server#", actual.getServerInfo().getName());
@ -109,7 +110,9 @@ public final class Listeners {
if (!configuration.isJoinEnabled()) { if (!configuration.isJoinEnabled()) {
return; return;
} }
String message = configuration.getJoinFormat() String message = configuration.getJoinFormat();
message = placeholder(message, p);
message = message
.replace("#player#", p.getUsername()) .replace("#player#", p.getUsername())
.replace("#server#", serverConnection.get().getServerInfo().getName()); .replace("#server#", serverConnection.get().getServerInfo().getName());
if (luckPermsAPI != null) { if (luckPermsAPI != null) {
@ -122,7 +125,6 @@ public final class Listeners {
} }
} }
} }
private String luckperms(String message, final Player p) { private String luckperms(String message, final Player p) {
final CachedMetaData data = luckPermsAPI.getPlayerAdapter(Player.class).getMetaData(p); final CachedMetaData data = luckPermsAPI.getPlayerAdapter(Player.class).getMetaData(p);
final String prefix = data.getPrefix(); final String prefix = data.getPrefix();
@ -136,10 +138,18 @@ public final class Listeners {
message = message.replace("#prefix#", "").replace("#suffix#", ""); message = message.replace("#prefix#", "").replace("#suffix#", "");
return message; return message;
} }
private String placeholder(String message, final Player player){
if(placeholderAPI == null)return message;
UUID p = player.getUniqueId();
AtomicReference<String> formated = new AtomicReference<>("");
placeholderAPI.formatPlaceholders("Hello %player_name%!", p).thenAccept(formatedd -> {proxyServer.sendMessage(Component.text("test: "+formatedd));});
return formated.get();
}
public void message(final Player p, final String m) { public void message(final Player p, final String m) {
final boolean permission = p.hasPermission("vmessage.minimessage"); final boolean permission = p.hasPermission("vmessage.minimessage");
String message = configuration.getMessageFormat() String message = configuration.getMessageFormat();
message = placeholder(message, p);
message = message
.replace("#player#", p.getUsername()) .replace("#player#", p.getUsername())
.replace("#server#", p.getCurrentServer().orElseThrow().getServerInfo().getName()); .replace("#server#", p.getCurrentServer().orElseThrow().getServerInfo().getName());
if (luckPermsAPI != null) { if (luckPermsAPI != null) {

View File

@ -20,7 +20,10 @@ import java.nio.file.Path;
version = "1.5.3", version = "1.5.3",
description = "A velocity plugin that creates a multi server chat for the network", description = "A velocity plugin that creates a multi server chat for the network",
authors = {"FeuSalamander"}, authors = {"FeuSalamander"},
dependencies = { @Dependency(id = "luckperms", optional = true) } dependencies = {
@Dependency(id = "luckperms", optional = true),
@Dependency(id = "papiproxybridge",optional = true)
}
) )
public class VMessage { public class VMessage {
private final ProxyServer proxy; private final ProxyServer proxy;

View File

@ -1,3 +1,4 @@
#you can use placeholders from placeholder api
[Message-format] [Message-format]
#set it to true to use MiniMessage and false to use hex colors #set it to true to use MiniMessage and false to use hex colors
minimessage = false minimessage = false