fixes
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
package com.alttd.chat.config;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class ServerConfig {
|
||||
private static final Pattern PATH_PATTERN = Pattern.compile("\\.");
|
||||
|
||||
private final String serverName;
|
||||
private final String configPath;
|
||||
private final String defaultPath;
|
||||
|
||||
public ServerConfig(String serverName) {
|
||||
this.serverName = serverName;
|
||||
this.configPath = "server-settings." + this.serverName + ".";
|
||||
this.defaultPath = "server-settings.default.";
|
||||
init();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
Config.readConfig(ServerConfig.class, this);
|
||||
Config.saveConfig();
|
||||
}
|
||||
|
||||
public static Object[] splitPath(String key) {
|
||||
return PATH_PATTERN.split(key);
|
||||
}
|
||||
|
||||
private static void set(String path, Object def) {
|
||||
if(Config.config.getNode(splitPath(path)).isVirtual()) {
|
||||
Config.config.getNode(splitPath(path)).setValue(def);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setString(String path, String def) {
|
||||
try {
|
||||
if(Config.config.getNode(splitPath(path)).isVirtual())
|
||||
Config.config.getNode(splitPath(path)).setValue(TypeToken.of(String.class), def);
|
||||
} catch(ObjectMappingException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean getBoolean(String path, boolean def) {
|
||||
set(defaultPath +path, def);
|
||||
return Config.config.getNode(splitPath(configPath+path)).getBoolean(
|
||||
Config.config.getNode(splitPath(defaultPath +path)).getBoolean(def));
|
||||
}
|
||||
|
||||
private double getDouble(String path, double def) {
|
||||
set(defaultPath +path, def);
|
||||
return Config.config.getNode(splitPath(configPath+path)).getDouble(
|
||||
Config.config.getNode(splitPath(defaultPath +path)).getDouble(def));
|
||||
}
|
||||
|
||||
private int getInt(String path, int def) {
|
||||
set(defaultPath +path, def);
|
||||
return Config.config.getNode(splitPath(configPath+path)).getInt(
|
||||
Config.config.getNode(splitPath(defaultPath +path)).getInt(def));
|
||||
}
|
||||
|
||||
private String getString(String path, String def) {
|
||||
set(defaultPath +path, def);
|
||||
return Config.config.getNode(splitPath(configPath+path)).getString(
|
||||
Config.config.getNode(splitPath(defaultPath +path)).getString(def));
|
||||
}
|
||||
|
||||
/** DO NOT EDIT ANYTHING ABOVE **/
|
||||
|
||||
public boolean GLOBALCHAT = true;
|
||||
public boolean JOINLEAVEMSSAGES = true;
|
||||
private void ServerSettings() {
|
||||
GLOBALCHAT = getBoolean("global-chat-enabled", GLOBALCHAT);
|
||||
JOINLEAVEMSSAGES = getBoolean("joinleave-messages-enabled", JOINLEAVEMSSAGES);
|
||||
}
|
||||
}
|
||||
@@ -340,7 +340,8 @@ public class Queries {
|
||||
statement.setString(1, user.getUuid().toString());
|
||||
statement.setInt(2, user.getPartyId());
|
||||
statement.setInt(3, user.toggledPartyChat() ? 1 : 0);
|
||||
statement.setInt(5, user.isGcOn() ? 1 : 0);
|
||||
statement.setInt(4, 0);
|
||||
// statement.setInt(5, user.isGcOn() ? 1 : 0);
|
||||
|
||||
statement.execute();
|
||||
} catch (SQLException e) {
|
||||
@@ -423,10 +424,10 @@ public class Queries {
|
||||
statement.setString(1, user.getUuid().toString());
|
||||
statement.setInt(2, user.getPartyId());
|
||||
statement.setInt(3, user.toggledPartyChat() ? 1 : 0);
|
||||
statement.setInt(4, user.isGcOn() ? 1 : 0);
|
||||
statement.setInt(4, 0);
|
||||
statement.setInt(5, user.getPartyId());
|
||||
statement.setInt(6, user.toggledPartyChat() ? 1 : 0);
|
||||
statement.setInt(7, user.isGcOn() ? 1 : 0);
|
||||
statement.setInt(7, 0);
|
||||
|
||||
statement.execute();
|
||||
} catch (SQLException e) {
|
||||
|
||||
@@ -27,7 +27,7 @@ public final class ChatUserManager {
|
||||
|
||||
public static ChatUser getChatUser(UUID uuid) {
|
||||
for(ChatUser user : chatUsers) {
|
||||
if(uuid.compareTo(user.getUuid()) == 0) {
|
||||
if(uuid.equals(user.getUuid())) {
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class ChatUser {
|
||||
// private Component prefix; // doesn't need saving, we get this from luckperms
|
||||
// private Component staffPrefix; // doesn't need saving, we get this from luckperms
|
||||
// private Component prefixAll; // doesn't need saving, we get this from luckperms
|
||||
private boolean toggleGc; // should be saved, this toggles if the player can see and use global chat
|
||||
//private boolean toggleGc; // should be saved, this toggles if the player can see and use global chat
|
||||
private String replyTarget; // reply target for use in /msg i don't mind setting this to null on login, feedback?
|
||||
private long gcCooldown; // the time when they last used gc, is used for the cooldown, i wouldn't save this, but setting this to the login time means they can't use gc for 30 seconds after logging in
|
||||
|
||||
@@ -41,7 +41,7 @@ public class ChatUser {
|
||||
//
|
||||
// prefixAll = Utility.getPrefix(uuid, false);
|
||||
|
||||
this.toggleGc = toggleGc;
|
||||
//this.toggleGc = toggleGc;
|
||||
replyTarget = null;
|
||||
gcCooldown = System.currentTimeMillis(); // players can't use gc for 30 seconds after logging in if we use this?
|
||||
mails = Queries.getMails(uuid);
|
||||
@@ -89,14 +89,6 @@ public class ChatUser {
|
||||
return Utility.getPrefix(uuid, false);
|
||||
}
|
||||
|
||||
public void toggleGc() {
|
||||
toggleGc = !toggleGc;
|
||||
}
|
||||
|
||||
public boolean isGcOn() {
|
||||
return toggleGc;
|
||||
}
|
||||
|
||||
public String getReplyTarget() {
|
||||
return replyTarget;
|
||||
}
|
||||
|
||||
@@ -10,13 +10,10 @@ import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.model.group.Group;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import net.luckperms.api.node.Node;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
public class Utility {
|
||||
|
||||
@@ -58,22 +55,17 @@ public class Utility {
|
||||
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
||||
User user = luckPerms.getUserManager().getUser(uuid);
|
||||
if(user == null) return Component.empty();
|
||||
if(single) {
|
||||
Group group = luckPerms.getGroupManager().getGroup(user.getPrimaryGroup());
|
||||
if(group != null)
|
||||
prefix.append(group.getCachedData().getMetaData().getPrefix());
|
||||
// Collection<Group> inheritedGroups = user.getInheritedGroups(user.getQueryOptions());
|
||||
// inheritedGroups.stream()
|
||||
// .sorted(Comparator.comparingInt(o -> o.getWeight().orElse(0)))
|
||||
// .distinct()
|
||||
// .forEach(group -> {
|
||||
// if (Config.PREFIXGROUPS.contains(group.getName())) {
|
||||
// prefix.append("[").append(group.getCachedData().getMetaData().getPrefix()).append("]");
|
||||
// }
|
||||
// });
|
||||
} else {
|
||||
prefix.append(user.getCachedData().getMetaData().getPrefix());
|
||||
if(!single) {
|
||||
Collection<Group> inheritedGroups = user.getInheritedGroups(user.getQueryOptions());
|
||||
inheritedGroups.stream()
|
||||
.sorted(Comparator.comparingInt(o -> o.getWeight().orElse(0)))
|
||||
.forEach(group -> {
|
||||
if (Config.PREFIXGROUPS.contains(group.getName())) {
|
||||
prefix.append(group.getCachedData().getMetaData().getPrefix());
|
||||
}
|
||||
});
|
||||
}
|
||||
prefix.append(user.getCachedData().getMetaData().getPrefix());
|
||||
|
||||
return applyColor(prefix.toString());
|
||||
}
|
||||
@@ -98,6 +90,21 @@ public class Utility {
|
||||
return user.getUsername();
|
||||
}
|
||||
|
||||
public static void flipPermission(UUID uuid, String permission) {
|
||||
ChatAPI.get().getLuckPerms().getUserManager().modifyUser(uuid, user -> {
|
||||
// Add the permission
|
||||
user.data().add(Node.builder(permission)
|
||||
.value(user.getCachedData().getPermissionData().checkPermission(permission).asBoolean()).build());
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean hasPermission(UUID uuid, String permission) {
|
||||
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
||||
User user = luckPerms.getUserManager().getUser(uuid);
|
||||
if(user == null) return false;
|
||||
return user.getCachedData().getPermissionData().checkPermission(permission).asBoolean();
|
||||
}
|
||||
|
||||
public static Component applyColor(String message) {
|
||||
String hexColor1 = "";
|
||||
String hexColor2 = "";
|
||||
@@ -172,23 +179,4 @@ public class Utility {
|
||||
: miniMessage.parse(stringBuilder.toString());
|
||||
}
|
||||
|
||||
|
||||
public static void sendBlockedNotification(String prefix, Player player, String input, String target) {
|
||||
MiniMessage miniMessage = MiniMessage.get();
|
||||
Bukkit.getOnlinePlayers().forEach(a ->{
|
||||
Component blockedNotification = miniMessage.parse("<red>[" + prefix + "] "
|
||||
+ getDisplayName(player.getUniqueId())
|
||||
+ (target.isEmpty() ? " tried to say: " : " -> " + target + ": ")
|
||||
+ input + "</red>");
|
||||
if (a.hasPermission("chat.alert-blocked")) {
|
||||
a.sendMessage(blockedNotification);//TODO make configurable (along with all the messages)
|
||||
}
|
||||
});
|
||||
player.sendMessage(miniMessage.parse("<red>The language you used in your message is not allowed, " +
|
||||
"this constitutes as your only warning. Any further attempts at bypassing the filter will result in staff intervention.</red>"));
|
||||
}
|
||||
|
||||
public static void sendBlockedNotification(String prefix, Player player, Component input, String target) {
|
||||
sendBlockedNotification(prefix, player, PlainComponentSerializer.plain().serialize(input), target);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user