mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 22:15:45 +00:00
Merge addons into main plugin
This commit is contained in:
1 parent
02732d5b5d
commit
ad9a794156
28 files changed
+258
-516
No files matched your search
@@ -6,6 +6,8 @@ plugins {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
maven { url = "https://maven.enginehub.org/repo/" }
|
||||
maven { url = "https://jitpack.io" }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -20,6 +22,9 @@ dependencies {
|
||||
compile 'io.github.leonardosnt:bungeechannelapi:1.0.0-SNAPSHOT'
|
||||
compile 'io.lettuce:lettuce-core:6.0.0.M1'
|
||||
|
||||
compileOnly 'com.gmail.nossr50.mcMMO:mcMMO:2.1.143'
|
||||
compileOnly 'com.github.TownyAdvanced:Towny:0.96.2.0'
|
||||
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.4-SNAPSHOT'
|
||||
compileOnly 'me.clip:placeholderapi:2.10.9'
|
||||
compileOnly 'com.github.TownyAdvanced:Towny:0.96.1.11'
|
||||
compileOnly 'com.github.MilkBowl:VaultAPI:1.7'
|
||||
@@ -37,7 +42,7 @@ bukkit {
|
||||
apiVersion = '1.13'
|
||||
author = 'Draycia'
|
||||
depend = ['PlaceholderAPI', 'Vault']
|
||||
softDepend = ['LuckPerms']
|
||||
softDepend = ['LuckPerms', 'Towny', 'mcMMO', 'WorldGuard']
|
||||
loadBefore = ["Essentials"]
|
||||
permissions {
|
||||
'carbonchat.channels.Global.see' {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package net.draycia.carbon;
|
||||
|
||||
import net.draycia.carbon.channels.contexts.impl.DistanceContext;
|
||||
import net.draycia.carbon.channels.contexts.impl.TownyContext;
|
||||
import net.draycia.carbon.channels.contexts.impl.WorldGuardContext;
|
||||
import net.draycia.carbon.channels.contexts.impl.mcMMOContext;
|
||||
import net.draycia.carbon.listeners.*;
|
||||
import net.draycia.carbon.managers.*;
|
||||
import net.draycia.carbon.messaging.MessageManager;
|
||||
@@ -11,9 +14,15 @@ import net.draycia.carbon.util.CarbonPlaceholders;
|
||||
import net.draycia.carbon.util.ItemStackUtils;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class CarbonChat extends JavaPlugin {
|
||||
|
||||
private Permission permission;
|
||||
@@ -28,11 +37,25 @@ public final class CarbonChat extends JavaPlugin {
|
||||
|
||||
private ItemStackUtils itemStackUtils;
|
||||
|
||||
private YamlConfiguration modConfig;
|
||||
|
||||
public static final LegacyComponentSerializer LEGACY =
|
||||
LegacyComponentSerializer.builder().extractUrls().character('§').build();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Ensure config is present to be modified by the user
|
||||
saveDefaultConfig();
|
||||
saveResource("moderation.yml", false);
|
||||
|
||||
modConfig = new YamlConfiguration();
|
||||
|
||||
try {
|
||||
modConfig.load(new File(getDataFolder(), "moderation.yml"));
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Setup Adventure
|
||||
adventureManager = new AdventureManager(this);
|
||||
|
||||
@@ -45,9 +68,6 @@ public final class CarbonChat extends JavaPlugin {
|
||||
// Setup vault and permissions
|
||||
permission = getServer().getServicesManager().getRegistration(Permission.class).getProvider();
|
||||
|
||||
// Ensure config is present to be modified by the user
|
||||
saveDefaultConfig();
|
||||
|
||||
// Initialize managers
|
||||
commandManager = new CommandManager(this);
|
||||
channelManager = new ChannelManager(this);
|
||||
@@ -72,6 +92,18 @@ public final class CarbonChat extends JavaPlugin {
|
||||
registerContexts();
|
||||
|
||||
new CarbonPlaceholders(this).register();
|
||||
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Towny")) {
|
||||
getServer().getPluginManager().registerEvents(new TownyContext(this), this);
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("mcMMO")) {
|
||||
getServer().getPluginManager().registerEvents(new mcMMOContext(this), this);
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("WorldGuard")) {
|
||||
getServer().getPluginManager().registerEvents(new WorldGuardContext(this), this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,12 +127,21 @@ public final class CarbonChat extends JavaPlugin {
|
||||
pluginManager.registerEvents(new UserFormattingListener(), this);
|
||||
pluginManager.registerEvents(new WhisperPingHandler(this), this);
|
||||
pluginManager.registerEvents(new RequiredBalanceHandler(this), this);
|
||||
|
||||
pluginManager.registerEvents(new CapsHandler(this), this);
|
||||
pluginManager.registerEvents(new FilterHandler(this), this);
|
||||
pluginManager.registerEvents(new MuteHandler(), this);
|
||||
pluginManager.registerEvents(new ShadowMuteHandler(this), this);
|
||||
}
|
||||
|
||||
private void registerContexts() {
|
||||
getContextManager().register("distance", new DistanceContext());
|
||||
}
|
||||
|
||||
public YamlConfiguration getModConfig() {
|
||||
return modConfig;
|
||||
}
|
||||
|
||||
public Permission getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package net.draycia.carbon.channels.contexts.impl;
|
||||
|
||||
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.CarbonChat;
|
||||
import net.draycia.carbon.events.ChannelSwitchEvent;
|
||||
import net.draycia.carbon.events.PreChatFormatEvent;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public final class TownyContext implements Listener {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
private static final String KEY = "towny-town";
|
||||
|
||||
public TownyContext(CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
this.carbonChat.getContextManager().register("towny-town", (context) -> {
|
||||
if ((context.getValue() instanceof Boolean) && ((Boolean) context.getValue())) {
|
||||
return isInSameTown(context.getSender(), context.getTarget());
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelSwitch(ChannelSwitchEvent event) {
|
||||
Object town = event.getChannel().getContext(KEY);
|
||||
|
||||
if ((town instanceof Boolean) && ((Boolean) town)) {
|
||||
if (!isInTown(event.getUser())) {
|
||||
event.setCancelled(true);
|
||||
event.setFailureMessage(carbonChat.getConfig().getString("contexts.Towny.cancellation-message"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelMessage(PreChatFormatEvent event) {
|
||||
// TODO: event.setFailureMessage
|
||||
Object town = event.getChannel().getContext(KEY);
|
||||
|
||||
if ((town instanceof Boolean) && ((Boolean) town)) {
|
||||
if (!isInTown(event.getUser())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onResidentRemove(TownRemoveResidentEvent event) {
|
||||
String name = event.getResident().getName();
|
||||
ChatUser user = carbonChat.getUserService().wrap(name);
|
||||
Object town = user.getSelectedChannel().getContext(KEY);
|
||||
|
||||
if ((town instanceof Boolean) && ((Boolean) town)) {
|
||||
user.clearSelectedChannel();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
||||
Object town = user.getSelectedChannel().getContext(KEY);
|
||||
|
||||
if ((town instanceof Boolean) && ((Boolean) town) && !isInTown(user)) {
|
||||
user.clearSelectedChannel();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInTown(ChatUser user) {
|
||||
try {
|
||||
return TownyAPI.getInstance().getDataSource().getResident(user.asPlayer().getName()).hasTown();
|
||||
} catch (NotRegisteredException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isInSameTown(ChatUser user1, ChatUser user2) {
|
||||
if (!user1.isOnline() || !user2.isOnline()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
Resident resident = TownyAPI.getInstance().getDataSource().getResident(user1.asPlayer().getName());
|
||||
|
||||
if (resident.hasTown()) {
|
||||
return resident.getTown().hasResident(user2.asPlayer().getName());
|
||||
}
|
||||
} catch (NotRegisteredException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
package net.draycia.carbon.channels.contexts.impl;
|
||||
|
||||
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.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.events.ChannelSwitchEvent;
|
||||
import net.draycia.carbon.events.PreChatFormatEvent;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class WorldGuardContext implements Listener {
|
||||
|
||||
private static final String KEY = "worldguard-region";
|
||||
|
||||
public WorldGuardContext(CarbonChat carbonChat) {
|
||||
carbonChat.getContextManager().register(KEY, (context) -> {
|
||||
return this.testContext(context.getSender(), context.getTarget(), context.getValue());
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelSwitch(ChannelSwitchEvent event) {
|
||||
// TODO: cancellation message
|
||||
Object value = event.getChannel().getContext(KEY);
|
||||
|
||||
if ((value instanceof String || value instanceof List) && !isInRegionOrRegions(value, event.getUser())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelMessage(PreChatFormatEvent event) {
|
||||
// TODO: cancellation message
|
||||
Object value = event.getChannel().getContext(KEY);
|
||||
|
||||
if ((value instanceof String || value instanceof List) && !isInRegionOrRegions(value, event.getUser())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isInRegionOrRegions(Object value, ChatUser user) {
|
||||
if ((value instanceof String)) {
|
||||
return isInRegion((String) value, user);
|
||||
}
|
||||
|
||||
if (value instanceof List) {
|
||||
for (String region : ((List<String>) value)) {
|
||||
if (isInRegion(region, user)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean testContext(ChatUser sender, ChatUser target, Object value) {
|
||||
boolean user1InRegion = false;
|
||||
boolean user2InRegion = false;
|
||||
|
||||
if ((value instanceof Boolean) && ((Boolean) value)) {
|
||||
return isInSameRegion(sender, target);
|
||||
} else if (value instanceof String) {
|
||||
user1InRegion = isInRegion((String)value, sender);
|
||||
user2InRegion = isInRegion((String)value, target);
|
||||
} else if (value instanceof List) {
|
||||
for (String item : (List<String>)value) {
|
||||
if (!user1InRegion) {
|
||||
user1InRegion = isInRegion(item, sender);
|
||||
}
|
||||
|
||||
if (!user2InRegion) {
|
||||
user2InRegion = isInRegion(item, target);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
return user1InRegion && user2InRegion;
|
||||
}
|
||||
|
||||
public boolean isInSameRegion(ChatUser user1, ChatUser user2) {
|
||||
if (!user1.isOnline() || !user2.isOnline()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Location user1Location = BukkitAdapter.adapt(user1.asPlayer().getLocation());
|
||||
Location user2Location = BukkitAdapter.adapt(user2.asPlayer().getLocation());
|
||||
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionQuery regionQuery = container.createQuery();
|
||||
|
||||
ApplicableRegionSet user1Regions = regionQuery.getApplicableRegions(user1Location);
|
||||
ApplicableRegionSet user2Regions = regionQuery.getApplicableRegions(user2Location);
|
||||
|
||||
for (ProtectedRegion region : user1Regions) {
|
||||
if (user2Regions.getRegions().contains(region)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isInRegion(String region, ChatUser user) {
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
World world = BukkitAdapter.adapt(user.asPlayer().getWorld());
|
||||
ProtectedRegion protection = container.get(world).getRegion(region);
|
||||
|
||||
return isInRegion(protection, user);
|
||||
}
|
||||
|
||||
public boolean isInRegion(ProtectedRegion region, ChatUser user) {
|
||||
Location location = BukkitAdapter.adapt(user.asPlayer().getLocation());
|
||||
|
||||
return region.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package net.draycia.carbon.channels.contexts.impl;
|
||||
|
||||
import com.gmail.nossr50.api.PartyAPI;
|
||||
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.events.ChannelSwitchEvent;
|
||||
import net.draycia.carbon.events.PreChatFormatEvent;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public final class mcMMOContext implements Listener {
|
||||
|
||||
private CarbonChat carbonChat;
|
||||
|
||||
public mcMMOContext(CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
this.carbonChat.getContextManager().register("mcmmo-party", (context) -> {
|
||||
if ((context.getValue() instanceof Boolean) && ((Boolean) context.getValue())) {
|
||||
return isInSameParty(context.getSender(), context.getTarget());
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelSwitch(ChannelSwitchEvent event) {
|
||||
Object party = event.getChannel().getContext("mcmmo-party");
|
||||
|
||||
if ((party instanceof Boolean) && ((Boolean) party)) {
|
||||
if (!isInParty(event.getUser())) {
|
||||
event.setCancelled(true);
|
||||
event.setFailureMessage(carbonChat.getConfig().getString("contexts.mcMMO.cancellation-message"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChannelMessage(PreChatFormatEvent event) {
|
||||
Object party = event.getChannel().getContext("mcmmo-party");
|
||||
|
||||
if ((party instanceof Boolean) && ((Boolean) party)) {
|
||||
if (!isInParty(event.getUser())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final McMMOPartyChangeEvent.EventReason LEFT = McMMOPartyChangeEvent.EventReason.LEFT_PARTY;
|
||||
private final McMMOPartyChangeEvent.EventReason KICKED = McMMOPartyChangeEvent.EventReason.KICKED_FROM_PARTY;
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPartyLeave(McMMOPartyChangeEvent event) {
|
||||
if (event.getReason() != LEFT && event.getReason() != KICKED) {
|
||||
return;
|
||||
}
|
||||
|
||||
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
||||
Object party = user.getSelectedChannel().getContext("mcmmo-party");
|
||||
|
||||
if ((party instanceof Boolean) && ((Boolean) party)) {
|
||||
user.clearSelectedChannel();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
||||
Object party = user.getSelectedChannel().getContext("mcmmo-party");
|
||||
|
||||
if ((party instanceof Boolean) && ((Boolean) party) && !isInParty(user)) {
|
||||
user.clearSelectedChannel();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInParty(ChatUser user) {
|
||||
return PartyAPI.inParty(user.asPlayer());
|
||||
}
|
||||
|
||||
public boolean isInSameParty(ChatUser user1, ChatUser user2) {
|
||||
if (!user1.isOnline() || !user2.isOnline()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return PartyAPI.inSameParty(user1.asPlayer(), user2.asPlayer());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package net.draycia.carbon.commands;
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Default;
|
||||
import co.aikar.commands.annotation.Dependency;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandAlias("clearchat|cc")
|
||||
@CommandPermission("carbonchat.clearchat.clear")
|
||||
public class ClearChatCommand extends BaseCommand {
|
||||
|
||||
@Dependency
|
||||
private CarbonChat carbonChat;
|
||||
|
||||
@Default
|
||||
public void baseCommand(CommandSender issuer) {
|
||||
String format = carbonChat.getModConfig().getString("clear-chat.message", "");
|
||||
Component component = carbonChat.getAdventureManager().processMessage(format, "br", "\n");
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (player.hasPermission("carbonchat.clearchat.exempt")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ChatUser audience = carbonChat.getUserService().wrap(player);
|
||||
|
||||
for (int i = 0; i < carbonChat.getModConfig().getInt("clear-chat.message-count", 100); i++) {
|
||||
audience.sendMessage(component);
|
||||
}
|
||||
|
||||
if (player.hasPermission("carbonchat.clearchat.notify")) {
|
||||
String message = carbonChat.getModConfig().getString("language.clear-notify");
|
||||
audience.sendMessage(carbonChat.getAdventureManager().processMessage(message, "player", issuer.getName()));
|
||||
}
|
||||
|
||||
if (player.hasPermission("carbonchat.clearchat.exempt")) {
|
||||
String message = carbonChat.getModConfig().getString("language.clear-exempt");
|
||||
audience.sendMessage(carbonChat.getAdventureManager().processMessage(message, "player", issuer.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package net.draycia.carbon.commands;
|
||||
|
||||
import co.aikar.commands.annotation.*;
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@CommandAlias("mute")
|
||||
@CommandPermission("carbonchat.mute")
|
||||
public class MuteCommand extends BaseCommand {
|
||||
|
||||
@Dependency
|
||||
private CarbonChat carbonChat;
|
||||
|
||||
@Default
|
||||
@CommandCompletion("@players")
|
||||
@Syntax("<player>")
|
||||
public void baseCommand(CommandSender sender, ChatUser targetUser) {
|
||||
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
||||
|
||||
if (targetUser.isMuted()) {
|
||||
targetUser.setMuted(false);
|
||||
String format = carbonChat.getModConfig().getString("language.no-longer-muted");
|
||||
|
||||
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||
"player", targetUser.asOfflinePlayer().getName());
|
||||
|
||||
audience.sendMessage(message);
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
||||
Permission permission = carbonChat.getPermission();
|
||||
String format;
|
||||
|
||||
if (permission.playerHas(null, targetUser.asOfflinePlayer(), "carbonchat.mute.exempt")) {
|
||||
format = carbonChat.getModConfig().getString("language.mute-exempt");
|
||||
} else {
|
||||
targetUser.setMuted(true);
|
||||
format = carbonChat.getModConfig().getString("language.is-now-muted");
|
||||
}
|
||||
|
||||
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||
"player", targetUser.asOfflinePlayer().getName());
|
||||
|
||||
audience.sendMessage(message);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package net.draycia.carbon.commands;
|
||||
|
||||
import co.aikar.commands.annotation.*;
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@CommandAlias("shadowmute|sm|smute")
|
||||
@CommandPermission("carbonchat.shadowmute")
|
||||
public class ShadowMuteCommand extends BaseCommand {
|
||||
|
||||
@Dependency
|
||||
private CarbonChat carbonChat;
|
||||
|
||||
@Default
|
||||
@CommandCompletion("@players")
|
||||
@Syntax("<player>")
|
||||
public void baseCommand(CommandSender sender, ChatUser targetUser) {
|
||||
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
||||
|
||||
if (targetUser.isShadowMuted()) {
|
||||
targetUser.setShadowMuted(false);
|
||||
String format = carbonChat.getModConfig().getString("language.no-longer-shadow-muted");
|
||||
|
||||
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||
"player", targetUser.asOfflinePlayer().getName());
|
||||
|
||||
audience.sendMessage(message);
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
||||
Permission permission = carbonChat.getPermission();
|
||||
String format;
|
||||
|
||||
if (permission.playerHas(null, targetUser.asOfflinePlayer(), "carbonchat.shadowmute.exempt")) {
|
||||
format = carbonChat.getModConfig().getString("language.shadow-mute-exempt");
|
||||
} else {
|
||||
targetUser.setShadowMuted(true);
|
||||
format = carbonChat.getModConfig().getString("language.is-now-shadow-muted");
|
||||
}
|
||||
|
||||
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||
"player", targetUser.asOfflinePlayer().getName());
|
||||
|
||||
audience.sendMessage(message);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package net.draycia.carbon.listeners;
|
||||
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.events.PreChatFormatEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class CapsHandler implements Listener {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public CapsHandler(CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onMessage(PreChatFormatEvent event) {
|
||||
if (!carbonChat.getModConfig().getBoolean("caps-protection.enabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getMessage().length() >= carbonChat.getModConfig().getInt("caps-protection.minimum-length"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
int amountOfCaps = 0;
|
||||
|
||||
for (char letter : event.getMessage().toCharArray()) {
|
||||
if (Character.isUpperCase(letter)) {
|
||||
amountOfCaps++;
|
||||
}
|
||||
}
|
||||
|
||||
double capsPercentage = (amountOfCaps * 100.0) / event.getMessage().length();
|
||||
|
||||
if (!(capsPercentage >= carbonChat.getModConfig().getDouble("caps-protection.percent-caps"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (carbonChat.getModConfig().getBoolean("block-message")) {
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
event.setMessage(event.getMessage().toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package net.draycia.carbon.listeners;
|
||||
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.channels.ChatChannel;
|
||||
import net.draycia.carbon.events.PreChatFormatEvent;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class FilterHandler implements Listener {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
private final Map<String, List<Pattern>> patternReplacements = new HashMap<>();
|
||||
private final List<Pattern> blockedWords = new ArrayList<>();
|
||||
|
||||
public FilterHandler(CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
FileConfiguration config = carbonChat.getModConfig();
|
||||
|
||||
ConfigurationSection filters = config.getConfigurationSection("filters.filters");
|
||||
|
||||
for (String replacement : filters.getKeys(false)) {
|
||||
List<Pattern> patterns = new ArrayList<>();
|
||||
|
||||
for (String word : filters.getStringList(replacement)) {
|
||||
if (carbonChat.getModConfig().getBoolean("filters.case-sensitive")) {
|
||||
patterns.add(Pattern.compile(word));
|
||||
} else {
|
||||
patterns.add(Pattern.compile(word, Pattern.CASE_INSENSITIVE));
|
||||
}
|
||||
}
|
||||
|
||||
patternReplacements.put(replacement, patterns);
|
||||
}
|
||||
|
||||
for (String replacement : config.getStringList("filters.blocked-words")) {
|
||||
for (String word : filters.getStringList(replacement)) {
|
||||
if (carbonChat.getModConfig().getBoolean("filters.case-sensitive")) {
|
||||
blockedWords.add(Pattern.compile(word));
|
||||
} else {
|
||||
blockedWords.add(Pattern.compile(word, Pattern.CASE_INSENSITIVE));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onFilter(PreChatFormatEvent event) {
|
||||
if (!carbonChat.getModConfig().getBoolean("filters.enabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!channelUsesFilter(event.getChannel())) {
|
||||
return;
|
||||
}
|
||||
|
||||
String message = event.getMessage();
|
||||
//Matcher matcher;
|
||||
|
||||
for (Map.Entry<String, List<Pattern>> entry : patternReplacements.entrySet()) {
|
||||
for (Pattern pattern : entry.getValue()) {
|
||||
Matcher matcher = pattern.matcher(message);
|
||||
|
||||
if (entry.getKey().equals("_")) {
|
||||
message = matcher.replaceAll("");
|
||||
} else {
|
||||
message = matcher.replaceAll(entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
event.setMessage(message);
|
||||
|
||||
for (Pattern blockedWord : blockedWords) {
|
||||
if (blockedWord.matcher(event.getMessage()).find()) {
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean channelUsesFilter(ChatChannel chatChannel) {
|
||||
Object filter = chatChannel.getContext("filter");
|
||||
|
||||
return filter instanceof Boolean && ((Boolean) filter);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package net.draycia.carbon.listeners;
|
||||
|
||||
import net.draycia.carbon.events.PreChatFormatEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class MuteHandler implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onMute(PreChatFormatEvent event) {
|
||||
if (event.getUser().isMuted()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package net.draycia.carbon.listeners;
|
||||
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.events.ChatComponentEvent;
|
||||
import net.draycia.carbon.events.ChatFormatEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class ShadowMuteHandler implements Listener {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ShadowMuteHandler(CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onComponent(ChatComponentEvent event) {
|
||||
if (event.getSender().isShadowMuted()) {
|
||||
if (!event.getSender().equals(event.getTarget())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void on(ChatFormatEvent event) {
|
||||
if (event.getTarget() != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.getSender().isShadowMuted()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String prefix = carbonChat.getModConfig().getString("shadow-mute-prefix", "[SM] ");
|
||||
|
||||
event.setFormat(prefix + event.getFormat());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -91,6 +91,10 @@ public class CommandManager {
|
||||
this.commandManager.registerCommand(new ReplyCommand());
|
||||
this.commandManager.registerCommand(new SetColorCommand());
|
||||
this.commandManager.registerCommand(new SpyChannelCommand());
|
||||
|
||||
this.commandManager.registerCommand(new ClearChatCommand());
|
||||
this.commandManager.registerCommand(new MuteCommand());
|
||||
this.commandManager.registerCommand(new ShadowMuteCommand());
|
||||
}
|
||||
|
||||
public BukkitCommandManager getCommandManager() {
|
||||
|
||||
@@ -127,6 +127,12 @@ language:
|
||||
nickname-set: '<green>Your nickname was set to <nickname><reset><green>!'
|
||||
nickname-reset: '<green>Your nickname was reset!'
|
||||
|
||||
contexts:
|
||||
Towny:
|
||||
cancellation-message: '<red>You do not belong to a town!'
|
||||
mcMMO:
|
||||
cancellation-message: '<red>You do not have a party!'
|
||||
|
||||
# Used for <server> placeholder in channel formats
|
||||
server-name: 'Server'
|
||||
|
||||
|
||||
Reference in new issue
Block a user