diff --git a/README.md b/README.md
index 2dc4846ba..3eb26b510 100644
--- a/README.md
+++ b/README.md
@@ -1,17 +1,15 @@
![WorldEdit](http://static.sk89q.com/readme/worldedit.png)
=========
-WorldEdit is an easy-to-use in-game world editor for Minecraft, supporting both
-single player and multiplayer, that lets you:
+WorldEdit is Minecraft mod that turns Minecraft into an in-game map editor (sorta, kinda).
-* Change thousands of blocks in an area at once by selecting regions.
-* Use over 100 functions to modify the world or remove problems.
-* Remove large chunks of land as you wish.
-* Sculpt the world and build mountains with brushes.
-* Fix annoyances such as broken water, missing snow, raging fires, and more.
+* Make awesome stuff with half the time OR make ***quadriply** awesome* creations with the same time :sparkles:
+* Get lost in hundreds of options and functions that even we've forgotten existed
+* Utilize Photoshop-like tools like "selection areas" and "brushes"
+* Making fjords and other natural wonders with weird names
+* Also: fix grief, broken water, missing snow, raging fires, and other :poop:
-WorldEdit is open source and is available under the GNU Lesser General Public
-License v3.
+WorldEdit is open source!, so if you've just learned how to make a button blink, I probably recommend picking up a book on CS algorithms. The project is licensed using the GNU Lesser General Public License license, v3.
Compiling
---------
diff --git a/build.gradle b/build.gradle
index a97b88a56..9d91915c1 100644
--- a/build.gradle
+++ b/build.gradle
@@ -21,7 +21,8 @@ buildscript {
configurations.all {
resolutionStrategy {
- force 'com.google.guava:guava:17.0'
+ force 'com.google.guava:guava:21.0'
+ force 'org.ow2.asm:asm:6.0_BETA'
}
}
@@ -34,7 +35,7 @@ buildscript {
allprojects {
group = 'com.sk89q.worldedit'
- version = '6.1.7-SNAPSHOT'
+ version = '7.0.0-SNAPSHOT'
}
if (!project.hasProperty("artifactory_contextUrl")) ext.artifactory_contextUrl = "http://localhost"
@@ -86,10 +87,11 @@ subprojects {
ext.internalVersion = version + ";" + gitCommitHash
- sourceCompatibility = 1.7
- targetCompatibility = 1.7
+ sourceCompatibility = JavaVersion.VERSION_1_8
+ targetCompatibility = JavaVersion.VERSION_1_8
checkstyle.configFile = new File(rootProject.projectDir, "config/checkstyle/checkstyle.xml")
+ checkstyle.toolVersion = '7.6.1'
repositories {
mavenCentral()
diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml
index 1e33564c4..cd403cf91 100644
--- a/config/checkstyle/checkstyle.xml
+++ b/config/checkstyle/checkstyle.xml
@@ -27,7 +27,6 @@
-
@@ -61,4 +60,4 @@
-
\ No newline at end of file
+
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index d6e2637af..0d4a95168 100644
Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 589dd6099..a95009c3b 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,5 @@
-#Wed Nov 23 21:39:25 PST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-bin.zip
diff --git a/gradlew b/gradlew
index 4ef3a871f..cccdd3d51 100755
--- a/gradlew
+++ b/gradlew
@@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
-warn ( ) {
+warn () {
echo "$*"
}
-die ( ) {
+die () {
echo
echo "$*"
echo
@@ -155,13 +155,14 @@ if $cygwin ; then
fi
# Escape application args
-for s in "${@}" ; do
- s=\"$s\"
- APP_ARGS=$APP_ARGS" "$s
-done
+save () {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
+}
+APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
-eval set -- "$DEFAULT_JVM_OPTS" "$JAVA_OPTS" "$GRADLE_OPTS" "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
diff --git a/worldedit-bukkit/build.gradle b/worldedit-bukkit/build.gradle
index 2413532e3..5c1a39cd9 100644
--- a/worldedit-bukkit/build.gradle
+++ b/worldedit-bukkit/build.gradle
@@ -1,5 +1,6 @@
apply plugin: 'eclipse'
apply plugin: 'idea'
+apply plugin: 'maven'
repositories {
maven { url "https://hub.spigotmc.org/nexus/content/groups/public" }
@@ -8,7 +9,7 @@ repositories {
dependencies {
compile project(':worldedit-core')
compile 'com.sk89q:dummypermscompat:1.8'
- compile 'org.bukkit:bukkit:1.9.4-R0.1-SNAPSHOT' // zzz
+ compile 'org.bukkit:bukkit:1.13-R0.1-SNAPSHOT' // zzz
testCompile 'org.mockito:mockito-core:1.9.0-rc1'
}
@@ -33,10 +34,7 @@ jar {
shadowJar {
dependencies {
include(dependency(':worldedit-core'))
- include(dependency('com.google.code.gson:gson:2.2.4'))
}
-
- relocate('com.google.gson', 'com.sk89q.worldedit.internal.gson')
}
build.dependsOn(shadowJar)
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/bukkit/util/CommandRegistration.java b/worldedit-bukkit/src/main/java/com/sk89q/bukkit/util/CommandRegistration.java
index 2417b2ced..e7df6832c 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/bukkit/util/CommandRegistration.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/bukkit/util/CommandRegistration.java
@@ -82,7 +82,7 @@ public class CommandRegistration {
public boolean unregisterCommands() {
CommandMap commandMap = getCommandMap();
- List toRemove = new ArrayList();
+ List toRemove = new ArrayList<>();
Map knownCommands = ReflectionUtil.getField(commandMap, "knownCommands");
Set aliases = ReflectionUtil.getField(commandMap, "aliases");
if (knownCommands == null || aliases == null) {
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/bukkit/util/CommandsManagerRegistration.java b/worldedit-bukkit/src/main/java/com/sk89q/bukkit/util/CommandsManagerRegistration.java
index 175c51c6d..5f8bfbc8c 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/bukkit/util/CommandsManagerRegistration.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/bukkit/util/CommandsManagerRegistration.java
@@ -50,7 +50,7 @@ public class CommandsManagerRegistration extends CommandRegistration {
}
public boolean registerAll(List registered) {
- List toRegister = new ArrayList();
+ List toRegister = new ArrayList<>();
for (Command command : registered) {
List permissions = null;
Method cmdMethod = commands.getMethods().get(null).get(command.aliases()[0]);
@@ -59,7 +59,7 @@ public class CommandsManagerRegistration extends CommandRegistration {
if (cmdMethod != null && cmdMethod.isAnnotationPresent(CommandPermissions.class)) {
permissions = Arrays.asList(cmdMethod.getAnnotation(CommandPermissions.class).value());
} else if (cmdMethod != null && childMethods != null && !childMethods.isEmpty()) {
- permissions = new ArrayList();
+ permissions = new ArrayList<>();
for (Method m : childMethods.values()) {
if (m.isAnnotationPresent(CommandPermissions.class)) {
permissions.addAll(Arrays.asList(m.getAnnotation(CommandPermissions.class).value()));
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/wepif/ConfigurationPermissionsResolver.java b/worldedit-bukkit/src/main/java/com/sk89q/wepif/ConfigurationPermissionsResolver.java
index 75beabdf2..d61674c1e 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/wepif/ConfigurationPermissionsResolver.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/wepif/ConfigurationPermissionsResolver.java
@@ -19,16 +19,16 @@
package com.sk89q.wepif;
+import com.sk89q.util.yaml.YAMLNode;
+import com.sk89q.util.yaml.YAMLProcessor;
+import org.bukkit.OfflinePlayer;
+
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import com.sk89q.util.yaml.YAMLNode;
-import com.sk89q.util.yaml.YAMLProcessor;
-import org.bukkit.OfflinePlayer;
-
public class ConfigurationPermissionsResolver implements PermissionsResolver {
private YAMLProcessor config;
private Map> userPermissionsCache;
@@ -52,11 +52,11 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
@Override
public void load() {
- userGroups = new HashMap>();
- userPermissionsCache = new HashMap>();
- defaultPermissionsCache = new HashSet();
+ userGroups = new HashMap<>();
+ userPermissionsCache = new HashMap<>();
+ defaultPermissionsCache = new HashSet<>();
- Map> userGroupPermissions = new HashMap>();
+ Map> userGroupPermissions = new HashMap<>();
List groupKeys = config.getStringList("permissions.groups", null);
@@ -66,7 +66,7 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
config.getStringList("permissions.groups." + key + ".permissions", null);
if (!permissions.isEmpty()) {
- Set groupPerms = new HashSet(permissions);
+ Set groupPerms = new HashSet<>(permissions);
userGroupPermissions.put(key, groupPerms);
if (key.equals("default")) {
@@ -80,7 +80,7 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
if (userKeys != null) {
for (String key : userKeys) {
- Set permsCache = new HashSet();
+ Set permsCache = new HashSet<>();
List permissions =
config.getStringList("permissions.users." + key + ".permissions", null);
@@ -103,7 +103,7 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
}
userPermissionsCache.put(key.toLowerCase(), permsCache);
- userGroups.put(key.toLowerCase(), new HashSet(groups));
+ userGroups.put(key.toLowerCase(), new HashSet<>(groups));
}
}
}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/wepif/DinnerPermsResolver.java b/worldedit-bukkit/src/main/java/com/sk89q/wepif/DinnerPermsResolver.java
index 4e8199f9b..d5f9c7fc6 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/wepif/DinnerPermsResolver.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/wepif/DinnerPermsResolver.java
@@ -114,13 +114,13 @@ public class DinnerPermsResolver implements PermissionsResolver {
if (perms == null) {
return new String[0];
}
- List groupNames = new ArrayList();
+ List groupNames = new ArrayList<>();
for (PermissionAttachmentInfo permAttach : perms.getEffectivePermissions()) {
String perm = permAttach.getPermission();
if (!(perm.startsWith(GROUP_PREFIX) && permAttach.getValue())) {
continue;
}
- groupNames.add(perm.substring(GROUP_PREFIX.length(), perm.length()));
+ groupNames.add(perm.substring(GROUP_PREFIX.length()));
}
return groupNames.toArray(new String[groupNames.size()]);
}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/wepif/FlatFilePermissionsResolver.java b/worldedit-bukkit/src/main/java/com/sk89q/wepif/FlatFilePermissionsResolver.java
index 6caa45207..3f2324596 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/wepif/FlatFilePermissionsResolver.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/wepif/FlatFilePermissionsResolver.java
@@ -66,13 +66,8 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
this.userFile = userFile;
}
- @Deprecated
- public static boolean filesExists() {
- return (new File("perms_groups.txt")).exists() && (new File("perms_users.txt")).exists();
- }
-
public Map> loadGroupPermissions() {
- Map> userGroupPermissions = new HashMap>();
+ Map> userGroupPermissions = new HashMap<>();
BufferedReader buff = null;
@@ -98,7 +93,7 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
if (parts.length > 1) {
String[] perms = parts[1].split(",");
- Set groupPerms = new HashSet(Arrays.asList(perms));
+ Set groupPerms = new HashSet<>(Arrays.asList(perms));
userGroupPermissions.put(key, groupPerms);
}
}
@@ -118,9 +113,9 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
@Override
public void load() {
- userGroups = new HashMap>();
- userPermissionsCache = new HashMap>();
- defaultPermissionsCache = new HashSet();
+ userGroups = new HashMap<>();
+ userPermissionsCache = new HashMap<>();
+ defaultPermissionsCache = new HashSet<>();
Map> userGroupPermissions = loadGroupPermissions();
@@ -136,7 +131,7 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
String line;
while ((line = buff.readLine()) != null) {
- Set permsCache = new HashSet();
+ Set permsCache = new HashSet<>();
line = line.trim();
@@ -165,7 +160,7 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
}
userPermissionsCache.put(key.toLowerCase(), permsCache);
- userGroups.put(key.toLowerCase(), new HashSet(Arrays.asList(groups)));
+ userGroups.put(key.toLowerCase(), new HashSet<>(Arrays.asList(groups)));
}
}
} catch (IOException e) {
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/wepif/NijiPermissionsResolver.java b/worldedit-bukkit/src/main/java/com/sk89q/wepif/NijiPermissionsResolver.java
index f3502d460..fe23bfa46 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/wepif/NijiPermissionsResolver.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/wepif/NijiPermissionsResolver.java
@@ -19,6 +19,7 @@
package com.sk89q.wepif;
+import com.nijikokun.bukkit.Permissions.Permissions;
import com.sk89q.util.yaml.YAMLProcessor;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
@@ -27,7 +28,6 @@ import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
-import com.nijikokun.bukkit.Permissions.Permissions;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -50,7 +50,7 @@ public class NijiPermissionsResolver implements PermissionsResolver {
Plugin plugin = pluginManager.getPlugin("Permissions");
// Check if plugin is loaded and has Permissions interface
- if (plugin == null || !(plugin instanceof Permissions)) {
+ if (!(plugin instanceof Permissions)) {
return null;
}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/wepif/PermissionsProvider.java b/worldedit-bukkit/src/main/java/com/sk89q/wepif/PermissionsProvider.java
index 2d9be46a3..8332a519b 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/wepif/PermissionsProvider.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/wepif/PermissionsProvider.java
@@ -22,19 +22,19 @@ package com.sk89q.wepif;
import org.bukkit.OfflinePlayer;
public interface PermissionsProvider {
- public boolean hasPermission(String name, String permission);
+ boolean hasPermission(String name, String permission);
- public boolean hasPermission(String worldName, String name, String permission);
+ boolean hasPermission(String worldName, String name, String permission);
- public boolean inGroup(String player, String group);
+ boolean inGroup(String player, String group);
- public String[] getGroups(String player);
+ String[] getGroups(String player);
- public boolean hasPermission(OfflinePlayer player, String permission);
+ boolean hasPermission(OfflinePlayer player, String permission);
- public boolean hasPermission(String worldName, OfflinePlayer player, String permission);
+ boolean hasPermission(String worldName, OfflinePlayer player, String permission);
- public boolean inGroup(OfflinePlayer player, String group);
+ boolean inGroup(OfflinePlayer player, String group);
- public String[] getGroups(OfflinePlayer player);
+ String[] getGroups(OfflinePlayer player);
}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/wepif/PermissionsResolver.java b/worldedit-bukkit/src/main/java/com/sk89q/wepif/PermissionsResolver.java
index 1423ede23..918c1bc23 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/wepif/PermissionsResolver.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/wepif/PermissionsResolver.java
@@ -20,7 +20,7 @@
package com.sk89q.wepif;
public interface PermissionsResolver extends PermissionsProvider {
- public void load();
+ void load();
- public String getDetectionMessage();
+ String getDetectionMessage();
}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/wepif/PermissionsResolverManager.java b/worldedit-bukkit/src/main/java/com/sk89q/wepif/PermissionsResolverManager.java
index babc4a4cf..01f04546b 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/wepif/PermissionsResolverManager.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/wepif/PermissionsResolverManager.java
@@ -86,7 +86,7 @@ public class PermissionsResolverManager implements PermissionsResolver {
private PermissionsResolver permissionResolver;
private YAMLProcessor config;
private Logger logger = Logger.getLogger(getClass().getCanonicalName());
- private List> enabledResolvers = new ArrayList>();
+ private List> enabledResolvers = new ArrayList<>();
@SuppressWarnings("unchecked")
protected Class extends PermissionsResolver>[] availableResolvers = new Class[] {
@@ -213,7 +213,7 @@ public class PermissionsResolverManager implements PermissionsResolver {
if (!keys.contains("resolvers")) {
//List resolverKeys = config.getKeys("resolvers");
- List resolvers = new ArrayList();
+ List resolvers = new ArrayList<>();
for (Class> clazz : availableResolvers) {
resolvers.add(clazz.getSimpleName());
}
@@ -221,7 +221,7 @@ public class PermissionsResolverManager implements PermissionsResolver {
config.setProperty("resolvers.enabled", resolvers);
isUpdated = true;
} else {
- List disabledResolvers = config.getStringList("resolvers.disabled", new ArrayList());
+ List disabledResolvers = config.getStringList("resolvers.disabled", new ArrayList<>());
List stagedEnabled = config.getStringList("resolvers.enabled", null);
for (Iterator i = stagedEnabled.iterator(); i.hasNext();) {
String nextName = i.next();
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java
index 306f19b7b..f1181cf50 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java
@@ -19,22 +19,62 @@
package com.sk89q.worldedit.bukkit;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.common.base.Function;
import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.WorldEdit;
+import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.entity.Entity;
+import com.sk89q.worldedit.extension.input.InputParseException;
+import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World;
+import com.sk89q.worldedit.world.block.BlockState;
+import com.sk89q.worldedit.world.block.BlockStateHolder;
+import com.sk89q.worldedit.world.block.BlockType;
+import com.sk89q.worldedit.world.block.BlockTypes;
+import com.sk89q.worldedit.world.gamemode.GameMode;
+import com.sk89q.worldedit.world.gamemode.GameModes;
+import com.sk89q.worldedit.world.item.ItemType;
+import com.sk89q.worldedit.world.item.ItemTypes;
import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.block.data.BlockData;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
-import static com.google.common.base.Preconditions.checkNotNull;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+import javax.annotation.Nullable;
/**
* Adapts between Bukkit and WorldEdit equivalent objects.
*/
-final class BukkitAdapter {
+public class BukkitAdapter {
private BukkitAdapter() {
}
+ private static final ParserContext TO_BLOCK_CONTEXT = new ParserContext();
+
+ static {
+ TO_BLOCK_CONTEXT.setRestricted(false);
+ }
+
+ /**
+ * Checks equality between a WorldEdit BlockType and a Bukkit Material
+ *
+ * @param blockType The WorldEdit BlockType
+ * @param type The Bukkit Material
+ * @return If they are equal
+ */
+ public static boolean equals(BlockType blockType, Material type) {
+ return Objects.equals(blockType.getId(), type.getKey().toString());
+ }
+
/**
* Convert any WorldEdit world into an equivalent wrapped Bukkit world.
*
@@ -67,6 +107,26 @@ final class BukkitAdapter {
return new BukkitWorld(world);
}
+ /**
+ * Create a WorldEdit Player from a Bukkit Player.
+ *
+ * @param player The Bukkit player
+ * @return The WorldEdit player
+ */
+ public static BukkitPlayer adapt(Player player) {
+ return WorldEditPlugin.getInstance().wrapPlayer(player);
+ }
+
+ /**
+ * Create a Bukkit Player from a WorldEdit Player.
+ *
+ * @param player The WorldEdit player
+ * @return The Bukkit player
+ */
+ public static Player adapt(com.sk89q.worldedit.entity.Player player) {
+ return ((BukkitPlayer) player).getPlayer();
+ }
+
/**
* Create a Bukkit world from a WorldEdit world.
*
@@ -95,7 +155,7 @@ final class BukkitAdapter {
*/
public static Location adapt(org.bukkit.Location location) {
checkNotNull(location);
- Vector position = BukkitUtil.toVector(location);
+ Vector position = asVector(location);
return new com.sk89q.worldedit.util.Location(
adapt(location.getWorld()),
position,
@@ -151,6 +211,17 @@ final class BukkitAdapter {
location.getPitch());
}
+ /**
+ * Create a WorldEdit Vector from a Bukkit location.
+ *
+ * @param location The Bukkit location
+ * @return a WorldEdit vector
+ */
+ public static Vector asVector(org.bukkit.Location location) {
+ checkNotNull(location);
+ return new Vector(location.getX(), location.getY(), location.getZ());
+ }
+
/**
* Create a WorldEdit entity from a Bukkit entity.
*
@@ -162,4 +233,142 @@ final class BukkitAdapter {
return new BukkitEntity(entity);
}
+ /**
+ * Create a Bukkit Material form a WorldEdit ItemType
+ *
+ * @param itemType The WorldEdit ItemType
+ * @return The Bukkit Material
+ */
+ public static Material adapt(ItemType itemType) {
+ checkNotNull(itemType);
+ if (!itemType.getId().startsWith("minecraft:")) {
+ throw new IllegalArgumentException("Bukkit only supports Minecraft items");
+ }
+ return Material.getMaterial(itemType.getId().replace("minecraft:", "").toUpperCase());
+ }
+
+ /**
+ * Create a Bukkit Material form a WorldEdit BlockType
+ *
+ * @param blockType The WorldEdit BlockType
+ * @return The Bukkit Material
+ */
+ public static Material adapt(BlockType blockType) {
+ checkNotNull(blockType);
+ if (!blockType.getId().startsWith("minecraft:")) {
+ throw new IllegalArgumentException("Bukkit only supports Minecraft blocks");
+ }
+ return Material.getMaterial(blockType.getId().replace("minecraft:", "").toUpperCase());
+ }
+
+ /**
+ * Create a WorldEdit GameMode from a Bukkit one.
+ *
+ * @param gameMode Bukkit GameMode
+ * @return WorldEdit GameMode
+ */
+ public static GameMode adapt(org.bukkit.GameMode gameMode) {
+ checkNotNull(gameMode);
+ return GameModes.get(gameMode.name().toLowerCase());
+ }
+
+ /**
+ * Converts a Material to a BlockType
+ *
+ * @param material The material
+ * @return The blocktype
+ */
+ public static BlockType asBlockType(Material material) {
+ checkNotNull(material);
+ if (!material.isBlock()) {
+ throw new IllegalArgumentException(material.getKey().toString() + " is not a block!");
+ }
+ return BlockTypes.get(material.getKey().toString());
+ }
+
+ /**
+ * Converts a Material to a ItemType
+ *
+ * @param material The material
+ * @return The itemtype
+ */
+ public static ItemType asItemType(Material material) {
+ checkNotNull(material);
+ if (!material.isItem()) {
+ throw new IllegalArgumentException(material.getKey().toString() + " is not an item!");
+ }
+ return ItemTypes.get(material.getKey().toString());
+ }
+
+ private static Map blockStateCache = new HashMap<>();
+
+ /**
+ * Create a WorldEdit BlockState from a Bukkit BlockData
+ *
+ * @param blockData The Bukkit BlockData
+ * @return The WorldEdit BlockState
+ */
+ public static BlockState adapt(BlockData blockData) {
+ checkNotNull(blockData);
+ return blockStateCache.computeIfAbsent(blockData.getAsString(), new Function() {
+ @Nullable
+ @Override
+ public BlockState apply(@Nullable String input) {
+ try {
+ return WorldEdit.getInstance().getBlockFactory().parseFromInput(input, TO_BLOCK_CONTEXT).toImmutableState();
+ } catch (InputParseException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+ });
+ }
+
+ /**
+ * Create a Bukkit BlockData from a WorldEdit BlockStateHolder
+ *
+ * @param block The WorldEdit BlockStateHolder
+ * @return The Bukkit BlockData
+ */
+ public static BlockData adapt(BlockStateHolder block) {
+ checkNotNull(block);
+ return Bukkit.createBlockData(block.getAsString());
+ }
+
+ /**
+ * Create a WorldEdit BlockState from a Bukkit ItemStack
+ *
+ * @param itemStack The Bukkit ItemStack
+ * @return The WorldEdit BlockState
+ */
+ public static BlockState asBlockState(ItemStack itemStack) {
+ checkNotNull(itemStack);
+ if (itemStack.getType().isBlock()) {
+ return adapt(itemStack.getType().createBlockData());
+ } else {
+ return BlockTypes.AIR.getDefaultState();
+ }
+ }
+
+ /**
+ * Create a WorldEdit BaseItemStack from a Bukkit ItemStack
+ *
+ * @param itemStack The Bukkit ItemStack
+ * @return The WorldEdit BaseItemStack
+ */
+ public static BaseItemStack adapt(ItemStack itemStack) {
+ checkNotNull(itemStack);
+ return new BaseItemStack(ItemTypes.get(itemStack.getType().getKey().toString()), itemStack.getAmount());
+ }
+
+ /**
+ * Create a Bukkit ItemStack from a WorldEdit BaseItemStack
+ *
+ * @param item The WorldEdit BaseItemStack
+ * @return The Bukkit ItemStack
+ */
+ public static ItemStack adapt(BaseItemStack item) {
+ checkNotNull(item);
+ return new ItemStack(adapt(item.getType()), item.getAmount());
+ }
}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBiomeRegistry.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBiomeRegistry.java
index 72e3379fc..cb0fea4de 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBiomeRegistry.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBiomeRegistry.java
@@ -25,11 +25,12 @@ import com.sk89q.worldedit.world.biome.BiomeData;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
import org.bukkit.block.Biome;
-import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import javax.annotation.Nullable;
+
/**
* A biome registry for Bukkit.
*/
@@ -48,7 +49,7 @@ class BukkitBiomeRegistry implements BiomeRegistry {
public List getBiomes() {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
- List biomes = new ArrayList();
+ List biomes = new ArrayList<>();
for (Biome biome : Biome.values()) {
int biomeId = adapter.getBiomeId(biome);
biomes.add(new BaseBiome(biomeId));
@@ -65,12 +66,7 @@ class BukkitBiomeRegistry implements BiomeRegistry {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
final Biome bukkitBiome = adapter.getBiome(biome.getId());
- return new BiomeData() {
- @Override
- public String getName() {
- return bukkitBiome.name();
- }
- };
+ return bukkitBiome::name;
} else {
return null;
}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java
new file mode 100644
index 000000000..6f272af72
--- /dev/null
+++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java
@@ -0,0 +1,78 @@
+/*
+ * WorldEdit, a Minecraft world manipulation toolkit
+ * Copyright (C) sk89q
+ * 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 .
+ */
+
+package com.sk89q.worldedit.bukkit;
+
+import com.sk89q.worldedit.world.registry.BlockMaterial;
+import com.sk89q.worldedit.registry.state.Property;
+import com.sk89q.worldedit.world.block.BlockType;
+import com.sk89q.worldedit.world.registry.BundledBlockRegistry;
+import com.sk89q.worldedit.world.registry.PassthroughBlockMaterial;
+import org.bukkit.Material;
+
+import java.util.EnumMap;
+import java.util.Map;
+
+import javax.annotation.Nullable;
+
+public class BukkitBlockRegistry extends BundledBlockRegistry {
+
+ private Map materialMap = new EnumMap<>(Material.class);
+
+ @Nullable
+ @Override
+ public BlockMaterial getMaterial(BlockType blockType) {
+ return materialMap.computeIfAbsent(BukkitAdapter.adapt(blockType),
+ material -> new BukkitBlockMaterial(BukkitBlockRegistry.super.getMaterial(blockType), material));
+ }
+
+ @Nullable
+ @Override
+ public Map getProperties(BlockType blockType) {
+ if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) {
+ return WorldEditPlugin.getInstance().getBukkitImplAdapter().getProperties(blockType);
+ }
+ return super.getProperties(blockType);
+ }
+
+ public static class BukkitBlockMaterial extends PassthroughBlockMaterial {
+
+ private final Material material;
+
+ public BukkitBlockMaterial(@Nullable BlockMaterial material, Material bukkitMaterial) {
+ super(material);
+ this.material = bukkitMaterial;
+ }
+
+ @Override
+ public boolean isSolid() {
+ return material.isSolid();
+ }
+
+ @Override
+ public boolean isBurnable() {
+ return material.isBurnable();
+ }
+
+ @Override
+ public boolean isTranslucent() {
+ return material.isTransparent();
+ }
+ }
+}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandInspector.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandInspector.java
index 8f4b8e5ae..b392c50ac 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandInspector.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandInspector.java
@@ -19,6 +19,8 @@
package com.sk89q.worldedit.bukkit;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import com.sk89q.bukkit.util.CommandInspector;
import com.sk89q.minecraft.util.commands.CommandLocals;
import com.sk89q.worldedit.extension.platform.Actor;
@@ -30,8 +32,6 @@ import org.bukkit.command.CommandSender;
import java.util.logging.Logger;
-import static com.google.common.base.Preconditions.checkNotNull;
-
class BukkitCommandInspector implements CommandInspector {
private static final Logger logger = Logger.getLogger(BukkitCommandInspector.class.getCanonicalName());
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java
index df7fdd520..55929af02 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java
@@ -19,19 +19,20 @@
package com.sk89q.worldedit.bukkit;
-import com.sk89q.worldedit.session.SessionKey;
-import com.sk89q.worldedit.util.auth.AuthorizationException;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.cui.CUIEvent;
+import com.sk89q.worldedit.session.SessionKey;
+import com.sk89q.worldedit.util.auth.AuthorizationException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
-import javax.annotation.Nullable;
import java.io.File;
import java.util.UUID;
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
+import javax.annotation.Nullable;
public class BukkitCommandSender implements Actor {
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java
index cfc49b01b..418980ad7 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java
@@ -19,19 +19,20 @@
package com.sk89q.worldedit.bukkit;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.Player;
-import com.sk89q.worldedit.entity.metadata.EntityType;
+import com.sk89q.worldedit.entity.metadata.EntityProperties;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.NullWorld;
-import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
-import static com.google.common.base.Preconditions.checkNotNull;
+import javax.annotation.Nullable;
/**
* An adapter to adapt a Bukkit entity into a WorldEdit one.
@@ -47,7 +48,7 @@ class BukkitEntity implements Entity {
*/
BukkitEntity(org.bukkit.entity.Entity entity) {
checkNotNull(entity);
- this.entityRef = new WeakReference(entity);
+ this.entityRef = new WeakReference<>(entity);
}
@Override
@@ -105,8 +106,8 @@ class BukkitEntity implements Entity {
@Override
public T getFacet(Class extends T> cls) {
org.bukkit.entity.Entity entity = entityRef.get();
- if (entity != null && EntityType.class.isAssignableFrom(cls)) {
- return (T) new BukkitEntityType(entity);
+ if (entity != null && EntityProperties.class.isAssignableFrom(cls)) {
+ return (T) new BukkitEntityProperties(entity);
} else {
return null;
}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntityType.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntityProperties.java
similarity index 88%
rename from worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntityType.java
rename to worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntityProperties.java
index 57e57c29b..86618f62f 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntityType.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntityProperties.java
@@ -19,11 +19,14 @@
package com.sk89q.worldedit.bukkit;
-import com.sk89q.worldedit.entity.metadata.EntityType;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.sk89q.worldedit.entity.metadata.EntityProperties;
import com.sk89q.worldedit.util.Enums;
import org.bukkit.entity.Ambient;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Boat;
+import org.bukkit.entity.ComplexEntityPart;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.FallingBlock;
@@ -34,22 +37,21 @@ import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Painting;
+import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Villager;
import org.bukkit.entity.minecart.ExplosiveMinecart;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-class BukkitEntityType implements EntityType {
+class BukkitEntityProperties implements EntityProperties {
private static final org.bukkit.entity.EntityType armorStandType =
Enums.findByValue(org.bukkit.entity.EntityType.class, "ARMOR_STAND");
private final Entity entity;
- BukkitEntityType(Entity entity) {
+ BukkitEntityProperties(Entity entity) {
checkNotNull(entity);
this.entity = entity;
}
@@ -136,11 +138,16 @@ class BukkitEntityType implements EntityType {
@Override
public boolean isTagged() {
- return entity instanceof LivingEntity && ((LivingEntity) entity).getCustomName() != null;
+ return entity instanceof LivingEntity && entity.getCustomName() != null;
}
@Override
public boolean isArmorStand() {
return entity.getType() == armorStandType;
}
+
+ @Override
+ public boolean isPasteable() {
+ return !(entity instanceof Player || entity instanceof ComplexEntityPart);
+ }
}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java
index 25f02915b..7066da770 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java
@@ -20,32 +20,34 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.util.StringUtil;
-import com.sk89q.worldedit.LocalPlayer;
-import com.sk89q.worldedit.LocalWorld;
-import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
-import com.sk89q.worldedit.WorldVector;
-import com.sk89q.worldedit.blocks.BaseBlock;
+import com.sk89q.worldedit.world.block.BaseBlock;
+import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.entity.BaseEntity;
+import com.sk89q.worldedit.extension.platform.AbstractPlayerActor;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.session.SessionKey;
+import com.sk89q.worldedit.util.HandSide;
+import com.sk89q.worldedit.world.World;
+import com.sk89q.worldedit.world.gamemode.GameMode;
+import com.sk89q.worldedit.world.gamemode.GameModes;
import org.bukkit.Bukkit;
-import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
-import javax.annotation.Nullable;
import java.util.UUID;
-public class BukkitPlayer extends LocalPlayer {
+import javax.annotation.Nullable;
+
+public class BukkitPlayer extends AbstractPlayerActor {
private Player player;
private WorldEditPlugin plugin;
- public BukkitPlayer(WorldEditPlugin plugin, ServerInterface server, Player player) {
+ public BukkitPlayer(WorldEditPlugin plugin, Player player) {
this.plugin = plugin;
this.player = player;
}
@@ -56,15 +58,19 @@ public class BukkitPlayer extends LocalPlayer {
}
@Override
- public int getItemInHand() {
- ItemStack itemStack = player.getItemInHand();
- return itemStack != null ? itemStack.getTypeId() : 0;
+ public BaseItemStack getItemInHand(HandSide handSide) {
+ ItemStack itemStack = handSide == HandSide.MAIN_HAND
+ ? player.getInventory().getItemInMainHand()
+ : player.getInventory().getItemInOffHand();
+ return BukkitAdapter.adapt(itemStack);
}
@Override
- public BaseBlock getBlockInHand() throws WorldEditException {
- ItemStack itemStack = player.getItemInHand();
- return BukkitUtil.toBlock(getWorld(), itemStack);
+ public BaseBlock getBlockInHand(HandSide handSide) throws WorldEditException {
+ ItemStack itemStack = handSide == HandSide.MAIN_HAND
+ ? player.getInventory().getItemInMainHand()
+ : player.getInventory().getItemInOffHand();
+ return BukkitAdapter.asBlockState(itemStack).toBaseBlock();
}
@Override
@@ -73,25 +79,8 @@ public class BukkitPlayer extends LocalPlayer {
}
@Override
- public WorldVector getPosition() {
- Location loc = player.getLocation();
- return new WorldVector(BukkitUtil.getLocalWorld(loc.getWorld()),
- loc.getX(), loc.getY(), loc.getZ());
- }
-
- @Override
- public double getPitch() {
- return player.getLocation().getPitch();
- }
-
- @Override
- public double getYaw() {
- return player.getLocation().getYaw();
- }
-
- @Override
- public void giveItem(int type, int amt) {
- player.getInventory().addItem(new ItemStack(type, amt));
+ public void giveItem(BaseItemStack itemStack) {
+ player.getInventory().addItem(BukkitAdapter.adapt(itemStack));
}
@Override
@@ -138,6 +127,16 @@ public class BukkitPlayer extends LocalPlayer {
return new BukkitPlayerBlockBag(player);
}
+ @Override
+ public GameMode getGameMode() {
+ return GameModes.get(player.getGameMode().name().toLowerCase());
+ }
+
+ @Override
+ public void setGameMode(GameMode gameMode) {
+ player.setGameMode(org.bukkit.GameMode.valueOf(gameMode.getId().toUpperCase()));
+ }
+
@Override
public boolean hasPermission(String perm) {
return (!plugin.getLocalConfiguration().noOpPermissions && player.isOp())
@@ -146,8 +145,8 @@ public class BukkitPlayer extends LocalPlayer {
}
@Override
- public LocalWorld getWorld() {
- return BukkitUtil.getLocalWorld(player.getWorld());
+ public World getWorld() {
+ return BukkitAdapter.adapt(player.getWorld());
}
@Override
@@ -164,11 +163,6 @@ public class BukkitPlayer extends LocalPlayer {
return player;
}
- @Override
- public boolean hasCreativeMode() {
- return player.getGameMode() == GameMode.CREATIVE;
- }
-
@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
if (alwaysGlass || !player.getAllowFlight()) {
@@ -188,7 +182,7 @@ public class BukkitPlayer extends LocalPlayer {
@Override
public com.sk89q.worldedit.util.Location getLocation() {
Location nativeLocation = player.getLocation();
- Vector position = BukkitUtil.toVector(nativeLocation);
+ Vector position = BukkitAdapter.asVector(nativeLocation);
return new com.sk89q.worldedit.util.Location(
getWorld(),
position,
@@ -235,7 +229,7 @@ public class BukkitPlayer extends LocalPlayer {
// CopyOnWrite list for the list of players, but the Bukkit
// specification doesn't require thread safety (though the
// spec is extremely incomplete)
- return Bukkit.getServer().getPlayerExact(name) != null;
+ return Bukkit.getServer().getPlayer(uuid) != null;
}
@Override
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java
index acacad5e8..7334a48c8 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java
@@ -19,14 +19,16 @@
package com.sk89q.worldedit.bukkit;
-import com.sk89q.worldedit.WorldVector;
+import com.sk89q.worldedit.blocks.BaseItemStack;
+import com.sk89q.worldedit.extent.inventory.BlockBag;
+import com.sk89q.worldedit.extent.inventory.BlockBagException;
+import com.sk89q.worldedit.extent.inventory.OutOfBlocksException;
+import com.sk89q.worldedit.extent.inventory.OutOfSpaceException;
+import com.sk89q.worldedit.util.Location;
+import com.sk89q.worldedit.world.block.BlockState;
+import com.sk89q.worldedit.world.block.BlockTypes;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
-import com.sk89q.worldedit.extent.inventory.*;
-import com.sk89q.worldedit.blocks.BaseItem;
-import com.sk89q.worldedit.blocks.BaseItemStack;
-import com.sk89q.worldedit.blocks.BlockID;
-import com.sk89q.worldedit.blocks.ItemType;
public class BukkitPlayerBlockBag extends BlockBag {
@@ -61,14 +63,8 @@ public class BukkitPlayerBlockBag extends BlockBag {
}
@Override
- public void fetchItem(BaseItem item) throws BlockBagException {
- final int id = item.getType();
- final int damage = item.getData();
- int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
- assert(amount == 1);
- boolean usesDamageValue = ItemType.usesDamageValue(id);
-
- if (id == BlockID.AIR) {
+ public void fetchBlock(BlockState blockState) throws BlockBagException {
+ if (blockState.getBlockType() == BlockTypes.AIR) {
throw new IllegalArgumentException("Can't fetch air block");
}
@@ -83,16 +79,11 @@ public class BukkitPlayerBlockBag extends BlockBag {
continue;
}
- if (bukkitItem.getTypeId() != id) {
+ if (!BukkitAdapter.equals(blockState.getBlockType(), bukkitItem.getType())) {
// Type id doesn't fit
continue;
}
- if (usesDamageValue && bukkitItem.getDurability() != damage) {
- // Damage value doesn't fit.
- continue;
- }
-
int currentAmount = bukkitItem.getAmount();
if (currentAmount < 0) {
// Unlimited
@@ -116,16 +107,13 @@ public class BukkitPlayerBlockBag extends BlockBag {
}
@Override
- public void storeItem(BaseItem item) throws BlockBagException {
- final int id = item.getType();
- final int damage = item.getData();
- int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
- assert(amount <= 64);
- boolean usesDamageValue = ItemType.usesDamageValue(id);
-
- if (id == BlockID.AIR) {
+ public void storeBlock(BlockState blockState, int amount) throws BlockBagException {
+ if (blockState.getBlockType() == BlockTypes.AIR) {
throw new IllegalArgumentException("Can't store air block");
}
+ if (!blockState.getBlockType().hasItemType()) {
+ throw new IllegalArgumentException("This block cannot be stored");
+ }
loadInventory();
@@ -144,16 +132,11 @@ public class BukkitPlayerBlockBag extends BlockBag {
continue;
}
- if (bukkitItem.getTypeId() != id) {
+ if (!BukkitAdapter.equals(blockState.getBlockType(), bukkitItem.getType())) {
// Type id doesn't fit
continue;
}
- if (usesDamageValue && bukkitItem.getDurability() != damage) {
- // Damage value doesn't fit.
- continue;
- }
-
int currentAmount = bukkitItem.getAmount();
if (currentAmount < 0) {
// Unlimited
@@ -175,11 +158,11 @@ public class BukkitPlayerBlockBag extends BlockBag {
}
if (freeSlot > -1) {
- items[freeSlot] = new ItemStack(id, amount);
+ items[freeSlot] = BukkitAdapter.adapt(new BaseItemStack(blockState.getBlockType().getItemType(), amount));
return;
}
- throw new OutOfSpaceException(id);
+ throw new OutOfSpaceException(blockState.getBlockType());
}
@Override
@@ -191,11 +174,11 @@ public class BukkitPlayerBlockBag extends BlockBag {
}
@Override
- public void addSourcePosition(WorldVector pos) {
+ public void addSourcePosition(Location pos) {
}
@Override
- public void addSingleSourcePosition(WorldVector pos) {
+ public void addSingleSourcePosition(Location pos) {
}
}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorldData.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitRegistries.java
similarity index 72%
rename from worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorldData.java
rename to worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitRegistries.java
index 6d747f4aa..6ed0999c7 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorldData.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitRegistries.java
@@ -20,20 +20,27 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
-import com.sk89q.worldedit.world.registry.LegacyWorldData;
+import com.sk89q.worldedit.world.registry.BlockRegistry;
+import com.sk89q.worldedit.world.registry.BundledRegistries;
/**
* World data for the Bukkit platform.
*/
-class BukkitWorldData extends LegacyWorldData {
+class BukkitRegistries extends BundledRegistries {
- private static final BukkitWorldData INSTANCE = new BukkitWorldData();
+ private static final BukkitRegistries INSTANCE = new BukkitRegistries();
+ private final BlockRegistry blockRegistry = new BukkitBlockRegistry();
private final BiomeRegistry biomeRegistry = new BukkitBiomeRegistry();
/**
* Create a new instance.
*/
- BukkitWorldData() {
+ BukkitRegistries() {
+ }
+
+ @Override
+ public BlockRegistry getBlockRegistry() {
+ return blockRegistry;
}
@Override
@@ -46,7 +53,7 @@ class BukkitWorldData extends LegacyWorldData {
*
* @return an instance
*/
- public static BukkitWorldData getInstance() {
+ public static BukkitRegistries getInstance() {
return INSTANCE;
}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java
index 3681aff06..3e8f4bcf9 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java
@@ -22,8 +22,6 @@ package com.sk89q.worldedit.bukkit;
import com.sk89q.bukkit.util.CommandInfo;
import com.sk89q.bukkit.util.CommandRegistration;
import com.sk89q.worldedit.LocalConfiguration;
-import com.sk89q.worldedit.LocalWorld;
-import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
@@ -32,30 +30,29 @@ import com.sk89q.worldedit.extension.platform.Preference;
import com.sk89q.worldedit.util.command.CommandMapping;
import com.sk89q.worldedit.util.command.Description;
import com.sk89q.worldedit.util.command.Dispatcher;
+import com.sk89q.worldedit.world.registry.Registries;
import org.bukkit.Bukkit;
-import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
-import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
-public class BukkitServerInterface extends ServerInterface implements MultiUserPlatform {
+import javax.annotation.Nullable;
+
+public class BukkitServerInterface implements MultiUserPlatform {
public Server server;
public WorldEditPlugin plugin;
private CommandRegistration dynamicCommands;
- private BukkitBiomeRegistry biomes;
private boolean hookingEvents;
public BukkitServerInterface(WorldEditPlugin plugin, Server server) {
this.plugin = plugin;
this.server = server;
- this.biomes = new BukkitBiomeRegistry();
dynamicCommands = new CommandRegistration(plugin);
}
@@ -64,9 +61,8 @@ public class BukkitServerInterface extends ServerInterface implements MultiUserP
}
@Override
- public int resolveItem(String name) {
- Material mat = Material.matchMaterial(name);
- return mat == null ? 0 : mat.getId();
+ public Registries getRegistries() {
+ return BukkitRegistries.getInstance();
}
@Override
@@ -86,12 +82,12 @@ public class BukkitServerInterface extends ServerInterface implements MultiUserP
}
@Override
- public List getWorlds() {
+ public List getWorlds() {
List worlds = server.getWorlds();
- List ret = new ArrayList(worlds.size());
+ List ret = new ArrayList<>(worlds.size());
for (World world : worlds) {
- ret.add(BukkitUtil.getLocalWorld(world));
+ ret.add(BukkitAdapter.adapt(world));
}
return ret;
@@ -104,7 +100,7 @@ public class BukkitServerInterface extends ServerInterface implements MultiUserP
return player;
} else {
org.bukkit.entity.Player bukkitPlayer = server.getPlayerExact(player.getName());
- return bukkitPlayer != null ? new BukkitPlayer(plugin, this, bukkitPlayer) : null;
+ return bukkitPlayer != null ? new BukkitPlayer(plugin, bukkitPlayer) : null;
}
}
@@ -121,7 +117,7 @@ public class BukkitServerInterface extends ServerInterface implements MultiUserP
@Override
public void registerCommands(Dispatcher dispatcher) {
- List toRegister = new ArrayList();
+ List toRegister = new ArrayList<>();
BukkitCommandInspector inspector = new BukkitCommandInspector(plugin, dispatcher);
for (CommandMapping command : dispatcher.getCommands()) {
@@ -163,7 +159,7 @@ public class BukkitServerInterface extends ServerInterface implements MultiUserP
@Override
public Map getCapabilities() {
- Map capabilities = new EnumMap(Capability.class);
+ Map capabilities = new EnumMap<>(Capability.class);
capabilities.put(Capability.CONFIGURATION, Preference.NORMAL);
capabilities.put(Capability.WORLDEDIT_CUI, Preference.NORMAL);
capabilities.put(Capability.GAME_HOOKS, Preference.PREFERRED);
@@ -179,9 +175,9 @@ public class BukkitServerInterface extends ServerInterface implements MultiUserP
@Override
public Collection getConnectedUsers() {
- List users = new ArrayList();
+ List users = new ArrayList<>();
for (org.bukkit.entity.Player player : Bukkit.getServer().getOnlinePlayers()) {
- users.add(new BukkitPlayer(plugin, this, player));
+ users.add(new BukkitPlayer(plugin, player));
}
return users;
}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java
deleted file mode 100644
index d4cb72a6d..000000000
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.bukkit;
-
-import java.util.List;
-
-import com.sk89q.worldedit.NotABlockException;
-import com.sk89q.worldedit.WorldEditException;
-import com.sk89q.worldedit.blocks.BaseBlock;
-import com.sk89q.worldedit.blocks.BlockID;
-import com.sk89q.worldedit.blocks.BlockType;
-import com.sk89q.worldedit.blocks.ItemID;
-import com.sk89q.worldedit.blocks.SkullBlock;
-import org.bukkit.DyeColor;
-import org.bukkit.Server;
-import org.bukkit.World;
-import org.bukkit.block.Block;
-import org.bukkit.block.BlockFace;
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.ExperienceOrb;
-import org.bukkit.entity.Item;
-import org.bukkit.entity.Painting;
-import org.bukkit.entity.Player;
-
-import com.sk89q.worldedit.BlockVector;
-import com.sk89q.worldedit.BlockWorldVector;
-import com.sk89q.worldedit.LocalWorld;
-import com.sk89q.worldedit.Location;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.WorldVector;
-import com.sk89q.worldedit.bukkit.entity.BukkitEntity;
-import com.sk89q.worldedit.bukkit.entity.BukkitExpOrb;
-import com.sk89q.worldedit.bukkit.entity.BukkitItem;
-import com.sk89q.worldedit.bukkit.entity.BukkitPainting;
-import org.bukkit.inventory.ItemStack;
-import org.bukkit.material.Dye;
-
-public final class BukkitUtil {
-
- private BukkitUtil() {
- }
-
- public static LocalWorld getLocalWorld(World w) {
- return new BukkitWorld(w);
- }
-
- public static BlockVector toVector(Block block) {
- return new BlockVector(block.getX(), block.getY(), block.getZ());
- }
-
- public static BlockVector toVector(BlockFace face) {
- return new BlockVector(face.getModX(), face.getModY(), face.getModZ());
- }
-
- public static BlockWorldVector toWorldVector(Block block) {
- return new BlockWorldVector(getLocalWorld(block.getWorld()), block.getX(), block.getY(), block.getZ());
- }
-
- public static Vector toVector(org.bukkit.Location loc) {
- return new Vector(loc.getX(), loc.getY(), loc.getZ());
- }
-
- public static Location toLocation(org.bukkit.Location loc) {
- return new Location(
- getLocalWorld(loc.getWorld()),
- new Vector(loc.getX(), loc.getY(), loc.getZ()),
- loc.getYaw(), loc.getPitch()
- );
- }
-
- public static Vector toVector(org.bukkit.util.Vector vector) {
- return new Vector(vector.getX(), vector.getY(), vector.getZ());
- }
-
- public static org.bukkit.Location toLocation(WorldVector pt) {
- return new org.bukkit.Location(toWorld(pt), pt.getX(), pt.getY(), pt.getZ());
- }
-
- public static org.bukkit.Location toLocation(World world, Vector pt) {
- return new org.bukkit.Location(world, pt.getX(), pt.getY(), pt.getZ());
- }
-
- public static org.bukkit.Location center(org.bukkit.Location loc) {
- return new org.bukkit.Location(
- loc.getWorld(),
- loc.getBlockX() + 0.5,
- loc.getBlockY() + 0.5,
- loc.getBlockZ() + 0.5,
- loc.getPitch(),
- loc.getYaw()
- );
- }
-
- public static Player matchSinglePlayer(Server server, String name) {
- List players = server.matchPlayer(name);
- if (players.isEmpty()) {
- return null;
- }
- return players.get(0);
- }
-
- public static Block toBlock(BlockWorldVector pt) {
- return toWorld(pt).getBlockAt(toLocation(pt));
- }
-
- public static World toWorld(WorldVector pt) {
- return ((BukkitWorld) pt.getWorld()).getWorld();
- }
-
- /**
- * Bukkit's Location class has serious problems with floating point
- * precision.
- */
- @SuppressWarnings("RedundantIfStatement")
- public static boolean equals(org.bukkit.Location a, org.bukkit.Location b) {
- if (Math.abs(a.getX() - b.getX()) > EQUALS_PRECISION) return false;
- if (Math.abs(a.getY() - b.getY()) > EQUALS_PRECISION) return false;
- if (Math.abs(a.getZ() - b.getZ()) > EQUALS_PRECISION) return false;
- return true;
- }
-
- public static final double EQUALS_PRECISION = 0.0001;
-
- public static org.bukkit.Location toLocation(Location location) {
- Vector pt = location.getPosition();
- return new org.bukkit.Location(
- toWorld(location.getWorld()),
- pt.getX(), pt.getY(), pt.getZ(),
- location.getYaw(), location.getPitch()
- );
- }
-
- public static World toWorld(final LocalWorld world) {
- return ((BukkitWorld) world).getWorld();
- }
-
- public static BukkitEntity toLocalEntity(Entity e) {
- switch (e.getType()) {
- case EXPERIENCE_ORB:
- return new BukkitExpOrb(toLocation(e.getLocation()), e.getUniqueId(), ((ExperienceOrb)e).getExperience());
- case PAINTING:
- Painting paint = (Painting) e;
- return new BukkitPainting(toLocation(e.getLocation()), paint.getArt(), paint.getFacing(), e.getUniqueId());
- case DROPPED_ITEM:
- return new BukkitItem(toLocation(e.getLocation()), ((Item)e).getItemStack(), e.getUniqueId());
- default:
- return new BukkitEntity(toLocation(e.getLocation()), e.getType(), e.getUniqueId());
- }
- }
-
- public static BaseBlock toBlock(LocalWorld world, ItemStack itemStack) throws WorldEditException {
- final int typeId = itemStack.getTypeId();
-
- switch (typeId) {
- case ItemID.INK_SACK:
- final Dye materialData = (Dye) itemStack.getData();
- if (materialData.getColor() == DyeColor.BROWN) {
- return new BaseBlock(BlockID.COCOA_PLANT, -1);
- }
- break;
-
- case ItemID.HEAD:
- return new SkullBlock(0, (byte) itemStack.getDurability());
-
- default:
- final BaseBlock baseBlock = BlockType.getBlockForItem(typeId, itemStack.getDurability());
- if (baseBlock != null) {
- return baseBlock;
- }
- break;
- }
-
- if (world.isValidBlockType(typeId)) {
- return new BaseBlock(typeId, -1);
- }
-
- throw new NotABlockException(typeId);
- }
-}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java
index df7714295..c0d16dddb 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java
@@ -19,24 +19,27 @@
package com.sk89q.worldedit.bukkit;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.EditSession;
-import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
-import com.sk89q.worldedit.blocks.BaseBlock;
+import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.blocks.BaseItemStack;
-import com.sk89q.worldedit.blocks.LazyBlock;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.entity.BaseEntity;
+import com.sk89q.worldedit.history.change.BlockChange;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.TreeGenerator;
+import com.sk89q.worldedit.world.AbstractWorld;
import com.sk89q.worldedit.world.biome.BaseBiome;
-import com.sk89q.worldedit.world.registry.WorldData;
+import com.sk89q.worldedit.world.block.BlockStateHolder;
+import com.sk89q.worldedit.world.weather.WeatherType;
+import com.sk89q.worldedit.world.weather.WeatherTypes;
import org.bukkit.Effect;
-import org.bukkit.Material;
import org.bukkit.TreeType;
import org.bukkit.World;
import org.bukkit.block.Biome;
@@ -46,9 +49,7 @@ import org.bukkit.block.Chest;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.DoubleChestInventory;
import org.bukkit.inventory.Inventory;
-import org.bukkit.inventory.ItemStack;
-import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.EnumMap;
@@ -58,13 +59,13 @@ import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
-import static com.google.common.base.Preconditions.checkNotNull;
+import javax.annotation.Nullable;
-public class BukkitWorld extends LocalWorld {
+public class BukkitWorld extends AbstractWorld {
private static final Logger logger = WorldEdit.logger;
- private static final Map effects = new HashMap();
+ private static final Map effects = new HashMap<>();
static {
for (Effect effect : Effect.values()) {
effects.put(effect.getId(), effect);
@@ -78,9 +79,8 @@ public class BukkitWorld extends LocalWorld {
*
* @param world the world
*/
- @SuppressWarnings("unchecked")
public BukkitWorld(World world) {
- this.worldRef = new WeakReference(world);
+ this.worldRef = new WeakReference<>(world);
}
@Override
@@ -88,9 +88,9 @@ public class BukkitWorld extends LocalWorld {
World world = getWorld();
List ents = world.getEntities();
- List entities = new ArrayList();
+ List entities = new ArrayList<>();
for (Entity ent : ents) {
- if (region.contains(BukkitUtil.toVector(ent.getLocation()))) {
+ if (region.contains(BukkitAdapter.asVector(ent.getLocation()))) {
entities.add(BukkitAdapter.adapt(ent));
}
}
@@ -99,7 +99,7 @@ public class BukkitWorld extends LocalWorld {
@Override
public List getEntities() {
- List list = new ArrayList();
+ List list = new ArrayList<>();
for (Entity entity : getWorld().getEntities()) {
list.add(BukkitAdapter.adapt(entity));
}
@@ -111,10 +111,19 @@ public class BukkitWorld extends LocalWorld {
public com.sk89q.worldedit.entity.Entity createEntity(com.sk89q.worldedit.util.Location location, BaseEntity entity) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
- Entity createdEntity = adapter.createEntity(BukkitAdapter.adapt(getWorld(), location), entity);
- if (createdEntity != null) {
- return new BukkitEntity(createdEntity);
- } else {
+ try {
+ Entity createdEntity = adapter.createEntity(BukkitAdapter.adapt(getWorld(), location), entity);
+ if (createdEntity != null) {
+ return new BukkitEntity(createdEntity);
+ } else {
+ return null;
+ }
+ } catch (Exception e) {
+ logger.warning("Corrupt entity found when creating: " + entity.getType().getId());
+ if (entity.getNbtData() != null) {
+ logger.warning(entity.getNbtData().toString());
+ }
+ e.printStackTrace();
return null;
}
} else {
@@ -156,7 +165,7 @@ public class BukkitWorld extends LocalWorld {
@Override
public boolean regenerate(Region region, EditSession editSession) {
- BaseBlock[] history = new BaseBlock[16 * 16 * (getMaxY() + 1)];
+ BlockStateHolder[] history = new BlockStateHolder[16 * 16 * (getMaxY() + 1)];
for (Vector2D chunk : region.getChunks()) {
Vector min = new Vector(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16);
@@ -167,7 +176,7 @@ public class BukkitWorld extends LocalWorld {
for (int z = 0; z < 16; ++z) {
Vector pt = min.add(x, y, z);
int index = y * 16 * 16 + z * 16 + x;
- history[index] = editSession.getBlock(pt);
+ history[index] = editSession.getFullBlock(pt);
}
}
}
@@ -189,8 +198,7 @@ public class BukkitWorld extends LocalWorld {
if (!region.contains(pt)) {
editSession.smartSetBlock(pt, history[index]);
} else { // Otherwise fool with history
- editSession.rememberChange(pt, history[index],
- editSession.rawGetBlock(pt));
+ editSession.getChangeSet().add(new BlockChange(pt.toBlockVector(), history[index], editSession.getFullBlock(pt)));
}
}
}
@@ -248,41 +256,11 @@ public class BukkitWorld extends LocalWorld {
return true;
}
- @Override
- @Deprecated
- public boolean generateTree(EditSession editSession, Vector pt) {
- return generateTree(TreeGenerator.TreeType.TREE, editSession, pt);
- }
-
- @Override
- @Deprecated
- public boolean generateBigTree(EditSession editSession, Vector pt) {
- return generateTree(TreeGenerator.TreeType.BIG_TREE, editSession, pt);
- }
-
- @Override
- @Deprecated
- public boolean generateBirchTree(EditSession editSession, Vector pt) {
- return generateTree(TreeGenerator.TreeType.BIRCH, editSession, pt);
- }
-
- @Override
- @Deprecated
- public boolean generateRedwoodTree(EditSession editSession, Vector pt) {
- return generateTree(TreeGenerator.TreeType.REDWOOD, editSession, pt);
- }
-
- @Override
- @Deprecated
- public boolean generateTallRedwoodTree(EditSession editSession, Vector pt) {
- return generateTree(TreeGenerator.TreeType.TALL_REDWOOD, editSession, pt);
- }
-
/**
* An EnumMap that stores which WorldEdit TreeTypes apply to which Bukkit TreeTypes
*/
private static final EnumMap treeTypeMapping =
- new EnumMap(TreeGenerator.TreeType.class);
+ new EnumMap<>(TreeGenerator.TreeType.class);
static {
for (TreeGenerator.TreeType type : TreeGenerator.TreeType.values()) {
@@ -316,22 +294,14 @@ public class BukkitWorld extends LocalWorld {
public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector pt) {
World world = getWorld();
TreeType bukkitType = toBukkitTreeType(type);
- return type != null && world.generateTree(BukkitUtil.toLocation(world, pt), bukkitType,
+ return type != null && world.generateTree(BukkitAdapter.adapt(world, pt), bukkitType,
new EditSessionBlockChangeDelegate(editSession));
}
@Override
public void dropItem(Vector pt, BaseItemStack item) {
World world = getWorld();
- ItemStack bukkitItem = new ItemStack(item.getType(), item.getAmount(),
- item.getData());
- world.dropItemNaturally(BukkitUtil.toLocation(world, pt), bukkitItem);
- }
-
- @SuppressWarnings("deprecation")
- @Override
- public boolean isValidBlockType(int type) {
- return Material.getMaterial(type) != null && Material.getMaterial(type).isBlock();
+ world.dropItemNaturally(BukkitAdapter.adapt(world, pt), BukkitAdapter.adapt(item));
}
@Override
@@ -383,14 +353,54 @@ public class BukkitWorld extends LocalWorld {
return false;
}
- world.playEffect(BukkitUtil.toLocation(world, position), effect, data);
+ world.playEffect(BukkitAdapter.adapt(world, position), effect, data);
return true;
}
@Override
- public WorldData getWorldData() {
- return BukkitWorldData.getInstance();
+ public WeatherType getWeather() {
+ if (getWorld().isThundering()) {
+ return WeatherTypes.THUNDER_STORM;
+ } else if (getWorld().hasStorm()) {
+ return WeatherTypes.RAIN;
+ }
+
+ return WeatherTypes.CLEAR;
+ }
+
+ @Override
+ public long getRemainingWeatherDuration() {
+ return getWorld().getWeatherDuration();
+ }
+
+ @Override
+ public void setWeather(WeatherType weatherType) {
+ if (weatherType == WeatherTypes.THUNDER_STORM) {
+ getWorld().setThundering(true);
+ } else if (weatherType == WeatherTypes.RAIN) {
+ getWorld().setStorm(true);
+ } else {
+ getWorld().setStorm(false);
+ getWorld().setThundering(false);
+ }
+ }
+
+ @Override
+ public void setWeather(WeatherType weatherType, long duration) {
+ // Who named these methods...
+ if (weatherType == WeatherTypes.THUNDER_STORM) {
+ getWorld().setThundering(true);
+ getWorld().setThunderDuration((int) duration);
+ getWorld().setWeatherDuration((int) duration);
+ } else if (weatherType == WeatherTypes.RAIN) {
+ getWorld().setStorm(true);
+ getWorld().setWeatherDuration((int) duration);
+ } else {
+ getWorld().setStorm(false);
+ getWorld().setThundering(false);
+ getWorld().setWeatherDuration((int) duration);
+ }
}
@Override
@@ -399,35 +409,44 @@ public class BukkitWorld extends LocalWorld {
}
@Override
- public BaseBlock getBlock(Vector position) {
+ public com.sk89q.worldedit.world.block.BlockState getBlock(Vector position) {
+ Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
+ return BukkitAdapter.adapt(bukkitBlock.getBlockData());
+ }
+
+ @Override
+ public boolean setBlock(Vector position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException {
+ BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
+ if (adapter != null) {
+ try {
+ return adapter.setBlock(BukkitAdapter.adapt(getWorld(), position), block, notifyAndLight);
+ } catch (Exception e) {
+ if (block instanceof BaseBlock && ((BaseBlock) block).getNbtData() != null) {
+ logger.warning("Tried to set a corrupt tile entity at " + position.toString());
+ logger.warning(((BaseBlock) block).getNbtData().toString());
+ }
+ e.printStackTrace();
+ Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
+ bukkitBlock.setBlockData(BukkitAdapter.adapt(block), notifyAndLight);
+ return true;
+ }
+ } else {
+ Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
+ bukkitBlock.setBlockData(BukkitAdapter.adapt(block), notifyAndLight);
+ return true;
+ }
+ }
+
+ @Override
+ public BaseBlock getFullBlock(Vector position) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
return adapter.getBlock(BukkitAdapter.adapt(getWorld(), position));
} else {
- Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
- return new BaseBlock(bukkitBlock.getTypeId(), bukkitBlock.getData());
+ return getBlock(position).toBaseBlock();
}
}
- @Override
- public boolean setBlock(Vector position, BaseBlock block, boolean notifyAndLight) throws WorldEditException {
- BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
- if (adapter != null) {
- return adapter.setBlock(BukkitAdapter.adapt(getWorld(), position), block, notifyAndLight);
- } else {
- Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
- return bukkitBlock.setTypeIdAndData(block.getType(), (byte) block.getData(), notifyAndLight);
- }
- }
-
- @SuppressWarnings("deprecation")
- @Override
- public BaseBlock getLazyBlock(Vector position) {
- World world = getWorld();
- Block bukkitBlock = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
- return new LazyBlock(bukkitBlock.getTypeId(), bukkitBlock.getData(), this, position);
- }
-
@Override
public BaseBiome getBiome(Vector2D position) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
@@ -450,12 +469,4 @@ public class BukkitWorld extends LocalWorld {
return false;
}
}
-
- /**
- * @deprecated Use {@link #setBlock(Vector, BaseBlock, boolean)}
- */
- @Deprecated
- public boolean setBlock(Vector pt, com.sk89q.worldedit.foundation.Block block, boolean notifyAdjacent) throws WorldEditException {
- return setBlock(pt, (BaseBlock) block, notifyAdjacent);
- }
}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java
index c3d1b2059..24e14d964 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java
@@ -19,12 +19,12 @@
package com.sk89q.worldedit.bukkit;
-import com.sk89q.worldedit.blocks.BlockID;
-import org.bukkit.BlockChangeDelegate;
import com.sk89q.worldedit.EditSession;
-import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.MaxChangedBlocksException;
-import com.sk89q.worldedit.blocks.BaseBlock;
+import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.world.block.BlockTypes;
+import org.bukkit.BlockChangeDelegate;
+import org.bukkit.block.data.BlockData;
/**
* Proxy class to catch calls to set blocks.
@@ -38,36 +38,18 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
}
@Override
- public boolean setRawTypeId(int x, int y, int z, int typeId) {
+ public boolean setBlockData(int x, int y, int z, BlockData blockData) {
try {
- return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId));
- } catch (MaxChangedBlocksException ex) {
+ editSession.setBlock(new Vector(x, y, z), BukkitAdapter.adapt(blockData));
+ } catch (MaxChangedBlocksException e) {
return false;
}
+ return true;
}
@Override
- public boolean setRawTypeIdAndData(int x, int y, int z, int typeId, int data) {
- try {
- return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId, data));
- } catch (MaxChangedBlocksException ex) {
- return false;
- }
- }
-
- @Override
- public boolean setTypeId(int x, int y, int z, int typeId) {
- return setRawTypeId(x, y, z, typeId);
- }
-
- @Override
- public boolean setTypeIdAndData(int x, int y, int z, int typeId, int data) {
- return setRawTypeIdAndData(x, y, z, typeId, data);
- }
-
- @Override
- public int getTypeId(int x, int y, int z) {
- return editSession.getBlockType(new Vector(x, y, z));
+ public BlockData getBlockData(int x, int y, int z) {
+ return BukkitAdapter.adapt(editSession.getBlock(new Vector(x, y, z)));
}
@Override
@@ -77,7 +59,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
@Override
public boolean isEmpty(int x, int y, int z) {
- return editSession.getBlockType(new Vector(x, y, z)) == BlockID.AIR;
+ return editSession.getBlock(new Vector(x, y, z)).getBlockType() == BlockTypes.AIR;
}
}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditListener.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditListener.java
index bd9a92b09..44dd56b44 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditListener.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditListener.java
@@ -22,10 +22,9 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.util.StringUtil;
-import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.WorldEdit;
-import com.sk89q.worldedit.WorldVector;
-import com.sk89q.worldedit.internal.LocalWorldAdapter;
+import com.sk89q.worldedit.entity.Player;
+import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World;
import org.bukkit.block.Block;
import org.bukkit.event.Event.Result;
@@ -67,7 +66,7 @@ public class WorldEditListener implements Listener {
}
// this will automatically refresh their session, we don't have to do anything
- WorldEdit.getInstance().getSession(plugin.wrapPlayer(event.getPlayer()));
+ WorldEdit.getInstance().getSessionManager().get(plugin.wrapPlayer(event.getPlayer()));
}
/**
@@ -120,18 +119,17 @@ public class WorldEditListener implements Listener {
return; // TODO api needs to be able to get either hand depending on event
// for now just ignore all off hand interacts
}
- } catch (NoSuchMethodError ignored) {
- } catch (NoSuchFieldError ignored) {
+ } catch (NoSuchMethodError | NoSuchFieldError ignored) {
}
- final LocalPlayer player = plugin.wrapPlayer(event.getPlayer());
+ final Player player = plugin.wrapPlayer(event.getPlayer());
final World world = player.getWorld();
final WorldEdit we = plugin.getWorldEdit();
Action action = event.getAction();
if (action == Action.LEFT_CLICK_BLOCK) {
final Block clickedBlock = event.getClickedBlock();
- final WorldVector pos = new WorldVector(LocalWorldAdapter.adapt(world), clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());
+ final Location pos = new Location(world, clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());
if (we.handleBlockLeftClick(player, pos)) {
event.setCancelled(true);
@@ -150,8 +148,7 @@ public class WorldEditListener implements Listener {
} else if (action == Action.RIGHT_CLICK_BLOCK) {
final Block clickedBlock = event.getClickedBlock();
- final WorldVector pos = new WorldVector(LocalWorldAdapter.adapt(world), clickedBlock.getX(),
- clickedBlock.getY(), clickedBlock.getZ());
+ final Location pos = new Location(world, clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());
if (we.handleBlockRightClick(player, pos)) {
event.setCancelled(true);
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java
index 4ffde3d85..057742b92 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java
@@ -19,23 +19,17 @@
package com.sk89q.worldedit.bukkit;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import com.google.common.base.Joiner;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.wepif.PermissionsResolverManager;
import com.sk89q.worldedit.EditSession;
-import com.sk89q.worldedit.IncompleteRegionException;
-import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
-import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.WorldEdit;
-import com.sk89q.worldedit.WorldEditOperation;
import com.sk89q.worldedit.bukkit.adapter.AdapterLoadException;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplLoader;
-import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
-import com.sk89q.worldedit.bukkit.selections.CylinderSelection;
-import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection;
-import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.event.platform.CommandSuggestionEvent;
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
@@ -43,21 +37,12 @@ import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extent.inventory.BlockBag;
-import com.sk89q.worldedit.regions.CuboidRegion;
-import com.sk89q.worldedit.regions.CylinderRegion;
-import com.sk89q.worldedit.regions.Polygonal2DRegion;
-import com.sk89q.worldedit.regions.Region;
-import com.sk89q.worldedit.regions.RegionSelector;
-import com.sk89q.worldedit.util.Java8Detector;
-
-import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
-import javax.annotation.Nullable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -69,21 +54,19 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
-import static com.google.common.base.Preconditions.checkNotNull;
+import javax.annotation.Nullable;
/**
* Plugin for Bukkit.
*/
-@SuppressWarnings("deprecation")
public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
private static final Logger log = Logger.getLogger(WorldEditPlugin.class.getCanonicalName());
- public static final String CUI_PLUGIN_CHANNEL = "WECUI";
+ public static final String CUI_PLUGIN_CHANNEL = "worldedit:cui";
private static WorldEditPlugin INSTANCE;
private BukkitImplAdapter bukkitAdapter;
private BukkitServerInterface server;
- private final WorldEditAPI api = new WorldEditAPI(this);
private BukkitConfiguration config;
/**
@@ -99,12 +82,15 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
WorldEdit worldEdit = WorldEdit.getInstance();
- loadConfig(); // Load configuration
- PermissionsResolverManager.initialize(this); // Setup permission resolver
+ loadAdapter(); // Need an adapter to work with special blocks with NBT data
// Setup platform
server = new BukkitServerInterface(this, getServer());
worldEdit.getPlatformManager().register(server);
+ worldEdit.loadMappings();
+
+ loadConfig(); // Load configuration
+ PermissionsResolverManager.initialize(this); // Setup permission resolver
// Register CUI
getServer().getMessenger().registerIncomingPluginChannel(this, CUI_PLUGIN_CHANNEL, new CUIChannelListener(this));
@@ -117,11 +103,6 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
// Forge WorldEdit and there's (probably) not going to be any other
// platforms to be worried about... at the current time of writing
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent());
-
- loadAdapter(); // Need an adapter to work with special blocks with NBT data
-
- // Check Java version
- Java8Detector.notifyIfNot8();
}
private void loadConfig() {
@@ -169,7 +150,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
@Override
public void onDisable() {
WorldEdit worldEdit = WorldEdit.getInstance();
- worldEdit.clearSessions();
+ worldEdit.getSessionManager().clear();
worldEdit.getPlatformManager().unregister(server);
if (config != null) {
config.unload();
@@ -269,7 +250,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
* @return a session
*/
public LocalSession getSession(Player player) {
- return WorldEdit.getInstance().getSession(wrapPlayer(player));
+ return WorldEdit.getInstance().getSessionManager().get(wrapPlayer(player));
}
/**
@@ -279,8 +260,8 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
* @return a session
*/
public EditSession createEditSession(Player player) {
- LocalPlayer wePlayer = wrapPlayer(player);
- LocalSession session = WorldEdit.getInstance().getSession(wePlayer);
+ com.sk89q.worldedit.entity.Player wePlayer = wrapPlayer(player);
+ LocalSession session = WorldEdit.getInstance().getSessionManager().get(wePlayer);
BlockBag blockBag = session.getBlockBag(wePlayer);
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory()
@@ -297,8 +278,8 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
* @param editSession an edit session
*/
public void remember(Player player, EditSession editSession) {
- LocalPlayer wePlayer = wrapPlayer(player);
- LocalSession session = WorldEdit.getInstance().getSession(wePlayer);
+ com.sk89q.worldedit.entity.Player wePlayer = wrapPlayer(player);
+ LocalSession session = WorldEdit.getInstance().getSessionManager().get(wePlayer);
session.remember(editSession);
editSession.flushQueue();
@@ -306,38 +287,6 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
WorldEdit.getInstance().flushBlockBag(wePlayer, editSession);
}
- /**
- * Wrap an operation into an EditSession.
- *
- * @param player a player
- * @param op the operation
- * @throws Throwable on any error
- * @deprecated use the regular API
- */
- @Deprecated
- public void perform(Player player, WorldEditOperation op) throws Throwable {
- LocalPlayer wePlayer = wrapPlayer(player);
- LocalSession session = WorldEdit.getInstance().getSession(wePlayer);
-
- EditSession editSession = createEditSession(player);
- try {
- op.run(session, wePlayer, editSession);
- } finally {
- remember(player, editSession);
- }
- }
-
- /**
- * Get the API.
- *
- * @return the API
- * @deprecated use the regular API
- */
- @Deprecated
- public WorldEditAPI getAPI() {
- return api;
- }
-
/**
* Returns the configuration used by WorldEdit.
*
@@ -357,13 +306,13 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
}
/**
- * Used to wrap a Bukkit Player as a LocalPlayer.
+ * Used to wrap a Bukkit Player as a WorldEdit Player.
*
* @param player a player
* @return a wrapped player
*/
public BukkitPlayer wrapPlayer(Player player) {
- return new BukkitPlayer(this, this.server, player);
+ return new BukkitPlayer(this, player);
}
public Actor wrapCommandSender(CommandSender sender) {
@@ -374,15 +323,6 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
return new BukkitCommandSender(this, sender);
}
- /**
- * Get the server interface.
- *
- * @return the server interface
- */
- public ServerInterface getServerInterface() {
- return server;
- }
-
BukkitServerInterface getInternalPlatform() {
return server;
}
@@ -396,64 +336,6 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
return WorldEdit.getInstance();
}
- /**
- * Gets the region selection for the player.
- *
- * @param player aplayer
- * @return the selection or null if there was none
- */
- public Selection getSelection(Player player) {
- if (player == null) {
- throw new IllegalArgumentException("Null player not allowed");
- }
- if (!player.isOnline()) {
- throw new IllegalArgumentException("Offline player not allowed");
- }
-
- LocalSession session = WorldEdit.getInstance().getSession(wrapPlayer(player));
- RegionSelector selector = session.getRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()));
-
- try {
- Region region = selector.getRegion();
- World world = BukkitAdapter.asBukkitWorld(session.getSelectionWorld()).getWorld();
-
- if (region instanceof CuboidRegion) {
- return new CuboidSelection(world, selector, (CuboidRegion) region);
- } else if (region instanceof Polygonal2DRegion) {
- return new Polygonal2DSelection(world, selector, (Polygonal2DRegion) region);
- } else if (region instanceof CylinderRegion) {
- return new CylinderSelection(world, selector, (CylinderRegion) region);
- } else {
- return null;
- }
- } catch (IncompleteRegionException e) {
- return null;
- }
- }
-
- /**
- * Sets the region selection for a player.
- *
- * @param player the player
- * @param selection a selection
- */
- public void setSelection(Player player, Selection selection) {
- if (player == null) {
- throw new IllegalArgumentException("Null player not allowed");
- }
- if (!player.isOnline()) {
- throw new IllegalArgumentException("Offline player not allowed");
- }
- if (selection == null) {
- throw new IllegalArgumentException("Null selection not allowed");
- }
-
- LocalSession session = WorldEdit.getInstance().getSession(wrapPlayer(player));
- RegionSelector sel = selection.getRegionSelector();
- session.setRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()), sel);
- session.dispatchCUISelection(wrapPlayer(player));
- }
-
/**
* Gets the instance of this plugin.
*
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java
index 04113a6d5..4a30a11c0 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java
@@ -19,13 +19,17 @@
package com.sk89q.worldedit.bukkit.adapter;
-import com.sk89q.worldedit.blocks.BaseBlock;
+import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity;
+import com.sk89q.worldedit.registry.state.Property;
+import com.sk89q.worldedit.world.block.BlockStateHolder;
+import com.sk89q.worldedit.world.block.BlockType;
import org.bukkit.Location;
-import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.entity.Entity;
+import java.util.Map;
+
import javax.annotation.Nullable;
/**
@@ -33,26 +37,6 @@ import javax.annotation.Nullable;
*/
public interface BukkitImplAdapter {
- /**
- * Get the block ID for the given material.
- *
- *
Returns 0 if it is not known or it doesn't exist.
- *
- * @param material the material
- * @return the block ID
- */
- int getBlockId(Material material);
-
- /**
- * Get the material for the given block ID.
- *
- *
Returns {@link Material#AIR} if it is not known or it doesn't exist.
- *
- * @param id the block ID
- * @return the material
- */
- Material getMaterial(int id);
-
/**
* Get the biome ID for the given biome.
*
@@ -89,7 +73,7 @@ public interface BukkitImplAdapter {
* @param notifyAndLight notify and light if set
* @return true if a block was likely changed
*/
- boolean setBlock(Location location, BaseBlock state, boolean notifyAndLight);
+ boolean setBlock(Location location, BlockStateHolder state, boolean notifyAndLight);
/**
* Get the state for the given entity.
@@ -110,5 +94,11 @@ public interface BukkitImplAdapter {
@Nullable
Entity createEntity(Location location, BaseEntity state);
-
+ /**
+ * Get a map of string -> properties
+ *
+ * @param blockType The block type
+ * @return The properties map
+ */
+ Map getProperties(BlockType blockType);
}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java
index 1bb953421..40a94baf1 100644
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java
+++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java
@@ -38,7 +38,7 @@ import java.util.logging.Logger;
public class BukkitImplLoader {
private static final Logger log = Logger.getLogger(BukkitImplLoader.class.getCanonicalName());
- private final List adapterCandidates = new ArrayList();
+ private final List adapterCandidates = new ArrayList<>();
private String customCandidate;
private static final String SEARCH_PACKAGE = "com.sk89q.worldedit.bukkit.adapter.impl";
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/entity/BukkitExpOrb.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/entity/BukkitExpOrb.java
deleted file mode 100644
index 1b57f8143..000000000
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/entity/BukkitExpOrb.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.bukkit.entity;
-
-import com.sk89q.worldedit.Location;
-import com.sk89q.worldedit.bukkit.BukkitUtil;
-import org.bukkit.entity.EntityType;
-import org.bukkit.entity.ExperienceOrb;
-
-import java.util.UUID;
-
-public class BukkitExpOrb extends BukkitEntity {
-
- private final int amount;
-
- public BukkitExpOrb(Location loc, UUID entityId, int amount) {
- super(loc, EntityType.EXPERIENCE_ORB, entityId);
- this.amount = amount;
- }
-
- @Override
- public boolean spawn(Location weLoc) {
- org.bukkit.Location loc = BukkitUtil.toLocation(weLoc);
- ExperienceOrb orb = loc.getWorld().spawn(loc, ExperienceOrb.class);
- if (orb != null) {
- orb.setExperience(amount);
- return true;
- }
- return false;
- }
-
-}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/entity/BukkitPainting.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/entity/BukkitPainting.java
deleted file mode 100644
index 57f7eb4f5..000000000
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/entity/BukkitPainting.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.bukkit.entity;
-
-import com.sk89q.worldedit.Location;
-import com.sk89q.worldedit.bukkit.BukkitUtil;
-import org.bukkit.Art;
-import org.bukkit.Bukkit;
-import org.bukkit.block.BlockFace;
-import org.bukkit.entity.EntityType;
-import org.bukkit.entity.Painting;
-
-import java.util.ArrayDeque;
-import java.util.Deque;
-import java.util.UUID;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-public class BukkitPainting extends BukkitEntity {
-
- private static final Logger log = Logger.getLogger(BukkitPainting.class.getCanonicalName());
-
- private static int spawnTask = -1;
- private static final Deque spawnQueue = new ArrayDeque();
-
- private class QueuedPaintingSpawn {
- private final Location weLoc;
-
- private QueuedPaintingSpawn(Location weLoc) {
- this.weLoc = weLoc;
- }
-
- public void spawn() {
- spawnRaw(weLoc);
- }
- }
-
- private static class PaintingSpawnRunnable implements Runnable {
- @Override
- public void run() {
- synchronized (spawnQueue) {
- QueuedPaintingSpawn spawn;
- while ((spawn = spawnQueue.poll()) != null) {
- try {
- spawn.spawn();
- } catch (Throwable t) {
- log.log(Level.WARNING, "Failed to spawn painting", t);
- continue;
- }
- }
- spawnTask = -1;
- }
- }
- }
-
- private final Art art;
- private final BlockFace facingDirection;
- public BukkitPainting(Location loc, Art art, BlockFace facingDirection, UUID entityId) {
- super(loc, EntityType.PAINTING, entityId);
- this.art = art;
- this.facingDirection = facingDirection;
- }
-
- /**
- * Queue the painting to be spawned at the specified location.
- * This operation is delayed so that the block changes that may be applied can be applied before the painting spawn is attempted.
- *
- * @param weLoc The WorldEdit location
- * @return Whether the spawn as successful
- */
- @Override
- public boolean spawn(Location weLoc) {
- synchronized (spawnQueue) {
- spawnQueue.add(new QueuedPaintingSpawn(weLoc));
- if (spawnTask == -1) {
- spawnTask = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"), new PaintingSpawnRunnable(), 1L);
- }
- }
- return true;
- }
-
- public boolean spawnRaw(Location weLoc) {
- org.bukkit.Location loc = BukkitUtil.toLocation(weLoc);
- Painting paint = loc.getWorld().spawn(loc, Painting.class);
- if (paint != null) {
- paint.setFacingDirection(facingDirection, true);
- paint.setArt(art, true);
- return true;
- }
- return false;
- }
-
-}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/selections/CuboidSelection.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/selections/CuboidSelection.java
deleted file mode 100644
index 5ecd74956..000000000
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/selections/CuboidSelection.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.bukkit.selections;
-
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.bukkit.BukkitUtil;
-import com.sk89q.worldedit.regions.CuboidRegion;
-import com.sk89q.worldedit.regions.RegionSelector;
-import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
-import com.sk89q.worldedit.regions.selector.limit.PermissiveSelectorLimits;
-import org.bukkit.Location;
-import org.bukkit.World;
-
-public class CuboidSelection extends RegionSelection {
-
- protected CuboidRegion cuboid;
-
- public CuboidSelection(World world, Location pt1, Location pt2) {
- this(world, BukkitUtil.toVector(pt1), BukkitUtil.toVector(pt2));
- }
-
- public CuboidSelection(World world, Vector pt1, Vector pt2) {
- super(world);
-
- // Validate input
- if (pt1 == null) {
- throw new IllegalArgumentException("Null point 1 not permitted");
- }
-
- if (pt2 == null) {
- throw new IllegalArgumentException("Null point 2 not permitted");
- }
-
- // Create new selector
- CuboidRegionSelector sel = new CuboidRegionSelector(BukkitUtil.getLocalWorld(world));
-
- // set up selector
- sel.selectPrimary(pt1, PermissiveSelectorLimits.getInstance());
- sel.selectSecondary(pt2, PermissiveSelectorLimits.getInstance());
-
- // set up CuboidSelection
- cuboid = sel.getIncompleteRegion();
-
- // set up RegionSelection
- setRegionSelector(sel);
- setRegion(cuboid);
- }
-
- public CuboidSelection(World world, RegionSelector sel, CuboidRegion region) {
- super(world, sel, region);
- this.cuboid = region;
- }
-}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/selections/CylinderSelection.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/selections/CylinderSelection.java
deleted file mode 100644
index c7dee7c79..000000000
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/selections/CylinderSelection.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.bukkit.selections;
-
-import com.sk89q.worldedit.regions.selector.CylinderRegionSelector;
-import org.bukkit.World;
-
-import com.sk89q.worldedit.BlockVector2D;
-import com.sk89q.worldedit.LocalWorld;
-import com.sk89q.worldedit.bukkit.BukkitUtil;
-import com.sk89q.worldedit.regions.CylinderRegion;
-import com.sk89q.worldedit.regions.RegionSelector;
-
-/**
- * A selection representing a {@link CylinderRegion}
- */
-public class CylinderSelection extends RegionSelection {
-
- private CylinderRegion cylRegion;
-
- public CylinderSelection(World world, RegionSelector selector, CylinderRegion region) {
- super(world, selector, region);
- this.cylRegion = region;
- }
-
- public CylinderSelection(World world, BlockVector2D center, BlockVector2D radius, int minY, int maxY) {
- super(world);
- LocalWorld lWorld = BukkitUtil.getLocalWorld(world);
-
- // Validate input
- minY = Math.min(Math.max(0, minY), world.getMaxHeight());
- maxY = Math.min(Math.max(0, maxY), world.getMaxHeight());
-
- // Create and set up new selector
- CylinderRegionSelector sel = new CylinderRegionSelector(lWorld, center, radius, minY, maxY);
-
- // set up selection
- cylRegion = sel.getIncompleteRegion();
-
- // set up RegionSelection
- setRegionSelector(sel);
- setRegion(cylRegion);
- }
-
- /**
- * Returns the center vector of the cylinder
- *
- * @return the center
- */
- public BlockVector2D getCenter() {
- return cylRegion.getCenter().toVector2D().toBlockVector2D();
- }
-
- /**
- * Returns the radius vector of the cylinder
- *
- * @return the radius
- */
- public BlockVector2D getRadius() {
- return cylRegion.getRadius().toBlockVector2D();
- }
-
-}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/selections/Polygonal2DSelection.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/selections/Polygonal2DSelection.java
deleted file mode 100644
index 387bcf6de..000000000
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/selections/Polygonal2DSelection.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.bukkit.selections;
-
-import java.util.Collections;
-import java.util.List;
-
-import com.sk89q.worldedit.LocalWorld;
-import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector;
-import org.bukkit.World;
-import com.sk89q.worldedit.BlockVector2D;
-import com.sk89q.worldedit.bukkit.BukkitUtil;
-import com.sk89q.worldedit.regions.*;
-
-public class Polygonal2DSelection extends RegionSelection {
-
- protected Polygonal2DRegion poly2d;
-
- public Polygonal2DSelection(World world, RegionSelector sel, Polygonal2DRegion region) {
- super(world, sel, region);
- this.poly2d = region;
- }
-
- public Polygonal2DSelection(World world, List points, int minY, int maxY) {
- super(world);
- LocalWorld lWorld = BukkitUtil.getLocalWorld(world);
-
- // Validate input
- minY = Math.min(Math.max(0, minY), world.getMaxHeight());
- maxY = Math.min(Math.max(0, maxY), world.getMaxHeight());
-
- // Create and set up new selector
- Polygonal2DRegionSelector sel = new Polygonal2DRegionSelector(lWorld, points, minY, maxY);
-
- // set up CuboidSelection
- poly2d = sel.getIncompleteRegion();
-
- // set up RegionSelection
- setRegionSelector(sel);
- setRegion(poly2d);
- }
-
- public List getNativePoints() {
- return Collections.unmodifiableList(poly2d.getPoints());
- }
-}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/selections/RegionSelection.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/selections/RegionSelection.java
deleted file mode 100644
index db705a8be..000000000
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/selections/RegionSelection.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.bukkit.selections;
-
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.regions.Region;
-import com.sk89q.worldedit.regions.RegionSelector;
-import org.bukkit.Location;
-import org.bukkit.World;
-
-import static com.sk89q.worldedit.bukkit.BukkitUtil.toLocation;
-import static com.sk89q.worldedit.bukkit.BukkitUtil.toVector;
-
-public abstract class RegionSelection implements Selection {
-
- private World world;
- private RegionSelector selector;
- private Region region;
-
- public RegionSelection(World world) {
- this.world = world;
- }
-
- public RegionSelection(World world, RegionSelector selector, Region region) {
- this.world = world;
- this.region = region;
- this.selector = selector;
- }
-
- protected Region getRegion() {
- return region;
- }
-
- protected void setRegion(Region region) {
- this.region = region;
- }
-
- @Override
- public RegionSelector getRegionSelector() {
- return selector;
- }
-
- protected void setRegionSelector(RegionSelector selector) {
- this.selector = selector;
- }
-
- @Override
- public Location getMinimumPoint() {
- return toLocation(world, region.getMinimumPoint());
- }
-
- @Override
- public Vector getNativeMinimumPoint() {
- return region.getMinimumPoint();
- }
-
- @Override
- public Location getMaximumPoint() {
- return toLocation(world, region.getMaximumPoint());
- }
-
- @Override
- public Vector getNativeMaximumPoint() {
- return region.getMaximumPoint();
- }
-
- @Override
- public World getWorld() {
- return world;
- }
-
- @Override
- public int getArea() {
- return region.getArea();
- }
-
- @Override
- public int getWidth() {
- return region.getWidth();
- }
-
- @Override
- public int getHeight() {
- return region.getHeight();
- }
-
- @Override
- public int getLength() {
- return region.getLength();
- }
-
- @Override
- public boolean contains(Location position) {
- if (!position.getWorld().equals(world)) {
- return false;
- }
-
- return region.contains(toVector(position));
- }
-
-}
diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/selections/Selection.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/selections/Selection.java
deleted file mode 100644
index c3788affc..000000000
--- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/selections/Selection.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.bukkit.selections;
-
-import org.bukkit.Location;
-import org.bukkit.World;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.regions.RegionSelector;
-
-import javax.annotation.Nullable;
-
-/**
- * An abstraction of WorldEdit regions, which do not use Bukkit objects.
- */
-public interface Selection {
-
- /**
- * Get the lower point of a region.
- *
- * @return min. point
- */
- public Location getMinimumPoint();
-
- /**
- * Get the lower point of a region.
- *
- * @return min. point
- */
- public Vector getNativeMinimumPoint();
-
- /**
- * Get the upper point of a region.
- *
- * @return max. point
- */
- public Location getMaximumPoint();
-
- /**
- * Get the upper point of a region.
- *
- * @return max. point
- */
- public Vector getNativeMaximumPoint();
-
- /**
- * Get the region selector. This is for internal use.
- *
- * @return the region selector
- */
- public RegionSelector getRegionSelector();
-
- /**
- * Get the world.
- *
- * @return the world, which may be null
- */
- @Nullable
- public World getWorld();
-
- /**
- * Get the number of blocks in the region.
- *
- * @return number of blocks
- */
- public int getArea();
-
- /**
- * Get X-size.
- *
- * @return width
- */
- public int getWidth();
-
- /**
- * Get Y-size.
- *
- * @return height
- */
- public int getHeight();
-
- /**
- * Get Z-size.
- *
- * @return length
- */
- public int getLength();
-
- /**
- * Returns true based on whether the region contains the point,
- *
- * @param position a vector
- * @return true if it is contained
- */
- public boolean contains(Location position);
-
-}
diff --git a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/CraftBukkit_v1_6_R3.class b/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/CraftBukkit_v1_6_R3.class
deleted file mode 100644
index 4f3c4dab7..000000000
Binary files a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/CraftBukkit_v1_6_R3.class and /dev/null differ
diff --git a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/CraftBukkit_v1_7_R2.class b/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/CraftBukkit_v1_7_R2.class
deleted file mode 100644
index c61abe627..000000000
Binary files a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/CraftBukkit_v1_7_R2.class and /dev/null differ
diff --git a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/CraftBukkit_v1_7_R3.class b/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/CraftBukkit_v1_7_R3.class
deleted file mode 100644
index c08893d3b..000000000
Binary files a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/CraftBukkit_v1_7_R3.class and /dev/null differ
diff --git a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/CraftBukkit_v1_7_R4.class b/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/CraftBukkit_v1_7_R4.class
deleted file mode 100644
index cecbd02ca..000000000
Binary files a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/CraftBukkit_v1_7_R4.class and /dev/null differ
diff --git a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_10_R1.class b/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_10_R1.class
deleted file mode 100644
index fad3f0bd1..000000000
Binary files a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_10_R1.class and /dev/null differ
diff --git a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_11_R1.class b/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_11_R1.class
deleted file mode 100644
index c8b7a3fc6..000000000
Binary files a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_11_R1.class and /dev/null differ
diff --git a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_13_R1.class b/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_13_R1.class
new file mode 100644
index 000000000..9655a35a6
Binary files /dev/null and b/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_13_R1.class differ
diff --git a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_8_R1.class b/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_8_R1.class
deleted file mode 100644
index 22d0efe35..000000000
Binary files a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_8_R1.class and /dev/null differ
diff --git a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_8_R2.class b/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_8_R2.class
deleted file mode 100644
index 4364089e0..000000000
Binary files a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_8_R2.class and /dev/null differ
diff --git a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_8_R3.class b/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_8_R3.class
deleted file mode 100644
index ad8fa4d66..000000000
Binary files a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_8_R3.class and /dev/null differ
diff --git a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_9_R1.class b/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_9_R1.class
deleted file mode 100644
index 77edca329..000000000
Binary files a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_9_R1.class and /dev/null differ
diff --git a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_9_R2.class b/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_9_R2.class
deleted file mode 100644
index 198451706..000000000
Binary files a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_9_R2.class and /dev/null differ
diff --git a/worldedit-bukkit/src/main/resources/defaults/config.yml b/worldedit-bukkit/src/main/resources/defaults/config.yml
index 2ad742afb..fd931081f 100644
--- a/worldedit-bukkit/src/main/resources/defaults/config.yml
+++ b/worldedit-bukkit/src/main/resources/defaults/config.yml
@@ -1,18 +1,19 @@
#
-# WorldEdit's configuration file
+# WorldEdit's Configuration File
#
# About editing this file:
-# - DO NOT USE TABS. You MUST use spaces or Bukkit will complain. If
-# you use an editor like Notepad++ (recommended for Windows users), you
-# must configure it to "replace tabs with spaces." In Notepad++, this can
-# be changed in Settings > Preferences > Language Menu.
-# - Don't get rid of the indents. They are indented so some entries are
-# in categories (like "max-blocks-changed" is in the "limits"
+# - DO NOT USE TABS. You MUST use spaces or Bukkit will complain and post
+# errors. If you use an editor, like Notepad++ (recommended for Windows
+# users), you must configure it to "replace tabs with spaces."
+# This can be changed in Settings > Preferences > Language Menu.
+# - Don't get rid of indentations. They are indented so some entries that are
+# in categories, like "max-blocks-changed", are placed in the "limits"
# category.
# - If you want to check the format of this file before putting it
# into WorldEdit, paste it into http://yaml-online-parser.appspot.com/
-# and see if it gives "ERROR:".
-# - Lines starting with # are commentsand so they are ignored.
+# and see if it gives you "ERROR:".
+# - Lines starting with # are comments, so they are ignored.
+# - If you want to allow blocks, make sure to change "disallowed-blocks" to []
#
limits:
@@ -29,7 +30,67 @@ limits:
butcher-radius:
default: -1
maximum: -1
- disallowed-blocks: [6, 7, 14, 15, 16, 26, 27, 28, 29, 39, 31, 32, 33, 34, 36, 37, 38, 39, 40, 46, 50, 51, 56, 59, 69, 73, 74, 75, 76, 77, 81, 83]
+ disallowed-blocks:
+ - "minecraft:oak_sapling"
+ - "minecraft:jungle_sapling"
+ - "minecraft:dark_oak_sapling:"
+ - "minecraft:spruce_sapling"
+ - "minecraft:birch_sapling"
+ - "minecraft:acacia_sapling"
+ - "minecraft:black_bed"
+ - "minecraft:blue_bed"
+ - "minecraft:brown_bed"
+ - "minecraft:cyan_bed"
+ - "minecraft:gray_bed"
+ - "minecraft:green_bed"
+ - "minecraft:light_blue_bed"
+ - "minecraft:light_gray_bed"
+ - "minecraft:lime_bed"
+ - "minecraft:magenta_bed"
+ - "minecraft:orange_bed"
+ - "minecraft:pink_bed"
+ - "minecraft:purple_bed"
+ - "minecraft:red_bed"
+ - "minecraft:white_bed"
+ - "minecraft:yellow_bed"
+ - "minecraft:powered_rail"
+ - "minecraft:detector_rail"
+ - "minecraft:grass"
+ - "minecraft:dead_bush"
+ - "minecraft:moving_piston"
+ - "minecraft:piston_head"
+ - "minecraft:sunflower"
+ - "minecraft:rose_bush"
+ - "minecraft:dandelion"
+ - "minecraft:poppy"
+ - "minecraft:brown_mushroom"
+ - "minecraft:red_mushroom"
+ - "minecraft:tnt"
+ - "minecraft:torch"
+ - "minecraft:fire"
+ - "minecraft:redstone_wire"
+ - "minecraft:wheat"
+ - "minecraft:potatoes"
+ - "minecraft:carrots"
+ - "minecraft:melon_stem"
+ - "minecraft:pumpkin_stem"
+ - "minecraft:beetroots"
+ - "minecraft:rail"
+ - "minecraft:lever"
+ - "minecraft:redstone_torch"
+ - "minecraft:redstone_wall_torch"
+ - "minecraft:repeater"
+ - "minecraft:comparator"
+ - "minecraft:stone_button"
+ - "minecraft:birch_button"
+ - "minecraft:acacia_button"
+ - "minecraft:dark_oak_button"
+ - "minecraft:jungle_button"
+ - "minecraft:oak_button"
+ - "minecraft:spruce_button"
+ - "minecraft:cactus"
+ - "minecraft:sugar_cane"
+ - "minecraft:bedrock"
use-inventory:
enable: false
@@ -39,6 +100,17 @@ use-inventory:
logging:
log-commands: false
file: worldedit.log
+ # The format of custom log message. This is java general format string (java.util.Formatter). Arguments are:
+ # 1$ : date - a Date object representing event time of the log record.
+ # 2$ : source - a string representing the caller, if available; otherwise, the logger's name.
+ # 3$ : logger - the logger's name.
+ # 4$ : level - the log level.
+ # 5$ : message - the formatted log message returned from the Formatter.formatMessage(LogRecord) method. It uses java.text formatting and does not use the java.util.Formatter format argument.
+ # 6$ : thrown - a string representing the throwable associated with the log record and its backtrace beginning with a newline character, if any; otherwise, an empty string.
+ # For details see:
+ # https://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html
+ # https://docs.oracle.com/javase/8/docs/api/java/util/logging/SimpleFormatter.html#format-java.util.logging.LogRecord-
+ format: "[%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s]: %5$s%6$s%n"
super-pickaxe:
drop-items: true
@@ -48,7 +120,7 @@ snapshots:
directory:
navigation-wand:
- item: 345
+ item: minecraft:compass
max-distance: 100
scripting:
@@ -65,7 +137,7 @@ history:
size: 15
expiration: 10
-wand-item: 271
+wand-item: minecraft:wooden_axe
shell-save-type:
no-double-slash: false
no-op-permissions: false
diff --git a/worldedit-bukkit/src/main/resources/plugin.yml b/worldedit-bukkit/src/main/resources/plugin.yml
index d071c6f04..9afc2c5a5 100644
--- a/worldedit-bukkit/src/main/resources/plugin.yml
+++ b/worldedit-bukkit/src/main/resources/plugin.yml
@@ -2,6 +2,7 @@ name: WorldEdit
main: com.sk89q.worldedit.bukkit.WorldEditPlugin
version: "${internalVersion}"
softdepend: [Spout] #hack to fix trove errors
+api-version: 1.13
# Permissions aren't here. Read http://wiki.sk89q.com/wiki/WEPIF/DinnerPerms
# for how WorldEdit permissions actually work.
diff --git a/worldedit-bukkit/src/test/java/com/sk89q/wepif/DinnerPermsResolverTest.java b/worldedit-bukkit/src/test/java/com/sk89q/wepif/DinnerPermsResolverTest.java
index 8e80a57bc..e207e7b8d 100644
--- a/worldedit-bukkit/src/test/java/com/sk89q/wepif/DinnerPermsResolverTest.java
+++ b/worldedit-bukkit/src/test/java/com/sk89q/wepif/DinnerPermsResolverTest.java
@@ -19,13 +19,15 @@
package com.sk89q.wepif;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import org.bukkit.Server;
import org.bukkit.plugin.PluginManager;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.*;
-
-import static org.mockito.Mockito.*;
public class DinnerPermsResolverTest {
private DinnerPermsResolver resolver;
diff --git a/worldedit-bukkit/src/test/java/com/sk89q/wepif/TestOfflinePermissible.java b/worldedit-bukkit/src/test/java/com/sk89q/wepif/TestOfflinePermissible.java
index 81e41e9d7..21c83228f 100644
--- a/worldedit-bukkit/src/test/java/com/sk89q/wepif/TestOfflinePermissible.java
+++ b/worldedit-bukkit/src/test/java/com/sk89q/wepif/TestOfflinePermissible.java
@@ -28,13 +28,17 @@ import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
-import java.util.*;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
public class TestOfflinePermissible implements OfflinePlayer, Permissible {
private boolean op;
private UUID randomUuid = UUID.randomUUID();
- private final Map assignedPermissions = new HashMap();
+ private final Map assignedPermissions = new HashMap<>();
@Override
public boolean isOp() {
@@ -101,7 +105,7 @@ public class TestOfflinePermissible implements OfflinePlayer, Permissible {
@Override
public Set getEffectivePermissions() {
- Set ret = new HashSet();
+ Set ret = new HashSet<>();
for (Map.Entry entry : assignedPermissions.entrySet()) {
ret.add(new PermissionAttachmentInfo(this, entry.getKey(), null, entry.getValue()));
}
@@ -141,11 +145,6 @@ public class TestOfflinePermissible implements OfflinePlayer, Permissible {
throw new UnsupportedOperationException("Not supported yet.");
}
- @Override
- public void setBanned(boolean b) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
@Override
public boolean isWhitelisted() {
throw new UnsupportedOperationException("Not supported yet.");
diff --git a/worldedit-bukkit/src/test/java/com/sk89q/worldedit/bukkit/BukkitWorldTest.java b/worldedit-bukkit/src/test/java/com/sk89q/worldedit/bukkit/BukkitWorldTest.java
index cf627e393..e6776cf8c 100644
--- a/worldedit-bukkit/src/test/java/com/sk89q/worldedit/bukkit/BukkitWorldTest.java
+++ b/worldedit-bukkit/src/test/java/com/sk89q/worldedit/bukkit/BukkitWorldTest.java
@@ -28,7 +28,7 @@ public class BukkitWorldTest {
@Test
public void testTreeTypeMapping() {
for (TreeGenerator.TreeType type : TreeGenerator.TreeType.values()) {
- Assert.assertFalse("No mapping for: " + type, BukkitWorld.toBukkitTreeType(type) == null);
+ Assert.assertNotNull("No mapping for: " + type, BukkitWorld.toBukkitTreeType(type));
}
}
diff --git a/worldedit-core/build.gradle b/worldedit-core/build.gradle
index 079e3c124..57a5eb2ca 100644
--- a/worldedit-core/build.gradle
+++ b/worldedit-core/build.gradle
@@ -5,11 +5,11 @@ dependencies {
compile 'de.schlichtherle:truezip:6.8.3'
compile 'rhino:js:1.7R2'
compile 'org.yaml:snakeyaml:1.9'
- compile 'com.google.guava:guava:17.0'
+ compile 'com.google.guava:guava:21.0'
compile 'com.sk89q:jchronic:0.2.4a'
compile 'com.google.code.findbugs:jsr305:1.3.9'
compile 'com.thoughtworks.paranamer:paranamer:2.6'
- compile 'com.google.code.gson:gson:2.2.4'
+ compile 'com.google.code.gson:gson:2.8.0'
compile 'com.sk89q.lib:jlibnoise:1.0.0'
//compile 'net.sf.trove4j:trove4j:3.0.3'
testCompile 'org.mockito:mockito-core:1.9.0-rc1'
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/bags/BlockBag.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/bags/BlockBag.java
deleted file mode 100644
index c8842ccb2..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/bags/BlockBag.java
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.bags;
-
-import com.sk89q.worldedit.WorldVector;
-import com.sk89q.worldedit.blocks.*;
-
-/**
- * @deprecated Block bags are currently not a supported feature of WorldEdit
- */
-@SuppressWarnings("deprecation")
-@Deprecated
-
-public abstract class BlockBag {
-
- /**
- * Stores a block as if it was mined.
- *
- * @param id the ID of the block
- * @throws BlockBagException thrown on a error
- * @deprecated Use {@link BlockBag#storeDroppedBlock(int, int)} instead
- */
- @Deprecated
- public void storeDroppedBlock(int id) throws BlockBagException {
- storeDroppedBlock(id, 0);
- }
-
- /**
- * Stores a block as if it was mined.
- *
- * @param id the ID of the block
- * @param data the data value of the block
- * @throws BlockBagException thrown on a error
- */
- public void storeDroppedBlock(int id, int data) throws BlockBagException {
- BaseItem dropped = BlockType.getBlockBagItem(id, data);
- if (dropped == null) return;
- if (dropped.getType() == BlockID.AIR) return;
-
- storeItem(dropped);
- }
-
- /**
- * Sets a block as if it was placed by hand.
- *
- * @param id the ID of the block
- * @throws BlockBagException
- * @deprecated Use {@link #fetchPlacedBlock(int,int)} instead
- */
- @Deprecated
- public void fetchPlacedBlock(int id) throws BlockBagException {
- fetchPlacedBlock(id, 0);
- }
-
- /**
- * Sets a block as if it was placed by hand.
- *
- * @param id the ID of the block
- * @param data the data value of the block
- * @throws BlockBagException
- */
- public void fetchPlacedBlock(int id, int data) throws BlockBagException {
- try {
- // Blocks that can't be fetched...
- switch (id) {
- case BlockID.BEDROCK:
- case BlockID.GOLD_ORE:
- case BlockID.IRON_ORE:
- case BlockID.COAL_ORE:
- case BlockID.DIAMOND_ORE:
- case BlockID.TNT:
- case BlockID.MOB_SPAWNER:
- case BlockID.CROPS:
- case BlockID.REDSTONE_ORE:
- case BlockID.GLOWING_REDSTONE_ORE:
- case BlockID.SNOW:
- case BlockID.LIGHTSTONE:
- case BlockID.PORTAL:
- throw new UnplaceableBlockException();
-
- case BlockID.WATER:
- case BlockID.STATIONARY_WATER:
- case BlockID.LAVA:
- case BlockID.STATIONARY_LAVA:
- // Override liquids
- return;
-
- default:
- fetchBlock(id);
- break;
- }
-
- } catch (OutOfBlocksException e) {
- BaseItem placed = BlockType.getBlockBagItem(id, data);
- if (placed == null) throw e; // TODO: check
- if (placed.getType() == BlockID.AIR) throw e; // TODO: check
-
- fetchItem(placed);
- }
- }
-
- /**
- * Get a block.
- *
- * Either this method or fetchItem needs to be overridden
- *
- * @param id the ID of the block
- * @throws BlockBagException
- */
- public void fetchBlock(int id) throws BlockBagException {
- fetchItem(new BaseItem(id));
- }
-
- /**
- * Get a block.
- *
- * Either this method or fetchBlock needs to be overridden
- *
- * @param item the item
- * @throws BlockBagException
- */
- public void fetchItem(BaseItem item) throws BlockBagException {
- fetchBlock(item.getType());
- }
-
- /**
- * Store a block.
- *
- * Either this method or storeItem needs to be overridden
- *
- * @param id the ID of the block
- * @throws BlockBagException
- */
- public void storeBlock(int id) throws BlockBagException {
- storeItem(new BaseItem(id));
- }
-
- /**
- * Store a block.
- *
- * Either this method or storeBlock needs to be overridden
- *
- * @param item the item
- * @throws BlockBagException
- */
- public void storeItem(BaseItem item) throws BlockBagException {
- storeBlock(item.getType());
- }
-
- /**
- * Checks to see if a block exists without removing it.
- *
- * @param id the ID of the block
- * @return whether the block exists
- */
- public boolean peekBlock(int id) {
- try {
- fetchBlock(id);
- storeBlock(id);
- return true;
- } catch (BlockBagException e) {
- return false;
- }
- }
-
- /**
- * Flush any changes. This is called at the end.
- */
- public abstract void flushChanges();
-
- /**
- * Adds a position to be used a source.
- *
- * @param position the position of the source
- */
- public abstract void addSourcePosition(WorldVector position);
-
- /**
- * Adds a position to be used a source.
- *
- * @param position the position of the source
- */
- public abstract void addSingleSourcePosition(WorldVector position);
-
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/ChestBlock.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/ChestBlock.java
deleted file mode 100644
index 9c62e7f6d..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/ChestBlock.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.blocks;
-
-import com.sk89q.jnbt.CompoundTag;
-import com.sk89q.jnbt.ListTag;
-import com.sk89q.jnbt.NBTUtils;
-import com.sk89q.jnbt.StringTag;
-import com.sk89q.jnbt.Tag;
-import com.sk89q.worldedit.world.DataException;
-import com.sk89q.worldedit.world.storage.InvalidFormatException;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Represents a chest block.
- */
-public class ChestBlock extends ContainerBlock {
-
- /**
- * Construct an empty chest block with the default orientation (data value).
- */
- public ChestBlock() {
- super(BlockID.CHEST, 27);
- }
-
- /**
- * Construct an empty chest block with a custom data value.
- *
- * @param data data indicating the position of the chest
- */
- public ChestBlock(int data) {
- super(BlockID.CHEST, data, 27);
- }
-
- /**
- * Construct the chest block with a custom data value and a list of items.
- *
- * @param data data indicating the position of the chest
- * @param items array of items
- */
- public ChestBlock(int data, BaseItemStack[] items) {
- super(BlockID.CHEST, data, 27);
- setItems(items);
- }
-
- @Override
- public String getNbtId() {
- return "Chest";
- }
-
- @Override
- public CompoundTag getNbtData() {
- Map values = new HashMap();
- values.put("Items", new ListTag(CompoundTag.class, serializeInventory(getItems())));
- return new CompoundTag(values);
- }
-
- @Override
- public void setNbtData(CompoundTag rootTag) {
- if (rootTag == null) {
- return;
- }
-
- Map values = rootTag.getValue();
-
- Tag t = values.get("id");
- if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals("Chest")) {
- throw new RuntimeException("'Chest' tile entity expected");
- }
-
- List items = new ArrayList();
-
- try {
- for (Tag tag : NBTUtils.getChildTag(values, "Items", ListTag.class).getValue()) {
- if (!(tag instanceof CompoundTag)) {
- throw new RuntimeException("CompoundTag expected as child tag of Chest's Items");
- }
-
- items.add((CompoundTag) tag);
- }
-
- setItems(deserializeInventory(items));
- } catch (InvalidFormatException e) {
- throw new RuntimeException(e);
- } catch (DataException e) {
- throw new RuntimeException(e);
- }
- }
-
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/ContainerBlock.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/ContainerBlock.java
deleted file mode 100644
index 05709cd0b..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/ContainerBlock.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.blocks;
-
-import com.sk89q.jnbt.ByteTag;
-import com.sk89q.jnbt.CompoundTag;
-import com.sk89q.jnbt.ListTag;
-import com.sk89q.jnbt.NBTUtils;
-import com.sk89q.jnbt.ShortTag;
-import com.sk89q.jnbt.Tag;
-import com.sk89q.worldedit.world.DataException;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Represents a block that stores items.
- */
-public abstract class ContainerBlock extends BaseBlock implements TileEntityBlock {
-
- private BaseItemStack[] items;
-
- public ContainerBlock(int type, int inventorySize) {
- super(type);
- this.items = new BaseItemStack[inventorySize];
- }
-
- public ContainerBlock(int type, int data, int inventorySize) {
- super(type, data);
- this.items = new BaseItemStack[inventorySize];
- }
-
- /**
- * Get the list of items.
- *
- * @return an array of stored items
- */
- public BaseItemStack[] getItems() {
- return this.items;
- }
-
- /**
- * Set the list of items.
- *
- * @param items an array of stored items
- */
- public void setItems(BaseItemStack[] items) {
- this.items = items;
- }
-
- @Override
- public boolean hasNbtData() {
- return true;
- }
-
- public Map serializeItem(BaseItemStack item) {
- Map data = new HashMap();
- data.put("id", new ShortTag((short) item.getType()));
- data.put("Damage", new ShortTag(item.getData()));
- data.put("Count", new ByteTag((byte) item.getAmount()));
- if (!item.getEnchantments().isEmpty()) {
- List enchantmentList = new ArrayList();
- for(Map.Entry entry : item.getEnchantments().entrySet()) {
- Map enchantment = new HashMap();
- enchantment.put("id", new ShortTag(entry.getKey().shortValue()));
- enchantment.put("lvl", new ShortTag(entry.getValue().shortValue()));
- enchantmentList.add(new CompoundTag(enchantment));
- }
-
- Map auxData = new HashMap();
- auxData.put("ench", new ListTag(CompoundTag.class, enchantmentList));
- data.put("tag", new CompoundTag(auxData));
- }
- return data;
- }
-
- public BaseItemStack deserializeItem(Map data) throws DataException {
- short id = NBTUtils.getChildTag(data, "id", ShortTag.class).getValue();
- short damage = NBTUtils.getChildTag(data, "Damage", ShortTag.class).getValue();
- byte count = NBTUtils.getChildTag(data, "Count", ByteTag.class).getValue();
-
- BaseItemStack stack = new BaseItemStack(id, count, damage);
-
- if (data.containsKey("tag")) {
- Map auxData = NBTUtils.getChildTag(data, "tag", CompoundTag.class).getValue();
- ListTag ench = (ListTag)auxData.get("ench");
- for(Tag e : ench.getValue()) {
- Map vars = ((CompoundTag) e).getValue();
- short enchId = NBTUtils.getChildTag(vars, "id", ShortTag.class).getValue();
- short enchLevel = NBTUtils.getChildTag(vars, "lvl", ShortTag.class).getValue();
- stack.getEnchantments().put((int) enchId, (int) enchLevel);
- }
- }
- return stack;
- }
-
- public BaseItemStack[] deserializeInventory(List items) throws DataException {
- BaseItemStack[] stacks = new BaseItemStack[items.size()];
- for (CompoundTag tag : items) {
- Map item = tag.getValue();
- BaseItemStack stack = deserializeItem(item);
- byte slot = NBTUtils.getChildTag(item, "Slot", ByteTag.class).getValue();
- if (slot >= 0 && slot < stacks.length) {
- stacks[slot] = stack;
- }
- }
- return stacks;
- }
-
- public List serializeInventory(BaseItemStack[] items) {
- List tags = new ArrayList();
- for (int i = 0; i < items.length; ++i) {
- if (items[i] != null) {
- Map tagData = serializeItem(items[i]);
- tagData.put("Slot", new ByteTag((byte) i));
- tags.add(new CompoundTag(tagData));
- }
- }
- return tags;
- }
-
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/DispenserBlock.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/DispenserBlock.java
deleted file mode 100644
index 4140ee88a..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/DispenserBlock.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.blocks;
-
-import com.sk89q.jnbt.CompoundTag;
-import com.sk89q.jnbt.ListTag;
-import com.sk89q.jnbt.NBTUtils;
-import com.sk89q.jnbt.StringTag;
-import com.sk89q.jnbt.Tag;
-import com.sk89q.worldedit.world.DataException;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Represents dispensers.
- */
-public class DispenserBlock extends ContainerBlock {
-
- /**
- * Construct an empty dispenser block.
- */
- public DispenserBlock() {
- super(BlockID.DISPENSER, 9);
- }
-
- /**
- * Construct an empty dispenser block.
- *
- * @param data data value (orientation)
- */
- public DispenserBlock(int data) {
- super(BlockID.DISPENSER, data, 9);
- }
-
- /**
- * Construct a dispenser block with the given orientation and inventory.
- *
- * @param data data value (orientation)
- * @param items array of items in the inventory
- */
- public DispenserBlock(int data, BaseItemStack[] items) {
- super(BlockID.DISPENSER, data, 9);
- this.setItems(items);
- }
-
- @Override
- public String getNbtId() {
- return "Trap";
- }
-
- @Override
- public CompoundTag getNbtData() {
- Map values = new HashMap();
- values.put("Items", new ListTag(CompoundTag.class, serializeInventory(getItems())));
- return new CompoundTag(values);
- }
-
- @Override
- public void setNbtData(CompoundTag rootTag) {
- try {
- if (rootTag == null) {
- return;
- }
-
- Map values = rootTag.getValue();
-
- Tag t = values.get("id");
- if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals("Trap")) {
- throw new DataException("'Trap' tile entity expected");
- }
-
- List items = new ArrayList();
- for (Tag tag : NBTUtils.getChildTag(values, "Items", ListTag.class).getValue()) {
- if (!(tag instanceof CompoundTag)) {
- throw new DataException("CompoundTag expected as child tag of Trap Items");
- }
-
- items.add((CompoundTag) tag);
- }
-
- setItems(deserializeInventory(items));
- } catch (DataException e) {
- throw new RuntimeException(e);
- }
- }
-
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/FurnaceBlock.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/FurnaceBlock.java
deleted file mode 100644
index f2001d754..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/FurnaceBlock.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.blocks;
-
-import com.sk89q.jnbt.CompoundTag;
-import com.sk89q.jnbt.ListTag;
-import com.sk89q.jnbt.NBTUtils;
-import com.sk89q.jnbt.ShortTag;
-import com.sk89q.jnbt.StringTag;
-import com.sk89q.jnbt.Tag;
-import com.sk89q.worldedit.world.DataException;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Represents a furnace block.
- */
-public class FurnaceBlock extends ContainerBlock {
-
- private short burnTime;
- private short cookTime;
-
- /**
- * Construct an empty furnace block with the default orientation.
- *
- * @param type type ID
- */
- public FurnaceBlock(int type) {
- super(type, 2);
- }
-
- /**
- * Construct an empty furnace block with a given orientation.
- *
- * @param type type ID
- * @param data orientation
- */
- public FurnaceBlock(int type, int data) {
- super(type, data, 2);
- }
-
- /**
- * Construct an furnace block with a given orientation and inventory.
- *
- * @param type type ID
- * @param data orientation
- * @param items inventory items
- */
- public FurnaceBlock(int type, int data, BaseItemStack[] items) {
- super(type, data, 2);
- setItems(items);
- }
-
- /**
- * Get the burn time.
- *
- * @return the burn time
- */
- public short getBurnTime() {
- return burnTime;
- }
-
- /**
- * Set the burn time.
- *
- * @param burnTime the burn time
- */
- public void setBurnTime(short burnTime) {
- this.burnTime = burnTime;
- }
-
- /**
- * Get the cook time.
- *
- * @return the cook time
- */
- public short getCookTime() {
- return cookTime;
- }
-
- /**
- * Set the cook time.
- *
- * @param cookTime the cook time to set
- */
- public void setCookTime(short cookTime) {
- this.cookTime = cookTime;
- }
-
- @Override
- public String getNbtId() {
- return "Furnace";
- }
-
- @Override
- public CompoundTag getNbtData() {
- Map values = new HashMap();
- values.put("Items", new ListTag(CompoundTag.class, serializeInventory(getItems())));
- values.put("BurnTime", new ShortTag(burnTime));
- values.put("CookTime", new ShortTag(cookTime));
- return new CompoundTag(values);
- }
-
- @Override
- public void setNbtData(CompoundTag rootTag) {
- if (rootTag == null) {
- return;
- }
-
- try {
- Map values = rootTag.getValue();
-
- Tag t = values.get("id");
- if (!(t instanceof StringTag)
- || !((StringTag) t).getValue().equals("Furnace")) {
- throw new RuntimeException("'Furnace' tile entity expected");
- }
-
- ListTag items = NBTUtils.getChildTag(values, "Items", ListTag.class);
-
- List compound = new ArrayList();
-
- for (Tag tag : items.getValue()) {
- if (!(tag instanceof CompoundTag)) {
- throw new RuntimeException("CompoundTag expected as child tag of Furnace Items");
- }
- compound.add((CompoundTag) tag);
- }
- setItems(deserializeInventory(compound));
-
- t = values.get("BurnTime");
- if (t instanceof ShortTag) {
- burnTime = ((ShortTag) t).getValue();
- }
-
- t = values.get("CookTime");
- if (t instanceof ShortTag) {
- cookTime = ((ShortTag) t).getValue();
- }
- } catch (DataException e) {
- throw new RuntimeException(e);
- }
- }
-
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/LazyBlock.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/LazyBlock.java
deleted file mode 100644
index cb34a71d3..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/LazyBlock.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.blocks;
-
-import com.sk89q.jnbt.CompoundTag;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.extent.Extent;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * A implementation of a lazy block for {@link Extent#getLazyBlock(Vector)}
- * that takes the block's ID and metadata, but will defer loading of NBT
- * data until time of access.
- *
- *
NBT data is later loaded using a call to {@link Extent#getBlock(Vector)}
- * with a stored {@link Extent} and location.
- *
- *
All mutators on this object will throw an
- * {@link UnsupportedOperationException}.
- */
-public class LazyBlock extends BaseBlock {
-
- private final Extent extent;
- private final Vector position;
- private boolean loaded = false;
-
- /**
- * Create a new lazy block.
- *
- * @param type the block type
- * @param extent the extent to later load the full block data from
- * @param position the position to later load the full block data from
- */
- public LazyBlock(int type, Extent extent, Vector position) {
- super(type);
- checkNotNull(extent);
- checkNotNull(position);
- this.extent = extent;
- this.position = position;
- }
-
- /**
- * Create a new lazy block.
- *
- * @param type the block type
- * @param data the data value
- * @param extent the extent to later load the full block data from
- * @param position the position to later load the full block data from
- */
- public LazyBlock(int type, int data, Extent extent, Vector position) {
- super(type, data);
- checkNotNull(extent);
- checkNotNull(position);
- this.extent = extent;
- this.position = position;
- }
-
- @Override
- public void setId(int id) {
- throw new UnsupportedOperationException("This object is immutable");
- }
-
- @Override
- public void setData(int data) {
- throw new UnsupportedOperationException("This object is immutable");
- }
-
- @Override
- public CompoundTag getNbtData() {
- if (!loaded) {
- BaseBlock loadedBlock = extent.getBlock(position);
- super.setNbtData(loadedBlock.getNbtData());
- }
- return super.getNbtData();
- }
-
- @Override
- public void setNbtData(CompoundTag nbtData) {
- throw new UnsupportedOperationException("This object is immutable");
- }
-
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java
index a876a1c1f..0d175e974 100644
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java
+++ b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java
@@ -25,7 +25,8 @@ import com.sk89q.jnbt.NBTUtils;
import com.sk89q.jnbt.ShortTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
-import com.sk89q.worldedit.blocks.metadata.MobType;
+import com.sk89q.worldedit.world.block.BaseBlock;
+import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.storage.InvalidFormatException;
import java.util.HashMap;
@@ -49,41 +50,23 @@ public class MobSpawnerBlock extends BaseBlock implements TileEntityBlock {
private short maxNearbyEntities;
private short requiredPlayerRange;
- /**
- * Construct the mob spawner block with a pig as the mob type.
- */
- public MobSpawnerBlock() {
- super(BlockID.MOB_SPAWNER);
- this.mobType = MobType.PIG.getName();
- }
-
- /**
- * Construct the mob spawner block with a given mob type.
- *
- * @param mobType mob type
- */
- public MobSpawnerBlock(String mobType) {
- super(BlockID.MOB_SPAWNER);
- this.mobType = mobType;
- }
-
/**
* Construct the mob spawner block with a specified data value.
*
- * @param data data value
+ * @param blockState The block state
*/
- public MobSpawnerBlock(int data) {
- super(BlockID.MOB_SPAWNER, data);
+ public MobSpawnerBlock(BlockState blockState) {
+ super(blockState);
}
/**
* Construct the mob spawner block.
*
- * @param data data value
+ * @param blockState The block state
* @param mobType mob type
*/
- public MobSpawnerBlock(int data, String mobType) {
- super(BlockID.MOB_SPAWNER, data);
+ public MobSpawnerBlock(BlockState blockState, String mobType) {
+ super(blockState);
this.mobType = mobType;
}
@@ -135,7 +118,7 @@ public class MobSpawnerBlock extends BaseBlock implements TileEntityBlock {
@Override
public CompoundTag getNbtData() {
- Map values = new HashMap();
+ Map values = new HashMap<>();
values.put("EntityId", new StringTag(mobType));
values.put("Delay", new ShortTag(delay));
values.put("SpawnCount", new ShortTag(spawnCount));
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/NoteBlock.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/NoteBlock.java
deleted file mode 100644
index f061723c1..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/NoteBlock.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.blocks;
-
-import com.sk89q.jnbt.ByteTag;
-import com.sk89q.jnbt.CompoundTag;
-import com.sk89q.jnbt.StringTag;
-import com.sk89q.jnbt.Tag;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * A note block.
- */
-public class NoteBlock extends BaseBlock implements TileEntityBlock {
-
- private byte note;
-
- /**
- * Construct the note block with a data value of 0.
- */
- public NoteBlock() {
- super(BlockID.NOTE_BLOCK);
- this.note = 0;
- }
-
- /**
- * Construct the note block with a given data value.
- *
- * @param data data value
- */
- public NoteBlock(int data) {
- super(BlockID.NOTE_BLOCK, data);
- this.note = 0;
- }
-
- /**
- * Construct the note block with a given data value and note.
- *
- * @param data data value
- * @param note note
- */
- public NoteBlock(int data, byte note) {
- super(BlockID.NOTE_BLOCK, data);
- this.note = note;
- }
-
- /**
- * Get the note.
- *
- * @return the note
- */
- public byte getNote() {
- return note;
- }
-
- /**
- * Set the note.
- *
- * @param note the note to set
- */
- public void setNote(byte note) {
- this.note = note;
- }
-
- @Override
- public boolean hasNbtData() {
- return true;
- }
-
- @Override
- public String getNbtId() {
- return "Music";
- }
-
- @Override
- public CompoundTag getNbtData() {
- Map values = new HashMap();
- values.put("note", new ByteTag(note));
- return new CompoundTag(values);
- }
-
- @Override
- public void setNbtData(CompoundTag rootTag) {
- if (rootTag == null) {
- return;
- }
-
- Map values = rootTag.getValue();
-
- Tag t;
-
- t = values.get("id");
- if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals("Music")) {
- throw new RuntimeException("'Music' tile entity expected");
- }
-
- t = values.get("note");
- if (t instanceof ByteTag) {
- note = ((ByteTag) t).getValue();
- }
- }
-
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SignBlock.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SignBlock.java
index 78f78419e..e11330faa 100644
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SignBlock.java
+++ b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SignBlock.java
@@ -23,6 +23,8 @@ import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.util.gson.GsonUtil;
+import com.sk89q.worldedit.world.block.BaseBlock;
+import com.sk89q.worldedit.world.block.BlockState;
import java.util.HashMap;
import java.util.Map;
@@ -36,26 +38,14 @@ public class SignBlock extends BaseBlock implements TileEntityBlock {
private static String EMPTY = "{\"text\":\"\"}";
- /**
- * Construct the sign without text.
- *
- * @param type type ID
- * @param data data value (orientation)
- */
- public SignBlock(int type, int data) {
- super(type, data);
- this.text = new String[] { EMPTY, EMPTY, EMPTY, EMPTY };
- }
-
/**
* Construct the sign with text.
*
- * @param type type ID
- * @param data data value (orientation)
+ * @param blockState The block state
* @param text lines of text
*/
- public SignBlock(int type, int data, String[] text) {
- super(type, data);
+ public SignBlock(BlockState blockState, String[] text) {
+ super(blockState);
if (text == null) {
this.text = new String[] { EMPTY, EMPTY, EMPTY, EMPTY };
return;
@@ -103,7 +93,7 @@ public class SignBlock extends BaseBlock implements TileEntityBlock {
@Override
public CompoundTag getNbtData() {
- Map values = new HashMap();
+ Map values = new HashMap<>();
values.put("Text1", new StringTag(text[0]));
values.put("Text2", new StringTag(text[1]));
values.put("Text3", new StringTag(text[2]));
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SkullBlock.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SkullBlock.java
index d440ee0f7..4ecddddc2 100644
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SkullBlock.java
+++ b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SkullBlock.java
@@ -19,10 +19,11 @@
package com.sk89q.worldedit.blocks;
-import com.sk89q.jnbt.ByteTag;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
+import com.sk89q.worldedit.world.block.BaseBlock;
+import com.sk89q.worldedit.world.block.BlockState;
import java.util.HashMap;
import java.util.Map;
@@ -33,60 +34,25 @@ import java.util.Map;
public class SkullBlock extends BaseBlock implements TileEntityBlock {
private String owner = ""; // notchian
- private byte skullType; // stored here for block, in damage value for item
- private byte rot; // only matters if block data == 0x1 (on floor)
/**
* Construct the skull block with a default type of skelton.
- * @param data data value to set, controls placement
+ * @param state BlockState to set
*/
- public SkullBlock(int data) {
- this(data, (byte) 0);
- }
-
- /**
- * Construct the skull block with a given type.
- * 0 - skeleton
- * 1 - wither skelly
- * 2 - zombie
- * 3 - human
- * 4 - creeper
- * @param data data value to set, controls placement
- * @param type type of skull
- */
- public SkullBlock(int data, byte type) {
- this(data, type, (byte) 0);
- }
-
- /**
- * Construct the skull block with a given type and rotation.
- * @param data data value to set, controls placement
- * @param type type of skull
- * @param rot rotation (if on floor)
- */
- public SkullBlock(int data, byte type, byte rot) {
- super(BlockID.HEAD, data);
- if (type < (byte) 0 || type > (byte) 4) {
- this.skullType = (byte) 0;
- } else {
- this.skullType = type;
- }
- this.rot = rot;
+ public SkullBlock(BlockState state) {
+ super(state);
this.owner = "";
}
/**
* Construct the skull block with a given rotation and owner.
* The type is assumed to be player unless owner is null or empty.
- * @param data data value to set, controls placement
- * @param rot rotation of skull
+ * @param blockState BlockState to set
* @param owner name of player
*/
- public SkullBlock(int data, byte rot, String owner) {
- super(BlockID.HEAD, data);
- this.rot = rot;
+ public SkullBlock(BlockState blockState, String owner) {
+ super(blockState);
this.setOwner(owner);
- if (owner == null || owner.isEmpty()) this.skullType = (byte) 0;
}
/**
@@ -100,7 +66,6 @@ public class SkullBlock extends BaseBlock implements TileEntityBlock {
if (owner.length() > 16 || owner.isEmpty()) this.owner = "";
else this.owner = owner;
}
- if (this.owner != null && !this.owner.isEmpty()) this.skullType = (byte) 3;
}
/**
@@ -111,38 +76,6 @@ public class SkullBlock extends BaseBlock implements TileEntityBlock {
return owner;
}
- /**
- * Get the type of skull.
- * @return the skullType
- */
- public byte getSkullType() {
- return skullType;
- }
-
- /**
- * Set the type of skull;
- * @param skullType the skullType to set
- */
- public void setSkullType(byte skullType) {
- this.skullType = skullType;
- }
-
- /**
- * Get rotation of skull. This only means anything if the block data is 1.
- * @return the rotation
- */
- public byte getRot() {
- return rot;
- }
-
- /**
- * Set the rotation of skull.
- * @param rot the rotation to set
- */
- public void setRot(byte rot) {
- this.rot = rot;
- }
-
@Override
public boolean hasNbtData() {
return true;
@@ -155,11 +88,9 @@ public class SkullBlock extends BaseBlock implements TileEntityBlock {
@Override
public CompoundTag getNbtData() {
- Map values = new HashMap();
- values.put("SkullType", new ByteTag(skullType));
+ Map values = new HashMap<>();
if (owner == null) owner = "";
- values.put("ExtraType", new StringTag( owner));
- values.put("Rot", new ByteTag(rot));
+ values.put("ExtraType", new StringTag(owner));
return new CompoundTag(values);
}
@@ -178,17 +109,9 @@ public class SkullBlock extends BaseBlock implements TileEntityBlock {
throw new RuntimeException("'Skull' tile entity expected");
}
- t = values.get("SkullType");
- if (t instanceof ByteTag) {
- skullType = ((ByteTag) t).getValue();
- }
t = values.get("ExtraType");
- if (t != null && t instanceof StringTag) {
+ if (t instanceof StringTag) {
owner = ((StringTag) t).getValue();
}
- t = values.get("Rot");
- if (t instanceof ByteTag) {
- rot = ((ByteTag) t).getValue();
- }
}
}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/foundation/Block.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/foundation/Block.java
deleted file mode 100644
index c39c51e57..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/foundation/Block.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.foundation;
-
-import com.sk89q.worldedit.blocks.BaseBlock;
-
-/**
- * @deprecated Use {@link BaseBlock}
- */
-@Deprecated
-public abstract class Block {
-
- public abstract int getId();
-
- public abstract void setId(int id);
-
- public abstract int getData();
-
- public abstract void setData(int data);
-
- public abstract void setIdAndData(int id, int data);
-
- public abstract boolean hasWildcardData();
-
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/AbstractMask.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/AbstractMask.java
deleted file mode 100644
index 704ce4035..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/AbstractMask.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.masks;
-
-import com.sk89q.worldedit.LocalPlayer;
-import com.sk89q.worldedit.LocalSession;
-import com.sk89q.worldedit.Vector;
-
-/**
- * @deprecated Switch to {@link com.sk89q.worldedit.function.mask.AbstractMask}
- */
-@Deprecated
-public abstract class AbstractMask implements Mask {
- @Override
- public void prepare(LocalSession session, LocalPlayer player, Vector target) {
- }
-
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/BlockMask.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/BlockMask.java
deleted file mode 100644
index a6dd9ab97..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/BlockMask.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.masks;
-
-import com.sk89q.worldedit.EditSession;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.blocks.BaseBlock;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * @deprecated Use {@link com.sk89q.worldedit.function.mask.BlockMask}
- */
-@Deprecated
-public class BlockMask extends AbstractMask {
-
- private final Set blocks;
-
- public BlockMask() {
- blocks = new HashSet();
- }
-
- public BlockMask(Set types) {
- this.blocks = types;
- }
-
- public BlockMask(BaseBlock... block) {
- blocks = new HashSet();
- for (BaseBlock b : block) {
- add(b);
- }
- }
-
- public BlockMask(BaseBlock block) {
- this();
- add(block);
- }
-
- public void add(BaseBlock block) {
- blocks.add(block);
- }
-
- public void addAll(Collection blocks) {
- blocks.addAll(blocks);
- }
-
- @Override
- public boolean matches(EditSession editSession, Vector position) {
- BaseBlock block = editSession.getBlock(position);
- return blocks.contains(block)
- || blocks.contains(new BaseBlock(block.getType(), -1));
- }
-
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/CombinedMask.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/CombinedMask.java
deleted file mode 100644
index 3f7a6690e..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/CombinedMask.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.masks;
-
-import com.sk89q.worldedit.EditSession;
-import com.sk89q.worldedit.LocalPlayer;
-import com.sk89q.worldedit.LocalSession;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.function.mask.MaskIntersection;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @deprecated See {@link MaskIntersection}
- */
-@Deprecated
-public class CombinedMask extends AbstractMask {
- private final List masks = new ArrayList();
-
- public CombinedMask() {
- }
-
- public CombinedMask(Mask mask) {
- add(mask);
- }
-
- public CombinedMask(Mask ...mask) {
- for (Mask m : mask) {
- add(m);
- }
- }
-
- public CombinedMask(List masks) {
- this.masks.addAll(masks);
- }
-
- public void add(Mask mask) {
- masks.add(mask);
- }
-
- public boolean remove(Mask mask) {
- return masks.remove(mask);
- }
-
- public boolean has(Mask mask) {
- return masks.contains(mask);
- }
-
- @Override
- public void prepare(LocalSession session, LocalPlayer player, Vector target) {
- for (Mask mask : masks) {
- mask.prepare(session, player, target);
- }
- }
-
- @Override
- public boolean matches(EditSession editSession, Vector position) {
- for (Mask mask : masks) {
- if (!mask.matches(editSession, position)) {
- return false;
- }
- }
-
- return true;
- }
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/ExistingBlockMask.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/ExistingBlockMask.java
deleted file mode 100644
index 487786d06..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/ExistingBlockMask.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.masks;
-
-import com.sk89q.worldedit.EditSession;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.blocks.BlockID;
-
-/**
- * @deprecated See {@link com.sk89q.worldedit.function.mask.ExistingBlockMask}
- */
-@Deprecated
-public class ExistingBlockMask extends AbstractMask {
- @Override
- public boolean matches(EditSession editSession, Vector position) {
- return editSession.getBlockType(position) != BlockID.AIR;
- }
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/FuzzyBlockMask.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/FuzzyBlockMask.java
deleted file mode 100644
index 63093624c..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/FuzzyBlockMask.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.masks;
-
-import com.sk89q.worldedit.EditSession;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.blocks.BaseBlock;
-import com.sk89q.worldedit.blocks.Blocks;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * @deprecated See {@link com.sk89q.worldedit.function.mask.FuzzyBlockMask}
- */
-@Deprecated
-public class FuzzyBlockMask extends AbstractMask {
-
- private final Set filter;
-
- /**
- * Create a new fuzzy block mask.
- *
- * @param filter a list of block types to match
- */
- public FuzzyBlockMask(Set filter) {
- this.filter = filter;
- }
-
- /**
- * Create a new fuzzy block mask.
- *
- * @param block a list of block types to match
- */
- public FuzzyBlockMask(BaseBlock... block) {
- Set filter = new HashSet();
- Collections.addAll(filter, block);
- this.filter = filter;
- }
-
- @Override
- public boolean matches(EditSession editSession, Vector position) {
- BaseBlock compare = new BaseBlock(editSession.getBlockType(position), editSession.getBlockData(position));
- return Blocks.containsFuzzy(filter, compare);
- }
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/Mask.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/Mask.java
deleted file mode 100644
index cf0a04c89..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/Mask.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.masks;
-
-import com.sk89q.worldedit.EditSession;
-import com.sk89q.worldedit.LocalPlayer;
-import com.sk89q.worldedit.LocalSession;
-import com.sk89q.worldedit.Vector;
-
-/**
- * @deprecated Use {@link com.sk89q.worldedit.function.mask.Mask}
- */
-@Deprecated
-public interface Mask {
-
- /**
- * Called one time before each edit session.
- *
- * @param session a session
- * @param player a player
- * @param target target of the brush, null if not a brush mask
- */
- void prepare(LocalSession session, LocalPlayer player, Vector target);
-
- /**
- * Given a block position, this method returns true if the block at
- * that position matches the filter. Block information is not provided
- * as getting a BaseBlock has unneeded overhead in most block querying
- * situations (enumerating a chest's contents is a waste, for example).
- *
- * @param editSession an instance
- * @param position the position to check
- * @return true if it matches
- */
- boolean matches(EditSession editSession, Vector position);
-
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/SolidBlockMask.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/SolidBlockMask.java
deleted file mode 100644
index dd5403441..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/SolidBlockMask.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.masks;
-
-import com.sk89q.worldedit.EditSession;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.blocks.BlockType;
-
-/**
- * @deprecated See {@link com.sk89q.worldedit.function.mask.SolidBlockMask}
- */
-@Deprecated
-public class SolidBlockMask extends AbstractMask {
- @Override
- public boolean matches(EditSession editSession, Vector position) {
- return !BlockType.canPassThrough(editSession.getBlockType(position), editSession.getBlockData(position));
- }
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/UnderOverlayMask.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/UnderOverlayMask.java
deleted file mode 100644
index 39fe3dc8e..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/masks/UnderOverlayMask.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.masks;
-
-import com.sk89q.worldedit.EditSession;
-import com.sk89q.worldedit.LocalPlayer;
-import com.sk89q.worldedit.LocalSession;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.blocks.BaseBlock;
-import com.sk89q.worldedit.function.mask.MaskIntersection;
-import com.sk89q.worldedit.function.mask.Masks;
-import com.sk89q.worldedit.function.mask.OffsetMask;
-
-import java.util.Set;
-
-/**
- * @deprecated Use {@link OffsetMask} with {@link MaskIntersection} and {@link Masks#negate(com.sk89q.worldedit.function.mask.Mask)}
- */
-@Deprecated
-public class UnderOverlayMask extends AbstractMask {
- private final int yMod;
- private Mask mask;
-
- @Deprecated
- public UnderOverlayMask(Set ids, boolean overlay) {
- this(new BlockTypeMask(ids), overlay);
- }
-
- public UnderOverlayMask(Mask mask, boolean overlay) {
- this.yMod = overlay ? -1 : 1;
- this.mask = mask;
- }
-
- @Deprecated
- public void addAll(Set ids) {
- if (mask instanceof BlockMask) {
- final BlockMask blockTypeMask = (BlockMask) mask;
- for (Integer id : ids) {
- blockTypeMask.add(new BaseBlock(id));
- }
- } else if (mask instanceof ExistingBlockMask) {
- final BlockMask blockMask = new BlockMask();
- for (int type : ids) {
- blockMask.add(new BaseBlock(type));
- }
- mask = blockMask;
- }
- }
-
- @Override
- public void prepare(LocalSession session, LocalPlayer player, Vector target) {
- mask.prepare(session, player, target);
- }
-
- @Override
- public boolean matches(EditSession editSession, Vector position) {
- return !mask.matches(editSession, position) && mask.matches(editSession, position.add(0, yMod, 0));
- }
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/patterns/Pattern.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/patterns/Pattern.java
deleted file mode 100644
index b27e8e0fc..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/patterns/Pattern.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.patterns;
-
-import com.sk89q.worldedit.*;
-import com.sk89q.worldedit.blocks.BaseBlock;
-
-/**
- * @deprecated See {@link com.sk89q.worldedit.function.pattern.Pattern}
- */
-@Deprecated
-public interface Pattern {
-
- /**
- * Get a block for a position. This return value of this method does
- * not have to be consistent for the same position.
- *
- * @param position the position where a block is needed
- * @return a block
- */
- public BaseBlock next(Vector position);
-
- /**
- * Get a block for a position. This return value of this method does
- * not have to be consistent for the same position.
- *
- * @param x the X coordinate
- * @param y the Y coordinate
- * @param z the Z coordinate
- * @return a block
- */
- public BaseBlock next(int x, int y, int z);
-
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/patterns/RandomFillPattern.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/patterns/RandomFillPattern.java
deleted file mode 100644
index 6014eec36..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/patterns/RandomFillPattern.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.patterns;
-
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.blocks.BaseBlock;
-import com.sk89q.worldedit.function.pattern.RandomPattern;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Random;
-
-/**
- * @deprecated See {@link RandomPattern}
- */
-@Deprecated
-public class RandomFillPattern implements Pattern {
-
- private static final Random random = new Random();
- private List blocks;
-
- /**
- * Construct the object.
- *
- * @param blocks a list of blocks
- */
- public RandomFillPattern(List blocks) {
- double max = 0;
-
- for (BlockChance block : blocks) {
- max += block.getChance();
- }
-
- List finalBlocks = new ArrayList();
-
- double i = 0;
-
- for (BlockChance block : blocks) {
- double v = block.getChance() / max;
- i += v;
- finalBlocks.add(new BlockChance(block.getBlock(), i));
- }
-
- this.blocks = finalBlocks;
- }
-
- @Override
- public BaseBlock next(Vector position) {
- double r = random.nextDouble();
-
- for (BlockChance block : blocks) {
- if (r <= block.getChance()) {
- return block.getBlock();
- }
- }
-
- throw new RuntimeException("ProportionalFillPattern");
- }
-
- @Override
- public BaseBlock next(int x, int y, int z) {
- return next(null);
- }
-
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/AbstractLegacyRegionSelector.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/AbstractLegacyRegionSelector.java
deleted file mode 100644
index 1930e3b9f..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/AbstractLegacyRegionSelector.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.regions;
-
-import com.sk89q.worldedit.LocalPlayer;
-import com.sk89q.worldedit.LocalSession;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.extension.platform.Actor;
-
-abstract class AbstractLegacyRegionSelector implements RegionSelector {
-
- @Deprecated
- public final void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector position) {
- explainPrimarySelection((Actor) player, session, position);
- }
-
- @Deprecated
- public final void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector position) {
- explainSecondarySelection((Actor) player, session, position);
- }
-
- @Deprecated
- public final void explainRegionAdjust(LocalPlayer player, LocalSession session) {
- explainRegionAdjust((Actor) player, session);
- }
-
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/ConvexPolyhedralRegionSelector.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/ConvexPolyhedralRegionSelector.java
deleted file mode 100644
index f264546dd..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/ConvexPolyhedralRegionSelector.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.regions;
-
-import com.sk89q.worldedit.internal.cui.CUIRegion;
-
-/**
- * @deprecated This class only exists as to not break binary compatibility
- */
-@Deprecated
-public abstract class ConvexPolyhedralRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/CuboidRegionSelector.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/CuboidRegionSelector.java
deleted file mode 100644
index 458d75cb3..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/CuboidRegionSelector.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.regions;
-
-import com.sk89q.worldedit.internal.cui.CUIRegion;
-
-/**
- * @deprecated This class only exists as to not break binary compatibility
- */
-@Deprecated
-public abstract class CuboidRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/CylinderRegionSelector.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/CylinderRegionSelector.java
deleted file mode 100644
index b54709e7d..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/CylinderRegionSelector.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.regions;
-
-import com.sk89q.worldedit.internal.cui.CUIRegion;
-
-/**
- * @deprecated This class only exists as to not break binary compatibility
- */
-@Deprecated
-public abstract class CylinderRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/EllipsoidRegionSelector.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/EllipsoidRegionSelector.java
deleted file mode 100644
index 69bf5ba2b..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/EllipsoidRegionSelector.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.regions;
-
-import com.sk89q.worldedit.internal.cui.CUIRegion;
-
-/**
- * @deprecated This class only exists as to not break binary compatibility
- */
-@Deprecated
-public abstract class EllipsoidRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/ExtendingCuboidRegionSelector.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/ExtendingCuboidRegionSelector.java
deleted file mode 100644
index d9888a447..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/ExtendingCuboidRegionSelector.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.regions;
-
-import com.sk89q.worldedit.internal.cui.CUIRegion;
-
-/**
- * @deprecated This class only exists as to not break binary compatibility
- */
-@Deprecated
-public abstract class ExtendingCuboidRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/Polygonal2DRegionSelector.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/Polygonal2DRegionSelector.java
deleted file mode 100644
index f3b8a9cbd..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/Polygonal2DRegionSelector.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.regions;
-
-import com.sk89q.worldedit.internal.cui.CUIRegion;
-
-/**
- * @deprecated This class only exists as to not break binary compatibility
- */
-@Deprecated
-public abstract class Polygonal2DRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
-
- /**
- * Get the number of points.
- *
- * @return the number of points
- */
- public abstract int getPointCount();
-
-}
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/SphereRegionSelector.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/SphereRegionSelector.java
deleted file mode 100644
index 8a3057dc0..000000000
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/regions/SphereRegionSelector.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * 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 .
- */
-
-package com.sk89q.worldedit.regions;
-
-import com.sk89q.worldedit.internal.cui.CUIRegion;
-
-/**
- * @deprecated This class only exists as to not break binary compatibility
- */
-@Deprecated
-public abstract class SphereRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
-}
diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java
index 6477d2502..2c439e11b 100644
--- a/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java
+++ b/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java
@@ -72,7 +72,7 @@ public final class CompoundTag extends Tag {
* @return the builder
*/
public CompoundTagBuilder createBuilder() {
- return new CompoundTagBuilder(new HashMap(value));
+ return new CompoundTagBuilder(new HashMap<>(value));
}
/**
@@ -317,6 +317,24 @@ public final class CompoundTag extends Tag {
}
}
+ /**
+ * Get a {@code long[]} named with the given key.
+ *
+ *
If the key does not exist or its value is not an long array tag,
+ * then an empty array will be returned.
+ *
+ * @param key the key
+ * @return an int array
+ */
+ public long[] getLongArray(String key) {
+ Tag tag = value.get(key);
+ if (tag instanceof LongArrayTag) {
+ return ((LongArrayTag) tag).getValue();
+ } else {
+ return new long[0];
+ }
+ }
+
/**
* Get a long named with the given key.
*
diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTagBuilder.java b/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTagBuilder.java
index 3d476fa40..b0e873c0d 100644
--- a/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTagBuilder.java
+++ b/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTagBuilder.java
@@ -19,11 +19,11 @@
package com.sk89q.jnbt;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import java.util.HashMap;
import java.util.Map;
-import static com.google.common.base.Preconditions.checkNotNull;
-
/**
* Helps create compound tags.
*/
@@ -35,7 +35,7 @@ public class CompoundTagBuilder {
* Create a new instance.
*/
CompoundTagBuilder() {
- this.entries = new HashMap();
+ this.entries = new HashMap<>();
}
/**
@@ -133,6 +133,18 @@ public class CompoundTagBuilder {
return put(key, new IntTag(value));
}
+ /**
+ * Put the given key and value into the compound tag as a
+ * {@code LongArrayTag}.
+ *
+ * @param key they key
+ * @param value the value
+ * @return this object
+ */
+ public CompoundTagBuilder putLongArray(String key, long[] value) {
+ return put(key, new LongArrayTag(value));
+ }
+
/**
* Put the given key and value into the compound tag as a
* {@code LongTag}.
@@ -189,7 +201,7 @@ public class CompoundTagBuilder {
* @return the new compound tag
*/
public CompoundTag build() {
- return new CompoundTag(new HashMap(entries));
+ return new CompoundTag(new HashMap<>(entries));
}
/**
diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/ListTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/ListTag.java
index 3cbe42977..7a2482344 100644
--- a/worldedit-core/src/main/java/com/sk89q/jnbt/ListTag.java
+++ b/worldedit-core/src/main/java/com/sk89q/jnbt/ListTag.java
@@ -19,12 +19,12 @@
package com.sk89q.jnbt;
-import javax.annotation.Nullable;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import java.util.Collections;
import java.util.List;
-import java.util.NoSuchElementException;
-import static com.google.common.base.Preconditions.checkNotNull;
+import javax.annotation.Nullable;
/**
* The {@code TAG_List} tag.
@@ -79,11 +79,10 @@ public final class ListTag extends Tag {
*/
@Nullable
public Tag getIfExists(int index) {
- try {
- return value.get(index);
- } catch (NoSuchElementException e) {
+ if (index >= value.size()) {
return null;
}
+ return value.get(index);
}
/**
diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/ListTagBuilder.java b/worldedit-core/src/main/java/com/sk89q/jnbt/ListTagBuilder.java
index 9bcbbfd05..c410ec3ae 100644
--- a/worldedit-core/src/main/java/com/sk89q/jnbt/ListTagBuilder.java
+++ b/worldedit-core/src/main/java/com/sk89q/jnbt/ListTagBuilder.java
@@ -19,13 +19,13 @@
package com.sk89q.jnbt;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
-import static com.google.common.base.Preconditions.checkNotNull;
-
/**
* Helps create list tags.
*/
@@ -42,7 +42,7 @@ public class ListTagBuilder {
ListTagBuilder(Class extends Tag> type) {
checkNotNull(type);
this.type = type;
- this.entries = new ArrayList();
+ this.entries = new ArrayList<>();
}
/**
@@ -80,7 +80,7 @@ public class ListTagBuilder {
* @return the new list tag
*/
public ListTag build() {
- return new ListTag(type, new ArrayList(entries));
+ return new ListTag(type, new ArrayList<>(entries));
}
/**
diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/patterns/ClipboardPattern.java b/worldedit-core/src/main/java/com/sk89q/jnbt/LongArrayTag.java
similarity index 51%
rename from worldedit-core/src/legacy/java/com/sk89q/worldedit/patterns/ClipboardPattern.java
rename to worldedit-core/src/main/java/com/sk89q/jnbt/LongArrayTag.java
index 8808a0684..30dad0cc3 100644
--- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/patterns/ClipboardPattern.java
+++ b/worldedit-core/src/main/java/com/sk89q/jnbt/LongArrayTag.java
@@ -17,41 +17,44 @@
* along with this program. If not, see .
*/
-package com.sk89q.worldedit.patterns;
+package com.sk89q.jnbt;
-import com.sk89q.worldedit.*;
-import com.sk89q.worldedit.blocks.BaseBlock;
+import static com.google.common.base.Preconditions.checkNotNull;
/**
- * Pattern that repeats the clipboard.
+ * The {@code TAG_Long_Array} tag.
*/
-public class ClipboardPattern implements Pattern {
+public class LongArrayTag extends Tag {
- private CuboidClipboard clipboard;
- private Vector size;
+ private final long[] value;
/**
- * Construct the object.
+ * Creates the tag with an empty name.
*
- * @param clipboard the clipboard
+ * @param value the value of the tag
*/
- public ClipboardPattern(CuboidClipboard clipboard) {
- this.clipboard = clipboard;
- this.size = clipboard.getSize();
+ public LongArrayTag(long[] value) {
+ super();
+ checkNotNull(value);
+ this.value = value;
}
@Override
- public BaseBlock next(Vector position) {
- return next(position.getBlockX(), position.getBlockY(), position.getBlockZ());
+ public long[] getValue() {
+ return value;
}
@Override
- public BaseBlock next(int x, int y, int z) {
- int xp = Math.abs(x) % size.getBlockX();
- int yp = Math.abs(y) % size.getBlockY();
- int zp = Math.abs(z) % size.getBlockZ();
-
- return clipboard.getPoint(new Vector(xp, yp, zp));
+ public String toString() {
+ StringBuilder hex = new StringBuilder();
+ for (long b : value) {
+ String hexDigits = Long.toHexString(b).toUpperCase();
+ if (hexDigits.length() == 1) {
+ hex.append("0");
+ }
+ hex.append(hexDigits).append(" ");
+ }
+ return "TAG_Long_Array(" + hex + ")";
}
}
diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTConstants.java b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTConstants.java
index 2ff2768ac..1cbff362d 100644
--- a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTConstants.java
+++ b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTConstants.java
@@ -31,7 +31,7 @@ public final class NBTConstants {
public static final int TYPE_END = 0, TYPE_BYTE = 1, TYPE_SHORT = 2,
TYPE_INT = 3, TYPE_LONG = 4, TYPE_FLOAT = 5, TYPE_DOUBLE = 6,
TYPE_BYTE_ARRAY = 7, TYPE_STRING = 8, TYPE_LIST = 9,
- TYPE_COMPOUND = 10, TYPE_INT_ARRAY = 11;
+ TYPE_COMPOUND = 10, TYPE_INT_ARRAY = 11, TYPE_LONG_ARRAY = 12;
/**
* Default private constructor.
@@ -73,6 +73,8 @@ public final class NBTConstants {
return CompoundTag.class;
case TYPE_INT_ARRAY:
return IntArrayTag.class;
+ case TYPE_LONG_ARRAY:
+ return LongArrayTag.class;
default:
throw new IllegalArgumentException("Unknown tag type ID of " + id);
}
diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTInputStream.java b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTInputStream.java
index 223ca2248..b6096a163 100644
--- a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTInputStream.java
+++ b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTInputStream.java
@@ -128,7 +128,7 @@ public final class NBTInputStream implements Closeable {
int childType = is.readByte();
length = is.readInt();
- List tagList = new ArrayList();
+ List tagList = new ArrayList<>();
for (int i = 0; i < length; ++i) {
Tag tag = readTagPayload(childType, depth + 1);
if (tag instanceof EndTag) {
@@ -139,7 +139,7 @@ public final class NBTInputStream implements Closeable {
return new ListTag(NBTUtils.getTypeClass(childType), tagList);
case NBTConstants.TYPE_COMPOUND:
- Map tagMap = new HashMap();
+ Map tagMap = new HashMap<>();
while (true) {
NamedTag namedTag = readNamedTag(depth + 1);
Tag tag = namedTag.getTag();
@@ -158,6 +158,13 @@ public final class NBTInputStream implements Closeable {
data[i] = is.readInt();
}
return new IntArrayTag(data);
+ case NBTConstants.TYPE_LONG_ARRAY:
+ length = is.readInt();
+ long[] longData = new long[length];
+ for (int i = 0; i < length; i++) {
+ longData[i] = is.readLong();
+ }
+ return new LongArrayTag(longData);
default:
throw new IOException("Invalid tag type: " + type + ".");
}
diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java
index a54ea6e26..5bed0297f 100644
--- a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java
+++ b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java
@@ -19,6 +19,8 @@
package com.sk89q.jnbt;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import java.io.Closeable;
import java.io.DataOutputStream;
import java.io.IOException;
@@ -26,8 +28,6 @@ import java.io.OutputStream;
import java.util.List;
import java.util.Map;
-import static com.google.common.base.Preconditions.checkNotNull;
-
/**
* This class writes NBT, or Named Binary Tag
* {@code Tag} objects to an underlying {@code OutputStream}.
@@ -129,6 +129,9 @@ public final class NBTOutputStream implements Closeable {
case NBTConstants.TYPE_INT_ARRAY:
writeIntArrayTagPayload((IntArrayTag) tag);
break;
+ case NBTConstants.TYPE_LONG_ARRAY:
+ writeLongArrayTagPayload((LongArrayTag) tag);
+ break;
default:
throw new IOException("Invalid tag type: " + type + ".");
}
@@ -286,6 +289,14 @@ public final class NBTOutputStream implements Closeable {
}
}
+ private void writeLongArrayTagPayload(LongArrayTag tag) throws IOException {
+ long[] data = tag.getValue();
+ os.writeInt(data.length);
+ for (long aData : data) {
+ os.writeLong(aData);
+ }
+ }
+
@Override
public void close() throws IOException {
os.close();
diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTUtils.java b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTUtils.java
index 428ff4d86..e44262911 100644
--- a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTUtils.java
+++ b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTUtils.java
@@ -19,13 +19,13 @@
package com.sk89q.jnbt;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.world.storage.InvalidFormatException;
import java.util.Map;
-import static com.google.common.base.Preconditions.checkNotNull;
-
/**
* A class which contains NBT-related utility methods.
*
@@ -69,6 +69,8 @@ public final class NBTUtils {
return "TAG_String";
} else if (clazz.equals(IntArrayTag.class)) {
return "TAG_Int_Array";
+ } else if (clazz.equals(LongArrayTag.class)) {
+ return "TAG_Long_Array";
} else {
throw new IllegalArgumentException("Invalid tag classs ("
+ clazz.getName() + ").");
@@ -107,6 +109,8 @@ public final class NBTUtils {
return NBTConstants.TYPE_STRING;
} else if (clazz.equals(IntArrayTag.class)) {
return NBTConstants.TYPE_INT_ARRAY;
+ } else if (clazz.equals(LongArrayTag.class)) {
+ return NBTConstants.TYPE_LONG_ARRAY;
} else {
throw new IllegalArgumentException("Invalid tag classs ("
+ clazz.getName() + ").");
@@ -146,6 +150,8 @@ public final class NBTUtils {
return CompoundTag.class;
case NBTConstants.TYPE_INT_ARRAY:
return IntArrayTag.class;
+ case NBTConstants.TYPE_LONG_ARRAY:
+ return LongArrayTag.class;
default:
throw new IllegalArgumentException("Invalid tag type : " + type
+ ".");
diff --git a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandContext.java b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandContext.java
index d1db70207..9dfc58d6f 100644
--- a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandContext.java
+++ b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandContext.java
@@ -34,8 +34,8 @@ public class CommandContext {
protected final List originalArgIndices;
protected final String[] originalArgs;
- protected final Set booleanFlags = new HashSet();
- protected final Map valueFlags = new HashMap();
+ protected final Set booleanFlags = new HashSet<>();
+ protected final Map valueFlags = new HashMap<>();
protected final SuggestionContext suggestionContext;
protected final CommandLocals locals;
@@ -103,8 +103,8 @@ public class CommandContext {
SuggestionContext suggestionContext = SuggestionContext.hangingValue();
// Eliminate empty args and combine multiword args first
- List argIndexList = new ArrayList(args.length);
- List argList = new ArrayList(args.length);
+ List argIndexList = new ArrayList<>(args.length);
+ List argList = new ArrayList<>(args.length);
for (int i = 1; i < args.length; ++i) {
isHanging = false;
@@ -152,8 +152,8 @@ public class CommandContext {
// Then flags
- this.originalArgIndices = new ArrayList(argIndexList.size());
- this.parsedArgs = new ArrayList(argList.size());
+ this.originalArgIndices = new ArrayList<>(argIndexList.size());
+ this.parsedArgs = new ArrayList<>(argList.size());
if (parseFlags) {
for (int nextArg = 0; nextArg < argList.size(); ) {
diff --git a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandException.java b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandException.java
index e81344e56..4345793d1 100644
--- a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandException.java
+++ b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandException.java
@@ -19,16 +19,17 @@
package com.sk89q.minecraft.util.commands;
-import javax.annotation.Nullable;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
-import static com.google.common.base.Preconditions.checkNotNull;
+import javax.annotation.Nullable;
public class CommandException extends Exception {
- private List commandStack = new ArrayList();
+ private List commandStack = new ArrayList<>();
public CommandException() {
super();
diff --git a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandLocals.java b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandLocals.java
index e0053f0b3..0bc2992a5 100644
--- a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandLocals.java
+++ b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandLocals.java
@@ -24,7 +24,7 @@ import java.util.Map;
public class CommandLocals {
- private final Map