Fix /plot setup back

This commit is contained in:
Hannes Greule 2020-06-05 13:59:03 +02:00 committed by Alexander Söderberg
parent ae1427b189
commit 67b80bb8e8
3 changed files with 11 additions and 32 deletions

View File

@ -76,11 +76,7 @@ public enum CommonSetupSteps implements SetupStep {
// TODO reimplement SetupUtils.generators.get(object.plotManager).getPlotGenerator() // TODO reimplement SetupUtils.generators.get(object.plotManager).getPlotGenerator()
// .processSetup(process); // .processSetup(process);
} }
if (!builder.settingsNodesWrapper().hasStep()) { return builder.settingsNodesWrapper().getFirstStep();
// object.setup_index = 0; TODO what did that do?
return builder.settingsNodesWrapper().getAfterwards(); // skip
}
return builder.settingsNodesWrapper().first();
} else { } else {
if (gen.isFull()) { if (gen.isFull()) {
builder.plotManager(builder.generatorName()); builder.plotManager(builder.generatorName());
@ -179,7 +175,7 @@ public enum CommonSetupSteps implements SetupStep {
builder.settingsNodesWrapper(CommonSetupSteps.wrap(builder.plotManager())); builder.settingsNodesWrapper(CommonSetupSteps.wrap(builder.plotManager()));
} }
SettingsNodesWrapper wrapper = builder.settingsNodesWrapper(); SettingsNodesWrapper wrapper = builder.settingsNodesWrapper();
return wrapper.hasStep() ? wrapper.first() : wrapper.getAfterwards(); return wrapper.getFirstStep();
} }
@Nullable @Override public String getDefaultValue() { @Nullable @Override public String getDefaultValue() {

View File

@ -17,19 +17,23 @@ import java.util.Collections;
public class SettingsNodeStep implements SetupStep { public class SettingsNodeStep implements SetupStep {
@Getter private final ConfigurationNode configurationNode; @Getter private final ConfigurationNode configurationNode;
@Getter private final int id; @Getter private final int id;
private final SettingsNodesWrapper wrapper; private final SetupStep next;
public SettingsNodeStep(ConfigurationNode configurationNode, int id, SettingsNodesWrapper wrapper) { public SettingsNodeStep(ConfigurationNode configurationNode, int id, SettingsNodesWrapper wrapper) {
this.configurationNode = configurationNode; this.configurationNode = configurationNode;
this.id = id; this.id = id;
this.wrapper = wrapper; if (wrapper.getSettingsNodes().length > id + 1) {
this.next = new SettingsNodeStep(wrapper.getSettingsNodes()[id + 1], id + 1, wrapper);
} else {
this.next = wrapper.getAfterwards();
}
} }
@Override public SetupStep handleInput(PlotPlayer<?> plotPlayer, PlotAreaBuilder builder, String argument) { @Override public SetupStep handleInput(PlotPlayer<?> plotPlayer, PlotAreaBuilder builder, String argument) {
if (this.configurationNode.isValid(argument)) { if (this.configurationNode.isValid(argument)) {
this.configurationNode.setValue(argument); this.configurationNode.setValue(argument);
} }
return this.wrapper.hasNext(this.id) ? wrapper.next(this.id) : wrapper.getAfterwards(); return this.next;
} }
@NotNull @Override public Collection<String> getSuggestions() { @NotNull @Override public Collection<String> getSuggestions() {

View File

@ -12,28 +12,7 @@ public class SettingsNodesWrapper {
this.afterwards = afterwards; this.afterwards = afterwards;
} }
public SetupStep getFirstStep() {
public SettingsNodeStep next(int current) { return this.settingsNodes.length == 0 ? this.afterwards : new SettingsNodeStep(this.settingsNodes[0], 0, this);
if (this.settingsNodes.length <= current + 1) {
throw new IllegalStateException("No step left");
} else {
return new SettingsNodeStep(this.settingsNodes[current + 1], current + 1, this);
}
}
public SettingsNodeStep first() {
if (this.settingsNodes.length == 0) {
throw new IllegalStateException("No step left");
} else {
return new SettingsNodeStep(this.settingsNodes[0], 0, this);
}
}
public boolean hasNext(int current) {
return current + 1 < this.settingsNodes.length;
}
public boolean hasStep() {
return this.settingsNodes.length > 0;
} }
} }