#83 Fixes some template inheritance issues

This commit is contained in:
ME1312 2023-05-25 22:22:09 -04:00
parent c511ded3d4
commit 78f50e77b2
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
2 changed files with 15 additions and 12 deletions

View File

@ -64,8 +64,10 @@ public class InternalSubCreator extends SubCreator {
private final int port; private final int port;
private final String prefix; private final String prefix;
private final InternalSubLogger log; private final InternalSubLogger log;
private final LinkedList<String> replace;
private final HashMap<String, String> replacements; private final HashMap<String, String> replacements;
private final Consumer<SubServer> callback; private final Consumer<SubServer> callback;
private Boolean install;
private Process process; private Process process;
private CreatorTask(UUID player, String name, ServerTemplate template, Version version, int port, Consumer<SubServer> callback) { private CreatorTask(UUID player, String name, ServerTemplate template, Version version, int port, Consumer<SubServer> callback) {
@ -77,6 +79,7 @@ public class InternalSubCreator extends SubCreator {
this.version = version; this.version = version;
this.port = port; this.port = port;
this.log = new InternalSubLogger(null, this, prefix = name + File.separator + "Creator", InternalSubCreator.this.log, null); this.log = new InternalSubLogger(null, this, prefix = name + File.separator + "Creator", InternalSubCreator.this.log, null);
(this.replace = new LinkedList<String>()).add("/server.properties");
this.replacements = new HashMap<String, String>(); this.replacements = new HashMap<String, String>();
this.callback = callback; this.callback = callback;
} }
@ -90,6 +93,7 @@ public class InternalSubCreator extends SubCreator {
this.version = version; this.version = version;
this.port = server.getAddress().getPort(); this.port = server.getAddress().getPort();
this.log = new InternalSubLogger(null, this, prefix = name + File.separator + "Updater", InternalSubCreator.this.log, null); this.log = new InternalSubLogger(null, this, prefix = name + File.separator + "Updater", InternalSubCreator.this.log, null);
(this.replace = new LinkedList<String>()).add("/server.properties");
this.replacements = new HashMap<String, String>(); this.replacements = new HashMap<String, String>();
this.callback = callback; this.callback = callback;
} }
@ -132,6 +136,8 @@ public class InternalSubCreator extends SubCreator {
log.log(INFO, "Loading" + ((template.isDynamic())?" Dynamic":"") + " Template: " + template.getDisplayName()); log.log(INFO, "Loading" + ((template.isDynamic())?" Dynamic":"") + " Template: " + template.getDisplayName());
updateDirectory(template.getDirectory(), dir, template.getBuildOptions().getBoolean("Update-Files", false)); updateDirectory(template.getDirectory(), dir, template.getBuildOptions().getBoolean("Update-Files", false));
install = template.getBuildOptions().getBoolean("Install-Client", install);
replace.addAll(template.getBuildOptions().getStringList("Replace", Collections.emptyList()));
for (ObjectMapValue<String> replacement : template.getBuildOptions().getMap("Replacements", new ObjectMap<>()).getValues()) if (!replacement.isNull()) { for (ObjectMapValue<String> replacement : template.getBuildOptions().getMap("Replacements", new ObjectMap<>()).getValues()) if (!replacement.isNull()) {
replacements.put(replacement.getHandle().toLowerCase().replace('-', '_').replace(' ', '_'), replacement.asString()); replacements.put(replacement.getHandle().toLowerCase().replace('-', '_').replace(' ', '_'), replacement.asString());
} }
@ -259,12 +265,8 @@ public class InternalSubCreator extends SubCreator {
ReplacementScanner replacements = new ReplacementScanner(this.replacements); ReplacementScanner replacements = new ReplacementScanner(this.replacements);
if (config != null) { if (config != null) {
try { try {
if (template.getBuildOptions().getBoolean("Install-Client", true)) generateClient(dir, template.getType(), name); if (install != Boolean.FALSE) generateClient(dir, template.getType(), name);
replacements.replace(dir, replace.toArray(new String[0]));
LinkedList<String> masks = new LinkedList<>();
masks.add("/server.properties");
masks.addAll(template.getBuildOptions().getStringList("Replace", Collections.emptyList()));
replacements.replace(dir, masks.toArray(new String[0]));
} catch (Exception e) { } catch (Exception e) {
config = null; config = null;
e.printStackTrace(); e.printStackTrace();

View File

@ -270,7 +270,9 @@ public class SubCreatorImpl {
private final UUID address; private final UUID address;
private final UUID tracker; private final UUID tracker;
private final SubLoggerImpl log; private final SubLoggerImpl log;
private final LinkedList<String> replace;
private final HashMap<String, String> replacements; private final HashMap<String, String> replacements;
private Boolean install;
private Process process; private Process process;
private CreatorTask(UUID player, String name, ServerTemplate template, Version version, int port, Boolean mode, UUID address, UUID tracker) { private CreatorTask(UUID player, String name, ServerTemplate template, Version version, int port, Boolean mode, UUID address, UUID tracker) {
@ -285,6 +287,7 @@ public class SubCreatorImpl {
this.mode = mode; this.mode = mode;
this.log = new SubLoggerImpl(null, this, name + File.separator + ((update == null)?"Creator":"Updater"), address, new Container<Boolean>(true), null); this.log = new SubLoggerImpl(null, this, name + File.separator + ((update == null)?"Creator":"Updater"), address, new Container<Boolean>(true), null);
this.replacements = new HashMap<String, String>(); this.replacements = new HashMap<String, String>();
(this.replace = new LinkedList<String>()).add("/server.properties");
this.address = address; this.address = address;
this.tracker = tracker; this.tracker = tracker;
@ -330,6 +333,8 @@ public class SubCreatorImpl {
log.logger.info.println("Loading" + ((template.isDynamic())?" Dynamic":"") + " Template: " + template.getDisplayName()); log.logger.info.println("Loading" + ((template.isDynamic())?" Dynamic":"") + " Template: " + template.getDisplayName());
updateDirectory(template.getDirectory(), dir, template.getBuildOptions().getBoolean("Update-Files", false)); updateDirectory(template.getDirectory(), dir, template.getBuildOptions().getBoolean("Update-Files", false));
install = template.getBuildOptions().getBoolean("Install-Client", install);
replace.addAll(template.getBuildOptions().getStringList("Replace", Collections.emptyList()));
for (ObjectMapValue<String> replacement : template.getBuildOptions().getMap("Replacements", new ObjectMap<>()).getValues()) if (!replacement.isNull()) { for (ObjectMapValue<String> replacement : template.getBuildOptions().getMap("Replacements", new ObjectMap<>()).getValues()) if (!replacement.isNull()) {
replacements.put(replacement.getHandle().toLowerCase().replace('-', '_').replace(' ', '_'), replacement.asString()); replacements.put(replacement.getHandle().toLowerCase().replace('-', '_').replace(' ', '_'), replacement.asString());
} }
@ -455,12 +460,8 @@ public class SubCreatorImpl {
ReplacementScanner replacements = new ReplacementScanner(this.replacements); ReplacementScanner replacements = new ReplacementScanner(this.replacements);
if (config != null) { if (config != null) {
try { try {
if (template.getBuildOptions().getBoolean("Install-Client", true)) generateClient(dir, template.getType(), name); if (install != Boolean.FALSE) generateClient(dir, template.getType(), name);
replacements.replace(dir, replace.toArray(new String[0]));
LinkedList<String> masks = new LinkedList<>();
masks.add("/server.properties");
masks.addAll(template.getBuildOptions().getStringList("Replace", Collections.emptyList()));
replacements.replace(dir, masks.toArray(new String[0]));
} catch (Exception e) { } catch (Exception e) {
config = null; config = null;
e.printStackTrace(); e.printStackTrace();