Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
718247a3d4
Commit
71e51654ce
@ -30,17 +30,18 @@ import de.steamwar.bausystem.features.world.WorldEditListener;
|
|||||||
import de.steamwar.bausystem.linkage.LinkageType;
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
import de.steamwar.bausystem.linkage.Linked;
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.bausystem.region.Color;
|
import de.steamwar.bausystem.region.Color;
|
||||||
|
import de.steamwar.bausystem.shared.Pair;
|
||||||
import de.steamwar.bausystem.utils.WorldEditUtils;
|
import de.steamwar.bausystem.utils.WorldEditUtils;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
|
import de.steamwar.command.TypeMapper;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
import java.util.stream.Collectors;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Linked(LinkageType.COMMAND)
|
@Linked(LinkageType.COMMAND)
|
||||||
public class ColorReplaceCommand extends SWCommand {
|
public class ColorReplaceCommand extends SWCommand {
|
||||||
@ -62,8 +63,8 @@ public class ColorReplaceCommand extends SWCommand {
|
|||||||
|
|
||||||
@Register(description = "COLORREPLACE_HELP")
|
@Register(description = "COLORREPLACE_HELP")
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public void genericCommand(Player player, Color from, Color to) {
|
public void genericCommand(Player player, Pair<Integer, Color> from, Color to) {
|
||||||
if (from == to) {
|
if (from.getValue() == to) {
|
||||||
BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(0)}));
|
BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(0)}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -72,15 +73,51 @@ public class ColorReplaceCommand extends SWCommand {
|
|||||||
|
|
||||||
Map<String, String> replacements = new HashMap<>();
|
Map<String, String> replacements = new HashMap<>();
|
||||||
for (String type : types) {
|
for (String type : types) {
|
||||||
replacements.put("minecraft:" + from.name().toLowerCase() + "_" + type.toLowerCase(), "minecraft:" + to.name().toLowerCase() + "_" + type.toLowerCase());
|
replacements.put("minecraft:" + from.getValue().name().toLowerCase() + "_" + type.toLowerCase(), "minecraft:" + to.name().toLowerCase() + "_" + type.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
Region region = WorldEditUtils.getRegion(player);
|
Region region = WorldEditUtils.getRegion(player);
|
||||||
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(BukkitAdapter.adapt(world), -1, BukkitAdapter.adapt(player));
|
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(BukkitAdapter.adapt(world), -1, BukkitAdapter.adapt(player));
|
||||||
|
|
||||||
SpecialReplace specialReplace = new SpecialReplace(editSession, replacements);
|
SpecialReplace specialReplace = new SpecialReplace(editSession, replacements, from.getKey());
|
||||||
int affected = editSession.replaceBlocks(region, specialReplace, specialReplace);
|
int affected = editSession.replaceBlocks(region, specialReplace, specialReplace);
|
||||||
editSession.flushSession();
|
editSession.flushSession();
|
||||||
BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(affected)}));
|
BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(affected)}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ClassMapper(value = Pair.class, local = true)
|
||||||
|
public TypeMapper<Pair<Integer, Color>> typeMapper() {
|
||||||
|
return new TypeMapper<Pair<Integer, Color>>() {
|
||||||
|
@Override
|
||||||
|
public Pair<Integer, Color> map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||||
|
if (s.contains("%")) {
|
||||||
|
String[] split = s.split("%");
|
||||||
|
if (split.length != 2) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Color color = Color.valueOf(split[1].toUpperCase());
|
||||||
|
try {
|
||||||
|
return new Pair<>(Integer.parseInt(split[0]), color);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Pair<>(100, Color.valueOf(s.toUpperCase()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
|
||||||
|
if (s.matches("[0-9].*")) {
|
||||||
|
if (s.contains("%")) {
|
||||||
|
String sub = s.substring(0, s.indexOf("%") + 1);
|
||||||
|
return Arrays.stream(Color.values()).map(Color::name).map(t -> sub + t.toLowerCase()).collect(Collectors.toSet());
|
||||||
|
} else {
|
||||||
|
return Arrays.asList(s);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Arrays.stream(Color.values()).map(Color::name).map(String::toLowerCase).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,27 +33,32 @@ import org.bukkit.block.data.BlockData;
|
|||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
public class SpecialReplace implements Mask, Pattern {
|
public class SpecialReplace implements Mask, Pattern {
|
||||||
|
|
||||||
private EditSession editSession;
|
private EditSession editSession;
|
||||||
private Map<String, String> replacements;
|
private Map<String, String> replacements;
|
||||||
|
private Random random = new Random();
|
||||||
|
private int percentage;
|
||||||
private BiConsumer<BlockData, BlockData> blockDataMerger;
|
private BiConsumer<BlockData, BlockData> blockDataMerger;
|
||||||
|
|
||||||
public SpecialReplace(EditSession editSession, Map<String, String> replacements) {
|
public SpecialReplace(EditSession editSession, Map<String, String> replacements, int percentage) {
|
||||||
this(editSession, replacements, (_1, _2) -> {
|
this(editSession, replacements, percentage, (_1, _2) -> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpecialReplace(EditSession editSession, Map<String, String> replacements, BiConsumer<BlockData, BlockData> blockDataMerger) {
|
public SpecialReplace(EditSession editSession, Map<String, String> replacements, int percentage, BiConsumer<BlockData, BlockData> blockDataMerger) {
|
||||||
this.editSession = editSession;
|
this.editSession = editSession;
|
||||||
this.replacements = replacements;
|
this.replacements = replacements;
|
||||||
|
this.percentage = percentage;
|
||||||
this.blockDataMerger = blockDataMerger;
|
this.blockDataMerger = blockDataMerger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(BlockVector3 blockVector3) {
|
public boolean test(BlockVector3 blockVector3) {
|
||||||
|
if (random.nextInt(100) > percentage) return false;
|
||||||
return replacements.containsKey(editSession.getFullBlock(blockVector3).getBlockType().getId());
|
return replacements.containsKey(editSession.getFullBlock(blockVector3).getBlockType().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,8 +30,10 @@ import de.steamwar.bausystem.features.world.WorldEditListener;
|
|||||||
import de.steamwar.bausystem.linkage.LinkageType;
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
import de.steamwar.bausystem.linkage.Linked;
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.bausystem.linkage.MinVersion;
|
import de.steamwar.bausystem.linkage.MinVersion;
|
||||||
|
import de.steamwar.bausystem.shared.Pair;
|
||||||
import de.steamwar.bausystem.utils.WorldEditUtils;
|
import de.steamwar.bausystem.utils.WorldEditUtils;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
|
import de.steamwar.command.TypeMapper;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -39,10 +41,14 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.data.type.Fence;
|
import org.bukkit.block.data.type.Fence;
|
||||||
import org.bukkit.block.data.type.Wall;
|
import org.bukkit.block.data.type.Wall;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.bukkit.Material.*;
|
import static org.bukkit.Material.*;
|
||||||
|
|
||||||
@ -61,8 +67,8 @@ public class TypeReplaceCommand extends SWCommand {
|
|||||||
|
|
||||||
@Register(description = "TYPEREPLACE_HELP")
|
@Register(description = "TYPEREPLACE_HELP")
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public void genericCommand(Player player, Type from, Type to) {
|
public void genericCommand(Player player, Pair<Integer, Type> from, Type to) {
|
||||||
if (from == to) {
|
if (from.getValue() == to) {
|
||||||
BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(0)}));
|
BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(0)}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -72,7 +78,7 @@ public class TypeReplaceCommand extends SWCommand {
|
|||||||
Region region = WorldEditUtils.getRegion(player);
|
Region region = WorldEditUtils.getRegion(player);
|
||||||
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(BukkitAdapter.adapt(world), -1, BukkitAdapter.adapt(player));
|
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(BukkitAdapter.adapt(world), -1, BukkitAdapter.adapt(player));
|
||||||
|
|
||||||
SpecialReplace specialReplace = new SpecialReplace(editSession, to.replacements(from), (oldBlockData, newBlockData) -> {
|
SpecialReplace specialReplace = new SpecialReplace(editSession, to.replacements(from.getValue()), from.getKey(), (oldBlockData, newBlockData) -> {
|
||||||
if (newBlockData instanceof Fence && oldBlockData instanceof Wall) {
|
if (newBlockData instanceof Fence && oldBlockData instanceof Wall) {
|
||||||
Wall wall = (Wall) oldBlockData;
|
Wall wall = (Wall) oldBlockData;
|
||||||
Fence fence = (Fence) newBlockData;
|
Fence fence = (Fence) newBlockData;
|
||||||
@ -97,6 +103,42 @@ public class TypeReplaceCommand extends SWCommand {
|
|||||||
BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(affected)}));
|
BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(affected)}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ClassMapper(value = Pair.class, local = true)
|
||||||
|
public TypeMapper<Pair<Integer, Type>> typeMapper() {
|
||||||
|
return new TypeMapper<Pair<Integer, Type>>() {
|
||||||
|
@Override
|
||||||
|
public Pair<Integer, Type> map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||||
|
if (s.contains("%")) {
|
||||||
|
String[] split = s.split("%");
|
||||||
|
if (split.length != 2) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Type type = Type.valueOf(split[1].toUpperCase());
|
||||||
|
try {
|
||||||
|
return new Pair<>(Integer.parseInt(split[0]), type);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Pair<>(100, Type.valueOf(s.toUpperCase()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
|
||||||
|
if (s.matches("[0-9].*")) {
|
||||||
|
if (s.contains("%")) {
|
||||||
|
String sub = s.substring(0, s.indexOf("%") + 1);
|
||||||
|
return Arrays.stream(Type.values()).map(Type::name).map(t -> sub + t.toLowerCase()).collect(Collectors.toSet());
|
||||||
|
} else {
|
||||||
|
return Arrays.asList(s);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Arrays.stream(Type.values()).map(Type::name).map(String::toLowerCase).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
private enum Type {
|
private enum Type {
|
||||||
IRON(IRON_BLOCK, null, null, null, null, null, null, IRON_BARS, IRON_DOOR, IRON_TRAPDOOR, null, HEAVY_WEIGHTED_PRESSURE_PLATE, null, null, null, null),
|
IRON(IRON_BLOCK, null, null, null, null, null, null, IRON_BARS, IRON_DOOR, IRON_TRAPDOOR, null, HEAVY_WEIGHTED_PRESSURE_PLATE, null, null, null, null),
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren