TestBlockPaste-Without-Water #146
@ -21,6 +21,9 @@ package de.steamwar.bausystem.features.region;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
|
import de.steamwar.bausystem.features.tracer.TraceCommand;
|
||||||
|
import de.steamwar.bausystem.features.tracer.show.ShowModeParameter;
|
||||||
|
import de.steamwar.bausystem.features.tracer.show.ShowModeParameterType;
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
import de.steamwar.bausystem.region.RegionUtils;
|
import de.steamwar.bausystem.region.RegionUtils;
|
||||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||||
@ -29,16 +32,18 @@ import de.steamwar.command.*;
|
|||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import de.steamwar.sql.SchematicNode;
|
import de.steamwar.sql.SchematicNode;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
|
import lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.List;
|
import java.util.function.Consumer;
|
||||||
import java.util.Map;
|
import java.util.function.Supplier;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
public class TestblockCommand extends SWCommand {
|
public class TestblockCommand extends SWCommand {
|
||||||
@ -86,7 +91,7 @@ public class TestblockCommand extends SWCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
region.reset(node, RegionType.TESTBLOCK, regionExtensionType,true);
|
region.reset(node, RegionType.TESTBLOCK, regionExtensionType,false);
|
||||||
RegionUtils.message(region, "REGION_TB_DONE");
|
RegionUtils.message(region, "REGION_TB_DONE");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
BauSystem.MESSAGE.send("REGION_TB_ERROR", p);
|
BauSystem.MESSAGE.send("REGION_TB_ERROR", p);
|
||||||
@ -94,18 +99,47 @@ public class TestblockCommand extends SWCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ClassMapper(value = RegionExtensionType.class, local = true)
|
@ClassMapper(value = TestblockParamaterType.class, local = true)
|
||||||
private TypeMapper<RegionExtensionType> regionExtensionTypeTypeMapper() {
|
private TypeMapper<TestblockParamaterType> testblockParamaterTypeMapper() {
|
||||||
Map<String, RegionExtensionType> showModeParameterTypesMap = new HashMap<>();
|
Map<TestblockParamaterType, List<String>> testblockParamaterTypeListMap = new EnumMap<>(TestblockParamaterType.class);
|
||||||
showModeParameterTypesMap.put("-normal", RegionExtensionType.NORMAL);
|
for (TestblockParamaterType value : TestblockParamaterType.values()) {
|
||||||
showModeParameterTypesMap.put("-n", RegionExtensionType.NORMAL);
|
testblockParamaterTypeListMap.put(value, value.getTabCompletes());
|
||||||
showModeParameterTypesMap.put("-extension", RegionExtensionType.EXTENSION);
|
}
|
||||||
showModeParameterTypesMap.put("-e", RegionExtensionType.EXTENSION);
|
|
||||||
showModeParameterTypesMap.put("-t", null);
|
|
||||||
showModeParameterTypesMap.put("-tnt", null);
|
|
||||||
|
|
||||||
List<String> tabCompletes = new ArrayList<>(showModeParameterTypesMap.keySet());
|
Map<String, TestblockParamaterType> testblockParameterTypesMap = new HashMap<>();
|
||||||
return SWCommandUtils.createMapper(s -> showModeParameterTypesMap.getOrDefault(s, null), s -> tabCompletes);
|
testblockParamaterTypeListMap.forEach((k, v) -> v.forEach(s -> testblockParameterTypesMap.put(s, k)));
|
||||||
|
|
||||||
|
return new TypeMapper<TestblockParamaterType>() {
|
||||||
|
@Override
|
||||||
|
public TestblockParamaterType map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
|
||||||
|
return testblockParameterTypesMap.get(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) {
|
||||||
|
Set<TestblockParamaterType> testblockParameterTypeSet = new HashSet<>();
|
||||||
|
previousArguments.getAll(TestblockParamaterType.class).forEach(showModeType -> {
|
||||||
|
testblockParameterTypeSet.addAll(Arrays.asList(showModeType.removed.get()));
|
||||||
|
});
|
||||||
|
Arrays.stream(previousArguments.userArgs).map(testblockParameterTypesMap::get).forEach(testblockParameterTypeSet::add);
|
||||||
|
testblockParameterTypeSet.remove(null);
|
||||||
|
|
||||||
|
Set<TestblockParamaterType> removed = testblockParameterTypeSet.stream()
|
||||||
|
.map(TestblockParamaterType::getRemoved)
|
||||||
|
.map(Supplier::get)
|
||||||
|
.flatMap(Arrays::stream)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
List<String> tabCompletes = new ArrayList<>();
|
||||||
|
for (Map.Entry<TestblockParamaterType, List<String>> entry : testblockParamaterTypeListMap.entrySet()) {
|
||||||
|
if (removed.contains(entry.getKey()) || testblockParameterTypeSet.contains(entry.getKey())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
tabCompletes.addAll(entry.getValue());
|
||||||
|
}
|
||||||
|
return tabCompletes;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ClassValidator(value = Player.class, local = true)
|
@ClassValidator(value = Player.class, local = true)
|
||||||
@ -144,4 +178,61 @@ public class TestblockCommand extends SWCommand {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum TestblockParamaterType {
|
||||||
|
NORMAL(TestblockParameter::enableWater, Arrays.asList("-n","-normal"), "EXTENSION"),
|
||||||
|
EXTENSION(TestblockParameter::enableExtension, Arrays.asList("-e", "-extension"), "NORMAL"),
|
||||||
|
TNT(TestblockParameter::enableTNT, Arrays.asList("-t", "-interpolate-x", "-tnt")),
|
||||||
|
WATER(TestblockParameter::enableWater, Arrays.asList("-w", "-water"));
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final Consumer<TestblockParameter> testblockParameterConsumer;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private List<String> tabCompletes;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final Supplier<TestblockParamaterType[]> removed;
|
||||||
|
private AtomicReference<TestblockParamaterType[]> cached = new AtomicReference<>();
|
||||||
|
|
||||||
|
TestblockParamaterType(Consumer<TestblockParameter> testblockParameterConsumer, List<String> tabCompletes, String... removed) {
|
||||||
|
this.testblockParameterConsumer = testblockParameterConsumer;
|
||||||
|
this.tabCompletes = tabCompletes;
|
||||||
|
this.removed = () -> {
|
||||||
|
if (cached.get() == null) {
|
||||||
|
TestblockParamaterType[] showModeParameterTypes = new TestblockParamaterType[removed.length];
|
||||||
|
for (int i = 0; i < removed.length; i++) {
|
||||||
|
showModeParameterTypes[i] = TestblockParamaterType.valueOf(removed[i]);
|
||||||
|
}
|
||||||
|
cached.set(showModeParameterTypes);
|
||||||
|
return showModeParameterTypes;
|
||||||
|
}
|
||||||
|
return cached.get();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private class TestblockParameter {
|
||||||
|
private boolean water = false;
|
||||||
|
private boolean tnt = false;
|
||||||
|
private boolean extension = false;
|
||||||
|
private boolean normal = false;
|
||||||
|
|
||||||
|
public void enableWater() {
|
||||||
|
this.water = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enableTNT() {
|
||||||
|
this.tnt = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enableExtension() {
|
||||||
|
this.extension = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enableNormal() {
|
||||||
|
this.normal = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren