Skip to content

Commit

Permalink
feat: make config values import from the old files
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 authored Dec 18, 2024
1 parent 3919a83 commit 04f1941
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.sekwah.advancedportals.core.serializeddata.DataStorage;
import com.sekwah.advancedportals.core.serializeddata.config.CommandPortalConfig;
import com.sekwah.advancedportals.core.serializeddata.config.Config;

public interface ConfigRepository {
boolean getUseOnlySpecialAxe();
Expand Down Expand Up @@ -54,4 +55,6 @@ public interface ConfigRepository {
boolean getEnableProxySupport();

boolean getDisableGatewayBeam();

void importConfig(Config config);
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,9 @@ public boolean warpMessageInChat() {
public void storeConfig() {
this.dataStorage.storeFile(this.config, "config.yaml");
}

public void importConfig(Config config) {
this.config = config;
this.storeConfig();
}
}
4 changes: 2 additions & 2 deletions lang/src/main/resources/lang/en_GB.lang
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ command.selector= You have been given a portal selector.
command.selector.help=Gives you a portal region selector
command.selector.detailedhelp=Gives you a portal selector to select the regions for making portals.

command.portal.import= &e%1$s &aportals and &e%2$s &adestinations will be imported. Please type &e/portal import confirm &ato confirm this action. &7Config values will not be imported.
command.portal.import= &e%1$s &aportals and &e%2$s &adestinations will be imported. The config file will also be overwritten. Please type &e/portal import confirm &ato confirm this action.
command.portal.import.confirm= &aImporting portals and destinations.
command.portal.import.complete= &aImported &e%1$s &aportals and &e%2$s &adestinations.
command.portal.import.help=Imports portals and destinations from the old format.
command.portal.import.detailedhelp=Imports portals and destinations from the old format. This not overwrite any existing portals and destinations with the same name.
command.portal.import.detailedhelp=Imports portals and destinations from the old format. This not overwrite any existing portals and destinations with the same name however you will lose any config values setup.

command.portalblock= You have been given a &ePortal Block&a!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.sekwah.advancedportals.core.connector.commands.CommandRegister;
import com.sekwah.advancedportals.core.module.AdvancedPortalsModule;
import com.sekwah.advancedportals.core.permissions.Permissions;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
import com.sekwah.advancedportals.core.services.DestinationServices;
import com.sekwah.advancedportals.core.services.PortalServices;
import com.sekwah.advancedportals.core.util.GameScheduler;
Expand All @@ -12,6 +13,7 @@
import com.sekwah.advancedportals.spigot.commands.subcommands.portal.ImportPortalSubCommand;
import com.sekwah.advancedportals.spigot.connector.command.SpigotCommandRegister;
import com.sekwah.advancedportals.spigot.connector.container.SpigotServerContainer;
import com.sekwah.advancedportals.spigot.importer.ConfigAccessor;
import com.sekwah.advancedportals.spigot.importer.LegacyImporter;
import com.sekwah.advancedportals.spigot.metrics.Metrics;
import com.sekwah.advancedportals.spigot.warpeffects.SpigotWarpEffects;
Expand All @@ -29,6 +31,9 @@ public class AdvancedPortalsPlugin extends JavaPlugin {
@Inject
PortalServices portalServices;

@Inject
ConfigRepository configRepo;

private static AdvancedPortalsPlugin instance;

public static AdvancedPortalsPlugin getInstance() {
Expand Down Expand Up @@ -97,17 +102,24 @@ private void checkAndCreateConfig() {
if (destiFile.exists() && !destiFolder.exists()) {
destiFolder.mkdirs();
getLogger().info(
"Importing old destinations from destinations.yaml");
"Importing old destinations from destinations.yml");
LegacyImporter.importDestinations(this.destinationServices);
}

File portalFile = new File(this.getDataFolder(), "portals.yml");
File portalFolder = new File(this.getDataFolder(), "portals");
if (portalFile.exists() && !portalFolder.exists()) {
portalFolder.mkdirs();
getLogger().info("Importing old portals from portals.yaml");
getLogger().info("Importing old portals from portals.yml");
LegacyImporter.importPortals(this.portalServices);
}

// Check if config.yml exists and config.yaml doesnt exist
File configFile = new File(this.getDataFolder(), "config.yml");
File configYamlFile = new File(this.getDataFolder(), "config.yaml");
if (configFile.exists() && !configYamlFile.exists()) {
LegacyImporter.importConfig(this.configRepo);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.sekwah.advancedportals.spigot.commands.subcommands.portal;

import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.commands.SubCommand;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.permissions.Permissions;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
import com.sekwah.advancedportals.core.services.DestinationServices;
import com.sekwah.advancedportals.core.services.PortalServices;
import com.sekwah.advancedportals.core.util.Lang;
Expand All @@ -14,12 +16,18 @@
import java.util.Set;

public class ImportPortalSubCommand implements SubCommand {
@Inject
private AdvancedPortalsCore portalsCore;

@Inject
DestinationServices destinationServices;

@Inject
PortalServices portalServices;

@Inject
ConfigRepository configRepo;

@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
if (args.length > 1 && "confirm".equals(args[1])) {
Expand All @@ -29,6 +37,12 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
int destinations =
LegacyImporter.importDestinations(destinationServices);
int portals = LegacyImporter.importPortals(portalServices);
LegacyImporter.importConfig(this.configRepo);

portalsCore.loadPortalConfig();
portalServices.loadPortals();
destinationServices.loadDestinations();

sender.sendMessage(
Lang.getPositivePrefix()
+ Lang.translateInsertVariables(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.sekwah.advancedportals.spigot.importer;

import com.sekwah.advancedportals.core.repository.ConfigRepository;
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
import com.sekwah.advancedportals.core.serializeddata.DataTag;
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
import com.sekwah.advancedportals.core.serializeddata.config.CommandPortalConfig;
import com.sekwah.advancedportals.core.serializeddata.config.Config;
import com.sekwah.advancedportals.core.serializeddata.config.WarpEffectConfig;
import com.sekwah.advancedportals.core.services.DestinationServices;
import com.sekwah.advancedportals.core.services.PortalServices;
import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin;
Expand All @@ -16,6 +20,7 @@ private LegacyImporter() {
}

public static int importPortals(PortalServices portalServices) {
// Check if the file exists and skip if it doesn't
ConfigAccessor portalConfig = new ConfigAccessor(
AdvancedPortalsPlugin.getInstance(), "portals.yml");
var config = portalConfig.getConfig();
Expand Down Expand Up @@ -136,4 +141,46 @@ public static String getArg(List<DataTag> tags, String arg) {
}
return null;
}

public static void importConfig(ConfigRepository configRepo) {
var config = new Config();
ConfigAccessor configOldAccessor = new ConfigAccessor(
AdvancedPortalsPlugin.getInstance(), "config.yml");
var configOld = configOldAccessor.getConfig();

config.useOnlySpecialAxe = configOld.getBoolean("UseOnlyServerMadeAxe", config.useOnlySpecialAxe);
config.blockSpectatorMode = configOld.getBoolean("BlockSpectatorMode", config.blockSpectatorMode);
config.selectorMaterial = configOld.getString("AxeItemId", config.selectorMaterial);
config.portalProtection = configOld.getBoolean("PortalProtection", config.portalProtection);
config.portalProtectionRaduis = configOld.getInt("PortalProtectionArea", config.portalProtectionRaduis);
config.defaultTriggerBlock = configOld.getString("DefaultPortalTriggerBlock", config.defaultTriggerBlock);
if (config.defaultTriggerBlock.equals("PORTAL")) {
config.defaultTriggerBlock = "NETHER_PORTAL";
}
config.stopWaterFlow = configOld.getBoolean("StopWaterFlow", config.stopWaterFlow);
config.joinCooldown = configOld.getInt("PortalCooldown", config.joinCooldown);
config.throwbackStrength = configOld.getDouble("ThrowbackAmount", config.throwbackStrength);
config.playFailSound = configOld.getBoolean("PlayFailSound", config.playFailSound);
config.warpMessageOnActionBar = configOld.getInt("WarpMessageDisplay", 2) == 2;
config.warpMessageInChat = configOld.getInt("WarpMessageDisplay", 2) == 1;
config.enableProxySupport = configOld.getBoolean("ForceEnableProxySupport", config.enableProxySupport);
config.disableGatewayBeam = configOld.getBoolean("DisableGatewayBeam", config.disableGatewayBeam);

CommandPortalConfig commandConfig = new CommandPortalConfig();
var commandString = configOld.getString("CommandLevels", "opcb");
commandConfig.enabled = !commandString.contains("n");
commandConfig.op = commandString.contains("o");
commandConfig.permsWildcard = commandString.contains("p");
commandConfig.console = commandString.contains("c");
commandConfig.proxy = commandString.contains("b");

config.commandPortals = commandConfig;

WarpEffectConfig warpEffectConfig = new WarpEffectConfig();
warpEffectConfig.visualEffect = configOld.getInt("WarpParticles", 1) == 1 ? "ender" : null;
warpEffectConfig.soundEffect = configOld.getInt("WarpSound", 1) == 1 ? "ender" : null;
config.warpEffect = warpEffectConfig;

configRepo.importConfig(config);
}
}

0 comments on commit 04f1941

Please sign in to comment.