mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 06:28:54 +00:00
Scrap LP hook and fix bugs
This commit is contained in:
1 parent
3a6f51ddc6
commit
9f98f6a42d
12 files changed
+103
-154
No files matched your search
@@ -37,11 +37,17 @@ public class ChannelManager {
|
||||
channels.add(channel);
|
||||
|
||||
if (channel.isDefault()) {
|
||||
simpleChat.getLogger().info("Default channel found: " + channel.getName());
|
||||
defaultChannelKey = channel.getKey();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (ChatChannel channel : channels) {
|
||||
simpleChat.getLogger().info("Registering channel: " + channel.getName());
|
||||
getRegistry().register(channel.getKey(), channel);
|
||||
}
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new ChannelRegisterEvent(channels, getRegistry()));
|
||||
}
|
||||
|
||||
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
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
@@ -1,41 +0,0 @@
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user