3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-12-23 23:00:35 +01:00

Allow using a '\n' in config. Create a method to generate a random string.

Dieser Commit ist enthalten in:
Leymooo 2018-08-31 20:36:10 +03:00
Ursprung b201d82a31
Commit 57ccb6eec2
2 geänderte Dateien mit 12 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -163,7 +163,7 @@ public class AnnotatedConfig {
if (stringValue.isEmpty()) {
return "\"\"";
}
return "\"" + stringValue + "\"";
return "\"" + stringValue.replace("\n", "\\n") + "\"";
}
return value != null ? value.toString() : "null";
}

Datei anzeigen

@ -5,7 +5,6 @@ import com.moandjiezana.toml.Toml;
import com.velocitypowered.api.util.Favicon;
import com.velocitypowered.proxy.util.AddressUtil;
import com.velocitypowered.api.util.LegacyChatColorUtils;
import com.velocitypowered.proxy.VelocityServer;
import io.netty.buffer.ByteBufUtil;
import net.kyori.text.Component;
import net.kyori.text.serializer.ComponentSerializers;
@ -61,8 +60,7 @@ public class VelocityConfiguration extends AnnotatedConfig {
@StringAsBytes
@Comment("If you are using modern IP forwarding, configure an unique secret here.")
@ConfigKey("forwarding-secret")
private byte[] forwardingSecret = new Random().ints(48, 123).filter(i -> (i < 58) || (i > 64 && i < 91) || (i > 96)).limit(12)
.collect(StringBuilder::new, (sb, i) -> sb.append((char) i), StringBuilder::append).toString().getBytes(StandardCharsets.UTF_8); //One line string generation
private byte[] forwardingSecret = generateRandomString(12).getBytes(StandardCharsets.UTF_8);
@Table("[servers]")
private final Servers servers;
@ -357,6 +355,16 @@ public class VelocityConfiguration extends AnnotatedConfig {
}
}
private static String generateRandomString(int lenght) {
String chars = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890";
StringBuilder builder = new StringBuilder();
Random rnd = new Random();
for (int i = 0; i < lenght; i++) {
builder.append(chars.charAt(rnd.nextInt(chars.length())));
}
return builder.toString();
}
private static class Servers {
@IsMap