mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 14:38:49 +00:00
1 parent
2c1bbf04e3
commit
1ce21395dd
2 files changed
+79
No files matched your search
@@ -25,6 +25,7 @@ import net.draycia.carbon.common.messaging.RedisMessageService;
|
||||
import net.draycia.carbon.listeners.contexts.DistanceContext;
|
||||
import net.draycia.carbon.listeners.contexts.EconomyContext;
|
||||
import net.draycia.carbon.common.contexts.FilterContext;
|
||||
import net.draycia.carbon.listeners.contexts.PAPIContext;
|
||||
import net.draycia.carbon.listeners.contexts.TownyContext;
|
||||
import net.draycia.carbon.listeners.contexts.WorldGuardContext;
|
||||
import net.draycia.carbon.listeners.contexts.mcMMOContext;
|
||||
@@ -343,6 +344,7 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
|
||||
new DistanceContext();
|
||||
new FilterContext(this);
|
||||
new PAPIContext();
|
||||
}
|
||||
|
||||
public @NonNull MessageManager messageManager() {
|
||||
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package net.draycia.carbon.listeners.contexts;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.draycia.carbon.api.events.MessageContextEvent;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.ReceiverContextEvent;
|
||||
import net.draycia.carbon.api.Context;
|
||||
import net.kyori.event.PostOrders;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class PAPIContext {
|
||||
|
||||
private @NonNull static final String KEY = "placeholder";
|
||||
private @NonNull static final String SENDER = "-sender";
|
||||
private @NonNull static final String RECEIVER = "-receiver";
|
||||
|
||||
public PAPIContext() {
|
||||
CarbonEvents.register(ReceiverContextEvent.class, PostOrders.NORMAL, false, event -> {
|
||||
final Context context = event.channel().context(KEY + RECEIVER);
|
||||
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!context.isString()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String[] pieces = context.asString().split("=");
|
||||
|
||||
if (pieces.length != 2) {
|
||||
return; // TODO: maybe alert of misconfiguration?
|
||||
}
|
||||
|
||||
final Player receiver = Bukkit.getPlayer(event.recipient().uuid());
|
||||
|
||||
if (receiver == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String output = PlaceholderAPI.setPlaceholders(receiver, pieces[0]);
|
||||
|
||||
event.cancelled(output.equals(pieces[1]));
|
||||
});
|
||||
|
||||
CarbonEvents.register(MessageContextEvent.class, PostOrders.NORMAL, false, event -> {
|
||||
final Context context = event.channel().context(KEY + SENDER);
|
||||
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!context.isString()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String[] pieces = context.asString().split("=");
|
||||
|
||||
if (pieces.length != 2) {
|
||||
return; // TODO: maybe alert of misconfiguration?
|
||||
}
|
||||
|
||||
final Player receiver = Bukkit.getPlayer(event.user().uuid());
|
||||
|
||||
if (receiver == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String output = PlaceholderAPI.setPlaceholders(receiver, pieces[0]);
|
||||
|
||||
event.cancelled(output.equals(pieces[1]));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user