From 67b80bb8e8502a9653243873c05287ce76880aa4 Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Fri, 5 Jun 2020 13:59:03 +0200 Subject: [PATCH] Fix /plot setup back --- .../core/setup/CommonSetupSteps.java | 8 ++---- .../core/setup/SettingsNodeStep.java | 10 +++++--- .../core/setup/SettingsNodesWrapper.java | 25 ++----------------- 3 files changed, 11 insertions(+), 32 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/setup/CommonSetupSteps.java b/Core/src/main/java/com/plotsquared/core/setup/CommonSetupSteps.java index f299f0b42..39dc2dd1b 100644 --- a/Core/src/main/java/com/plotsquared/core/setup/CommonSetupSteps.java +++ b/Core/src/main/java/com/plotsquared/core/setup/CommonSetupSteps.java @@ -76,11 +76,7 @@ public enum CommonSetupSteps implements SetupStep { // TODO reimplement SetupUtils.generators.get(object.plotManager).getPlotGenerator() // .processSetup(process); } - if (!builder.settingsNodesWrapper().hasStep()) { - // object.setup_index = 0; TODO what did that do? - return builder.settingsNodesWrapper().getAfterwards(); // skip - } - return builder.settingsNodesWrapper().first(); + return builder.settingsNodesWrapper().getFirstStep(); } else { if (gen.isFull()) { builder.plotManager(builder.generatorName()); @@ -179,7 +175,7 @@ public enum CommonSetupSteps implements SetupStep { builder.settingsNodesWrapper(CommonSetupSteps.wrap(builder.plotManager())); } SettingsNodesWrapper wrapper = builder.settingsNodesWrapper(); - return wrapper.hasStep() ? wrapper.first() : wrapper.getAfterwards(); + return wrapper.getFirstStep(); } @Nullable @Override public String getDefaultValue() { diff --git a/Core/src/main/java/com/plotsquared/core/setup/SettingsNodeStep.java b/Core/src/main/java/com/plotsquared/core/setup/SettingsNodeStep.java index e5f3da3bd..ec384884e 100644 --- a/Core/src/main/java/com/plotsquared/core/setup/SettingsNodeStep.java +++ b/Core/src/main/java/com/plotsquared/core/setup/SettingsNodeStep.java @@ -17,19 +17,23 @@ import java.util.Collections; public class SettingsNodeStep implements SetupStep { @Getter private final ConfigurationNode configurationNode; @Getter private final int id; - private final SettingsNodesWrapper wrapper; + private final SetupStep next; public SettingsNodeStep(ConfigurationNode configurationNode, int id, SettingsNodesWrapper wrapper) { this.configurationNode = configurationNode; 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) { if (this.configurationNode.isValid(argument)) { this.configurationNode.setValue(argument); } - return this.wrapper.hasNext(this.id) ? wrapper.next(this.id) : wrapper.getAfterwards(); + return this.next; } @NotNull @Override public Collection getSuggestions() { diff --git a/Core/src/main/java/com/plotsquared/core/setup/SettingsNodesWrapper.java b/Core/src/main/java/com/plotsquared/core/setup/SettingsNodesWrapper.java index 2c0fd0b0f..cdcb74bce 100644 --- a/Core/src/main/java/com/plotsquared/core/setup/SettingsNodesWrapper.java +++ b/Core/src/main/java/com/plotsquared/core/setup/SettingsNodesWrapper.java @@ -12,28 +12,7 @@ public class SettingsNodesWrapper { this.afterwards = afterwards; } - - public SettingsNodeStep next(int current) { - 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; + public SetupStep getFirstStep() { + return this.settingsNodes.length == 0 ? this.afterwards : new SettingsNodeStep(this.settingsNodes[0], 0, this); } }