Removed Bukkit stuff I missed from the general use API
This commit is contained in:
@@ -434,4 +434,30 @@ public class Queries {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getDisplayName(UUID uuid) {
|
||||
String nickname = getNickname(uuid);
|
||||
if (nickname != null) return nickname;
|
||||
|
||||
// View has been created.
|
||||
String query = "SELECT Username FROM utility_users WHERE uuid = ?";
|
||||
|
||||
try {
|
||||
Connection connection = DatabaseConnection.getConnection();
|
||||
|
||||
PreparedStatement statement = connection.prepareStatement(query);
|
||||
|
||||
statement.setString(1, uuid.toString());
|
||||
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
|
||||
if (resultSet.next()) {
|
||||
return resultSet.getString("Username");
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
package com.alttd.chat.managers;
|
||||
|
||||
import com.alttd.chat.ChatAPI;
|
||||
import com.alttd.chat.config.RegexConfig;
|
||||
import com.alttd.chat.objects.ChatFilter;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.cacheddata.CachedPermissionData;
|
||||
import net.luckperms.api.model.user.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -26,7 +29,13 @@ public class RegexManager {
|
||||
chatFilters.add(filter);
|
||||
}
|
||||
|
||||
public static String replaceText(Player player, String text) { // TODO loop all objects in the list and check if they violate based on the MATCHER
|
||||
public static String replaceText(String playerName, UUID uuid, String text) { // TODO loop all objects in the list and check if they violate based on the MATCHER
|
||||
User user = ChatAPI.get().getLuckPerms().getUserManager().getUser(uuid);
|
||||
if (user == null) {
|
||||
ALogger.warn("Tried to check chat filters for a user who doesn't exist in LuckPerms");
|
||||
return null;
|
||||
}
|
||||
CachedPermissionData permissionData = user.getCachedData().getPermissionData();
|
||||
for(ChatFilter chatFilter : chatFilters) {
|
||||
switch (chatFilter.getType()) {
|
||||
case CHAT:
|
||||
@@ -35,8 +44,8 @@ public class RegexManager {
|
||||
text = chatFilter.replaceText(text);
|
||||
break;
|
||||
case BLOCK:
|
||||
if(chatFilter.matches(text) && !player.hasPermission("chat.bypass-filter." + chatFilter.getName())) { // todo find a better way to do this?
|
||||
ALogger.info(player.getName() + " triggered the chat filter for " + chatFilter.getName() + ".");
|
||||
if(chatFilter.matches(text) && !permissionData.checkPermission("chat.bypass-filter." + chatFilter.getName()).asBoolean()) { // todo find a better way to do this?
|
||||
ALogger.info(playerName + " triggered the chat filter for " + chatFilter.getName() + ".");
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -3,8 +3,6 @@ package com.alttd.chat.objects;
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -32,14 +30,9 @@ public class ChatUser {
|
||||
this.partyId = partyId;
|
||||
this.toggledPartyChat = toggledChat;
|
||||
|
||||
name = Queries.getNickname(uuid);
|
||||
name = Queries.getDisplayName(uuid);
|
||||
if (name == null) {
|
||||
OfflinePlayer player = Bukkit.getPlayer(uuid);
|
||||
String playerName = "";
|
||||
if (player != null && player.hasPlayedBefore()) {
|
||||
playerName = player.getName();
|
||||
}
|
||||
name = Utility.getDisplayName(uuid, playerName);
|
||||
name = Utility.getDisplayName(uuid, "");
|
||||
}
|
||||
setDisplayName(name);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user