3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-07 12:00:07 +01:00

Selective upstream merge

Signed-off-by: MattBDev <4009945+MattBDev@users.noreply.github.com>
Dieser Commit ist enthalten in:
MattBDev 2019-06-04 11:48:30 -04:00
Ursprung c73fc28847
Commit 6c94cca15e
75 geänderte Dateien mit 1039 neuen und 1182 gelöschten Zeilen

Datei anzeigen

@ -83,6 +83,9 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
// ------------------------------------------------------------------------
public Spigot_v1_13_R2() throws NoSuchFieldException, NoSuchMethodException {
// A simple test
CraftServer.class.cast(Bukkit.getServer());
// The list of tags on an NBTTagList
nbtListTagListField = NBTTagList.class.getDeclaredField("list");
nbtListTagListField.setAccessible(true);
@ -139,6 +142,7 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
@Nullable
private static String getEntityId(Entity entity) {
MinecraftKey minecraftkey = EntityTypes.getName(entity.getBukkitEntity().getHandle().P());
return minecraftkey == null ? null : minecraftkey.toString();
}

Datei anzeigen

@ -23,6 +23,7 @@ public final class ArrayWrapper<E> {
*
* @param elements The elements of the array.
*/
@SafeVarargs
public ArrayWrapper(E... elements) {
setArray(elements);
}

Datei anzeigen

@ -12,27 +12,17 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.function.Consumer;
import java.util.logging.Level;
import org.bukkit.Achievement;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.Statistic.Type;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import static com.boydti.fawe.bukkit.chat.TextualComponent.rawText;
@ -271,162 +261,6 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
return this;
}
/**
* Set the behavior of the current editing component to display information about an achievement when the client hovers over the text.
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
*
* @param name The name of the achievement to display, excluding the "achievement." prefix.
* @return This builder instance.
*/
public FancyMessage achievementTooltip(final String name) {
onHover("show_achievement", new JsonString("achievement." + name));
return this;
}
/**
* Set the behavior of the current editing component to display information about an achievement when the client hovers over the text.
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
*
* @param which The achievement to display.
* @return This builder instance.
*/
public FancyMessage achievementTooltip(final Achievement which) {
try {
Object achievement = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getNMSAchievement", Achievement.class).invoke(null, which);
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Achievement"), "name").get(achievement));
} catch (IllegalAccessException e) {
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
return this;
} catch (IllegalArgumentException e) {
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
return this;
} catch (InvocationTargetException e) {
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
return this;
}
}
/**
* Set the behavior of the current editing component to display information about a parameterless statistic when the client hovers over the text.
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
*
* @param which The statistic to display.
* @return This builder instance.
* @throws IllegalArgumentException If the statistic requires a parameter which was not supplied.
*/
public FancyMessage statisticTooltip(final Statistic which) {
Type type = which.getType();
if (type != Type.UNTYPED) {
throw new IllegalArgumentException("That statistic requires an additional " + type + " parameter!");
}
try {
Object statistic = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getNMSStatistic", Statistic.class).invoke(null, which);
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name").get(statistic));
} catch (IllegalAccessException e) {
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
return this;
} catch (IllegalArgumentException e) {
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
return this;
} catch (InvocationTargetException e) {
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
return this;
}
}
/**
* Set the behavior of the current editing component to display information about a statistic parameter with a material when the client hovers over the text.
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
*
* @param which The statistic to display.
* @param item The sole material parameter to the statistic.
* @return This builder instance.
* @throws IllegalArgumentException If the statistic requires a parameter which was not supplied, or was supplied a parameter that was not required.
*/
public FancyMessage statisticTooltip(final Statistic which, Material item) {
Type type = which.getType();
if (type == Type.UNTYPED) {
throw new IllegalArgumentException("That statistic needs no additional parameter!");
}
if ((type == Type.BLOCK && item.isBlock()) || type == Type.ENTITY) {
throw new IllegalArgumentException("Wrong parameter type for that statistic - needs " + type + "!");
}
try {
Object statistic = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getMaterialStatistic", Statistic.class, Material.class).invoke(null, which, item);
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name").get(statistic));
} catch (IllegalAccessException e) {
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
return this;
} catch (IllegalArgumentException e) {
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
return this;
} catch (InvocationTargetException e) {
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
return this;
}
}
/**
* Set the behavior of the current editing component to display information about a statistic parameter with an entity type when the client hovers over the text.
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
*
* @param which The statistic to display.
* @param entity The sole entity type parameter to the statistic.
* @return This builder instance.
* @throws IllegalArgumentException If the statistic requires a parameter which was not supplied, or was supplied a parameter that was not required.
*/
public FancyMessage statisticTooltip(final Statistic which, EntityType entity) {
Type type = which.getType();
if (type == Type.UNTYPED) {
throw new IllegalArgumentException("That statistic needs no additional parameter!");
}
if (type != Type.ENTITY) {
throw new IllegalArgumentException("Wrong parameter type for that statistic - needs " + type + "!");
}
try {
Object statistic = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getEntityStatistic", Statistic.class, EntityType.class).invoke(null, which, entity);
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name").get(statistic));
} catch (IllegalAccessException e) {
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
return this;
} catch (IllegalArgumentException e) {
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
return this;
} catch (InvocationTargetException e) {
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
return this;
}
}
/**
* Set the behavior of the current editing component to display information about an item when the client hovers over the text.
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
*
* @param itemJSON A string representing the JSON-serialized NBT data tag of an {@link ItemStack}.
* @return This builder instance.
*/
public FancyMessage itemTooltip(final String itemJSON) {
onHover("show_item", new JsonString(itemJSON)); // Seems a bit hacky, considering we have a JSON object as a parameter
return this;
}
/**
* Set the behavior of the current editing component to display information about an item when the client hovers over the text.
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
*
* @param itemStack The stack for which to display information.
* @return This builder instance.
*/
public FancyMessage itemTooltip(final ItemStack itemStack) {
try {
Object nmsItem = Reflection.getMethod(Reflection.getOBCClass("inventory.CraftItemStack"), "asNMSCopy", ItemStack.class).invoke(null, itemStack);
return itemTooltip(Reflection.getMethod(Reflection.getNMSClass("ItemStack"), "save", Reflection.getNMSClass("NBTTagCompound")).invoke(nmsItem, Reflection.getNMSClass("NBTTagCompound").newInstance()).toString());
} catch (Exception e) {
e.printStackTrace();
return this;
}
}
/**
* Set the behavior of the current editing component to display raw text when the client hovers over the text.
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
@ -579,9 +413,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
* @return This builder instance.
*/
public FancyMessage translationReplacements(final FancyMessage... replacements) {
for (FancyMessage str : replacements) {
latest().translationReplacements.add(str);
}
Collections.addAll(latest().translationReplacements, replacements);
dirty = true;
@ -873,6 +705,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
/**
* <b>Internally called method. Not for API consumption.</b>
*/
@NotNull
public Iterator<MessagePart> iterator() {
return messageParts.iterator();
}

Datei anzeigen

@ -1,7 +1,6 @@
package com.boydti.fawe.bukkit.chat;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.util.HashMap;
@ -75,48 +74,6 @@ public abstract class TextualComponent implements Cloneable {
throw new UnsupportedOperationException("This feature is only supported in snapshot releases.");
}
/**
* Create a textual component representing a scoreboard value.
* The client will see their own score for the specified objective as the text represented by this component.
* <p>
* <b>This method is currently guaranteed to throw an {@code UnsupportedOperationException} as it is only supported on snapshot clients.</b>
* </p>
*
* @param scoreboardObjective The name of the objective for which to display the score.
* @return The text component representing the specified scoreboard score (for the viewing player), or {@code null} if an error occurs during
* JSON serialization.
*/
public static TextualComponent objectiveScore(String scoreboardObjective) {
return objectiveScore("*", scoreboardObjective);
}
/**
* Create a textual component representing a scoreboard value.
* The client will see the score of the specified player for the specified objective as the text represented by this component.
*
* <p><b>This method is currently guaranteed to throw an {@code UnsupportedOperationException}
* as it is only supported on snapshot clients.</b>
*
* @param playerName The name of the player whos score will be shown. If
* this string represents the single-character sequence
* "*", the viewing player's score will be displayed.
* Standard minecraft selectors (@a, @p, etc)
* are <em>not</em> supported.
* @param scoreboardObjective The name of the objective for
* which to display the score.
* @return The text component representing the specified scoreboard score
* for the specified player, or {@code null} if an error occurs during JSON serialization.
*/
public static TextualComponent objectiveScore(String playerName, String scoreboardObjective) {
throwUnsupportedSnapshot(); // Remove this line when the feature is released to non-snapshot versions, in addition to updating ALL THE
// OVERLOADS documentation accordingly
return new ComplexTextTypeComponent("score", ImmutableMap.<String, String>builder()
.put("name", playerName)
.put("objective", scoreboardObjective)
.build());
}
/**
* Create a textual component representing a player name, retrievable by using a standard minecraft selector.
* The client will see the players or entities captured by the specified selector as the text represented by this component.

Datei anzeigen

@ -14,11 +14,9 @@ import org.bukkit.plugin.Plugin;
public class FactionsFeature extends BukkitMaskManager implements Listener {
FaweBukkit plugin;
private Plugin factions;
public FactionsFeature(final Plugin factionsPlugin, final FaweBukkit p3) {
super(factionsPlugin.getName());
this.factions = factionsPlugin;
this.plugin = p3;
}
@ -42,8 +40,7 @@ public class FactionsFeature extends BukkitMaskManager implements Listener {
}
};
}
}
else if (fac.getOnlinePlayers().contains(player)) {
} else if (fac.getOnlinePlayers().contains(player)) {
if (!fac.getComparisonName().equals("wilderness")) {
final Chunk chunk = loc.getChunk();
final Location pos1 = new Location(loc.getWorld(), chunk.getX() * 16, 0, chunk.getZ() * 16);

Datei anzeigen

@ -26,14 +26,14 @@ import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
public class Worldguard extends BukkitMaskManager implements Listener {
WorldGuardPlugin worldguard;
private WorldGuardPlugin worldguard;
FaweBukkit plugin;
private WorldGuardPlugin getWorldGuard() {
final Plugin plugin = Bukkit.getPluginManager().getPlugin("WorldGuard");
// WorldGuard may not be loaded
if ((plugin == null) || !(plugin instanceof WorldGuardPlugin)) {
if (!(plugin instanceof WorldGuardPlugin)) {
return null; // Maybe you want throw an exception instead
}
@ -46,13 +46,13 @@ public class Worldguard extends BukkitMaskManager implements Listener {
this.plugin = p3;
}
public ProtectedRegion getRegion(final com.sk89q.worldguard.LocalPlayer player, final Location loc) {
public ProtectedRegion getRegion(final LocalPlayer player, final Location location) {
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
if (container == null) {
System.out.println("Region capability is not enabled for WorldGuard.");
return null;
}
RegionManager manager = container.get(FaweAPI.getWorld(loc.getWorld().getName()));
RegionManager manager = container.get(FaweAPI.getWorld(location.getWorld().getName()));
if (manager == null) {
System.out.println("Region capability is not enabled for that world.");
return null;
@ -61,7 +61,7 @@ public class Worldguard extends BukkitMaskManager implements Listener {
if (global != null && isAllowed(player, global)) {
return global;
}
final ApplicableRegionSet regions = manager.getApplicableRegions(BlockVector3.at(loc.getX(), loc.getY(), loc.getZ()));
final ApplicableRegionSet regions = manager.getApplicableRegions(BlockVector3.at(location.getX(), location.getY(), location.getZ()));
for (final ProtectedRegion region : regions) {
if (isAllowed(player, region)) {
return region;
@ -71,7 +71,7 @@ public class Worldguard extends BukkitMaskManager implements Listener {
}
public boolean isAllowed(LocalPlayer localplayer, ProtectedRegion region) {
if (region.isOwner(localplayer) || region.isOwner(localplayer.getName())) {
if (region.isOwner(localplayer) || region.isOwner(localplayer)) {
return true;
} else if (region.getId().toLowerCase().equals(localplayer.getName().toLowerCase())) {
return true;
@ -81,7 +81,7 @@ public class Worldguard extends BukkitMaskManager implements Listener {
return true;
}
if (localplayer.hasPermission("fawe.worldguard.member")) {
if (region.isMember(localplayer) || region.isMember(localplayer.getName())) {
if (region.isMember(localplayer) || region.isMember(localplayer)) {
return true;
} else if (region.isMember("*")) {
return true;
@ -93,7 +93,7 @@ public class Worldguard extends BukkitMaskManager implements Listener {
@Override
public FaweMask getMask(FawePlayer<Player> fp, MaskType type) {
final Player player = fp.parent;
final com.sk89q.worldguard.LocalPlayer localplayer = this.worldguard.wrapPlayer(player);
final LocalPlayer localplayer = this.worldguard.wrapPlayer(player);
final Location location = player.getLocation();
final ProtectedRegion myregion = this.getRegion(localplayer, location);
if (myregion != null) {

Datei anzeigen

@ -15,49 +15,33 @@ public class BukkitReflectionUtils {
* prefix of minecraft classes
*/
private static volatile String preClassM = null;
/**
* boolean value, TRUE if server uses forge or MCPC+
*/
private static boolean forge = false;
/**
* check server version and class names
*/
public static void init() {
if (Bukkit.getServer() != null) {
if (Bukkit.getVersion().contains("MCPC") || Bukkit.getVersion().contains("Forge")) {
forge = true;
}
final Server server = Bukkit.getServer();
final Class<?> bukkitServerClass = server.getClass();
String[] pas = bukkitServerClass.getName().split("\\.");
final Server server = Bukkit.getServer();
final Class<?> bukkitServerClass = server.getClass();
String[] pas = bukkitServerClass.getName().split("\\.");
if (pas.length == 5) {
final String verB = pas[3];
preClassB = "org.bukkit.craftbukkit." + verB;
}
try {
final Method getHandle = bukkitServerClass.getDeclaredMethod("getHandle");
final Object handle = getHandle.invoke(server);
final Class handleServerClass = handle.getClass();
pas = handleServerClass.getName().split("\\.");
if (pas.length == 5) {
final String verB = pas[3];
preClassB = "org.bukkit.craftbukkit." + verB;
}
try {
final Method getHandle = bukkitServerClass.getDeclaredMethod("getHandle");
final Object handle = getHandle.invoke(server);
final Class handleServerClass = handle.getClass();
pas = handleServerClass.getName().split("\\.");
if (pas.length == 5) {
final String verM = pas[3];
preClassM = "net.minecraft.server." + verM;
}
} catch (final Exception ignored) {
MainUtil.handleError(ignored);
final String verM = pas[3];
preClassM = "net.minecraft.server." + verM;
}
} catch (final Exception e) {
MainUtil.handleError(e);
}
}
/**
* @return true if server has forge classes
*/
public static boolean isForge() {
return forge;
}
/**
* Get class for name. Replace {nms} to net.minecraft.server.V*. Replace {cb} to org.bukkit.craftbukkit.V*. Replace
* {nm} to net.minecraft

Datei anzeigen

@ -61,7 +61,7 @@ public class ItemUtil {
Int2ObjectOpenHashMap<WeakReference<Tag>> map = hashToNMSTag.get();
if (map == null) {
map = new Int2ObjectOpenHashMap<>();
hashToNMSTag = new SoftReference(new Int2ObjectOpenHashMap<>(map));
hashToNMSTag = new SoftReference<>(new Int2ObjectOpenHashMap<>(map));
}
WeakReference<Tag> nativeTagRef = map.get(nmsTag.hashCode());
if (nativeTagRef != null) {

Datei anzeigen

@ -442,7 +442,7 @@ public class Fawe {
}
public static boolean isMainThread() {
return INSTANCE != null ? INSTANCE.thread == Thread.currentThread() : true;
return INSTANCE == null || INSTANCE.thread == Thread.currentThread();
}
/**

Datei anzeigen

@ -75,7 +75,7 @@ public abstract class FaweParser<T> extends InputParser<T> {
}
}
}
inputs.add(toParse.substring(last, toParse.length()));
inputs.add(toParse.substring(last));
for (int i = 0; i < inputs.size(); i++) {
String full = inputs.get(i);
String command = full;

Datei anzeigen

@ -41,7 +41,7 @@ public class JSystemFileChooser extends JFileChooser {
private static FilePane findFilePane(Container parent){
for(Component comp: parent.getComponents()){
if(FilePane.class.isInstance(comp)){
if(comp instanceof FilePane){
return (FilePane)comp;
}
if(comp instanceof Container){

Datei anzeigen

@ -227,14 +227,14 @@ public class SchematicStreamer extends NBTStreamer {
if (forwardType.hasProperty(PropertyKey.SHAPE) && forwardType.hasProperty(PropertyKey.FACING)) {
Direction forwardFacing = (Direction) forwardBlock.getState(PropertyKey.FACING);
if (forwardFacing == left) {
BlockStateHolder rightBlock = fc.getBlock(x + right.getBlockX(), y + right.getBlockY(), z + right.getBlockZ());
BlockStateHolder rightBlock = fc.getBlock(x + right.toBlockVector().getBlockX(), y + right.toBlockVector().getBlockY(), z + right.toBlockVector().getBlockZ());
BlockType rightType = rightBlock.getBlockType();
if (!rightType.hasProperty(PropertyKey.SHAPE) || rightBlock.getState(PropertyKey.FACING) != facing) {
fc.setBlock(x, y, z, block.with(PropertyKey.SHAPE, "inner_left"));
}
return;
} else if (forwardFacing == right) {
BlockStateHolder leftBlock = fc.getBlock(x + left.getBlockX(), y + left.getBlockY(), z + left.getBlockZ());
BlockStateHolder leftBlock = fc.getBlock(x + left.toBlockVector().getBlockX(), y + left.toBlockVector().getBlockY(), z + left.toBlockVector().getBlockZ());
BlockType leftType = leftBlock.getBlockType();
if (!leftType.hasProperty(PropertyKey.SHAPE) || leftBlock.getState(PropertyKey.FACING) != facing) {
fc.setBlock(x, y, z, block.with(PropertyKey.SHAPE, "inner_right"));
@ -248,14 +248,14 @@ public class SchematicStreamer extends NBTStreamer {
if (backwardsType.hasProperty(PropertyKey.SHAPE) && backwardsType.hasProperty(PropertyKey.FACING)) {
Direction backwardsFacing = (Direction) backwardsBlock.getState(PropertyKey.FACING);
if (backwardsFacing == left) {
BlockStateHolder rightBlock = fc.getBlock(x + right.getBlockX(), y + right.getBlockY(), z + right.getBlockZ());
BlockStateHolder rightBlock = fc.getBlock(x + right.toBlockVector().getBlockX(), y + right.toBlockVector().getBlockY(), z + right.toBlockVector().getBlockZ());
BlockType rightType = rightBlock.getBlockType();
if (!rightType.hasProperty(PropertyKey.SHAPE) || rightBlock.getState(PropertyKey.FACING) != facing) {
fc.setBlock(x, y, z, block.with(PropertyKey.SHAPE, "outer_left"));
}
return;
} else if (backwardsFacing == right) {
BlockStateHolder leftBlock = fc.getBlock(x + left.getBlockX(), y + left.getBlockY(), z + left.getBlockZ());
BlockStateHolder leftBlock = fc.getBlock(x + left.toBlockVector().getBlockX(), y + left.toBlockVector().getBlockY(), z + left.toBlockVector().getBlockZ());
BlockType leftType = leftBlock.getBlockType();
if (!leftType.hasProperty(PropertyKey.SHAPE) || leftBlock.getState(PropertyKey.FACING) != facing) {
fc.setBlock(x, y, z, block.with(PropertyKey.SHAPE, "outer_right"));

Datei anzeigen

@ -14,7 +14,6 @@ import java.util.concurrent.ForkJoinPool;
public class MCAFilter<T> extends IterableThreadLocal<T> {
public void withPool(ForkJoinPool pool, MCAQueue queue) {
return;
}
/**

Datei anzeigen

@ -621,8 +621,8 @@ public class MCAQueue extends NMSMappedFaweQueue<FaweQueue, FaweChunk, FaweChunk
@Override
public boolean supports(Capability capability) {
switch (capability) {
case CHANGE_TASKS: return false;
if (capability == Capability.CHANGE_TASKS) {
return false;
}
return super.supports(capability);
}
@ -823,4 +823,4 @@ public class MCAQueue extends NMSMappedFaweQueue<FaweQueue, FaweChunk, FaweChunk
parentNMS.sendBlockUpdate(chunk, players);
}
}
}
}

Datei anzeigen

@ -108,9 +108,7 @@ public class WritableMCAChunk extends FaweChunk<Void> {
}
out.writeNamedTag("InhabitedTime", inhabitedTime);
out.writeNamedTag("LastUpdate", lastUpdate);
if (biomes != null) {
out.writeNamedTag("Biomes", biomes);
}
out.writeNamedTag("Biomes", biomes);
int len = 0;
for (boolean hasSection : hasSections) {
if (hasSection) len++;

Datei anzeigen

@ -98,7 +98,7 @@ public abstract class FawePlayer<T> extends Metadatable {
FakePlayer fake = new FakePlayer(actor.getName(), actor.getUniqueId(), actor);
return fake.toFawePlayer();
}
if (obj != null && obj.getClass().getName().contains("CraftPlayer") && !Fawe.imp().getPlatform().equals("bukkit")) {
if (obj.getClass().getName().contains("CraftPlayer") && !Fawe.imp().getPlatform().equals("bukkit")) {
try {
Method methodGetHandle = obj.getClass().getDeclaredMethod("getHandle");
obj = methodGetHandle.invoke(obj);
@ -206,7 +206,7 @@ public abstract class FawePlayer<T> extends Metadatable {
if (region != null) {
BlockVector3 min = region.getMinimumPoint();
BlockVector3 max = region.getMaximumPoint();
long area = (long) ((max.getX() - min.getX()) * (max.getZ() - min.getZ() + 1));
long area = (max.getX() - min.getX()) * (max.getZ() - min.getZ() + 1);
if (area > 2 << 18) {
setConfirmTask(task, context, command);
BlockVector3 base = max.subtract(min).add(BlockVector3.ONE);
@ -220,7 +220,7 @@ public abstract class FawePlayer<T> extends Metadatable {
public synchronized boolean confirm() {
Runnable confirm = deleteMeta("cmdConfirm");
if (!(confirm instanceof Runnable)) {
if (confirm == null) {
return false;
}
queueAction(() -> {
@ -341,7 +341,7 @@ public abstract class FawePlayer<T> extends Metadatable {
if (session.getClipboard() != null) {
return;
}
} catch (EmptyClipboardException e) {
} catch (EmptyClipboardException ignored) {
}
if (player != null) {
Clipboard clip = doc.toClipboard();

Datei anzeigen

@ -222,7 +222,7 @@ public class BrushSettings {
}
public BrushSettings addPermissions(String... perms) {
for (String perm : perms) permissions.add(perm);
Collections.addAll(permissions, perms);
return this;
}

Datei anzeigen

@ -45,7 +45,7 @@ public class SweepBrush implements Brush, ResettableTool {
return;
}
boolean newPos = this.position == null || !position.equals(this.position);
boolean newPos = !position.equals(this.position);
this.position = position;
FawePlayer player = editSession.getPlayer();
if (newPos) {
@ -98,7 +98,6 @@ public class SweepBrush implements Brush, ResettableTool {
MutableVector3 last = new MutableVector3(0, 0, 0);
for (double pos = 0D; pos <= 1D; pos += step) {
Vector3 gradient = interpol.get1stDerivative(pos);
if (last == null) last = new MutableVector3(interpol.get1stDerivative(pos));
double dist = MathMan.sqrtApprox(last.distanceSq(gradient));
last.mutX(gradient.getX());
last.mutY(gradient.getY());

Datei anzeigen

@ -2,7 +2,6 @@ package com.boydti.fawe.object.changeset;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.logging.rollback.RollbackOptimizedHistory;
import com.boydti.fawe.object.FaweChunk;
@ -14,9 +13,6 @@ import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.TaskManager;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockID;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.history.change.BlockChange;
import com.sk89q.worldedit.history.change.Change;
@ -27,7 +23,8 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockID;
import java.util.Iterator;
import java.util.Map;
@ -58,7 +55,7 @@ public abstract class FaweChangeSet implements ChangeSet {
public FaweChangeSet(String world) {
this.worldName = world;
this.mainThread = (Fawe.get() != null) ? Fawe.isMainThread() : true;
this.mainThread = (Fawe.get() == null) || Fawe.isMainThread();
this.layers = FaweChunk.HEIGHT >> 4;
}
@ -85,15 +82,12 @@ public abstract class FaweChangeSet implements ChangeSet {
public boolean closeAsync() {
waitingAsync.incrementAndGet();
TaskManager.IMP.async(new Runnable() {
@Override
public void run() {
waitingAsync.decrementAndGet();
synchronized (waitingAsync) {
waitingAsync.notifyAll();
}
close();
TaskManager.IMP.async(() -> {
waitingAsync.decrementAndGet();
synchronized (waitingAsync) {
waitingAsync.notifyAll();
}
close();
});
return true;
}
@ -153,8 +147,6 @@ public abstract class FaweChangeSet implements ChangeSet {
public void delete() {
}
;
public EditSession toEditSession(FawePlayer player) {
return toEditSession(player, null);
}
@ -258,115 +250,109 @@ public abstract class FaweChangeSet implements ChangeSet {
@Override
public void run(final FaweChunk previous, final FaweChunk next) {
FaweChangeSet.this.waitingCombined.incrementAndGet();
Runnable run = new Runnable() {
@Override
public void run() {
try {
int cx = previous.getX();
int cz = previous.getZ();
int bx = cx << 4;
int bz = cz << 4;
synchronized (FaweChangeSet.this) {
BiomeType[] previousBiomes = previous.getBiomeArray();
if (previousBiomes != null) {
BiomeType[] nextBiomes = next.getBiomeArray();
int index = 0;
for (int z = 0; z < 16; z++) {
int zz = bz + z;
for (int x = 0; x < 16; x++) {
BiomeType idFrom = previousBiomes[index];
BiomeType idTo = nextBiomes[index];
if (idFrom != idTo && idTo != null) {
addBiomeChange(bx + x, zz, idFrom, idTo);
}
index++;
Runnable run = () -> {
try {
int cx = previous.getX();
int cz = previous.getZ();
int bx = cx << 4;
int bz = cz << 4;
synchronized (FaweChangeSet.this) {
BiomeType[] previousBiomes = previous.getBiomeArray();
if (previousBiomes != null) {
BiomeType[] nextBiomes = next.getBiomeArray();
int index = 0;
for (int z = 0; z < 16; z++) {
int zz = bz + z;
for (int x = 0; x < 16; x++) {
BiomeType idFrom = previousBiomes[index];
BiomeType idTo = nextBiomes[index];
if (idFrom != idTo && idTo != null) {
addBiomeChange(bx + x, zz, idFrom, idTo);
}
index++;
}
}
// Block changes
for (int layer = 0; layer < layers; layer++) {
int[] currentLayer = next.getIdArray(layer);
int[] previousLayer = previous.getIdArray(layer);
if (currentLayer == null) {
continue;
}
int startY = layer << 4;
int index = 0;
for (int y = 0; y < 16; y++) {
int yy = y + startY;
for (int z = 0; z < 16; z++) {
int zz = z + bz;
for (int x = 0; x < 16; x++, index++) {
int xx = x + bx;
int combinedIdCurrent = currentLayer[index];
switch (combinedIdCurrent) {
case 0:
continue;
default:
int combinedIdPrevious;
if (previousLayer != null) {
combinedIdPrevious = previousLayer[index];
if (combinedIdPrevious == 0) {
combinedIdPrevious = BlockID.AIR;
}
} else {
combinedIdPrevious = BlockID.AIR;
}
if (combinedIdCurrent != combinedIdPrevious) {
add(xx, yy, zz, combinedIdPrevious, combinedIdCurrent);
}
}
// Block changes
for (int layer = 0; layer < layers; layer++) {
int[] currentLayer = next.getIdArray(layer);
int[] previousLayer = previous.getIdArray(layer);
if (currentLayer == null) {
continue;
}
int startY = layer << 4;
int index = 0;
for (int y = 0; y < 16; y++) {
int yy = y + startY;
for (int z = 0; z < 16; z++) {
int zz = z + bz;
for (int x = 0; x < 16; x++, index++) {
int xx = x + bx;
int combinedIdCurrent = currentLayer[index];
if (combinedIdCurrent != 0) {
int combinedIdPrevious;
if (previousLayer != null) {
combinedIdPrevious = previousLayer[index];
if (combinedIdPrevious == 0) {
combinedIdPrevious = BlockID.AIR;
}
} else {
combinedIdPrevious = BlockID.AIR;
}
if (combinedIdCurrent != combinedIdPrevious) {
add(xx, yy, zz, combinedIdPrevious, combinedIdCurrent);
}
}
}
}
}
// Tile changes
{
// Tiles created
Map<Short, CompoundTag> tiles = next.getTiles();
if (!tiles.isEmpty()) {
for (Map.Entry<Short, CompoundTag> entry : tiles.entrySet()) {
addTileCreate(entry.getValue());
}
}
// Tiles removed
tiles = previous.getTiles();
if (!tiles.isEmpty()) {
for (Map.Entry<Short, CompoundTag> entry : tiles.entrySet()) {
addTileRemove(entry.getValue());
}
}
// Tile changes
{
// Tiles created
Map<Short, CompoundTag> tiles = next.getTiles();
if (!tiles.isEmpty()) {
for (Map.Entry<Short, CompoundTag> entry : tiles.entrySet()) {
addTileCreate(entry.getValue());
}
}
// Entity changes
{
// Entities created
Set<CompoundTag> entities = next.getEntities();
if (!entities.isEmpty()) {
for (CompoundTag entityTag : entities) {
addEntityCreate(entityTag);
}
}
// Entities removed
entities = previous.getEntities();
if (!entities.isEmpty()) {
for (CompoundTag entityTag : entities) {
addEntityRemove(entityTag);
}
// Tiles removed
tiles = previous.getTiles();
if (!tiles.isEmpty()) {
for (Map.Entry<Short, CompoundTag> entry : tiles.entrySet()) {
addTileRemove(entry.getValue());
}
}
}
} catch (Throwable e) {
MainUtil.handleError(e);
} finally {
if (FaweChangeSet.this.waitingCombined.decrementAndGet() <= 0) {
synchronized (FaweChangeSet.this.waitingAsync) {
FaweChangeSet.this.waitingAsync.notifyAll();
// Entity changes
{
// Entities created
Set<CompoundTag> entities = next.getEntities();
if (!entities.isEmpty()) {
for (CompoundTag entityTag : entities) {
addEntityCreate(entityTag);
}
}
synchronized (FaweChangeSet.this.waitingCombined) {
FaweChangeSet.this.waitingCombined.notifyAll();
// Entities removed
entities = previous.getEntities();
if (!entities.isEmpty()) {
for (CompoundTag entityTag : entities) {
addEntityRemove(entityTag);
}
}
}
}
} catch (Throwable e) {
MainUtil.handleError(e);
} finally {
if (FaweChangeSet.this.waitingCombined.decrementAndGet() <= 0) {
synchronized (FaweChangeSet.this.waitingAsync) {
FaweChangeSet.this.waitingAsync.notifyAll();
}
synchronized (FaweChangeSet.this.waitingCombined) {
FaweChangeSet.this.waitingCombined.notifyAll();
}
}
}
};
if (mainThread) {
@ -377,4 +363,4 @@ public abstract class FaweChangeSet implements ChangeSet {
}
});
}
}
}

Datei anzeigen

@ -229,8 +229,8 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
// skip mode
int mode = is.read();
// origin
int x = ((is.read() << 24) + (is.read() << 16) + (is.read() << 8) + (is.read() << 0));
int z = ((is.read() << 24) + (is.read() << 16) + (is.read() << 8) + (is.read() << 0));
int x = ((is.read() << 24) + (is.read() << 16) + (is.read() << 8) + is.read());
int z = ((is.read() << 24) + (is.read() << 16) + (is.read() << 8) + is.read());
setOrigin(x, z);
setupStreamDelegates(mode);
}
@ -328,7 +328,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
public void addBiomeChange(int x, int z, BiomeType from, BiomeType to) {
blockSize++;
try {
OutputStream os = getBiomeOS();
FaweOutputStream os = getBiomeOS();
os.write((byte) (x >> 24));
os.write((byte) (x >> 16));
os.write((byte) (x >> 8));
@ -337,8 +337,8 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
os.write((byte) (z >> 16));
os.write((byte) (z >> 8));
os.write((byte) (z));
((FaweOutputStream) os).writeVarInt(from.getInternalId());
((FaweOutputStream) os).writeVarInt(to.getInternalId());
os.writeVarInt(from.getInternalId());
os.writeVarInt(to.getInternalId());
} catch (Throwable e) {
MainUtil.handleError(e);
}
@ -412,7 +412,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
change.z = posDel.readZ(is) + originZ;
idDel.readCombined(is, change, dir);
return change;
} catch (EOFException ignoreOEF) {
} catch (EOFException ignored) {
} catch (Exception e) {
e.printStackTrace();
MainUtil.handleError(e);
@ -448,7 +448,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
}
public Iterator<MutableBiomeChange> getBiomeIterator(final boolean dir) throws IOException {
final InputStream is = getBiomeIS();
final FaweInputStream is = getBiomeIS();
if (is == null) {
return new ArrayList<MutableBiomeChange>().iterator();
}
@ -460,14 +460,14 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
try {
int int1 = is.read();
if (int1 != -1) {
int x = ((int1 << 24) + (is.read() << 16) + (is.read() << 8) + (is.read() << 0));
int z = ((is.read() << 24) + (is.read() << 16) + (is.read() << 8) + (is.read() << 0));
int from = ((FaweInputStream) is).readVarInt();
int to = ((FaweInputStream) is).readVarInt();
int x = ((int1 << 24) + (is.read() << 16) + (is.read() << 8) + is.read());
int z = ((is.read() << 24) + (is.read() << 16) + (is.read() << 8) + is.read());
int from = is.readVarInt();
int to = is.readVarInt();
change.setBiome(x, z, from, to);
return change;
}
} catch (EOFException ignoreOEF) {
} catch (EOFException ignored) {
} catch (Exception e) {
e.printStackTrace();
MainUtil.handleError(e);
@ -516,9 +516,6 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
public Iterator<MutableFullBlockChange> getFullBlockIterator(BlockBag blockBag, int inventory, final boolean dir) throws IOException {
final FaweInputStream is = new FaweInputStream(getBlockIS());
if (is == null) {
return new ArrayList<MutableFullBlockChange>().iterator();
}
final MutableFullBlockChange change = new MutableFullBlockChange(blockBag, inventory, dir);
return new Iterator<MutableFullBlockChange>() {
private MutableFullBlockChange last = read();
@ -530,7 +527,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
change.z = posDel.readZ(is) + originZ;
idDel.readCombined(is, change, dir);
return change;
} catch (EOFException ignoreOEF) {
} catch (EOFException ignored) {
} catch (Exception e) {
e.printStackTrace();
MainUtil.handleError(e);
@ -576,10 +573,9 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
public MutableEntityChange read() {
try {
CompoundTag tag = (CompoundTag) is.readTag();
change.tag = tag;
change.tag = (CompoundTag) is.readTag();
return change;
} catch (Exception ignoreOEF) {
} catch (Exception ignored) {
}
try {
is.close();
@ -626,10 +622,9 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
public MutableTileChange read() {
try {
CompoundTag tag = (CompoundTag) is.readTag();
change.tag = tag;
change.tag = (CompoundTag) is.readTag();
return change;
} catch (Exception ignoreOEF) {
} catch (Exception ignored) {
}
try {
is.close();

Datei anzeigen

@ -24,6 +24,7 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import sun.misc.Unsafe;
import java.io.Closeable;
import java.io.File;
@ -209,7 +210,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
MainUtil.handleError(e);
}
this.braf = new RandomAccessFile(file, "rw");
long volume = (long) width * (long) height * (long) length * 4l + (long) HEADER_SIZE;
long volume = (long) width * (long) height * (long) length * 4L + (long) HEADER_SIZE;
braf.setLength(0);
braf.setLength(volume);
if (width * height * length != 0) {
@ -243,7 +244,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
length = dimensions.getBlockZ();
area = width * length;
volume = width * length * height;
long size = width * height * length * 4l + HEADER_SIZE + (hasBiomes() ? area : 0);
long size = width * height * length * 4L + HEADER_SIZE + (hasBiomes() ? area : 0);
if (braf.length() < size) {
close();
this.braf = new RandomAccessFile(file, "rw");
@ -505,7 +506,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
mbb.putInt(index, combined);
boolean hasNbt = block instanceof BaseBlock && ((BaseBlock)block).hasNbtData();
if (hasNbt) {
setTile(x, y, z, ((BaseBlock)block).getNbtData());
setTile(x, y, z, block.getNbtData());
}
return true;
} catch (Exception e) {
@ -520,13 +521,13 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
int combined = block.getInternalId();
int index = (HEADER_SIZE) + (i << 2);
mbb.putInt(index, combined);
boolean hasNbt = block instanceof BaseBlock && ((BaseBlock)block).hasNbtData();
boolean hasNbt = block instanceof BaseBlock && block.hasNbtData();
if (hasNbt) {
int y = i / area;
int newI = (i - (y * area));
int z = newI / width;
int x = newI - z * width;
setTile(x, y, z, ((BaseBlock)block).getNbtData());
setTile(x, y, z, block.getNbtData());
}
return true;
} catch (Exception e) {

Datei anzeigen

@ -2,8 +2,6 @@ package com.boydti.fawe.object.clipboard;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
@ -14,12 +12,13 @@ import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
public class EmptyClipboard implements Clipboard {

Datei anzeigen

@ -77,7 +77,7 @@ public class ResizableClipboardBuilder extends MemoryOptimizedHistory {
int x = tileChange.tag.getInt("x");
int y = tileChange.tag.getInt("y");
int z = tileChange.tag.getInt("z");
clipboard.setTile(x, y, z, tileChange.tag);
clipboard.setTile(BlockVector3.at(x,y,z), tileChange.tag);
}
}
} catch (WorldEditException e) {

Datei anzeigen

@ -7,13 +7,9 @@ import com.sk89q.worldedit.math.MutableBlockVector3;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectIterator;
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Set;
import org.jetbrains.annotations.NotNull;
import java.util.*;
/**
* The BlockVectorSet is a Memory optimized Set for storing BlockVectors
@ -35,23 +31,19 @@ public class BlockVectorSet extends AbstractCollection<BlockVector3> implements
public BlockVector3 get(int index) {
int count = 0;
ObjectIterator<Int2ObjectMap.Entry<LocalBlockVectorSet>> iter = localSets.int2ObjectEntrySet().iterator();
while (iter.hasNext()) {
Int2ObjectMap.Entry<LocalBlockVectorSet> entry = iter.next();
for (Int2ObjectMap.Entry<LocalBlockVectorSet> entry : localSets.int2ObjectEntrySet()) {
LocalBlockVectorSet set = entry.getValue();
int size = set.size();
int newSize = count + size;
if (newSize > index) {
int localIndex = index - count;
MutableBlockVector3 pos = new MutableBlockVector3(set.getIndex(localIndex));
if (pos != null) {
int pair = entry.getIntKey();
int cx = MathMan.unpairX(pair);
int cz = MathMan.unpairY(pair);
pos.mutX((cx << 11) + pos.getBlockX());
pos.mutZ((cz << 11) + pos.getBlockZ());
return pos;
}
int pair = entry.getIntKey();
int cx = MathMan.unpairX(pair);
int cz = MathMan.unpairY(pair);
pos.mutX((cx << 11) + pos.getBlockX());
pos.mutZ((cz << 11) + pos.getBlockZ());
return pos;
}
count += newSize;
}
@ -83,11 +75,12 @@ public class BlockVectorSet extends AbstractCollection<BlockVector3> implements
return false;
}
@NotNull
@Override
public Iterator<BlockVector3> iterator() {
final ObjectIterator<Int2ObjectMap.Entry<LocalBlockVectorSet>> entries = localSets.int2ObjectEntrySet().iterator();
if (!entries.hasNext()) {
return new ArrayList<BlockVector3>().iterator();
return Collections.emptyIterator();
}
return new Iterator<BlockVector3>() {
Int2ObjectMap.Entry<LocalBlockVectorSet> entry = entries.next();
@ -182,7 +175,7 @@ public class BlockVectorSet extends AbstractCollection<BlockVector3> implements
}
@Override
public boolean retainAll(Collection<?> c) {
public boolean retainAll(@NotNull Collection<?> c) {
Objects.requireNonNull(c);
boolean modified = false;
Iterator it = iterator();
@ -209,4 +202,4 @@ public class BlockVectorSet extends AbstractCollection<BlockVector3> implements
public void clear() {
localSets.clear();
}
}
}

Datei anzeigen

@ -6,6 +6,7 @@ import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.regions.Region;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
public class HeightBoundExtent extends FaweRegionExtent {
@ -35,6 +36,6 @@ public class HeightBoundExtent extends FaweRegionExtent {
@Override
public Collection<Region> getRegions() {
return Arrays.asList(new RegionWrapper(Integer.MIN_VALUE, Integer.MAX_VALUE, min, max, Integer.MIN_VALUE, Integer.MAX_VALUE));
return Collections.singletonList(new RegionWrapper(Integer.MIN_VALUE, Integer.MAX_VALUE, min, max, Integer.MIN_VALUE, Integer.MAX_VALUE));
}
}

Datei anzeigen

@ -5,6 +5,7 @@ import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.regions.Region;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
public class SingleRegionExtent extends FaweRegionExtent {
@ -32,6 +33,6 @@ public class SingleRegionExtent extends FaweRegionExtent {
@Override
public Collection<Region> getRegions() {
return Arrays.asList(region);
return Collections.singletonList(region);
}
}

Datei anzeigen

@ -103,7 +103,7 @@ public abstract class DFSVisitor implements Operation {
BlockVector3 bv2 = BlockVector3.at(from.getX() + direction.x, from.getY() + direction.y, from.getZ() + direction.z);
if (isVisitable(bv, bv2)) {
adjacent = new Node(bv2.getBlockX(), bv2.getBlockY(), bv2.getBlockZ());
if ((current.from == null || !adjacent.equals(current.from))) {
if ((!adjacent.equals(current.from))) {
AtomicInteger adjacentCount = visited.get(adjacent);
if (adjacentCount == null) {
if (countAdd++ < maxBranch) {

Datei anzeigen

@ -8,6 +8,7 @@ import com.boydti.fawe.util.ExtentTraverser;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector2;
import org.jetbrains.annotations.NotNull;
import java.util.Iterator;
import javax.annotation.Nonnull;
@ -27,18 +28,19 @@ public class FastChunkIterator implements Iterable<BlockVector2> {
}
public FastChunkIterator(@Nonnull Iterable<? extends BlockVector2> iter, @Nullable HasFaweQueue editSession) {
this(iter, (FaweQueue) (editSession != null ? editSession.getQueue() : null));
this(iter, editSession != null ? editSession.getQueue() : null);
}
public FastChunkIterator(@Nonnull Iterable<? extends BlockVector2> iter, @Nullable FaweQueue faweQueue) {
this.iterable = iter;
this.queue = faweQueue != null && faweQueue instanceof MappedFaweQueue ? (MappedFaweQueue) faweQueue : null;
this.queue = faweQueue instanceof MappedFaweQueue ? (MappedFaweQueue) faweQueue : null;
}
public Iterable<? extends BlockVector2> getIterable() {
return iterable;
}
@NotNull
@Override
public Iterator<BlockVector2> iterator() {
if (queue == null || Settings.IMP.QUEUE.PRELOAD_CHUNKS <= 1) {

Datei anzeigen

@ -44,66 +44,57 @@ public class FaweChunkManager extends ChunkManager {
@Override
public void swap(final Location pos1, final Location pos2, final Location pos3, final Location pos4, final Runnable whenDone) {
TaskManager.IMP.async(new Runnable() {
@Override
public void run() {
synchronized (FaweChunkManager.class) {
EditSession sessionA = new EditSessionBuilder(pos1.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
EditSession sessionB = new EditSessionBuilder(pos3.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
CuboidRegion regionA = new CuboidRegion(BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()), BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ()));
CuboidRegion regionB = new CuboidRegion(BlockVector3.at(pos3.getX(), pos3.getY(), pos3.getZ()), BlockVector3.at(pos4.getX(), pos4.getY(), pos4.getZ()));
ForwardExtentCopy copyA = new ForwardExtentCopy(sessionA, regionA, sessionB, regionB.getMinimumPoint());
ForwardExtentCopy copyB = new ForwardExtentCopy(sessionB, regionB, sessionA, regionA.getMinimumPoint());
try {
Operations.completeLegacy(copyA);
Operations.completeLegacy(copyB);
sessionA.flushQueue();
sessionB.flushQueue();
} catch (MaxChangedBlocksException e) {
e.printStackTrace();
}
TaskManager.IMP.task(whenDone);
TaskManager.IMP.async(() -> {
synchronized (FaweChunkManager.class) {
EditSession sessionA = new EditSessionBuilder(pos1.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
EditSession sessionB = new EditSessionBuilder(pos3.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
CuboidRegion regionA = new CuboidRegion(BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()), BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ()));
CuboidRegion regionB = new CuboidRegion(BlockVector3.at(pos3.getX(), pos3.getY(), pos3.getZ()), BlockVector3.at(pos4.getX(), pos4.getY(), pos4.getZ()));
ForwardExtentCopy copyA = new ForwardExtentCopy(sessionA, regionA, sessionB, regionB.getMinimumPoint());
ForwardExtentCopy copyB = new ForwardExtentCopy(sessionB, regionB, sessionA, regionA.getMinimumPoint());
try {
Operations.completeLegacy(copyA);
Operations.completeLegacy(copyB);
sessionA.flushQueue();
sessionB.flushQueue();
} catch (MaxChangedBlocksException e) {
e.printStackTrace();
}
TaskManager.IMP.task(whenDone);
}
});
}
@Override
public boolean copyRegion(final Location pos1, final Location pos2, final Location pos3, final Runnable whenDone) {
TaskManager.IMP.async(new Runnable() {
@Override
public void run() {
synchronized (FaweChunkManager.class) {
EditSession from = new EditSessionBuilder(pos1.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
EditSession to = new EditSessionBuilder(pos3.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
CuboidRegion region = new CuboidRegion(BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()), BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ()));
ForwardExtentCopy copy = new ForwardExtentCopy(from, region, to, BlockVector3.at(pos3.getX(), pos3.getY(), pos3.getZ()));
try {
Operations.completeLegacy(copy);
to.flushQueue();
} catch (MaxChangedBlocksException e) {
e.printStackTrace();
}
TaskManager.IMP.async(() -> {
synchronized (FaweChunkManager.class) {
EditSession from = new EditSessionBuilder(pos1.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
EditSession to = new EditSessionBuilder(pos3.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
CuboidRegion region = new CuboidRegion(BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()), BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ()));
ForwardExtentCopy copy = new ForwardExtentCopy(from, region, to, BlockVector3.at(pos3.getX(), pos3.getY(), pos3.getZ()));
try {
Operations.completeLegacy(copy);
to.flushQueue();
} catch (MaxChangedBlocksException e) {
e.printStackTrace();
}
TaskManager.IMP.task(whenDone);
}
TaskManager.IMP.task(whenDone);
});
return true;
}
@Override
public boolean regenerateRegion(final Location pos1, final Location pos2, boolean ignore, final Runnable whenDone) {
TaskManager.IMP.async(new Runnable() {
@Override
public void run() {
synchronized (FaweChunkManager.class) {
EditSession editSession = new EditSessionBuilder(pos1.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
World world = editSession.getWorld();
CuboidRegion region = new CuboidRegion(BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()), BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ()));
world.regenerate(region, editSession);
editSession.flushQueue();
TaskManager.IMP.task(whenDone);
}
TaskManager.IMP.async(() -> {
synchronized (FaweChunkManager.class) {
EditSession editSession = new EditSessionBuilder(pos1.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
World world = editSession.getWorld();
CuboidRegion region = new CuboidRegion(BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()), BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ()));
world.regenerate(region, editSession);
editSession.flushQueue();
TaskManager.IMP.task(whenDone);
}
});
return true;

Datei anzeigen

@ -1,11 +1,8 @@
package com.boydti.fawe.regions.general.plot;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.object.FaweOutputStream;
import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.object.clipboard.ReadOnlyClipboard;
import com.boydti.fawe.object.io.FastByteArrayOutputStream;
import com.boydti.fawe.object.io.FastByteArraysInputStream;
import com.boydti.fawe.object.io.PGZIPOutputStream;
import com.boydti.fawe.util.EditSessionBuilder;
import com.boydti.fawe.util.IOUtil;
@ -22,15 +19,12 @@ import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.CompressedCompoundTag;
import com.sk89q.jnbt.CompressedSchematicTag;
import com.sk89q.jnbt.NBTOutputStream;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.SpongeSchematicWriter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import net.jpountz.lz4.LZ4BlockInputStream;
import net.jpountz.lz4.LZ4BlockOutputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
@ -45,7 +39,6 @@ import java.net.URL;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.zip.GZIPInputStream;
public class FaweSchematicHandler extends SchematicHandler {
@Override
@ -62,25 +55,22 @@ public class FaweSchematicHandler extends SchematicHandler {
@Override
public void getCompoundTag(final String world, final Set<RegionWrapper> regions, final RunnableVal<CompoundTag> whenDone) {
TaskManager.IMP.async(new Runnable() {
@Override
public void run() {
Location[] corners = MainUtil.getCorners(world, regions);
Location pos1 = corners[0];
Location pos2 = corners[1];
final CuboidRegion region = new CuboidRegion(BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()), BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ()));
final EditSession editSession = new EditSessionBuilder(world).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
TaskManager.IMP.async(() -> {
Location[] corners = MainUtil.getCorners(world, regions);
Location pos1 = corners[0];
Location pos2 = corners[1];
final CuboidRegion region = new CuboidRegion(BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()), BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ()));
final EditSession editSession = new EditSessionBuilder(world).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
final int mx = pos1.getX();
final int my = pos1.getY();
final int mz = pos1.getZ();
final int mx = pos1.getX();
final int my = pos1.getY();
final int mz = pos1.getZ();
ReadOnlyClipboard clipboard = ReadOnlyClipboard.of(editSession, region);
ReadOnlyClipboard clipboard = ReadOnlyClipboard.of(editSession, region);
Clipboard holder = new BlockArrayClipboard(region, clipboard);
CompressedSchematicTag tag = new CompressedSchematicTag(holder);
whenDone.run(tag);
}
Clipboard holder = new BlockArrayClipboard(region, clipboard);
CompressedSchematicTag tag = new CompressedSchematicTag(holder);
whenDone.run(tag);
});
}
@ -109,7 +99,7 @@ public class FaweSchematicHandler extends SchematicHandler {
} else {
try (OutputStream stream = new FileOutputStream(tmp); NBTOutputStream output = new NBTOutputStream(new PGZIPOutputStream(stream))) {
Map<String, com.sk89q.jnbt.Tag> map = tag.getValue();
output.writeNamedTag("Schematic", map.containsKey("Schematic") ? map.get("Schematic") : tag);
output.writeNamedTag("Schematic", map.getOrDefault("Schematic", tag));
}
}
} catch (FileNotFoundException e) {
@ -136,7 +126,7 @@ public class FaweSchematicHandler extends SchematicHandler {
com.sk89q.jnbt.CompoundTag weTag = (com.sk89q.jnbt.CompoundTag) FaweCache.asTag(tag);
try (NBTOutputStream nos = new NBTOutputStream(gzip)) {
Map<String, com.sk89q.jnbt.Tag> map = weTag.getValue();
nos.writeNamedTag("Schematic", map.containsKey("Schematic") ? map.get("Schematic") : weTag);
nos.writeNamedTag("Schematic", map.getOrDefault("Schematic", weTag));
}
}
} catch (IOException e) {

Datei anzeigen

@ -88,8 +88,7 @@ public class PlotTrim {
return false;
}
});
ArrayList<Plot> plots = new ArrayList<>();
plots.addAll(PlotSquared.get().getPlots(area));
ArrayList<Plot> plots = new ArrayList<>(PlotSquared.get().getPlots(area));
if (ExpireManager.IMP != null) {
plots.removeAll(ExpireManager.IMP.getPendingExpired());
}

Datei anzeigen

@ -50,13 +50,11 @@ public final class BrushCache {
tool.setHolder(item);
brushCache.put(key, tool);
return tool;
} catch (Throwable ignore) {
ignore.printStackTrace();
} catch (Exception throwable) {
throwable.printStackTrace();
Fawe.debug("Invalid brush for " + player + " holding " + item.getType() + ": " + json.getValue());
if (item != null) {
item.setNbtData(null);
brushCache.remove(key);
}
item.setNbtData(null);
brushCache.remove(key);
} finally {
RECURSION.remove();
}
@ -123,4 +121,4 @@ public final class BrushCache {
}
return tool;
}
}
}

Datei anzeigen

@ -77,7 +77,7 @@ public class CachedMathMan {
add = 0.0f;
}
float invDiv = 1.0f / (((x < y) ? y : x) * INV_ATAN2_DIM_MINUS_1);
float invDiv = 1.0f / ((Math.max(x, y)) * INV_ATAN2_DIM_MINUS_1);
int xi = (int) (x * invDiv);
int yi = (int) (y * invDiv);

Datei anzeigen

@ -26,7 +26,7 @@ public class ColorUtil {
: Float.parseFloat(color));
switch (type) {
case PARSE_ALPHA:
return (c < 0f) ? 0f : ((c > 1f) ? 1f : c);
return (c < 0f) ? 0f : (Math.min(c, 1f));
case PARSE_PERCENT:
return (c <= 0f) ? 0f : ((c >= 100f) ? 1f : (c / 100f));
case PARSE_COMPONENT:

Datei anzeigen

@ -54,7 +54,7 @@ public class EditSessionBuilder {
public EditSessionBuilder(@Nonnull World world) {
checkNotNull(world);
this.world = world;
this.worldName = Fawe.imp().getWorldName(world);
this.worldName = world.getName();
}
public EditSessionBuilder(@Nonnull String worldName) {

Datei anzeigen

@ -81,11 +81,11 @@ public class MathMan {
}
public static int clamp(int check, int min, int max) {
return check > max ? max : (check < min ? min : check);
return check > max ? max : (Math.max(check, min));
}
public static float clamp(float check, float min, float max) {
return check > max ? max : (check < min ? min : check);
return check > max ? max : (Math.max(check, min));
}
public static double hypot(final double... pars) {
@ -104,7 +104,7 @@ public class MathMan {
return sum;
}
public static final int wrap(int value, int min, int max) {
public static int wrap(int value, int min, int max) {
if (max < min) {
return value;
}

Datei anzeigen

@ -7,11 +7,7 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.*;
import sun.reflect.ConstructorAccessor;
import sun.reflect.FieldAccessor;
@ -126,7 +122,7 @@ public class ReflectionUtils {
Class<?>[] additionalTypes, Object[] additionalValues) throws Exception {
Object[] parms = new Object[additionalValues.length + 2];
parms[0] = value;
parms[1] = Integer.valueOf(ordinal);
parms[1] = ordinal;
System.arraycopy(additionalValues, 0, parms, 2, additionalValues.length);
return enumClass.cast(getConstructorAccessor(enumClass, additionalTypes).newInstance(parms));
}
@ -332,12 +328,12 @@ public class ReflectionUtils {
}
public static Method[] sortMethods(Method[] methods) {
Arrays.sort(methods, (o1, o2) -> o1.getName().compareTo(o2.getName()));
Arrays.sort(methods, Comparator.comparing(Method::getName));
return methods;
}
public static Field[] sortFields(Field[] fields) {
Arrays.sort(fields, (o1, o2) -> o1.getName().compareTo(o2.getName()));
Arrays.sort(fields, Comparator.comparing(Field::getName));
return fields;
}

Datei anzeigen

@ -293,15 +293,14 @@ public class GenerationCommands extends MethodCommands {
@Command(
aliases = {"pumpkins"},
usage = "[size=10] [density=0.02]",
usage = "[size=10]",
desc = "Generate pumpkin patches",
min = 0,
max = 2
)
@CommandPermissions("worldedit.generation.pumpkins")
@Logging(POSITION)
public void pumpkins(Player player, LocalSession session, EditSession editSession, @Optional("10") int apothem, @Optional("0.02") double density) throws WorldEditException, ParameterException {
int affected = editSession.makePumpkinPatches(session.getPlacementPosition(player), apothem, density);
public void pumpkins(Player player, LocalSession session, EditSession editSession, @Optional("10") int apothem) throws WorldEditException, ParameterException {
int affected = editSession.makePumpkinPatches(session.getPlacementPosition(player), apothem);
BBC.COMMAND_PUMPKIN.send(player, affected);
}

Datei anzeigen

@ -9,22 +9,18 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.CommandManager;
import com.sk89q.worldedit.util.command.*;
import com.sk89q.worldedit.util.command.parametric.AParametricCallable;
import org.jetbrains.annotations.NotNull;
import java.util.*;
public abstract class HelpBuilder implements Runnable {
private final CommandCallable callable;
private final CommandContext args;
private final String prefix;
private final int perPage;
public HelpBuilder(CommandCallable callable, CommandContext args, final String prefix, int perPage) {
if (callable == null) {
callable = WorldEdit.getInstance().getPlatformManager().getCommandManager().getDispatcher();
}
HelpBuilder(@NotNull CommandCallable callable, CommandContext args, int perPage) {
this.callable = callable;
this.args = args;
this.prefix = prefix;
this.perPage = perPage;
}
@ -33,7 +29,6 @@ public abstract class HelpBuilder implements Runnable {
try {
CommandCallable callable = this.callable;
int page = -1;
String category = null;
int effectiveLength = args.argsLength();
// Detect page from args
@ -84,11 +79,7 @@ public abstract class HelpBuilder implements Runnable {
}
group = group.replace("/", "");
group = StringMan.toProperCase(group);
Map<CommandMapping, String> queue = grouped.get(group);
if (queue == null) {
queue = new LinkedHashMap<>();
grouped.put(group, queue);
}
Map<CommandMapping, String> queue = grouped.computeIfAbsent(group, k -> new LinkedHashMap<>());
if (c instanceof Dispatcher) {
for (CommandMapping m : ((Dispatcher) c).getCommands()) {
queue.put(m, mapping.getPrimaryAlias() + " ");
@ -190,28 +181,25 @@ public abstract class HelpBuilder implements Runnable {
return;
}
}
// else
{
Collections.sort(aliases, new PrimaryAliasComparator(CommandManager.COMMAND_CLEAN_PATTERN));
aliases.sort(new PrimaryAliasComparator(CommandManager.COMMAND_CLEAN_PATTERN));
// Calculate pagination
int offset = perPage * Math.max(0, page);
int pageTotal = (int) Math.ceil(aliases.size() / (double) perPage);
// Calculate pagination
int offset = perPage * Math.max(0, page);
int pageTotal = (int) Math.ceil(aliases.size() / (double) perPage);
// Box
if (offset >= aliases.size()) {
displayFailure(String.format(BBC.getPrefix() + "There is no page %d (total number of pages is %d).", page + 1, pageTotal));
} else {
int end = Math.min(offset + perPage, aliases.size());
List<CommandMapping> subAliases = aliases.subList(offset, end);
List<String> subPrefixes = prefixes.subList(offset, end);
Map<CommandMapping, String> commandMap = new LinkedHashMap<>();
for (int i = 0; i < subAliases.size(); i++) {
commandMap.put(subAliases.get(i), subPrefixes.get(i));
}
String visitedString = Joiner.on(" ").join(visited);
displayCommands(commandMap, visitedString, page, pageTotal, effectiveLength);
// Box
if (offset >= aliases.size()) {
displayFailure(String.format(BBC.getPrefix() + "There is no page %d (total number of pages is %d).", page + 1, pageTotal));
} else {
int end = Math.min(offset + perPage, aliases.size());
List<CommandMapping> subAliases = aliases.subList(offset, end);
List<String> subPrefixes = prefixes.subList(offset, end);
Map<CommandMapping, String> commandMap = new LinkedHashMap<>();
for (int i = 0; i < subAliases.size(); i++) {
commandMap.put(subAliases.get(i), subPrefixes.get(i));
}
String visitedString = Joiner.on(" ").join(visited);
displayCommands(commandMap, visitedString, page, pageTotal, effectiveLength);
}
} else {
String cmd = (WorldEdit.getInstance().getConfiguration().noDoubleSlash ? "" : "/") + Joiner.on(" ").join(visited);

Datei anzeigen

@ -53,14 +53,11 @@ import com.sk89q.worldedit.command.util.CreatureButcher;
import com.sk89q.worldedit.command.util.EntityRemover;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.extension.factory.DefaultTransformParser;
import com.sk89q.worldedit.extension.factory.parser.mask.DefaultMaskParser;
import com.sk89q.worldedit.extension.factory.parser.pattern.ClipboardPatternParser;
import com.sk89q.worldedit.extension.factory.parser.pattern.DefaultPatternParser;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.CommandManager;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
@ -78,16 +75,12 @@ import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.CylinderRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.command.binding.Range;
import com.sk89q.worldedit.session.SessionOwner;
import com.sk89q.worldedit.util.command.CommandCallable;
import com.sk89q.worldedit.util.command.CommandMapping;
import com.sk89q.worldedit.util.command.Dispatcher;
import com.sk89q.worldedit.util.command.PrimaryAliasComparator;
import com.sk89q.worldedit.util.command.binding.Text;
import com.sk89q.worldedit.util.command.parametric.Optional;
import com.sk89q.worldedit.util.command.parametric.ParameterData;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes;
import javax.imageio.ImageIO;
@ -96,7 +89,6 @@ import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.lang.reflect.Type;
import java.net.URI;
import java.nio.file.Files;
import java.util.*;
@ -105,9 +97,6 @@ import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.PLACEMENT;
/**
* Utility commands.
*/
@ -460,7 +449,7 @@ public class UtilityCommands extends MethodCommands {
we.checkMaxRadius(size);
final boolean onlyNormalDirt = !args.hasFlag('f');
final int affected = editSession.green(session.getPlacementPosition(player), size);
final int affected = editSession.green(session.getPlacementPosition(player), size, onlyNormalDirt);
BBC.VISITOR_BLOCK.send(player, affected);
}
@ -997,13 +986,13 @@ public class UtilityCommands extends MethodCommands {
}
public static void help(CommandContext args, WorldEdit we, Actor actor) {
help(args, we, actor, "/", null);
help(args, we, actor, "/", we.getPlatformManager().getCommandManager().getDispatcher());
}
public static void help(CommandContext args, WorldEdit we, Actor actor, String prefix, CommandCallable callable) {
final int perPage = actor instanceof Player ? 12 : 20; // More pages for console
HelpBuilder builder = new HelpBuilder(callable, args, prefix, perPage) {
HelpBuilder builder = new HelpBuilder(callable, args, perPage) {
@Override
public void displayFailure(String message) {
actor.printError(message);
@ -1023,7 +1012,7 @@ public class UtilityCommands extends MethodCommands {
String s1 = Commands.getAlias(UtilityCommands.class, "/help") + " " + entry.getKey();
String s2 = entry.getValue().size() + "";
msg.text(BBC.HELP_ITEM_ALLOWED, "&a" + s1, s2);
msg.tooltip(StringMan.join(entry.getValue().keySet(), ", ", cm -> cm.getPrimaryAlias()));
msg.tooltip(StringMan.join(entry.getValue().keySet(), ", ", CommandMapping::getPrimaryAlias));
msg.command(s1);
msg.newline();
}

Datei anzeigen

@ -20,11 +20,7 @@
package com.sk89q.worldedit.command.composition;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.object.RegionWrapper;
import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.object.*;
import com.boydti.fawe.object.extent.FaweRegionExtent;
import com.boydti.fawe.util.MainUtil;
import com.google.common.base.Joiner;
@ -36,8 +32,6 @@ import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.function.Contextual;
@ -53,14 +47,11 @@ import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.command.argument.CommandArgs;
import com.sk89q.worldedit.util.command.composition.CommandExecutor;
import com.sk89q.worldedit.util.command.composition.SimpleCommand;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.lang.reflect.Field;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
public class SelectionCommand extends SimpleCommand<Operation> {

Datei anzeigen

@ -82,7 +82,7 @@ public class ShapedBrushCommand extends SimpleCommand<Object> {
WorldEdit.getInstance().getPlatformManager().getCommandManager().getExceptionConverter().convert(e);
}
player.print(BBC.getPrefix() + "Set brush to " + factory);
player.print("Set brush to " + factory);
return true;
}

Datei anzeigen

@ -37,7 +37,7 @@ public class CylinderBrush implements Brush {
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
if (pattern == null) {
pattern = (BlockTypes.COBBLESTONE.getDefaultState());
pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState());
}
editSession.makeCylinder(position, pattern, size, size, height, true);
}

Datei anzeigen

@ -192,7 +192,8 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
state = LegacyMapper.getInstance().getBlockFromLegacy(type.getLegacyCombinedId() >> 4, data);
}
}
} catch (NumberFormatException ignore) {}
} catch (NumberFormatException e) {
}
}
if (state == null) {
@ -220,10 +221,10 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
throw new InputParseException("Your selection is not complete.");
}
state = world.getBlock(primaryPosition);
} else if (typeString.equalsIgnoreCase("hand")) {
} else if ("hand".equalsIgnoreCase(typeString)) {
// Get the block type from the item in the user's hand.
state = getBlockInHand(context.requireActor(), HandSide.MAIN_HAND);
} else if (typeString.equalsIgnoreCase("offhand")) {
} else if ("offhand".equalsIgnoreCase(typeString)) {
// Get the block type from the item in the user's off hand.
state = getBlockInHand(context.requireActor(), HandSide.OFF_HAND);
} else if (typeString.matches("slot[0-9]+")) {
@ -241,7 +242,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
BaseItem item = slottable.getItem(slot);
if (!item.getType().hasBlockType()) {
throw new InputParseException(BBC.getPrefix() + "You're not holding a block!");
throw new InputParseException("You're not holding a block!");
}
state = item.getType().getBlockType().getDefaultState();
nbt = item.getNbtData();
@ -249,7 +250,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
BlockType type = BlockTypes.parse(typeString.toLowerCase());
if (type != null) state = type.getDefaultState();
if (state == null) {
throw new NoMatchException(BBC.getPrefix() + "Does not match a valid block type: '" + input + "'");
throw new NoMatchException("Does not match a valid block type: '" + input + "'");
}
}
if (nbt == null) nbt = state.getNbtData();
@ -309,10 +310,9 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
break;
}
}
Platform capability = worldEdit.getPlatformManager().queryCapability(Capability.USER_COMMANDS);
if (!capability.isValidMobType(mobName)) {
if (!worldEdit.getPlatformManager().queryCapability(Capability.USER_COMMANDS).isValidMobType(mobName)) {
final String finalMobName = mobName.toLowerCase();
throw new SuggestInputParseException(BBC.getPrefix() + "Unknown mob type '" + mobName + "'", mobName, () -> Stream.of(MobType.values())
throw new SuggestInputParseException("Unknown mob type '" + mobName + "'", mobName, () -> Stream.of(MobType.values())
.map(m -> m.getName().toLowerCase())
.filter(s -> s.startsWith(finalMobName))
.collect(Collectors.toList()));
@ -350,4 +350,4 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
}
return holder;
}
}
}

Datei anzeigen

@ -170,10 +170,8 @@ public final class CommandManager {
builder.setAuthorizer(new ActorAuthorizer());
builder.setDefaultCompleter(new UserCommandCompleter(platformManager));
builder.addBinding(new WorldEditBinding(worldEdit));
builder.addBinding(new PatternBinding(worldEdit), com.sk89q.worldedit.function.pattern.Pattern.class);
builder.addBinding(new MaskBinding(worldEdit), com.sk89q.worldedit.function.mask.Mask.class);
builder.addInvokeListener(new LegacyCommandsHandler());
builder.addInvokeListener(new CommandLoggingHandler(worldEdit, commandLog));
@ -371,7 +369,7 @@ public final class CommandManager {
setupDispatcher();
}
public void unregister() {
void unregister() {
dynamicHandler.setHandler(null);
}
@ -401,8 +399,7 @@ public final class CommandManager {
public void handleCommandOnCurrentThread(CommandEvent event) {
Actor actor = platformManager.createProxyActor(event.getActor());
final String args = event.getArguments();
final String[] split = commandDetection(args.split(" "));
String[] split = commandDetection(event.getArguments().split(" "));
// No command found!
if (!dispatcher.contains(split[0])) {
return;
@ -410,7 +407,7 @@ public final class CommandManager {
if (!actor.isPlayer()) {
actor = FakePlayer.wrap(actor.getName(), actor.getUniqueId(), actor);
}
final LocalSession session = worldEdit.getSessionManager().get(actor);
LocalSession session = worldEdit.getSessionManager().get(actor);
Request.request().setSession(session);
if (actor instanceof Entity) {
Extent extent = ((Entity) actor).getExtent();
@ -419,7 +416,8 @@ public final class CommandManager {
}
}
LocalConfiguration config = worldEdit.getConfiguration();
final CommandLocals locals = new CommandLocals();
CommandLocals locals = new CommandLocals();
final FawePlayer fp = FawePlayer.wrap(actor);
if (fp == null) {
throw new IllegalArgumentException("FAWE doesn't support: " + actor);
@ -430,7 +428,7 @@ public final class CommandManager {
if (actor instanceof Player) {
Player player = (Player) actor;
Player unwrapped = LocationMaskedPlayerWrapper.unwrap(player);
actor = new LocationMaskedPlayerWrapper((Player) unwrapped, player.getLocation(), true) {
actor = new LocationMaskedPlayerWrapper(unwrapped, player.getLocation(), true) {
@Override
public boolean hasPermission(String permission) {
if (!super.hasPermission(permission)) {
@ -452,8 +450,7 @@ public final class CommandManager {
};
}
locals.put(Actor.class, actor);
final Actor finalActor = actor;
locals.put("arguments", args);
locals.put("arguments", event.getArguments());
ThrowableSupplier<Throwable> task =
() -> dispatcher.call(Joiner.on(" ").join(split), locals, new String[0]);
@ -527,7 +524,6 @@ public final class CommandManager {
}
} catch (Throwable e) {
Exception faweException = FaweException.get(e);
String message = e.getMessage();
if (faweException != null) {
BBC.WORLDEDIT_CANCEL_REASON.send(actor, faweException.getMessage());
} else {
@ -541,7 +537,7 @@ public final class CommandManager {
editSession.flushQueue();
worldEdit.flushBlockBag(locals.get(Actor.class), editSession);
session.remember(editSession);
final long time = System.currentTimeMillis() - start;
long time = System.currentTimeMillis() - start;
if (time > 1000) {
BBC.ACTION_COMPLETE.send(actor, (time / 1000d));
}

Datei anzeigen

@ -43,8 +43,12 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.registry.BundledBlockData;
import java.util.List;
import javax.annotation.Nullable;
/**
* A base class for {@link Extent}s that merely passes extents onto another.
*/
public class AbstractDelegateExtent implements LightingExtent {
private transient final Extent extent;
protected MutableBlockVector3 mutable = new MutableBlockVector3(0, 0, 0);
@ -264,8 +268,7 @@ public class AbstractDelegateExtent implements LightingExtent {
}
@Override
public @Nullable
Operation commit() {
public @Nullable Operation commit() {
Operation ours = commitBefore();
Operation other = null;
if (extent != this) other = extent.commit();

Datei anzeigen

@ -40,11 +40,10 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
/**
* Stores changes to a {@link ChangeSet}.

Datei anzeigen

@ -30,22 +30,18 @@ import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Requires that all mutating methods pass a given {@link Mask}.
*/
public class MaskingExtent extends AbstractDelegateExtent {
private Mask mask;
// private MutableBlockVector3 mutable = new MutableBlockVector3();
/**
* Create a new instance.
*
* @param extent the extent
* @param mask the mask
* @param mask the mask
*/
public MaskingExtent(Extent extent, Mask mask) {
super(extent);

Datei anzeigen

@ -34,10 +34,11 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
/**
* An extent that returns air blocks for all blocks and does not
* pass on any changes.

Datei anzeigen

@ -28,12 +28,6 @@ import com.boydti.fawe.object.extent.LightingExtent;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.function.operation.Operation;
@ -41,15 +35,18 @@ import com.sk89q.worldedit.math.BlockVector2;
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.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import javax.annotation.Nullable;
import java.io.Closeable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
@ -63,27 +60,21 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
private BlockVector3 origin;
public FaweClipboard IMP;
private BlockVector3 size;
private int mx;
private int my;
private int mz;
private BlockStateHolder[][][] blocks;
private final List<ClipboardEntity> entities = new ArrayList<>();
public BlockArrayClipboard(Region region) {
checkNotNull(region);
this.region = region.clone();
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.mx = origin.getBlockX();
this.my = origin.getBlockY();
this.mz = origin.getBlockZ();
this.blocks = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
}
/**
* Create a new instance.
* <p>
*
* <p>The origin will be placed at the region's lowest minimum point.</p>
*
* @param region the bounding region
@ -94,9 +85,6 @@ 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.mx = origin.getBlockX();
this.my = origin.getBlockY();
this.mz = origin.getBlockZ();
this.blocks = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
}
@ -105,9 +93,6 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
this.region = region.clone();
this.size = getDimensions();
this.origin = region.getMinimumPoint();
this.mx = origin.getBlockX();
this.my = origin.getBlockY();
this.mz = origin.getBlockZ();
this.IMP = clipboard;
this.blocks = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
}
@ -119,9 +104,6 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
this.size = getDimensions();
this.IMP = fc;
this.origin = region.getMinimumPoint();
this.mx = origin.getBlockX();
this.my = origin.getBlockY();
this.mz = origin.getBlockZ();
this.blocks = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
}
@ -196,12 +178,11 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
@Override
public BlockState getBlock(BlockVector3 position) {
if (region.contains(position)) {
int x = position.getBlockX() - mx;
int y = position.getBlockY() - my;
int z = position.getBlockZ() - mz;
return IMP.getBlock(x, y, z).toImmutableState();
BlockVector3 v = position.subtract(region.getMinimumPoint());
return IMP.getBlock(v.getX(),v.getY(),v.getZ()).toImmutableState();
}
return EditSession.nullBlock;
return BlockTypes.AIR.getDefaultState();
}
public BlockState getBlockAbs(int x, int y, int z) {
@ -215,13 +196,12 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
@Override
public BaseBlock getFullBlock(BlockVector3 position) {
if(region.contains(position)) {
int x = position.getBlockX() - mx;
int y = position.getBlockY() - my;
int z = position.getBlockZ() - mz;
return IMP.getBlock(x, y, z);
if (region.contains(position)) {
BlockVector3 v = position.subtract(region.getMinimumPoint());
return IMP.getBlock(v.getX(),v.getY(),v.getZ());
}
return EditSession.nullBlock.toBaseBlock();
return BlockTypes.AIR.getDefaultState().toBaseBlock();
}
@Override
@ -235,33 +215,28 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
return false;
}
public boolean setTile(int x, int y, int z, CompoundTag tag) {
x -= mx;
y -= my;
z -= mz;
return IMP.setTile(x, y, z, tag);
public boolean setTile(BlockVector3 position, CompoundTag tag) {
BlockVector3 v = position.subtract(region.getMinimumPoint());
return IMP.setTile(v.getX(), v.getY(), v.getZ(), tag);
}
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
x -= mx;
y -= my;
z -= mz;
return IMP.setBlock(x, y, z, block);
BlockVector3 position = BlockVector3.at(x, y, z);
BlockVector3 v = position.subtract(region.getMinimumPoint());
return IMP.setBlock(v.getX(), v.getY(), v.getZ(), block);
}
@Override
public BiomeType getBiome(BlockVector2 position) {
int x = position.getBlockX() - mx;
int z = position.getBlockZ() - mz;
return IMP.getBiome(x, z);
BlockVector2 v = position.subtract(region.getMinimumPoint().toBlockVector2());
return IMP.getBiome(v.getX(), v.getZ());
}
@Override
public boolean setBiome(BlockVector2 position, BiomeType biome) {
int x = position.getBlockX() - mx;
int z = position.getBlockZ() - mz;
IMP.setBiome(x, z, biome);
BlockVector2 v = position.subtract(region.getMinimumPoint().toBlockVector2());
IMP.setBiome(v.getX(), v.getZ(), biome);
return true;
}
@ -297,4 +272,4 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
public int getBrightness(int x, int y, int z) {
return getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial().getLightValue();
}
}
}

Datei anzeigen

@ -20,6 +20,7 @@
package com.sk89q.worldedit.extent.clipboard;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
@ -58,4 +59,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;
}
}

Datei anzeigen

@ -1,12 +1,28 @@
/*
* 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.extent.inventory;
import com.boydti.fawe.object.exception.FaweException;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
@ -33,7 +49,7 @@ public class BlockBagExtent extends AbstractDelegateExtent {
/**
* Create a new instance.
*
* @param extent the extent
* @param extent the extent
* @param blockBag the block bag
*/
public BlockBagExtent(Extent extent, @Nonnull BlockBag blockBag) {
@ -52,9 +68,7 @@ public class BlockBagExtent extends AbstractDelegateExtent {
*
* @return a block bag, which may be null if none is used
*/
public
@Nullable
BlockBag getBlockBag() {
public @Nullable BlockBag getBlockBag() {
return blockBag;
}
@ -92,34 +106,32 @@ public class BlockBagExtent extends AbstractDelegateExtent {
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
if(blockBag != null) {
BlockStateHolder lazyBlock = getExtent().getLazyBlock(x, y, z);
BlockType fromType = lazyBlock.getBlockType();
if(!block.getBlockType().equals(fromType)) {
BlockType type = block.getBlockType();
if (!type.getMaterial().isAir()) {
try {
blockBag.fetchPlacedBlock(block.toImmutableState());
} catch (UnplaceableBlockException e) {
throw new FaweException.FaweBlockBagException();
} catch (BlockBagException e) {
missingBlocks[type.getInternalId()]++;
throw new FaweException.FaweBlockBagException();
}
}
if (mine) {
if (!fromType.getMaterial().isAir()) {
try {
blockBag.storeDroppedBlock(fromType.getDefaultState());
} catch (BlockBagException ignored) {
}
}
}
}
if (blockBag != null) {
BlockState existing = getExtent().getBlock(BlockVector3.at(x,y,z));
if (!block.getBlockType().equals(existing.getBlockType())) {
if (!block.getBlockType().getMaterial().isAir()) {
try {
blockBag.fetchPlacedBlock(block.toImmutableState());
} catch (UnplaceableBlockException e) {
throw new FaweException.FaweBlockBagException();
} catch (BlockBagException e) {
missingBlocks[block.getBlockType().getInternalId()]++;
throw new FaweException.FaweBlockBagException();
}
}
if (mine) {
if (!existing.getBlockType().getMaterial().isAir()) {
try {
blockBag.storeDroppedBlock(existing);
} catch (BlockBagException ignored) {
}
}
}
}
}
return getExtent().setBlock(x, y, z, block);
return super.setBlock(x, y, z, block);
}
}
}

Datei anzeigen

@ -1,3 +1,22 @@
/*
* 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.extent.transform;
import com.boydti.fawe.object.extent.ResettableExtent;
@ -32,6 +51,7 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.worldedit.util.Direction.*;
public class BlockTransformExtent extends ResettableExtent {
@ -46,8 +66,14 @@ public class BlockTransformExtent extends ResettableExtent {
this(parent, new AffineTransform());
}
public BlockTransformExtent(Extent parent, Transform transform) {
super(parent);
/**
* Create a new instance.
*
* @param extent the extent
*/
public BlockTransformExtent(Extent extent, Transform transform) {
super(extent);
checkNotNull(transform);
this.transform = transform;
this.transformInverse = this.transform.inverse();
cache();
@ -134,7 +160,7 @@ public class BlockTransformExtent extends ResettableExtent {
continue;
default:
System.out.println("Unknown direction " + value);
result.add(0l);
result.add(0L);
}
}
return adapt(result.toArray(new Long[0]));
@ -174,7 +200,7 @@ public class BlockTransformExtent extends ResettableExtent {
break;
default:
System.out.println("Unknown direction " + value);
directions.add(0l);
directions.add(0L);
}
}
return adapt(directions.toArray(new Long[0]));
@ -268,7 +294,7 @@ public class BlockTransformExtent extends ResettableExtent {
}
}
private static final BaseBlock transformBaseBlockNBT(BlockState transformed, CompoundTag tag, Transform transform) {
private static BaseBlock transformBaseBlockNBT(BlockState transformed, CompoundTag tag, Transform transform) {
if (tag != null) {
if (tag.containsKey("Rot")) {
int rot = tag.asInt("Rot");
@ -321,7 +347,7 @@ public class BlockTransformExtent extends ResettableExtent {
newMaskedId = tmp.getInternalId();
}
for (AbstractProperty property : (Collection<AbstractProperty>) (Collection) type.getProperties()) {
for (AbstractProperty property : (List<AbstractProperty<?>>) type.getProperties()) {
if (isDirectional(property)) {
long[] directions = getDirections(property);
if (directions != null) {
@ -358,7 +384,6 @@ public class BlockTransformExtent extends ResettableExtent {
BLOCK_ROTATION_BITMASK = new int[BlockTypes.size()];
BLOCK_TRANSFORM = new int[BlockTypes.size()][];
BLOCK_TRANSFORM_INVERSE = new int[BlockTypes.size()][];
outer:
for (int i = 0; i < BLOCK_TRANSFORM.length; i++) {
BLOCK_TRANSFORM[i] = ALL;
BLOCK_TRANSFORM_INVERSE[i] = ALL;
@ -392,7 +417,7 @@ public class BlockTransformExtent extends ResettableExtent {
cache();
}
private final BlockState transform(BlockState state, int[][] transformArray, Transform transform) {
private BlockState transform(BlockState state, int[][] transformArray, Transform transform) {
int typeId = state.getInternalBlockTypeId();
int[] arr = transformArray[typeId];
if (arr == ALL) {
@ -478,4 +503,4 @@ public class BlockTransformExtent extends ResettableExtent {
}
}
}

Datei anzeigen

@ -1,10 +1,26 @@
/*
* 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.function.pattern;
import java.io.Serializable;
public abstract class AbstractPattern implements Pattern, Serializable {
public AbstractPattern() {
}
/**
* An abstract implementation for {@link Pattern}s.
*/
public abstract class AbstractPattern implements Pattern {
}

Datei anzeigen

@ -16,6 +16,7 @@
* 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.function.pattern;
import static com.google.common.base.Preconditions.checkNotNull;

Datei anzeigen

@ -1,3 +1,22 @@
/*
* 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.function.pattern;
import com.sk89q.worldedit.extent.clipboard.Clipboard;

Datei anzeigen

@ -26,23 +26,12 @@ import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockState;
/**
* Returns a {@link BlockStateHolder} for a given position.
*/
@Link(clazz = UtilityCommands.class, value = "patterns")
public interface Pattern{
// @Override
// default BaseBlock next(BlockVector3 position) {
// return new BaseBlock(apply(position));
// }
//
// @Override
// default BaseBlock next(int x, int y, int z) {
// return new BaseBlock(apply(BlockVector3.at(x, y, z)));
// }
public interface Pattern {
/**
* Return a {@link BlockStateHolder} for the given position.

Datei anzeigen

@ -1,3 +1,22 @@
/*
* 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.function.pattern;
import com.boydti.fawe.object.collection.RandomCollection;
@ -39,12 +58,12 @@ public class RandomPattern extends AbstractPattern {
/**
* Add a pattern to the weight list of patterns.
* <p>
*
* <p>The probability for the pattern added is chance / max where max is
* the sum of the probabilities of all added patterns.</p>
*
* @param pattern the pattern
* @param chance the chance, which can be any positive number
* @param chance the chance, which can be any positive number
*/
public void add(Pattern pattern, double chance) {
checkNotNull(pattern);
@ -75,4 +94,4 @@ public class RandomPattern extends AbstractPattern {
}
}

Datei anzeigen

@ -95,4 +95,5 @@ public class RepeatingExtentPattern extends AbstractExtentPattern {
int z = (Math.abs((p.getZ() + offset.getZ())) % size.getBlockZ()) + origin.getZ();
return getExtent().getFullBlock(mutable.setComponents(x, y, z));
}
}

Datei anzeigen

@ -1,3 +1,22 @@
/*
* 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.function.visitor;
import com.boydti.fawe.config.BBC;
@ -7,25 +26,20 @@ import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.object.HasFaweQueue;
import com.boydti.fawe.object.IntegerTrio;
import com.boydti.fawe.object.collection.BlockVectorSet;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.RunContext;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.util.Direction;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Queue;
import java.util.Set;
/**
* Performs a breadth-first search starting from points added with
@ -63,26 +77,26 @@ public abstract class BreadthFirstSearch implements Operation {
}
}
}
Collections.sort(list, new Comparator<BlockVector3>() {
@Override
public int compare(BlockVector3 o1, BlockVector3 o2) {
return (int) Math.signum(o1.lengthSq() - o2.lengthSq());
}
});
list.sort((o1, o2) -> (int) Math.signum(o1.lengthSq() - o2.lengthSq()));
DIAGONAL_DIRECTIONS = list.toArray(new BlockVector3[list.size()]);
}
private final RegionFunction function;
private List<BlockVector3> directions = new ArrayList<>();
private BlockVectorSet visited;
private final MappedFaweQueue mFaweQueue;
private BlockVectorSet queue;
private int currentDepth = 0;
private final int maxDepth;
private List<BlockVector3> directions = new ArrayList<>();
private int affected = 0;
private int maxBranch = Integer.MAX_VALUE;
public BreadthFirstSearch(final RegionFunction function) {
/**
* Create a new instance.
*
* @param function the function to apply to visited blocks
*/
public BreadthFirstSearch(RegionFunction function) {
this(function, Integer.MAX_VALUE);
}
@ -133,29 +147,44 @@ public abstract class BreadthFirstSearch implements Operation {
* Add the directions along the axes as directions to visit.
*/
protected void addAxes() {
directions.add(BlockVector3.at(0, -1, 0));
directions.add(BlockVector3.at(0, 1, 0));
directions.add(BlockVector3.at(-1, 0, 0));
directions.add(BlockVector3.at(1, 0, 0));
directions.add(BlockVector3.at(0, 0, -1));
directions.add(BlockVector3.at(0, 0, 1));
directions.add(BlockVector3.UNIT_MINUS_Y);
directions.add(BlockVector3.UNIT_Y);
directions.add(BlockVector3.UNIT_MINUS_X);
directions.add(BlockVector3.UNIT_X);
directions.add(BlockVector3.UNIT_MINUS_Z);
directions.add(BlockVector3.UNIT_Z);
}
/**
* Add the diagonal directions as directions to visit.
*/
protected void addDiagonal() {
directions.add(BlockVector3.at(1, 0, 1));
directions.add(BlockVector3.at(-1, 0, -1));
directions.add(BlockVector3.at(1, 0, -1));
directions.add(BlockVector3.at(-1, 0, 1));
directions.add(Direction.NORTHEAST.toBlockVector());
directions.add(Direction.SOUTHEAST.toBlockVector());
directions.add(Direction.SOUTHWEST.toBlockVector());
directions.add(Direction.NORTHWEST.toBlockVector());
}
public void visit(final BlockVector3 pos) {
if (!isVisited(pos)) {
isVisitable(pos, pos); // Ignore this, just to initialize mask on this point
queue.add(pos);
visited.add(pos);
/**
* Add the given location to the list of locations to visit, provided
* that it has not been visited. The position passed to this method
* will still be visited even if it fails
* {@link #isVisitable(BlockVector3, BlockVector3)}.
*
* <p>This method should be used before the search begins, because if
* the position <em>does</em> fail the test, and the search has already
* visited it (because it is connected to another root point),
* the search will mark the position as "visited" and a call to this
* method will do nothing.</p>
*
* @param position the position
*/
public void visit(BlockVector3 position) {
if (!isVisited(position)) {
isVisitable(position, position); // Ignore this, just to initialize mask on this point
queue.add(position);
visited.add(position);
}
}
@ -217,9 +246,6 @@ public abstract class BreadthFirstSearch implements Operation {
@Override
public Operation resume(RunContext run) throws WorldEditException {
MutableBlockVector3 mutable = new MutableBlockVector3();
// MutableBlockVector3 mutable2 = new MutableBlockVector3();
boolean shouldTrim = false;
IntegerTrio[] dirs = getIntDirections();
BlockVectorSet tempQueue = new BlockVectorSet();
BlockVectorSet chunkLoadSet = new BlockVectorSet();
@ -268,7 +294,6 @@ public abstract class BreadthFirstSearch implements Operation {
if (currentDepth == maxDepth) {
break;
}
int size = queue.size();
BlockVectorSet tmp = queue;
queue = tempQueue;
tmp.clear();

Datei anzeigen

@ -30,26 +30,23 @@ import com.sk89q.worldedit.math.BlockVector3;
import java.util.Collection;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Visits adjacent points on the same X-Z plane as long as the points
* pass the given mask, and then executes the provided region
* function on the entire column.
* <p>
*
* <p>This is used by {@code //fill}.</p>
*/
public class DownwardVisitor extends RecursiveVisitor {
private final int baseY;
private int baseY;
/**
* Create a new visitor.
*
* @param mask the mask
* @param mask the mask
* @param function the function
* @param baseY the base Y
* @param baseY the base Y
*/
public DownwardVisitor(Mask mask, RegionFunction function, int baseY) {
this(mask, function, baseY, Integer.MAX_VALUE, null);
@ -58,15 +55,16 @@ public class DownwardVisitor extends RecursiveVisitor {
public DownwardVisitor(Mask mask, RegionFunction function, int baseY, int depth, HasFaweQueue hasFaweQueue) {
super(mask, function, depth, hasFaweQueue);
checkNotNull(mask);
this.baseY = baseY;
Collection<BlockVector3> directions = getDirections();
directions.clear();
directions.add(BlockVector3.at(1, 0, 0));
directions.add(BlockVector3.at(-1, 0, 0));
directions.add(BlockVector3.at(0, 0, 1));
directions.add(BlockVector3.at(0, 0, -1));
directions.add(BlockVector3.at(0, -1, 0));
directions.add(BlockVector3.UNIT_X);
directions.add(BlockVector3.UNIT_MINUS_X);
directions.add(BlockVector3.UNIT_Z);
directions.add(BlockVector3.UNIT_MINUS_Z);
directions.add(BlockVector3.UNIT_MINUS_Y);
}
@Override
@ -74,6 +72,4 @@ public class DownwardVisitor extends RecursiveVisitor {
int fromY = from.getBlockY();
return (fromY == baseY || to.subtract(from).getBlockY() < 0) && super.isVisitable(from, to);
}
}

Datei anzeigen

@ -35,6 +35,9 @@ public class BlockVector3 {
public static final BlockVector3 UNIT_X = new BlockVector3(1, 0, 0);
public static final BlockVector3 UNIT_Y = new BlockVector3(0, 1, 0);
public static final BlockVector3 UNIT_Z = new BlockVector3(0, 0, 1);
public static final BlockVector3 UNIT_MINUS_X = new BlockVector3(-1, 0, 0);
public static final BlockVector3 UNIT_MINUS_Y = new BlockVector3(0, -1, 0);
public static final BlockVector3 UNIT_MINUS_Z = new BlockVector3(0, 0, -1);
public static final BlockVector3 ONE = new BlockVector3(1, 1, 1);
public static BlockVector3 at(double x, double y, double z) {

Datei anzeigen

@ -1,29 +1,44 @@
/*
* 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.math.convolution;
import com.boydti.fawe.object.visitor.Fast2DIterator;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.Regions;
import com.sk89q.worldedit.registry.state.PropertyGroup;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.Iterator;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
/**
* Allows applications of Kernels onto the region's height map.
* <p>
*
* <p>Currently only used for smoothing (with a GaussianKernel)</p>.
*/
public class HeightMap {
@ -41,7 +56,7 @@ public class HeightMap {
* Constructs the HeightMap
*
* @param session an edit session
* @param region the region
* @param region the region
*/
public HeightMap(EditSession session, Region region) {
this(session, region, (Mask) null, false);
@ -68,12 +83,12 @@ public class HeightMap {
int minZ = region.getMinimumPoint().getBlockZ();
int maxY = region.getMaximumPoint().getBlockY();
// Store current heightmap data
data = new int[width * height];
invalid = new boolean[data.length];
if (layers) {
BlockVector3 min = region.getMinimumPoint();
BlockVector3 max = region.getMaximumPoint();
int bx = min.getBlockX();
int bz = min.getBlockZ();
Iterable<BlockVector2> flat = Regions.asFlatRegion(region).asFlatRegion();
@ -128,11 +143,12 @@ public class HeightMap {
/**
* Apply the filter 'iterations' amount times.
*
* @param filter the filter
* @param filter the filter
* @param iterations the number of iterations
* @return number of blocks affected
* @throws MaxChangedBlocksException
*/
public int applyFilter(HeightMapFilter filter, int iterations) throws MaxChangedBlocksException {
checkNotNull(filter);
@ -155,11 +171,11 @@ public class HeightMap {
int originZ = minY.getBlockZ();
int maxY = region.getMaximumPoint().getBlockY();
BlockStateHolder fillerAir = EditSession.nullBlock;
BlockStateHolder fillerAir = BlockTypes.AIR.getDefaultState();
int blocksChanged = 0;
BlockStateHolder tmpBlock = EditSession.nullBlock;
BlockStateHolder tmpBlock = BlockTypes.AIR.getDefaultState();
// Apply heightmap
int maxY4 = maxY << 4;
@ -233,12 +249,11 @@ public class HeightMap {
int originZ = minY.getBlockZ();
int maxY = region.getMaximumPoint().getBlockY();
BlockStateHolder fillerAir = EditSession.nullBlock;
BlockState fillerAir = BlockTypes.AIR.getDefaultState();
int blocksChanged = 0;
BlockStateHolder tmpBlock = EditSession.nullBlock;
BlockState tmpBlock = BlockTypes.AIR.getDefaultState();
// Apply heightmap
int index = 0;
for (int z = 0; z < height; ++z) {
@ -248,20 +263,20 @@ public class HeightMap {
if (this.invalid != null && this.invalid[index]) continue;
int newHeight = Math.min(maxY, data[index]);
// Offset x,z to be 'real' coordinates
int xr = x + originX;
// Depending on growing or shrinking we need to start at the bottom or top
if (newHeight > curHeight) {
// Set the top block of the column to be the same type (this might go wrong with rounding)
BlockStateHolder existing = session.getBlock(xr, curHeight, zr);
BlockState existing = session.getBlock(BlockVector3.at(xr, curHeight, zr));
// Skip water/lava
if (existing.getBlockType().getMaterial().isMovementBlocker()) {
if (existing.getBlockType() != BlockTypes.WATER && existing.getBlockType() != BlockTypes.LAVA) {
int y0 = newHeight - 1;
for (int setY = y0, getY = curHeight - 1; setY >= curHeight; setY--, getY--) {
BlockStateHolder get = session.getBlock(xr, getY, zr);
if (get != EditSession.nullBlock) tmpBlock = get;
BlockState get = session.getBlock(xr, getY, zr);
if (get != BlockTypes.AIR.getDefaultState()) tmpBlock = get;
session.setBlock(xr, setY, zr, tmpBlock);
++blocksChanged;
}
@ -282,9 +297,10 @@ public class HeightMap {
}
}
}
// Drop trees to the floor -- TODO
return blocksChanged;
}
}

Datei anzeigen

@ -23,6 +23,7 @@ import com.sk89q.worldedit.util.Direction;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import javax.annotation.Nullable;
@ -63,7 +64,7 @@ public class DirectionalProperty extends AbstractProperty<Direction> {
@Nullable
@Override
public Direction getValueFor(final String string) {
Direction direction = Direction.valueOf(string.toUpperCase());
Direction direction = Direction.valueOf(string.toUpperCase(Locale.ROOT));
if (!getValues().contains(direction)) {
throw new IllegalArgumentException("Invalid direction value: " + string + ". Must be in " + getValues().toString());
}

Datei anzeigen

@ -67,9 +67,9 @@ public class IntegerProperty extends AbstractProperty<Integer> {
public Integer getValueFor(String string) {
try {
int val = Integer.parseInt(string);
// if (!getValues().contains(val)) {
// throw new IllegalArgumentException("Invalid int value: " + string + ". Must be in " + getValues().toString());
// }
if (!getValues().contains(val)) {
throw new IllegalArgumentException("Invalid int value: " + string + ". Must be in " + getValues().toString());
}
return val;
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid int value: " + string + ". Not an int.");

Datei anzeigen

@ -64,9 +64,11 @@ public enum Direction {
;
private final Vector3 direction;
private final BlockVector3 blockVector;
private final int flags, left, right;
private final int flags;
private final int left;
private final int right;
private final BlockVector3 blockPoint;
private static HashMap<String, Direction> map = new HashMap<>();
static {
@ -77,15 +79,15 @@ public enum Direction {
}
Direction(Vector3 vector, int flags, int left, int right) {
this.blockPoint = vector.toBlockPoint();
this.direction = vector.normalize();
this.blockVector = BlockVector3.at(Math.signum(vector.getX()), Math.signum(vector.getY()), Math.signum(vector.getZ()));
this.flags = flags;
this.left = left;
this.right = right;
}
public static Direction get(CharSequence sequence) {
return map.get(sequence);
return map.get((String)sequence);
}
public Direction getLeft() {
@ -96,30 +98,6 @@ public enum Direction {
return right != -1 ? values()[right] : null;
}
public double getX() {
return direction.getX();
}
public double getY() {
return direction.getY();
}
public double getZ() {
return direction.getZ();
}
public int getBlockX() {
return blockVector.getBlockX();
}
public int getBlockY() {
return blockVector.getBlockY();
}
public int getBlockZ() {
return blockVector.getBlockZ();
}
/**
* Return true if the direction is of a cardinal direction (north, west
* east, and south).
@ -177,7 +155,7 @@ public enum Direction {
* @return the vector
*/
public BlockVector3 toBlockVector() {
return direction.toBlockPoint();
return blockPoint;
}
/**
@ -332,3 +310,4 @@ public enum Direction {
}
}

Datei anzeigen

@ -20,10 +20,15 @@
package com.sk89q.worldedit.util;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.SolidBlockMask;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.world.World;
import javax.annotation.Nullable;
/**
* This class uses an inefficient method to figure out what block a player
* is looking towards.
@ -33,7 +38,8 @@ import com.sk89q.worldedit.world.World;
*/
public class TargetBlock {
private World world;
private final World world;
private int maxDistance;
private double checkDistance, curDistance;
private BlockVector3 targetPos = BlockVector3.ZERO;
@ -41,6 +47,11 @@ public class TargetBlock {
private BlockVector3 prevPos = BlockVector3.ZERO;
private Vector3 offset = Vector3.ZERO;
// the mask which dictates when to stop a trace - defaults to stopping at non-air blocks
private Mask stopMask;
// the mask which dictates when to stop a solid block trace - default to BlockMaterial#isMovementBlocker
private Mask solidMask;
/**
* Constructor requiring a player, uses default values
*
@ -48,7 +59,10 @@ public class TargetBlock {
*/
public TargetBlock(Player player) {
this.world = player.getWorld();
this.setValues(player.getLocation(), player.getLocation().getYaw(), player.getLocation().getPitch(), 300, 1.65, 0.2);
this.setValues(player.getLocation().toVector(), player.getLocation().getYaw(), player.getLocation().getPitch(),
300, 1.65, 0.2);
this.stopMask = new ExistingBlockMask(world);
this.solidMask = new SolidBlockMask(world);
}
/**
@ -60,7 +74,37 @@ public class TargetBlock {
*/
public TargetBlock(Player player, int maxDistance, double checkDistance) {
this.world = player.getWorld();
this.setValues(player.getLocation(), player.getLocation().getYaw(), player.getLocation().getPitch(), maxDistance, 1.65, checkDistance);
this.setValues(player.getLocation().toVector(), player.getLocation().getYaw(), player.getLocation().getPitch(), maxDistance, 1.65, checkDistance);
this.stopMask = new ExistingBlockMask(world);
this.solidMask = new SolidBlockMask(world);
}
/**
* Set the mask used for determine where to stop traces.
* Setting to null will restore the default.
*
* @param stopMask the mask used to stop traces
*/
public void setStopMask(@Nullable Mask stopMask) {
if (stopMask == null) {
this.stopMask = new ExistingBlockMask(world);
} else {
this.stopMask = stopMask;
}
}
/**
* Set the mask used for determine where to stop solid block traces.
* Setting to null will restore the default.
*
* @param solidMask the mask used to stop solid block traces
*/
public void setSolidMask(@Nullable Mask solidMask) {
if (solidMask == null) {
this.solidMask = new SolidBlockMask(world);
} else {
this.solidMask = solidMask;
}
}
/**
@ -78,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)));
@ -101,15 +145,15 @@ public class TargetBlock {
boolean searchForLastBlock = true;
Location lastBlock = null;
while (getNextBlock() != null) {
if (world.getBlock(targetPos).getBlockType().getMaterial().isAir()) {
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();
@ -123,7 +167,8 @@ public class TargetBlock {
* @return Block
*/
public Location getTargetBlock() {
while (getNextBlock() != null && world.getBlock(targetPos).getBlockType().getMaterial().isAir()) ;
//noinspection StatementWithEmptyBody
while (getNextBlock() != null && !stopMask.test(targetPos)) ;
return getCurrentBlock();
}
@ -134,7 +179,8 @@ public class TargetBlock {
* @return Block
*/
public Location getSolidTargetBlock() {
while (getNextBlock() != null && !world.getBlock(targetPos).getBlockType().getMaterial().isMovementBlocker()) ;
//noinspection StatementWithEmptyBody
while (getNextBlock() != null && !solidMask.test(targetPos)) ;
return getCurrentBlock();
}
@ -149,8 +195,8 @@ public class TargetBlock {
curDistance += checkDistance;
targetPosDouble = offset.add(targetPosDouble.getX(),
targetPosDouble.getY(),
targetPosDouble.getZ());
targetPosDouble.getY(),
targetPosDouble.getZ());
targetPos = targetPosDouble.toBlockPoint();
} while (curDistance <= maxDistance
&& targetPos.getBlockX() == prevPos.getBlockX()
@ -188,12 +234,17 @@ public class TargetBlock {
public Location getAnyTargetBlockFace() {
getAnyTargetBlock();
return getCurrentBlock().setDirection(getCurrentBlock().subtract(getPreviousBlock()));
Location current = getCurrentBlock();
if (current != null)
return current.setDirection(current.toVector().subtract(getPreviousBlock().toVector()));
else
return new Location(world, targetPos.toVector3(), Float.NaN, Float.NaN);
}
public Location getTargetBlockFace() {
getAnyTargetBlock();
return getCurrentBlock().setDirection(getCurrentBlock().subtract(getPreviousBlock()));
getTargetBlock();
if (getCurrentBlock() == null) return null;
return getCurrentBlock().setDirection(getCurrentBlock().toVector().subtract(getPreviousBlock().toVector()));
}
}

Datei anzeigen

@ -19,6 +19,7 @@
package com.sk89q.worldedit.util;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
@ -30,6 +31,7 @@ import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.Set;
@ -64,8 +66,8 @@ public class TreeGenerator {
}
},
JUNGLE("Jungle tree", "jungle"),
SMALL_JUNGLE("Small jungle tree", "shortjungle", "smalljungle"),
SHORT_JUNGLE("Short jungle tree") {
SMALL_JUNGLE("Small jungle tree", "smalljungle"),
SHORT_JUNGLE("Short jungle tree", "shortjungle") {
@Override
public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException {
return SMALL_JUNGLE.generate(editSession, pos);
@ -113,22 +115,22 @@ public class TreeGenerator {
private static final Set<String> primaryAliases = Sets.newHashSet();
private final String name;
private final String[] lookupKeys;
public final ImmutableList<String> lookupKeys;
static {
for (TreeType type : EnumSet.allOf(TreeType.class)) {
for (String key : type.lookupKeys) {
lookup.put(key, type);
}
if (type.lookupKeys.length > 0) {
primaryAliases.add(type.lookupKeys[0]);
if (type.lookupKeys.size() > 0) {
primaryAliases.add(type.lookupKeys.get(0));
}
}
}
TreeType(String name, String... lookupKeys) {
this.name = name;
this.lookupKeys = lookupKeys;
this.lookupKeys = ImmutableList.copyOf(lookupKeys);
}
public static Set<String> getAliases() {
@ -160,7 +162,7 @@ public class TreeGenerator {
*/
@Nullable
public static TreeType lookup(String name) {
return lookup.get(name.toLowerCase());
return lookup.get(name.toLowerCase(Locale.ROOT));
}
}
@ -179,8 +181,8 @@ public class TreeGenerator {
int trunkHeight = (int) Math.floor(Math.random() * 2) + 3;
int height = (int) Math.floor(Math.random() * 5) + 8;
BlockStateHolder logBlock = BlockTypes.OAK_LOG.getDefaultState();
BlockStateHolder leavesBlock = BlockTypes.OAK_LEAVES.getDefaultState();
BlockState logBlock = BlockTypes.OAK_LOG.getDefaultState();
BlockState leavesBlock = BlockTypes.OAK_LEAVES.getDefaultState();
// Create trunk
for (int i = 0; i < trunkHeight; ++i) {

Datei anzeigen

@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Function;
import java.util.Locale;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
@ -60,7 +61,7 @@ public class LevenshteinDistance implements Function<String, Integer> {
checkNotNull(baseString);
this.caseSensitive = caseSensitive;
this.replacePattern = replacePattern;
baseString = caseSensitive ? baseString : baseString.toLowerCase();
baseString = caseSensitive ? baseString : baseString.toLowerCase(Locale.ROOT);
baseString = replacePattern != null ? replacePattern.matcher(baseString).replaceAll("") : baseString;
this.baseString = baseString;
}
@ -79,7 +80,7 @@ public class LevenshteinDistance implements Function<String, Integer> {
if (caseSensitive) {
return distance(baseString, input);
} else {
return distance(baseString, input.toLowerCase());
return distance(baseString, input.toLowerCase(Locale.ROOT));
}
}
@ -189,5 +190,5 @@ public class LevenshteinDistance implements Function<String, Integer> {
// actually has the most recent cost counts
return p[n];
}
}

Datei anzeigen

@ -19,9 +19,15 @@
package com.sk89q.worldedit.util.logging;
import javax.annotation.Nullable;
import java.io.UnsupportedEncodingException;
import java.util.logging.*;
import java.util.logging.Filter;
import java.util.logging.Formatter;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.SimpleFormatter;
import java.util.logging.StreamHandler;
import javax.annotation.Nullable;
/**
* A {@link StreamHandler} delegate that allows for the swap and disable of

Datei anzeigen

@ -39,7 +39,7 @@ public class EngineHubPaste implements Paster {
return Pasters.getExecutor().submit(new PasteTask(content));
}
private final class PasteTask implements Callable<URL> {
private static final class PasteTask implements Callable<URL> {
private final String content;
private PasteTask(String content) {
@ -50,7 +50,7 @@ public class EngineHubPaste implements Paster {
public URL call() throws IOException, InterruptedException {
HttpRequest.Form form = HttpRequest.Form.create();
form.add("content", content);
form.add("from", "worldguard");
form.add("from", "enginehub");
URL url = HttpRequest.url("http://paste.enginehub.org/paste");
String result = HttpRequest.post(url)

Datei anzeigen

@ -21,7 +21,6 @@ package com.sk89q.worldedit.util.report;
public interface Report {
String getTitle();
}

Datei anzeigen

@ -38,10 +38,7 @@ import com.sk89q.worldedit.registry.state.PropertyKey;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -124,7 +121,7 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
String input = key.toString();
throw new SuggestInputParseException("Does not match a valid block type: " + input, input, () -> Stream.of(BlockTypes.values)
.filter(b -> StringMan.blockStateMatches(input, b.getId()))
.map(e1 -> e1.getId())
.map(BlockType::getId)
.sorted(StringMan.blockStateComparator(input))
.collect(Collectors.toList())
);
@ -181,12 +178,12 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
BlockType finalType = type;
throw new SuggestInputParseException("Invalid property " + charSequence + ":" + input + " for type " + type, input, () ->
finalType.getProperties().stream()
.map(p -> p.getName())
.map(Property::getName)
.filter(p -> StringMan.blockStateMatches(input, p))
.sorted(StringMan.blockStateComparator(input))
.collect(Collectors.toList()));
} else {
throw new SuggestInputParseException("No operator for " + state, "", () -> Arrays.asList("="));
throw new SuggestInputParseException("No operator for " + state, "", () -> Collections.singletonList("="));
}
}
property = null;
@ -211,6 +208,11 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
return getBlockType().withPropertyId(propertyId);
}
@Override
public BlockType getBlockType() {
return this.blockType;
}
@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
return extent.setBlock(set, this);
@ -259,6 +261,14 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
}
}
@Override
public final Map<Property<?>, Object> getStates() {
BlockType type = this.getBlockType();
// Lazily initialize the map
Map<? extends Property, Object> map = Maps.asMap(type.getPropertiesSet(), (Function<Property, Object>) this::getState);
return (Map<Property<?>, Object>) map;
}
@Override
public final <V> V getState(final Property<V> property) {
try {
@ -269,19 +279,9 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
}
}
@Deprecated
@Override
public final <V> V getState(final PropertyKey key) {
return getState(getBlockType().getProperty(key));
}
@Override
@Deprecated
public final Map<Property<?>, Object> getStates() {
BlockType type = this.getBlockType();
// Lazily initialize the map
Map<? extends Property, Object> map = Maps.asMap(type.getPropertiesSet(), (Function<Property, Object>) input -> getState(input));
return (Map<Property<?>, Object>) map;
public BlockState toImmutableState() {
return this;
}
@Override
@ -289,6 +289,12 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
return this.emptyBaseBlock;
}
@Deprecated
@Override
public final <V> V getState(final PropertyKey key) {
return getState(getBlockType().getProperty(key));
}
@Override
public BaseBlock toBaseBlock(CompoundTag compoundTag) {
if (compoundTag == null) {
@ -296,11 +302,6 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
}
return new BaseBlock(this, compoundTag);
}
@Override
public BlockType getBlockType() {
return this.blockType;
}
@Override
public boolean equalsFuzzy(BlockStateHolder<?> o) {
@ -310,11 +311,6 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
return o.equalsFuzzy(this);
}
@Override
public BlockState toImmutableState() {
return this;
}
@Override
public int getInternalId() {
return internalId;
@ -326,9 +322,7 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
if (blockType == BlockTypes.__RESERVED__) {
return this.material = blockType.getMaterial();
}
if (this.material == null) {
this.material = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getMaterial(this);
}
this.material = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getMaterial(this);
}
return material;
}

Datei anzeigen

@ -19,41 +19,31 @@
package com.sk89q.worldedit.world.block;
import static com.google.common.base.Preconditions.checkArgument;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.command.SuggestInputParseException;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.ReflectionUtils;
import com.boydti.fawe.util.StringMan;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.SingleBlockTypeMask;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.AbstractProperty;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.registry.state.PropertyKey;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.world.registry.BundledBlockData;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import it.unimi.dsi.fastutil.ints.IntCollections;
import javax.annotation.Nullable;
import java.lang.reflect.Field;
import java.util.*;
import java.util.function.Function;
import java.util.function.IntPredicate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
/**