Updated a class, minor command tweaks, and formatting

This commit is contained in:
MattBDev 2019-07-25 14:58:59 -04:00
parent ff5860113d
commit 3a3efb8117
14 changed files with 1508 additions and 1233 deletions

View File

@ -110,7 +110,7 @@ public class AnvilCommands {
@Command( @Command(
name = "replaceall", name = "replaceall",
aliases = {"rea", "repall"}, aliases = {"rea", "repall"},
desc = "Replace all blocks in the selection with another", desc = "Replace all blocks in the selection with another"
) )
@CommandPermissions("worldedit.anvil.replaceall") @CommandPermissions("worldedit.anvil.replaceall")
public void replaceAll(Player player, String folder, public void replaceAll(Player player, String folder,
@ -221,8 +221,7 @@ public class AnvilCommands {
aliases = {"deloldreg" }, aliases = {"deloldreg" },
desc = "Delete regions which haven't been accessed in a certain amount of time", desc = "Delete regions which haven't been accessed in a certain amount of time",
descFooter = "You can use seconds (s), minutes (m), hours (h), days (d), weeks (w), years (y)\n" + descFooter = "You can use seconds (s), minutes (m), hours (h), days (d), weeks (w), years (y)\n" +
"(months are not a unit of time)\n" + "(months are not a unit of time) E.g. 8h5m12s\n"
"E.g. 8h5m12s\n"
) )
@CommandPermissions("worldedit.anvil.deletealloldregions") @CommandPermissions("worldedit.anvil.deletealloldregions")
public void deleteAllOldRegions(Player player, String folder, String time) throws WorldEditException { public void deleteAllOldRegions(Player player, String folder, String time) throws WorldEditException {
@ -300,7 +299,7 @@ public class AnvilCommands {
desc = "Replace all blocks in the selection with another" desc = "Replace all blocks in the selection with another"
) )
@CommandPermissions("worldedit.anvil.replaceall") @CommandPermissions("worldedit.anvil.replaceall")
public void replaceAllPattern(Player player, String folder, @Arg(name = "from", desc = "String", def = "") String from, final Pattern to, @Switch(name = 'd', desc = "TODO") boolean useData, @Switch(name = 'm', desc = "TODO") boolean useMap) throws WorldEditException { public void replaceAllPattern(Player player, String folder, @Arg(name = "from", desc = "String", def = "") String from, Pattern to, @Switch(name = 'd', desc = "TODO") boolean useData, @Switch(name = 'm', desc = "TODO") boolean useMap) throws WorldEditException {
// MCAFilterCounter filter; TODO NOT IMPLEMENTED // MCAFilterCounter filter; TODO NOT IMPLEMENTED
// if (useMap) { // if (useMap) {
// if (to instanceof RandomPattern) { // if (to instanceof RandomPattern) {

View File

@ -26,15 +26,15 @@ public class VisualExtent extends AbstractDelegateExtent {
this.queue = queue; this.queue = queue;
} }
public VisualChunk getChunk(int cx, int cz) {
return chunks.get(MathMan.pairInt(cx, cz));
}
@Override @Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
return setBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block); return setBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block);
} }
public VisualChunk getChunk(int cx, int cz) {
return chunks.get(MathMan.pairInt(cx, cz));
}
@Override @Override
public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException { public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException {
BlockStateHolder previous = super.getBlock(x, y, z); BlockStateHolder previous = super.getBlock(x, y, z);

View File

@ -16,8 +16,7 @@ public class VisualQueue extends SingleThreadIntervalQueue<FawePlayer> {
@Override @Override
public void operate(FawePlayer fp) { public void operate(FawePlayer fp) {
LocalSession session = WorldEdit.getInstance().getSessionManager() LocalSession session = WorldEdit.getInstance().getSessionManager().get(fp.toWorldEditPlayer());
.get(fp.toWorldEditPlayer());
Player player = fp.getPlayer(); Player player = fp.getPlayer();
Tool tool = session.getTool(player); Tool tool = session.getTool(player);
if (tool instanceof BrushTool) { if (tool instanceof BrushTool) {

View File

@ -6,7 +6,8 @@ import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.AbstractPattern;
public abstract class AbstractExtentPattern extends AbstractPattern { public abstract class AbstractExtentPattern extends AbstractPattern {
private transient final Extent extent;
private final transient Extent extent;
public AbstractExtentPattern(Extent extent) { public AbstractExtentPattern(Extent extent) {
checkNotNull(extent); checkNotNull(extent);

View File

@ -18,7 +18,6 @@ import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.registry.BiomeRegistry; import com.sk89q.worldedit.world.registry.BiomeRegistry;
import com.sk89q.worldedit.world.registry.LegacyMapper; import com.sk89q.worldedit.world.registry.LegacyMapper;
import java.util.Collection; import java.util.Collection;
// TODO FIXME // TODO FIXME

View File

@ -24,8 +24,6 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.SpongeSchematicWriter; import com.sk89q.worldedit.extent.clipboard.io.SpongeSchematicWriter;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import net.jpountz.lz4.LZ4BlockInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -36,6 +34,7 @@ import java.net.URL;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import net.jpountz.lz4.LZ4BlockInputStream;
public class FaweSchematicHandler extends SchematicHandler { public class FaweSchematicHandler extends SchematicHandler {
@Override @Override

View File

@ -1,39 +1,8 @@
package com.boydti.fawe.regions.general.plot; package com.boydti.fawe.regions.general.plot;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.example.NullFaweChunk;
import com.boydti.fawe.jnbt.anvil.MCAChunk;
import com.boydti.fawe.jnbt.anvil.MCAQueue;
import com.boydti.fawe.jnbt.anvil.MCAWriter;
import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.util.SetQueue;
import com.github.intellectualsites.plotsquared.commands.Command;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.commands.CommandCategory; import com.github.intellectualsites.plotsquared.plot.commands.CommandCategory;
import com.github.intellectualsites.plotsquared.plot.commands.MainCommand;
import com.github.intellectualsites.plotsquared.plot.commands.RequiredType; import com.github.intellectualsites.plotsquared.plot.commands.RequiredType;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
import com.github.intellectualsites.plotsquared.plot.database.SQLManager;
import com.github.intellectualsites.plotsquared.plot.generator.HybridPlotWorld;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3;
import com.github.intellectualsites.plotsquared.plot.object.SetupObject;
import com.github.intellectualsites.plotsquared.plot.util.SetupUtils;
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
@CommandDeclaration( @CommandDeclaration(
command = "moveto512", command = "moveto512",

View File

@ -1,16 +1,14 @@
package com.boydti.fawe.regions.general.plot; package com.boydti.fawe.regions.general.plot;
import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.regions.general.CuboidRegionFilter; import com.boydti.fawe.regions.general.CuboidRegionFilter;
import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector2;
import java.util.ArrayList; import java.util.ArrayList;
import static com.google.common.base.Preconditions.checkNotNull;
public class PlotRegionFilter extends CuboidRegionFilter { public class PlotRegionFilter extends CuboidRegionFilter {
private final PlotArea area; private final PlotArea area;

View File

@ -27,10 +27,8 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.biome.Biomes; import com.sk89q.worldedit.world.biome.Biomes;
import com.sk89q.worldedit.world.registry.BiomeRegistry; import com.sk89q.worldedit.world.registry.BiomeRegistry;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@CommandDeclaration( @CommandDeclaration(

View File

@ -13,6 +13,7 @@ import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.database.DBFunc; import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.generator.HybridPlotManager; import com.github.intellectualsites.plotsquared.plot.generator.HybridPlotManager;
import com.github.intellectualsites.plotsquared.plot.listener.WEManager;
import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
@ -22,7 +23,6 @@ import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler;
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue;
import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider; import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider;
import com.github.intellectualsites.plotsquared.plot.listener.WEManager;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;

View File

@ -17,8 +17,6 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntArraySet; import it.unimi.dsi.fastutil.ints.IntArraySet;
import it.unimi.dsi.fastutil.longs.LongArrayList; import it.unimi.dsi.fastutil.longs.LongArrayList;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -41,50 +39,11 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import javax.imageio.ImageIO;
// TODO FIXME // TODO FIXME
public class TextureUtil implements TextureHolder { public class TextureUtil implements TextureHolder {
public static TextureUtil fromClipboard(Clipboard clipboard) throws FileNotFoundException {
boolean[] ids = new boolean[BlockTypes.size()];
for (BlockVector3 pt : clipboard.getRegion()) {
ids[clipboard.getBlock(pt).getInternalBlockTypeId()] = true;
}
HashSet<BlockType> blocks = new HashSet<>();
for (int typeId = 0; typeId < ids.length; typeId++) {
if (ids[typeId]) {
blocks.add(BlockTypes.get(typeId));
}
}
return fromBlocks(blocks);
}
public static TextureUtil fromBlocks(Set<BlockType> blocks) throws FileNotFoundException {
return new FilteredTextureUtil(Fawe.get().getTextureUtil(), blocks);
}
public static TextureUtil fromMask(Mask mask) throws FileNotFoundException {
HashSet<BlockType> blocks = new HashSet<>();
SingleFilterBlock extent = new SingleFilterBlock();
new MaskTraverser(mask).reset(extent);
TextureUtil tu = Fawe.get().getTextureUtil();
for (int typeId : tu.getValidBlockIds()) {
BlockType block = BlockTypes.get(typeId);
extent.init(0, 0, 0, block.getDefaultState().toBaseBlock());
if (mask.test(extent)) {
blocks.add(block);
}
}
return fromBlocks(blocks);
}
@Override public TextureUtil getTextureUtil() {
return this;
}
private final File folder;
private static final int[] FACTORS = new int[766]; private static final int[] FACTORS = new int[766];
static { static {
@ -93,23 +52,21 @@ public class TextureUtil implements TextureHolder {
} }
} }
private final File folder;
protected int[] blockColors = new int[BlockTypes.size()]; protected int[] blockColors = new int[BlockTypes.size()];
protected long[] blockDistance = new long[BlockTypes.size()]; protected long[] blockDistance = new long[BlockTypes.size()];
protected long[] distances; protected long[] distances;
protected int[] validColors; protected int[] validColors;
protected int[] validBlockIds; protected int[] validBlockIds;
protected int[] validLayerColors; protected int[] validLayerColors;
protected int[][] validLayerBlocks; protected int[][] validLayerBlocks;
protected int[] validMixBiomeColors; protected int[] validMixBiomeColors;
protected long[] validMixBiomeIds; protected long[] validMixBiomeIds;
/** /**
* https://github.com/erich666/Mineways/blob/master/Win/biomes.cpp * https://github.com/erich666/Mineways/blob/master/Win/biomes.cpp
*/ */
protected BiomeColor[] validBiomes; protected BiomeColor[] validBiomes;
private BiomeColor[] biomes = new BiomeColor[] { private BiomeColor[] biomes = new BiomeColor[]{
// ID Name Temperature, rainfall, grass, foliage colors // ID Name Temperature, rainfall, grass, foliage colors
// - note: the colors here are just placeholders, they are computed in the program // - note: the colors here are just placeholders, they are computed in the program
new BiomeColor(0, "ocean", 0.5f, 0.5f, 0x92BD59, 0x77AB2F), new BiomeColor(0, "ocean", 0.5f, 0.5f, 0x92BD59, 0x77AB2F),
@ -373,6 +330,7 @@ public class TextureUtil implements TextureHolder {
new BiomeColor(253, "Unknown Biome", 0.8f, 0.4f, 0x92BD59, 0x77AB2F), new BiomeColor(253, "Unknown Biome", 0.8f, 0.4f, 0x92BD59, 0x77AB2F),
new BiomeColor(254, "Unknown Biome", 0.8f, 0.4f, 0x92BD59, 0x77AB2F), new BiomeColor(254, "Unknown Biome", 0.8f, 0.4f, 0x92BD59, 0x77AB2F),
new BiomeColor(255, "Unknown Biome", 0.8f, 0.4f, 0x92BD59, 0x77AB2F),}; new BiomeColor(255, "Unknown Biome", 0.8f, 0.4f, 0x92BD59, 0x77AB2F),};
private BlockType[] layerBuffer = new BlockType[2];
public TextureUtil() throws FileNotFoundException { public TextureUtil() throws FileNotFoundException {
this(MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.TEXTURES)); this(MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.TEXTURES));
@ -386,6 +344,61 @@ public class TextureUtil implements TextureHolder {
} }
} }
public static TextureUtil fromClipboard(Clipboard clipboard) throws FileNotFoundException {
boolean[] ids = new boolean[BlockTypes.size()];
for (BlockVector3 pt : clipboard.getRegion()) {
ids[clipboard.getBlock(pt).getInternalBlockTypeId()] = true;
}
HashSet<BlockType> blocks = new HashSet<>();
for (int typeId = 0; typeId < ids.length; typeId++) {
if (ids[typeId]) {
blocks.add(BlockTypes.get(typeId));
}
}
return fromBlocks(blocks);
}
public static TextureUtil fromBlocks(Set<BlockType> blocks) throws FileNotFoundException {
return new FilteredTextureUtil(Fawe.get().getTextureUtil(), blocks);
}
public static TextureUtil fromMask(Mask mask) throws FileNotFoundException {
HashSet<BlockType> blocks = new HashSet<>();
SingleFilterBlock extent = new SingleFilterBlock();
new MaskTraverser(mask).reset(extent);
TextureUtil tu = Fawe.get().getTextureUtil();
for (int typeId : tu.getValidBlockIds()) {
BlockType block = BlockTypes.get(typeId);
extent.init(0, 0, 0, block.getDefaultState().toBaseBlock());
if (mask.test(extent)) {
blocks.add(block);
}
}
return fromBlocks(blocks);
}
protected static int hueDistance(int red1, int green1, int blue1, int red2, int green2,
int blue2) {
int total1 = (red1 + green1 + blue1);
int total2 = (red2 + green2 + blue2);
if (total1 == 0 || total2 == 0) {
return 0;
}
int factor1 = FACTORS[total1];
int factor2 = FACTORS[total2];
long r = (512 * (red1 * factor1 - red2 * factor2)) >> 10;
long g = (green1 * factor1 - green2 * factor2);
long b = (767 * (blue1 * factor1 - blue2 * factor2)) >> 10;
return (int) ((r * r + g * g + b * b) >> 25);
}
@Override
public TextureUtil getTextureUtil() {
return this;
}
public BlockType getNearestBlock(int color) { public BlockType getNearestBlock(int color) {
long min = Long.MAX_VALUE; long min = Long.MAX_VALUE;
int closest = 0; int closest = 0;
@ -440,8 +453,6 @@ public class TextureUtil implements TextureHolder {
return BlockTypes.get(closest); return BlockTypes.get(closest);
} }
private BlockType[] layerBuffer = new BlockType[2];
/** /**
* Returns the block combined ids as an array * Returns the block combined ids as an array
* *
@ -887,7 +898,7 @@ public class TextureUtil implements TextureHolder {
if (!hasAlpha(colorOther)) { if (!hasAlpha(colorOther)) {
int combinedOther = validBlockIds[j]; int combinedOther = validBlockIds[j];
int combinedColor = combineTransparency(color, colorOther); int combinedColor = combineTransparency(color, colorOther);
colorLayerMap.put(combinedColor, new int[] {combined, combinedOther}); colorLayerMap.put(combinedColor, new int[]{combined, combinedOther});
} }
} }
} }
@ -975,21 +986,6 @@ public class TextureUtil implements TextureHolder {
* hd); * hd);
} }
protected static int hueDistance(int red1, int green1, int blue1, int red2, int green2,
int blue2) {
int total1 = (red1 + green1 + blue1);
int total2 = (red2 + green2 + blue2);
if (total1 == 0 || total2 == 0) {
return 0;
}
int factor1 = FACTORS[total1];
int factor2 = FACTORS[total2];
long r = (512 * (red1 * factor1 - red2 * factor2)) >> 10;
long g = (green1 * factor1 - green2 * factor2);
long b = (767 * (blue1 * factor1 - blue2 * factor2)) >> 10;
return (int) ((r * r + g * g + b * b) >> 25);
}
public long getDistance(BufferedImage image, int c1) { public long getDistance(BufferedImage image, int c1) {
long totalDistSqr = 0; long totalDistSqr = 0;
int width = image.getWidth(); int width = image.getWidth();
@ -1008,7 +1004,12 @@ public class TextureUtil implements TextureHolder {
return totalDistSqr / area; return totalDistSqr / area;
} }
public int[] getValidBlockIds() {
return validBlockIds.clone();
}
public static class BiomeColor { public static class BiomeColor {
public int id; public int id;
public String name; public String name;
public float temperature; public float temperature;
@ -1028,8 +1029,4 @@ public class TextureUtil implements TextureHolder {
this.foliage = foliage; this.foliage = foliage;
} }
} }
public int[] getValidBlockIds() {
return validBlockIds.clone();
}
} }

View File

@ -45,13 +45,12 @@ import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import javax.annotation.Nullable;
import java.io.File; import java.io.File;
import javax.annotation.Nullable;
/** /**
* An abstract implementation of both a {@link Actor} and a {@link Player} * An abstract implementation of both a {@link Actor} and a {@link Player} that is intended for
* that is intended for implementations of WorldEdit to use to wrap * implementations of WorldEdit to use to wrap players that make use of WorldEdit.
* players that make use of WorldEdit.
*/ */
public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@ -111,7 +110,8 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
BlockVector3 mutablePos = MutableBlockVector3.ZERO; BlockVector3 mutablePos = MutableBlockVector3.ZERO;
while (y <= world.getMaximumPoint().getBlockY() + 2) { while (y <= world.getMaximumPoint().getBlockY() + 2) {
if (!world.getBlock(mutablePos.setComponents(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) { if (!world.getBlock(mutablePos.setComponents(x, y, z)).getBlockType().getMaterial()
.isMovementBlocker()) {
++free; ++free;
} else { } else {
free = 0; free = 0;
@ -120,7 +120,8 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
if (free == 2) { if (free == 2) {
final BlockVector3 pos = mutablePos.setComponents(x, y - 2, z); final BlockVector3 pos = mutablePos.setComponents(x, y - 2, z);
final BlockStateHolder state = world.getBlock(pos); final BlockStateHolder state = world.getBlock(pos);
setPosition(new Location(world, Vector3.at(x + 0.5, y - 2 + BlockTypeUtil.centralTopLimit(state), z + 0.5))); setPosition(new Location(world,
Vector3.at(x + 0.5, y - 2 + BlockTypeUtil.centralTopLimit(state), z + 0.5)));
return; return;
} }
@ -139,7 +140,8 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
final BlockVector3 pos = BlockVector3.at(x, y, z); final BlockVector3 pos = BlockVector3.at(x, y, z);
final BlockState id = world.getBlock(pos); final BlockState id = world.getBlock(pos);
if (id.getBlockType().getMaterial().isMovementBlocker()) { if (id.getBlockType().getMaterial().isMovementBlocker()) {
setPosition(new Location(world, Vector3.at(x + 0.5, y + + BlockTypeUtil.centralTopLimit(id), z + 0.5))); setPosition(new Location(world,
Vector3.at(x + 0.5, y + +BlockTypeUtil.centralTopLimit(id), z + 0.5)));
return; return;
} }
@ -161,7 +163,9 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
final Extent world = pos.getExtent(); final Extent world = pos.getExtent();
int maxY = world.getMaxY(); int maxY = world.getMaxY();
if (y >= maxY) return false; if (y >= maxY) {
return false;
}
BlockMaterial initialMaterial = world.getBlock(BlockVector3.at(x, y, z)).getMaterial(); BlockMaterial initialMaterial = world.getBlock(BlockVector3.at(x, y, z)).getMaterial();
@ -172,8 +176,11 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
for (int level = y + 1; level <= maxY + 2; level++) { for (int level = y + 1; level <= maxY + 2; level++) {
BlockState state; BlockState state;
if (level >= maxY) state = BlockTypes.VOID_AIR.getDefaultState(); if (level >= maxY) {
else state = world.getBlock(BlockVector3.at(x, level, z)); state = BlockTypes.VOID_AIR.getDefaultState();
} else {
state = world.getBlock(BlockVector3.at(x, level, z));
}
BlockType type = state.getBlockType(); BlockType type = state.getBlockType();
BlockMaterial material = type.getMaterial(); BlockMaterial material = type.getMaterial();
@ -218,14 +225,19 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
boolean lastState = initialMaterial.isMovementBlocker() && initialMaterial.isFullCube(); boolean lastState = initialMaterial.isMovementBlocker() && initialMaterial.isFullCube();
int maxY = world.getMaxY(); int maxY = world.getMaxY();
if (y <= 2) return false; if (y <= 2) {
return false;
}
double freeEnd = -1; double freeEnd = -1;
double height = 1.85; double height = 1.85;
for (int level = y + 1; level > 0; level--) { for (int level = y + 1; level > 0; level--) {
BlockState state; BlockState state;
if (level >= maxY) state = BlockTypes.VOID_AIR.getDefaultState(); if (level >= maxY) {
else state = world.getBlock(BlockVector3.at(x, level, z)); state = BlockTypes.VOID_AIR.getDefaultState();
} else {
state = world.getBlock(BlockVector3.at(x, level, z));
}
BlockType type = state.getBlockType(); BlockType type = state.getBlockType();
BlockMaterial material = type.getMaterial(); BlockMaterial material = type.getMaterial();
@ -279,7 +291,8 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
while (y <= world.getMaximumPoint().getY()) { while (y <= world.getMaximumPoint().getY()) {
// Found a ceiling! // Found a ceiling!
if (world.getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) { if (world.getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial()
.isMovementBlocker()) {
int platformY = Math.max(initialY, y - 3 - clearance); int platformY = Math.max(initialY, y - 3 - clearance);
floatAt(x, platformY + 1, z, alwaysGlass); floatAt(x, platformY + 1, z, alwaysGlass);
return true; return true;
@ -307,7 +320,8 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
final Extent world = getLocation().getExtent(); final Extent world = getLocation().getExtent();
while (y <= world.getMaximumPoint().getY() + 2) { while (y <= world.getMaximumPoint().getY() + 2) {
if (world.getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) { if (world.getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial()
.isMovementBlocker()) {
break; // Hit something break; // Hit something
} else if (y > maxY + 1) { } else if (y > maxY + 1) {
break; break;
@ -326,7 +340,8 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
public void floatAt(int x, int y, int z, boolean alwaysGlass) { public void floatAt(int x, int y, int z, boolean alwaysGlass) {
try { try {
BlockVector3 spot = BlockVector3.at(x, y - 1, z); BlockVector3 spot = BlockVector3.at(x, y - 1, z);
if (!getLocation().getExtent().getBlock(spot).getBlockType().getMaterial().isMovementBlocker()) { if (!getLocation().getExtent().getBlock(spot).getBlockType().getMaterial()
.isMovementBlocker()) {
getLocation().getExtent().setBlock(spot, BlockTypes.GLASS.getDefaultState()); getLocation().getExtent().setBlock(spot, BlockTypes.GLASS.getDefaultState());
} }
} catch (WorldEditException e) { } catch (WorldEditException e) {
@ -342,7 +357,8 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override @Override
public Location getBlockOn() { public Location getBlockOn() {
return getLocation().setPosition(getLocation().setY(getLocation().getY() - 1).toVector().floor()); return getLocation()
.setPosition(getLocation().setY(getLocation().getY() - 1).toVector().floor());
} }
@Override @Override
@ -433,7 +449,8 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
boolean inFree = false; boolean inFree = false;
while ((block = hitBlox.getNextBlock()) != null) { while ((block = hitBlox.getNextBlock()) != null) {
boolean free = !world.getBlock(block.toVector().toBlockPoint()).getBlockType().getMaterial().isMovementBlocker(); boolean free = !world.getBlock(block.toVector().toBlockPoint()).getBlockType()
.getMaterial().isMovementBlocker();
if (firstBlock) { if (firstBlock) {
firstBlock = false; firstBlock = false;

View File

@ -22,8 +22,6 @@
package com.sk89q.worldedit.world.snapshot; package com.sk89q.worldedit.world.snapshot;
import com.sk89q.worldedit.world.storage.MissingWorldException; import com.sk89q.worldedit.world.storage.MissingWorldException;
import javax.annotation.Nullable;
import java.io.File; import java.io.File;
import java.io.FilenameFilter; import java.io.FilenameFilter;
import java.time.ZoneOffset; import java.time.ZoneOffset;
@ -33,6 +31,7 @@ import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import javax.annotation.Nullable;
/** /**
* A repository contains zero or more snapshots. * A repository contains zero or more snapshots.
@ -67,13 +66,13 @@ public class SnapshotRepository {
} }
/** /**
* Get a list of snapshots in a directory. The newest snapshot is * Get a list of snapshots in a directory. The newest snapshot is near the top of the array.
* near the top of the array.
* *
* @param newestFirst true to get the newest first * @param newestFirst true to get the newest first
* @return a list of snapshots * @return a list of snapshots
*/ */
public List<Snapshot> getSnapshots(boolean newestFirst, String worldName) throws MissingWorldException { public List<Snapshot> getSnapshots(boolean newestFirst, String worldName)
throws MissingWorldException {
FilenameFilter filter = (dir, name) -> { FilenameFilter filter = (dir, name) -> {
File f = new File(dir, name); File f = new File(dir, name);
return isValidSnapshot(f); return isValidSnapshot(f);
@ -117,7 +116,8 @@ public class SnapshotRepository {
* @return a snapshot or null * @return a snapshot or null
*/ */
@Nullable @Nullable
public Snapshot getSnapshotAfter(ZonedDateTime date, String world) throws MissingWorldException { public Snapshot getSnapshotAfter(ZonedDateTime date, String world)
throws MissingWorldException {
List<Snapshot> snapshots = getSnapshots(true, world); List<Snapshot> snapshots = getSnapshots(true, world);
Snapshot last = null; Snapshot last = null;
@ -139,7 +139,8 @@ public class SnapshotRepository {
* @return a snapshot or null * @return a snapshot or null
*/ */
@Nullable @Nullable
public Snapshot getSnapshotBefore(ZonedDateTime date, String world) throws MissingWorldException { public Snapshot getSnapshotBefore(ZonedDateTime date, String world)
throws MissingWorldException {
List<Snapshot> snapshots = getSnapshots(false, world); List<Snapshot> snapshots = getSnapshots(false, world);
Snapshot last = null; Snapshot last = null;
@ -205,7 +206,8 @@ public class SnapshotRepository {
* @return whether it is a valid snapshot * @return whether it is a valid snapshot
*/ */
protected boolean isValidSnapshot(File file) { protected boolean isValidSnapshot(File file) {
if (!file.getName().matches("^[A-Za-z0-9_\\- \\./\\\\'\\$@~!%\\^\\*\\(\\)\\[\\]\\+\\{\\},\\?]+$")) { if (!file.getName()
.matches("^[A-Za-z0-9_\\- \\./\\\\'\\$@~!%\\^\\*\\(\\)\\[\\]\\+\\{\\},\\?]+$")) {
return false; return false;
} }