aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/hype/bbsentials/chat/Chat.java303
-rw-r--r--src/main/java/de/hype/bbsentials/chat/Message.java111
-rw-r--r--src/main/java/de/hype/bbsentials/client/BBsentialsConfigScreemFactory.java5
-rw-r--r--src/main/java/de/hype/bbsentials/client/Config.java14
-rw-r--r--src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java11
5 files changed, 235 insertions, 209 deletions
diff --git a/src/main/java/de/hype/bbsentials/chat/Chat.java b/src/main/java/de/hype/bbsentials/chat/Chat.java
index 454b637..38447da 100644
--- a/src/main/java/de/hype/bbsentials/chat/Chat.java
+++ b/src/main/java/de/hype/bbsentials/chat/Chat.java
@@ -22,9 +22,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.FutureTask;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -139,274 +136,185 @@ public class Chat {
});
}
- private Text onEvent(Text message) {
- Callable<Text> callable = () -> {
- if (!isSpam(message.toString())) {
- if (getConfig().isDetailedDevModeEnabled()) {
- System.out.println("got a message: " + Text.Serializer.toJson(message));
- }
- return handleInClient(message);
+ private Text onEvent(Text text) {
+ if (!isSpam(text.toString())) {
+ if (getConfig().isDetailedDevModeEnabled()) {
+ System.out.println("got a message: " + Text.Serializer.toJson(text));
}
- return message; // Return the original message if it is spam
- };
-
- FutureTask<Text> future = new FutureTask<>(callable);
- Thread thread = new Thread(future);
- thread.start();
-
- try {
- return future.get(); // Retrieve the result from the background thread
- } catch (InterruptedException | ExecutionException e) {
- // Handle exceptions, if needed
- e.printStackTrace();
+ Message message = new Message(text);
+ executionService.execute(() -> processThreaded(message));
+ return processNotThreaded(message);
}
-
- return message; // Return the original message if an exception occurred
+ return text; // Return the original message if it is spam
}
- //Handle in client
- public Text handleInClient(Text messageOriginal) {
- String message = messageOriginal.getString().trim();
- String messageUnformatted = message.replaceAll("§.","");
- if (getConfig().messageFromAlreadyReported(message) && getPlayerNameFromMessage(message) != " " && getPlayerNameFromMessage(message) != "") {
- System.out.println("Message: " + message);
+ //Handle in the messages which need to be modified here
+ public Text processNotThreaded(Message message) {
+// if (message.isFromParty()) {
+// message.replaceInJson("\"action\":\"run_command\",\"value\":\"/viewprofile", "\"action\":\"run_command\",\"value\":\"/bviewprofile " + messageUnformatted.split(">", 1)[1].trim());
+// }
+ if (message.isFromReportedUser()) {
sendPrivateMessageToSelfBase(Formatting.RED + "B: " + message);
return null;
}
- if (getConfig().isDetailedDevModeEnabled()) {
- System.out.println("Got message to analyse internally: " + message);
- }
- //party accepter
- if (message != null) {
- if (message.contains("party")) {
- if (message.contains("disbanded the party")) {
- lastPartyDisbandedMessage = message;
- partyDisbandedMap.put(getPlayerNameFromMessage(message), Instant.now());
- if (getConfig().isDevModeEnabled()&&config.acceptReparty) {
- sendPrivateMessageToSelfDebug("Watching next 20 Sec for invite: " + getPlayerNameFromMessage(message));
+ return message.text;
+ }
+
+ public void processThreaded(Message message) {
+ if (message.getString() != null) {
+ String messageUnformatted = message.getUnformattedString();
+ String username = message.getPlayerName();
+ if (message.isFromReportedUser()) {
+
+ }
+ else if (!MinecraftClient.getInstance().isWindowFocused()) {
+ if (config.doDesktopNotifications) {
+ if ((messageUnformatted.endsWith("is visiting Your Garden !") || messageUnformatted.endsWith("is visiting Your Island !")) && !MinecraftClient.getInstance().isWindowFocused() && config.doDesktopNotifications) {
+ sendNotification("BBsentials Visit-Watcher", messageUnformatted);
+ }
+ else if (message.isMsg()) {
+ sendNotification("BBsentials Message Notifier", username + " sent you the following message: " + message.getMessageContent());
}
+ else {
+ if (message.getMessageContent().toLowerCase().contains(getConfig().getUsername().toLowerCase()) || message.getMessageContent().toLowerCase().contains(config.getNickname().toLowerCase() + " ")) {
+ sendNotification("BBsentials Notifier", "You got mentioned in chat! " + message.getMessageContent());
+ }
+ }
+ }
+ }
+ else if (message.isServerMessage()) {
+ if (messageUnformatted.contains("disbanded the party")) {
+ lastPartyDisbandedUsername = username;
+ partyDisbandedMap.put(username, Instant.now());
}
else if (message.contains("invited you to join their party")) {
- if (lastPartyDisbandedMessage != null && partyDisbandedMap != null) {
- Instant lastDisbandedInstant = partyDisbandedMap.get(getPlayerNameFromMessage(lastPartyDisbandedMessage));
- if (config.acceptReparty){
- if (lastDisbandedInstant != null && lastDisbandedInstant.isAfter(Instant.now().minusSeconds(20)) && (getPlayerNameFromMessage(message).equals(getPlayerNameFromMessage(lastPartyDisbandedMessage)))) {
- sendCommand("/p accept " + getPlayerNameFromMessage(lastPartyDisbandedMessage));}
+ if (lastPartyDisbandedUsername != null && partyDisbandedMap != null) {
+ Instant lastDisbandedInstant = partyDisbandedMap.get(lastPartyDisbandedUsername);
+ if (config.acceptReparty) {
+ if (lastDisbandedInstant != null && lastDisbandedInstant.isAfter(Instant.now().minusSeconds(20)) && (username.equals(lastPartyDisbandedUsername))) {
+ sendCommand("/p accept " + username);
+ }
}
}
if (!MinecraftClient.getInstance().isWindowFocused()) {
- sendNotification("BBsentials Party Notifier", "You got invited too a party by: " + getPlayerNameFromMessage(message));
+ sendNotification("BBsentials Party Notifier", "You got invited too a party by: " + username);
}
}
- else if (message.equals("Party > " + BBsentials.getConfig().getUsername() + ": rp")) {
- sendCommand("/pl");
- repartyActive = true;
- }
else if (message.startsWith("Party Members (")) {
- Config.partyMembers = new ArrayList<String>();
+ Config.partyMembers = new ArrayList<>();
}
- else if (message.startsWith("Party Moderators:") && repartyActive) {
- message = message.replace("Party Moderators:", "").replace(" ●", "").replaceAll("\\s*\\[[^\\]]+\\]", "").trim();
- if (message.contains(",")) {
- for (int i = 0; i < message.split(",").length; i++) {
- Config.partyMembers.add(message.split(",")[i - 1]);
+ else if (message.startsWith("Party Moderators:")) {
+ String temp = messageUnformatted.replace("Party Moderators:", "").replace(" ●", "").replaceAll("\\s*\\[[^\\]]+\\]", "").trim();
+ if (temp.contains(",")) {
+ for (int i = 0; i < temp.split(",").length; i++) {
+ Config.partyMembers.add(temp.split(",")[i - 1]);
}
}
else {
- Config.partyMembers.add(message);
+ Config.partyMembers.add(temp);
}
}
else if (message.startsWith("Party Members:")) {
- message = message.replace("Party Members:", "").replace(" ●", "").replaceAll("\\s*\\[[^\\]]+\\]", "").trim();
- if (message.contains(",")) {
- for (int i = 0; i < message.split(",").length; i++) {
- System.out.println("Added to plist: " + (message.split(",")[i - 1]));
- Config.partyMembers.add(message.split(",")[i - 1]);
+ String temp = messageUnformatted.replace("Party Members:", "").replace(" ●", "").replaceAll("\\s*\\[[^\\]]+\\]", "").trim();
+ if (temp.contains(",")) {
+ for (int i = 0; i < temp.split(",").length; i++) {
+ System.out.println("Added to plist: " + (temp.split(",")[i - 1]));
+ Config.partyMembers.add(temp.split(",")[i - 1]);
}
}
else {
- Config.partyMembers.add(message);
- }
- if (repartyActive) {
- repartyActive = false;
- sendCommand("/p disband");
- for (int i = 0; i < Integer.max(4, getConfig().getPlayersInParty().length); i++) {
- if (i < getConfig().getPlayersInParty().length) {
- sendCommand("/p invite " + getConfig().getPlayersInParty()[i]);
- }
- }
+ Config.partyMembers.add(temp);
}
}
- else if (message.endsWith("bb:party me") && message.startsWith("From ")) {
- if (BBsentials.getConfig().allowBBinviteMe()) {
- sendCommand("/p " + getPlayerNameFromMessage(message.replace("From ", "")));
+ else if ((message.contains("Party Leader:") && !message.contains(getConfig().getUsername())) || message.equals("You are not currently in a party.") || (message.contains("warped the party into a Skyblock Dungeon") && !message.startsWith(getConfig().getUsername()) || (!message.startsWith("The party was transferred to " + getConfig().getUsername()) && message.startsWith("The party was transferred to"))) || message.equals(getConfig().getUsername() + " is now a Party Moderator") || (message.equals("The party was disbanded because all invites expired and the party was empty.")) || (message.contains("You have joined ") && message.contains("'s party!")) || (message.contains("Party Leader, ") && message.contains(" , summoned you to their server.")) || (message.contains("warped to your dungeon"))) {
+ BBsentials.getConfig().setIsLeader(false);
+ if (getConfig().isDetailedDevModeEnabled()) {
+ sendPrivateMessageToSelfDebug("Leader: " + getConfig().isLeader());
}
}
-
- }
- else if (message.contains("bb:test")) {
- sendPrivateMessageToSelfDebug(test());
- }
- else if ((message.endsWith("is visiting Your Garden !") || message.endsWith("is visiting Your Island !")) && !MinecraftClient.getInstance().isWindowFocused()&& config.doDesktopNotifications) {
- sendNotification("BBsentials Visit-Watcher", message);
- }
- else if (message.equals("Please type /report confirm to log your report for staff review.")) {
- sendCommand("/report confirm");
- }
- else if (message.contains(":") && !MinecraftClient.getInstance().isWindowFocused()&&config.doDesktopNotifications) {
- if (message.startsWith("Party >")) {
- String partyMessage = message.replaceFirst("Party >", "").trim();
- messageOriginal = replaceAllForText(messageOriginal, "\"action\":\"run_command\",\"value\":\"/viewprofile", "\"action\":\"run_command\",\"value\":\"/hci menu pcm " + partyMessage);
- if (partyMessage.split(":", 2)[1].toLowerCase().contains(getConfig().getUsername().toLowerCase()) || (partyMessage.toLowerCase().contains(getConfig().getNickname().toLowerCase() + " ") && getConfig().getNotifForParty().toLowerCase().equals("nick")) || getConfig().getNotifForParty().toLowerCase().equals("all")) {
- sendNotification("BBsentials Party Chat Notification", partyMessage);
+ else if ((messageUnformatted.equals("Party Leader: " + getConfig().getUsername() + " ●")) || (message.contains(getConfig().getUsername() + " warped the party to a SkyBlock dungeon!")) || message.startsWith("The party was transferred to " + getConfig().getUsername()) || message.equals("Raul_J has promoted " + getConfig().getUsername() + " to Party Leader") || (message.contains("warped to your dungeon"))) {
+ BBsentials.getConfig().setIsLeader(true);
+ if (getConfig().isDetailedDevModeEnabled()) {
+ sendPrivateMessageToSelfDebug("Leader: " + getConfig().isLeader());
}
}
- else if (message.startsWith("From ")) {
- String sender = getPlayerNameFromMessage(message.replaceFirst("From", "").trim());
- String content = message.split(":", 2)[1];
- sendNotification("BBsentials Message Notifier", sender + " sent you the following message: " + content);
+ else if (message.getUnformattedString().equals("Please type /report confirm to log your report for staff review.")) {
+ sendCommand("/report confirm");
}
- else if (message.toLowerCase().contains("party")) {
- if ((message.contains("Party Leader:") && !message.contains(getConfig().getUsername())) || message.equals("You are not currently in a party.") || (message.contains("warped the party into a Skyblock Dungeon") && !message.startsWith(getConfig().getUsername()) || (!message.startsWith("The party was transferred to " + getConfig().getUsername()) && message.startsWith("The party was transferred to"))) || message.equals(getConfig().getUsername() + " is now a Party Moderator") || (message.equals("The party was disbanded because all invites expired and the party was empty.")) || (message.contains("You have joined ") && message.contains("'s party!")) || (message.contains("Party Leader, ") && message.contains(" , summoned you to their server.")) || (message.contains("warped to your dungeon"))) {
- BBsentials.getConfig().setIsLeader(false);
- if (getConfig().isDetailedDevModeEnabled()) {
- sendPrivateMessageToSelfDebug("Leader: " + getConfig().isLeader());
- }
- }
- if ((message.equals("Party Leader: " + getConfig().getUsername() + " ●")) || (message.contains(getConfig().getUsername() + " warped the party to a SkyBlock dungeon!")) || message.startsWith("The party was transferred to " + getConfig().getUsername()) || message.equals("Raul_J has promoted " + getConfig().getUsername() + " to Party Leader") || (message.contains("warped to your dungeon"))) {
- BBsentials.getConfig().setIsLeader(true);
- if (getConfig().isDetailedDevModeEnabled()) {
- sendPrivateMessageToSelfDebug("Leader: " + getConfig().isLeader());
- }
- }
- else if (repartyActive && !BBsentials.getConfig().isLeader()) {
- repartyActive = false;
- sendPrivateMessageToSelfInfo("Resetted Reparty is Active since you are not leader ");
+ else if (messageUnformatted.startsWith("BUFF! You splashed yourself with")) {
+ if (splashStatusUpdateListener != null) {
+ splashStatusUpdateListener.setStatus(SplashUpdatePacket.STATUS_SPLASHING);
}
}
- else {
- String[] temp = message.split(":", 2);
- String content = temp[temp.length - 1];
- if (temp.length == 2 && (content.toLowerCase().contains(getConfig().getUsername().toLowerCase()) || content.toLowerCase().contains(config.getNickname().toLowerCase() + " "))) {
- sendNotification("BBsentials Notifier", "You got mentioned in chat! " + content);
- }
+ }
+
+ else if (message.isFromGuild()) {
+
+ }
+ else if (message.isFromParty()) {
+ if (message.getMessageContent().toLowerCase().contains(getConfig().getUsername().toLowerCase()) || (message.getMessageContent().toLowerCase().contains(getConfig().getNickname().toLowerCase() + " ") && getConfig().getNotifForParty().toLowerCase().equals("nick")) || getConfig().getNotifForParty().toLowerCase().equals("all")) {
+ sendNotification("BBsentials Party Chat Notification", username + " : " + message.getMessageContent());
}
}
- else if (message.contains("[OPEN MENU]") || message.contains("[YES]")) {
- setChatPromtId(messageOriginal.toString());
+ else if (message.isMsg()) {
+ if (messageUnformatted.endsWith("bb:party me")) {
+ if (BBsentials.getConfig().allowBBinviteMe()) {
+ sendCommand("/p " + username);
+ }
+ }
}
- else if (messageUnformatted.startsWith("BUFF! You splashed yourself with")){
- if (splashStatusUpdateListener!=null){
- splashStatusUpdateListener.setStatus(SplashUpdatePacket.STATUS_SPLASHING);
+ else {
+ if (message.contains("[OPEN MENU]") || message.contains("[YES]")) {
+ setChatPromtId(message.getText().toString());
}
}
-
}
- return messageOriginal;
}
//{"strikethrough":false,"extra":[{"strikethrough":false,"clickEvent":{"action":"run_command","value":"/viewprofile 4fa1228c-8dd6-47c4-8fe3-b04b580311b8"},"hoverEvent":{"action":"show_text","contents":{"strikethrough":false,"text":"§eClick here to view §bHype_the_Time§e's profile"}},"text":"§9Party §8> §b[MVP§2+§b] Hype_the_Time§f: "},{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"text":"h:test"}],"text":""}// {"strikethrough":false,"extra":[{"strikethrough":false,"clickEvent":{"action":"run_command","value":"/viewprofile f772b2c7-bd2a-46e1-b1a2-41fa561157d6"},"hoverEvent":{"action":"show_text","contents":{"strikethrough":false,"text":"§eClick here to view §bShourtu§e's profile"}},"text":"§9Party §8> §b[MVP§c+§b] Shourtu§f: "},{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"text":"Hype_the_Time TEST"}],"text":""}
//{"strikethrough":false,"extra":[{"strikethrough":false,"clickEvent":{"action":"run_command","value":"/viewprofile 4fa1228c-8dd6-47c4-8fe3-b04b580311b8"},"hoverEvent":{"action":"show_text","contents":{"strikethrough":false,"text":"§eClick here to view §bHype_the_Time§e's profile"}},"text":"§9Party §8> §b[MVP§2+§b] Hype_the_Time§f: "},{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"text":"h:test"}],"text":""}
private final Map<String, Instant> partyDisbandedMap = new HashMap<>();
- private String lastPartyDisbandedMessage = null;
-
- public static String getPlayerNameFromMessage(String message) {
- message = message.replaceAll("\\[.*?\\]", "").trim();
- message = message.replaceAll("-----------------------------------------------------", "").replaceAll(":", "");
- String[] temp = message.split(" ");
- String playerName = "";
-
- for (int i = 0; i < temp.length; i++) {
- if (!temp[i].equals(" ") && !temp[i].equals("")) {
- playerName = temp[i];
- break; // Stop looping after finding the first non-empty value
- }
- }
-
- // Remove the rank from the player name, if it exists
- Pattern rankPattern = Pattern.compile("\\s*\\[[^\\]]+\\]");
- playerName = rankPattern.matcher(playerName).replaceAll(" ");
-
- return playerName;
- }
-
- public String extractPlainText(String input) {
- String returns = "";
- String[] literals = input.split("literal\\{");
- if (!input.startsWith("literal")) {
- literals[0] = "";
- }
- for (int i = 0; i < literals.length; i++) {
- if (dontExclude(literals, i) && !literals[i].equals("")) {
- String literal = literals[i].split("}")[0];
-
- if (!literal.isEmpty()) {
- returns = returns + literal;
- }
- }
- }
- // Remove § formatting
- returns = returns.replaceAll("§.", "");
- // Remove brackets that contain only uppercase letters or pluses
- returns = returns.replaceAll("\\[[A-Z+]+\\]", "");
- returns = returns.replaceAll("\\[[0-9]+\\]", "");
- returns = returns.trim();
- returns = returns.replaceAll("\\s+", " ");
-
- return returns;
- }
+ private String lastPartyDisbandedUsername = null;
- private boolean dontExclude(String[] s, int i) {
- if ((i - 1) < 0) {
- return true;
- }
- else {
- if (s[i - 1].endsWith("value='")) {
- return false;
- }
- else {
- return true;
- }
- }
- }
public boolean isSpam(String message) {
if (message.contains("Mana")) return true;
+ if (message.contains("Status")) return true;
if (message.contains("Achievement Points")) return true;
return false;
}
- private boolean repartyActive = false;
-
public String test() {
//put test code here
sendNotification("test", "This is an example which was run of the h:test test");
return new String();
}
- private static String removeMultipleSpaces(String input) {
- return input.replaceAll("\\s+", " ");
- }
-
public static void sendPrivateMessageToSelfError(String message) {
sendPrivateMessageToSelfBase(Formatting.RED + message);
}
+
public static void sendPrivateMessageToSelfFatal(String message) {
sendPrivateMessageToSelfBase(Formatting.DARK_RED + message);
}
+
public static void sendPrivateMessageToSelfSuccess(String message) {
sendPrivateMessageToSelfBase(Formatting.GREEN + message);
}
+
public static void sendPrivateMessageToSelfInfo(String message) {
sendPrivateMessageToSelfBase(Formatting.YELLOW + message);
}
+
public static void sendPrivateMessageToSelfImportantInfo(String message) {
sendPrivateMessageToSelfBase(Formatting.GOLD + message);
}
+
public static void sendPrivateMessageToSelfDebug(String message) {
sendPrivateMessageToSelfBase(Formatting.AQUA + message);
}
+
private static void sendPrivateMessageToSelfBase(String message) {
MinecraftClient client = MinecraftClient.getInstance();
if (client.player != null) {
@@ -426,7 +334,7 @@ public class Chat {
}
public void sendNotification(String title, String text) {
- Thread soundThread = new Thread(() -> {
+ executionService.execute(() -> {
try {
InputStream inputStream = getClass().getResourceAsStream("/sounds/mixkit-sci-fi-confirmation-914.wav");
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(inputStream);
@@ -440,9 +348,6 @@ public class Chat {
e.printStackTrace();
}
});
-
- soundThread.start();
-
List<String> argsList = new ArrayList<>();
argsList.add("--title");
argsList.add(title);
@@ -476,7 +381,7 @@ public class Chat {
public static void followMenu(String menu, String message) {
// Check the "menu" argument and execute the appropriate logic
String command;
- String username = getPlayerNameFromMessage(message);
+ String username = message.split(" ", 1)[0];
if (message.contains(":")) {
message = message.split(":", 2)[1].trim();
if (menu.equalsIgnoreCase("pcm")) {
@@ -521,7 +426,7 @@ public class Chat {
String promptCommand = "/cb " + finalLastPrompt1;
BBsentials.getConfig().setLastChatPromptAnswer(promptCommand);
if (config.isDevModeEnabled()) {
- Chat.sendPrivateMessageToSelfDebug("set the last prompt action too + \""+promptCommand+"\"");
+ Chat.sendPrivateMessageToSelfDebug("set the last prompt action too + \"" + promptCommand + "\"");
}
try {
Thread.sleep(10 * 1000);
@@ -542,7 +447,7 @@ public class Chat {
String promptCommand = "/chatprompt " + finalLastPrompt + " YES";
getConfig().setLastChatPromptAnswer(promptCommand);
if (config.isDevModeEnabled()) {
- Chat.sendPrivateMessageToSelfDebug("set the last prompt action too + \""+promptCommand+"\"");
+ Chat.sendPrivateMessageToSelfDebug("set the last prompt action too + \"" + promptCommand + "\"");
}
try {
Thread.sleep(10 * 1000);
diff --git a/src/main/java/de/hype/bbsentials/chat/Message.java b/src/main/java/de/hype/bbsentials/chat/Message.java
new file mode 100644
index 0000000..9ff05a1
--- /dev/null
+++ b/src/main/java/de/hype/bbsentials/chat/Message.java
@@ -0,0 +1,111 @@
+package de.hype.bbsentials.chat;
+
+import de.hype.bbsentials.client.BBsentials;
+import net.minecraft.text.Text;
+
+public class Message {
+ public Text text;
+ private String unformattedString = null;
+ private String playerName = null;
+
+ public Message(Text text) {
+ this.text = text;
+ }
+
+ public Text getText() {
+ return text;
+ }
+
+ public String getString() {
+ return text.getString();
+ }
+
+ public String getUnformattedString() {
+ if (unformattedString != null) return unformattedString;
+ unformattedString = text.getString().replaceAll("§.", "").trim();
+ return unformattedString;
+ }
+
+ public String getMessageContent() {
+ if (isServerMessage()) return unformattedString;
+ return getUnformattedString().split(":", 1)[1];
+ }
+
+ Boolean guild = null;
+
+ public boolean isFromGuild() {
+ if (guild != null) return guild;
+ guild = getUnformattedString().startsWith("Guild >");
+ return guild;
+ }
+
+ Boolean party = null;
+
+ public boolean isFromParty() {
+ if (party != null) return party;
+ party = getUnformattedString().startsWith("Party >");
+ return party;
+ }
+
+ Boolean msg = null;
+
+ public boolean isMsg() {
+ if (msg != null) return msg;
+ msg = getUnformattedString().startsWith("From") || getUnformattedString().startsWith("To");
+ return msg;
+ }
+
+ Boolean server = null;
+
+ public boolean isServerMessage() {
+ if (server != null) return server;
+ int space = getUnformattedString().indexOf(" ");
+ int doublepoint = getUnformattedString().indexOf(":");
+ return ((space + 2 < doublepoint)&&doublepoint!=-1&&space!=-1);
+ }
+
+ public String getPlayerName() {
+ if (playerName != null) return playerName;
+ playerName = getUnformattedString();
+ if (!playerName.contains(":")) {
+ playerName = "";
+ return "";
+ }
+ playerName = playerName.split(":", 1)[0];
+ if (isMsg()) {
+ playerName = playerName.replaceFirst("From", "").replace("To", "").trim();
+ }
+ playerName = playerName.replaceFirst("\\[[^\\]]*\\](?:\\s?\\[[^\\]]*\\])*", "").trim();
+ if (playerName.matches("^[a-zA-Z0-9_-]+$")) playerName = "";
+ return playerName;
+ }
+
+ public void replaceInJson(String replace, String replaceWith) {
+ String textString = toJson();
+ if (textString.contains(replace)) {
+ textString = textString.replaceAll("\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}", "");
+ }
+ textString = textString.replace(replace, replaceWith);
+ text = Text.Serializer.fromJson(textString);
+ }
+
+ public static Message fromJson(String json) {
+ return new Message(Text.Serializer.fromJson(json));
+ }
+
+ public String toJson() {
+ return Text.Serializer.toJson(text);
+ }
+
+ public boolean isFromReportedUser() {
+ return BBsentials.config.alreadyReported.contains(getPlayerName()) && !getPlayerName().isEmpty();
+ }
+
+ public boolean contains(String string) {
+ return getUnformattedString().contains(string);
+ }
+
+ public boolean startsWith(String string) {
+ return getUnformattedString().startsWith(string);
+ }
+}
diff --git a/src/main/java/de/hype/bbsentials/client/BBsentialsConfigScreemFactory.java b/src/main/java/de/hype/bbsentials/client/BBsentialsConfigScreemFactory.java
index 17fc3f1..dc521f2 100644
--- a/src/main/java/de/hype/bbsentials/client/BBsentialsConfigScreemFactory.java
+++ b/src/main/java/de/hype/bbsentials/client/BBsentialsConfigScreemFactory.java
@@ -69,6 +69,11 @@ public class BBsentialsConfigScreemFactory {
.setTooltip(Text.of("Override the Bingo Time and connect always to the Server. (Bingo time is 14 days cause Extreme Bingo)"))
.setSaveConsumer(newValue -> config.overrideBingoTime = newValue)
.build());
+ server.addEntry(entryBuilder.startBooleanToggle(Text.of("Allow Server Partying"), config.allowServerPartyInvite)
+ .setDefaultValue(true)
+ .setTooltip(Text.of("Allow the Server to party players for you automatically. (Convenience Feature. Is used for example for services to automatically party the persons which joined it)"))
+ .setSaveConsumer(newValue -> config.allowServerPartyInvite = newValue)
+ .build());
//Visual
ConfigCategory visual = builder.getOrCreateCategory(Text.of("Visual"));
visual.addEntry(entryBuilder.startBooleanToggle(Text.of("Show Bingo Chat"), config.showBingoChat)
diff --git a/src/main/java/de/hype/bbsentials/client/Config.java b/src/main/java/de/hype/bbsentials/client/Config.java
index ab4440b..9c62d2e 100644
--- a/src/main/java/de/hype/bbsentials/client/Config.java
+++ b/src/main/java/de/hype/bbsentials/client/Config.java
@@ -2,7 +2,6 @@ package de.hype.bbsentials.client;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
-import de.hype.bbsentials.chat.Chat;
import de.hype.bbsentials.chat.Sender;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
@@ -14,13 +13,14 @@ import java.util.ArrayList;
public class Config implements Serializable {
//DO NOT Change any of the following unless you know what you are doing!
public int apiVersion = 1;
- boolean devMode = false;
+ public boolean allowServerPartyInvite = true;
+ boolean devMode = false;
boolean detailedDevMode = false;
//You can change again
// set automatically
private transient boolean isLeader;
- private transient String alreadyReported = "";
+ public transient String alreadyReported = "";
public String[] bbsentialsRoles = {""};
public static ArrayList<String> partyMembers = new ArrayList<>();
public transient ToDisplayConfig toDisplayConfig = ToDisplayConfig.loadFromFile();
@@ -143,10 +143,6 @@ public class Config implements Serializable {
return partyMembers.toArray(new String[0]);
}
- public boolean messageFromAlreadyReported(String message) {
- return alreadyReported.contains(Chat.getPlayerNameFromMessage(message));
- }
-
public void addReported(String playerName) {
alreadyReported = alreadyReported + " , " + playerName;
}
@@ -197,4 +193,8 @@ public class Config implements Serializable {
public int getApiVersion() {
return apiVersion;
}
+
+ public String getMCUUID() {
+ return MinecraftClient.getInstance().player.getUuid().toString().replace("-", "");
+ }
}
diff --git a/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java b/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java
index 0d43bd9..49353be 100644
--- a/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java
+++ b/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java
@@ -259,7 +259,7 @@ public class BBsentialConnection {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
- sendPacket(new RequestConnectPacket(MinecraftClient.getInstance().player.getUuid().toString().replace("-", ""), BBsentials.getConfig().getApiKey(), BBsentials.getConfig().getApiVersion(), AuthenticationConstants.DATABASE));
+ sendPacket(new RequestConnectPacket(config.getMCUUID(), BBsentials.getConfig().getApiKey(), BBsentials.getConfig().getApiVersion(), AuthenticationConstants.DATABASE));
}
}
else {
@@ -314,7 +314,7 @@ public class BBsentialConnection {
public void onSplashNotifyPacket(SplashNotifyPacket packet) {
int waitTime;
- if (packet.splasherUsername.equals(config.getUsername())) {
+ if (packet.splasherUsername.equals(config.getUsername())&&config.autoSplashStatusUpdates) {
Chat.sendPrivateMessageToSelfInfo("The Splash Update Statuses will be updatet automatically for you. If you need to do something manually go into Discord Splash Dashboard");
SplashStatusUpdateListener splashStatusUpdateListener = new SplashStatusUpdateListener(this, packet);
BBsentials.splashStatusUpdateListener = splashStatusUpdateListener;
@@ -491,7 +491,12 @@ public class BBsentialConnection {
}
public void onPartyPacket(PartyPacket packet) {
- Chat.sendCommand("/p " + packet.type + String.join(" ", packet.users));
+ if (config.allowServerPartyInvite) {
+ Chat.sendCommand("/p " + packet.type + String.join(" ", packet.users));
+ }
+ else {
+ Chat.sendPrivateMessageToSelfImportantInfo("Blocked a Party Command from the Server: "+packet.type+" : "+String.join(" ", packet.users));
+ }
}
public void onSystemMessagePacket(SystemMessagePacket packet) {