mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-12-18 15:47:46 +01:00
Add config file
This commit is contained in:
parent
08ce779d4b
commit
cda0152a4b
@ -63,3 +63,7 @@ dependencies {
|
||||
|
||||
minecraft {
|
||||
}
|
||||
|
||||
license {
|
||||
include("**/*.java")
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
package com.github.creeper123123321.viafabric;
|
||||
|
||||
import com.github.creeper123123321.viafabric.commands.VRCommandHandler;
|
||||
import com.github.creeper123123321.viafabric.config.VRConfig;
|
||||
import com.github.creeper123123321.viafabric.platform.VRInjector;
|
||||
import com.github.creeper123123321.viafabric.platform.VRLoader;
|
||||
import com.github.creeper123123321.viafabric.platform.VRPlatform;
|
||||
@ -52,6 +53,7 @@ public class ViaFabric implements ModInitializer {
|
||||
public static final Logger JLOGGER = new JLoggerToLog4j(LogManager.getLogger("ViaFabric"));
|
||||
public static final ExecutorService ASYNC_EXECUTOR;
|
||||
public static final EventLoop EVENT_LOOP;
|
||||
public static VRConfig config;
|
||||
|
||||
static {
|
||||
ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat("ViaFabric-%d").build();
|
||||
@ -89,5 +91,8 @@ public class ViaFabric implements ModInitializer {
|
||||
CommandRegistry.INSTANCE.register(false, c -> c.register(command("viaversion")));
|
||||
CommandRegistry.INSTANCE.register(false, c -> c.register(command("viaver")));
|
||||
CommandRegistry.INSTANCE.register(false, c -> c.register(command("vvfabric")));
|
||||
|
||||
config = new VRConfig(FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaFabric")
|
||||
.resolve("viafabric.yml").toFile());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 creeper123123321 and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.creeper123123321.viafabric.config;
|
||||
|
||||
import net.minecraft.SharedConstants;
|
||||
import us.myles.ViaVersion.util.Config;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class VRConfig extends Config {
|
||||
public static final String ENABLE_CLIENT_SIDE = "enable-client-side";
|
||||
public static final String CLIENT_SIDE_VERSION = "client-side-version";
|
||||
|
||||
public VRConfig(File configFile) {
|
||||
super(configFile);
|
||||
reloadConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getDefaultConfigURL() {
|
||||
return getClass().getClassLoader().getResource("assets/viafabric/config.yml");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleConfig(Map<String, Object> map) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUnsupportedOptions() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public boolean isClientSideEnabled() {
|
||||
return getBoolean(ENABLE_CLIENT_SIDE, false);
|
||||
}
|
||||
|
||||
public int getClientSideVersion() {
|
||||
int nat = SharedConstants.getGameVersion().getProtocolVersion();
|
||||
return !isClientSideEnabled() ? nat : getInt(CLIENT_SIDE_VERSION, -1);
|
||||
}
|
||||
|
||||
public void setClientSideEnabled(boolean val) {
|
||||
set(ENABLE_CLIENT_SIDE, val);
|
||||
}
|
||||
|
||||
public void setClientSideVersion(int val) {
|
||||
set(CLIENT_SIDE_VERSION, val);
|
||||
}
|
||||
}
|
@ -24,9 +24,8 @@
|
||||
|
||||
package com.github.creeper123123321.viafabric.mixin.client;
|
||||
|
||||
import com.github.creeper123123321.viafabric.providers.VRVersionProvider;
|
||||
import com.github.creeper123123321.viafabric.ViaFabric;
|
||||
import com.github.creeper123123321.viafabric.util.VersionFormatFilter;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.ConfirmScreen;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
@ -43,14 +42,12 @@ import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||
import us.myles.ViaVersion.protocols.base.VersionProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ -64,6 +61,8 @@ public abstract class MixinMultiplayerScreen extends Screen {
|
||||
private boolean validProtocol;
|
||||
@Unique
|
||||
private boolean supportedProtocol;
|
||||
@Unique
|
||||
private CompletableFuture<Void> latestProtocolSave;
|
||||
|
||||
protected MixinMultiplayerScreen(Text title, UnsupportedOperationException e) {
|
||||
super(title);
|
||||
@ -76,7 +75,7 @@ public abstract class MixinMultiplayerScreen extends Screen {
|
||||
protocolVersion.setTextPredicate(new VersionFormatFilter());
|
||||
protocolVersion.setChangedListener((text) -> {
|
||||
protocolVersion.setSuggestion(null);
|
||||
int newVersion = ((VRVersionProvider) Via.getManager().getProviders().get(VersionProvider.class)).clientSideModeVersion;
|
||||
int newVersion = ViaFabric.config.getClientSideVersion();
|
||||
validProtocol = true;
|
||||
try {
|
||||
newVersion = Integer.parseInt(text);
|
||||
@ -102,9 +101,17 @@ public abstract class MixinMultiplayerScreen extends Screen {
|
||||
}
|
||||
supportedProtocol = isSupported(newVersion);
|
||||
protocolVersion.setEditableColor(getTextColor());
|
||||
((VRVersionProvider) Via.getManager().getProviders().get(VersionProvider.class)).clientSideModeVersion = newVersion;
|
||||
int finalNewVersion = newVersion;
|
||||
if (latestProtocolSave == null) latestProtocolSave = CompletableFuture.completedFuture(null);
|
||||
latestProtocolSave = latestProtocolSave.thenRunAsync(() -> {
|
||||
ViaFabric.config.setClientSideVersion(finalNewVersion);
|
||||
ViaFabric.config.saveConfig();
|
||||
}, ViaFabric.ASYNC_EXECUTOR);
|
||||
});
|
||||
int clientSideVersion = ((VRVersionProvider) Via.getManager().getProviders().get(VersionProvider.class)).clientSideModeVersion;
|
||||
int clientSideVersion = ViaFabric.config.getClientSideVersion();
|
||||
|
||||
protocolVersion.setVisible(ViaFabric.config.isClientSideEnabled());
|
||||
|
||||
protocolVersion.setText(ProtocolVersion.isRegistered(clientSideVersion)
|
||||
? ProtocolVersion.getProtocol(clientSideVersion).getName()
|
||||
: Integer.toString(clientSideVersion));
|
||||
@ -120,13 +127,10 @@ public abstract class MixinMultiplayerScreen extends Screen {
|
||||
answer -> {
|
||||
MinecraftClient.getInstance().openScreen(this);
|
||||
if (answer) {
|
||||
try {
|
||||
FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaFabric").resolve("enable_client_side").toFile().createNewFile();
|
||||
protocolVersion.setVisible(true);
|
||||
enableClientSideViaVersion.visible = false;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ViaFabric.config.setClientSideEnabled(true);
|
||||
ViaFabric.config.saveConfig();
|
||||
protocolVersion.setVisible(true);
|
||||
enableClientSideViaVersion.visible = false;
|
||||
}
|
||||
},
|
||||
new TranslatableText("gui.enable_client_side.question"),
|
||||
@ -135,7 +139,6 @@ public abstract class MixinMultiplayerScreen extends Screen {
|
||||
I18n.translate("gui.cancel")
|
||||
)),
|
||||
I18n.translate("gui.enable_client_side_button"));
|
||||
protocolVersion.setVisible(FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaFabric").resolve("enable_client_side").toFile().exists());
|
||||
enableClientSideViaVersion.visible = !protocolVersion.isVisible();
|
||||
addButton(enableClientSideViaVersion);
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ package com.github.creeper123123321.viafabric.platform;
|
||||
import com.github.creeper123123321.viafabric.ViaFabric;
|
||||
import com.github.creeper123123321.viafabric.commands.NMSCommandSender;
|
||||
import com.github.creeper123123321.viafabric.commands.UserCommandSender;
|
||||
import com.github.creeper123123321.viafabric.providers.VRVersionProvider;
|
||||
import com.github.creeper123123321.viafabric.util.FutureTaskId;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
@ -52,7 +51,6 @@ import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.platform.TaskId;
|
||||
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
||||
import us.myles.ViaVersion.dump.PluginInfo;
|
||||
import us.myles.ViaVersion.protocols.base.VersionProvider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||
import us.myles.ViaVersion.sponge.VersionInfo;
|
||||
import us.myles.ViaVersion.util.GsonUtil;
|
||||
@ -295,7 +293,6 @@ public class VRPlatform implements ViaPlatform {
|
||||
}
|
||||
|
||||
platformSpecific.add("mods", GsonUtil.getGson().toJsonTree(mods));
|
||||
platformSpecific.addProperty("client-sided-version", ((VRVersionProvider) Via.getManager().getProviders().get(VersionProvider.class)).clientSideModeVersion);
|
||||
return platformSpecific;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,6 @@
|
||||
package com.github.creeper123123321.viafabric.platform;
|
||||
|
||||
import us.myles.ViaVersion.AbstractViaConfig;
|
||||
import us.myles.ViaVersion.util.Config;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
@ -24,17 +24,16 @@
|
||||
|
||||
package com.github.creeper123123321.viafabric.providers;
|
||||
|
||||
import com.github.creeper123123321.viafabric.ViaFabric;
|
||||
import com.github.creeper123123321.viafabric.platform.VRClientSideUserConnection;
|
||||
import net.minecraft.SharedConstants;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.protocols.base.VersionProvider;
|
||||
|
||||
public class VRVersionProvider extends VersionProvider {
|
||||
public int clientSideModeVersion = SharedConstants.getGameVersion().getProtocolVersion();
|
||||
|
||||
@Override
|
||||
public int getServerProtocol(UserConnection connection) throws Exception {
|
||||
if (connection instanceof VRClientSideUserConnection) return clientSideModeVersion;
|
||||
if (connection instanceof VRClientSideUserConnection)
|
||||
return ViaFabric.config.getClientSideVersion();
|
||||
return super.getServerProtocol(connection);
|
||||
}
|
||||
}
|
||||
|
6
src/main/resources/assets/viafabric/config.yml
Normal file
6
src/main/resources/assets/viafabric/config.yml
Normal file
@ -0,0 +1,6 @@
|
||||
# WARNING
|
||||
# I can not guarantee that this mod is allowed on every (or even any) server. This mod may cause problems with anti cheat plugins. USE AT OWN RISK
|
||||
# This option enables client-side transforming (can also be enabled in-game)
|
||||
enable-client-side: false
|
||||
# This option sets the protocol version to be used when connection to the server (can also be changed in-game)
|
||||
client-side-version: -1
|
Loading…
Reference in New Issue
Block a user