3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

Add Resource pack prompt message option (1.17+) (#2544)

Dieser Commit ist enthalten in:
LemonCaramel 2021-06-21 21:55:49 +09:00 committet von GitHub
Ursprung 44d836e2e7
Commit 14cd568e46
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
5 geänderte Dateien mit 31 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -22,6 +22,7 @@
*/
package com.viaversion.viaversion.api.configuration;
import com.google.gson.JsonElement;
import it.unimi.dsi.fastutil.ints.IntSet;
public interface ViaVersionConfig {
@ -414,4 +415,11 @@ public interface ViaVersionConfig {
* @return true if enabled
*/
boolean isForcedUse1_17ResourcePack();
/**
* Get the message that is sent when a user displays a resource pack prompt.
*
* @return cached serialized component
*/
JsonElement get1_17ResourcePackPrompt();
}

Datei anzeigen

@ -17,6 +17,7 @@
*/
package com.viaversion.viaversion.configuration;
import com.google.gson.JsonElement;
import com.viaversion.viaversion.api.configuration.ViaVersionConfig;
import com.viaversion.viaversion.util.Config;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
@ -75,6 +76,7 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
private boolean instantRespawn;
private boolean ignoreLongChannelNames;
private boolean forcedUse1_17ResourcePack;
private JsonElement resourcePack1_17PromptMessage;
protected AbstractViaConfig(File configFile) {
super(configFile);
@ -136,6 +138,7 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
instantRespawn = getBoolean("use-1_15-instant-respawn", false);
ignoreLongChannelNames = getBoolean("ignore-long-1_16-channel-names", true);
forcedUse1_17ResourcePack = getBoolean("forced-use-1_17-resource-pack", false);
resourcePack1_17PromptMessage = getSerializedComponent("resource-pack-1_17-prompt");
}
@Override
@ -414,4 +417,9 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
public boolean isForcedUse1_17ResourcePack() {
return forcedUse1_17ResourcePack;
}
@Override
public JsonElement get1_17ResourcePackPrompt() {
return resourcePack1_17PromptMessage;
}
}

Datei anzeigen

@ -102,7 +102,7 @@ public final class Protocol1_17To1_16_4 extends AbstractProtocol<ClientboundPack
wrapper.passthrough(Type.STRING);
wrapper.passthrough(Type.STRING);
wrapper.write(Type.BOOLEAN, Via.getConfig().isForcedUse1_17ResourcePack()); // Required
wrapper.write(Type.OPTIONAL_COMPONENT, null); // Prompt message
wrapper.write(Type.OPTIONAL_COMPONENT, Via.getConfig().get1_17ResourcePackPrompt()); // Prompt message
});
}
});

Datei anzeigen

@ -17,7 +17,10 @@
*/
package com.viaversion.viaversion.util;
import com.google.gson.JsonElement;
import com.viaversion.viaversion.api.configuration.ConfigurationProvider;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
@ -207,4 +210,13 @@ public abstract class Config implements ConfigurationProvider {
return new ArrayList<>();
}
}
public @Nullable JsonElement getSerializedComponent(String key) {
final Object o = this.config.get(key);
if (o != null && !((String) o).isEmpty()) {
return GsonComponentSerializer.gson().serializeToTree(LegacyComponentSerializer.legacySection().deserialize((String) o));
} else {
return null;
}
}
}

Datei anzeigen

@ -153,6 +153,8 @@ ignore-long-1_16-channel-names: true
#
# Force 1.17+ client to accept the server resource pack; they will automatically disconnect if they decline.
forced-use-1_17-resource-pack: false
# The message to be displayed at the prompt when the 1.17+ client receives the server resource pack.
resource-pack-1_17-prompt: ''
#
#----------------------------------------------------------#
# 1.9+ CLIENTS ON 1.8 SERVERS OPTIONS #