forked from RepoMirrors/kami-blue
add custom delimiter to chatencryption for #723
This commit is contained in:
parent
42429b207c
commit
1f510a8cea
|
@ -18,6 +18,7 @@ import me.zeroeightsix.kami.gui.rgui.util.ContainerHelper;
|
|||
import me.zeroeightsix.kami.gui.rgui.util.Docking;
|
||||
import me.zeroeightsix.kami.module.Module;
|
||||
import me.zeroeightsix.kami.module.ModuleManager;
|
||||
import me.zeroeightsix.kami.module.modules.chat.ChatEncryption;
|
||||
import me.zeroeightsix.kami.module.modules.hidden.RunConfig;
|
||||
import me.zeroeightsix.kami.setting.Setting;
|
||||
import me.zeroeightsix.kami.setting.Settings;
|
||||
|
@ -142,6 +143,7 @@ public class KamiMod {
|
|||
|
||||
Friends.initFriends();
|
||||
SettingsRegister.register("commandPrefix", Command.commandPrefix);
|
||||
SettingsRegister.register("delimiterV", ChatEncryption.delimiterValue);
|
||||
loadConfiguration();
|
||||
log.info("Settings loaded");
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package me.zeroeightsix.kami.command.commands;
|
||||
|
||||
import me.zeroeightsix.kami.command.Command;
|
||||
import me.zeroeightsix.kami.command.syntax.ChunkBuilder;
|
||||
import me.zeroeightsix.kami.module.modules.chat.ChatEncryption;
|
||||
|
||||
import static me.zeroeightsix.kami.KamiMod.MODULE_MANAGER;
|
||||
import static me.zeroeightsix.kami.util.MessageSendHelper.*;
|
||||
|
||||
public class ChatEncryptionCommand extends Command {
|
||||
public ChatEncryptionCommand() {
|
||||
super("chatencryption", new ChunkBuilder().append("delimiter").build(), "delimiter");
|
||||
setDescription("Allows you to customize ChatEncryption's delimiter");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(String[] args) {
|
||||
ChatEncryption ce = MODULE_MANAGER.getModuleT(ChatEncryption.class);
|
||||
if (ce == null) {
|
||||
sendErrorMessage("&cThe ChatEncryption module is not available for some reason. Make sure the name you're calling is correct and that you have the module installed!!");
|
||||
return;
|
||||
}
|
||||
if (!ce.isEnabled()) {
|
||||
sendWarningMessage("&6Warning: The ChatEncryption module is not enabled!");
|
||||
sendWarningMessage("The command will still work, but will not visibly do anything.");
|
||||
}
|
||||
for (String s : args) {
|
||||
if (s == null)
|
||||
continue;
|
||||
if (s.length() > 1) {
|
||||
sendErrorMessage("Delimiter can only be 1 character long");
|
||||
return;
|
||||
}
|
||||
ChatEncryption.delimiterValue.setValue(s);
|
||||
sendChatMessage("Set the delimiter to <" + s + ">");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,14 +18,17 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static me.zeroeightsix.kami.command.Command.getCommandPrefix;
|
||||
import static me.zeroeightsix.kami.util.MessageSendHelper.sendChatMessage;
|
||||
import static me.zeroeightsix.kami.util.MessageSendHelper.sendErrorMessage;
|
||||
|
||||
/**
|
||||
* Created by 086 on 9/04/2018.
|
||||
* Updated by dominikaaaa on 20/04/20
|
||||
*/
|
||||
@Module.Info(
|
||||
name = "ChatEncryption",
|
||||
description = "Encrypts and decrypts chat messages (Delimiter %)",
|
||||
description = "Encrypts and decrypts chat messages",
|
||||
category = Module.Category.CHAT,
|
||||
showOnArray = Module.ShowOnArray.OFF
|
||||
)
|
||||
|
@ -35,6 +38,7 @@ public class ChatEncryption extends Module {
|
|||
private Setting<EncryptionMode> mode = register(Settings.e("Mode", EncryptionMode.SHUFFLE));
|
||||
private Setting<Integer> key = register(Settings.i("Key", 6));
|
||||
private Setting<Boolean> delim = register(Settings.b("Delimiter", true));
|
||||
public static Setting<String> delimiterValue = Settings.s("delimiterV", "unchanged");
|
||||
|
||||
private final Pattern CHAT_PATTERN = Pattern.compile("<.*?> ");
|
||||
|
||||
|
@ -45,7 +49,7 @@ public class ChatEncryption extends Module {
|
|||
if (event.getPacket() instanceof CPacketChatMessage) {
|
||||
String s = ((CPacketChatMessage) event.getPacket()).getMessage();
|
||||
if (delim.getValue()) {
|
||||
if (!s.startsWith("%")) return;
|
||||
if (getDelimiter() == null || !s.startsWith(getDelimiter())) return;
|
||||
s = s.substring(1);
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
@ -85,20 +89,21 @@ public class ChatEncryption extends Module {
|
|||
}
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String substring = s.substring(0, s.length() - 2);
|
||||
switch (mode.getValue()) {
|
||||
case SHUFFLE:
|
||||
if (!s.endsWith("\uD83D\uDE4D")) return;
|
||||
s = s.substring(0, s.length() - 2);
|
||||
s = substring;
|
||||
builder.append(unshuffle(key.getValue(), s));
|
||||
break;
|
||||
case SHIFT:
|
||||
if (!s.endsWith("\uD83D\uDE48")) return;
|
||||
s = s.substring(0, s.length() - 2);
|
||||
s = substring;
|
||||
s.chars().forEachOrdered(value -> builder.append((char) (value + (ChatAllowedCharacters.isAllowedCharacter((char) value) ? -key.getValue() : 0))));
|
||||
break;
|
||||
}
|
||||
|
||||
((SPacketChat) event.getPacket()).chatComponent = new TextComponentString("<" + username + ">: " + KamiMod.colour + "lDECRYPT" + KamiMod.colour + "r: " + builder.toString());
|
||||
((SPacketChat) event.getPacket()).chatComponent = new TextComponentString("<" + username + ">: " + KamiMod.colour + "lDECRYPTED" + KamiMod.colour + "r: " + builder.toString());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -150,4 +155,13 @@ public class ChatEncryption extends Module {
|
|||
private boolean isOwn(String message) {
|
||||
return Pattern.compile("^<" + mc.player.getName() + "> ", Pattern.CASE_INSENSITIVE).matcher(message).find();
|
||||
}
|
||||
|
||||
private String getDelimiter() {
|
||||
if (delimiterValue.getValue().equalsIgnoreCase("unchanged")) {
|
||||
sendErrorMessage(getChatName() + "Please change the delimiter with &7" + getCommandPrefix() + "chatencryption&f, disabling");
|
||||
disable();
|
||||
return null;
|
||||
}
|
||||
return delimiterValue.getValue();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public class CustomChat extends Module {
|
|||
|
||||
private enum DecoMode { SEPARATOR, CLASSIC, NONE }
|
||||
public enum TextMode { NAME, ON_TOP, WEBSITE, JAPANESE, CUSTOM }
|
||||
public static String[] cmdCheck = new String[]{"/", ",", ".", "-", ";", "?", "*", "^", "&", "%", Command.getCommandPrefix()};
|
||||
public static String[] cmdCheck = new String[]{"/", ",", ".", "-", ";", "?", "*", "^", "&", "%", "#", "$", Command.getCommandPrefix(), ChatEncryption.delimiterValue.getValue()};
|
||||
|
||||
private String getText(TextMode t) {
|
||||
switch (t) {
|
||||
|
|
Loading…
Reference in New Issue