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 {
|
minecraft {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
license {
|
||||||
|
include("**/*.java")
|
||||||
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
package com.github.creeper123123321.viafabric;
|
package com.github.creeper123123321.viafabric;
|
||||||
|
|
||||||
import com.github.creeper123123321.viafabric.commands.VRCommandHandler;
|
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.VRInjector;
|
||||||
import com.github.creeper123123321.viafabric.platform.VRLoader;
|
import com.github.creeper123123321.viafabric.platform.VRLoader;
|
||||||
import com.github.creeper123123321.viafabric.platform.VRPlatform;
|
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 Logger JLOGGER = new JLoggerToLog4j(LogManager.getLogger("ViaFabric"));
|
||||||
public static final ExecutorService ASYNC_EXECUTOR;
|
public static final ExecutorService ASYNC_EXECUTOR;
|
||||||
public static final EventLoop EVENT_LOOP;
|
public static final EventLoop EVENT_LOOP;
|
||||||
|
public static VRConfig config;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat("ViaFabric-%d").build();
|
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("viaversion")));
|
||||||
CommandRegistry.INSTANCE.register(false, c -> c.register(command("viaver")));
|
CommandRegistry.INSTANCE.register(false, c -> c.register(command("viaver")));
|
||||||
CommandRegistry.INSTANCE.register(false, c -> c.register(command("vvfabric")));
|
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;
|
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 com.github.creeper123123321.viafabric.util.VersionFormatFilter;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.gui.screen.ConfirmScreen;
|
import net.minecraft.client.gui.screen.ConfirmScreen;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
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.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
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.ProtocolRegistry;
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
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.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@ -64,6 +61,8 @@ public abstract class MixinMultiplayerScreen extends Screen {
|
|||||||
private boolean validProtocol;
|
private boolean validProtocol;
|
||||||
@Unique
|
@Unique
|
||||||
private boolean supportedProtocol;
|
private boolean supportedProtocol;
|
||||||
|
@Unique
|
||||||
|
private CompletableFuture<Void> latestProtocolSave;
|
||||||
|
|
||||||
protected MixinMultiplayerScreen(Text title, UnsupportedOperationException e) {
|
protected MixinMultiplayerScreen(Text title, UnsupportedOperationException e) {
|
||||||
super(title);
|
super(title);
|
||||||
@ -76,7 +75,7 @@ public abstract class MixinMultiplayerScreen extends Screen {
|
|||||||
protocolVersion.setTextPredicate(new VersionFormatFilter());
|
protocolVersion.setTextPredicate(new VersionFormatFilter());
|
||||||
protocolVersion.setChangedListener((text) -> {
|
protocolVersion.setChangedListener((text) -> {
|
||||||
protocolVersion.setSuggestion(null);
|
protocolVersion.setSuggestion(null);
|
||||||
int newVersion = ((VRVersionProvider) Via.getManager().getProviders().get(VersionProvider.class)).clientSideModeVersion;
|
int newVersion = ViaFabric.config.getClientSideVersion();
|
||||||
validProtocol = true;
|
validProtocol = true;
|
||||||
try {
|
try {
|
||||||
newVersion = Integer.parseInt(text);
|
newVersion = Integer.parseInt(text);
|
||||||
@ -102,9 +101,17 @@ public abstract class MixinMultiplayerScreen extends Screen {
|
|||||||
}
|
}
|
||||||
supportedProtocol = isSupported(newVersion);
|
supportedProtocol = isSupported(newVersion);
|
||||||
protocolVersion.setEditableColor(getTextColor());
|
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.setText(ProtocolVersion.isRegistered(clientSideVersion)
|
||||||
? ProtocolVersion.getProtocol(clientSideVersion).getName()
|
? ProtocolVersion.getProtocol(clientSideVersion).getName()
|
||||||
: Integer.toString(clientSideVersion));
|
: Integer.toString(clientSideVersion));
|
||||||
@ -120,13 +127,10 @@ public abstract class MixinMultiplayerScreen extends Screen {
|
|||||||
answer -> {
|
answer -> {
|
||||||
MinecraftClient.getInstance().openScreen(this);
|
MinecraftClient.getInstance().openScreen(this);
|
||||||
if (answer) {
|
if (answer) {
|
||||||
try {
|
ViaFabric.config.setClientSideEnabled(true);
|
||||||
FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaFabric").resolve("enable_client_side").toFile().createNewFile();
|
ViaFabric.config.saveConfig();
|
||||||
protocolVersion.setVisible(true);
|
protocolVersion.setVisible(true);
|
||||||
enableClientSideViaVersion.visible = false;
|
enableClientSideViaVersion.visible = false;
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new TranslatableText("gui.enable_client_side.question"),
|
new TranslatableText("gui.enable_client_side.question"),
|
||||||
@ -135,7 +139,6 @@ public abstract class MixinMultiplayerScreen extends Screen {
|
|||||||
I18n.translate("gui.cancel")
|
I18n.translate("gui.cancel")
|
||||||
)),
|
)),
|
||||||
I18n.translate("gui.enable_client_side_button"));
|
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();
|
enableClientSideViaVersion.visible = !protocolVersion.isVisible();
|
||||||
addButton(enableClientSideViaVersion);
|
addButton(enableClientSideViaVersion);
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@ package com.github.creeper123123321.viafabric.platform;
|
|||||||
import com.github.creeper123123321.viafabric.ViaFabric;
|
import com.github.creeper123123321.viafabric.ViaFabric;
|
||||||
import com.github.creeper123123321.viafabric.commands.NMSCommandSender;
|
import com.github.creeper123123321.viafabric.commands.NMSCommandSender;
|
||||||
import com.github.creeper123123321.viafabric.commands.UserCommandSender;
|
import com.github.creeper123123321.viafabric.commands.UserCommandSender;
|
||||||
import com.github.creeper123123321.viafabric.providers.VRVersionProvider;
|
|
||||||
import com.github.creeper123123321.viafabric.util.FutureTaskId;
|
import com.github.creeper123123321.viafabric.util.FutureTaskId;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
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.TaskId;
|
||||||
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
||||||
import us.myles.ViaVersion.dump.PluginInfo;
|
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.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||||
import us.myles.ViaVersion.sponge.VersionInfo;
|
import us.myles.ViaVersion.sponge.VersionInfo;
|
||||||
import us.myles.ViaVersion.util.GsonUtil;
|
import us.myles.ViaVersion.util.GsonUtil;
|
||||||
@ -295,7 +293,6 @@ public class VRPlatform implements ViaPlatform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
platformSpecific.add("mods", GsonUtil.getGson().toJsonTree(mods));
|
platformSpecific.add("mods", GsonUtil.getGson().toJsonTree(mods));
|
||||||
platformSpecific.addProperty("client-sided-version", ((VRVersionProvider) Via.getManager().getProviders().get(VersionProvider.class)).clientSideModeVersion);
|
|
||||||
return platformSpecific;
|
return platformSpecific;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
package com.github.creeper123123321.viafabric.platform;
|
package com.github.creeper123123321.viafabric.platform;
|
||||||
|
|
||||||
import us.myles.ViaVersion.AbstractViaConfig;
|
import us.myles.ViaVersion.AbstractViaConfig;
|
||||||
import us.myles.ViaVersion.util.Config;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
@ -24,17 +24,16 @@
|
|||||||
|
|
||||||
package com.github.creeper123123321.viafabric.providers;
|
package com.github.creeper123123321.viafabric.providers;
|
||||||
|
|
||||||
|
import com.github.creeper123123321.viafabric.ViaFabric;
|
||||||
import com.github.creeper123123321.viafabric.platform.VRClientSideUserConnection;
|
import com.github.creeper123123321.viafabric.platform.VRClientSideUserConnection;
|
||||||
import net.minecraft.SharedConstants;
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.protocols.base.VersionProvider;
|
import us.myles.ViaVersion.protocols.base.VersionProvider;
|
||||||
|
|
||||||
public class VRVersionProvider extends VersionProvider {
|
public class VRVersionProvider extends VersionProvider {
|
||||||
public int clientSideModeVersion = SharedConstants.getGameVersion().getProtocolVersion();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getServerProtocol(UserConnection connection) throws Exception {
|
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);
|
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