Added ignore ? (ignore list) and sync ignores
This commit is contained in:
parent
dfcf8de34e
commit
e51c893649
|
|
@ -438,26 +438,39 @@ public class Queries {
|
||||||
public static String getDisplayName(UUID uuid) {
|
public static String getDisplayName(UUID uuid) {
|
||||||
String nickname = getNickname(uuid);
|
String nickname = getNickname(uuid);
|
||||||
if (nickname != null) return nickname;
|
if (nickname != null) return nickname;
|
||||||
|
HashSet<String> userNames = getUserNames(List.of(uuid));
|
||||||
|
return userNames.isEmpty() ? null : userNames.iterator().next();
|
||||||
|
}
|
||||||
|
|
||||||
// View has been created.
|
public static HashSet<String> getUserNames(List<UUID> uuid) {
|
||||||
String query = "SELECT Username FROM utility_users WHERE uuid = ?";
|
StringBuilder query = new StringBuilder("SELECT Username FROM utility_users WHERE uuid IN (");
|
||||||
|
if (uuid.isEmpty()) return new HashSet<>();
|
||||||
|
|
||||||
|
query.append("?, ".repeat(uuid.size()));
|
||||||
|
query.delete(query.length() - 2, query.length());
|
||||||
|
query.append(")");
|
||||||
|
|
||||||
|
HashSet<String> userNames = new HashSet<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Connection connection = DatabaseConnection.getConnection();
|
Connection connection = DatabaseConnection.getConnection();
|
||||||
|
|
||||||
PreparedStatement statement = connection.prepareStatement(query);
|
PreparedStatement statement = connection.prepareStatement(query.toString());
|
||||||
|
|
||||||
statement.setString(1, uuid.toString());
|
for (int i = 0; i < uuid.size(); i++) {
|
||||||
|
statement.setString(i + 1, uuid.get(i).toString());
|
||||||
|
}
|
||||||
|
|
||||||
ResultSet resultSet = statement.executeQuery();
|
ResultSet resultSet = statement.executeQuery();
|
||||||
|
|
||||||
if (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
return resultSet.getString("Username");
|
userNames.add(resultSet.getString("Username"));
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
return userNames;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,15 @@ public final class ChatUserManager {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ChatUser user = Queries.loadChatUser(uuid);
|
ChatUser chatUser = Queries.loadChatUser(uuid);
|
||||||
if(user == null) user = new ChatUser(uuid, -1, false, false);
|
if (chatUser != null) {
|
||||||
Queries.saveUser(user);
|
ChatUserManager.addUser(chatUser);
|
||||||
chatUsers.add(user);
|
}
|
||||||
return user;
|
return chatUser;
|
||||||
|
// if(user == null) user = new ChatUser(uuid, -1, false, false);
|
||||||
|
// Queries.saveUser(user);
|
||||||
|
// chatUsers.add(user);
|
||||||
|
// return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Mail> getUnReadMail(ChatUser user) {
|
public List<Mail> getUnReadMail(ChatUser user) {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
package com.alttd.chat.commands;
|
package com.alttd.chat.commands;
|
||||||
|
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.chat.ChatPlugin;
|
||||||
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.database.Queries;
|
import com.alttd.chat.database.Queries;
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.ChatUser;
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
|
@ -11,41 +15,83 @@ import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class Ignore implements CommandExecutor {
|
public class Ignore implements CommandExecutor {
|
||||||
|
|
||||||
|
private final ChatPlugin plugin;
|
||||||
|
|
||||||
|
public Ignore() {
|
||||||
|
plugin = ChatPlugin.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if(!(sender instanceof Player)) { // must be a player
|
if(!(sender instanceof Player player)) { // must be a player
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(args.length > 1) return false; // todo error message or command info
|
if(args.length > 1) return false; // todo error message or command info
|
||||||
String targetName = args[0];
|
String targetName = args[0];
|
||||||
|
if (targetName.equals("?")) {
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
|
HashSet<String> userNames = Queries.getUserNames(chatUser.getIgnoredPlayers());
|
||||||
|
StringBuilder ignoredMessage = new StringBuilder();
|
||||||
|
|
||||||
|
if (userNames.isEmpty()) {
|
||||||
|
player.sendMessage(MiniMessage.get().parse("You don't have anyone ignored!")); //TODO load from config
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ignoredMessage.append("You have the following users ignored:\n");
|
||||||
|
userNames.forEach(username -> ignoredMessage.append(username).append("\n"));
|
||||||
|
ignoredMessage.delete(ignoredMessage.length() - 1, ignoredMessage.length());
|
||||||
|
|
||||||
|
player.sendMessage(MiniMessage.get().parse(ignoredMessage.toString()));
|
||||||
|
}
|
||||||
|
}.runTaskAsynchronously(plugin);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Player targetPlayer = Bukkit.getPlayer(targetName);
|
Player targetPlayer = Bukkit.getPlayer(targetName);
|
||||||
if(targetPlayer == null) { // can't ignore offline players
|
if(targetPlayer == null) { // can't ignore offline players
|
||||||
|
sender.sendMessage("You can't ignore offline players");
|
||||||
//sender.sendMessage("Target not found..."); // TODO load from config and minimessage
|
//sender.sendMessage("Target not found..."); // TODO load from config and minimessage
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(targetPlayer.hasPermission("chat.ignorebypass")) {
|
|
||||||
|
UUID target = targetPlayer.getUniqueId();
|
||||||
|
if(targetPlayer.hasPermission("chat.ignorebypass") || target.equals(player.getUniqueId())) {
|
||||||
sender.sendMessage("You can't ignore this player"); // TODO load from config and minimessage
|
sender.sendMessage("You can't ignore this player"); // TODO load from config and minimessage
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
UUID target = targetPlayer.getUniqueId();
|
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ChatUser chatUser = ChatUserManager.getChatUser(((Player) sender).getUniqueId());
|
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
if(!chatUser.getIgnoredPlayers().contains(target)) {
|
if(!chatUser.getIgnoredPlayers().contains(target)) {
|
||||||
chatUser.addIgnoredPlayers(target);
|
chatUser.addIgnoredPlayers(target);
|
||||||
Queries.ignoreUser(((Player) sender).getUniqueId(), target);
|
Queries.ignoreUser(((Player) sender).getUniqueId(), target);
|
||||||
sender.sendMessage("You have ignored " + targetName + "."); // TODO load from config and minimessage
|
sender.sendMessage("You have ignored " + targetName + "."); // TODO load from config and minimessage
|
||||||
|
sendPluginMessage("ignore", player, target);
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("You have ignored " + targetName + "."); // TODO load from config and minimessage
|
sender.sendMessage("You already have " + targetName + " ignored, to unignore use /unignore " + targetName + "."); // TODO load from config and minimessage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
}.runTaskAsynchronously(plugin);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendPluginMessage(String channel, Player player, UUID target) {
|
||||||
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
out.writeUTF(channel);
|
||||||
|
out.writeUTF(player.getUniqueId().toString());
|
||||||
|
out.writeUTF(target.toString());
|
||||||
|
player.sendPluginMessage(plugin, Config.MESSAGECHANNEL, out.toByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,21 @@
|
||||||
package com.alttd.chat.commands;
|
package com.alttd.chat.commands;
|
||||||
|
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.chat.ChatPlugin;
|
||||||
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.database.Queries;
|
import com.alttd.chat.database.Queries;
|
||||||
|
import com.alttd.chat.listeners.PluginMessage;
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.ChatUser;
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.PluginCommand;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
|
@ -15,9 +23,15 @@ import java.util.UUID;
|
||||||
|
|
||||||
public class Unignore implements CommandExecutor {
|
public class Unignore implements CommandExecutor {
|
||||||
|
|
||||||
|
private final ChatPlugin plugin;
|
||||||
|
|
||||||
|
public Unignore() {
|
||||||
|
plugin = ChatPlugin.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if(!(sender instanceof Player)) { // must be a player
|
if(!(sender instanceof Player player)) { // must be a player
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(args.length > 1) return false; // todo error message or command info
|
if(args.length > 1) return false; // todo error message or command info
|
||||||
|
|
@ -30,11 +44,12 @@ public class Unignore implements CommandExecutor {
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ChatUser chatUser = ChatUserManager.getChatUser(((Player) sender).getUniqueId());
|
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
if(chatUser.getIgnoredPlayers().contains(target)) {
|
if(chatUser.getIgnoredPlayers().contains(target)) {
|
||||||
chatUser.removeIgnoredPlayers(target);
|
chatUser.removeIgnoredPlayers(target);
|
||||||
Queries.unIgnoreUser(((Player) sender).getUniqueId(), target);
|
Queries.unIgnoreUser(player.getUniqueId(), target);
|
||||||
sender.sendMessage("You no longer ignore " + targetName + "."); // TODO load from config and minimessage
|
sender.sendMessage("You no longer ignore " + targetName + "."); // TODO load from config and minimessage
|
||||||
|
sendPluginMessage("unignore", player, target);
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("You don't have " + targetName + " ignored."); // TODO load from config and minimessage
|
sender.sendMessage("You don't have " + targetName + " ignored."); // TODO load from config and minimessage
|
||||||
}
|
}
|
||||||
|
|
@ -43,4 +58,11 @@ public class Unignore implements CommandExecutor {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendPluginMessage(String channel, Player player, UUID target) {
|
||||||
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
out.writeUTF(channel);
|
||||||
|
out.writeUTF(player.getUniqueId().toString());
|
||||||
|
out.writeUTF(target.toString());
|
||||||
|
player.sendPluginMessage(plugin, Config.MESSAGECHANNEL, out.toByteArray());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user