Fixed configs being reset to default on startup

This commit is contained in:
RaphiMC 2023-02-01 17:42:43 +01:00
parent b1b54e1dd7
commit 8228f03549
10 changed files with 133 additions and 124 deletions

View File

@ -0,0 +1,40 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2023 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.injection.transformer;
import com.viaversion.viaversion.util.Config;
import net.lenni0451.classtransform.annotations.CTarget;
import net.lenni0451.classtransform.annotations.CTransformer;
import net.lenni0451.classtransform.annotations.injection.CRedirect;
import net.raphimc.viaproxy.protocolhack.ConfigPatcher;
import java.util.Map;
@CTransformer(Config.class)
public abstract class ConfigTransformer {
@CRedirect(method = "loadConfig(Ljava/io/File;Ljava/net/URL;)Ljava/util/Map;", target = @CTarget(value = "INVOKE", target = "Ljava/util/Map;containsKey(Ljava/lang/Object;)Z"))
private boolean allowConfigPatching(final Map<String, Object> map, final Object key) {
if (((Object) this) instanceof ConfigPatcher) {
return true;
}
return map.containsKey(key);
}
}

View File

@ -0,0 +1,58 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2023 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.protocolhack;
import com.viaversion.viaversion.util.Config;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class ConfigPatcher extends Config {
private final Map<String, Object> patches;
public ConfigPatcher(final File configFile, final Map<String, Object> patches) {
super(configFile);
this.patches = patches;
this.reloadConfig();
}
@Override
public URL getDefaultConfigURL() {
return ConfigPatcher.class.getClassLoader().getResource("assets/viaproxy/dummy.yml");
}
@Override
protected void handleConfig(Map<String, Object> config) {
for (final Map.Entry<String, Object> entry : this.patches.entrySet()) {
if (!config.containsKey(entry.getKey())) {
config.put(entry.getKey(), entry.getValue());
}
}
}
@Override
public List<String> getUnsupportedOptions() {
return new ArrayList<>();
}
}

View File

@ -18,18 +18,49 @@
package net.raphimc.viaproxy.protocolhack;
import net.raphimc.viaprotocolhack.ViaProtocolHack;
import net.raphimc.viaprotocolhack.impl.platform.ViaBackwardsPlatformImpl;
import net.raphimc.viaprotocolhack.impl.platform.ViaLegacyPlatformImpl;
import net.raphimc.viaprotocolhack.impl.platform.ViaRewindPlatformImpl;
import net.raphimc.viaproxy.plugins.PluginManager;
import net.raphimc.viaproxy.plugins.events.ProtocolHackInitEvent;
import net.raphimc.viaproxy.protocolhack.impl.*;
import net.raphimc.viaproxy.protocolhack.impl.ViaAprilFoolsPlatformImpl;
import net.raphimc.viaproxy.protocolhack.impl.ViaProxyVPLoader;
import net.raphimc.viaproxy.protocolhack.impl.ViaProxyViaVersionPlatformImpl;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
public class ProtocolHack {
public static void init() {
patchConfigs();
final Supplier<?>[] additionalPlatformSuppliers = PluginManager.EVENT_MANAGER.call(new ProtocolHackInitEvent(ViaAprilFoolsPlatformImpl::new)).getPlatformSuppliers().toArray(new Supplier[0]);
ViaProtocolHack.init(new ViaProxyViaVersionPlatformImpl(), new ViaProxyVPLoader(), null, null, ViaProxyViaBackwardsPlatformImpl::new, ViaProxyViaRewindPlatformImpl::new, ViaLegacyPlatformImpl::new, additionalPlatformSuppliers);
ViaProtocolHack.init(new ViaProxyViaVersionPlatformImpl(), new ViaProxyVPLoader(), null, null, ViaBackwardsPlatformImpl::new, ViaRewindPlatformImpl::new, ViaLegacyPlatformImpl::new, additionalPlatformSuppliers);
}
private static void patchConfigs() {
final File configFolder = new File("ViaProtocolHack");
final File viaVersionConfig = new File(configFolder, "viaversion.yml");
final Map<String, Object> viaVersionPatches = new HashMap<>();
viaVersionPatches.put("1_13-tab-complete-delay", 5);
viaVersionPatches.put("no-delay-shield-blocking", true);
viaVersionPatches.put("chunk-border-fix", true);
new ConfigPatcher(viaVersionConfig, viaVersionPatches);
final File viaBackwardsConfig = new File(configFolder, "config.yml");
final Map<String, Object> viaBackwardsPatches = new HashMap<>();
viaBackwardsPatches.put("fix-1_13-face-player", true);
viaBackwardsPatches.put("handle-pings-as-inv-acknowledgements", true);
new ConfigPatcher(viaBackwardsConfig, viaBackwardsPatches);
final File viaRewindConfig = new File(configFolder, "viarewind.yml");
final Map<String, Object> viaRewindPatches = new HashMap<>();
viaRewindPatches.put("replace-adventure", true);
viaRewindPatches.put("replace-particles", true);
new ConfigPatcher(viaRewindConfig, viaRewindPatches);
}
}

View File

@ -1,40 +0,0 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2023 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.protocolhack.impl;
import com.viaversion.viabackwards.ViaBackwardsConfig;
import net.raphimc.viaprotocolhack.impl.platform.ViaBackwardsPlatformImpl;
import java.io.File;
import java.net.URL;
public class ViaProxyViaBackwardsPlatformImpl extends ViaBackwardsPlatformImpl {
@Override
public void init(File dataFolder) {
new ViaBackwardsConfig(new File(dataFolder, "config.yml")) {
@Override
public URL getDefaultConfigURL() {
return ViaProxyViaVersionPlatformImpl.class.getClassLoader().getResource("assets/viaproxy/config_diff/viabackwards.yml");
}
}.reloadConfig();
super.init(dataFolder);
}
}

View File

@ -1,52 +0,0 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2023 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.protocolhack.impl;
import com.viaversion.viaversion.api.Via;
import de.gerrygames.viarewind.api.ViaRewindConfigImpl;
import de.gerrygames.viarewind.api.ViaRewindPlatform;
import net.raphimc.viaprotocolhack.util.JLoggerToSLF4J;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.net.URL;
import java.util.logging.Logger;
public class ViaProxyViaRewindPlatformImpl implements ViaRewindPlatform {
private static final Logger LOGGER = new JLoggerToSLF4J(LoggerFactory.getLogger("ViaRewind"));
public ViaProxyViaRewindPlatformImpl() {
new ViaRewindConfigImpl(new File(Via.getPlatform().getDataFolder(), "viarewind.yml")) {
@Override
public URL getDefaultConfigURL() {
return ViaProxyViaVersionPlatformImpl.class.getClassLoader().getResource("assets/viaproxy/config_diff/viarewind.yml");
}
}.reloadConfig();
final ViaRewindConfigImpl config = new ViaRewindConfigImpl(new File(Via.getPlatform().getDataFolder(), "viarewind.yml"));
config.reloadConfig();
this.init(config);
}
@Override
public Logger getLogger() {
return LOGGER;
}
}

View File

@ -17,13 +17,9 @@
*/
package net.raphimc.viaproxy.protocolhack.impl;
import com.viaversion.viaversion.configuration.AbstractViaConfig;
import net.raphimc.viaprotocolhack.impl.platform.ViaVersionPlatformImpl;
import net.raphimc.viaprotocolhack.impl.viaversion.VPViaConfig;
import net.raphimc.viaproxy.cli.ConsoleFormatter;
import java.io.File;
import java.net.URL;
import java.util.UUID;
public class ViaProxyViaVersionPlatformImpl extends ViaVersionPlatformImpl {
@ -37,16 +33,4 @@ public class ViaProxyViaVersionPlatformImpl extends ViaVersionPlatformImpl {
super.sendMessage(uuid, ConsoleFormatter.convert(msg));
}
@Override
protected AbstractViaConfig createConfig() {
new VPViaConfig(new File(this.getDataFolder(), "viaversion.yml")) {
@Override
public URL getDefaultConfigURL() {
return ViaProxyViaVersionPlatformImpl.class.getClassLoader().getResource("assets/viaproxy/config_diff/viaversion.yml");
}
}.reloadConfig();
return super.createConfig();
}
}

View File

@ -1,4 +0,0 @@
#Overwrite default value
fix-1_13-face-player: true
#Overwrite default value
handle-pings-as-inv-acknowledgements: true

View File

@ -1,4 +0,0 @@
#Overwrite default value
replace-adventure: true
#Overwrite default value
replace-particles: true

View File

@ -1,6 +0,0 @@
#Overwrite default value
1_13-tab-complete-delay: 5
#Overwrite default value
no-delay-shield-blocking: true
#Overwrite default value
chunk-border-fix: true

View File

@ -0,0 +1,2 @@
#Dummy config
this_is_a_dummy_config: true