mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 06:28:53 +00:00
Add ignore feature
This commit is contained in:
1 parent
68fcaeb56d
commit
85a938005b
5 files changed
+70
-18
No files matched your search
@@ -10,6 +10,7 @@ import net.draycia.simplechat.listeners.PlayerChatListener;
|
|||||||
import net.kyori.text.format.TextColor;
|
import net.kyori.text.format.TextColor;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@@ -24,8 +25,9 @@ public final class SimpleChat extends JavaPlugin {
|
|||||||
|
|
||||||
private ArrayList<ChatChannel> channels = new ArrayList<>();
|
private ArrayList<ChatChannel> channels = new ArrayList<>();
|
||||||
|
|
||||||
private HashMap<UUID, ChatChannel> userChannels = new HashMap<>();
|
private HashMap<UUID, ChatChannel> userChannels = new HashMap<>(); // TODO: persistence
|
||||||
private HashMap<UUID, ArrayList<String>> userToggles = new HashMap<>();
|
private HashMap<UUID, ArrayList<String>> userToggles = new HashMap<>(); // TODO: persistence
|
||||||
|
private HashMap<UUID, ArrayList<UUID>> userIgnores = new HashMap<>(); // TODO: persistence
|
||||||
|
|
||||||
private Permission permission;
|
private Permission permission;
|
||||||
|
|
||||||
@@ -202,6 +204,28 @@ public final class SimpleChat extends JavaPlugin {
|
|||||||
getServer().getPluginManager().registerEvents(new PlayerChatListener(this), this);
|
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) {
|
public boolean playerHasChannelMuted(Player player, ChatChannel chatChannel) {
|
||||||
return getUserChannelMutes(player).contains(chatChannel.getName());
|
return getUserChannelMutes(player).contains(chatChannel.getName());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package net.draycia.simplechat.channels;
|
package net.draycia.simplechat.channels;
|
||||||
|
|
||||||
import com.earth2me.essentials.Essentials;
|
|
||||||
import com.gmail.nossr50.api.PartyAPI;
|
import com.gmail.nossr50.api.PartyAPI;
|
||||||
import com.palmergames.bukkit.towny.TownyAPI;
|
import com.palmergames.bukkit.towny.TownyAPI;
|
||||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
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 net.kyori.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.javacord.api.entity.channel.ServerTextChannel;
|
import org.javacord.api.entity.channel.ServerTextChannel;
|
||||||
import org.javacord.api.entity.message.MessageAuthor;
|
import org.javacord.api.entity.message.MessageAuthor;
|
||||||
import org.javacord.api.entity.permission.Role;
|
import org.javacord.api.entity.permission.Role;
|
||||||
@@ -237,18 +235,6 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
System.out.println(LegacyComponentSerializer.INSTANCE.serialize(formattedMessage));
|
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) {
|
public boolean canUserSeeMessage(Player sender, Player target) {
|
||||||
if (!target.hasPermission("simplechat.see." + getName().toLowerCase())) {
|
if (!target.hasPermission("simplechat.see." + getName().toLowerCase())) {
|
||||||
return false;
|
return false;
|
||||||
@@ -259,7 +245,7 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isIgnorable()) {
|
if (isIgnorable()) {
|
||||||
if (isUserIgnoringUser(sender, target)) {
|
if (simpleChat.playerHasPlayerIgnored(sender, target)) {
|
||||||
return false;
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -15,3 +15,7 @@ channels:
|
|||||||
distance: -1 # Set to -1, comment out, or remove to disable distance checking
|
distance: -1 # Set to -1, comment out, or remove to disable distance checking
|
||||||
|
|
||||||
bot-token: -1
|
bot-token: -1
|
||||||
|
|
||||||
|
language:
|
||||||
|
ignoring-user: '<green>You are now ignoring <gold><player><green>!'
|
||||||
|
not-ignoring-user: '<greey>You are no longer ignoring <gold><player><green>!'
|
||||||
@@ -3,4 +3,4 @@ version: ${project.version}
|
|||||||
main: net.draycia.simplechat.SimpleChat
|
main: net.draycia.simplechat.SimpleChat
|
||||||
api-version: 1.13
|
api-version: 1.13
|
||||||
depend: [PlaceholderAPI, Vault]
|
depend: [PlaceholderAPI, Vault]
|
||||||
softdepend: [Essentials, Towny, mcMMO]
|
softdepend: [Towny, mcMMO]
|
||||||
Reference in new issue
Block a user