mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +00:00
Small changes
This commit is contained in:
parent
1932c96d4f
commit
d0a31691e1
@ -107,7 +107,7 @@ public class FaweBukkit implements IFawe, Listener {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
Bukkit.getServer().shutdown();
|
||||
}
|
||||
|
||||
@ -411,7 +411,7 @@ public class FaweBukkit implements IFawe, Listener {
|
||||
managers.add(new WorldguardFlag(worldguardPlugin, this));
|
||||
Fawe.debug("Plugin 'WorldGuard' found. Using it now.");
|
||||
} catch (final Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
final Plugin townyPlugin = Bukkit.getServer().getPluginManager().getPlugin("Towny");
|
||||
@ -420,7 +420,7 @@ public class FaweBukkit implements IFawe, Listener {
|
||||
managers.add(new TownyFeature(townyPlugin, this));
|
||||
Fawe.debug("Plugin 'Towny' found. Using it now.");
|
||||
} catch (final Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
final Plugin factionsPlugin = Bukkit.getServer().getPluginManager().getPlugin("Factions");
|
||||
@ -437,7 +437,7 @@ public class FaweBukkit implements IFawe, Listener {
|
||||
managers.add(new FactionsOneFeature(factionsPlugin));
|
||||
Fawe.debug("Plugin 'FactionsUUID' found. Using it now.");
|
||||
} catch (Throwable e3) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
@ -449,7 +449,7 @@ public class FaweBukkit implements IFawe, Listener {
|
||||
managers.add(new ResidenceFeature(residencePlugin, this));
|
||||
Fawe.debug("Plugin 'Residence' found. Using it now.");
|
||||
} catch (final Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
final Plugin griefpreventionPlugin = Bukkit.getServer().getPluginManager().getPlugin("GriefPrevention");
|
||||
@ -458,7 +458,7 @@ public class FaweBukkit implements IFawe, Listener {
|
||||
managers.add(new GriefPreventionFeature(griefpreventionPlugin));
|
||||
Fawe.debug("Plugin 'GriefPrevention' found. Using it now.");
|
||||
} catch (final Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
final Plugin preciousstonesPlugin = Bukkit.getServer().getPluginManager().getPlugin("PreciousStones");
|
||||
@ -467,7 +467,7 @@ public class FaweBukkit implements IFawe, Listener {
|
||||
managers.add(new PreciousStonesFeature(preciousstonesPlugin, this));
|
||||
Fawe.debug("Plugin 'PreciousStones' found. Using it now.");
|
||||
} catch (final Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -478,7 +478,7 @@ public class FaweBukkit implements IFawe, Listener {
|
||||
managers.add(new ASkyBlockHook(aSkyBlock));
|
||||
Fawe.debug("Plugin 'ASkyBlock' found. Using it now.");
|
||||
} catch (final Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (Settings.IMP.EXPERIMENTAL.FREEBUILD) {
|
||||
@ -486,7 +486,7 @@ public class FaweBukkit implements IFawe, Listener {
|
||||
managers.add(new FreeBuildRegion());
|
||||
Fawe.debug("Plugin '<internal.freebuild>' found. Using it now.");
|
||||
} catch (final Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,6 @@ package com.boydti.fawe.bukkit.regions;
|
||||
import com.boydti.fawe.object.FawePlayer;
|
||||
import com.boydti.fawe.object.RegionWrapper;
|
||||
import com.boydti.fawe.regions.FaweMask;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.Perm;
|
||||
import com.massivecraft.factions.FLocation;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
@ -107,7 +106,7 @@ public class FactionsOneFeature extends BukkitMaskManager implements Listener {
|
||||
}
|
||||
return true;
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.boydti.fawe.bukkit.util;
|
||||
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.ReflectionUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
@ -38,7 +37,7 @@ public class BukkitReflectionUtils {
|
||||
preClassM = "net.minecraft.server." + verM;
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -334,7 +334,7 @@ public class BukkitChunk_All extends IntFaweChunk<Chunk, BukkitQueue_All> {
|
||||
index = 0;
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
} while (System.currentTimeMillis() - start < recommended);
|
||||
if (more || place) {
|
||||
|
@ -284,7 +284,7 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
|
||||
copy.sectionPalettes[i] = copy(current);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return copy;
|
||||
@ -620,7 +620,7 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
|
||||
getParent().getChangeTask().run(copy, this);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import com.boydti.fawe.object.FawePlayer;
|
||||
import com.boydti.fawe.object.RegionWrapper;
|
||||
import com.boydti.fawe.object.brush.visualization.VisualChunk;
|
||||
import com.boydti.fawe.object.visitor.FaweChunkVisitor;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.boydti.fawe.util.TaskManager;
|
||||
|
||||
@ -701,7 +700,7 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
|
||||
tile.save(tag); // readTagIntoEntity
|
||||
return (CompoundTag) toNative(tag);
|
||||
} catch (Exception e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import org.bukkit.OfflinePlayer;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@ -58,7 +59,7 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
|
||||
|
||||
Map<String, Set<String>> userGroupPermissions = new HashMap<>();
|
||||
|
||||
List<String> groupKeys = config.getStringList("permissions.groups", null);
|
||||
List<String> groupKeys = config.getKeys("permissions.groups");
|
||||
|
||||
if (groupKeys != null) {
|
||||
for (String key : groupKeys) {
|
||||
@ -76,7 +77,7 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
|
||||
}
|
||||
}
|
||||
|
||||
List<String> userKeys = config.getStringList("permissions.users", null);
|
||||
List<String> userKeys = config.getKeys("permissions.users");
|
||||
|
||||
if (userKeys != null) {
|
||||
for (String key : userKeys) {
|
||||
@ -102,8 +103,8 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
|
||||
}
|
||||
}
|
||||
|
||||
userPermissionsCache.put(key.toLowerCase(), permsCache);
|
||||
userGroups.put(key.toLowerCase(), new HashSet<>(groups));
|
||||
userPermissionsCache.put(key.toLowerCase(Locale.ROOT), permsCache);
|
||||
userGroups.put(key.toLowerCase(Locale.ROOT), new HashSet<>(groups));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -117,7 +118,7 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> perms = userPermissionsCache.get(player.toLowerCase());
|
||||
Set<String> perms = userPermissionsCache.get(player.toLowerCase(Locale.ROOT));
|
||||
if (perms == null) {
|
||||
return defaultPermissionsCache.contains(permission)
|
||||
|| defaultPermissionsCache.contains("*");
|
||||
@ -134,7 +135,7 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
|
||||
|
||||
@Override
|
||||
public boolean inGroup(String player, String group) {
|
||||
Set<String> groups = userGroups.get(player.toLowerCase());
|
||||
Set<String> groups = userGroups.get(player.toLowerCase(Locale.ROOT));
|
||||
if (groups == null) {
|
||||
return false;
|
||||
}
|
||||
@ -144,12 +145,12 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
|
||||
|
||||
@Override
|
||||
public String[] getGroups(String player) {
|
||||
Set<String> groups = userGroups.get(player.toLowerCase());
|
||||
Set<String> groups = userGroups.get(player.toLowerCase(Locale.ROOT));
|
||||
if (groups == null) {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
return groups.toArray(new String[groups.size()]);
|
||||
return groups.toArray(new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -382,7 +382,7 @@ public class Fawe {
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
debug("====== MEMORY LISTENER ERROR ======");
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
debug("===================================");
|
||||
debug("FAWE needs access to the JVM memory system:");
|
||||
debug(" - Change your Java security settings");
|
||||
|
@ -5,7 +5,6 @@ import com.boydti.fawe.configuration.MemorySection;
|
||||
import com.boydti.fawe.configuration.file.YamlConfiguration;
|
||||
import com.boydti.fawe.object.FawePlayer;
|
||||
import com.boydti.fawe.object.RunnableVal3;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.StringMan;
|
||||
import com.boydti.fawe.util.chat.Message;
|
||||
import com.google.gson.Gson;
|
||||
@ -472,7 +471,7 @@ public enum BBC {
|
||||
yml.save(file);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,6 @@ import com.boydti.fawe.object.RunnableVal;
|
||||
import com.boydti.fawe.object.RunnableVal2;
|
||||
import com.boydti.fawe.object.exception.FaweException;
|
||||
import com.boydti.fawe.object.extent.LightingExtent;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.boydti.fawe.util.SetQueue;
|
||||
import com.boydti.fawe.util.TaskManager;
|
||||
@ -229,7 +228,7 @@ public abstract class MappedFaweQueue<WORLD, CHUNK, CHUNKSECTIONS, SECTION> impl
|
||||
try {
|
||||
task.run();
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -246,7 +245,7 @@ public abstract class MappedFaweQueue<WORLD, CHUNK, CHUNKSECTIONS, SECTION> impl
|
||||
try {
|
||||
run.run();
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,10 @@
|
||||
package com.boydti.fawe.example;
|
||||
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.object.FaweChunk;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.TaskManager;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class NMSMappedFaweQueue<WORLD, CHUNK, CHUNKSECTION, SECTION> extends MappedFaweQueue<WORLD, CHUNK, CHUNKSECTION, SECTION> {
|
||||
|
||||
private final int maxY;
|
||||
@ -104,7 +97,7 @@ public abstract class NMSMappedFaweQueue<WORLD, CHUNK, CHUNKSECTION, SECTION> ex
|
||||
try {
|
||||
refreshChunk(fc);
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,13 @@
|
||||
package com.boydti.fawe.object;
|
||||
|
||||
import com.boydti.fawe.object.visitor.FaweChunkVisitor;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -121,7 +120,7 @@ public abstract class FaweChunk<T> implements Callable<FaweChunk> {
|
||||
return BaseBlock.getFromInternalId(combined, tile).toImmutableState();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return BlockState.getFromInternalId(combined);
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.boydti.fawe.object;
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.TaskManager;
|
||||
|
||||
public abstract class FaweCommand<T> {
|
||||
@ -36,7 +35,7 @@ public abstract class FaweCommand<T> {
|
||||
}
|
||||
return true;
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.ConvexPolyhedralRegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.CylinderRegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
@ -353,7 +354,7 @@ public abstract class FawePlayer<T> extends Metadatable {
|
||||
}
|
||||
} catch (Exception event) {
|
||||
Fawe.debug("====== INVALID CLIPBOARD ======");
|
||||
MainUtil.handleError(event);
|
||||
event.printStackTrace();
|
||||
Fawe.debug("===============---=============");
|
||||
Fawe.debug("This shouldn't result in any failure");
|
||||
Fawe.debug("File: " + file.getName() + " (len:" + file.length() + ")");
|
||||
@ -560,19 +561,14 @@ public abstract class FawePlayer<T> extends Metadatable {
|
||||
|
||||
public void setSelection(Region region) {
|
||||
RegionSelector selector;
|
||||
switch (region.getClass().getName()) {
|
||||
case "ConvexPolyhedralRegion":
|
||||
if (region instanceof ConvexPolyhedralRegion) {
|
||||
selector = new ConvexPolyhedralRegionSelector((ConvexPolyhedralRegion) region);
|
||||
break;
|
||||
case "CylinderRegion":
|
||||
} else if (region instanceof CylinderRegion) {
|
||||
selector = new CylinderRegionSelector((CylinderRegion) region);
|
||||
break;
|
||||
case "Polygonal2DRegion":
|
||||
selector = new com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector((Polygonal2DRegion) region);
|
||||
break;
|
||||
default:
|
||||
} else if (region instanceof Polygonal2DRegion) {
|
||||
selector = new Polygonal2DRegionSelector((Polygonal2DRegion) region);
|
||||
} else {
|
||||
selector = new CuboidRegionSelector(null, region.getMinimumPoint(), region.getMaximumPoint());
|
||||
break;
|
||||
}
|
||||
selector.setWorld(region.getWorld());
|
||||
|
||||
|
@ -77,7 +77,7 @@ public interface FaweQueue extends HasFaweQueue, Extent {
|
||||
try {
|
||||
return BlockState.getFromInternalId(combinedId4Data);
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
return BlockTypes.AIR.getDefaultState();
|
||||
}
|
||||
}
|
||||
@ -100,7 +100,7 @@ public interface FaweQueue extends HasFaweQueue, Extent {
|
||||
}
|
||||
return block;
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
return BlockTypes.AIR.getDefaultState().toBaseBlock();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.boydti.fawe.object.brush.heightmap;
|
||||
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
@ -14,21 +13,19 @@ import com.sk89q.worldedit.util.Location;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public interface HeightMap {
|
||||
public double getHeight(int x, int z);
|
||||
double getHeight(int x, int z);
|
||||
|
||||
public void setSize(int size);
|
||||
void setSize(int size);
|
||||
|
||||
|
||||
default void perform(EditSession session, Mask mask, BlockVector3 pos, int size, int rotationMode, double yscale, boolean smooth, boolean towards, boolean layers) throws MaxChangedBlocksException {
|
||||
int[][] data = generateHeightData(session, mask, pos, size, rotationMode, yscale, smooth, towards, layers);
|
||||
applyHeightMapData(data, session, mask, pos, size, rotationMode, yscale, smooth, towards, layers);
|
||||
applyHeightMapData(data, session, pos, size, yscale, smooth, towards, layers);
|
||||
}
|
||||
|
||||
default void applyHeightMapData(int[][] data, EditSession session, Mask mask, BlockVector3 pos, int size, int rotationMode, double yscale, boolean smooth, boolean towards, boolean layers) throws MaxChangedBlocksException {
|
||||
default void applyHeightMapData(int[][] data, EditSession session, BlockVector3 pos, int size, double yscale, boolean smooth, boolean towards, boolean layers) throws MaxChangedBlocksException {
|
||||
BlockVector3 top = session.getMaximumPoint();
|
||||
int maxY = top.getBlockY();
|
||||
int diameter = 2 * size + 1;
|
||||
int iterations = 1;
|
||||
Location min = new Location(session.getWorld(), pos.subtract(size, maxY, size).toVector3());
|
||||
BlockVector3 max = pos.add(size, maxY, size);
|
||||
Region region = new CuboidRegion(session.getWorld(), min.toBlockPoint(), max);
|
||||
@ -36,20 +33,17 @@ public interface HeightMap {
|
||||
if (smooth) {
|
||||
try {
|
||||
HeightMapFilter filter = (HeightMapFilter) HeightMapFilter.class.getConstructors()[0].newInstance(GaussianKernel.class.getConstructors()[0].newInstance(5, 1));
|
||||
int diameter = 2 * size + 1;
|
||||
data[1] = filter.filter(data[1], diameter, diameter);
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (layers) {
|
||||
heightMap.applyLayers(data[1]);
|
||||
} else {
|
||||
heightMap.apply(data[1]);
|
||||
}
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
default int[][] generateHeightData(EditSession session, Mask mask, BlockVector3 pos, int size, final int rotationMode, double yscale, boolean smooth, boolean towards, final boolean layers) {
|
||||
@ -59,22 +53,18 @@ public interface HeightMap {
|
||||
int centerX = pos.getBlockX();
|
||||
int centerZ = pos.getBlockZ();
|
||||
int centerY = pos.getBlockY();
|
||||
int endY = pos.getBlockY() + size;
|
||||
int startY = pos.getBlockY() - size;
|
||||
int[] oldData = new int[diameter * diameter];
|
||||
int[] newData = new int[oldData.length];
|
||||
if (layers) { // Pixel accuracy
|
||||
centerY <<= 3;
|
||||
maxY <<= 3;
|
||||
}
|
||||
// Vector mutablePos = new Vector(0, 0, 0);
|
||||
if (towards) {
|
||||
double sizePowInv = 1d / Math.pow(size, yscale);
|
||||
int targetY = pos.getBlockY();
|
||||
int tmpY = targetY;
|
||||
for (int x = -size; x <= size; x++) {
|
||||
int xx = centerX + x;
|
||||
// mutablePos.mutX(xx);
|
||||
for (int z = -size; z <= size; z++) {
|
||||
int index = (z + size) * diameter + (x + size);
|
||||
int zz = centerZ + z;
|
||||
@ -118,7 +108,6 @@ public interface HeightMap {
|
||||
int height = pos.getBlockY();
|
||||
for (int x = -size; x <= size; x++) {
|
||||
int xx = centerX + x;
|
||||
// mutablePos.mutX(xx);
|
||||
for (int z = -size; z <= size; z++) {
|
||||
int index = (z + size) * diameter + (x + size);
|
||||
int zz = centerZ + z;
|
||||
|
@ -13,13 +13,12 @@ import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
import java.io.DataOutput;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -181,7 +180,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
|
||||
if (osENTCF != null) osENTCF.flush();
|
||||
if (osENTCT != null) osENTCT.flush();
|
||||
} catch (Exception e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return flushed;
|
||||
}
|
||||
@ -218,7 +217,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
|
||||
osENTCT = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return flushed;
|
||||
}
|
||||
@ -418,7 +417,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
|
||||
}
|
||||
return summary;
|
||||
} catch (IOException e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -439,7 +438,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
|
||||
fis.close();
|
||||
gis.close();
|
||||
} catch (IOException e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return new IntegerPair(ox, oz);
|
||||
|
@ -107,7 +107,7 @@ public abstract class FaweChangeSet implements ChangeSet {
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -194,7 +194,7 @@ public abstract class FaweChangeSet implements ChangeSet {
|
||||
BaseBlock to = change.getCurrent();
|
||||
add(loc, from, to);
|
||||
} catch (Exception e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,7 +222,7 @@ public abstract class FaweChangeSet implements ChangeSet {
|
||||
add(x, y, z, combinedFrom, combinedTo);
|
||||
|
||||
} catch (Exception e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,7 +241,7 @@ public abstract class FaweChangeSet implements ChangeSet {
|
||||
add(x, y, z, combinedFrom, combinedTo);
|
||||
|
||||
} catch (Exception e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -343,7 +343,7 @@ public abstract class FaweChangeSet implements ChangeSet {
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (FaweChangeSet.this.waitingCombined.decrementAndGet() <= 0) {
|
||||
synchronized (FaweChangeSet.this.waitingAsync) {
|
||||
|
@ -320,7 +320,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
|
||||
posDel.write(stream, x - originX, y, z - originZ);
|
||||
idDel.writeChange(stream, combinedFrom, combinedTo);
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -340,7 +340,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
|
||||
os.writeVarInt(from.getInternalId());
|
||||
os.writeVarInt(to.getInternalId());
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -353,7 +353,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
|
||||
NBTOutputStream nbtos = getTileCreateOS();
|
||||
nbtos.writeTag(tag);
|
||||
} catch (IOException e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -366,7 +366,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
|
||||
NBTOutputStream nbtos = getTileRemoveOS();
|
||||
nbtos.writeTag(tag);
|
||||
} catch (IOException e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -379,7 +379,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
|
||||
NBTOutputStream nbtos = getEntityRemoveOS();
|
||||
nbtos.writeTag(tag);
|
||||
} catch (IOException e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -392,7 +392,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
|
||||
NBTOutputStream nbtos = getEntityCreateOS();
|
||||
nbtos.writeTag(tag);
|
||||
} catch (IOException e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -415,12 +415,12 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
|
||||
} catch (EOFException ignored) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -470,12 +470,12 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
|
||||
} catch (EOFException ignored) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -530,12 +530,12 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
|
||||
} catch (EOFException ignored) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -562,7 +562,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
|
||||
};
|
||||
}
|
||||
|
||||
public Iterator<MutableEntityChange> getEntityIterator(final NBTInputStream is, final boolean create, final boolean dir) {
|
||||
public Iterator<MutableEntityChange> getEntityIterator(final NBTInputStream is, final boolean create) {
|
||||
if (is == null) {
|
||||
return new ArrayList<MutableEntityChange>().iterator();
|
||||
}
|
||||
@ -580,7 +580,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -606,12 +606,12 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
|
||||
}
|
||||
};
|
||||
} catch (Exception e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Iterator<MutableTileChange> getTileIterator(final NBTInputStream is, final boolean create, final boolean dir) {
|
||||
public Iterator<MutableTileChange> getTileIterator(final NBTInputStream is, final boolean create) {
|
||||
if (is == null) {
|
||||
return new ArrayList<MutableTileChange>().iterator();
|
||||
}
|
||||
@ -629,7 +629,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -655,7 +655,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
|
||||
}
|
||||
};
|
||||
} catch (Exception e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -663,11 +663,11 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
|
||||
public Iterator<Change> getIterator(final boolean dir) {
|
||||
close();
|
||||
try {
|
||||
final Iterator<MutableTileChange> tileCreate = getTileIterator(getTileCreateIS(), true, dir);
|
||||
final Iterator<MutableTileChange> tileRemove = getTileIterator(getTileRemoveIS(), false, dir);
|
||||
final Iterator<MutableTileChange> tileCreate = getTileIterator(getTileCreateIS(), true);
|
||||
final Iterator<MutableTileChange> tileRemove = getTileIterator(getTileRemoveIS(), false);
|
||||
|
||||
final Iterator<MutableEntityChange> entityCreate = getEntityIterator(getEntityCreateIS(), true, dir);
|
||||
final Iterator<MutableEntityChange> entityRemove = getEntityIterator(getEntityRemoveIS(), false, dir);
|
||||
final Iterator<MutableEntityChange> entityCreate = getEntityIterator(getEntityCreateIS(), true);
|
||||
final Iterator<MutableEntityChange> entityRemove = getEntityIterator(getEntityRemoveIS(), false);
|
||||
|
||||
final Iterator<MutableBlockChange> blockChange = getBlockIterator(dir);
|
||||
|
||||
@ -709,7 +709,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
|
||||
}
|
||||
};
|
||||
} catch (Exception e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new ArrayList<Change>().iterator();
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ import com.boydti.fawe.util.MainUtil;
|
||||
import com.sk89q.jnbt.NBTInputStream;
|
||||
import com.sk89q.jnbt.NBTOutputStream;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* ChangeSet optimized for low memory usage
|
||||
@ -66,7 +66,7 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet {
|
||||
if (tileRStream != null) tileRStreamZip.flush();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -115,7 +115,7 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet {
|
||||
}
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -78,9 +78,9 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
|
||||
this.braf = new RandomAccessFile(file, "rw");
|
||||
braf.setLength(file.length());
|
||||
init();
|
||||
width = (int) mbb.getChar(2);
|
||||
height = (int) mbb.getChar(4);
|
||||
length = (int) mbb.getChar(6);
|
||||
width = mbb.getChar(2);
|
||||
height = mbb.getChar(4);
|
||||
length = mbb.getChar(6);
|
||||
area = width * length;
|
||||
this.volume = length * width * height;
|
||||
|
||||
@ -180,7 +180,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
|
||||
clipboard.setOrigin(BlockVector3.at(ox, oy, oz));
|
||||
return clipboard;
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -204,7 +204,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
|
||||
file.createNewFile();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.braf = new RandomAccessFile(file, "rw");
|
||||
long volume = (long) width * (long) height * (long) length * 4L + (long) HEADER_SIZE;
|
||||
@ -229,7 +229,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
|
||||
mbb.putShort(10, (short) offset.getBlockY());
|
||||
mbb.putShort(12, (short) offset.getBlockZ());
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -252,7 +252,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
|
||||
mbb.putChar(4, (char) height);
|
||||
mbb.putChar(6, (char) length);
|
||||
} catch (IOException e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -289,7 +289,6 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
cb = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -311,7 +310,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
|
||||
braf = null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -350,7 +349,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -441,7 +440,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
|
||||
} catch (IndexOutOfBoundsException ignore) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return BlockTypes.AIR.getDefaultState().toBaseBlock();
|
||||
}
|
||||
@ -480,7 +479,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
|
||||
return base;
|
||||
} catch (IndexOutOfBoundsException ignore) {
|
||||
} catch (Exception e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return BlockTypes.AIR.getDefaultState().toBaseBlock();
|
||||
}
|
||||
@ -501,13 +500,13 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
|
||||
int index = (HEADER_SIZE) + ((getIndex(x, y, z) << 2));
|
||||
int combined = block.getInternalId();
|
||||
mbb.putInt(index, combined);
|
||||
boolean hasNbt = block instanceof BaseBlock && ((BaseBlock)block).hasNbtData();
|
||||
boolean hasNbt = block instanceof BaseBlock && block.hasNbtData();
|
||||
if (hasNbt) {
|
||||
setTile(x, y, z, block.getNbtData());
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -528,7 +527,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.boydti.fawe.util;
|
||||
|
||||
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class ExtentTraverser<T extends Extent> {
|
||||
@ -75,7 +76,7 @@ public class ExtentTraverser<T extends Extent> {
|
||||
}
|
||||
return null;
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -91,7 +92,7 @@ public class ExtentTraverser<T extends Extent> {
|
||||
}
|
||||
return null;
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -609,18 +609,12 @@ public class MainUtil {
|
||||
return newFile;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
Fawe.debug("&cCould not save " + resource);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void handleError(Throwable e) {
|
||||
if (e == null) {
|
||||
return;
|
||||
}
|
||||
e.printStackTrace(); }
|
||||
|
||||
public static int[] regionNameToCoords(String fileName) {
|
||||
int[] res = new int[2];
|
||||
int len = fileName.length() - 4;
|
||||
|
@ -150,7 +150,7 @@ public class ReflectionUtils {
|
||||
m.setAccessible(true);
|
||||
return (Map<T, V>) m.get(map);
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@ -163,7 +163,7 @@ public class ReflectionUtils {
|
||||
m.setAccessible(true);
|
||||
return (List<T>) m.get(list);
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.object.FaweQueue;
|
||||
import com.boydti.fawe.wrappers.WorldWrapper;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -273,7 +274,7 @@ public class SetQueue {
|
||||
} catch (Throwable e) {
|
||||
pool.awaitQuiescence(Settings.IMP.QUEUE.DISCARD_AFTER_MS, TimeUnit.MILLISECONDS);
|
||||
completer = new ExecutorCompletionService(pool);
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
queue.endSet(Settings.IMP.QUEUE.PARALLEL_THREADS > 1);
|
||||
queue.setStage(QueueStage.NONE);
|
||||
|
@ -4,15 +4,16 @@ import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.object.FaweQueue;
|
||||
import com.boydti.fawe.object.RunnableVal;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Supplier;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public abstract class TaskManager {
|
||||
|
||||
@ -283,7 +284,7 @@ public abstract class TaskManager {
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -330,7 +331,7 @@ public abstract class TaskManager {
|
||||
} catch (RuntimeException e) {
|
||||
this.value = e;
|
||||
} catch (Throwable neverHappens) {
|
||||
MainUtil.handleError(neverHappens);
|
||||
neverHappens.printStackTrace();
|
||||
} finally {
|
||||
running.set(false);
|
||||
}
|
||||
@ -347,7 +348,7 @@ public abstract class TaskManager {
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (run.value != null) {
|
||||
throw run.value;
|
||||
@ -382,7 +383,7 @@ public abstract class TaskManager {
|
||||
} catch (RuntimeException e) {
|
||||
this.value = e;
|
||||
} catch (Throwable neverHappens) {
|
||||
MainUtil.handleError(neverHappens);
|
||||
neverHappens.printStackTrace();
|
||||
} finally {
|
||||
running.set(false);
|
||||
synchronized (function) {
|
||||
@ -399,7 +400,7 @@ public abstract class TaskManager {
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (run.value instanceof RuntimeException) {
|
||||
throw (RuntimeException) run.value;
|
||||
|
@ -14,9 +14,9 @@ import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class WEManager {
|
||||
|
||||
@ -33,7 +33,7 @@ public class WEManager {
|
||||
field.set(parent, new NullExtent((Extent) field.get(parent), reason));
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
throw new FaweException(reason);
|
||||
}
|
||||
@ -189,7 +189,7 @@ public class WEManager {
|
||||
}), 2);
|
||||
});
|
||||
} catch (final Exception e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, false, false);
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
package com.sk89q.jnbt;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* The {@code TAG_Byte_Array} tag.
|
||||
*/
|
||||
@ -45,7 +47,7 @@ public final class ByteArrayTag extends Tag {
|
||||
public String toString() {
|
||||
StringBuilder hex = new StringBuilder();
|
||||
for (byte b : value) {
|
||||
String hexDigits = Integer.toHexString(b).toUpperCase();
|
||||
String hexDigits = Integer.toHexString(b).toUpperCase(Locale.ROOT);
|
||||
if (hexDigits.length() == 1) {
|
||||
hex.append("0");
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ package com.sk89q.util;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -274,7 +275,7 @@ public final class StringUtil {
|
||||
}
|
||||
|
||||
public static <T extends Enum<?>> T lookup(Map<String, T> lookup, String name, boolean fuzzy) {
|
||||
String testName = name.replaceAll("[ _]", "").toLowerCase();
|
||||
String testName = name.replaceAll("[ _]", "").toLowerCase(Locale.ROOT);
|
||||
|
||||
T type = lookup.get(testName);
|
||||
if (type != null) {
|
||||
@ -305,6 +306,10 @@ public final class StringUtil {
|
||||
}
|
||||
|
||||
public static List<String> parseListInQuotes(String[] input, char delimiter, char quoteOpen, char quoteClose) {
|
||||
return parseListInQuotes(input, delimiter, quoteOpen, quoteClose, false);
|
||||
}
|
||||
|
||||
public static List<String> parseListInQuotes(String[] input, char delimiter, char quoteOpen, char quoteClose, boolean appendLeftover) {
|
||||
List<String> parsableBlocks = new ArrayList<>();
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
for (String split : input) {
|
||||
@ -320,6 +325,9 @@ public final class StringUtil {
|
||||
buffer.append(split).append(delimiter);
|
||||
}
|
||||
}
|
||||
if (appendLeftover && buffer.length() != 0) {
|
||||
parsableBlocks.add(buffer.delete(buffer.length() - 1, buffer.length()).toString());
|
||||
}
|
||||
|
||||
return parsableBlocks;
|
||||
}
|
||||
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.blocks;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* The colors for wool.
|
||||
*
|
||||
* <p>This class may be removed in the future.</p>
|
||||
*/
|
||||
public enum ClothColor {
|
||||
|
||||
WHITE("White", "white"),
|
||||
ORANGE("Orange", "orange"),
|
||||
MAGENTA("Magenta", "magenta"),
|
||||
LIGHT_BLUE("Light blue", "lightblue"),
|
||||
YELLOW("Yellow", "yellow"),
|
||||
LIGHT_GREEN("Light green", "lightgreen"),
|
||||
PINK("Pink", "pink", "lightred"),
|
||||
GRAY("Gray", "grey", "gray"),
|
||||
LIGHT_GRAY("Light gray", "lightgrey", "lightgray"),
|
||||
CYAN("Cyan", "cyan", "turquoise"),
|
||||
PURPLE("Purple", "purple", "violet"),
|
||||
BLUE("Blue", "blue"),
|
||||
BROWN("Brown", "brown", "cocoa", "coffee"),
|
||||
DARK_GREEN("Dark green", "green", "darkgreen", "cactusgreen", "cactigreen"),
|
||||
RED("Red", "red"),
|
||||
BLACK("Black", "black");
|
||||
/**
|
||||
* Stores a map of the names for fast access.
|
||||
*/
|
||||
private static final Map<String, ClothColor> lookup = new HashMap<>();
|
||||
|
||||
private final String name;
|
||||
private final String[] lookupKeys;
|
||||
|
||||
static {
|
||||
for (ClothColor type : EnumSet.allOf(ClothColor.class)) {
|
||||
for (String key : type.lookupKeys) {
|
||||
lookup.put(key, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct the type.
|
||||
*
|
||||
* @param name the name of the color
|
||||
* @param lookupKeys a name to refer to the color by
|
||||
*/
|
||||
ClothColor(String name, String ... lookupKeys) {
|
||||
this.name = name;
|
||||
this.lookupKeys = lookupKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return type from name. May return null.
|
||||
*
|
||||
* @param name the name of the color
|
||||
* @return a color or null
|
||||
*/
|
||||
@Nullable
|
||||
public static ClothColor lookup(String name) {
|
||||
return lookup.get(name.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user-friendly item name.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
@ -149,7 +149,7 @@ public class SelectionCommand extends SimpleCommand<Operation> {
|
||||
return null;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,33 +19,32 @@
|
||||
|
||||
package com.sk89q.worldedit.event.extent;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import static com.sk89q.worldedit.EditSession.Stage;
|
||||
import com.sk89q.worldedit.event.Cancellable;
|
||||
import com.sk89q.worldedit.event.Event;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.sk89q.worldedit.EditSession.Stage;
|
||||
|
||||
/**
|
||||
* Raised (several times) when a new {@link EditSession} is being instantiated.
|
||||
* <p>
|
||||
*
|
||||
* <p></p>Block loggers, as well as block set interceptors, can use this event to wrap
|
||||
* the given {@link Extent} with their own, which would allow them to intercept
|
||||
* all changes made to the world. For example, the code below would wrap the
|
||||
* existing extent with a custom one, and the custom extent would receive
|
||||
* all method calls <strong>before</strong> the extent fetched from
|
||||
* {@link #getExtent()} would.</p>
|
||||
* <p>
|
||||
*
|
||||
* <pre>
|
||||
* event.setExtent(new MyExtent(event.getExtent())
|
||||
* </pre>
|
||||
* <p>
|
||||
*
|
||||
* <p></p>This event is fired several times during the creation of a single
|
||||
* {@link EditSession}, but {@link #getStage()} will differ each time.
|
||||
* The stage determines at which point {@link Extent}s added to this event
|
||||
|
@ -56,6 +56,7 @@ import com.sk89q.worldedit.world.block.FuzzyBlockState;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Parses block input strings.
|
||||
@ -112,8 +113,9 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
* @param string Input string
|
||||
* @return Mapped string
|
||||
*/
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
private String woolMapper(String string) {
|
||||
switch (string.toLowerCase()) {
|
||||
switch (string.toLowerCase(Locale.ROOT)) {
|
||||
case "white":
|
||||
return BlockTypes.WHITE_WOOL.getId();
|
||||
case "black":
|
||||
|
@ -21,13 +21,19 @@ package com.sk89q.worldedit.extension.factory.parser;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.util.HandSide;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class DefaultItemParser extends InputParser<BaseItem> {
|
||||
|
||||
public DefaultItemParser(WorldEdit worldEdit) {
|
||||
@ -42,18 +48,22 @@ public class DefaultItemParser extends InputParser<BaseItem> {
|
||||
try {
|
||||
String[] split = input.split(":");
|
||||
ItemType type;
|
||||
if (split.length == 1) {
|
||||
if (split.length == 0) {
|
||||
throw new InputParseException("Invalid colon.");
|
||||
} else if (split.length == 1) {
|
||||
type = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(split[0]));
|
||||
} else {
|
||||
type = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
||||
}
|
||||
if (type != null) {
|
||||
item = new BaseItem(type);
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
if (item == null) {
|
||||
ItemType type = ItemTypes.get(input.toLowerCase());
|
||||
ItemType type = ItemTypes.get(input.toLowerCase(Locale.ROOT));
|
||||
if (type != null) {
|
||||
item = new BaseItem(type);
|
||||
}
|
||||
@ -66,4 +76,11 @@ public class DefaultItemParser extends InputParser<BaseItem> {
|
||||
}
|
||||
}
|
||||
|
||||
private BaseItemStack getItemInHand(Actor actor, HandSide handSide) throws InputParseException {
|
||||
if (actor instanceof Player) {
|
||||
return ((Player) actor).getItemInHand(handSide);
|
||||
} else {
|
||||
throw new InputParseException("The user is not a player!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ import com.boydti.fawe.object.FawePlayer;
|
||||
import com.boydti.fawe.object.brush.visualization.VirtualWorld;
|
||||
import com.boydti.fawe.object.exception.FaweException;
|
||||
import com.boydti.fawe.object.pattern.PatternTraverser;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.wrappers.LocationMaskedPlayerWrapper;
|
||||
import com.boydti.fawe.wrappers.PlayerWrapper;
|
||||
import com.boydti.fawe.wrappers.WorldWrapper;
|
||||
@ -434,7 +433,7 @@ public class PlatformManager {
|
||||
} else {
|
||||
actor.printError("Please report this error: [See console]");
|
||||
actor.printRaw(e.getClass().getName() + ": " + e.getMessage());
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -518,7 +517,7 @@ public class PlatformManager {
|
||||
} else {
|
||||
player.printError("Please report this error: [See console]");
|
||||
player.printRaw(e.getClass().getName() + ": " + e.getMessage());
|
||||
MainUtil.handleError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
} finally {
|
||||
Request.reset();
|
||||
|
@ -65,7 +65,7 @@ public interface InputExtent {
|
||||
* modifiable copy is required, then the block should be cloned.</p>
|
||||
*
|
||||
* <p>This method exists because it is sometimes important to inspect the block
|
||||
* at a given location, but {@link #getBlock(Vector)} may be too expensive in
|
||||
* at a given location, but {@link #getBlock(BlockVector3)} may be too expensive in
|
||||
* the underlying implementation. It is also not possible to implement
|
||||
* caching if the returned object is mutable, so this methods allows caching
|
||||
* implementations to be used.</p>
|
||||
|
@ -25,8 +25,9 @@ import com.boydti.fawe.object.clipboard.FaweClipboard;
|
||||
import com.boydti.fawe.object.clipboard.FaweClipboard.ClipboardEntity;
|
||||
import com.boydti.fawe.object.clipboard.MemoryOptimizedClipboard;
|
||||
import com.boydti.fawe.object.extent.LightingExtent;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
@ -36,6 +37,7 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
@ -48,8 +50,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Stores block data as a multi-dimensional array of {@link BlockState}s and
|
||||
* other data as lists or maps.
|
||||
@ -58,7 +58,8 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
|
||||
|
||||
private Region region;
|
||||
private BlockVector3 origin;
|
||||
private BlockStateHolder[][][] blocks;
|
||||
private BaseBlock[][][] blocks;
|
||||
private BiomeType[][] biomes = null;
|
||||
public FaweClipboard IMP;
|
||||
private BlockVector3 size;
|
||||
private final List<ClipboardEntity> entities = new ArrayList<>();
|
||||
@ -69,7 +70,7 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
|
||||
this.size = getDimensions();
|
||||
this.IMP = Settings.IMP.CLIPBOARD.USE_DISK ? new DiskOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ()) : new MemoryOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ());
|
||||
this.origin = region.getMinimumPoint();
|
||||
this.blocks = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
||||
this.blocks = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,7 +86,7 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
|
||||
this.size = getDimensions();
|
||||
this.IMP = Settings.IMP.CLIPBOARD.USE_DISK ? new DiskOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ(), clipboardId) : new MemoryOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ());
|
||||
this.origin = region.getMinimumPoint();
|
||||
this.blocks = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
||||
this.blocks = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
||||
}
|
||||
|
||||
public BlockArrayClipboard(Region region, FaweClipboard clipboard) {
|
||||
@ -94,7 +95,7 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
|
||||
this.size = getDimensions();
|
||||
this.origin = region.getMinimumPoint();
|
||||
this.IMP = clipboard;
|
||||
this.blocks = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
||||
this.blocks = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
||||
}
|
||||
|
||||
public void init(Region region, FaweClipboard fc) {
|
||||
@ -104,7 +105,7 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
|
||||
this.size = getDimensions();
|
||||
this.IMP = fc;
|
||||
this.origin = region.getMinimumPoint();
|
||||
this.blocks = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
||||
this.blocks = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -157,7 +158,7 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
|
||||
public List<? extends Entity> getEntities(Region region) {
|
||||
List<Entity> filtered = new ArrayList<>();
|
||||
for (Entity entity : getEntities()) {
|
||||
if (region.contains(entity.getLocation().toBlockPoint())) {
|
||||
if (region.contains(entity.getLocation().toVector().toBlockPoint())) {
|
||||
filtered.add(entity);
|
||||
}
|
||||
}
|
||||
@ -185,10 +186,6 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
|
||||
return BlockTypes.AIR.getDefaultState();
|
||||
}
|
||||
|
||||
public BlockState getBlockAbs(int x, int y, int z) {
|
||||
return IMP.getBlock(x, y, z).toImmutableState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getLazyBlock(BlockVector3 position) {
|
||||
return getBlock(position);
|
||||
@ -205,11 +202,11 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
|
||||
}
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
|
||||
if (region.contains(location)) {
|
||||
final int x = location.getBlockX();
|
||||
final int y = location.getBlockY();
|
||||
final int z = location.getBlockZ();
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws WorldEditException {
|
||||
if (region.contains(position)) {
|
||||
final int x = position.getBlockX();
|
||||
final int y = position.getBlockY();
|
||||
final int z = position.getBlockZ();
|
||||
return setBlock(x, y, z, block);
|
||||
}
|
||||
return false;
|
||||
@ -227,18 +224,39 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
|
||||
return IMP.setBlock(v.getX(), v.getY(), v.getZ(), block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBiomes() {
|
||||
return biomes != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeType getBiome(BlockVector2 position) {
|
||||
if (biomes != null
|
||||
&& position.containedWithin(getMinimumPoint().toBlockVector2(), getMaximumPoint().toBlockVector2())) {
|
||||
BlockVector2 v = position.subtract(region.getMinimumPoint().toBlockVector2());
|
||||
BiomeType biomeType = biomes[v.getBlockX()][v.getBlockZ()];
|
||||
if (biomeType != null) {
|
||||
return IMP.getBiome(v.getX(), v.getZ());
|
||||
//TODO Remove the line above and replace with this: return biomeType;
|
||||
}
|
||||
return IMP.getBiome(v.getX(), v.getZ());
|
||||
}
|
||||
return BiomeTypes.OCEAN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBiome(BlockVector2 position, BiomeType biome) {
|
||||
if (position.containedWithin(getMinimumPoint().toBlockVector2(), getMaximumPoint().toBlockVector2())) {
|
||||
BlockVector2 v = position.subtract(region.getMinimumPoint().toBlockVector2());
|
||||
IMP.setBiome(v.getX(), v.getZ(), biome);
|
||||
if (biomes == null) {
|
||||
biomes = new BiomeType[region.getWidth()][region.getLength()];
|
||||
}
|
||||
biomes[v.getBlockX()][v.getBlockZ()] = biome;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
|
@ -58,4 +58,15 @@ public interface Clipboard extends Extent {
|
||||
*/
|
||||
void setOrigin(BlockVector3 origin);
|
||||
|
||||
/**
|
||||
* Returns true if the clipboard has biome data. This can be checked since {@link Extent#getBiome(BlockVector2)}
|
||||
* strongly suggests returning {@link com.sk89q.worldedit.world.biome.BiomeTypes.OCEAN} instead of {@code null}
|
||||
* if biomes aren't present. However, it might not be desired to set areas to ocean if the clipboard is defaulting
|
||||
* to ocean, instead of having biomes explicitly set.
|
||||
*
|
||||
* @return true if the clipboard has biome data set
|
||||
*/
|
||||
default boolean hasBiomes() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -85,6 +85,7 @@ public class GroundFunction implements LayerFunction {
|
||||
if (depth == 0) {
|
||||
if (function.apply(position)) {
|
||||
affected++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,13 +20,13 @@
|
||||
package com.sk89q.worldedit.function.block;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.function.LayerFunction;
|
||||
import com.sk89q.worldedit.function.mask.BlockTypeMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
/**
|
||||
@ -65,21 +65,32 @@ public class Naturalizer implements LayerFunction {
|
||||
return mask.test(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(BlockVector3 position, int depth) throws WorldEditException {
|
||||
if (mask.test(position)) {
|
||||
affected++;
|
||||
private BlockState getTargetBlock(int depth) {
|
||||
switch (depth) {
|
||||
case 0:
|
||||
editSession.setBlock(position, BlockTypes.GRASS_BLOCK.getDefaultState());
|
||||
break;
|
||||
return BlockTypes.GRASS_BLOCK.getDefaultState();
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
editSession.setBlock(position, BlockTypes.DIRT.getDefaultState());
|
||||
break;
|
||||
return BlockTypes.DIRT.getDefaultState();
|
||||
default:
|
||||
editSession.setBlock(position, BlockTypes.STONE.getDefaultState());
|
||||
return BlockTypes.STONE.getDefaultState();
|
||||
}
|
||||
}
|
||||
private boolean naturalize(BlockVector3 position, int depth) throws WorldEditException {
|
||||
BlockState block = editSession.getBlock(position);
|
||||
BlockState targetBlock = getTargetBlock(depth);
|
||||
|
||||
if (block.equalsFuzzy(targetBlock)) {
|
||||
return false;
|
||||
}
|
||||
return editSession.setBlock(position, targetBlock);
|
||||
}
|
||||
@Override
|
||||
public boolean apply(BlockVector3 position, int depth) throws WorldEditException {
|
||||
if (mask.test(position)) {
|
||||
if (naturalize(position, depth)) {
|
||||
++affected;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ public class NoiseFilter extends AbstractMask {
|
||||
*/
|
||||
public void setDensity(double density) {
|
||||
checkArgument(density >= 0, "density must be >= 0");
|
||||
checkArgument(density <= 1, "density must be >= 1");
|
||||
checkArgument(density <= 1, "density must be <= 1");
|
||||
this.density = density;
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ public class NoiseFilter2D extends AbstractMask2D {
|
||||
*/
|
||||
public void setDensity(double density) {
|
||||
checkArgument(density >= 0, "density must be >= 0");
|
||||
checkArgument(density <= 1, "density must be >= 1");
|
||||
checkArgument(density <= 1, "density must be <= 1");
|
||||
this.density = density;
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,6 @@ public class ChangeSetExecutor implements Operation {
|
||||
* @param context an undo context
|
||||
* @return an operation
|
||||
*/
|
||||
@Deprecated
|
||||
public static ChangeSetExecutor createUndo(ChangeSet changeSet, UndoContext context) {
|
||||
return new ChangeSetExecutor(changeSet, Type.UNDO, context, null, 0);
|
||||
}
|
||||
@ -111,7 +110,6 @@ public class ChangeSetExecutor implements Operation {
|
||||
* @param context an undo context
|
||||
* @return an operation
|
||||
*/
|
||||
@Deprecated
|
||||
public static ChangeSetExecutor createRedo(ChangeSet changeSet, UndoContext context) {
|
||||
return new ChangeSetExecutor(changeSet, Type.REDO, context, null, 0);
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Makes a copy of a portion of one extent to another extent or another point.
|
||||
*
|
||||
* <p>
|
||||
* <p>This is a forward extent copy, meaning that it iterates over the blocks
|
||||
* in the source extent, and will copy as many blocks as there are in the
|
||||
* source. Therefore, interpolation will not occur to fill in the gaps.</p>
|
||||
@ -73,11 +73,11 @@ public class ForwardExtentCopy implements Operation {
|
||||
private int repetitions = 1;
|
||||
private Mask sourceMask = Masks.alwaysTrue();
|
||||
private boolean removingEntities;
|
||||
private boolean copyingEntities = true; // default to true for backwards compatibility, sort of
|
||||
private RegionFunction sourceFunction = null;
|
||||
private Transform transform = new Identity();
|
||||
private Transform currentTransform = null;
|
||||
private int affected;
|
||||
private boolean copyEntities = true;
|
||||
private boolean copyBiomes = false;
|
||||
private RegionFunction filterFunction;
|
||||
|
||||
@ -119,7 +119,7 @@ public class ForwardExtentCopy implements Operation {
|
||||
|
||||
/**
|
||||
* Get the transformation that will occur on every point.
|
||||
*
|
||||
* <p>
|
||||
* <p>The transformation will stack with each repetition.</p>
|
||||
*
|
||||
* @return a transformation
|
||||
@ -141,7 +141,7 @@ public class ForwardExtentCopy implements Operation {
|
||||
|
||||
/**
|
||||
* Get the mask that gets applied to the source extent.
|
||||
*
|
||||
* <p>
|
||||
* <p>This mask can be used to filter what will be copied from the source.</p>
|
||||
*
|
||||
* @return a source mask
|
||||
@ -150,6 +150,24 @@ public class ForwardExtentCopy implements Operation {
|
||||
return sourceMask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether entities should be copied along with blocks.
|
||||
*
|
||||
* @param copyEntities true if copying
|
||||
*/
|
||||
public void setCopyingEntities(boolean copyEntities) {
|
||||
this.copyEntities = copyEntities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether entities should be copied along with blocks.
|
||||
*
|
||||
* @return true if copying
|
||||
*/
|
||||
public boolean isCopyingEntities() {
|
||||
return copyEntities;
|
||||
}
|
||||
|
||||
public void setCopyBiomes(boolean copyBiomes) {
|
||||
this.copyBiomes = copyBiomes;
|
||||
}
|
||||
@ -189,6 +207,7 @@ public class ForwardExtentCopy implements Operation {
|
||||
*
|
||||
* @param function a source function, or null if none is to be applied
|
||||
*/
|
||||
@Deprecated
|
||||
public void setSourceFunction(RegionFunction function) {
|
||||
this.sourceFunction = function;
|
||||
}
|
||||
@ -212,24 +231,6 @@ public class ForwardExtentCopy implements Operation {
|
||||
this.repetitions = repetitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether entities should be copied along with blocks.
|
||||
*
|
||||
* @return true if copying
|
||||
*/
|
||||
public boolean isCopyingEntities() {
|
||||
return copyingEntities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether entities should be copied along with blocks.
|
||||
*
|
||||
* @param copyingEntities true if copying
|
||||
*/
|
||||
public void setCopyingEntities(boolean copyingEntities) {
|
||||
this.copyingEntities = copyingEntities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether entities that are copied should be removed.
|
||||
*
|
||||
|
@ -28,5 +28,5 @@ public interface ExtentPattern extends Pattern {
|
||||
*
|
||||
* @return the extent for this pattern
|
||||
*/
|
||||
public Extent getExtent();
|
||||
Extent getExtent();
|
||||
}
|
||||
|
@ -89,11 +89,11 @@ public class RepeatingExtentPattern extends AbstractExtentPattern {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock apply(BlockVector3 p) {
|
||||
int x = Math.abs(p.getX() + offset.getX()) % size.getBlockX() + origin.getX();
|
||||
int y = Math.abs(p.getY() + offset.getY()) % size.getBlockY() + origin.getY();
|
||||
int z = Math.abs(p.getZ() + offset.getZ()) % size.getBlockZ() + origin.getZ();
|
||||
return getExtent().getFullBlock(mutable.setComponents(x, y, z));
|
||||
public BaseBlock apply(BlockVector3 position) {
|
||||
int x = Math.abs(position.getX() + offset.getX()) % size.getBlockX();
|
||||
int y = Math.abs(position.getY() + offset.getY()) % size.getBlockY();
|
||||
int z = Math.abs(position.getZ() + offset.getZ()) % size.getBlockZ();
|
||||
return getExtent().getFullBlock(mutable.setComponents(x, y, z).add(origin));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public abstract class BreadthFirstSearch implements Operation {
|
||||
}
|
||||
}
|
||||
list.sort((o1, o2) -> (int) Math.signum(o1.lengthSq() - o2.lengthSq()));
|
||||
DIAGONAL_DIRECTIONS = list.toArray(new BlockVector3[list.size()]);
|
||||
DIAGONAL_DIRECTIONS = list.toArray(new BlockVector3[0]);
|
||||
}
|
||||
|
||||
private final RegionFunction function;
|
||||
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.internal.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Marks features that should be replaced with Google Guava but cannot
|
||||
* yet because Bukkit uses such an old version of Guava.
|
||||
*/
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Documented
|
||||
public @interface RequiresNewerGuava {
|
||||
}
|
@ -104,12 +104,12 @@ public class Expression {
|
||||
}
|
||||
|
||||
private Expression(List<Token> tokens, String... variableNames) throws ExpressionException {
|
||||
this.variableNames = variableNames;
|
||||
variables.put("e", new Constant(-1, Math.E));
|
||||
variables.put("pi", new Constant(-1, Math.PI));
|
||||
variables.put("true", new Constant(-1, 1));
|
||||
variables.put("false", new Constant(-1, 0));
|
||||
|
||||
this.variableNames = variableNames;
|
||||
variableArray = new Variable[variableNames.length];
|
||||
for (int i = 0; i < variableNames.length; i++) {
|
||||
String variableName = variableNames[i];
|
||||
|
@ -170,7 +170,8 @@ public class HeightMap {
|
||||
int originZ = minY.getBlockZ();
|
||||
|
||||
int maxY = region.getMaximumPoint().getBlockY();
|
||||
BlockStateHolder fillerAir = BlockTypes.AIR.getDefaultState();
|
||||
|
||||
BlockState fillerAir = BlockTypes.AIR.getDefaultState();
|
||||
|
||||
int blocksChanged = 0;
|
||||
|
||||
@ -181,14 +182,19 @@ public class HeightMap {
|
||||
|
||||
// Apply heightmap
|
||||
for (int z = 0; z < height; ++z) {
|
||||
int zr = z + originZ;
|
||||
for (int x = 0; x < width; ++x) {
|
||||
int curHeight = this.data[index];
|
||||
if (this.invalid != null && this.invalid[index]) continue;
|
||||
|
||||
//Clamp newHeight within the selection area
|
||||
int newHeight = Math.min(maxY4, data[index++]);
|
||||
|
||||
int curBlock = (curHeight) >> 4;
|
||||
int newBlock = (newHeight + 15) >> 4;
|
||||
|
||||
// Offset x,z to be 'real' coordinates
|
||||
int xr = x + originX;
|
||||
int zr = z + originZ;
|
||||
|
||||
// Depending on growing or shrinking we need to start at the bottom or top
|
||||
if (newHeight > curHeight) {
|
||||
@ -239,6 +245,13 @@ public class HeightMap {
|
||||
return blocksChanged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a raw heightmap to the region
|
||||
*
|
||||
* @param data the data
|
||||
* @return number of blocks affected
|
||||
* @throws MaxChangedBlocksException
|
||||
*/
|
||||
public int apply(int[] data) throws MaxChangedBlocksException {
|
||||
checkNotNull(data);
|
||||
|
||||
@ -256,14 +269,17 @@ public class HeightMap {
|
||||
// Apply heightmap
|
||||
int index = 0;
|
||||
for (int z = 0; z < height; ++z) {
|
||||
int zr = z + originZ;
|
||||
for (int x = 0; x < width; ++x, index++) {
|
||||
int curHeight = this.data[index];
|
||||
if (this.invalid != null && this.invalid[index]) continue;
|
||||
|
||||
int curHeight = this.data[index];
|
||||
|
||||
// Clamp newHeight within the selection area
|
||||
int newHeight = Math.min(maxY, data[index]);
|
||||
|
||||
// Offset x,z to be 'real' coordinates
|
||||
int xr = x + originX;
|
||||
int zr = z + originZ;
|
||||
|
||||
// Depending on growing or shrinking we need to start at the bottom or top
|
||||
if (newHeight > curHeight) {
|
||||
@ -279,7 +295,7 @@ public class HeightMap {
|
||||
session.setBlock(xr, setY, zr, tmpBlock);
|
||||
++blocksChanged;
|
||||
}
|
||||
session.setBlock(xr, newHeight, zr, existing);
|
||||
session.setBlock(BlockVector3.at(xr, newHeight, zr), existing);
|
||||
++blocksChanged;
|
||||
}
|
||||
} else if (curHeight > newHeight) {
|
||||
|
@ -44,7 +44,7 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
private double scaling;
|
||||
|
||||
public KochanekBartelsInterpolation() {
|
||||
setNodes(Collections.emptyList());
|
||||
setNodes(Collections.<Node>emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -182,19 +182,19 @@ public class AffineTransform implements Transform, Serializable {
|
||||
public AffineTransform inverse() {
|
||||
if (inverse != null) return inverse;
|
||||
double det = this.determinant();
|
||||
return inverse = new AffineTransform(
|
||||
return new AffineTransform(
|
||||
(m11 * m22 - m21 * m12) / det,
|
||||
(m02 * m21 - m22 * m01) / det,
|
||||
(m21 * m02 - m01 * m22) / det,
|
||||
(m01 * m12 - m11 * m02) / det,
|
||||
(m01 * (m22 * m13 - m12 * m23) + m02 * (m11 * m23 - m21 * m13)
|
||||
- m03 * (m11 * m22 - m21 * m12)) / det,
|
||||
(m12 * m20 - m22 * m10) / det,
|
||||
(m20 * m12 - m10 * m22) / det,
|
||||
(m00 * m22 - m20 * m02) / det,
|
||||
(m02 * m10 - m12 * m00) / det,
|
||||
(m10 * m02 - m00 * m12) / det,
|
||||
(m00 * (m12 * m23 - m22 * m13) - m02 * (m10 * m23 - m20 * m13)
|
||||
+ m03 * (m10 * m22 - m20 * m12)) / det,
|
||||
(m10 * m21 - m20 * m11) / det,
|
||||
(m01 * m20 - m21 * m00) / det,
|
||||
(m20 * m01 - m00 * m21) / det,
|
||||
(m00 * m11 - m10 * m01) / det,
|
||||
(m00 * (m21 * m13 - m11 * m23) + m01 * (m10 * m23 - m20 * m13)
|
||||
- m03 * (m10 * m21 - m20 * m11)) / det);
|
||||
@ -348,9 +348,5 @@ public class AffineTransform implements Transform, Serializable {
|
||||
return String.format("Affine[%g %g %g %g, %g %g %g %g, %g %g %g %g]}", m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23);
|
||||
}
|
||||
|
||||
private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException {
|
||||
stream.defaultReadObject();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -20,10 +20,9 @@
|
||||
package com.sk89q.worldedit.regions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector2;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.math.geom.Polygons;
|
||||
@ -34,8 +33,6 @@ import com.sk89q.worldedit.world.World;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Represents a cylindrical region.
|
||||
*/
|
||||
@ -206,7 +203,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return getMaximumY() - getMinimumY() + 1;
|
||||
return maxY - minY + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -299,6 +296,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
if (blockY < minY || blockY > maxY) {
|
||||
return false;
|
||||
}
|
||||
//todo the following lines can possibly be removed and replaced with upstream
|
||||
int px = position.getBlockX();
|
||||
int pz = position.getBlockZ();
|
||||
|
||||
|
@ -64,7 +64,7 @@ public class WorldEditExpressionEnvironment implements ExpressionEnvironment {
|
||||
|
||||
@Override
|
||||
public int getBlockTypeAbs(double x, double y, double z) {
|
||||
return extent.getBlock(toWorld(x, y, z)).getBlockType().getLegacyCombinedId() >> 4;
|
||||
return extent.getBlock(BlockVector3.at(x, y, z)).getBlockType().getLegacyCombinedId() >> 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,7 +74,7 @@ public class WorldEditExpressionEnvironment implements ExpressionEnvironment {
|
||||
|
||||
@Override
|
||||
public int getBlockTypeRel(double x, double y, double z) {
|
||||
return extent.getBlock(toWorld(x, y, z)).getBlockType().getLegacyCombinedId() >> 4;
|
||||
return extent.getBlock(toWorldRel(x, y, z).toBlockPoint()).getBlockType().getLegacyCombinedId() >> 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,17 +20,12 @@
|
||||
package com.sk89q.worldedit.registry.state;
|
||||
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.Function;
|
||||
import com.sk89q.worldedit.math.MathUtils;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
public class AbstractProperty<T> implements Property<T> {
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.session;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||
@ -48,10 +49,6 @@ import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Session manager for WorldEdit.
|
||||
@ -245,12 +242,7 @@ public class SessionManager {
|
||||
* @return the key object
|
||||
*/
|
||||
protected UUID getKey(SessionKey key) {
|
||||
// String forcedKey = System.getProperty("worldedit.session.uuidOverride");
|
||||
// if (forcedKey != null) {
|
||||
// return UUID.fromString(forcedKey);
|
||||
// } else {
|
||||
return key.getUniqueId();
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
@ -268,6 +260,7 @@ public class SessionManager {
|
||||
*/
|
||||
public synchronized void unload() {
|
||||
clear();
|
||||
timer.cancel();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,13 +22,14 @@ package com.sk89q.worldedit.util;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A collection of cardinal, ordinal, and secondary-ordinal directions.
|
||||
*/
|
||||
|
@ -38,7 +38,8 @@ import javax.annotation.Nullable;
|
||||
*/
|
||||
public class TargetBlock {
|
||||
|
||||
private World world;
|
||||
private final World world;
|
||||
|
||||
private int maxDistance;
|
||||
private double checkDistance, curDistance;
|
||||
private BlockVector3 targetPos = BlockVector3.ZERO;
|
||||
@ -121,7 +122,7 @@ public class TargetBlock {
|
||||
this.checkDistance = checkDistance;
|
||||
this.curDistance = 0;
|
||||
xRotation = (xRotation + 90) % 360;
|
||||
yRotation = yRotation * -1;
|
||||
yRotation *= -1;
|
||||
|
||||
double h = (checkDistance * Math.cos(Math.toRadians(yRotation)));
|
||||
|
||||
@ -144,15 +145,15 @@ public class TargetBlock {
|
||||
boolean searchForLastBlock = true;
|
||||
Location lastBlock = null;
|
||||
while (getNextBlock() != null) {
|
||||
if (!stopMask.test(targetPos)) {
|
||||
if (stopMask.test(targetPos)) {
|
||||
break;
|
||||
} else {
|
||||
if (searchForLastBlock) {
|
||||
lastBlock = getCurrentBlock();
|
||||
if (lastBlock.getBlockY() <= 0 || lastBlock.getBlockY() >= world.getMaxY()) {
|
||||
searchForLastBlock = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Location currentBlock = getCurrentBlock();
|
||||
|
@ -19,11 +19,10 @@
|
||||
|
||||
package com.sk89q.worldedit.util.eventbus;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Multimaps;
|
||||
import com.google.common.collect.SetMultimap;
|
||||
import com.google.common.eventbus.DeadEvent;
|
||||
import com.sk89q.worldedit.internal.annotation.RequiresNewerGuava;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -31,13 +30,11 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
/**
|
||||
* Dispatches events to listeners, and provides ways for listeners to register
|
||||
@ -46,17 +43,15 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
* <p>This class is based on Guava's {@link EventBus} but priority is supported
|
||||
* and events are dispatched at the time of call, rather than being queued up.
|
||||
* This does allow dispatching during an in-progress dispatch.</p>
|
||||
*
|
||||
* <p>This implementation utilizes naive synchronization on all getter and
|
||||
* setter methods. Dispatch does not occur when a lock has been acquired,
|
||||
* however.</p>
|
||||
*/
|
||||
public class EventBus {
|
||||
public final class EventBus {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(EventBus.class);
|
||||
|
||||
private final ReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
|
||||
private final SetMultimap<Class<?>, EventHandler> handlersByType =
|
||||
Multimaps.newSetMultimap(new HashMap<>(), this::newHandlerSet);
|
||||
HashMultimap.create();
|
||||
|
||||
/**
|
||||
* Strategy for finding handler methods in registered objects. Currently,
|
||||
@ -65,7 +60,6 @@ public class EventBus {
|
||||
*/
|
||||
private final SubscriberFindingStrategy finder = new AnnotatedSubscriberFinder();
|
||||
|
||||
@RequiresNewerGuava
|
||||
private HierarchyCache flattenHierarchyCache = new HierarchyCache();
|
||||
|
||||
/**
|
||||
@ -74,10 +68,15 @@ public class EventBus {
|
||||
* @param clazz the event class to register
|
||||
* @param handler the handler to register
|
||||
*/
|
||||
public synchronized void subscribe(Class<?> clazz, EventHandler handler) {
|
||||
public void subscribe(Class<?> clazz, EventHandler handler) {
|
||||
checkNotNull(clazz);
|
||||
checkNotNull(handler);
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
handlersByType.put(clazz, handler);
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,9 +84,14 @@ public class EventBus {
|
||||
*
|
||||
* @param handlers a map of handlers
|
||||
*/
|
||||
public synchronized void subscribeAll(Multimap<Class<?>, EventHandler> handlers) {
|
||||
public void subscribeAll(Multimap<Class<?>, EventHandler> handlers) {
|
||||
checkNotNull(handlers);
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
handlersByType.putAll(handlers);
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,10 +100,15 @@ public class EventBus {
|
||||
* @param clazz the class
|
||||
* @param handler the handler
|
||||
*/
|
||||
public synchronized void unsubscribe(Class<?> clazz, EventHandler handler) {
|
||||
public void unsubscribe(Class<?> clazz, EventHandler handler) {
|
||||
checkNotNull(clazz);
|
||||
checkNotNull(handler);
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
handlersByType.remove(clazz, handler);
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,15 +116,15 @@ public class EventBus {
|
||||
*
|
||||
* @param handlers a map of handlers
|
||||
*/
|
||||
public synchronized void unsubscribeAll(Multimap<Class<?>, EventHandler> handlers) {
|
||||
public void unsubscribeAll(Multimap<Class<?>, EventHandler> handlers) {
|
||||
checkNotNull(handlers);
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
for (Map.Entry<Class<?>, Collection<EventHandler>> entry : handlers.asMap().entrySet()) {
|
||||
Set<EventHandler> currentHandlers = getHandlersForEventType(entry.getKey());
|
||||
Collection<EventHandler> eventMethodsInListener = entry.getValue();
|
||||
|
||||
if (currentHandlers != null &&!currentHandlers.containsAll(entry.getValue())) {
|
||||
currentHandlers.removeAll(eventMethodsInListener);
|
||||
handlersByType.get(entry.getKey()).removeAll(entry.getValue());
|
||||
}
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,25 +155,23 @@ public class EventBus {
|
||||
* successfully after the event has been posted to all handlers, and
|
||||
* regardless of any exceptions thrown by handlers.
|
||||
*
|
||||
* <p>If no handlers have been subscribed for {@code event}'s class, and
|
||||
* {@code event} is not already a {@link DeadEvent}, it will be wrapped in a
|
||||
* DeadEvent and reposted.
|
||||
*
|
||||
* @param event event to post.
|
||||
*/
|
||||
public void post(Object event) {
|
||||
List<EventHandler> dispatching = new ArrayList<>();
|
||||
|
||||
synchronized (this) {
|
||||
Set<Class<?>> dispatchTypes = flattenHierarchy(event.getClass());
|
||||
|
||||
Set<Class<?>> dispatchTypes = flattenHierarchyCache.get(event.getClass());
|
||||
lock.readLock().lock();
|
||||
try {
|
||||
for (Class<?> eventType : dispatchTypes) {
|
||||
Set<EventHandler> wrappers = getHandlersForEventType(eventType);
|
||||
Set<EventHandler> wrappers = handlersByType.get(eventType);
|
||||
|
||||
if (wrappers != null && !wrappers.isEmpty()) {
|
||||
dispatching.addAll(wrappers);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
lock.readLock().unlock();
|
||||
}
|
||||
|
||||
Collections.sort(dispatching);
|
||||
@ -175,14 +182,12 @@ public class EventBus {
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches {@code event} to the handler in {@code handler}. This method
|
||||
* is an appropriate override point for subclasses that wish to make
|
||||
* event delivery asynchronous.
|
||||
* Dispatches {@code event} to the handler in {@code handler}.
|
||||
*
|
||||
* @param event event to dispatch.
|
||||
* @param handler handler that will call the handler.
|
||||
*/
|
||||
protected void dispatch(Object event, EventHandler handler) {
|
||||
private void dispatch(Object event, EventHandler handler) {
|
||||
try {
|
||||
handler.handleEvent(event);
|
||||
} catch (InvocationTargetException e) {
|
||||
@ -190,39 +195,4 @@ public class EventBus {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a mutable set of the currently registered handlers for
|
||||
* {@code type}. If no handlers are currently registered for {@code type},
|
||||
* this method may either return {@code null} or an empty set.
|
||||
*
|
||||
* @param type type of handlers to retrieve.
|
||||
* @return currently registered handlers, or {@code null}.
|
||||
*/
|
||||
synchronized Set<EventHandler> getHandlersForEventType(Class<?> type) {
|
||||
return handlersByType.get(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Set for insertion into the handler map. This is provided
|
||||
* as an override point for subclasses. The returned set should support
|
||||
* concurrent access.
|
||||
*
|
||||
* @return a new, mutable set for handlers.
|
||||
*/
|
||||
protected synchronized Set<EventHandler> newHandlerSet() {
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Flattens a class's type hierarchy into a set of Class objects. The set
|
||||
* will include all superclasses (transitively), and all interfaces
|
||||
* implemented by these superclasses.
|
||||
*
|
||||
* @param concreteClass class whose type hierarchy will be retrieved.
|
||||
* @return {@code clazz}'s complete type hierarchy, flattened and uniqued.
|
||||
*/
|
||||
Set<Class<?>> flattenHierarchy(Class<?> concreteClass) {
|
||||
return flattenHierarchyCache.get(concreteClass);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,34 +19,27 @@
|
||||
|
||||
package com.sk89q.worldedit.util.eventbus;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.sk89q.worldedit.internal.annotation.RequiresNewerGuava;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
* Holds a cache of class hierarchy.
|
||||
*
|
||||
* <p>This exists because Bukkit has an ancient version of Guava and the cache
|
||||
* library in Guava has since changed.</>
|
||||
*/
|
||||
@RequiresNewerGuava
|
||||
class HierarchyCache {
|
||||
|
||||
private final Map<Class<?>, Set<Class<?>>> cache = new WeakHashMap<>();
|
||||
private final LoadingCache<Class<?>, Set<Class<?>>> cache = CacheBuilder.newBuilder()
|
||||
.weakKeys()
|
||||
.build(CacheLoader.from(this::build));
|
||||
|
||||
public Set<Class<?>> get(Class<?> concreteClass) {
|
||||
Set<Class<?>> ret = cache.get(concreteClass);
|
||||
if (ret == null) {
|
||||
ret = build(concreteClass);
|
||||
cache.put(concreteClass, ret);
|
||||
}
|
||||
return ret;
|
||||
return cache.getUnchecked(concreteClass);
|
||||
}
|
||||
|
||||
protected Set<Class<?>> build(Class<?> concreteClass) {
|
||||
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.logging;
|
||||
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Adds a WorldEdit prefix to WorldEdit's logger messages using a handler.
|
||||
*/
|
||||
public final class WorldEditPrefixHandler extends Handler {
|
||||
|
||||
private WorldEditPrefixHandler() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
String message = record.getMessage();
|
||||
if (!message.startsWith("WorldEdit: ") && !message.startsWith("[WorldEdit] ")) {
|
||||
record.setMessage("[WorldEdit] " + message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SecurityException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the handler to the following logger name.
|
||||
*
|
||||
* @param name the logger name
|
||||
*/
|
||||
public static void register(String name) {
|
||||
//todo fix this
|
||||
//Logger.getLogger(name).addHandler(new WorldEditPrefixHandler());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user