mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 14:38:49 +00:00
Add LuckPerms hook and fix PAPI parsing
This commit is contained in:
1 parent
dceb47e160
commit
6286811cb8
5 files changed
+112
-7
No files matched your search
@@ -243,5 +243,12 @@
|
|||||||
<version>2.6.0</version>
|
<version>2.6.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- LuckPerms for custom contexts -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.luckperms</groupId>
|
||||||
|
<artifactId>api</artifactId>
|
||||||
|
<version>5.1</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@@ -5,6 +5,7 @@ import me.clip.placeholderapi.PlaceholderAPI;
|
|||||||
import net.draycia.simplechat.channels.ChatChannel;
|
import net.draycia.simplechat.channels.ChatChannel;
|
||||||
import net.draycia.simplechat.listeners.*;
|
import net.draycia.simplechat.listeners.*;
|
||||||
import net.draycia.simplechat.managers.*;
|
import net.draycia.simplechat.managers.*;
|
||||||
|
import net.draycia.simplechat.managers.luckperms.LuckPermsHookManager;
|
||||||
import net.draycia.simplechat.storage.UserService;
|
import net.draycia.simplechat.storage.UserService;
|
||||||
import net.draycia.simplechat.storage.impl.JSONUserService;
|
import net.draycia.simplechat.storage.impl.JSONUserService;
|
||||||
import net.draycia.simplechat.storage.impl.MySQLUserService;
|
import net.draycia.simplechat.storage.impl.MySQLUserService;
|
||||||
@@ -14,6 +15,7 @@ import net.kyori.adventure.text.Component;
|
|||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeCordComponentSerializer;
|
import net.kyori.adventure.text.serializer.bungeecord.BungeeCordComponentSerializer;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@@ -30,6 +32,7 @@ public final class SimpleChat extends JavaPlugin {
|
|||||||
private PluginMessageManager pluginMessageManager;
|
private PluginMessageManager pluginMessageManager;
|
||||||
private CommandManager commandManager;
|
private CommandManager commandManager;
|
||||||
private ChannelManager channelManager;
|
private ChannelManager channelManager;
|
||||||
|
private LuckPermsHookManager luckPermsHookManager = null;
|
||||||
private RedisManager redisManager = null;
|
private RedisManager redisManager = null;
|
||||||
|
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
@@ -60,6 +63,10 @@ public final class SimpleChat extends JavaPlugin {
|
|||||||
commandManager = new CommandManager(this);
|
commandManager = new CommandManager(this);
|
||||||
channelManager = new ChannelManager(this);
|
channelManager = new ChannelManager(this);
|
||||||
|
|
||||||
|
if (Bukkit.getPluginManager().isPluginEnabled("LuckPerms")) {
|
||||||
|
luckPermsHookManager = new LuckPermsHookManager(this);
|
||||||
|
}
|
||||||
|
|
||||||
if (getConfig().getBoolean("redis.enabled")) {
|
if (getConfig().getBoolean("redis.enabled")) {
|
||||||
redisManager = new RedisManager(this);
|
redisManager = new RedisManager(this);
|
||||||
}
|
}
|
||||||
@@ -108,7 +115,7 @@ public final class SimpleChat extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Component processMessageWithPapi(Player player, String input, String... placeholders) {
|
public Component processMessageWithPapi(Player player, String input, String... placeholders) {
|
||||||
return processMessage(PlaceholderAPI.setPlaceholders(player, input));
|
return processMessage(PlaceholderAPI.setPlaceholders(player, input), placeholders);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component processMessage(String input, String... placeholders) {
|
public Component processMessage(String input, String... placeholders) {
|
||||||
@@ -143,6 +150,14 @@ public final class SimpleChat extends JavaPlugin {
|
|||||||
return pluginMessageManager;
|
return pluginMessageManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LuckPermsHookManager getLuckPermsHookManager() {
|
||||||
|
return luckPermsHookManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RedisManager getRedisManager() {
|
||||||
|
return redisManager;
|
||||||
|
}
|
||||||
|
|
||||||
public UserService getUserService() {
|
public UserService getUserService() {
|
||||||
return userService;
|
return userService;
|
||||||
}
|
}
|
||||||
@@ -154,8 +169,4 @@ public final class SimpleChat extends JavaPlugin {
|
|||||||
public ItemStackUtils getItemStackUtils() {
|
public ItemStackUtils getItemStackUtils() {
|
||||||
return itemStackUtils;
|
return itemStackUtils;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RedisManager getRedisManager() {
|
|
||||||
return redisManager;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
package net.draycia.simplechat.managers.luckperms;
|
||||||
|
|
||||||
|
import net.draycia.simplechat.SimpleChat;
|
||||||
|
import net.draycia.simplechat.managers.luckperms.contexts.CanSeeChannelCalculator;
|
||||||
|
import net.luckperms.api.LuckPerms;
|
||||||
|
import net.luckperms.api.context.ContextCalculator;
|
||||||
|
import net.luckperms.api.context.ContextManager;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class LuckPermsHookManager {
|
||||||
|
|
||||||
|
private final SimpleChat simpleChat;
|
||||||
|
private final ContextManager contextManager;
|
||||||
|
private final List<ContextCalculator<Player>> registeredCalculators = new ArrayList<>();
|
||||||
|
|
||||||
|
public LuckPermsHookManager(SimpleChat simpleChat) {
|
||||||
|
this.simpleChat = simpleChat;
|
||||||
|
|
||||||
|
LuckPerms luckPerms = this.simpleChat.getServer().getServicesManager().load(LuckPerms.class);
|
||||||
|
|
||||||
|
if (luckPerms == null) {
|
||||||
|
throw new IllegalStateException("LuckPerms API not loaded.");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.contextManager = luckPerms.getContextManager();
|
||||||
|
|
||||||
|
register(() -> new CanSeeChannelCalculator(simpleChat));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void register(Supplier<ContextCalculator<Player>> calculatorSupplier) {
|
||||||
|
ContextCalculator<Player> calculator = calculatorSupplier.get();
|
||||||
|
|
||||||
|
this.contextManager.registerCalculator(calculator);
|
||||||
|
this.registeredCalculators.add(calculator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unregisterContexts() {
|
||||||
|
this.registeredCalculators.forEach(this.contextManager::unregisterCalculator);
|
||||||
|
this.registeredCalculators.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+41
@@ -0,0 +1,41 @@
|
|||||||
|
package net.draycia.simplechat.managers.luckperms.contexts;
|
||||||
|
|
||||||
|
import net.draycia.simplechat.SimpleChat;
|
||||||
|
import net.draycia.simplechat.channels.ChatChannel;
|
||||||
|
import net.luckperms.api.context.ContextCalculator;
|
||||||
|
import net.luckperms.api.context.ContextConsumer;
|
||||||
|
import net.luckperms.api.context.ImmutableContextSet;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class CanSeeChannelCalculator implements ContextCalculator<Player> {
|
||||||
|
|
||||||
|
private static final String KEY = "can-see-channel";
|
||||||
|
|
||||||
|
private SimpleChat simpleChat;
|
||||||
|
|
||||||
|
public CanSeeChannelCalculator(SimpleChat simpleChat) {
|
||||||
|
this.simpleChat = simpleChat;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void calculate(Player player, ContextConsumer consumer) {
|
||||||
|
for (ChatChannel channel : simpleChat.getChannelManager().getRegistry().values()) {
|
||||||
|
boolean canUse = channel.canPlayerUse(simpleChat.getUserService().wrap(player));
|
||||||
|
|
||||||
|
consumer.accept(KEY + ":" + channel.getKey(), canUse ? "true" : "false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public net.luckperms.api.context.ContextSet estimatePotentialContexts() {
|
||||||
|
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
|
||||||
|
|
||||||
|
for (ChatChannel channel : simpleChat.getChannelManager().getRegistry().values()) {
|
||||||
|
builder.add(KEY + ":" + channel.getKey(), "true");
|
||||||
|
builder.add(KEY + ":" + channel.getKey(), "false");
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
name: SimpleChat
|
name: SimpleChat
|
||||||
version: ${project.version}
|
version: ${project.version}
|
||||||
main: net.draycia.simplechat.SimpleChat
|
main: net.draycia.simplechat.SimpleChat
|
||||||
api-version: 1.13
|
api-version: 1.16
|
||||||
depend: [PlaceholderAPI, Vault]
|
depend: [PlaceholderAPI, Vault]
|
||||||
softdepend: [Towny, mcMMO, Votifier]
|
softdepend: [LuckPerms]
|
||||||
Reference in new issue
Block a user