mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Remove contexts and item linking check
This commit is contained in:
1 parent
4131f811b7
commit
3c6f1feb22
10 files changed
+2
-770
No files matched your search
@@ -11,7 +11,6 @@ import net.draycia.carbon.bukkit.users.BukkitConsoleUser;
|
||||
import net.draycia.carbon.bukkit.users.BukkitPlayerUser;
|
||||
import net.draycia.carbon.bukkit.util.BungeeChannelApi;
|
||||
import net.draycia.carbon.bukkit.util.CarbonPlaceholders;
|
||||
import net.draycia.carbon.bukkit.util.FunctionalityConstants;
|
||||
import net.draycia.carbon.bukkit.util.Metrics;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
@@ -32,13 +31,6 @@ import net.draycia.carbon.common.config.ConfigLoader;
|
||||
import net.draycia.carbon.common.messaging.EmptyMessageService;
|
||||
import net.draycia.carbon.api.config.SQLCredentials;
|
||||
import net.draycia.carbon.common.messaging.RedisMessageService;
|
||||
import net.draycia.carbon.bukkit.listeners.contexts.DistanceContext;
|
||||
import net.draycia.carbon.bukkit.listeners.contexts.EconomyContext;
|
||||
import net.draycia.carbon.common.listeners.contexts.FilterContext;
|
||||
import net.draycia.carbon.bukkit.listeners.contexts.PAPIContext;
|
||||
import net.draycia.carbon.bukkit.listeners.contexts.TownyContext;
|
||||
import net.draycia.carbon.bukkit.listeners.contexts.WorldGuardContext;
|
||||
import net.draycia.carbon.bukkit.listeners.contexts.mcMMOContext;
|
||||
import net.draycia.carbon.common.listeners.events.CapsHandler;
|
||||
import net.draycia.carbon.common.listeners.events.CustomPlaceholderHandler;
|
||||
import net.draycia.carbon.common.listeners.events.IgnoredPlayerHandler;
|
||||
@@ -62,7 +54,6 @@ import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.serializer.craftbukkit.BukkitComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -196,16 +187,10 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
// Setup listeners
|
||||
this.setupCommands();
|
||||
this.setupListeners();
|
||||
this.registerContexts();
|
||||
|
||||
// Setup PlaceholderAPI placeholders
|
||||
new CarbonPlaceholders(this).register();
|
||||
|
||||
// Log missing functionality
|
||||
if (this.carbonSettings().showTips() && !FunctionalityConstants.HAS_HOVER_EVENT_METHOD) {
|
||||
this.logger().error("Item linking disabled! Please use Paper 1.16.2 #172 or newer.");
|
||||
}
|
||||
|
||||
this.logger().info("CarbonChat startup finished! Enjoy :)");
|
||||
}
|
||||
|
||||
@@ -304,28 +289,6 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
return this.getDataFolder();
|
||||
}
|
||||
|
||||
private void registerContexts() {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Towny")) {
|
||||
this.getServer().getPluginManager().registerEvents(new TownyContext(this), this);
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("mcMMO")) {
|
||||
this.getServer().getPluginManager().registerEvents(new mcMMOContext(this), this);
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("WorldGuard")) {
|
||||
new WorldGuardContext();
|
||||
}
|
||||
|
||||
if (Bukkit.getServicesManager().isProvidedFor(Economy.class)) {
|
||||
new EconomyContext(this);
|
||||
}
|
||||
|
||||
new DistanceContext();
|
||||
new FilterContext(this);
|
||||
new PAPIContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String resolveName(final @NonNull UUID uuid) {
|
||||
if (this.messageService() instanceof RedisMessageService) {
|
||||
|
||||
-54
@@ -1,54 +0,0 @@
|
||||
package net.draycia.carbon.bukkit.listeners.contexts;
|
||||
|
||||
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.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class DistanceContext {
|
||||
|
||||
private final static @NonNull String KEY = "distance";
|
||||
|
||||
public DistanceContext() {
|
||||
CarbonEvents.register(ReceiverContextEvent.class, PostOrders.NORMAL, false, event -> {
|
||||
final Context context = event.channel().context(KEY);
|
||||
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (context.isBoolean() && !context.asBoolean()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Player sender = Bukkit.getPlayer(event.sender().uuid());
|
||||
final Player recipient = Bukkit.getPlayer(event.recipient().uuid());
|
||||
|
||||
if (sender == null || recipient == null) {
|
||||
event.cancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final Location senderLocation = sender.getLocation();
|
||||
final Location targetLocation = recipient.getLocation();
|
||||
|
||||
if (!senderLocation.getWorld().equals(targetLocation.getWorld())) {
|
||||
event.cancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context.isNumber()) {
|
||||
final double value = context.asNumber().doubleValue();
|
||||
|
||||
if (value > 0) {
|
||||
event.cancelled(senderLocation.distance(targetLocation) > value);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
-105
@@ -1,105 +0,0 @@
|
||||
package net.draycia.carbon.bukkit.listeners.contexts;
|
||||
|
||||
import net.draycia.carbon.bukkit.CarbonChatBukkit;
|
||||
import net.draycia.carbon.api.channels.TextChannel;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.PreChatFormatEvent;
|
||||
import net.draycia.carbon.api.Context;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class EconomyContext {
|
||||
private final @NonNull CarbonChatBukkit carbonChat;
|
||||
|
||||
private final @NonNull Economy economy;
|
||||
|
||||
public EconomyContext(final @NonNull CarbonChatBukkit carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
final RegisteredServiceProvider<Economy> provider =
|
||||
this.carbonChat.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
|
||||
if (provider == null) {
|
||||
throw new IllegalArgumentException("Economy provider not found!");
|
||||
}
|
||||
|
||||
this.economy = provider.getProvider();
|
||||
|
||||
CarbonEvents.register(PreChatFormatEvent.class, event -> {
|
||||
if (!(event.channel() instanceof TextChannel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final TextChannel channel = (TextChannel) event.channel();
|
||||
final Context context = channel.context("vault-balance");
|
||||
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Double requiredBal;
|
||||
|
||||
if (context.isNumber()) {
|
||||
requiredBal = context.asNumber().doubleValue();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (requiredBal.equals(0.0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final OfflinePlayer player = Bukkit.getOfflinePlayer(event.user().uuid());
|
||||
|
||||
if (!this.economy.has(player, requiredBal)) {
|
||||
event.cancelled(true);
|
||||
|
||||
event.user().sendMessage(Identity.nil(), this.carbonChat.messageProcessor()
|
||||
.processMessage(this.carbonChat.translations().contextMessages().vaultBalanceNotEnough()));
|
||||
}
|
||||
});
|
||||
|
||||
CarbonEvents.register(PreChatFormatEvent.class, event -> {
|
||||
if (!(event.channel() instanceof TextChannel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final TextChannel channel = (TextChannel) event.channel();
|
||||
final Context context = channel.context("vault-cost");
|
||||
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Double cost;
|
||||
|
||||
if (context.isNumber()) {
|
||||
cost = context.asNumber().doubleValue();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cost.equals(0.0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final OfflinePlayer player = Bukkit.getOfflinePlayer(event.user().uuid());
|
||||
|
||||
if (!this.economy.has(player, cost)) {
|
||||
event.cancelled(true);
|
||||
|
||||
event.user().sendMessage(Identity.nil(), this.carbonChat.messageProcessor()
|
||||
.processMessage(this.carbonChat.translations().contextMessages().vaultCostNotEnough()));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.economy.withdrawPlayer(player, cost);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
-77
@@ -1,77 +0,0 @@
|
||||
package net.draycia.carbon.bukkit.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 final static @NonNull String KEY = "placeholder";
|
||||
private final static @NonNull String SENDER = "-sender";
|
||||
private final static @NonNull 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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]));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
-132
@@ -1,132 +0,0 @@
|
||||
package net.draycia.carbon.bukkit.listeners.contexts;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.event.TownRemoveResidentEvent;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.channels.TextChannel;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.ChannelSwitchEvent;
|
||||
import net.draycia.carbon.api.events.MessageContextEvent;
|
||||
import net.draycia.carbon.api.events.ReceiverContextEvent;
|
||||
import net.draycia.carbon.api.Context;
|
||||
import net.draycia.carbon.api.users.PlayerUser;
|
||||
import net.kyori.event.PostOrders;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class TownyContext implements Listener {
|
||||
|
||||
private final static @NonNull String KEY = "towny-town";
|
||||
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
public TownyContext(final @NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
CarbonEvents.register(ReceiverContextEvent.class, event -> {
|
||||
final Context context = event.channel().context(KEY);
|
||||
|
||||
if (context != null && context.isBoolean() && context.asBoolean()) {
|
||||
event.cancelled(!this.isInSameTown(event.sender(), event.recipient()));
|
||||
}
|
||||
});
|
||||
|
||||
CarbonEvents.register(ChannelSwitchEvent.class, event -> {
|
||||
if (!(event.channel() instanceof TextChannel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final TextChannel channel = (TextChannel) event.channel();
|
||||
final Context context = channel.context(KEY);
|
||||
|
||||
if (context != null && context.isBoolean() && context.asBoolean()) {
|
||||
if (!this.isInTown(event.user())) {
|
||||
event.failureMessage(this.carbonChat.translations().contextMessages().townyTownNotInTown());
|
||||
event.cancelled(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
CarbonEvents.register(MessageContextEvent.class, PostOrders.NORMAL, false, event -> {
|
||||
final Context context = event.channel().context(KEY);
|
||||
|
||||
if (context != null && context.isBoolean() && context.asBoolean()) {
|
||||
if (!this.isInTown(event.user())) {
|
||||
event.user().sendMessage(this.carbonChat.messageProcessor().processMessage(
|
||||
this.carbonChat.translations().contextMessages().townyTownNotInTown()));
|
||||
|
||||
event.cancelled(!this.isInTown(event.user()));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onResidentRemove(final TownRemoveResidentEvent event) {
|
||||
final PlayerUser user = this.carbonChat.userService().wrap(event.getResident().getUUID());
|
||||
final ChatChannel channel = user.selectedChannel();
|
||||
|
||||
if (!(channel instanceof TextChannel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final TextChannel textChannel = (TextChannel) channel;
|
||||
final Context context = textChannel.context(KEY);
|
||||
|
||||
if (context != null && context.isBoolean() && context.asBoolean()) {
|
||||
user.clearSelectedChannel();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||
final PlayerUser user = this.carbonChat.userService().wrap(event.getPlayer().getUniqueId());
|
||||
final ChatChannel channel = user.selectedChannel();
|
||||
|
||||
if (!(channel instanceof TextChannel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final TextChannel textChannel = (TextChannel) channel;
|
||||
final Context context = textChannel.context(KEY);
|
||||
|
||||
if (context != null && context.isBoolean() && context.asBoolean() && !this.isInTown(user)) {
|
||||
user.clearSelectedChannel();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInTown(final @NonNull PlayerUser user) {
|
||||
try {
|
||||
return TownyAPI.getInstance().getDataSource().getResident(user.name()).hasTown();
|
||||
} catch (final NotRegisteredException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isInSameTown(final @NonNull PlayerUser user1, final @NonNull PlayerUser user2) {
|
||||
if (Bukkit.getPlayer(user1.uuid()) == null || Bukkit.getPlayer(user2.uuid()) == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
final Resident resident = TownyAPI.getInstance().getDataSource().getResident(user1.name());
|
||||
|
||||
if (resident.hasTown()) {
|
||||
return resident.getTown().hasResident(user2.name());
|
||||
}
|
||||
} catch (final NotRegisteredException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
-141
@@ -1,141 +0,0 @@
|
||||
package net.draycia.carbon.bukkit.listeners.contexts;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.MessageContextEvent;
|
||||
import net.draycia.carbon.api.events.ReceiverContextEvent;
|
||||
import net.draycia.carbon.api.Context;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class WorldGuardContext {
|
||||
|
||||
private final static @NonNull String KEY = "worldguard-region";
|
||||
|
||||
public WorldGuardContext() {
|
||||
CarbonEvents.register(ReceiverContextEvent.class, event -> {
|
||||
final Player senderPlayer = Bukkit.getPlayer(event.sender().uuid());
|
||||
final Player recipientPlayer = Bukkit.getPlayer(event.recipient().uuid());
|
||||
|
||||
if (senderPlayer == null || recipientPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Context context = event.context(KEY);
|
||||
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.cancelled(this.testContext(senderPlayer, recipientPlayer, context));
|
||||
});
|
||||
|
||||
CarbonEvents.register(MessageContextEvent.class, event -> {
|
||||
final Context value = event.channel().context(KEY);
|
||||
final Player player = Bukkit.getPlayer(event.user().uuid());
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (value != null && (value.isString() || value.isList()) && !this.isInRegionOrRegions(value, player)) {
|
||||
event.cancelled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isInRegionOrRegions(final @NonNull Context context, final @NonNull Player player) {
|
||||
if (context.isString()) {
|
||||
return this.isInRegion(context.asString(), player);
|
||||
}
|
||||
|
||||
if (context.isList()) {
|
||||
for (final String region : context.<String>asList()) {
|
||||
if (this.isInRegion(region, player)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean testContext(final @NonNull Player sender, final @NonNull Player target, final @NonNull Context context) {
|
||||
boolean user1InRegion = false;
|
||||
boolean user2InRegion = false;
|
||||
|
||||
if (context.isBoolean() && context.asBoolean()) {
|
||||
return this.isInSameRegion(sender, target);
|
||||
} else if (context.isString()) {
|
||||
user1InRegion = this.isInRegion(context.asString(), sender);
|
||||
user2InRegion = this.isInRegion(context.asString(), target);
|
||||
} else if (context.isList()) {
|
||||
for (final String item : context.<String>asList()) {
|
||||
if (!user1InRegion) {
|
||||
user1InRegion = this.isInRegion(item, sender);
|
||||
}
|
||||
|
||||
if (!user2InRegion) {
|
||||
user2InRegion = this.isInRegion(item, target);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
return user1InRegion && user2InRegion;
|
||||
}
|
||||
|
||||
public boolean isInSameRegion(final @NonNull Player user1, final @NonNull Player user2) {
|
||||
final Location user1Location = BukkitAdapter.adapt(user1.getLocation());
|
||||
final Location user2Location = BukkitAdapter.adapt(user2.getLocation());
|
||||
|
||||
final RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
final RegionQuery regionQuery = container.createQuery();
|
||||
|
||||
final ApplicableRegionSet user1Regions = regionQuery.getApplicableRegions(user1Location);
|
||||
final ApplicableRegionSet user2Regions = regionQuery.getApplicableRegions(user2Location);
|
||||
|
||||
for (final ProtectedRegion region : user1Regions) {
|
||||
if (user2Regions.getRegions().contains(region)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isInRegion(final @NonNull String region, final @NonNull Player player) {
|
||||
final RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
final World world = BukkitAdapter.adapt(player.getWorld());
|
||||
final RegionManager regionManager = container.get(world);
|
||||
|
||||
if (regionManager == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final ProtectedRegion protection = regionManager.getRegion(region);
|
||||
|
||||
if (protection == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.isInRegion(protection, player);
|
||||
}
|
||||
|
||||
public boolean isInRegion(final @NonNull ProtectedRegion region, final @NonNull Player player) {
|
||||
final org.bukkit.Location location = player.getLocation();
|
||||
|
||||
return region.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
}
|
||||
|
||||
}
|
||||
-121
@@ -1,121 +0,0 @@
|
||||
package net.draycia.carbon.bukkit.listeners.contexts;
|
||||
|
||||
import com.gmail.nossr50.api.PartyAPI;
|
||||
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.channels.TextChannel;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.ChannelSwitchEvent;
|
||||
import net.draycia.carbon.api.events.MessageContextEvent;
|
||||
import net.draycia.carbon.api.events.ReceiverContextEvent;
|
||||
import net.draycia.carbon.api.Context;
|
||||
import net.draycia.carbon.api.users.PlayerUser;
|
||||
import net.kyori.event.PostOrders;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class mcMMOContext implements Listener {
|
||||
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
private final static @NonNull String KEY = "mcmmo-party";
|
||||
|
||||
public mcMMOContext(final @NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
CarbonEvents.register(ReceiverContextEvent.class, PostOrders.NORMAL, false, event -> {
|
||||
final Context context = event.channel().context(KEY);
|
||||
|
||||
if (context != null && context.isBoolean() && context.asBoolean()) {
|
||||
event.cancelled(!this.isInSameParty(event.sender(), event.recipient()));
|
||||
}
|
||||
});
|
||||
|
||||
CarbonEvents.register(ChannelSwitchEvent.class, PostOrders.NORMAL, false, event -> {
|
||||
if (!(event.channel() instanceof TextChannel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final TextChannel channel = (TextChannel) event.channel();
|
||||
final Context context = channel.context(KEY);
|
||||
|
||||
if (context != null && context.isBoolean() && context.asBoolean()) {
|
||||
if (!this.isInParty(event.user())) {
|
||||
event.failureMessage(this.carbonChat.translations().contextMessages().mcmmoPartyNotInParty());
|
||||
event.cancelled(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
CarbonEvents.register(MessageContextEvent.class, PostOrders.NORMAL, false, event -> {
|
||||
final Context context = event.channel().context(KEY);
|
||||
|
||||
if (context != null && context.isBoolean() && context.asBoolean()) {
|
||||
event.user().sendMessage(this.carbonChat.messageProcessor().processMessage(
|
||||
this.carbonChat.translations().contextMessages().mcmmoPartyNotInParty()));
|
||||
|
||||
event.cancelled(!this.isInParty(event.user()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static final McMMOPartyChangeEvent.EventReason LEFT = McMMOPartyChangeEvent.EventReason.LEFT_PARTY;
|
||||
private static final McMMOPartyChangeEvent.EventReason KICKED = McMMOPartyChangeEvent.EventReason.KICKED_FROM_PARTY;
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPartyLeave(final McMMOPartyChangeEvent event) {
|
||||
if (event.getReason() != LEFT && event.getReason() != KICKED) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.checkContext(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||
this.checkContext(event.getPlayer());
|
||||
}
|
||||
|
||||
private void checkContext(final Player player) {
|
||||
final PlayerUser user = this.carbonChat.userService().wrap(player.getUniqueId());
|
||||
final ChatChannel channel = user.selectedChannel();
|
||||
|
||||
if (!(channel instanceof TextChannel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final TextChannel textChannel = (TextChannel) channel;
|
||||
final Context context = textChannel.context(KEY);
|
||||
|
||||
if (context != null && context.isBoolean() && context.asBoolean() && !this.isInParty(user)) {
|
||||
user.clearSelectedChannel();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInParty(final @NonNull PlayerUser user) {
|
||||
final Player player = Bukkit.getPlayer(user.uuid());
|
||||
|
||||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return PartyAPI.inParty(player);
|
||||
}
|
||||
|
||||
public boolean isInSameParty(final @NonNull PlayerUser user1, final @NonNull PlayerUser user2) {
|
||||
final Player player1 = Bukkit.getPlayer(user1.uuid());
|
||||
final Player player2 = Bukkit.getPlayer(user2.uuid());
|
||||
|
||||
if (player1 == null || player2 == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return PartyAPI.inSameParty(player1, player2);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,7 +21,6 @@
|
||||
package net.draycia.carbon.bukkit.util;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
@@ -34,32 +33,13 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class CarbonUtils {
|
||||
|
||||
private static final @NonNull String @NonNull [] colors;
|
||||
|
||||
private CarbonUtils() {
|
||||
|
||||
}
|
||||
|
||||
static {
|
||||
final List<String> colorList = new ArrayList<>();
|
||||
|
||||
for (final NamedTextColor color : NamedTextColor.NAMES.values()) {
|
||||
colorList.add(color.toString());
|
||||
}
|
||||
|
||||
colors = colorList.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public static @NonNull Component createComponent(final @NonNull Player player) {
|
||||
if (!FunctionalityConstants.HAS_HOVER_EVENT_METHOD) {
|
||||
return net.kyori.adventure.text.Component.empty();
|
||||
}
|
||||
|
||||
final ItemStack itemStack = player.getInventory().getItemInMainHand();
|
||||
|
||||
if (itemStack.getType().isAir()) {
|
||||
|
||||
+2
-4
@@ -1,15 +1,12 @@
|
||||
package net.draycia.carbon.bukkit.util;
|
||||
|
||||
import org.bukkit.inventory.ItemFactory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
@SuppressWarnings({"ResultOfMethodCallIgnored", "argument.type.incompatible"})
|
||||
@SuppressWarnings("argument.type.incompatible")
|
||||
public final class FunctionalityConstants {
|
||||
|
||||
public static final boolean HAS_HOVER_EVENT_METHOD = noThrow(() -> ItemFactory.class.getMethod("hoverContentOf", ItemStack.class));
|
||||
public static final boolean HAS_PROXY;
|
||||
|
||||
static {
|
||||
@@ -18,6 +15,7 @@ public final class FunctionalityConstants {
|
||||
try {
|
||||
final Class<?> spigotConfig = Class.forName("org.spigotmc.SpigotConfig");
|
||||
final Field bungee = spigotConfig.getField("bungee");
|
||||
|
||||
hasProxy = bungee.getBoolean(null);
|
||||
} catch (final ClassNotFoundException | NoSuchFieldException | IllegalAccessException ignored) {
|
||||
}
|
||||
|
||||
-79
@@ -1,79 +0,0 @@
|
||||
package net.draycia.carbon.common.listeners.contexts;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.channels.TextChannel;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.PreChatFormatEvent;
|
||||
import net.draycia.carbon.api.Context;
|
||||
import net.kyori.event.PostOrders;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class FilterContext {
|
||||
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
@SuppressWarnings("method.invocation.invalid")
|
||||
public FilterContext(final @NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
CarbonEvents.register(PreChatFormatEvent.class, PostOrders.FIRST, false, event -> {
|
||||
if (!carbonChat.moderationSettings().filters().enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.user().hasPermission("carbonchat.filter.exempt")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.channelUsesFilter(event.channel())) {
|
||||
return;
|
||||
}
|
||||
|
||||
String message = event.message();
|
||||
|
||||
for (final Map.Entry<String, List<Pattern>> entry :
|
||||
this.carbonChat.moderationSettings().filters().replacements().entrySet()) {
|
||||
|
||||
for (final Pattern pattern : entry.getValue()) {
|
||||
final Matcher matcher = pattern.matcher(message);
|
||||
|
||||
if (entry.getKey().equals("_")) {
|
||||
message = matcher.replaceAll("");
|
||||
} else {
|
||||
message = matcher.replaceAll(entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
event.message(message);
|
||||
|
||||
for (final Pattern blockedWord : this.carbonChat.moderationSettings().filters().blockedPatterns()) {
|
||||
if (blockedWord.matcher(event.message()).find()) {
|
||||
event.cancelled(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean channelUsesFilter(final @NonNull ChatChannel chatChannel) {
|
||||
if (chatChannel instanceof TextChannel) {
|
||||
final Context context = ((TextChannel) chatChannel).context("filter");
|
||||
|
||||
if (context == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return context.isBoolean() && context.asBoolean();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user