mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Add ignore feature
This commit is contained in:
1 parent
68fcaeb56d
commit
85a938005b
5 files changed
+71
-19
No files matched your search
@@ -10,6 +10,7 @@ import net.draycia.simplechat.listeners.PlayerChatListener;
|
||||
import net.kyori.text.format.TextColor;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@@ -24,8 +25,9 @@ public final class SimpleChat extends JavaPlugin {
|
||||
|
||||
private ArrayList<ChatChannel> channels = new ArrayList<>();
|
||||
|
||||
private HashMap<UUID, ChatChannel> userChannels = new HashMap<>();
|
||||
private HashMap<UUID, ArrayList<String>> userToggles = new HashMap<>();
|
||||
private HashMap<UUID, ChatChannel> userChannels = new HashMap<>(); // TODO: persistence
|
||||
private HashMap<UUID, ArrayList<String>> userToggles = new HashMap<>(); // TODO: persistence
|
||||
private HashMap<UUID, ArrayList<UUID>> userIgnores = new HashMap<>(); // TODO: persistence
|
||||
|
||||
private Permission permission;
|
||||
|
||||
@@ -202,6 +204,28 @@ public final class SimpleChat extends JavaPlugin {
|
||||
getServer().getPluginManager().registerEvents(new PlayerChatListener(this), this);
|
||||
}
|
||||
|
||||
public boolean playerHasPlayerIgnored(Player player, OfflinePlayer target) {
|
||||
ArrayList<UUID> ignores = userIgnores.get(player.getUniqueId());
|
||||
|
||||
if (ignores == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ignores.contains(target.getUniqueId());
|
||||
}
|
||||
|
||||
public boolean togglePlayerIgnoringPlayer(Player player, OfflinePlayer target) {
|
||||
ArrayList<UUID> ignores = userIgnores.computeIfAbsent(player.getUniqueId(), (uuid) -> new ArrayList<>());
|
||||
|
||||
if (ignores.contains(target.getUniqueId())) {
|
||||
ignores.remove(target.getUniqueId());
|
||||
return false;
|
||||
} else {
|
||||
ignores.add(target.getUniqueId());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean playerHasChannelMuted(Player player, ChatChannel chatChannel) {
|
||||
return getUserChannelMutes(player).contains(chatChannel.getName());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.draycia.simplechat.channels;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.gmail.nossr50.api.PartyAPI;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
@@ -17,7 +16,6 @@ import net.kyori.text.format.TextColor;
|
||||
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.javacord.api.entity.channel.ServerTextChannel;
|
||||
import org.javacord.api.entity.message.MessageAuthor;
|
||||
import org.javacord.api.entity.permission.Role;
|
||||
@@ -237,18 +235,6 @@ public class SimpleChatChannel extends ChatChannel {
|
||||
System.out.println(LegacyComponentSerializer.INSTANCE.serialize(formattedMessage));
|
||||
}
|
||||
|
||||
private boolean isUserIgnoringUser(Player user, Player target) {
|
||||
Plugin essentials = Bukkit.getServer().getPluginManager().getPlugin("Essentials");
|
||||
|
||||
if (essentials != null) {
|
||||
Essentials essx = (Essentials)essentials;
|
||||
|
||||
return essx.getUser(user).isIgnoredPlayer(essx.getUser(target));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canUserSeeMessage(Player sender, Player target) {
|
||||
if (!target.hasPermission("simplechat.see." + getName().toLowerCase())) {
|
||||
return false;
|
||||
@@ -259,7 +245,7 @@ public class SimpleChatChannel extends ChatChannel {
|
||||
}
|
||||
|
||||
if (isIgnorable()) {
|
||||
if (isUserIgnoringUser(sender, target)) {
|
||||
if (simpleChat.playerHasPlayerIgnored(sender, target)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.draycia.simplechat.commands;
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Default;
|
||||
import me.minidigger.minimessage.text.MiniMessageParser;
|
||||
import net.draycia.simplechat.SimpleChat;
|
||||
import net.kyori.text.adapter.bukkit.TextAdapter;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandAlias("ignore")
|
||||
@CommandPermission("simplechat.ignore")
|
||||
public class IgnoreCommand extends BaseCommand {
|
||||
|
||||
private SimpleChat simpleChat;
|
||||
|
||||
public IgnoreCommand(SimpleChat simpleChat) {
|
||||
this.simpleChat = simpleChat;
|
||||
}
|
||||
|
||||
@Default
|
||||
@CommandCompletion("@players")
|
||||
public void baseCommand(Player player, OfflinePlayer target) {
|
||||
String message;
|
||||
|
||||
if (simpleChat.togglePlayerIgnoringPlayer(player, target)) {
|
||||
message = simpleChat.getConfig().getString("language.ignoring-user");
|
||||
} else {
|
||||
message = simpleChat.getConfig().getString("language.not-ignoring-user");
|
||||
}
|
||||
|
||||
TextAdapter.sendMessage(player, MiniMessageParser.parseFormat(message));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user