diff --git a/pom.xml b/pom.xml
index a7efcf4c5..923889ae5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,17 +1,27 @@
-
+4.0.0com.sk89qworldedit
- 5.7-SNAPSHOT
+ 6.0.0-SNAPSHOTjar
-
-
+
+
+
+ UTF-8
+
+
+
+
WorldEdit2010http://wiki.sk89q.com/wiki/WorldEdit
- A voxel map editor for Minecraft with tools for adventure map designers,
- server administrators, and anyone who enjoys building massive structures.
-
+ An in-game voxel map editor for Minecraft.
+
GNU General Public License 2.0
@@ -26,36 +36,44 @@
License on all new contributions
-
+
YouTrackhttp://youtrack.sk89q.com
-
+
- Jenkins
- http://build.sk89q.com
+ TeamCity
+ http://builds.enginehub.org
-
+
scm:git:git://github.com/sk89q/worldedit.gitscm:git:git@github.com:sk89q/worldedit.githttps://github.com/sk89q/worldeditmaster
-
+
Developer Discussionhttps://groups.google.com/d/forum/sk-dev-discuss
-
+
+
+
sk89q-docs-uploadftp://sk89q-maven-deploy/worldedit/
+
+
maven.sk89q.comhttp://maven.sk89q.com/artifactory/libs-release-local
@@ -65,91 +83,89 @@
http://maven.sk89q.com/artifactory/libs-snapshot-local
-
-
- UTF-8
-
-
+
+
+
- sk89q-repo
+ maven.sk89q.comhttp://maven.sk89q.com/repo/
-
- bukkit-repo
- http://repo.bukkit.org/content/groups/public
-
-
+
-
+
+ de.schlichtherletruezip6.8.3
- compile
+ compilejar
-
-
+
+
+ rhinojs1.7R2
- compile
+ compilejar
-
-
- com.sk89q
- jchronic
- 0.2.4a
- compile
- jar
-
-
-
-
- com.sk89q
- dummypermscompat
- 1.7
- compile
- jar
- true
-
-
- org.bukkit
- bukkit
- 1.7.2-R0.2
- compile
+
+
+ org.yaml
+ snakeyaml
+ 1.9jar
+ compiletrue
-
-
- org.bukkit
- craftbukkit
- 1.7.5-R0.1-SNAPSHOT
- compile
+
+
+
+ com.google.guava
+ guava
+ 10.0.1
+ compilejar
- true
-
-
+
+
+
+ com.sk89q
+ jchronic
+ 0.2.4a
+ compile
+ jar
+
+
+
+ org.mockitomockito-core1.9.0-rc1testjar
-
-
+
+
+
install${basedir}/src/main/java/
-
+
+ org.apache.maven.wagonwagon-ftp
@@ -157,34 +173,29 @@
-
-
- .
- true
- ${basedir}/src/main/resources/
-
- plugin.yml
-
-
-
- defaults/
- true
- ${basedir}/src/main/resources/
-
- config.yml
-
-
-
- nmsblocks/
- false
- ${basedir}/src/main/resources/nmsblocks/
-
- *.class
-
-
-
-
+
+
+ org.codehaus.mojo
+ build-helper-maven-plugin
+ 1.7
+
+
+ add-source
+ generate-sources
+
+ add-source
+
+
+
+
+
+
+
+
+
+
+
org.apache.maven.pluginsmaven-compiler-plugin
@@ -195,6 +206,7 @@
+
org.apache.maven.pluginsmaven-jar-plugin
@@ -216,6 +228,7 @@
+
maven-assembly-plugin2.2-beta-2
@@ -233,6 +246,7 @@
+
org.apache.maven.pluginsmaven-shade-plugin
@@ -254,6 +268,7 @@
+
org.apache.maven.pluginsmaven-release-plugin
@@ -265,6 +280,7 @@
+
org.apache.maven.pluginsmaven-surefire-plugin
@@ -276,12 +292,14 @@
+
org.apache.maven.pluginsmaven-site-plugin3.1
+
org.apache.maven.pluginsmaven-project-info-reports-plugin
@@ -295,7 +313,8 @@
-
+
+
org.apache.maven.pluginsmaven-javadoc-plugin
@@ -306,9 +325,141 @@
-
+
+
+
-
+
+
+ bukkit
+
+
+ true
+
+
+
+
+ bukkit-repo
+ http://repo.bukkit.org/content/groups/public
+
+
+
+
+
+
+ com.sk89q
+ dummypermscompat
+ 1.7
+ compile
+ jar
+ true
+
+
+
+
+ org.bukkit
+ bukkit
+ 1.7.2-R0.2
+ compile
+ jar
+ true
+
+
+
+
+ org.bukkit
+ craftbukkit
+ 1.7.5-R0.1-SNAPSHOT
+ compile
+ jar
+ true
+
+
+
+
+
+
+
+ .
+ true
+ ${basedir}/src/bukkit/resources/
+
+ plugin.yml
+
+
+
+
+
+ defaults/
+ true
+ ${basedir}/src/bukkit/resources/
+
+ config.yml
+
+
+
+
+
+ nmsblocks/
+ false
+ ${basedir}/src/bukkit/resources/nmsblocks/
+
+ *.class
+
+
+
+
+
+
+
+ org.codehaus.mojo
+ build-helper-maven-plugin
+ 1.7
+
+
+ add-bukkit-sources
+ generate-sources
+
+ add-source
+
+
+
+
+
+
+
+
+ add-bukkit-test-sources
+ generate-sources
+
+ add-test-source
+
+
+
+
+
+
+
+
+
+
+
+
+
+
forge
@@ -341,10 +492,14 @@
-
+
attach-docs
-
+
@@ -360,7 +515,7 @@
-
+
org.apache.maven.pluginsmaven-javadoc-plugin
@@ -377,18 +532,22 @@
-
-
+
+
spout
-
+
spout-repohttp://nexus.spout.org/content/groups/public/
-
+
org.spout
@@ -422,7 +581,7 @@
1.5
- add-sources
+ add-spout-sourcesgenerate-sourcesadd-source
diff --git a/src/test/java/com/sk89q/wepif/DinnerPermsResolverTest.java b/src/bukkit-test/java/com/sk89q/wepif/DinnerPermsResolverTest.java
similarity index 100%
rename from src/test/java/com/sk89q/wepif/DinnerPermsResolverTest.java
rename to src/bukkit-test/java/com/sk89q/wepif/DinnerPermsResolverTest.java
diff --git a/src/test/java/com/sk89q/wepif/TestOfflinePermissible.java b/src/bukkit-test/java/com/sk89q/wepif/TestOfflinePermissible.java
similarity index 100%
rename from src/test/java/com/sk89q/wepif/TestOfflinePermissible.java
rename to src/bukkit-test/java/com/sk89q/wepif/TestOfflinePermissible.java
diff --git a/src/test/java/com/sk89q/worldedit/bukkit/BukkitWorldTest.java b/src/bukkit-test/java/com/sk89q/worldedit/bukkit/BukkitWorldTest.java
similarity index 100%
rename from src/test/java/com/sk89q/worldedit/bukkit/BukkitWorldTest.java
rename to src/bukkit-test/java/com/sk89q/worldedit/bukkit/BukkitWorldTest.java
diff --git a/src/main/java/com/sk89q/bukkit/util/CommandInfo.java b/src/bukkit/java/com/sk89q/bukkit/util/CommandInfo.java
similarity index 100%
rename from src/main/java/com/sk89q/bukkit/util/CommandInfo.java
rename to src/bukkit/java/com/sk89q/bukkit/util/CommandInfo.java
diff --git a/src/main/java/com/sk89q/bukkit/util/CommandRegistration.java b/src/bukkit/java/com/sk89q/bukkit/util/CommandRegistration.java
similarity index 100%
rename from src/main/java/com/sk89q/bukkit/util/CommandRegistration.java
rename to src/bukkit/java/com/sk89q/bukkit/util/CommandRegistration.java
diff --git a/src/main/java/com/sk89q/bukkit/util/CommandsManagerRegistration.java b/src/bukkit/java/com/sk89q/bukkit/util/CommandsManagerRegistration.java
similarity index 100%
rename from src/main/java/com/sk89q/bukkit/util/CommandsManagerRegistration.java
rename to src/bukkit/java/com/sk89q/bukkit/util/CommandsManagerRegistration.java
diff --git a/src/main/java/com/sk89q/bukkit/util/DynamicPluginCommand.java b/src/bukkit/java/com/sk89q/bukkit/util/DynamicPluginCommand.java
similarity index 100%
rename from src/main/java/com/sk89q/bukkit/util/DynamicPluginCommand.java
rename to src/bukkit/java/com/sk89q/bukkit/util/DynamicPluginCommand.java
diff --git a/src/main/java/com/sk89q/bukkit/util/DynamicPluginCommandHelpTopic.java b/src/bukkit/java/com/sk89q/bukkit/util/DynamicPluginCommandHelpTopic.java
similarity index 100%
rename from src/main/java/com/sk89q/bukkit/util/DynamicPluginCommandHelpTopic.java
rename to src/bukkit/java/com/sk89q/bukkit/util/DynamicPluginCommandHelpTopic.java
diff --git a/src/main/java/com/sk89q/bukkit/util/FallbackRegistrationListener.java b/src/bukkit/java/com/sk89q/bukkit/util/FallbackRegistrationListener.java
similarity index 100%
rename from src/main/java/com/sk89q/bukkit/util/FallbackRegistrationListener.java
rename to src/bukkit/java/com/sk89q/bukkit/util/FallbackRegistrationListener.java
diff --git a/src/main/java/com/sk89q/wepif/ConfigurationPermissionsResolver.java b/src/bukkit/java/com/sk89q/wepif/ConfigurationPermissionsResolver.java
similarity index 97%
rename from src/main/java/com/sk89q/wepif/ConfigurationPermissionsResolver.java
rename to src/bukkit/java/com/sk89q/wepif/ConfigurationPermissionsResolver.java
index de8cedcba..674e60ef9 100644
--- a/src/main/java/com/sk89q/wepif/ConfigurationPermissionsResolver.java
+++ b/src/bukkit/java/com/sk89q/wepif/ConfigurationPermissionsResolver.java
@@ -1,170 +1,170 @@
-// $Id$
-/*
- * WorldEdit
- * Copyright (C) 2010 sk89q and contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package com.sk89q.wepif;
-
-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;
- private Set defaultPermissionsCache;
- private Map> userGroups;
-
- public ConfigurationPermissionsResolver(YAMLProcessor config) {
- this.config = config;
- }
-
- public static YAMLNode generateDefaultPerms(YAMLNode section) {
- section.setProperty("groups.default.permissions", new String[] {
- "worldedit.reload",
- "worldedit.selection",
- "worlds.creative.worldedit.region"});
- section.setProperty("groups.admins.permissions", new String[] { "*" });
- section.setProperty("users.sk89q.permissions", new String[] { "worldedit" });
- section.setProperty("users.sk89q.groups", new String[] { "admins" });
- return section;
- }
-
- public void load() {
- userGroups = new HashMap>();
- userPermissionsCache = new HashMap>();
- defaultPermissionsCache = new HashSet();
-
- Map> userGroupPermissions = new HashMap>();
-
- List groupKeys = config.getStringList("permissions.groups", null);
-
- if (groupKeys != null) {
- for (String key : groupKeys) {
- List permissions =
- config.getStringList("permissions.groups." + key + ".permissions", null);
-
- if (permissions.size() > 0) {
- Set groupPerms = new HashSet(permissions);
- userGroupPermissions.put(key, groupPerms);
-
- if (key.equals("default")) {
- defaultPermissionsCache.addAll(permissions);
- }
- }
- }
- }
-
- List userKeys = config.getStringList("permissions.users", null);
-
- if (userKeys != null) {
- for (String key : userKeys) {
- Set permsCache = new HashSet();
-
- List permissions =
- config.getStringList("permissions.users." + key + ".permissions", null);
-
- if (permissions.size() > 0) {
- permsCache.addAll(permissions);
- }
-
- List groups =
- config.getStringList("permissions.users." + key + ".groups", null);
- groups.add("default");
-
- if (groups.size() > 0) {
- for (String group : groups) {
- Set groupPerms = userGroupPermissions.get(group);
- if (groupPerms != null) {
- permsCache.addAll(groupPerms);
- }
- }
- }
-
- userPermissionsCache.put(key.toLowerCase(), permsCache);
- userGroups.put(key.toLowerCase(), new HashSet(groups));
- }
- }
- }
-
- public boolean hasPermission(String player, String permission) {
- int dotPos = permission.lastIndexOf(".");
- if (dotPos > -1) {
- if (hasPermission(player, permission.substring(0, dotPos))) {
- return true;
- }
- }
-
- Set perms = userPermissionsCache.get(player.toLowerCase());
- if (perms == null) {
- return defaultPermissionsCache.contains(permission)
- || defaultPermissionsCache.contains("*");
- }
-
- return perms.contains("*") || perms.contains(permission);
- }
-
- public boolean hasPermission(String worldName, String player, String permission) {
- return hasPermission(player, "worlds." + worldName + "." + permission)
- || hasPermission(player, permission);
- }
-
- public boolean inGroup(String player, String group) {
- Set groups = userGroups.get(player.toLowerCase());
- if (groups == null) {
- return false;
- }
-
- return groups.contains(group);
- }
-
- public String[] getGroups(String player) {
- Set groups = userGroups.get(player.toLowerCase());
- if (groups == null) {
- return new String[0];
- }
-
- return groups.toArray(new String[groups.size()]);
- }
-
- public boolean hasPermission(OfflinePlayer player, String permission) {
- return hasPermission(player.getName(), permission);
- }
-
- public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
- return hasPermission(worldName, player.getName(), permission);
- }
-
- public boolean inGroup(OfflinePlayer player, String group) {
- return inGroup(player.getName(), group);
- }
-
- public String[] getGroups(OfflinePlayer player) {
- return getGroups(player.getName());
- }
-
- public String getDetectionMessage() {
- return "No known permissions plugin detected. Using configuration file for permissions.";
- }
-
-}
+// $Id$
+/*
+ * WorldEdit
+ * Copyright (C) 2010 sk89q and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.sk89q.wepif;
+
+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;
+ private Set defaultPermissionsCache;
+ private Map> userGroups;
+
+ public ConfigurationPermissionsResolver(YAMLProcessor config) {
+ this.config = config;
+ }
+
+ public static YAMLNode generateDefaultPerms(YAMLNode section) {
+ section.setProperty("groups.default.permissions", new String[] {
+ "worldedit.reload",
+ "worldedit.selection",
+ "worlds.creative.worldedit.region"});
+ section.setProperty("groups.admins.permissions", new String[] { "*" });
+ section.setProperty("users.sk89q.permissions", new String[] { "worldedit" });
+ section.setProperty("users.sk89q.groups", new String[] { "admins" });
+ return section;
+ }
+
+ public void load() {
+ userGroups = new HashMap>();
+ userPermissionsCache = new HashMap>();
+ defaultPermissionsCache = new HashSet();
+
+ Map> userGroupPermissions = new HashMap>();
+
+ List groupKeys = config.getStringList("permissions.groups", null);
+
+ if (groupKeys != null) {
+ for (String key : groupKeys) {
+ List permissions =
+ config.getStringList("permissions.groups." + key + ".permissions", null);
+
+ if (permissions.size() > 0) {
+ Set groupPerms = new HashSet(permissions);
+ userGroupPermissions.put(key, groupPerms);
+
+ if (key.equals("default")) {
+ defaultPermissionsCache.addAll(permissions);
+ }
+ }
+ }
+ }
+
+ List userKeys = config.getStringList("permissions.users", null);
+
+ if (userKeys != null) {
+ for (String key : userKeys) {
+ Set permsCache = new HashSet();
+
+ List permissions =
+ config.getStringList("permissions.users." + key + ".permissions", null);
+
+ if (permissions.size() > 0) {
+ permsCache.addAll(permissions);
+ }
+
+ List groups =
+ config.getStringList("permissions.users." + key + ".groups", null);
+ groups.add("default");
+
+ if (groups.size() > 0) {
+ for (String group : groups) {
+ Set groupPerms = userGroupPermissions.get(group);
+ if (groupPerms != null) {
+ permsCache.addAll(groupPerms);
+ }
+ }
+ }
+
+ userPermissionsCache.put(key.toLowerCase(), permsCache);
+ userGroups.put(key.toLowerCase(), new HashSet(groups));
+ }
+ }
+ }
+
+ public boolean hasPermission(String player, String permission) {
+ int dotPos = permission.lastIndexOf(".");
+ if (dotPos > -1) {
+ if (hasPermission(player, permission.substring(0, dotPos))) {
+ return true;
+ }
+ }
+
+ Set perms = userPermissionsCache.get(player.toLowerCase());
+ if (perms == null) {
+ return defaultPermissionsCache.contains(permission)
+ || defaultPermissionsCache.contains("*");
+ }
+
+ return perms.contains("*") || perms.contains(permission);
+ }
+
+ public boolean hasPermission(String worldName, String player, String permission) {
+ return hasPermission(player, "worlds." + worldName + "." + permission)
+ || hasPermission(player, permission);
+ }
+
+ public boolean inGroup(String player, String group) {
+ Set groups = userGroups.get(player.toLowerCase());
+ if (groups == null) {
+ return false;
+ }
+
+ return groups.contains(group);
+ }
+
+ public String[] getGroups(String player) {
+ Set groups = userGroups.get(player.toLowerCase());
+ if (groups == null) {
+ return new String[0];
+ }
+
+ return groups.toArray(new String[groups.size()]);
+ }
+
+ public boolean hasPermission(OfflinePlayer player, String permission) {
+ return hasPermission(player.getName(), permission);
+ }
+
+ public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
+ return hasPermission(worldName, player.getName(), permission);
+ }
+
+ public boolean inGroup(OfflinePlayer player, String group) {
+ return inGroup(player.getName(), group);
+ }
+
+ public String[] getGroups(OfflinePlayer player) {
+ return getGroups(player.getName());
+ }
+
+ public String getDetectionMessage() {
+ return "No known permissions plugin detected. Using configuration file for permissions.";
+ }
+
+}
diff --git a/src/main/java/com/sk89q/wepif/DinnerPermsResolver.java b/src/bukkit/java/com/sk89q/wepif/DinnerPermsResolver.java
similarity index 100%
rename from src/main/java/com/sk89q/wepif/DinnerPermsResolver.java
rename to src/bukkit/java/com/sk89q/wepif/DinnerPermsResolver.java
diff --git a/src/main/java/com/sk89q/wepif/FlatFilePermissionsResolver.java b/src/bukkit/java/com/sk89q/wepif/FlatFilePermissionsResolver.java
similarity index 96%
rename from src/main/java/com/sk89q/wepif/FlatFilePermissionsResolver.java
rename to src/bukkit/java/com/sk89q/wepif/FlatFilePermissionsResolver.java
index aca21f199..7a035bc0b 100644
--- a/src/main/java/com/sk89q/wepif/FlatFilePermissionsResolver.java
+++ b/src/bukkit/java/com/sk89q/wepif/FlatFilePermissionsResolver.java
@@ -1,237 +1,237 @@
-// $Id$
-/*
- * WorldEdit
- * Copyright (C) 2010 sk89q and contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package com.sk89q.wepif;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.HashMap;
-
-import com.sk89q.util.yaml.YAMLProcessor;
-import org.bukkit.OfflinePlayer;
-import org.bukkit.Server;
-
-public class FlatFilePermissionsResolver implements PermissionsResolver {
- private Map> userPermissionsCache;
- private Set defaultPermissionsCache;
- private Map> userGroups;
-
- protected File groupFile;
- protected File userFile;
-
- public static PermissionsResolver factory(Server server, YAMLProcessor config) {
- File groups = new File("perms_groups.txt");
- File users = new File("perms_users.txt");
-
- if (!groups.exists() || !users.exists()) {
- return null;
- }
-
- return new FlatFilePermissionsResolver(groups, users);
- }
-
- public FlatFilePermissionsResolver() {
- this(new File("perms_groups.txt"), new File("perms_users.txt"));
- }
-
- public FlatFilePermissionsResolver(File groupFile, File userFile) {
- this.groupFile = groupFile;
- 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>();
-
- BufferedReader buff = null;
-
- try {
- FileReader input = new FileReader(this.groupFile);
- buff = new BufferedReader(input);
-
- String line;
- while ((line = buff.readLine()) != null) {
- line = line.trim();
-
- // Blank line
- if (line.length() == 0) {
- continue;
- } else if (line.charAt(0) == ';' || line.charAt(0) == '#') {
- continue;
- }
-
- String[] parts = line.split(":");
-
- String key = parts[0];
-
- if (parts.length > 1) {
- String[] perms = parts[1].split(",");
-
- Set groupPerms = new HashSet(Arrays.asList(perms));
- userGroupPermissions.put(key, groupPerms);
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- try {
- if (buff != null) {
- buff.close();
- }
- } catch (IOException e2) {
- }
- }
-
- return userGroupPermissions;
- }
-
- public void load() {
- userGroups = new HashMap>();
- userPermissionsCache = new HashMap>();
- defaultPermissionsCache = new HashSet();
-
- Map> userGroupPermissions = loadGroupPermissions();
-
- if (userGroupPermissions.containsKey("default")) {
- defaultPermissionsCache = userGroupPermissions.get("default");
- }
-
- BufferedReader buff = null;
-
- try {
- FileReader input = new FileReader(this.userFile);
- buff = new BufferedReader(input);
-
- String line;
- while ((line = buff.readLine()) != null) {
- Set permsCache = new HashSet();
-
- line = line.trim();
-
- // Blank line
- if (line.length() == 0) {
- continue;
- } else if (line.charAt(0) == ';' || line.charAt(0) == '#') {
- continue;
- }
-
- String[] parts = line.split(":");
-
- String key = parts[0];
-
- if (parts.length > 1) {
- String[] groups = (parts[1] + ",default").split(",");
- String[] perms = parts.length > 2 ? parts[2].split(",") : new String[0];
-
- permsCache.addAll(Arrays.asList(perms));
-
- for (String group : groups) {
- Set groupPerms = userGroupPermissions.get(group);
- if (groupPerms != null) {
- permsCache.addAll(groupPerms);
- }
- }
-
- userPermissionsCache.put(key.toLowerCase(), permsCache);
- userGroups.put(key.toLowerCase(), new HashSet(Arrays.asList(groups)));
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- try {
- if (buff != null) {
- buff.close();
- }
- } catch (IOException e2) {
- }
- }
- }
-
- public boolean hasPermission(String player, String permission) {
- int dotPos = permission.lastIndexOf(".");
- if (dotPos > -1) {
- if (hasPermission(player, permission.substring(0, dotPos))) {
- return true;
- }
- }
-
- Set perms = userPermissionsCache.get(player.toLowerCase());
- if (perms == null) {
- return defaultPermissionsCache.contains(permission)
- || defaultPermissionsCache.contains("*");
- }
-
- return perms.contains("*") || perms.contains(permission);
- }
-
- public boolean hasPermission(String worldName, String player, String permission) {
- return hasPermission(player, "worlds." + worldName + "." + permission)
- || hasPermission(player, permission);
- }
-
- public boolean inGroup(String player, String group) {
- Set groups = userGroups.get(player.toLowerCase());
- if (groups == null) {
- return false;
- }
-
- return groups.contains(group);
- }
-
- public String[] getGroups(String player) {
- Set groups = userGroups.get(player.toLowerCase());
- if (groups == null) {
- return new String[0];
- }
-
- return groups.toArray(new String[groups.size()]);
- }
-
- public boolean hasPermission(OfflinePlayer player, String permission) {
- return hasPermission(player.getName(), permission);
- }
-
- public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
- return hasPermission(worldName, player.getName(), permission);
- }
-
- public boolean inGroup(OfflinePlayer player, String group) {
- return inGroup(player.getName(), group);
- }
-
- public String[] getGroups(OfflinePlayer player) {
- return getGroups(player.getName());
- }
-
- public String getDetectionMessage() {
- return "perms_groups.txt and perms_users.txt detected! Using flat file permissions.";
- }
-
-}
+// $Id$
+/*
+ * WorldEdit
+ * Copyright (C) 2010 sk89q and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.sk89q.wepif;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.HashMap;
+
+import com.sk89q.util.yaml.YAMLProcessor;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.Server;
+
+public class FlatFilePermissionsResolver implements PermissionsResolver {
+ private Map> userPermissionsCache;
+ private Set defaultPermissionsCache;
+ private Map> userGroups;
+
+ protected File groupFile;
+ protected File userFile;
+
+ public static PermissionsResolver factory(Server server, YAMLProcessor config) {
+ File groups = new File("perms_groups.txt");
+ File users = new File("perms_users.txt");
+
+ if (!groups.exists() || !users.exists()) {
+ return null;
+ }
+
+ return new FlatFilePermissionsResolver(groups, users);
+ }
+
+ public FlatFilePermissionsResolver() {
+ this(new File("perms_groups.txt"), new File("perms_users.txt"));
+ }
+
+ public FlatFilePermissionsResolver(File groupFile, File userFile) {
+ this.groupFile = groupFile;
+ 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>();
+
+ BufferedReader buff = null;
+
+ try {
+ FileReader input = new FileReader(this.groupFile);
+ buff = new BufferedReader(input);
+
+ String line;
+ while ((line = buff.readLine()) != null) {
+ line = line.trim();
+
+ // Blank line
+ if (line.length() == 0) {
+ continue;
+ } else if (line.charAt(0) == ';' || line.charAt(0) == '#') {
+ continue;
+ }
+
+ String[] parts = line.split(":");
+
+ String key = parts[0];
+
+ if (parts.length > 1) {
+ String[] perms = parts[1].split(",");
+
+ Set groupPerms = new HashSet(Arrays.asList(perms));
+ userGroupPermissions.put(key, groupPerms);
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (buff != null) {
+ buff.close();
+ }
+ } catch (IOException e2) {
+ }
+ }
+
+ return userGroupPermissions;
+ }
+
+ public void load() {
+ userGroups = new HashMap>();
+ userPermissionsCache = new HashMap>();
+ defaultPermissionsCache = new HashSet();
+
+ Map> userGroupPermissions = loadGroupPermissions();
+
+ if (userGroupPermissions.containsKey("default")) {
+ defaultPermissionsCache = userGroupPermissions.get("default");
+ }
+
+ BufferedReader buff = null;
+
+ try {
+ FileReader input = new FileReader(this.userFile);
+ buff = new BufferedReader(input);
+
+ String line;
+ while ((line = buff.readLine()) != null) {
+ Set permsCache = new HashSet();
+
+ line = line.trim();
+
+ // Blank line
+ if (line.length() == 0) {
+ continue;
+ } else if (line.charAt(0) == ';' || line.charAt(0) == '#') {
+ continue;
+ }
+
+ String[] parts = line.split(":");
+
+ String key = parts[0];
+
+ if (parts.length > 1) {
+ String[] groups = (parts[1] + ",default").split(",");
+ String[] perms = parts.length > 2 ? parts[2].split(",") : new String[0];
+
+ permsCache.addAll(Arrays.asList(perms));
+
+ for (String group : groups) {
+ Set groupPerms = userGroupPermissions.get(group);
+ if (groupPerms != null) {
+ permsCache.addAll(groupPerms);
+ }
+ }
+
+ userPermissionsCache.put(key.toLowerCase(), permsCache);
+ userGroups.put(key.toLowerCase(), new HashSet(Arrays.asList(groups)));
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (buff != null) {
+ buff.close();
+ }
+ } catch (IOException e2) {
+ }
+ }
+ }
+
+ public boolean hasPermission(String player, String permission) {
+ int dotPos = permission.lastIndexOf(".");
+ if (dotPos > -1) {
+ if (hasPermission(player, permission.substring(0, dotPos))) {
+ return true;
+ }
+ }
+
+ Set perms = userPermissionsCache.get(player.toLowerCase());
+ if (perms == null) {
+ return defaultPermissionsCache.contains(permission)
+ || defaultPermissionsCache.contains("*");
+ }
+
+ return perms.contains("*") || perms.contains(permission);
+ }
+
+ public boolean hasPermission(String worldName, String player, String permission) {
+ return hasPermission(player, "worlds." + worldName + "." + permission)
+ || hasPermission(player, permission);
+ }
+
+ public boolean inGroup(String player, String group) {
+ Set groups = userGroups.get(player.toLowerCase());
+ if (groups == null) {
+ return false;
+ }
+
+ return groups.contains(group);
+ }
+
+ public String[] getGroups(String player) {
+ Set groups = userGroups.get(player.toLowerCase());
+ if (groups == null) {
+ return new String[0];
+ }
+
+ return groups.toArray(new String[groups.size()]);
+ }
+
+ public boolean hasPermission(OfflinePlayer player, String permission) {
+ return hasPermission(player.getName(), permission);
+ }
+
+ public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
+ return hasPermission(worldName, player.getName(), permission);
+ }
+
+ public boolean inGroup(OfflinePlayer player, String group) {
+ return inGroup(player.getName(), group);
+ }
+
+ public String[] getGroups(OfflinePlayer player) {
+ return getGroups(player.getName());
+ }
+
+ public String getDetectionMessage() {
+ return "perms_groups.txt and perms_users.txt detected! Using flat file permissions.";
+ }
+
+}
diff --git a/src/main/java/com/sk89q/wepif/GroupManagerResolver.java b/src/bukkit/java/com/sk89q/wepif/GroupManagerResolver.java
similarity index 100%
rename from src/main/java/com/sk89q/wepif/GroupManagerResolver.java
rename to src/bukkit/java/com/sk89q/wepif/GroupManagerResolver.java
diff --git a/src/main/java/com/sk89q/wepif/NijiPermissionsResolver.java b/src/bukkit/java/com/sk89q/wepif/NijiPermissionsResolver.java
similarity index 97%
rename from src/main/java/com/sk89q/wepif/NijiPermissionsResolver.java
rename to src/bukkit/java/com/sk89q/wepif/NijiPermissionsResolver.java
index 301c2a8ee..16d9662cc 100644
--- a/src/main/java/com/sk89q/wepif/NijiPermissionsResolver.java
+++ b/src/bukkit/java/com/sk89q/wepif/NijiPermissionsResolver.java
@@ -1,161 +1,161 @@
-// $Id$
-/*
- * WorldEdit
- * Copyright (C) 2010 sk89q and contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package com.sk89q.wepif;
-
-import com.sk89q.util.yaml.YAMLProcessor;
-import org.bukkit.Bukkit;
-import org.bukkit.OfflinePlayer;
-import org.bukkit.Server;
-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;
-
-public class NijiPermissionsResolver implements PermissionsResolver {
- private Server server;
- private Permissions api;
-
- public static PermissionsResolver factory(Server server, YAMLProcessor config) {
- PluginManager pluginManager = server.getPluginManager();
- try {
- Class.forName("com.nijikokun.bukkit.Permissions.Permissions");
- } catch (ClassNotFoundException e) {
- return null;
- }
-
- Plugin plugin = pluginManager.getPlugin("Permissions");
-
- // Check if plugin is loaded and has Permissions interface
- if (plugin == null || !(plugin instanceof Permissions)) {
- return null;
- }
-
- // Check for fake permissions
- if (config.getBoolean("ignore-nijiperms-bridges", true) && isFakeNijiPerms(plugin)) {
- return null;
- }
-
- return new NijiPermissionsResolver(server, (Permissions) plugin);
- }
-
- public void load() {
-
- }
-
- public NijiPermissionsResolver(Server server, Permissions plugin) {
- this.server = server;
- this.api = plugin;
- }
-
- @SuppressWarnings("static-access")
- public boolean hasPermission(String name, String permission) {
- try {
- Player player = server.getPlayerExact(name);
- if (player == null) return false;
- try {
- return api.getHandler().has(player, permission);
- } catch (Throwable t) {
- return api.Security.permission(player, permission);
- }
- } catch (Throwable t) {
- t.printStackTrace();
- return false;
- }
- }
-
- public boolean hasPermission(String worldName, String name, String permission) {
- try {
- try {
- return api.getHandler().has(worldName, name, permission);
- } catch (Throwable t) {
- return api.getHandler().has(server.getPlayerExact(name), permission);
- }
- } catch (Throwable t) {
- t.printStackTrace();
- return false;
- }
- }
-
- @SuppressWarnings("static-access")
- public boolean inGroup(String name, String group) {
- try {
- Player player = server.getPlayerExact(name);
- if (player == null) return false;
- try {
- return api.getHandler().inGroup(player.getWorld().getName(), name, group);
- } catch (Throwable t) {
- return api.Security.inGroup(name, group);
- }
- } catch (Throwable t) {
- t.printStackTrace();
- return false;
- }
- }
-
- @SuppressWarnings("static-access")
- public String[] getGroups(String name) {
- try {
- Player player = server.getPlayerExact(name);
- if (player == null) return new String[0];
- String[] groups = null;
- try {
- groups = api.getHandler().getGroups(player.getWorld().getName(), player.getName());
- } catch (Throwable t) {
- String group = api.Security.getGroup(player.getWorld().getName(), player.getName());
- if (group != null) groups = new String[] { group };
- }
- if (groups == null) {
- return new String[0];
- } else {
- return groups;
- }
- } catch (Throwable t) {
- t.printStackTrace();
- return new String[0];
- }
- }
-
- public boolean hasPermission(OfflinePlayer player, String permission) {
- return hasPermission(player.getName(), permission);
- }
-
- public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
- return hasPermission(worldName, player.getName(), permission);
- }
-
- public boolean inGroup(OfflinePlayer player, String group) {
- return inGroup(player.getName(), group);
- }
-
- public String[] getGroups(OfflinePlayer player) {
- return getGroups(player.getName());
- }
-
- public static boolean isFakeNijiPerms(Plugin plugin) {
- PluginCommand permsCommand = Bukkit.getServer().getPluginCommand("permissions");
-
- return permsCommand == null || !(permsCommand.getPlugin().equals(plugin));
- }
-
- public String getDetectionMessage() {
- return "Permissions plugin detected! Using Permissions plugin for permissions.";
- }
-}
+// $Id$
+/*
+ * WorldEdit
+ * Copyright (C) 2010 sk89q and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.sk89q.wepif;
+
+import com.sk89q.util.yaml.YAMLProcessor;
+import org.bukkit.Bukkit;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.Server;
+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;
+
+public class NijiPermissionsResolver implements PermissionsResolver {
+ private Server server;
+ private Permissions api;
+
+ public static PermissionsResolver factory(Server server, YAMLProcessor config) {
+ PluginManager pluginManager = server.getPluginManager();
+ try {
+ Class.forName("com.nijikokun.bukkit.Permissions.Permissions");
+ } catch (ClassNotFoundException e) {
+ return null;
+ }
+
+ Plugin plugin = pluginManager.getPlugin("Permissions");
+
+ // Check if plugin is loaded and has Permissions interface
+ if (plugin == null || !(plugin instanceof Permissions)) {
+ return null;
+ }
+
+ // Check for fake permissions
+ if (config.getBoolean("ignore-nijiperms-bridges", true) && isFakeNijiPerms(plugin)) {
+ return null;
+ }
+
+ return new NijiPermissionsResolver(server, (Permissions) plugin);
+ }
+
+ public void load() {
+
+ }
+
+ public NijiPermissionsResolver(Server server, Permissions plugin) {
+ this.server = server;
+ this.api = plugin;
+ }
+
+ @SuppressWarnings("static-access")
+ public boolean hasPermission(String name, String permission) {
+ try {
+ Player player = server.getPlayerExact(name);
+ if (player == null) return false;
+ try {
+ return api.getHandler().has(player, permission);
+ } catch (Throwable t) {
+ return api.Security.permission(player, permission);
+ }
+ } catch (Throwable t) {
+ t.printStackTrace();
+ return false;
+ }
+ }
+
+ public boolean hasPermission(String worldName, String name, String permission) {
+ try {
+ try {
+ return api.getHandler().has(worldName, name, permission);
+ } catch (Throwable t) {
+ return api.getHandler().has(server.getPlayerExact(name), permission);
+ }
+ } catch (Throwable t) {
+ t.printStackTrace();
+ return false;
+ }
+ }
+
+ @SuppressWarnings("static-access")
+ public boolean inGroup(String name, String group) {
+ try {
+ Player player = server.getPlayerExact(name);
+ if (player == null) return false;
+ try {
+ return api.getHandler().inGroup(player.getWorld().getName(), name, group);
+ } catch (Throwable t) {
+ return api.Security.inGroup(name, group);
+ }
+ } catch (Throwable t) {
+ t.printStackTrace();
+ return false;
+ }
+ }
+
+ @SuppressWarnings("static-access")
+ public String[] getGroups(String name) {
+ try {
+ Player player = server.getPlayerExact(name);
+ if (player == null) return new String[0];
+ String[] groups = null;
+ try {
+ groups = api.getHandler().getGroups(player.getWorld().getName(), player.getName());
+ } catch (Throwable t) {
+ String group = api.Security.getGroup(player.getWorld().getName(), player.getName());
+ if (group != null) groups = new String[] { group };
+ }
+ if (groups == null) {
+ return new String[0];
+ } else {
+ return groups;
+ }
+ } catch (Throwable t) {
+ t.printStackTrace();
+ return new String[0];
+ }
+ }
+
+ public boolean hasPermission(OfflinePlayer player, String permission) {
+ return hasPermission(player.getName(), permission);
+ }
+
+ public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
+ return hasPermission(worldName, player.getName(), permission);
+ }
+
+ public boolean inGroup(OfflinePlayer player, String group) {
+ return inGroup(player.getName(), group);
+ }
+
+ public String[] getGroups(OfflinePlayer player) {
+ return getGroups(player.getName());
+ }
+
+ public static boolean isFakeNijiPerms(Plugin plugin) {
+ PluginCommand permsCommand = Bukkit.getServer().getPluginCommand("permissions");
+
+ return permsCommand == null || !(permsCommand.getPlugin().equals(plugin));
+ }
+
+ public String getDetectionMessage() {
+ return "Permissions plugin detected! Using Permissions plugin for permissions.";
+ }
+}
diff --git a/src/main/java/com/sk89q/wepif/PermissionsExResolver.java b/src/bukkit/java/com/sk89q/wepif/PermissionsExResolver.java
similarity index 100%
rename from src/main/java/com/sk89q/wepif/PermissionsExResolver.java
rename to src/bukkit/java/com/sk89q/wepif/PermissionsExResolver.java
diff --git a/src/main/java/com/sk89q/wepif/PermissionsProvider.java b/src/bukkit/java/com/sk89q/wepif/PermissionsProvider.java
similarity index 97%
rename from src/main/java/com/sk89q/wepif/PermissionsProvider.java
rename to src/bukkit/java/com/sk89q/wepif/PermissionsProvider.java
index 199f1580a..033f0f0e6 100644
--- a/src/main/java/com/sk89q/wepif/PermissionsProvider.java
+++ b/src/bukkit/java/com/sk89q/wepif/PermissionsProvider.java
@@ -1,40 +1,40 @@
-// $Id$
-/*
- * WorldEdit
- * Copyright (C) 2010, 2011 sk89q and contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package com.sk89q.wepif;
-
-import org.bukkit.OfflinePlayer;
-
-public interface PermissionsProvider {
- public boolean hasPermission(String name, String permission);
-
- public boolean hasPermission(String worldName, String name, String permission);
-
- public boolean inGroup(String player, String group);
-
- public String[] getGroups(String player);
-
- public boolean hasPermission(OfflinePlayer player, String permission);
-
- public boolean hasPermission(String worldName, OfflinePlayer player, String permission);
-
- public boolean inGroup(OfflinePlayer player, String group);
-
- public String[] getGroups(OfflinePlayer player);
-}
+// $Id$
+/*
+ * WorldEdit
+ * Copyright (C) 2010, 2011 sk89q and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.sk89q.wepif;
+
+import org.bukkit.OfflinePlayer;
+
+public interface PermissionsProvider {
+ public boolean hasPermission(String name, String permission);
+
+ public boolean hasPermission(String worldName, String name, String permission);
+
+ public boolean inGroup(String player, String group);
+
+ public String[] getGroups(String player);
+
+ public boolean hasPermission(OfflinePlayer player, String permission);
+
+ public boolean hasPermission(String worldName, OfflinePlayer player, String permission);
+
+ public boolean inGroup(OfflinePlayer player, String group);
+
+ public String[] getGroups(OfflinePlayer player);
+}
diff --git a/src/main/java/com/sk89q/wepif/PermissionsResolver.java b/src/bukkit/java/com/sk89q/wepif/PermissionsResolver.java
similarity index 97%
rename from src/main/java/com/sk89q/wepif/PermissionsResolver.java
rename to src/bukkit/java/com/sk89q/wepif/PermissionsResolver.java
index dce444807..e8581a7f9 100644
--- a/src/main/java/com/sk89q/wepif/PermissionsResolver.java
+++ b/src/bukkit/java/com/sk89q/wepif/PermissionsResolver.java
@@ -1,26 +1,26 @@
-// $Id$
-/*
- * WorldEdit
- * Copyright (C) 2010 sk89q and contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package com.sk89q.wepif;
-
-public interface PermissionsResolver extends PermissionsProvider {
- public void load();
-
- public String getDetectionMessage();
-}
+// $Id$
+/*
+ * WorldEdit
+ * Copyright (C) 2010 sk89q and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.sk89q.wepif;
+
+public interface PermissionsResolver extends PermissionsProvider {
+ public void load();
+
+ public String getDetectionMessage();
+}
diff --git a/src/main/java/com/sk89q/wepif/PermissionsResolverManager.java b/src/bukkit/java/com/sk89q/wepif/PermissionsResolverManager.java
similarity index 97%
rename from src/main/java/com/sk89q/wepif/PermissionsResolverManager.java
rename to src/bukkit/java/com/sk89q/wepif/PermissionsResolverManager.java
index f5ae11fb8..3cf80d2fe 100644
--- a/src/main/java/com/sk89q/wepif/PermissionsResolverManager.java
+++ b/src/bukkit/java/com/sk89q/wepif/PermissionsResolverManager.java
@@ -1,298 +1,298 @@
-// $Id$
-/*
- * WorldEdit
- * Copyright (C) 2010 sk89q and contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package com.sk89q.wepif;
-
-import com.sk89q.util.yaml.YAMLFormat;
-import com.sk89q.util.yaml.YAMLProcessor;
-import org.bukkit.OfflinePlayer;
-import org.bukkit.Server;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.server.PluginDisableEvent;
-import org.bukkit.event.server.PluginEnableEvent;
-import org.bukkit.plugin.Plugin;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.logging.Logger;
-
-public class PermissionsResolverManager implements PermissionsResolver {
- private static final String CONFIG_HEADER = "#\r\n" +
- "# WEPIF Configuration File\r\n" +
- "#\r\n" +
- "# This file handles permissions configuration for every plugin using WEPIF\r\n" +
- "#\r\n" +
- "# About editing this file:\r\n" +
- "# - DO NOT USE TABS. You MUST use spaces or Bukkit will complain. If\r\n" +
- "# you use an editor like Notepad++ (recommended for Windows users), you\r\n" +
- "# must configure it to \"replace tabs with spaces.\" In Notepad++, this can\r\n" +
- "# be changed in Settings > Preferences > Language Menu.\r\n" +
- "# - Don't get rid of the indents. They are indented so some entries are\r\n" +
- "# in categories (like \"enforce-single-session\" is in the \"protection\"\r\n" +
- "# category.\r\n" +
- "# - If you want to check the format of this file before putting it\r\n" +
- "# into WEPIF, paste it into http://yaml-online-parser.appspot.com/\r\n" +
- "# and see if it gives \"ERROR:\".\r\n" +
- "# - Lines starting with # are comments and so they are ignored.\r\n" +
- "#\r\n" +
- "# About Configuration Permissions\r\n" +
- "# - See http://wiki.sk89q.com/wiki/WorldEdit/Permissions/Bukkit\r\n" +
- "# - Now with multiworld support (see example)\r\n" +
- "\r\n";
-
- private static PermissionsResolverManager instance;
-
- public static void initialize(Plugin plugin) {
- if (!isInitialized()) {
- instance = new PermissionsResolverManager(plugin);
- }
- }
-
- public static boolean isInitialized() {
- return instance != null;
- }
-
- public static PermissionsResolverManager getInstance() {
- if (!isInitialized()) {
- throw new WEPIFRuntimeException("WEPIF has not yet been initialized!");
- }
- return instance;
- }
-
- private Server server;
- private PermissionsResolver permissionResolver;
- private YAMLProcessor config;
- private Logger logger = Logger.getLogger(getClass().getCanonicalName());
- private List> enabledResolvers = new ArrayList>();
-
- @SuppressWarnings("unchecked")
- protected Class extends PermissionsResolver>[] availableResolvers = new Class[] {
- PluginPermissionsResolver.class,
- PermissionsExResolver.class,
- bPermissionsResolver.class,
- GroupManagerResolver.class,
- NijiPermissionsResolver.class,
- DinnerPermsResolver.class,
- FlatFilePermissionsResolver.class
- };
-
- protected PermissionsResolverManager(Plugin plugin) {
- this.server = plugin.getServer();
- (new ServerListener()).register(plugin); // Register the events
-
- loadConfig(new File("wepif.yml"));
- findResolver();
- }
-
- public void findResolver() {
- for (Class extends PermissionsResolver> resolverClass : enabledResolvers) {
- try {
- Method factoryMethod = resolverClass.getMethod("factory", Server.class, YAMLProcessor.class);
-
- this.permissionResolver = (PermissionsResolver) factoryMethod.invoke(null, this.server, this.config);
-
- if (this.permissionResolver != null) {
- break;
- }
- } catch (Throwable e) {
- logger.warning("Error in factory method for " + resolverClass.getSimpleName() + ": " + e);
- e.printStackTrace();
- continue;
- }
- }
- if (permissionResolver == null) {
- permissionResolver = new ConfigurationPermissionsResolver(config);
- }
- permissionResolver.load();
- logger.info("WEPIF: " + permissionResolver.getDetectionMessage());
- }
-
- public void setPluginPermissionsResolver(Plugin plugin) {
- if (!(plugin instanceof PermissionsProvider)) {
- return;
- }
-
- permissionResolver = new PluginPermissionsResolver((PermissionsProvider) plugin, plugin);
- logger.info("WEPIF: " + permissionResolver.getDetectionMessage());
- }
-
- public void load() {
- findResolver();
- }
-
- public boolean hasPermission(String name, String permission) {
- return permissionResolver.hasPermission(name, permission);
- }
-
- public boolean hasPermission(String worldName, String name, String permission) {
- return permissionResolver.hasPermission(worldName, name, permission);
- }
-
- public boolean inGroup(String player, String group) {
- return permissionResolver.inGroup(player, group);
- }
-
- public String[] getGroups(String player) {
- return permissionResolver.getGroups(player);
- }
-
- public boolean hasPermission(OfflinePlayer player, String permission) {
- return permissionResolver.hasPermission(player, permission);
- }
-
- public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
- return permissionResolver.hasPermission(worldName, player, permission);
- }
-
- public boolean inGroup(OfflinePlayer player, String group) {
- return permissionResolver.inGroup(player, group);
- }
-
- public String[] getGroups(OfflinePlayer player) {
- return permissionResolver.getGroups(player);
- }
-
- public String getDetectionMessage() {
- return "Using WEPIF for permissions";
- }
-
- private boolean loadConfig(File file) {
- boolean isUpdated = false;
- if (!file.exists()) {
- try {
- file.createNewFile();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- config = new YAMLProcessor(file, false, YAMLFormat.EXTENDED);
- try {
- config.load();
- } catch (IOException e) {
- logger.severe("Error loading WEPIF Config: " + e);
- e.printStackTrace();
- }
- List keys = config.getKeys(null);
- config.setHeader(CONFIG_HEADER);
-
- if (!keys.contains("ignore-nijiperms-bridges")) {
- config.setProperty("ignore-nijiperms-bridges", true);
- isUpdated = true;
- }
-
- if (!keys.contains("resolvers")) {
- //List resolverKeys = config.getKeys("resolvers");
- List resolvers = new ArrayList();
- for (Class> clazz : availableResolvers) {
- resolvers.add(clazz.getSimpleName());
- }
- enabledResolvers.addAll(Arrays.asList(availableResolvers));
- config.setProperty("resolvers.enabled", resolvers);
- isUpdated = true;
- } else {
- 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();
- Class> next = null;
- try {
- next = Class.forName(getClass().getPackage().getName() + "." + nextName);
- } catch (ClassNotFoundException e) {}
-
- if (next == null || !PermissionsResolver.class.isAssignableFrom(next)) {
- logger.warning("WEPIF: Invalid or unknown class found in enabled resolvers: "
- + nextName + ". Moving to disabled resolvers list.");
- i.remove();
- disabledResolvers.add(nextName);
- isUpdated = true;
- continue;
- }
- enabledResolvers.add(next.asSubclass(PermissionsResolver.class));
- }
-
- for (Class> clazz : availableResolvers) {
- if (!stagedEnabled.contains(clazz.getSimpleName()) &&
- !disabledResolvers.contains(clazz.getSimpleName())) {
- disabledResolvers.add(clazz.getSimpleName());
- logger.info("New permissions resolver: "
- + clazz.getSimpleName() + " detected. " +
- "Added to disabled resolvers list.");
- isUpdated = true;
- }
- }
- config.setProperty("resolvers.disabled", disabledResolvers);
- config.setProperty("resolvers.enabled", stagedEnabled);
- }
-
- if (keys.contains("dinner-perms") || keys.contains("dinnerperms")) {
- config.removeProperty("dinner-perms");
- config.removeProperty("dinnerperms");
- isUpdated = true;
- }
- if (!keys.contains("permissions")) {
- ConfigurationPermissionsResolver.generateDefaultPerms(
- config.addNode("permissions"));
- isUpdated = true;
- }
- if (isUpdated) {
- logger.info("WEPIF: Updated config file");
- config.save();
- }
- return isUpdated;
- }
-
- public static class MissingPluginException extends Exception {
- private static final long serialVersionUID = 7044832912491608706L;
- }
-
- class ServerListener implements org.bukkit.event.Listener {
- @EventHandler
- public void onPluginEnable(PluginEnableEvent event) {
- Plugin plugin = event.getPlugin();
- String name = plugin.getDescription().getName();
- if (plugin instanceof PermissionsProvider) {
- setPluginPermissionsResolver(plugin);
- } else if ("permissions".equalsIgnoreCase(name) || "permissionsex".equalsIgnoreCase(name)
- || "bpermissions".equalsIgnoreCase(name) || "groupmanager".equalsIgnoreCase(name)) {
- load();
- }
- }
-
- @EventHandler
- public void onPluginDisable(PluginDisableEvent event) {
- String name = event.getPlugin().getDescription().getName();
-
- if (event.getPlugin() instanceof PermissionsProvider
- || "permissions".equalsIgnoreCase(name) || "permissionsex".equalsIgnoreCase(name)
- || "bpermissions".equalsIgnoreCase(name) || "groupmanager".equalsIgnoreCase(name)) {
- load();
- }
- }
-
- void register(Plugin plugin) {
- plugin.getServer().getPluginManager().registerEvents(this, plugin);
- }
- }
-
-}
+// $Id$
+/*
+ * WorldEdit
+ * Copyright (C) 2010 sk89q and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.sk89q.wepif;
+
+import com.sk89q.util.yaml.YAMLFormat;
+import com.sk89q.util.yaml.YAMLProcessor;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.Server;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.server.PluginDisableEvent;
+import org.bukkit.event.server.PluginEnableEvent;
+import org.bukkit.plugin.Plugin;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.logging.Logger;
+
+public class PermissionsResolverManager implements PermissionsResolver {
+ private static final String CONFIG_HEADER = "#\r\n" +
+ "# WEPIF Configuration File\r\n" +
+ "#\r\n" +
+ "# This file handles permissions configuration for every plugin using WEPIF\r\n" +
+ "#\r\n" +
+ "# About editing this file:\r\n" +
+ "# - DO NOT USE TABS. You MUST use spaces or Bukkit will complain. If\r\n" +
+ "# you use an editor like Notepad++ (recommended for Windows users), you\r\n" +
+ "# must configure it to \"replace tabs with spaces.\" In Notepad++, this can\r\n" +
+ "# be changed in Settings > Preferences > Language Menu.\r\n" +
+ "# - Don't get rid of the indents. They are indented so some entries are\r\n" +
+ "# in categories (like \"enforce-single-session\" is in the \"protection\"\r\n" +
+ "# category.\r\n" +
+ "# - If you want to check the format of this file before putting it\r\n" +
+ "# into WEPIF, paste it into http://yaml-online-parser.appspot.com/\r\n" +
+ "# and see if it gives \"ERROR:\".\r\n" +
+ "# - Lines starting with # are comments and so they are ignored.\r\n" +
+ "#\r\n" +
+ "# About Configuration Permissions\r\n" +
+ "# - See http://wiki.sk89q.com/wiki/WorldEdit/Permissions/Bukkit\r\n" +
+ "# - Now with multiworld support (see example)\r\n" +
+ "\r\n";
+
+ private static PermissionsResolverManager instance;
+
+ public static void initialize(Plugin plugin) {
+ if (!isInitialized()) {
+ instance = new PermissionsResolverManager(plugin);
+ }
+ }
+
+ public static boolean isInitialized() {
+ return instance != null;
+ }
+
+ public static PermissionsResolverManager getInstance() {
+ if (!isInitialized()) {
+ throw new WEPIFRuntimeException("WEPIF has not yet been initialized!");
+ }
+ return instance;
+ }
+
+ private Server server;
+ private PermissionsResolver permissionResolver;
+ private YAMLProcessor config;
+ private Logger logger = Logger.getLogger(getClass().getCanonicalName());
+ private List> enabledResolvers = new ArrayList>();
+
+ @SuppressWarnings("unchecked")
+ protected Class extends PermissionsResolver>[] availableResolvers = new Class[] {
+ PluginPermissionsResolver.class,
+ PermissionsExResolver.class,
+ bPermissionsResolver.class,
+ GroupManagerResolver.class,
+ NijiPermissionsResolver.class,
+ DinnerPermsResolver.class,
+ FlatFilePermissionsResolver.class
+ };
+
+ protected PermissionsResolverManager(Plugin plugin) {
+ this.server = plugin.getServer();
+ (new ServerListener()).register(plugin); // Register the events
+
+ loadConfig(new File("wepif.yml"));
+ findResolver();
+ }
+
+ public void findResolver() {
+ for (Class extends PermissionsResolver> resolverClass : enabledResolvers) {
+ try {
+ Method factoryMethod = resolverClass.getMethod("factory", Server.class, YAMLProcessor.class);
+
+ this.permissionResolver = (PermissionsResolver) factoryMethod.invoke(null, this.server, this.config);
+
+ if (this.permissionResolver != null) {
+ break;
+ }
+ } catch (Throwable e) {
+ logger.warning("Error in factory method for " + resolverClass.getSimpleName() + ": " + e);
+ e.printStackTrace();
+ continue;
+ }
+ }
+ if (permissionResolver == null) {
+ permissionResolver = new ConfigurationPermissionsResolver(config);
+ }
+ permissionResolver.load();
+ logger.info("WEPIF: " + permissionResolver.getDetectionMessage());
+ }
+
+ public void setPluginPermissionsResolver(Plugin plugin) {
+ if (!(plugin instanceof PermissionsProvider)) {
+ return;
+ }
+
+ permissionResolver = new PluginPermissionsResolver((PermissionsProvider) plugin, plugin);
+ logger.info("WEPIF: " + permissionResolver.getDetectionMessage());
+ }
+
+ public void load() {
+ findResolver();
+ }
+
+ public boolean hasPermission(String name, String permission) {
+ return permissionResolver.hasPermission(name, permission);
+ }
+
+ public boolean hasPermission(String worldName, String name, String permission) {
+ return permissionResolver.hasPermission(worldName, name, permission);
+ }
+
+ public boolean inGroup(String player, String group) {
+ return permissionResolver.inGroup(player, group);
+ }
+
+ public String[] getGroups(String player) {
+ return permissionResolver.getGroups(player);
+ }
+
+ public boolean hasPermission(OfflinePlayer player, String permission) {
+ return permissionResolver.hasPermission(player, permission);
+ }
+
+ public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
+ return permissionResolver.hasPermission(worldName, player, permission);
+ }
+
+ public boolean inGroup(OfflinePlayer player, String group) {
+ return permissionResolver.inGroup(player, group);
+ }
+
+ public String[] getGroups(OfflinePlayer player) {
+ return permissionResolver.getGroups(player);
+ }
+
+ public String getDetectionMessage() {
+ return "Using WEPIF for permissions";
+ }
+
+ private boolean loadConfig(File file) {
+ boolean isUpdated = false;
+ if (!file.exists()) {
+ try {
+ file.createNewFile();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ config = new YAMLProcessor(file, false, YAMLFormat.EXTENDED);
+ try {
+ config.load();
+ } catch (IOException e) {
+ logger.severe("Error loading WEPIF Config: " + e);
+ e.printStackTrace();
+ }
+ List keys = config.getKeys(null);
+ config.setHeader(CONFIG_HEADER);
+
+ if (!keys.contains("ignore-nijiperms-bridges")) {
+ config.setProperty("ignore-nijiperms-bridges", true);
+ isUpdated = true;
+ }
+
+ if (!keys.contains("resolvers")) {
+ //List resolverKeys = config.getKeys("resolvers");
+ List resolvers = new ArrayList();
+ for (Class> clazz : availableResolvers) {
+ resolvers.add(clazz.getSimpleName());
+ }
+ enabledResolvers.addAll(Arrays.asList(availableResolvers));
+ config.setProperty("resolvers.enabled", resolvers);
+ isUpdated = true;
+ } else {
+ 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();
+ Class> next = null;
+ try {
+ next = Class.forName(getClass().getPackage().getName() + "." + nextName);
+ } catch (ClassNotFoundException e) {}
+
+ if (next == null || !PermissionsResolver.class.isAssignableFrom(next)) {
+ logger.warning("WEPIF: Invalid or unknown class found in enabled resolvers: "
+ + nextName + ". Moving to disabled resolvers list.");
+ i.remove();
+ disabledResolvers.add(nextName);
+ isUpdated = true;
+ continue;
+ }
+ enabledResolvers.add(next.asSubclass(PermissionsResolver.class));
+ }
+
+ for (Class> clazz : availableResolvers) {
+ if (!stagedEnabled.contains(clazz.getSimpleName()) &&
+ !disabledResolvers.contains(clazz.getSimpleName())) {
+ disabledResolvers.add(clazz.getSimpleName());
+ logger.info("New permissions resolver: "
+ + clazz.getSimpleName() + " detected. " +
+ "Added to disabled resolvers list.");
+ isUpdated = true;
+ }
+ }
+ config.setProperty("resolvers.disabled", disabledResolvers);
+ config.setProperty("resolvers.enabled", stagedEnabled);
+ }
+
+ if (keys.contains("dinner-perms") || keys.contains("dinnerperms")) {
+ config.removeProperty("dinner-perms");
+ config.removeProperty("dinnerperms");
+ isUpdated = true;
+ }
+ if (!keys.contains("permissions")) {
+ ConfigurationPermissionsResolver.generateDefaultPerms(
+ config.addNode("permissions"));
+ isUpdated = true;
+ }
+ if (isUpdated) {
+ logger.info("WEPIF: Updated config file");
+ config.save();
+ }
+ return isUpdated;
+ }
+
+ public static class MissingPluginException extends Exception {
+ private static final long serialVersionUID = 7044832912491608706L;
+ }
+
+ class ServerListener implements org.bukkit.event.Listener {
+ @EventHandler
+ public void onPluginEnable(PluginEnableEvent event) {
+ Plugin plugin = event.getPlugin();
+ String name = plugin.getDescription().getName();
+ if (plugin instanceof PermissionsProvider) {
+ setPluginPermissionsResolver(plugin);
+ } else if ("permissions".equalsIgnoreCase(name) || "permissionsex".equalsIgnoreCase(name)
+ || "bpermissions".equalsIgnoreCase(name) || "groupmanager".equalsIgnoreCase(name)) {
+ load();
+ }
+ }
+
+ @EventHandler
+ public void onPluginDisable(PluginDisableEvent event) {
+ String name = event.getPlugin().getDescription().getName();
+
+ if (event.getPlugin() instanceof PermissionsProvider
+ || "permissions".equalsIgnoreCase(name) || "permissionsex".equalsIgnoreCase(name)
+ || "bpermissions".equalsIgnoreCase(name) || "groupmanager".equalsIgnoreCase(name)) {
+ load();
+ }
+ }
+
+ void register(Plugin plugin) {
+ plugin.getServer().getPluginManager().registerEvents(this, plugin);
+ }
+ }
+
+}
diff --git a/src/main/java/com/sk89q/wepif/PluginPermissionsResolver.java b/src/bukkit/java/com/sk89q/wepif/PluginPermissionsResolver.java
similarity index 97%
rename from src/main/java/com/sk89q/wepif/PluginPermissionsResolver.java
rename to src/bukkit/java/com/sk89q/wepif/PluginPermissionsResolver.java
index 18e790b7b..2f3541380 100644
--- a/src/main/java/com/sk89q/wepif/PluginPermissionsResolver.java
+++ b/src/bukkit/java/com/sk89q/wepif/PluginPermissionsResolver.java
@@ -1,95 +1,95 @@
-// $Id$
-/*
- * WorldEdit
- * Copyright (C) 2010, 2011 sk89q and contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package com.sk89q.wepif;
-
-import com.sk89q.util.yaml.YAMLProcessor;
-import org.bukkit.OfflinePlayer;
-import org.bukkit.Server;
-import org.bukkit.plugin.Plugin;
-import org.bukkit.plugin.RegisteredServiceProvider;
-
-public class PluginPermissionsResolver implements PermissionsResolver {
-
- protected PermissionsProvider resolver;
- protected Plugin plugin;
-
- public static PermissionsResolver factory(Server server, YAMLProcessor config) {
- // Looking for service
- RegisteredServiceProvider serviceProvider = server.getServicesManager().getRegistration(PermissionsProvider.class);
-
- if (serviceProvider != null) {
- return new PluginPermissionsResolver(serviceProvider.getProvider(), serviceProvider.getPlugin());
- }
-
- // Looking for plugin
- for (Plugin plugin : server.getPluginManager().getPlugins()) {
- if (plugin instanceof PermissionsProvider) {
- return new PluginPermissionsResolver((PermissionsProvider) plugin, plugin);
- }
- }
-
- return null;
- }
-
- public PluginPermissionsResolver(PermissionsProvider resolver, Plugin permissionsPlugin) {
- this.resolver = resolver;
- this.plugin = permissionsPlugin;
- }
-
- public void load() {
- }
-
- public boolean hasPermission(String name, String permission) {
- return resolver.hasPermission(name, permission);
- }
-
- public boolean hasPermission(String worldName, String name, String permission) {
- return resolver.hasPermission(worldName, name, permission);
- }
-
- public boolean inGroup(String player, String group) {
- return resolver.inGroup(player, group);
- }
-
- public String[] getGroups(String player) {
- return resolver.getGroups(player);
- }
-
- public boolean hasPermission(OfflinePlayer player, String permission) {
- return resolver.hasPermission(player, permission);
- }
-
- public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
- return resolver.hasPermission(worldName, player, permission);
- }
-
- public boolean inGroup(OfflinePlayer player, String group) {
- return resolver.inGroup(player, group);
- }
-
- public String[] getGroups(OfflinePlayer player) {
- return resolver.getGroups(player);
- }
-
- public String getDetectionMessage() {
- return "Using plugin '" + this.plugin.getDescription().getName() + "' for permissions.";
- }
-
-}
+// $Id$
+/*
+ * WorldEdit
+ * Copyright (C) 2010, 2011 sk89q and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.sk89q.wepif;
+
+import com.sk89q.util.yaml.YAMLProcessor;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.Server;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.RegisteredServiceProvider;
+
+public class PluginPermissionsResolver implements PermissionsResolver {
+
+ protected PermissionsProvider resolver;
+ protected Plugin plugin;
+
+ public static PermissionsResolver factory(Server server, YAMLProcessor config) {
+ // Looking for service
+ RegisteredServiceProvider serviceProvider = server.getServicesManager().getRegistration(PermissionsProvider.class);
+
+ if (serviceProvider != null) {
+ return new PluginPermissionsResolver(serviceProvider.getProvider(), serviceProvider.getPlugin());
+ }
+
+ // Looking for plugin
+ for (Plugin plugin : server.getPluginManager().getPlugins()) {
+ if (plugin instanceof PermissionsProvider) {
+ return new PluginPermissionsResolver((PermissionsProvider) plugin, plugin);
+ }
+ }
+
+ return null;
+ }
+
+ public PluginPermissionsResolver(PermissionsProvider resolver, Plugin permissionsPlugin) {
+ this.resolver = resolver;
+ this.plugin = permissionsPlugin;
+ }
+
+ public void load() {
+ }
+
+ public boolean hasPermission(String name, String permission) {
+ return resolver.hasPermission(name, permission);
+ }
+
+ public boolean hasPermission(String worldName, String name, String permission) {
+ return resolver.hasPermission(worldName, name, permission);
+ }
+
+ public boolean inGroup(String player, String group) {
+ return resolver.inGroup(player, group);
+ }
+
+ public String[] getGroups(String player) {
+ return resolver.getGroups(player);
+ }
+
+ public boolean hasPermission(OfflinePlayer player, String permission) {
+ return resolver.hasPermission(player, permission);
+ }
+
+ public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
+ return resolver.hasPermission(worldName, player, permission);
+ }
+
+ public boolean inGroup(OfflinePlayer player, String group) {
+ return resolver.inGroup(player, group);
+ }
+
+ public String[] getGroups(OfflinePlayer player) {
+ return resolver.getGroups(player);
+ }
+
+ public String getDetectionMessage() {
+ return "Using plugin '" + this.plugin.getDescription().getName() + "' for permissions.";
+ }
+
+}
diff --git a/src/main/java/com/sk89q/wepif/WEPIFRuntimeException.java b/src/bukkit/java/com/sk89q/wepif/WEPIFRuntimeException.java
similarity index 97%
rename from src/main/java/com/sk89q/wepif/WEPIFRuntimeException.java
rename to src/bukkit/java/com/sk89q/wepif/WEPIFRuntimeException.java
index e99f03875..04e381eac 100644
--- a/src/main/java/com/sk89q/wepif/WEPIFRuntimeException.java
+++ b/src/bukkit/java/com/sk89q/wepif/WEPIFRuntimeException.java
@@ -1,31 +1,31 @@
-// $Id$
-/*
- * WorldEdit
- * Copyright (C) 2010 sk89q and contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package com.sk89q.wepif;
-
-/**
- * @author zml2008
- */
-public class WEPIFRuntimeException extends RuntimeException {
- private static final long serialVersionUID = 5092745960439109699L;
-
- public WEPIFRuntimeException(String message) {
- super(message);
- }
-}
+// $Id$
+/*
+ * WorldEdit
+ * Copyright (C) 2010 sk89q and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.sk89q.wepif;
+
+/**
+ * @author zml2008
+ */
+public class WEPIFRuntimeException extends RuntimeException {
+ private static final long serialVersionUID = 5092745960439109699L;
+
+ public WEPIFRuntimeException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/com/sk89q/wepif/bPermissionsResolver.java b/src/bukkit/java/com/sk89q/wepif/bPermissionsResolver.java
similarity index 100%
rename from src/main/java/com/sk89q/wepif/bPermissionsResolver.java
rename to src/bukkit/java/com/sk89q/wepif/bPermissionsResolver.java
diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitBiomeType.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitBiomeType.java
similarity index 100%
rename from src/main/java/com/sk89q/worldedit/bukkit/BukkitBiomeType.java
rename to src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitBiomeType.java
diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitBiomeTypes.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitBiomeTypes.java
similarity index 100%
rename from src/main/java/com/sk89q/worldedit/bukkit/BukkitBiomeTypes.java
rename to src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitBiomeTypes.java
diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java
similarity index 95%
rename from src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java
rename to src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java
index 5747a4607..2b6728be4 100644
--- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java
+++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java
@@ -1,134 +1,134 @@
-// $Id$
-/*
- * WorldEdit
- * Copyright (C) 2010 sk89q and contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
-*/
-
-package com.sk89q.worldedit.bukkit;
-
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-import com.sk89q.worldedit.LocalPlayer;
-import com.sk89q.worldedit.LocalWorld;
-import com.sk89q.worldedit.PlayerNeededException;
-import com.sk89q.worldedit.ServerInterface;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.WorldVector;
-import com.sk89q.worldedit.bags.BlockBag;
-
-public class BukkitCommandSender extends LocalPlayer {
- private CommandSender sender;
- private WorldEditPlugin plugin;
-
- public BukkitCommandSender(WorldEditPlugin plugin, ServerInterface server, CommandSender sender) {
- super(server);
- this.plugin = plugin;
- this.sender = sender;
- }
-
- @Override
- public String getName() {
- return sender.getName();
- }
-
- @Override
- public void printRaw(String msg) {
- for (String part : msg.split("\n")) {
- sender.sendMessage(part);
- }
- }
-
- @Override
- public void print(String msg) {
- for (String part : msg.split("\n")) {
- sender.sendMessage("\u00A7d" + part);
- }
- }
-
- @Override
- public void printDebug(String msg) {
- for (String part : msg.split("\n")) {
- sender.sendMessage("\u00A77" + part);
- }
- }
-
- @Override
- public void printError(String msg) {
- for (String part : msg.split("\n")) {
- sender.sendMessage("\u00A7c" + part);
- }
- }
-
- @Override
- public String[] getGroups() {
- return new String[0];
- }
-
- @Override
- public boolean hasPermission(String perm) {
- if (!plugin.getLocalConfiguration().noOpPermissions && sender.isOp()) {
- return true;
- }
-
- return plugin.getPermissionsResolver().hasPermission(null, sender.getName(), perm);
- }
-
- @Override
- public boolean isPlayer() {
- return sender instanceof Player;
- }
-
- @Override
- public int getItemInHand() {
- throw new PlayerNeededException();
- }
-
- @Override
- public WorldVector getPosition() {
- throw new PlayerNeededException();
- }
-
- @Override
- public LocalWorld getWorld() {
- throw new PlayerNeededException();
- }
-
- @Override
- public double getPitch() {
- throw new PlayerNeededException();
- }
-
- @Override
- public double getYaw() {
- throw new PlayerNeededException();
- }
-
- @Override
- public void giveItem(int type, int amt) {
- throw new PlayerNeededException();
- }
-
- @Override
- public void setPosition(Vector pos, float pitch, float yaw) {
- throw new PlayerNeededException();
- }
-
- @Override
- public BlockBag getInventoryBlockBag() {
- throw new PlayerNeededException();
- }
-}
+// $Id$
+/*
+ * WorldEdit
+ * Copyright (C) 2010 sk89q and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+*/
+
+package com.sk89q.worldedit.bukkit;
+
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import com.sk89q.worldedit.LocalPlayer;
+import com.sk89q.worldedit.LocalWorld;
+import com.sk89q.worldedit.PlayerNeededException;
+import com.sk89q.worldedit.ServerInterface;
+import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.WorldVector;
+import com.sk89q.worldedit.extent.inventory.BlockBag;
+
+public class BukkitCommandSender extends LocalPlayer {
+ private CommandSender sender;
+ private WorldEditPlugin plugin;
+
+ public BukkitCommandSender(WorldEditPlugin plugin, ServerInterface server, CommandSender sender) {
+ super(server);
+ this.plugin = plugin;
+ this.sender = sender;
+ }
+
+ @Override
+ public String getName() {
+ return sender.getName();
+ }
+
+ @Override
+ public void printRaw(String msg) {
+ for (String part : msg.split("\n")) {
+ sender.sendMessage(part);
+ }
+ }
+
+ @Override
+ public void print(String msg) {
+ for (String part : msg.split("\n")) {
+ sender.sendMessage("\u00A7d" + part);
+ }
+ }
+
+ @Override
+ public void printDebug(String msg) {
+ for (String part : msg.split("\n")) {
+ sender.sendMessage("\u00A77" + part);
+ }
+ }
+
+ @Override
+ public void printError(String msg) {
+ for (String part : msg.split("\n")) {
+ sender.sendMessage("\u00A7c" + part);
+ }
+ }
+
+ @Override
+ public String[] getGroups() {
+ return new String[0];
+ }
+
+ @Override
+ public boolean hasPermission(String perm) {
+ if (!plugin.getLocalConfiguration().noOpPermissions && sender.isOp()) {
+ return true;
+ }
+
+ return plugin.getPermissionsResolver().hasPermission(null, sender.getName(), perm);
+ }
+
+ @Override
+ public boolean isPlayer() {
+ return sender instanceof Player;
+ }
+
+ @Override
+ public int getItemInHand() {
+ throw new PlayerNeededException();
+ }
+
+ @Override
+ public WorldVector getPosition() {
+ throw new PlayerNeededException();
+ }
+
+ @Override
+ public LocalWorld getWorld() {
+ throw new PlayerNeededException();
+ }
+
+ @Override
+ public double getPitch() {
+ throw new PlayerNeededException();
+ }
+
+ @Override
+ public double getYaw() {
+ throw new PlayerNeededException();
+ }
+
+ @Override
+ public void giveItem(int type, int amt) {
+ throw new PlayerNeededException();
+ }
+
+ @Override
+ public void setPosition(Vector pos, float pitch, float yaw) {
+ throw new PlayerNeededException();
+ }
+
+ @Override
+ public BlockBag getInventoryBlockBag() {
+ throw new PlayerNeededException();
+ }
+}
diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitConfiguration.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitConfiguration.java
similarity index 100%
rename from src/main/java/com/sk89q/worldedit/bukkit/BukkitConfiguration.java
rename to src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitConfiguration.java
diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java
similarity index 95%
rename from src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java
rename to src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java
index 7374105e7..8cb16e8b1 100644
--- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java
+++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java
@@ -1,171 +1,171 @@
-// $Id$
-/*
- * WorldEdit
- * Copyright (C) 2010 sk89q and contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
-*/
-
-package com.sk89q.worldedit.bukkit;
-
-import com.sk89q.worldedit.WorldEditException;
-import com.sk89q.worldedit.blocks.BaseBlock;
-import org.bukkit.GameMode;
-import org.bukkit.Location;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.ItemStack;
-
-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.WorldVector;
-import com.sk89q.worldedit.bags.BlockBag;
-import com.sk89q.worldedit.cui.CUIEvent;
-
-public class BukkitPlayer extends LocalPlayer {
- private Player player;
- private WorldEditPlugin plugin;
-
- public BukkitPlayer(WorldEditPlugin plugin, ServerInterface server, Player player) {
- super(server);
- this.plugin = plugin;
- this.player = player;
- }
-
- @Override
- public int getItemInHand() {
- ItemStack itemStack = player.getItemInHand();
- return itemStack != null ? itemStack.getTypeId() : 0;
- }
-
- public BaseBlock getBlockInHand() throws WorldEditException {
- ItemStack itemStack = player.getItemInHand();
- return BukkitUtil.toBlock(getWorld(), itemStack);
- }
-
- @Override
- public String getName() {
- return player.getName();
- }
-
- @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));
- }
-
- @Override
- public void printRaw(String msg) {
- for (String part : msg.split("\n")) {
- player.sendMessage(part);
- }
- }
-
- @Override
- public void print(String msg) {
- for (String part : msg.split("\n")) {
- player.sendMessage("\u00A7d" + part);
- }
- }
-
- @Override
- public void printDebug(String msg) {
- for (String part : msg.split("\n")) {
- player.sendMessage("\u00A77" + part);
- }
- }
-
- @Override
- public void printError(String msg) {
- for (String part : msg.split("\n")) {
- player.sendMessage("\u00A7c" + part);
- }
- }
-
- @Override
- public void setPosition(Vector pos, float pitch, float yaw) {
- player.teleport(new Location(player.getWorld(), pos.getX(), pos.getY(),
- pos.getZ(), yaw, pitch));
- }
-
- @Override
- public String[] getGroups() {
- return plugin.getPermissionsResolver().getGroups(player);
- }
-
- @Override
- public BlockBag getInventoryBlockBag() {
- return new BukkitPlayerBlockBag(player);
- }
-
- @Override
- public boolean hasPermission(String perm) {
- return (!plugin.getLocalConfiguration().noOpPermissions && player.isOp())
- || plugin.getPermissionsResolver().hasPermission(
- player.getWorld().getName(), player, perm);
- }
-
- @Override
- public LocalWorld getWorld() {
- return BukkitUtil.getLocalWorld(player.getWorld());
- }
-
- @Override
- public void dispatchCUIEvent(CUIEvent event) {
- String[] params = event.getParameters();
- String send = event.getTypeId();
- if (params.length > 0) {
- send = send + "|" + StringUtil.joinString(params, "|");
- }
- player.sendPluginMessage(plugin, WorldEditPlugin.CUI_PLUGIN_CHANNEL, send.getBytes(CUIChannelListener.UTF_8_CHARSET));
- }
-
- public Player getPlayer() {
- 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()) {
- super.floatAt(x, y, z, alwaysGlass);
- return;
- }
-
- setPosition(new Vector(x + 0.5, y, z + 0.5));
- player.setFlying(true);
- }
-}
+// $Id$
+/*
+ * WorldEdit
+ * Copyright (C) 2010 sk89q and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+*/
+
+package com.sk89q.worldedit.bukkit;
+
+import com.sk89q.worldedit.WorldEditException;
+import com.sk89q.worldedit.blocks.BaseBlock;
+import org.bukkit.GameMode;
+import org.bukkit.Location;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+
+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.WorldVector;
+import com.sk89q.worldedit.extent.inventory.BlockBag;
+import com.sk89q.worldedit.internal.cui.CUIEvent;
+
+public class BukkitPlayer extends LocalPlayer {
+ private Player player;
+ private WorldEditPlugin plugin;
+
+ public BukkitPlayer(WorldEditPlugin plugin, ServerInterface server, Player player) {
+ super(server);
+ this.plugin = plugin;
+ this.player = player;
+ }
+
+ @Override
+ public int getItemInHand() {
+ ItemStack itemStack = player.getItemInHand();
+ return itemStack != null ? itemStack.getTypeId() : 0;
+ }
+
+ public BaseBlock getBlockInHand() throws WorldEditException {
+ ItemStack itemStack = player.getItemInHand();
+ return BukkitUtil.toBlock(getWorld(), itemStack);
+ }
+
+ @Override
+ public String getName() {
+ return player.getName();
+ }
+
+ @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));
+ }
+
+ @Override
+ public void printRaw(String msg) {
+ for (String part : msg.split("\n")) {
+ player.sendMessage(part);
+ }
+ }
+
+ @Override
+ public void print(String msg) {
+ for (String part : msg.split("\n")) {
+ player.sendMessage("\u00A7d" + part);
+ }
+ }
+
+ @Override
+ public void printDebug(String msg) {
+ for (String part : msg.split("\n")) {
+ player.sendMessage("\u00A77" + part);
+ }
+ }
+
+ @Override
+ public void printError(String msg) {
+ for (String part : msg.split("\n")) {
+ player.sendMessage("\u00A7c" + part);
+ }
+ }
+
+ @Override
+ public void setPosition(Vector pos, float pitch, float yaw) {
+ player.teleport(new Location(player.getWorld(), pos.getX(), pos.getY(),
+ pos.getZ(), yaw, pitch));
+ }
+
+ @Override
+ public String[] getGroups() {
+ return plugin.getPermissionsResolver().getGroups(player);
+ }
+
+ @Override
+ public BlockBag getInventoryBlockBag() {
+ return new BukkitPlayerBlockBag(player);
+ }
+
+ @Override
+ public boolean hasPermission(String perm) {
+ return (!plugin.getLocalConfiguration().noOpPermissions && player.isOp())
+ || plugin.getPermissionsResolver().hasPermission(
+ player.getWorld().getName(), player, perm);
+ }
+
+ @Override
+ public LocalWorld getWorld() {
+ return BukkitUtil.getLocalWorld(player.getWorld());
+ }
+
+ @Override
+ public void dispatchCUIEvent(CUIEvent event) {
+ String[] params = event.getParameters();
+ String send = event.getTypeId();
+ if (params.length > 0) {
+ send = send + "|" + StringUtil.joinString(params, "|");
+ }
+ player.sendPluginMessage(plugin, WorldEditPlugin.CUI_PLUGIN_CHANNEL, send.getBytes(CUIChannelListener.UTF_8_CHARSET));
+ }
+
+ public Player getPlayer() {
+ 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()) {
+ super.floatAt(x, y, z, alwaysGlass);
+ return;
+ }
+
+ setPosition(new Vector(x + 0.5, y, z + 0.5));
+ player.setFlying(true);
+ }
+}
diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java
similarity index 95%
rename from src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java
rename to src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java
index ab66726b3..b2807d223 100644
--- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java
+++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java
@@ -1,228 +1,228 @@
-// $Id$
-/*
- * WorldEdit
- * Copyright (C) 2010 sk89q and contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
-*/
-
-package com.sk89q.worldedit.bukkit;
-
-import com.sk89q.worldedit.WorldVector;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.ItemStack;
-import com.sk89q.worldedit.bags.*;
-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 {
- /**
- * Player instance.
- */
- private Player player;
- /**
- * The player's inventory;
- */
- private ItemStack[] items;
-
- /**
- * Construct the object.
- *
- * @param player
- */
- public BukkitPlayerBlockBag(Player player) {
- this.player = player;
- }
-
- /**
- * Loads inventory on first use.
- */
- private void loadInventory() {
- if (items == null) {
- items = player.getInventory().getContents();
- }
- }
-
- /**
- * Get the player.
- *
- * @return
- */
- public Player getPlayer() {
- return player;
- }
-
- /**
- * Get a block.
- *
- * @param id
- */
- @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) {
- throw new IllegalArgumentException("Can't fetch air block");
- }
-
- loadInventory();
-
- boolean found = false;
-
- for (int slot = 0; slot < items.length; ++slot) {
- ItemStack bukkitItem = items[slot];
-
- if (bukkitItem == null) {
- continue;
- }
-
- if (bukkitItem.getTypeId() != id) {
- // 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
- return;
- }
-
- if (currentAmount > 1) {
- bukkitItem.setAmount(currentAmount - 1);
- found = true;
- } else {
- items[slot] = null;
- found = true;
- }
-
- break;
- }
-
- if (!found) {
- throw new OutOfBlocksException();
- }
- }
-
- /**
- * Store a block.
- *
- * @param id
- */
- @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) {
- throw new IllegalArgumentException("Can't store air block");
- }
-
- loadInventory();
-
- int freeSlot = -1;
-
- for (int slot = 0; slot < items.length; ++slot) {
- ItemStack bukkitItem = items[slot];
-
- if (bukkitItem == null) {
- // Delay using up a free slot until we know there are no stacks
- // of this item to merge into
-
- if (freeSlot == -1) {
- freeSlot = slot;
- }
- continue;
- }
-
- if (bukkitItem.getTypeId() != id) {
- // 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
- return;
- }
- if (currentAmount >= 64) {
- // Full stack
- continue;
- }
-
- int spaceLeft = 64 - currentAmount;
- if (spaceLeft >= amount) {
- bukkitItem.setAmount(currentAmount + amount);
- return;
- }
-
- bukkitItem.setAmount(64);
- amount -= spaceLeft;
- }
-
- if (freeSlot > -1) {
- items[freeSlot] = new ItemStack(id, amount);
- return;
- }
-
- throw new OutOfSpaceException(id);
- }
-
- /**
- * Flush any changes. This is called at the end.
- */
- @Override
- public void flushChanges() {
- if (items != null) {
- player.getInventory().setContents(items);
- items = null;
- }
- }
-
- /**
- * Adds a position to be used a source.
- *
- * @param pos
- */
- @Override
- public void addSourcePosition(WorldVector pos) {
- }
-
- /**
- * Adds a position to be used a source.
- *
- * @param pos
- */
- @Override
- public void addSingleSourcePosition(WorldVector pos) {
- }
-}
+// $Id$
+/*
+ * WorldEdit
+ * Copyright (C) 2010 sk89q and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+*/
+
+package com.sk89q.worldedit.bukkit;
+
+import com.sk89q.worldedit.WorldVector;
+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 {
+ /**
+ * Player instance.
+ */
+ private Player player;
+ /**
+ * The player's inventory;
+ */
+ private ItemStack[] items;
+
+ /**
+ * Construct the object.
+ *
+ * @param player
+ */
+ public BukkitPlayerBlockBag(Player player) {
+ this.player = player;
+ }
+
+ /**
+ * Loads inventory on first use.
+ */
+ private void loadInventory() {
+ if (items == null) {
+ items = player.getInventory().getContents();
+ }
+ }
+
+ /**
+ * Get the player.
+ *
+ * @return
+ */
+ public Player getPlayer() {
+ return player;
+ }
+
+ /**
+ * Get a block.
+ *
+ * @param id
+ */
+ @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) {
+ throw new IllegalArgumentException("Can't fetch air block");
+ }
+
+ loadInventory();
+
+ boolean found = false;
+
+ for (int slot = 0; slot < items.length; ++slot) {
+ ItemStack bukkitItem = items[slot];
+
+ if (bukkitItem == null) {
+ continue;
+ }
+
+ if (bukkitItem.getTypeId() != id) {
+ // 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
+ return;
+ }
+
+ if (currentAmount > 1) {
+ bukkitItem.setAmount(currentAmount - 1);
+ found = true;
+ } else {
+ items[slot] = null;
+ found = true;
+ }
+
+ break;
+ }
+
+ if (!found) {
+ throw new OutOfBlocksException();
+ }
+ }
+
+ /**
+ * Store a block.
+ *
+ * @param id
+ */
+ @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) {
+ throw new IllegalArgumentException("Can't store air block");
+ }
+
+ loadInventory();
+
+ int freeSlot = -1;
+
+ for (int slot = 0; slot < items.length; ++slot) {
+ ItemStack bukkitItem = items[slot];
+
+ if (bukkitItem == null) {
+ // Delay using up a free slot until we know there are no stacks
+ // of this item to merge into
+
+ if (freeSlot == -1) {
+ freeSlot = slot;
+ }
+ continue;
+ }
+
+ if (bukkitItem.getTypeId() != id) {
+ // 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
+ return;
+ }
+ if (currentAmount >= 64) {
+ // Full stack
+ continue;
+ }
+
+ int spaceLeft = 64 - currentAmount;
+ if (spaceLeft >= amount) {
+ bukkitItem.setAmount(currentAmount + amount);
+ return;
+ }
+
+ bukkitItem.setAmount(64);
+ amount -= spaceLeft;
+ }
+
+ if (freeSlot > -1) {
+ items[freeSlot] = new ItemStack(id, amount);
+ return;
+ }
+
+ throw new OutOfSpaceException(id);
+ }
+
+ /**
+ * Flush any changes. This is called at the end.
+ */
+ @Override
+ public void flushChanges() {
+ if (items != null) {
+ player.getInventory().setContents(items);
+ items = null;
+ }
+ }
+
+ /**
+ * Adds a position to be used a source.
+ *
+ * @param pos
+ */
+ @Override
+ public void addSourcePosition(WorldVector pos) {
+ }
+
+ /**
+ * Adds a position to be used a source.
+ *
+ * @param pos
+ */
+ @Override
+ public void addSingleSourcePosition(WorldVector pos) {
+ }
+}
diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java
similarity index 97%
rename from src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java
rename to src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java
index 03d931ea6..642f30c62 100644
--- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java
+++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java
@@ -1,125 +1,125 @@
-// $Id$
-/*
- * WorldEdit
- * Copyright (C) 2010 sk89q and contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
-*/
-
-package com.sk89q.worldedit.bukkit;
-
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-import com.sk89q.bukkit.util.CommandInfo;
-import com.sk89q.bukkit.util.CommandRegistration;
-import com.sk89q.minecraft.util.commands.Command;
-
-import com.sk89q.minecraft.util.commands.CommandPermissions;
-import com.sk89q.minecraft.util.commands.CommandsManager;
-import com.sk89q.worldedit.LocalPlayer;
-import org.bukkit.Bukkit;
-import org.bukkit.Material;
-import org.bukkit.Server;
-import org.bukkit.World;
-import org.bukkit.entity.EntityType;
-
-import com.sk89q.worldedit.BiomeTypes;
-import com.sk89q.worldedit.LocalWorld;
-import com.sk89q.worldedit.ServerInterface;
-
-public class BukkitServerInterface extends ServerInterface {
- public Server server;
- public WorldEditPlugin plugin;
- private CommandRegistration dynamicCommands;
- private BukkitBiomeTypes biomes;
-
- public BukkitServerInterface(WorldEditPlugin plugin, Server server) {
- this.plugin = plugin;
- this.server = server;
- this.biomes = new BukkitBiomeTypes();
- dynamicCommands = new CommandRegistration(plugin);
- }
-
- @Override
- public int resolveItem(String name) {
- Material mat = Material.matchMaterial(name);
- return mat == null ? 0 : mat.getId();
- }
-
- @Override
- public boolean isValidMobType(String type) {
- final EntityType entityType = EntityType.fromName(type);
- return entityType != null && entityType.isAlive();
- }
-
- @Override
- public void reload() {
- plugin.loadConfiguration();
- }
-
- @Override
- public BiomeTypes getBiomes() {
- return biomes;
- }
-
- @Override
- public int schedule(long delay, long period, Runnable task) {
- return Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, task, delay, period);
- }
-
- @Override
- public List getWorlds() {
- List worlds = server.getWorlds();
- List ret = new ArrayList(worlds.size());
-
- for (World world : worlds) {
- ret.add(BukkitUtil.getLocalWorld(world));
- }
-
- return ret;
- }
-
- @Override
- public void onCommandRegistration(List commands, CommandsManager manager) {
- List toRegister = new ArrayList();
- for (Command command : commands) {
- List permissions = null;
- Method cmdMethod = manager.getMethods().get(null).get(command.aliases()[0]);
- Map childMethods = manager.getMethods().get(cmdMethod);
-
- if (cmdMethod != null && cmdMethod.isAnnotationPresent(CommandPermissions.class)) {
- permissions = Arrays.asList(cmdMethod.getAnnotation(CommandPermissions.class).value());
- } else if (cmdMethod != null && childMethods != null && childMethods.size() > 0) {
- permissions = new ArrayList();
- for (Method m : childMethods.values()) {
- if (m.isAnnotationPresent(CommandPermissions.class)) {
- permissions.addAll(Arrays.asList(m.getAnnotation(CommandPermissions.class).value()));
- }
- }
- }
-
- toRegister.add(new CommandInfo(command.usage(), command.desc(), command.aliases(), commands, permissions == null ? null : permissions.toArray(new String[permissions.size()])));
- }
-
- dynamicCommands.register(toRegister);
- }
-
- public void unregisterCommands() {
- dynamicCommands.unregisterCommands();
- }
-}
+// $Id$
+/*
+ * WorldEdit
+ * Copyright (C) 2010 sk89q and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+*/
+
+package com.sk89q.worldedit.bukkit;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import com.sk89q.bukkit.util.CommandInfo;
+import com.sk89q.bukkit.util.CommandRegistration;
+import com.sk89q.minecraft.util.commands.Command;
+
+import com.sk89q.minecraft.util.commands.CommandPermissions;
+import com.sk89q.minecraft.util.commands.CommandsManager;
+import com.sk89q.worldedit.LocalPlayer;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.Server;
+import org.bukkit.World;
+import org.bukkit.entity.EntityType;
+
+import com.sk89q.worldedit.BiomeTypes;
+import com.sk89q.worldedit.LocalWorld;
+import com.sk89q.worldedit.ServerInterface;
+
+public class BukkitServerInterface extends ServerInterface {
+ public Server server;
+ public WorldEditPlugin plugin;
+ private CommandRegistration dynamicCommands;
+ private BukkitBiomeTypes biomes;
+
+ public BukkitServerInterface(WorldEditPlugin plugin, Server server) {
+ this.plugin = plugin;
+ this.server = server;
+ this.biomes = new BukkitBiomeTypes();
+ dynamicCommands = new CommandRegistration(plugin);
+ }
+
+ @Override
+ public int resolveItem(String name) {
+ Material mat = Material.matchMaterial(name);
+ return mat == null ? 0 : mat.getId();
+ }
+
+ @Override
+ public boolean isValidMobType(String type) {
+ final EntityType entityType = EntityType.fromName(type);
+ return entityType != null && entityType.isAlive();
+ }
+
+ @Override
+ public void reload() {
+ plugin.loadConfiguration();
+ }
+
+ @Override
+ public BiomeTypes getBiomes() {
+ return biomes;
+ }
+
+ @Override
+ public int schedule(long delay, long period, Runnable task) {
+ return Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, task, delay, period);
+ }
+
+ @Override
+ public List getWorlds() {
+ List worlds = server.getWorlds();
+ List ret = new ArrayList(worlds.size());
+
+ for (World world : worlds) {
+ ret.add(BukkitUtil.getLocalWorld(world));
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void onCommandRegistration(List commands, CommandsManager manager) {
+ List toRegister = new ArrayList();
+ for (Command command : commands) {
+ List permissions = null;
+ Method cmdMethod = manager.getMethods().get(null).get(command.aliases()[0]);
+ Map childMethods = manager.getMethods().get(cmdMethod);
+
+ if (cmdMethod != null && cmdMethod.isAnnotationPresent(CommandPermissions.class)) {
+ permissions = Arrays.asList(cmdMethod.getAnnotation(CommandPermissions.class).value());
+ } else if (cmdMethod != null && childMethods != null && childMethods.size() > 0) {
+ permissions = new ArrayList();
+ for (Method m : childMethods.values()) {
+ if (m.isAnnotationPresent(CommandPermissions.class)) {
+ permissions.addAll(Arrays.asList(m.getAnnotation(CommandPermissions.class).value()));
+ }
+ }
+ }
+
+ toRegister.add(new CommandInfo(command.usage(), command.desc(), command.aliases(), commands, permissions == null ? null : permissions.toArray(new String[permissions.size()])));
+ }
+
+ dynamicCommands.register(toRegister);
+ }
+
+ public void unregisterCommands() {
+ dynamicCommands.unregisterCommands();
+ }
+}
diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitUtil.java
similarity index 97%
rename from src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java
rename to src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitUtil.java
index c3c2c09ba..b4e3bcd23 100644
--- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java
+++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitUtil.java
@@ -1,195 +1,195 @@
-// $Id$
-/*
- * WorldEdit
- * Copyright (C) 2010 sk89q and contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU 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 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.size() == 0) {
- 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);
- }
-}
+// $Id$
+/*
+ * WorldEdit
+ * Copyright (C) 2010 sk89q and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 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.size() == 0) {
+ 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/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitWorld.java
similarity index 92%
rename from src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java
rename to src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitWorld.java
index c7bf76097..9471bcd71 100644
--- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java
+++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitWorld.java
@@ -1,1371 +1,1328 @@
-// $Id$
-/*
- * WorldEdit
- * Copyright (C) 2010 sk89q and contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
-*/
-
-package com.sk89q.worldedit.bukkit;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.InputStream;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.bukkit.Bukkit;
-import org.bukkit.Effect;
-import org.bukkit.Location;
-import org.bukkit.Material;
-import org.bukkit.SkullType;
-import org.bukkit.TreeType;
-import org.bukkit.World;
-import org.bukkit.block.Biome;
-import org.bukkit.block.Block;
-import org.bukkit.block.BlockFace;
-import org.bukkit.block.BlockState;
-import org.bukkit.block.Chest;
-import org.bukkit.block.CreatureSpawner;
-import org.bukkit.block.Furnace;
-import org.bukkit.block.Sign;
-import org.bukkit.block.Skull;
-import org.bukkit.enchantments.Enchantment;
-import org.bukkit.entity.Ambient;
-import org.bukkit.entity.Animals;
-import org.bukkit.entity.Boat;
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.ExperienceOrb;
-import org.bukkit.entity.FallingBlock;
-import org.bukkit.entity.Golem;
-import org.bukkit.entity.Hanging;
-import org.bukkit.entity.HumanEntity;
-import org.bukkit.entity.Item;
-import org.bukkit.entity.ItemFrame;
-import org.bukkit.entity.LivingEntity;
-import org.bukkit.entity.Minecart;
-import org.bukkit.entity.Painting;
-import org.bukkit.entity.Projectile;
-import org.bukkit.entity.TNTPrimed;
-import org.bukkit.entity.Tameable;
-import org.bukkit.entity.Villager;
-import org.bukkit.inventory.DoubleChestInventory;
-import org.bukkit.inventory.Inventory;
-import org.bukkit.inventory.ItemStack;
-import org.bukkit.plugin.Plugin;
-
-import com.sk89q.worldedit.BiomeType;
-import com.sk89q.worldedit.BlockVector2D;
-import com.sk89q.worldedit.EditSession;
-import com.sk89q.worldedit.EntityType;
-import com.sk89q.worldedit.LocalEntity;
-import com.sk89q.worldedit.LocalWorld;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.Vector2D;
-import com.sk89q.worldedit.WorldEdit;
-import com.sk89q.worldedit.blocks.BaseBlock;
-import com.sk89q.worldedit.blocks.BaseItemStack;
-import com.sk89q.worldedit.blocks.BlockID;
-import com.sk89q.worldedit.blocks.ContainerBlock;
-import com.sk89q.worldedit.blocks.FurnaceBlock;
-import com.sk89q.worldedit.blocks.MobSpawnerBlock;
-import com.sk89q.worldedit.blocks.NoteBlock;
-import com.sk89q.worldedit.blocks.SignBlock;
-import com.sk89q.worldedit.blocks.SkullBlock;
-import com.sk89q.worldedit.bukkit.entity.BukkitEntity;
-import com.sk89q.worldedit.regions.Region;
-import com.sk89q.worldedit.util.TreeGenerator;
-
-public class BukkitWorld extends LocalWorld {
-
- private static final Logger logger = WorldEdit.logger;
- private World world;
- private static boolean skipNmsAccess = false;
- private static boolean skipNmsSafeSet = false;
- private static boolean skipNmsValidBlockCheck = false;
-
- /*
- * holder for the nmsblock class that we should use
- */
- private static Class extends NmsBlock> nmsBlockType;
- private static Method nmsSetMethod;
- private static Method nmsValidBlockMethod;
- private static Method nmsGetMethod;
- private static Method nmsSetSafeMethod;
-
- // copied from WG
- private static > T tryEnum(Class enumType, String ... values) {
- for (String val : values) {
- try {
- return Enum.valueOf(enumType, val);
- } catch (IllegalArgumentException e) {}
- }
- return null;
- }
- private static org.bukkit.entity.EntityType tntMinecartType;
- private static boolean checkMinecartType = true;
-
- /**
- * Construct the object.
- * @param world
- */
- @SuppressWarnings("unchecked")
- public BukkitWorld(World world) {
- this.world = world;
-
- if (checkMinecartType) {
- tntMinecartType = tryEnum(org.bukkit.entity.EntityType.class, "MINECART_TNT");
- checkMinecartType = false;
- }
- // check if we have a class we can use for nms access
-
- // only run once per server startup
- if (nmsBlockType != null || skipNmsAccess || skipNmsSafeSet || skipNmsValidBlockCheck) return;
- Plugin plugin = Bukkit.getPluginManager().getPlugin("WorldEdit");
- if (!(plugin instanceof WorldEditPlugin)) return; // hopefully never happens
- WorldEditPlugin wePlugin = ((WorldEditPlugin) plugin);
- File nmsBlocksDir = new File(wePlugin.getDataFolder() + File.separator + "nmsblocks" + File.separator);
- if (nmsBlocksDir.listFiles() == null) { // no files to use
- skipNmsAccess = true; skipNmsSafeSet = true; skipNmsValidBlockCheck = true;
- return;
- }
- try {
- // make a classloader that can handle our blocks
- NmsBlockClassLoader loader = new NmsBlockClassLoader(BukkitWorld.class.getClassLoader(), nmsBlocksDir);
- String filename;
- for (File f : nmsBlocksDir.listFiles()) {
- if (!f.isFile()) continue;
- filename = f.getName();
- // load class using magic keyword
- Class> testBlock = null;
- try {
- testBlock = loader.loadClass("CL-NMS" + filename);
- } catch (Throwable e) {
- // someone is putting things where they don't belong
- continue;
- }
- filename = filename.replaceFirst(".class$", ""); // get rid of extension
- if (NmsBlock.class.isAssignableFrom(testBlock)) {
- // got a NmsBlock, test it now
- Class extends NmsBlock> nmsClass = (Class extends NmsBlock>) testBlock;
- boolean canUse = false;
- try {
- canUse = (Boolean) nmsClass.getMethod("verify").invoke(null);
- } catch (Throwable e) {
- continue;
- }
- if (!canUse) continue; // not for this server
- nmsBlockType = nmsClass;
- nmsSetMethod = nmsBlockType.getMethod("set", World.class, Vector.class, BaseBlock.class);
- nmsValidBlockMethod = nmsBlockType.getMethod("isValidBlockType", int.class);
- nmsGetMethod = nmsBlockType.getMethod("get", World.class, Vector.class, int.class, int.class);
- nmsSetSafeMethod = nmsBlockType.getMethod("setSafely",
- BukkitWorld.class, Vector.class, com.sk89q.worldedit.foundation.Block.class, boolean.class);
- // phew
- break;
- }
- }
- if (nmsBlockType != null) {
- logger.info("[WorldEdit] Using external NmsBlock for this version: " + nmsBlockType.getName());
- } else {
- // try our default
- try {
- nmsBlockType = (Class extends NmsBlock>) Class.forName("com.sk89q.worldedit.bukkit.DefaultNmsBlock");
- boolean canUse = (Boolean) nmsBlockType.getMethod("verify").invoke(null);
- if (canUse) {
- nmsSetMethod = nmsBlockType.getMethod("set", World.class, Vector.class, BaseBlock.class);
- nmsValidBlockMethod = nmsBlockType.getMethod("isValidBlockType", int.class);
- nmsGetMethod = nmsBlockType.getMethod("get", World.class, Vector.class, int.class, int.class);
- nmsSetSafeMethod = nmsBlockType.getMethod("setSafely",
- BukkitWorld.class, Vector.class, com.sk89q.worldedit.foundation.Block.class, boolean.class);
- logger.info("[WorldEdit] Using inbuilt NmsBlock for this version.");
- }
- } catch (Throwable e) {
- // OMG DEVS WAI U NO SUPPORT SERVER
- skipNmsAccess = true; skipNmsSafeSet = true; skipNmsValidBlockCheck = true;
- logger.warning("[WorldEdit] No compatible nms block class found.");
- }
- }
- } catch (Throwable e) {
- logger.warning("[WorldEdit] Unable to load NmsBlock classes, make sure they are installed correctly.");
- e.printStackTrace();
- skipNmsAccess = true; skipNmsSafeSet = true; skipNmsValidBlockCheck = true;
- }
- }
-
- private class NmsBlockClassLoader extends ClassLoader {
- public File searchDir;
- public NmsBlockClassLoader(ClassLoader parent, File searchDir) {
- super(parent);
- this.searchDir = searchDir;
- }
-
- @Override
- public Class> loadClass(String name) throws ClassNotFoundException {
- if (!name.startsWith("CL-NMS")) {
- return super.loadClass(name);
- } else {
- name = name.replace("CL-NMS", ""); // hacky lol
- }
- try {
- URL url = new File(searchDir, name).toURI().toURL();
- InputStream input = url.openConnection().getInputStream();
- ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-
- int data = input.read();
- while (data != -1) {
- buffer.write(data);
- data = input.read();
- }
- input.close();
-
- byte[] classData = buffer.toByteArray();
-
- return defineClass(name.replaceFirst(".class$", ""), classData, 0, classData.length);
- } catch (Throwable e) {
- throw new ClassNotFoundException();
- }
- }
- }
-
- /**
- * Get the world handle.
- *
- * @return
- */
- public World getWorld() {
- return world;
- }
-
- /**
- * Get the name of the world
- *
- * @return
- */
- @Override
- public String getName() {
- return world.getName();
- }
-
- /**
- * Set block type.
- *
- * @param pt
- * @param type
- * @return
- */
- @Override
- public boolean setBlockType(Vector pt, int type) {
- return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setTypeId(type);
- }
-
- /**
- * Set block type.
- *
- * @param pt
- * @param type
- * @return
- */
- @Override
- public boolean setBlockTypeFast(Vector pt, int type) {
- return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setTypeId(type, false);
- }
-
- /**
- * set block type & data
- * @param pt
- * @param type
- * @param data
- * @return
- */
- @Override
- public boolean setTypeIdAndData(Vector pt, int type, int data) {
- return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setTypeIdAndData(type, (byte) data, true);
- }
-
- /**
- * set block type & data
- * @param pt
- * @param type
- * @param data
- * @return
- */
- @Override
- public boolean setTypeIdAndDataFast(Vector pt, int type, int data) {
- return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setTypeIdAndData(type, (byte) data, false);
- }
-
- /**
- * Get block type.
- *
- * @param pt
- * @return
- */
- @Override
- public int getBlockType(Vector pt) {
- return world.getBlockTypeIdAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
- }
-
- /**
- * Set block data.
- *
- * @param pt
- * @param data
- */
- @Override
- public void setBlockData(Vector pt, int data) {
- world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setData((byte) data);
- }
-
- /**
- * Set block data.
- *
- * @param pt
- * @param data
- */
- @Override
- public void setBlockDataFast(Vector pt, int data) {
- world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setData((byte) data, false);
- }
-
- /**
- * Get block data.
- *
- * @param pt
- * @return
- */
- @Override
- public int getBlockData(Vector pt) {
- return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getData();
- }
-
- /**
- * Get block light level.
- *
- * @param pt
- * @return
- */
- @Override
- public int getBlockLightLevel(Vector pt) {
- return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getLightLevel();
- }
-
- /**
- * Get biome type
- *
- * @param pt
- * @return
- */
- @Override
- public BiomeType getBiome(Vector2D pt) {
- Biome bukkitBiome = world.getBiome(pt.getBlockX(), pt.getBlockZ());
- try {
- return BukkitBiomeType.valueOf(bukkitBiome.name());
- } catch (IllegalArgumentException exc) {
- return BiomeType.UNKNOWN;
- }
- }
-
- @Override
- public void setBiome(Vector2D pt, BiomeType biome) {
- if (biome instanceof BukkitBiomeType) {
- Biome bukkitBiome;
- bukkitBiome = ((BukkitBiomeType) biome).getBukkitBiome();
- world.setBiome(pt.getBlockX(), pt.getBlockZ(), bukkitBiome);
- }
- }
-
- /**
- * Regenerate an area.
- *
- * @param region
- * @param editSession
- * @return
- */
- @Override
- public boolean regenerate(Region region, EditSession editSession) {
- BaseBlock[] history = new BaseBlock[16 * 16 * (getMaxY() + 1)];
-
- for (Vector2D chunk : region.getChunks()) {
- Vector min = new Vector(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16);
-
- // First save all the blocks inside
- for (int x = 0; x < 16; ++x) {
- for (int y = 0; y < (getMaxY() + 1); ++y) {
- 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);
- }
- }
- }
-
- try {
- world.regenerateChunk(chunk.getBlockX(), chunk.getBlockZ());
- } catch (Throwable t) {
- t.printStackTrace();
- }
-
- // Then restore
- for (int x = 0; x < 16; ++x) {
- for (int y = 0; y < (getMaxY() + 1); ++y) {
- for (int z = 0; z < 16; ++z) {
- Vector pt = min.add(x, y, z);
- int index = y * 16 * 16 + z * 16 + x;
-
- // We have to restore the block if it was outside
- if (!region.contains(pt)) {
- editSession.smartSetBlock(pt, history[index]);
- } else { // Otherwise fool with history
- editSession.rememberChange(pt, history[index],
- editSession.rawGetBlock(pt));
- }
- }
- }
- }
- }
-
- return true;
- }
-
- /**
- * Attempts to accurately copy a BaseBlock's extra data to the world.
- *
- * @param pt
- * @param block
- * @return
- */
- @Override
- public boolean copyToWorld(Vector pt, BaseBlock block) {
- if (block instanceof SignBlock) {
- // Signs
- setSignText(pt, ((SignBlock) block).getText());
- return true;
- }
-
- if (block instanceof FurnaceBlock) {
- // Furnaces
- Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
- if (bukkitBlock == null) return false;
- BlockState state = bukkitBlock.getState();
- if (!(state instanceof Furnace)) return false;
- Furnace bukkit = (Furnace) state;
- FurnaceBlock we = (FurnaceBlock) block;
- bukkit.setBurnTime(we.getBurnTime());
- bukkit.setCookTime(we.getCookTime());
- return setContainerBlockContents(pt, ((ContainerBlock) block).getItems());
- }
-
- if (block instanceof ContainerBlock) {
- // Chests/dispenser
- return setContainerBlockContents(pt, ((ContainerBlock) block).getItems());
- }
-
- if (block instanceof MobSpawnerBlock) {
- // Mob spawners
- Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
- if (bukkitBlock == null) return false;
- BlockState state = bukkitBlock.getState();
- if (!(state instanceof CreatureSpawner)) return false;
- CreatureSpawner bukkit = (CreatureSpawner) state;
- MobSpawnerBlock we = (MobSpawnerBlock) block;
- bukkit.setCreatureTypeByName(we.getMobType());
- bukkit.setDelay(we.getDelay());
- return true;
- }
-
- if (block instanceof NoteBlock) {
- // Note block
- Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
- if (bukkitBlock == null) return false;
- BlockState state = bukkitBlock.getState();
- if (!(state instanceof org.bukkit.block.NoteBlock)) return false;
- org.bukkit.block.NoteBlock bukkit = (org.bukkit.block.NoteBlock) state;
- NoteBlock we = (NoteBlock) block;
- bukkit.setRawNote(we.getNote());
- return true;
- }
-
- if (block instanceof SkullBlock) {
- // Skull block
- Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
- if (bukkitBlock == null) return false;
- BlockState state = bukkitBlock.getState();
- if (!(state instanceof org.bukkit.block.Skull)) return false;
- Skull bukkit = (Skull) state;
- SkullBlock we = (SkullBlock) block;
- // this is dumb
- SkullType skullType = SkullType.SKELETON;
- switch (we.getSkullType()) {
- case 0:
- skullType = SkullType.SKELETON;
- break;
- case 1:
- skullType = SkullType.WITHER;
- break;
- case 2:
- skullType = SkullType.ZOMBIE;
- break;
- case 3:
- skullType = SkullType.PLAYER;
- break;
- case 4:
- skullType = SkullType.CREEPER;
- break;
- }
- bukkit.setSkullType(skullType);
- BlockFace rotation;
- switch (we.getRot()) {
- // soooo dumb
- case 0:
- rotation = BlockFace.NORTH;
- break;
- case 1:
- rotation = BlockFace.NORTH_NORTH_EAST;
- break;
- case 2:
- rotation = BlockFace.NORTH_EAST;
- break;
- case 3:
- rotation = BlockFace.EAST_NORTH_EAST;
- break;
- case 4:
- rotation = BlockFace.EAST;
- break;
- case 5:
- rotation = BlockFace.EAST_SOUTH_EAST;
- break;
- case 6:
- rotation = BlockFace.SOUTH_EAST;
- break;
- case 7:
- rotation = BlockFace.SOUTH_SOUTH_EAST;
- break;
- case 8:
- rotation = BlockFace.SOUTH;
- break;
- case 9:
- rotation = BlockFace.SOUTH_SOUTH_WEST;
- break;
- case 10:
- rotation = BlockFace.SOUTH_WEST;
- break;
- case 11:
- rotation = BlockFace.WEST_SOUTH_WEST;
- break;
- case 12:
- rotation = BlockFace.WEST;
- break;
- case 13:
- rotation = BlockFace.WEST_NORTH_WEST;
- break;
- case 14:
- rotation = BlockFace.NORTH_WEST;
- break;
- case 15:
- rotation = BlockFace.NORTH_NORTH_WEST;
- break;
- default:
- rotation = BlockFace.NORTH;
- break;
- }
- bukkit.setRotation(rotation);
- if (we.getOwner() != null && !we.getOwner().isEmpty()) bukkit.setOwner(we.getOwner());
- bukkit.update(true);
- return true;
- }
-
- if (!skipNmsAccess) {
- try {
- return (Boolean) nmsSetMethod.invoke(null, world, pt, block);
- } catch (Throwable t) {
- logger.log(Level.WARNING, "WorldEdit: Failed to do NMS access for direct NBT data copy", t);
- skipNmsAccess = true;
- }
- }
-
- return false;
- }
-
- /**
- * Attempts to read a BaseBlock's extra data from the world.
- *
- * @param pt
- * @param block
- * @return
- */
- @Override
- public boolean copyFromWorld(Vector pt, BaseBlock block) {
- if (block instanceof SignBlock) {
- // Signs
- ((SignBlock) block).setText(getSignText(pt));
- return true;
- }
-
- if (block instanceof FurnaceBlock) {
- // Furnaces
- Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
- if (bukkitBlock == null) return false;
- BlockState state = bukkitBlock.getState();
- if (!(state instanceof Furnace)) return false;
- Furnace bukkit = (Furnace) state;
- FurnaceBlock we = (FurnaceBlock) block;
- we.setBurnTime(bukkit.getBurnTime());
- we.setCookTime(bukkit.getCookTime());
- ((ContainerBlock) block).setItems(getContainerBlockContents(pt));
- return true;
- }
-
- if (block instanceof ContainerBlock) {
- // Chests/dispenser
- ((ContainerBlock) block).setItems(getContainerBlockContents(pt));
- return true;
- }
-
- if (block instanceof MobSpawnerBlock) {
- // Mob spawners
- Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
- if (bukkitBlock == null) return false;
- BlockState state = bukkitBlock.getState();
- if (!(state instanceof CreatureSpawner)) return false;
- CreatureSpawner bukkit = (CreatureSpawner) state;
- MobSpawnerBlock we = (MobSpawnerBlock) block;
- we.setMobType(bukkit.getCreatureTypeName());
- we.setDelay((short) bukkit.getDelay());
- return true;
- }
-
- if (block instanceof NoteBlock) {
- // Note block
- Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
- if (bukkitBlock == null) return false;
- BlockState state = bukkitBlock.getState();
- if (!(state instanceof org.bukkit.block.NoteBlock)) return false;
- org.bukkit.block.NoteBlock bukkit = (org.bukkit.block.NoteBlock) state;
- NoteBlock we = (NoteBlock) block;
- we.setNote(bukkit.getRawNote());
- return true;
- }
-
- if (block instanceof SkullBlock) {
- // Skull block
- Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
- if (bukkitBlock == null) return false;
- BlockState state = bukkitBlock.getState();
- if (!(state instanceof org.bukkit.block.Skull)) return false;
- Skull bukkit = (Skull) state;
- SkullBlock we = (SkullBlock) block;
- byte skullType = 0;
- switch (bukkit.getSkullType()) {
- // this is dumb but whoever wrote the class is stupid
- case SKELETON:
- skullType = 0;
- break;
- case WITHER:
- skullType = 1;
- break;
- case ZOMBIE:
- skullType = 2;
- break;
- case PLAYER:
- skullType = 3;
- break;
- case CREEPER:
- skullType = 4;
- break;
- }
- we.setSkullType(skullType);
- byte rot = 0;
- switch (bukkit.getRotation()) {
- // this is even more dumb, hurray for copy/paste
- case NORTH:
- rot = (byte) 0;
- break;
- case NORTH_NORTH_EAST:
- rot = (byte) 1;
- break;
- case NORTH_EAST:
- rot = (byte) 2;
- break;
- case EAST_NORTH_EAST:
- rot = (byte) 3;
- break;
- case EAST:
- rot = (byte) 4;
- break;
- case EAST_SOUTH_EAST:
- rot = (byte) 5;
- break;
- case SOUTH_EAST:
- rot = (byte) 6;
- break;
- case SOUTH_SOUTH_EAST:
- rot = (byte) 7;
- break;
- case SOUTH:
- rot = (byte) 8;
- break;
- case SOUTH_SOUTH_WEST:
- rot = (byte) 9;
- break;
- case SOUTH_WEST:
- rot = (byte) 10;
- break;
- case WEST_SOUTH_WEST:
- rot = (byte) 11;
- break;
- case WEST:
- rot = (byte) 12;
- break;
- case WEST_NORTH_WEST:
- rot = (byte) 13;
- break;
- case NORTH_WEST:
- rot = (byte) 14;
- break;
- case NORTH_NORTH_WEST:
- rot = (byte) 15;
- break;
- }
- we.setRot(rot);
- we.setOwner(bukkit.hasOwner() ? bukkit.getOwner() : "");
- return true;
- }
-
- return false;
- }
-
- /**
- * Gets the single block inventory for a potentially double chest.
- * Handles people who have an old version of Bukkit.
- * This should be replaced with {@link org.bukkit.block.Chest#getBlockInventory()}
- * in a few months (now = March 2012) // note from future dev - lol
- *
- * @param chest The chest to get a single block inventory for
- * @return The chest's inventory
- */
- private Inventory getBlockInventory(Chest chest) {
- try {
- return chest.getBlockInventory();
- } catch (Throwable t) {
- if (chest.getInventory() instanceof DoubleChestInventory) {
- DoubleChestInventory inven = (DoubleChestInventory) chest.getInventory();
- if (inven.getLeftSide().getHolder().equals(chest)) {
- return inven.getLeftSide();
- } else if (inven.getRightSide().getHolder().equals(chest)) {
- return inven.getRightSide();
- } else {
- return inven;
- }
- } else {
- return chest.getInventory();
- }
- }
- }
-
- /**
- * Clear a chest's contents.
- *
- * @param pt
- */
- @Override
- public boolean clearContainerBlockContents(Vector pt) {
- Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
- if (block == null) {
- return false;
- }
- BlockState state = block.getState();
- if (!(state instanceof org.bukkit.inventory.InventoryHolder)) {
- return false;
- }
-
- org.bukkit.inventory.InventoryHolder chest = (org.bukkit.inventory.InventoryHolder) state;
- Inventory inven = chest.getInventory();
- if (chest instanceof Chest) {
- inven = getBlockInventory((Chest) chest);
- }
- inven.clear();
- return true;
- }
-
- /**
- * Generate a tree at a location.
- *
- * @param pt
- * @return
- */
- @Override
- @Deprecated
- public boolean generateTree(EditSession editSession, Vector pt) {
- return generateTree(TreeGenerator.TreeType.TREE, editSession, pt);
- }
-
- /**
- * Generate a big tree at a location.
- *
- * @param pt
- * @return
- */
- @Override
- @Deprecated
- public boolean generateBigTree(EditSession editSession, Vector pt) {
- return generateTree(TreeGenerator.TreeType.BIG_TREE, editSession, pt);
- }
-
- /**
- * Generate a birch tree at a location.
- *
- * @param pt
- * @return
- */
- @Override
- @Deprecated
- public boolean generateBirchTree(EditSession editSession, Vector pt) {
- return generateTree(TreeGenerator.TreeType.BIRCH, editSession, pt);
- }
-
- /**
- * Generate a redwood tree at a location.
- *
- * @param pt
- * @return
- */
- @Override
- @Deprecated
- public boolean generateRedwoodTree(EditSession editSession, Vector pt) {
- return generateTree(TreeGenerator.TreeType.REDWOOD, editSession, pt);
- }
-
- /**
- * Generate a redwood tree at a location.
- *
- * @param pt
- * @return
- */
- @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);
-
- static {
- for (TreeGenerator.TreeType type : TreeGenerator.TreeType.values()) {
- try {
- TreeType bukkitType = TreeType.valueOf(type.name());
- treeTypeMapping.put(type, bukkitType);
- } catch (IllegalArgumentException e) {
- // Unhandled TreeType
- }
- }
- // Other mappings for WE-specific values
- treeTypeMapping.put(TreeGenerator.TreeType.SHORT_JUNGLE, TreeType.SMALL_JUNGLE);
- treeTypeMapping.put(TreeGenerator.TreeType.RANDOM, TreeType.BROWN_MUSHROOM);
- treeTypeMapping.put(TreeGenerator.TreeType.RANDOM_REDWOOD, TreeType.REDWOOD);
- treeTypeMapping.put(TreeGenerator.TreeType.PINE, TreeType.REDWOOD);
- for (TreeGenerator.TreeType type : TreeGenerator.TreeType.values()) {
- if (treeTypeMapping.get(type) == null) {
- WorldEdit.logger.severe("No TreeType mapping for TreeGenerator.TreeType." + type);
- }
- }
- }
-
- public static TreeType toBukkitTreeType(TreeGenerator.TreeType type) {
- return treeTypeMapping.get(type);
- }
-
- @Override
- public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector pt) {
- TreeType bukkitType = toBukkitTreeType(type);
- return type != null && world.generateTree(BukkitUtil.toLocation(world, pt), bukkitType,
- new EditSessionBlockChangeDelegate(editSession));
- }
-
- /**
- * Drop an item.
- *
- * @param pt
- * @param item
- */
- @Override
- public void dropItem(Vector pt, BaseItemStack item) {
- ItemStack bukkitItem = new ItemStack(item.getType(), item.getAmount(),
- item.getData());
- world.dropItemNaturally(BukkitUtil.toLocation(world, pt), bukkitItem);
- }
-
- /**
- * Kill mobs in an area.
- *
- * @param origin The center of the area to kill mobs in.
- * @param radius Maximum distance to kill mobs at; radius < 0 means kill all mobs
- * @param flags various flags that determine what to kill
- * @return number of mobs killed
- */
- @Override
- public int killMobs(Vector origin, double radius, int flags) {
- boolean killPets = (flags & KillFlags.PETS) != 0;
- boolean killNPCs = (flags & KillFlags.NPCS) != 0;
- boolean killAnimals = (flags & KillFlags.ANIMALS) != 0;
- boolean withLightning = (flags & KillFlags.WITH_LIGHTNING) != 0;
- boolean killGolems = (flags & KillFlags.GOLEMS) != 0;
- boolean killAmbient = (flags & KillFlags.AMBIENT) != 0;
-
- int num = 0;
- double radiusSq = radius * radius;
-
- Location bukkitOrigin = BukkitUtil.toLocation(world, origin);
-
- for (LivingEntity ent : world.getLivingEntities()) {
- if (ent instanceof HumanEntity) {
- continue;
- }
-
- if (!killAnimals && ent instanceof Animals) {
- continue;
- }
-
- if (!killPets && ent instanceof Tameable && ((Tameable) ent).isTamed()) {
- continue; // tamed pet
- }
-
- if (!killGolems && ent instanceof Golem) {
- continue;
- }
-
- if (!killNPCs && ent instanceof Villager) {
- continue;
- }
-
- if (!killAmbient && ent instanceof Ambient) {
- continue;
- }
-
- if (radius < 0 || bukkitOrigin.distanceSquared(ent.getLocation()) <= radiusSq) {
- if (withLightning) {
- world.strikeLightningEffect(ent.getLocation());
- }
- ent.remove();
- ++num;
- }
- }
-
- return num;
- }
-
- /**
- * Remove entities in an area.
- *
- * @param origin
- * @param radius
- * @return
- */
- @Override
- public int removeEntities(EntityType type, Vector origin, int radius) {
- int num = 0;
- double radiusSq = Math.pow(radius, 2);
-
- for (Entity ent : world.getEntities()) {
- if (radius != -1
- && origin.distanceSq(BukkitUtil.toVector(ent.getLocation())) > radiusSq) {
- continue;
- }
-
- switch (type) {
- case ALL:
- if (ent instanceof Projectile || ent instanceof Boat || ent instanceof Item
- || ent instanceof FallingBlock || ent instanceof Minecart || ent instanceof Hanging
- || ent instanceof TNTPrimed || ent instanceof ExperienceOrb) {
- ent.remove();
- num++;
- }
- break;
-
- case PROJECTILES:
- case ARROWS:
- if (ent instanceof Projectile) {
- // covers: arrow, egg, enderpearl, fireball, fish, snowball, throwpotion, thrownexpbottle
- ent.remove();
- ++num;
- }
- break;
-
- case BOATS:
- if (ent instanceof Boat) {
- ent.remove();
- ++num;
- }
- break;
-
- case ITEMS:
- if (ent instanceof Item) {
- ent.remove();
- ++num;
- }
- break;
-
- case FALLING_BLOCKS:
- if (ent instanceof FallingBlock) {
- ent.remove();
- ++num;
- }
- break;
-
- case MINECARTS:
- if (ent instanceof Minecart) {
- ent.remove();
- ++num;
- }
- break;
-
- case PAINTINGS:
- if (ent instanceof Painting) {
- ent.remove();
- ++num;
- }
- break;
-
- case ITEM_FRAMES:
- if (ent instanceof ItemFrame) {
- ent.remove();
- ++num;
- }
- break;
-
- case TNT:
- if (ent instanceof TNTPrimed || ent.getType() == tntMinecartType) {
- ent.remove();
- ++num;
- }
- break;
-
- case XP_ORBS:
- if (ent instanceof ExperienceOrb) {
- ent.remove();
- ++num;
- }
- break;
- }
- }
-
- return num;
- }
-
- /**
- * Set a sign's text.
- *
- * @param pt
- * @param text
- * @return
- */
- private boolean setSignText(Vector pt, String[] text) {
- Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
- if (block == null) return false;
- BlockState state = block.getState();
- if (state == null || !(state instanceof Sign)) return false;
- Sign sign = (Sign) state;
- sign.setLine(0, text[0]);
- sign.setLine(1, text[1]);
- sign.setLine(2, text[2]);
- sign.setLine(3, text[3]);
- sign.update();
- return true;
- }
-
- /**
- * Get a sign's text.
- *
- * @param pt
- * @return
- */
- private String[] getSignText(Vector pt) {
- Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
- if (block == null) return new String[] { "", "", "", "" };
- BlockState state = block.getState();
- if (state == null || !(state instanceof Sign)) return new String[] { "", "", "", "" };
- Sign sign = (Sign) state;
- String line0 = sign.getLine(0);
- String line1 = sign.getLine(1);
- String line2 = sign.getLine(2);
- String line3 = sign.getLine(3);
- return new String[] {
- line0 != null ? line0 : "",
- line1 != null ? line1 : "",
- line2 != null ? line2 : "",
- line3 != null ? line3 : "",
- };
- }
-
- /**
- * Get a container block's contents.
- *
- * @param pt
- * @return
- */
- private BaseItemStack[] getContainerBlockContents(Vector pt) {
- Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
- if (block == null) {
- return new BaseItemStack[0];
- }
- BlockState state = block.getState();
- if (!(state instanceof org.bukkit.inventory.InventoryHolder)) {
- return new BaseItemStack[0];
- }
-
- org.bukkit.inventory.InventoryHolder container = (org.bukkit.inventory.InventoryHolder) state;
- Inventory inven = container.getInventory();
- if (container instanceof Chest) {
- inven = getBlockInventory((Chest) container);
- }
- int size = inven.getSize();
- BaseItemStack[] contents = new BaseItemStack[size];
-
- for (int i = 0; i < size; ++i) {
- ItemStack bukkitStack = inven.getItem(i);
- if (bukkitStack != null && bukkitStack.getTypeId() > 0) {
- contents[i] = new BaseItemStack(
- bukkitStack.getTypeId(),
- bukkitStack.getAmount(),
- bukkitStack.getDurability());
- try {
- for (Map.Entry entry : bukkitStack.getEnchantments().entrySet()) {
- contents[i].getEnchantments().put(entry.getKey().getId(), entry.getValue());
- }
- } catch (Throwable ignore) {}
- }
- }
-
- return contents;
- }
-
- /**
- * Set a container block's contents.
- *
- * @param pt
- * @param contents
- * @return
- */
- private boolean setContainerBlockContents(Vector pt, BaseItemStack[] contents) {
- Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
- if (block == null) {
- return false;
- }
- BlockState state = block.getState();
- if (!(state instanceof org.bukkit.inventory.InventoryHolder)) {
- return false;
- }
-
- org.bukkit.inventory.InventoryHolder chest = (org.bukkit.inventory.InventoryHolder) state;
- Inventory inven = chest.getInventory();
- if (chest instanceof Chest) {
- inven = getBlockInventory((Chest) chest);
- }
- int size = inven.getSize();
-
- for (int i = 0; i < size; ++i) {
- if (i >= contents.length) {
- break;
- }
-
- if (contents[i] != null) {
- ItemStack toAdd = new ItemStack(contents[i].getType(),
- contents[i].getAmount(),
- contents[i].getData());
- try {
- for (Map.Entry entry : contents[i].getEnchantments().entrySet()) {
- toAdd.addEnchantment(Enchantment.getById(entry.getKey()), entry.getValue());
- }
- } catch (Throwable ignore) {}
- inven.setItem(i, toAdd);
- } else {
- inven.setItem(i, null);
- }
- }
-
- return true;
- }
-
- /**
- * Returns whether a block has a valid ID.
- *
- * @param type
- * @return
- */
- @Override
- public boolean isValidBlockType(int type) {
- if (!skipNmsValidBlockCheck) {
- try {
- return (Boolean) nmsValidBlockMethod.invoke(null, type);
- } catch (Throwable e) {
- skipNmsValidBlockCheck = true;
- }
- }
- return Material.getMaterial(type) != null && Material.getMaterial(type).isBlock();
- }
-
- @Override
- public void checkLoadedChunk(Vector pt) {
- if (!world.isChunkLoaded(pt.getBlockX() >> 4, pt.getBlockZ() >> 4)) {
- world.loadChunk(pt.getBlockX() >> 4, pt.getBlockZ() >> 4);
- }
- }
-
- @Override
- public boolean equals(Object other) {
- if (!(other instanceof BukkitWorld)) {
- return false;
- }
-
- return ((BukkitWorld) other).world.equals(world);
- }
-
- @Override
- public int hashCode() {
- return world.hashCode();
- }
-
- @Override
- public int getMaxY() {
- return world.getMaxHeight() - 1;
- }
-
- @Override
- public void fixAfterFastMode(Iterable chunks) {
- for (BlockVector2D chunkPos : chunks) {
- world.refreshChunk(chunkPos.getBlockX(), chunkPos.getBlockZ());
- }
- }
-
- private static final Map effects = new HashMap();
- static {
- for (Effect effect : Effect.values()) {
- effects.put(effect.getId(), effect);
- }
- }
-
- @Override
- public boolean playEffect(Vector position, int type, int data) {
- final Effect effect = effects.get(type);
- if (effect == null) {
- return false;
- }
-
- world.playEffect(BukkitUtil.toLocation(world, position), effect, data);
-
- return true;
- }
-
- @Override
- public void simulateBlockMine(Vector pt) {
- world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).breakNaturally();
- }
-
- @Override
- public LocalEntity[] getEntities(Region region) {
- List entities = new ArrayList();
- for (Vector2D pt : region.getChunks()) {
- if (!world.isChunkLoaded(pt.getBlockX(), pt.getBlockZ())) {
- continue;
- }
-
- final Entity[] ents = world.getChunkAt(pt.getBlockX(), pt.getBlockZ()).getEntities();
- for (Entity ent : ents) {
- if (region.contains(BukkitUtil.toVector(ent.getLocation()))) {
- entities.add(BukkitUtil.toLocalEntity(ent));
- }
- }
- }
- return entities.toArray(new BukkitEntity[entities.size()]);
- }
-
- @Override
- public int killEntities(LocalEntity... entities) {
- int amount = 0;
- Set toKill = new HashSet();
- for (LocalEntity entity : entities) {
- toKill.add(((BukkitEntity) entity).getEntityId());
- }
- for (Entity entity : world.getEntities()) {
- if (toKill.contains(entity.getUniqueId())) {
- entity.remove();
- ++amount;
- }
- }
- return amount;
- }
-
- @Override
- public BaseBlock getBlock(Vector pt) {
- int type = getBlockType(pt);
- int data = getBlockData(pt);
-
- switch (type) {
- case BlockID.WALL_SIGN:
- case BlockID.SIGN_POST:
- //case BlockID.CHEST: // Prevent data loss for now
- //case BlockID.FURNACE:
- //case BlockID.BURNING_FURNACE:
- //case BlockID.DISPENSER:
- //case BlockID.MOB_SPAWNER:
- case BlockID.NOTE_BLOCK:
- case BlockID.HEAD:
- return super.getBlock(pt);
- default:
- if (!skipNmsAccess) {
- try {
- NmsBlock block = null;
- block = (NmsBlock) nmsGetMethod.invoke(null, getWorld(), pt, type, data);
- if (block != null) {
- return block;
- }
- } catch (Throwable t) {
- logger.log(Level.WARNING,
- "WorldEdit: Failed to do NMS access for direct NBT data copy", t);
- skipNmsAccess = true;
- }
- }
- }
-
- return super.getBlock(pt);
- }
-
- @Override
- public boolean setBlock(Vector pt, com.sk89q.worldedit.foundation.Block block, boolean notifyAdjacent) {
- if (!skipNmsSafeSet) {
- try {
- return (Boolean) nmsSetSafeMethod.invoke(null, this, pt, block, notifyAdjacent);
- } catch (Throwable t) {
- logger.log(Level.WARNING, "WorldEdit: Failed to do NMS safe block set", t);
- skipNmsSafeSet = true;
- }
- }
-
- return super.setBlock(pt, block, notifyAdjacent);
- }
-}
+// $Id$
+/*
+ * WorldEdit
+ * Copyright (C) 2010 sk89q and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+*/
+
+package com.sk89q.worldedit.bukkit;
+
+import com.sk89q.worldedit.*;
+import com.sk89q.worldedit.EntityType;
+import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.blocks.*;
+import com.sk89q.worldedit.blocks.ContainerBlock;
+import com.sk89q.worldedit.blocks.NoteBlock;
+import com.sk89q.worldedit.bukkit.entity.BukkitEntity;
+import com.sk89q.worldedit.regions.Region;
+import com.sk89q.worldedit.util.TreeGenerator;
+import org.bukkit.*;
+import org.bukkit.Location;
+import org.bukkit.block.*;
+import org.bukkit.enchantments.Enchantment;
+import org.bukkit.entity.*;
+import org.bukkit.inventory.DoubleChestInventory;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.plugin.Plugin;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class BukkitWorld extends LocalWorld {
+
+ private static final Logger logger = WorldEdit.logger;
+ private World world;
+ private static boolean skipNmsAccess = false;
+ private static boolean skipNmsSafeSet = false;
+ private static boolean skipNmsValidBlockCheck = false;
+
+ /*
+ * holder for the nmsblock class that we should use
+ */
+ private static Class extends NmsBlock> nmsBlockType;
+ private static Method nmsSetMethod;
+ private static Method nmsValidBlockMethod;
+ private static Method nmsGetMethod;
+ private static Method nmsSetSafeMethod;
+
+ // copied from WG
+ private static > T tryEnum(Class enumType, String ... values) {
+ for (String val : values) {
+ try {
+ return Enum.valueOf(enumType, val);
+ } catch (IllegalArgumentException e) {}
+ }
+ return null;
+ }
+ private static org.bukkit.entity.EntityType tntMinecartType;
+ private static boolean checkMinecartType = true;
+
+ /**
+ * Construct the object.
+ * @param world
+ */
+ @SuppressWarnings("unchecked")
+ public BukkitWorld(World world) {
+ this.world = world;
+
+ if (checkMinecartType) {
+ tntMinecartType = tryEnum(org.bukkit.entity.EntityType.class, "MINECART_TNT");
+ checkMinecartType = false;
+ }
+ // check if we have a class we can use for nms access
+
+ // only run once per server startup
+ if (nmsBlockType != null || skipNmsAccess || skipNmsSafeSet || skipNmsValidBlockCheck) return;
+ Plugin plugin = Bukkit.getPluginManager().getPlugin("WorldEdit");
+ if (!(plugin instanceof WorldEditPlugin)) return; // hopefully never happens
+ WorldEditPlugin wePlugin = ((WorldEditPlugin) plugin);
+ File nmsBlocksDir = new File(wePlugin.getDataFolder() + File.separator + "nmsblocks" + File.separator);
+ if (nmsBlocksDir.listFiles() == null) { // no files to use
+ skipNmsAccess = true; skipNmsSafeSet = true; skipNmsValidBlockCheck = true;
+ return;
+ }
+ try {
+ // make a classloader that can handle our blocks
+ NmsBlockClassLoader loader = new NmsBlockClassLoader(BukkitWorld.class.getClassLoader(), nmsBlocksDir);
+ String filename;
+ for (File f : nmsBlocksDir.listFiles()) {
+ if (!f.isFile()) continue;
+ filename = f.getName();
+ // load class using magic keyword
+ Class> testBlock = null;
+ try {
+ testBlock = loader.loadClass("CL-NMS" + filename);
+ } catch (Throwable e) {
+ // someone is putting things where they don't belong
+ continue;
+ }
+ filename = filename.replaceFirst(".class$", ""); // get rid of extension
+ if (NmsBlock.class.isAssignableFrom(testBlock)) {
+ // got a NmsBlock, test it now
+ Class extends NmsBlock> nmsClass = (Class extends NmsBlock>) testBlock;
+ boolean canUse = false;
+ try {
+ canUse = (Boolean) nmsClass.getMethod("verify").invoke(null);
+ } catch (Throwable e) {
+ continue;
+ }
+ if (!canUse) continue; // not for this server
+ nmsBlockType = nmsClass;
+ nmsSetMethod = nmsBlockType.getMethod("set", World.class, Vector.class, BaseBlock.class);
+ nmsValidBlockMethod = nmsBlockType.getMethod("isValidBlockType", int.class);
+ nmsGetMethod = nmsBlockType.getMethod("get", World.class, Vector.class, int.class, int.class);
+ nmsSetSafeMethod = nmsBlockType.getMethod("setSafely",
+ BukkitWorld.class, Vector.class, com.sk89q.worldedit.foundation.Block.class, boolean.class);
+ // phew
+ break;
+ }
+ }
+ if (nmsBlockType != null) {
+ logger.info("[WorldEdit] Using external NmsBlock for this version: " + nmsBlockType.getName());
+ } else {
+ // try our default
+ try {
+ nmsBlockType = (Class extends NmsBlock>) Class.forName("com.sk89q.worldedit.bukkit.DefaultNmsBlock");
+ boolean canUse = (Boolean) nmsBlockType.getMethod("verify").invoke(null);
+ if (canUse) {
+ nmsSetMethod = nmsBlockType.getMethod("set", World.class, Vector.class, BaseBlock.class);
+ nmsValidBlockMethod = nmsBlockType.getMethod("isValidBlockType", int.class);
+ nmsGetMethod = nmsBlockType.getMethod("get", World.class, Vector.class, int.class, int.class);
+ nmsSetSafeMethod = nmsBlockType.getMethod("setSafely",
+ BukkitWorld.class, Vector.class, com.sk89q.worldedit.foundation.Block.class, boolean.class);
+ logger.info("[WorldEdit] Using inbuilt NmsBlock for this version.");
+ }
+ } catch (Throwable e) {
+ // OMG DEVS WAI U NO SUPPORT SERVER
+ skipNmsAccess = true; skipNmsSafeSet = true; skipNmsValidBlockCheck = true;
+ logger.warning("[WorldEdit] No compatible nms block class found.");
+ }
+ }
+ } catch (Throwable e) {
+ logger.warning("[WorldEdit] Unable to load NmsBlock classes, make sure they are installed correctly.");
+ e.printStackTrace();
+ skipNmsAccess = true; skipNmsSafeSet = true; skipNmsValidBlockCheck = true;
+ }
+ }
+
+ private class NmsBlockClassLoader extends ClassLoader {
+ public File searchDir;
+ public NmsBlockClassLoader(ClassLoader parent, File searchDir) {
+ super(parent);
+ this.searchDir = searchDir;
+ }
+
+ @Override
+ public Class> loadClass(String name) throws ClassNotFoundException {
+ if (!name.startsWith("CL-NMS")) {
+ return super.loadClass(name);
+ } else {
+ name = name.replace("CL-NMS", ""); // hacky lol
+ }
+ try {
+ URL url = new File(searchDir, name).toURI().toURL();
+ InputStream input = url.openConnection().getInputStream();
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+
+ int data = input.read();
+ while (data != -1) {
+ buffer.write(data);
+ data = input.read();
+ }
+ input.close();
+
+ byte[] classData = buffer.toByteArray();
+
+ return defineClass(name.replaceFirst(".class$", ""), classData, 0, classData.length);
+ } catch (Throwable e) {
+ throw new ClassNotFoundException();
+ }
+ }
+ }
+
+ /**
+ * Get the world handle.
+ *
+ * @return
+ */
+ public World getWorld() {
+ return world;
+ }
+
+ /**
+ * Get the name of the world
+ *
+ * @return
+ */
+ @Override
+ public String getName() {
+ return world.getName();
+ }
+
+ /**
+ * Set block type.
+ *
+ * @param pt
+ * @param type
+ * @return
+ */
+ @Override
+ public boolean setBlockType(Vector pt, int type) {
+ return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setTypeId(type);
+ }
+
+ /**
+ * Set block type.
+ *
+ * @param pt
+ * @param type
+ * @return
+ */
+ @Override
+ public boolean setBlockTypeFast(Vector pt, int type) {
+ return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setTypeId(type, false);
+ }
+
+ /**
+ * set block type & data
+ * @param pt
+ * @param type
+ * @param data
+ * @return
+ */
+ @Override
+ public boolean setTypeIdAndData(Vector pt, int type, int data) {
+ return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setTypeIdAndData(type, (byte) data, true);
+ }
+
+ /**
+ * set block type & data
+ * @param pt
+ * @param type
+ * @param data
+ * @return
+ */
+ @Override
+ public boolean setTypeIdAndDataFast(Vector pt, int type, int data) {
+ return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setTypeIdAndData(type, (byte) data, false);
+ }
+
+ /**
+ * Get block type.
+ *
+ * @param pt
+ * @return
+ */
+ @Override
+ public int getBlockType(Vector pt) {
+ return world.getBlockTypeIdAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
+ }
+
+ /**
+ * Set block data.
+ *
+ * @param pt
+ * @param data
+ */
+ @Override
+ public void setBlockData(Vector pt, int data) {
+ world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setData((byte) data);
+ }
+
+ /**
+ * Set block data.
+ *
+ * @param pt
+ * @param data
+ */
+ @Override
+ public void setBlockDataFast(Vector pt, int data) {
+ world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setData((byte) data, false);
+ }
+
+ /**
+ * Get block data.
+ *
+ * @param pt
+ * @return
+ */
+ @Override
+ public int getBlockData(Vector pt) {
+ return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getData();
+ }
+
+ /**
+ * Get block light level.
+ *
+ * @param pt
+ * @return
+ */
+ @Override
+ public int getBlockLightLevel(Vector pt) {
+ return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getLightLevel();
+ }
+
+ /**
+ * Get biome type
+ *
+ * @param pt
+ * @return
+ */
+ @Override
+ public BiomeType getBiome(Vector2D pt) {
+ Biome bukkitBiome = world.getBiome(pt.getBlockX(), pt.getBlockZ());
+ try {
+ return BukkitBiomeType.valueOf(bukkitBiome.name());
+ } catch (IllegalArgumentException exc) {
+ return BiomeType.UNKNOWN;
+ }
+ }
+
+ @Override
+ public void setBiome(Vector2D pt, BiomeType biome) {
+ if (biome instanceof BukkitBiomeType) {
+ Biome bukkitBiome;
+ bukkitBiome = ((BukkitBiomeType) biome).getBukkitBiome();
+ world.setBiome(pt.getBlockX(), pt.getBlockZ(), bukkitBiome);
+ }
+ }
+
+ /**
+ * Regenerate an area.
+ *
+ * @param region
+ * @param editSession
+ * @return
+ */
+ @Override
+ public boolean regenerate(Region region, EditSession editSession) {
+ BaseBlock[] history = new BaseBlock[16 * 16 * (getMaxY() + 1)];
+
+ for (Vector2D chunk : region.getChunks()) {
+ Vector min = new Vector(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16);
+
+ // First save all the blocks inside
+ for (int x = 0; x < 16; ++x) {
+ for (int y = 0; y < (getMaxY() + 1); ++y) {
+ 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);
+ }
+ }
+ }
+
+ try {
+ world.regenerateChunk(chunk.getBlockX(), chunk.getBlockZ());
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+
+ // Then restore
+ for (int x = 0; x < 16; ++x) {
+ for (int y = 0; y < (getMaxY() + 1); ++y) {
+ for (int z = 0; z < 16; ++z) {
+ Vector pt = min.add(x, y, z);
+ int index = y * 16 * 16 + z * 16 + x;
+
+ // We have to restore the block if it was outside
+ if (!region.contains(pt)) {
+ editSession.smartSetBlock(pt, history[index]);
+ } else { // Otherwise fool with history
+ editSession.rememberChange(pt, history[index],
+ editSession.rawGetBlock(pt));
+ }
+ }
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Attempts to accurately copy a BaseBlock's extra data to the world.
+ *
+ * @param pt
+ * @param block
+ * @return
+ */
+ @Override
+ public boolean copyToWorld(Vector pt, BaseBlock block) {
+ if (block instanceof SignBlock) {
+ // Signs
+ setSignText(pt, ((SignBlock) block).getText());
+ return true;
+ }
+
+ if (block instanceof FurnaceBlock) {
+ // Furnaces
+ Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
+ if (bukkitBlock == null) return false;
+ BlockState state = bukkitBlock.getState();
+ if (!(state instanceof Furnace)) return false;
+ Furnace bukkit = (Furnace) state;
+ FurnaceBlock we = (FurnaceBlock) block;
+ bukkit.setBurnTime(we.getBurnTime());
+ bukkit.setCookTime(we.getCookTime());
+ return setContainerBlockContents(pt, ((ContainerBlock) block).getItems());
+ }
+
+ if (block instanceof ContainerBlock) {
+ // Chests/dispenser
+ return setContainerBlockContents(pt, ((ContainerBlock) block).getItems());
+ }
+
+ if (block instanceof MobSpawnerBlock) {
+ // Mob spawners
+ Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
+ if (bukkitBlock == null) return false;
+ BlockState state = bukkitBlock.getState();
+ if (!(state instanceof CreatureSpawner)) return false;
+ CreatureSpawner bukkit = (CreatureSpawner) state;
+ MobSpawnerBlock we = (MobSpawnerBlock) block;
+ bukkit.setCreatureTypeByName(we.getMobType());
+ bukkit.setDelay(we.getDelay());
+ return true;
+ }
+
+ if (block instanceof NoteBlock) {
+ // Note block
+ Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
+ if (bukkitBlock == null) return false;
+ BlockState state = bukkitBlock.getState();
+ if (!(state instanceof org.bukkit.block.NoteBlock)) return false;
+ org.bukkit.block.NoteBlock bukkit = (org.bukkit.block.NoteBlock) state;
+ NoteBlock we = (NoteBlock) block;
+ bukkit.setRawNote(we.getNote());
+ return true;
+ }
+
+ if (block instanceof SkullBlock) {
+ // Skull block
+ Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
+ if (bukkitBlock == null) return false;
+ BlockState state = bukkitBlock.getState();
+ if (!(state instanceof org.bukkit.block.Skull)) return false;
+ Skull bukkit = (Skull) state;
+ SkullBlock we = (SkullBlock) block;
+ // this is dumb
+ SkullType skullType = SkullType.SKELETON;
+ switch (we.getSkullType()) {
+ case 0:
+ skullType = SkullType.SKELETON;
+ break;
+ case 1:
+ skullType = SkullType.WITHER;
+ break;
+ case 2:
+ skullType = SkullType.ZOMBIE;
+ break;
+ case 3:
+ skullType = SkullType.PLAYER;
+ break;
+ case 4:
+ skullType = SkullType.CREEPER;
+ break;
+ }
+ bukkit.setSkullType(skullType);
+ BlockFace rotation;
+ switch (we.getRot()) {
+ // soooo dumb
+ case 0:
+ rotation = BlockFace.NORTH;
+ break;
+ case 1:
+ rotation = BlockFace.NORTH_NORTH_EAST;
+ break;
+ case 2:
+ rotation = BlockFace.NORTH_EAST;
+ break;
+ case 3:
+ rotation = BlockFace.EAST_NORTH_EAST;
+ break;
+ case 4:
+ rotation = BlockFace.EAST;
+ break;
+ case 5:
+ rotation = BlockFace.EAST_SOUTH_EAST;
+ break;
+ case 6:
+ rotation = BlockFace.SOUTH_EAST;
+ break;
+ case 7:
+ rotation = BlockFace.SOUTH_SOUTH_EAST;
+ break;
+ case 8:
+ rotation = BlockFace.SOUTH;
+ break;
+ case 9:
+ rotation = BlockFace.SOUTH_SOUTH_WEST;
+ break;
+ case 10:
+ rotation = BlockFace.SOUTH_WEST;
+ break;
+ case 11:
+ rotation = BlockFace.WEST_SOUTH_WEST;
+ break;
+ case 12:
+ rotation = BlockFace.WEST;
+ break;
+ case 13:
+ rotation = BlockFace.WEST_NORTH_WEST;
+ break;
+ case 14:
+ rotation = BlockFace.NORTH_WEST;
+ break;
+ case 15:
+ rotation = BlockFace.NORTH_NORTH_WEST;
+ break;
+ default:
+ rotation = BlockFace.NORTH;
+ break;
+ }
+ bukkit.setRotation(rotation);
+ if (we.getOwner() != null && !we.getOwner().isEmpty()) bukkit.setOwner(we.getOwner());
+ bukkit.update(true);
+ return true;
+ }
+
+ if (!skipNmsAccess) {
+ try {
+ return (Boolean) nmsSetMethod.invoke(null, world, pt, block);
+ } catch (Throwable t) {
+ logger.log(Level.WARNING, "WorldEdit: Failed to do NMS access for direct NBT data copy", t);
+ skipNmsAccess = true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Attempts to read a BaseBlock's extra data from the world.
+ *
+ * @param pt
+ * @param block
+ * @return
+ */
+ @Override
+ public boolean copyFromWorld(Vector pt, BaseBlock block) {
+ if (block instanceof SignBlock) {
+ // Signs
+ ((SignBlock) block).setText(getSignText(pt));
+ return true;
+ }
+
+ if (block instanceof FurnaceBlock) {
+ // Furnaces
+ Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
+ if (bukkitBlock == null) return false;
+ BlockState state = bukkitBlock.getState();
+ if (!(state instanceof Furnace)) return false;
+ Furnace bukkit = (Furnace) state;
+ FurnaceBlock we = (FurnaceBlock) block;
+ we.setBurnTime(bukkit.getBurnTime());
+ we.setCookTime(bukkit.getCookTime());
+ ((ContainerBlock) block).setItems(getContainerBlockContents(pt));
+ return true;
+ }
+
+ if (block instanceof ContainerBlock) {
+ // Chests/dispenser
+ ((ContainerBlock) block).setItems(getContainerBlockContents(pt));
+ return true;
+ }
+
+ if (block instanceof MobSpawnerBlock) {
+ // Mob spawners
+ Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
+ if (bukkitBlock == null) return false;
+ BlockState state = bukkitBlock.getState();
+ if (!(state instanceof CreatureSpawner)) return false;
+ CreatureSpawner bukkit = (CreatureSpawner) state;
+ MobSpawnerBlock we = (MobSpawnerBlock) block;
+ we.setMobType(bukkit.getCreatureTypeName());
+ we.setDelay((short) bukkit.getDelay());
+ return true;
+ }
+
+ if (block instanceof NoteBlock) {
+ // Note block
+ Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
+ if (bukkitBlock == null) return false;
+ BlockState state = bukkitBlock.getState();
+ if (!(state instanceof org.bukkit.block.NoteBlock)) return false;
+ org.bukkit.block.NoteBlock bukkit = (org.bukkit.block.NoteBlock) state;
+ NoteBlock we = (NoteBlock) block;
+ we.setNote(bukkit.getRawNote());
+ return true;
+ }
+
+ if (block instanceof SkullBlock) {
+ // Skull block
+ Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
+ if (bukkitBlock == null) return false;
+ BlockState state = bukkitBlock.getState();
+ if (!(state instanceof org.bukkit.block.Skull)) return false;
+ Skull bukkit = (Skull) state;
+ SkullBlock we = (SkullBlock) block;
+ byte skullType = 0;
+ switch (bukkit.getSkullType()) {
+ // this is dumb but whoever wrote the class is stupid
+ case SKELETON:
+ skullType = 0;
+ break;
+ case WITHER:
+ skullType = 1;
+ break;
+ case ZOMBIE:
+ skullType = 2;
+ break;
+ case PLAYER:
+ skullType = 3;
+ break;
+ case CREEPER:
+ skullType = 4;
+ break;
+ }
+ we.setSkullType(skullType);
+ byte rot = 0;
+ switch (bukkit.getRotation()) {
+ // this is even more dumb, hurray for copy/paste
+ case NORTH:
+ rot = (byte) 0;
+ break;
+ case NORTH_NORTH_EAST:
+ rot = (byte) 1;
+ break;
+ case NORTH_EAST:
+ rot = (byte) 2;
+ break;
+ case EAST_NORTH_EAST:
+ rot = (byte) 3;
+ break;
+ case EAST:
+ rot = (byte) 4;
+ break;
+ case EAST_SOUTH_EAST:
+ rot = (byte) 5;
+ break;
+ case SOUTH_EAST:
+ rot = (byte) 6;
+ break;
+ case SOUTH_SOUTH_EAST:
+ rot = (byte) 7;
+ break;
+ case SOUTH:
+ rot = (byte) 8;
+ break;
+ case SOUTH_SOUTH_WEST:
+ rot = (byte) 9;
+ break;
+ case SOUTH_WEST:
+ rot = (byte) 10;
+ break;
+ case WEST_SOUTH_WEST:
+ rot = (byte) 11;
+ break;
+ case WEST:
+ rot = (byte) 12;
+ break;
+ case WEST_NORTH_WEST:
+ rot = (byte) 13;
+ break;
+ case NORTH_WEST:
+ rot = (byte) 14;
+ break;
+ case NORTH_NORTH_WEST:
+ rot = (byte) 15;
+ break;
+ }
+ we.setRot(rot);
+ we.setOwner(bukkit.hasOwner() ? bukkit.getOwner() : "");
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Gets the single block inventory for a potentially double chest.
+ * Handles people who have an old version of Bukkit.
+ * This should be replaced with {@link org.bukkit.block.Chest#getBlockInventory()}
+ * in a few months (now = March 2012) // note from future dev - lol
+ *
+ * @param chest The chest to get a single block inventory for
+ * @return The chest's inventory
+ */
+ private Inventory getBlockInventory(Chest chest) {
+ try {
+ return chest.getBlockInventory();
+ } catch (Throwable t) {
+ if (chest.getInventory() instanceof DoubleChestInventory) {
+ DoubleChestInventory inven = (DoubleChestInventory) chest.getInventory();
+ if (inven.getLeftSide().getHolder().equals(chest)) {
+ return inven.getLeftSide();
+ } else if (inven.getRightSide().getHolder().equals(chest)) {
+ return inven.getRightSide();
+ } else {
+ return inven;
+ }
+ } else {
+ return chest.getInventory();
+ }
+ }
+ }
+
+ /**
+ * Clear a chest's contents.
+ *
+ * @param pt
+ */
+ @Override
+ public boolean clearContainerBlockContents(Vector pt) {
+ Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
+ if (block == null) {
+ return false;
+ }
+ BlockState state = block.getState();
+ if (!(state instanceof org.bukkit.inventory.InventoryHolder)) {
+ return false;
+ }
+
+ org.bukkit.inventory.InventoryHolder chest = (org.bukkit.inventory.InventoryHolder) state;
+ Inventory inven = chest.getInventory();
+ if (chest instanceof Chest) {
+ inven = getBlockInventory((Chest) chest);
+ }
+ inven.clear();
+ return true;
+ }
+
+ /**
+ * Generate a tree at a location.
+ *
+ * @param pt
+ * @return
+ */
+ @Override
+ @Deprecated
+ public boolean generateTree(EditSession editSession, Vector pt) {
+ return generateTree(TreeGenerator.TreeType.TREE, editSession, pt);
+ }
+
+ /**
+ * Generate a big tree at a location.
+ *
+ * @param pt
+ * @return
+ */
+ @Override
+ @Deprecated
+ public boolean generateBigTree(EditSession editSession, Vector pt) {
+ return generateTree(TreeGenerator.TreeType.BIG_TREE, editSession, pt);
+ }
+
+ /**
+ * Generate a birch tree at a location.
+ *
+ * @param pt
+ * @return
+ */
+ @Override
+ @Deprecated
+ public boolean generateBirchTree(EditSession editSession, Vector pt) {
+ return generateTree(TreeGenerator.TreeType.BIRCH, editSession, pt);
+ }
+
+ /**
+ * Generate a redwood tree at a location.
+ *
+ * @param pt
+ * @return
+ */
+ @Override
+ @Deprecated
+ public boolean generateRedwoodTree(EditSession editSession, Vector pt) {
+ return generateTree(TreeGenerator.TreeType.REDWOOD, editSession, pt);
+ }
+
+ /**
+ * Generate a redwood tree at a location.
+ *
+ * @param pt
+ * @return
+ */
+ @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);
+
+ static {
+ for (TreeGenerator.TreeType type : TreeGenerator.TreeType.values()) {
+ try {
+ TreeType bukkitType = TreeType.valueOf(type.name());
+ treeTypeMapping.put(type, bukkitType);
+ } catch (IllegalArgumentException e) {
+ // Unhandled TreeType
+ }
+ }
+ // Other mappings for WE-specific values
+ treeTypeMapping.put(TreeGenerator.TreeType.SHORT_JUNGLE, TreeType.SMALL_JUNGLE);
+ treeTypeMapping.put(TreeGenerator.TreeType.RANDOM, TreeType.BROWN_MUSHROOM);
+ treeTypeMapping.put(TreeGenerator.TreeType.RANDOM_REDWOOD, TreeType.REDWOOD);
+ treeTypeMapping.put(TreeGenerator.TreeType.PINE, TreeType.REDWOOD);
+ for (TreeGenerator.TreeType type : TreeGenerator.TreeType.values()) {
+ if (treeTypeMapping.get(type) == null) {
+ WorldEdit.logger.severe("No TreeType mapping for TreeGenerator.TreeType." + type);
+ }
+ }
+ }
+
+ public static TreeType toBukkitTreeType(TreeGenerator.TreeType type) {
+ return treeTypeMapping.get(type);
+ }
+
+ @Override
+ public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector pt) {
+ TreeType bukkitType = toBukkitTreeType(type);
+ return type != null && world.generateTree(BukkitUtil.toLocation(world, pt), bukkitType,
+ new EditSessionBlockChangeDelegate(editSession));
+ }
+
+ /**
+ * Drop an item.
+ *
+ * @param pt
+ * @param item
+ */
+ @Override
+ public void dropItem(Vector pt, BaseItemStack item) {
+ ItemStack bukkitItem = new ItemStack(item.getType(), item.getAmount(),
+ item.getData());
+ world.dropItemNaturally(BukkitUtil.toLocation(world, pt), bukkitItem);
+ }
+
+ /**
+ * Kill mobs in an area.
+ *
+ * @param origin The center of the area to kill mobs in.
+ * @param radius Maximum distance to kill mobs at; radius < 0 means kill all mobs
+ * @param flags various flags that determine what to kill
+ * @return number of mobs killed
+ */
+ @Override
+ public int killMobs(Vector origin, double radius, int flags) {
+ boolean killPets = (flags & KillFlags.PETS) != 0;
+ boolean killNPCs = (flags & KillFlags.NPCS) != 0;
+ boolean killAnimals = (flags & KillFlags.ANIMALS) != 0;
+ boolean withLightning = (flags & KillFlags.WITH_LIGHTNING) != 0;
+ boolean killGolems = (flags & KillFlags.GOLEMS) != 0;
+ boolean killAmbient = (flags & KillFlags.AMBIENT) != 0;
+
+ int num = 0;
+ double radiusSq = radius * radius;
+
+ Location bukkitOrigin = BukkitUtil.toLocation(world, origin);
+
+ for (LivingEntity ent : world.getLivingEntities()) {
+ if (ent instanceof HumanEntity) {
+ continue;
+ }
+
+ if (!killAnimals && ent instanceof Animals) {
+ continue;
+ }
+
+ if (!killPets && ent instanceof Tameable && ((Tameable) ent).isTamed()) {
+ continue; // tamed pet
+ }
+
+ if (!killGolems && ent instanceof Golem) {
+ continue;
+ }
+
+ if (!killNPCs && ent instanceof Villager) {
+ continue;
+ }
+
+ if (!killAmbient && ent instanceof Ambient) {
+ continue;
+ }
+
+ if (radius < 0 || bukkitOrigin.distanceSquared(ent.getLocation()) <= radiusSq) {
+ if (withLightning) {
+ world.strikeLightningEffect(ent.getLocation());
+ }
+ ent.remove();
+ ++num;
+ }
+ }
+
+ return num;
+ }
+
+ /**
+ * Remove entities in an area.
+ *
+ * @param origin
+ * @param radius
+ * @return
+ */
+ @Override
+ public int removeEntities(EntityType type, Vector origin, int radius) {
+ int num = 0;
+ double radiusSq = Math.pow(radius, 2);
+
+ for (Entity ent : world.getEntities()) {
+ if (radius != -1
+ && origin.distanceSq(BukkitUtil.toVector(ent.getLocation())) > radiusSq) {
+ continue;
+ }
+
+ switch (type) {
+ case ALL:
+ if (ent instanceof Projectile || ent instanceof Boat || ent instanceof Item
+ || ent instanceof FallingBlock || ent instanceof Minecart || ent instanceof Hanging
+ || ent instanceof TNTPrimed || ent instanceof ExperienceOrb) {
+ ent.remove();
+ num++;
+ }
+ break;
+
+ case PROJECTILES:
+ case ARROWS:
+ if (ent instanceof Projectile) {
+ // covers: arrow, egg, enderpearl, fireball, fish, snowball, throwpotion, thrownexpbottle
+ ent.remove();
+ ++num;
+ }
+ break;
+
+ case BOATS:
+ if (ent instanceof Boat) {
+ ent.remove();
+ ++num;
+ }
+ break;
+
+ case ITEMS:
+ if (ent instanceof Item) {
+ ent.remove();
+ ++num;
+ }
+ break;
+
+ case FALLING_BLOCKS:
+ if (ent instanceof FallingBlock) {
+ ent.remove();
+ ++num;
+ }
+ break;
+
+ case MINECARTS:
+ if (ent instanceof Minecart) {
+ ent.remove();
+ ++num;
+ }
+ break;
+
+ case PAINTINGS:
+ if (ent instanceof Painting) {
+ ent.remove();
+ ++num;
+ }
+ break;
+
+ case ITEM_FRAMES:
+ if (ent instanceof ItemFrame) {
+ ent.remove();
+ ++num;
+ }
+ break;
+
+ case TNT:
+ if (ent instanceof TNTPrimed || ent.getType() == tntMinecartType) {
+ ent.remove();
+ ++num;
+ }
+ break;
+
+ case XP_ORBS:
+ if (ent instanceof ExperienceOrb) {
+ ent.remove();
+ ++num;
+ }
+ break;
+ }
+ }
+
+ return num;
+ }
+
+ /**
+ * Set a sign's text.
+ *
+ * @param pt
+ * @param text
+ * @return
+ */
+ private boolean setSignText(Vector pt, String[] text) {
+ Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
+ if (block == null) return false;
+ BlockState state = block.getState();
+ if (state == null || !(state instanceof Sign)) return false;
+ Sign sign = (Sign) state;
+ sign.setLine(0, text[0]);
+ sign.setLine(1, text[1]);
+ sign.setLine(2, text[2]);
+ sign.setLine(3, text[3]);
+ sign.update();
+ return true;
+ }
+
+ /**
+ * Get a sign's text.
+ *
+ * @param pt
+ * @return
+ */
+ private String[] getSignText(Vector pt) {
+ Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
+ if (block == null) return new String[] { "", "", "", "" };
+ BlockState state = block.getState();
+ if (state == null || !(state instanceof Sign)) return new String[] { "", "", "", "" };
+ Sign sign = (Sign) state;
+ String line0 = sign.getLine(0);
+ String line1 = sign.getLine(1);
+ String line2 = sign.getLine(2);
+ String line3 = sign.getLine(3);
+ return new String[] {
+ line0 != null ? line0 : "",
+ line1 != null ? line1 : "",
+ line2 != null ? line2 : "",
+ line3 != null ? line3 : "",
+ };
+ }
+
+ /**
+ * Get a container block's contents.
+ *
+ * @param pt
+ * @return
+ */
+ private BaseItemStack[] getContainerBlockContents(Vector pt) {
+ Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
+ if (block == null) {
+ return new BaseItemStack[0];
+ }
+ BlockState state = block.getState();
+ if (!(state instanceof org.bukkit.inventory.InventoryHolder)) {
+ return new BaseItemStack[0];
+ }
+
+ org.bukkit.inventory.InventoryHolder container = (org.bukkit.inventory.InventoryHolder) state;
+ Inventory inven = container.getInventory();
+ if (container instanceof Chest) {
+ inven = getBlockInventory((Chest) container);
+ }
+ int size = inven.getSize();
+ BaseItemStack[] contents = new BaseItemStack[size];
+
+ for (int i = 0; i < size; ++i) {
+ ItemStack bukkitStack = inven.getItem(i);
+ if (bukkitStack != null && bukkitStack.getTypeId() > 0) {
+ contents[i] = new BaseItemStack(
+ bukkitStack.getTypeId(),
+ bukkitStack.getAmount(),
+ bukkitStack.getDurability());
+ try {
+ for (Map.Entry entry : bukkitStack.getEnchantments().entrySet()) {
+ contents[i].getEnchantments().put(entry.getKey().getId(), entry.getValue());
+ }
+ } catch (Throwable ignore) {}
+ }
+ }
+
+ return contents;
+ }
+
+ /**
+ * Set a container block's contents.
+ *
+ * @param pt
+ * @param contents
+ * @return
+ */
+ private boolean setContainerBlockContents(Vector pt, BaseItemStack[] contents) {
+ Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
+ if (block == null) {
+ return false;
+ }
+ BlockState state = block.getState();
+ if (!(state instanceof org.bukkit.inventory.InventoryHolder)) {
+ return false;
+ }
+
+ org.bukkit.inventory.InventoryHolder chest = (org.bukkit.inventory.InventoryHolder) state;
+ Inventory inven = chest.getInventory();
+ if (chest instanceof Chest) {
+ inven = getBlockInventory((Chest) chest);
+ }
+ int size = inven.getSize();
+
+ for (int i = 0; i < size; ++i) {
+ if (i >= contents.length) {
+ break;
+ }
+
+ if (contents[i] != null) {
+ ItemStack toAdd = new ItemStack(contents[i].getType(),
+ contents[i].getAmount(),
+ contents[i].getData());
+ try {
+ for (Map.Entry entry : contents[i].getEnchantments().entrySet()) {
+ toAdd.addEnchantment(Enchantment.getById(entry.getKey()), entry.getValue());
+ }
+ } catch (Throwable ignore) {}
+ inven.setItem(i, toAdd);
+ } else {
+ inven.setItem(i, null);
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns whether a block has a valid ID.
+ *
+ * @param type
+ * @return
+ */
+ @Override
+ public boolean isValidBlockType(int type) {
+ if (!skipNmsValidBlockCheck) {
+ try {
+ return (Boolean) nmsValidBlockMethod.invoke(null, type);
+ } catch (Throwable e) {
+ skipNmsValidBlockCheck = true;
+ }
+ }
+ return Material.getMaterial(type) != null && Material.getMaterial(type).isBlock();
+ }
+
+ @Override
+ public void checkLoadedChunk(Vector pt) {
+ if (!world.isChunkLoaded(pt.getBlockX() >> 4, pt.getBlockZ() >> 4)) {
+ world.loadChunk(pt.getBlockX() >> 4, pt.getBlockZ() >> 4);
+ }
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof BukkitWorld)) {
+ return false;
+ }
+
+ return ((BukkitWorld) other).world.equals(world);
+ }
+
+ @Override
+ public int hashCode() {
+ return world.hashCode();
+ }
+
+ @Override
+ public int getMaxY() {
+ return world.getMaxHeight() - 1;
+ }
+
+ @Override
+ public void fixAfterFastMode(Iterable chunks) {
+ for (BlockVector2D chunkPos : chunks) {
+ world.refreshChunk(chunkPos.getBlockX(), chunkPos.getBlockZ());
+ }
+ }
+
+ private static final Map effects = new HashMap();
+ static {
+ for (Effect effect : Effect.values()) {
+ effects.put(effect.getId(), effect);
+ }
+ }
+
+ @Override
+ public boolean playEffect(Vector position, int type, int data) {
+ final Effect effect = effects.get(type);
+ if (effect == null) {
+ return false;
+ }
+
+ world.playEffect(BukkitUtil.toLocation(world, position), effect, data);
+
+ return true;
+ }
+
+ @Override
+ public void simulateBlockMine(Vector pt) {
+ world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).breakNaturally();
+ }
+
+ @Override
+ public LocalEntity[] getEntities(Region region) {
+ List entities = new ArrayList();
+ for (Vector2D pt : region.getChunks()) {
+ if (!world.isChunkLoaded(pt.getBlockX(), pt.getBlockZ())) {
+ continue;
+ }
+
+ final Entity[] ents = world.getChunkAt(pt.getBlockX(), pt.getBlockZ()).getEntities();
+ for (Entity ent : ents) {
+ if (region.contains(BukkitUtil.toVector(ent.getLocation()))) {
+ entities.add(BukkitUtil.toLocalEntity(ent));
+ }
+ }
+ }
+ return entities.toArray(new BukkitEntity[entities.size()]);
+ }
+
+ @Override
+ public int killEntities(LocalEntity... entities) {
+ int amount = 0;
+ Set toKill = new HashSet();
+ for (LocalEntity entity : entities) {
+ toKill.add(((BukkitEntity) entity).getEntityId());
+ }
+ for (Entity entity : world.getEntities()) {
+ if (toKill.contains(entity.getUniqueId())) {
+ entity.remove();
+ ++amount;
+ }
+ }
+ return amount;
+ }
+
+ @Override
+ public BaseBlock getBlock(Vector pt) {
+ int type = getBlockType(pt);
+ int data = getBlockData(pt);
+
+ switch (type) {
+ case BlockID.WALL_SIGN:
+ case BlockID.SIGN_POST:
+ //case BlockID.CHEST: // Prevent data loss for now
+ //case BlockID.FURNACE:
+ //case BlockID.BURNING_FURNACE:
+ //case BlockID.DISPENSER:
+ //case BlockID.MOB_SPAWNER:
+ case BlockID.NOTE_BLOCK:
+ case BlockID.HEAD:
+ return super.getBlock(pt);
+ default:
+ if (!skipNmsAccess) {
+ try {
+ NmsBlock block = null;
+ block = (NmsBlock) nmsGetMethod.invoke(null, getWorld(), pt, type, data);
+ if (block != null) {
+ return block;
+ }
+ } catch (Throwable t) {
+ logger.log(Level.WARNING,
+ "WorldEdit: Failed to do NMS access for direct NBT data copy", t);
+ skipNmsAccess = true;
+ }
+ }
+ }
+
+ return super.getBlock(pt);
+ }
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public BaseBlock getLazyBlock(Vector position) {
+ Block bukkitBlock = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
+ return new LazyBlock(bukkitBlock.getTypeId(), bukkitBlock.getData(), this, position);
+ }
+
+ @Override
+ public boolean setBlock(Vector pt, BaseBlock block, boolean notifyAdjacent) {
+ if (!skipNmsSafeSet) {
+ try {
+ return (Boolean) nmsSetSafeMethod.invoke(null, this, pt, block, notifyAdjacent);
+ } catch (Throwable t) {
+ logger.log(Level.WARNING, "WorldEdit: Failed to do NMS safe block set", t);
+ skipNmsSafeSet = true;
+ }
+ }
+
+ return super.setBlock(pt, block, notifyAdjacent);
+ }
+}
diff --git a/src/main/java/com/sk89q/worldedit/bukkit/CUIChannelListener.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/CUIChannelListener.java
similarity index 100%
rename from src/main/java/com/sk89q/worldedit/bukkit/CUIChannelListener.java
rename to src/bukkit/java/com/sk89q/worldedit/bukkit/CUIChannelListener.java
diff --git a/src/main/java/com/sk89q/worldedit/bukkit/DefaultNmsBlock.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/DefaultNmsBlock.java
similarity index 97%
rename from src/main/java/com/sk89q/worldedit/bukkit/DefaultNmsBlock.java
rename to src/bukkit/java/com/sk89q/worldedit/bukkit/DefaultNmsBlock.java
index 23fd20561..2e718757b 100644
--- a/src/main/java/com/sk89q/worldedit/bukkit/DefaultNmsBlock.java
+++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/DefaultNmsBlock.java
@@ -1,436 +1,436 @@
-package com.sk89q.worldedit.bukkit;
-// $Id$
-/*
- * This file is a part of WorldEdit.
- * Copyright (c) sk89q
- * Copyright (c) the 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
- * (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
- * GNU 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 .
- */
-
-import com.sk89q.jnbt.*;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.WorldEdit;
-import com.sk89q.worldedit.blocks.BaseBlock;
-import com.sk89q.worldedit.blocks.TileEntityBlock;
-import com.sk89q.worldedit.data.DataException;
-import com.sk89q.worldedit.foundation.Block;
-import net.minecraft.server.v1_7_R2.*;
-import org.bukkit.World;
-import org.bukkit.craftbukkit.v1_7_R2.CraftWorld;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.*;
-import java.util.logging.Logger;
-
-/**
- * A blind handler of blocks with TileEntity data that directly access Minecraft's
- * classes through CraftBukkit.
- *
- * Usage of this class may break terribly in the future, and therefore usage should
- * be trapped in a handler for {@link Throwable}.
- */
-public class DefaultNmsBlock extends NmsBlock {
-
- private static final Logger logger = WorldEdit.logger;
- private static Field compoundMapField;
- private static final Field nmsBlock_isTileEntityField; // The field is deobfuscated but the method isn't. No idea why.
- private NBTTagCompound nbtData = null;
-
- static {
- Field field;
- try {
- field = net.minecraft.server.v1_7_R2.Block.class.getDeclaredField("isTileEntity");
- field.setAccessible(true);
- } catch (NoSuchFieldException e) {
- // logger.severe("Could not find NMS block tile entity field!");
- field = null;
- }
- nmsBlock_isTileEntityField = field;
- }
-
- public static boolean verify() {
- return nmsBlock_isTileEntityField != null;
- }
-
- /**
- * Create a new instance with a given type ID, data value, and previous
- * {@link TileEntityBlock}-implementing object.
- *
- * @param type block type ID
- * @param data data value
- * @param tileEntityBlock tile entity block
- */
- public DefaultNmsBlock(int type, int data, TileEntityBlock tileEntityBlock) {
- super(type, data);
-
- nbtData = (NBTTagCompound) fromNative(tileEntityBlock.getNbtData());
- }
-
- /**
- * Create a new instance with a given type ID, data value, and raw
- * {@link NBTTagCompound} copy.
- *
- * @param type block type ID
- * @param data data value
- * @param nbtData raw NBT data
- */
- public DefaultNmsBlock(int type, int data, NBTTagCompound nbtData) {
- super(type, data);
-
- this.nbtData = nbtData;
- }
-
- /**
- * Build a {@link NBTTagCompound} that has valid coordinates.
- *
- * @param pt coordinates to set
- * @return the tag compound
- */
- private NBTTagCompound getNmsData(Vector pt) {
- if (nbtData == null) {
- return null;
- }
-
- nbtData.set("x", new NBTTagInt(pt.getBlockX()));
- nbtData.set("y", new NBTTagInt(pt.getBlockY()));
- nbtData.set("z", new NBTTagInt(pt.getBlockZ()));
-
- return nbtData;
- }
-
- @Override
- public boolean hasNbtData() {
- return nbtData != null;
- }
-
- @Override
- public String getNbtId() {
- if (nbtData == null) {
- return "";
- }
-
- return nbtData.getString("id");
- }
-
- @Override
- public CompoundTag getNbtData() {
- if (nbtData == null) {
- return new CompoundTag(getNbtId(),
- new HashMap());
- }
- return (CompoundTag) toNative(nbtData);
- }
-
- @Override
- public void setNbtData(CompoundTag tag) throws DataException {
- if (tag == null) {
- this.nbtData = null;
- }
- this.nbtData = (NBTTagCompound) fromNative(tag);
- }
-
- /**
- * Build an instance from the given information.
- *
- * @param world world to get the block from
- * @param position position to get the block at
- * @param type type ID of block
- * @param data data value of block
- * @return the block, or null
- */
- public static DefaultNmsBlock get(World world, Vector position, int type, int data) {
- if (!hasTileEntity(type)) {
- return null;
- }
-
- TileEntity te = ((CraftWorld) world).getHandle().getTileEntity(
- position.getBlockX(), position.getBlockY(), position.getBlockZ());
-
- if (te != null) {
- NBTTagCompound tag = new NBTTagCompound();
- te.b(tag); // Load data
- return new DefaultNmsBlock(type, data, tag);
- }
-
- return null;
- }
-
- /**
- * Set an instance or a {@link TileEntityBlock} to the given position.
- *
- * @param world world to set the block in
- * @param position position to set the block at
- * @param block the block to set
- * @return true if tile entity data was copied to the world
- */
- public static boolean set(World world, Vector position, BaseBlock block) {
- NBTTagCompound data = null;
- if (!hasTileEntity(world.getBlockTypeIdAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()))) {
- return false;
- }
-
- if (block instanceof DefaultNmsBlock) {
- DefaultNmsBlock nmsProxyBlock = (DefaultNmsBlock) block;
- data = nmsProxyBlock.getNmsData(position);
- } else if (block instanceof TileEntityBlock) {
- DefaultNmsBlock nmsProxyBlock = new DefaultNmsBlock(
- block.getId(), block.getData(), block);
- data = nmsProxyBlock.getNmsData(position);
- }
-
- if (data != null) {
- TileEntity te = ((CraftWorld) world).getHandle().getTileEntity(
- position.getBlockX(), position.getBlockY(), position.getBlockZ());
- if (te != null) {
- te.a(data); // Load data
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Tries to set a block 'safely', as in setting the block data to the location, and
- * then triggering physics only at the end.
- *
- * @param world world to set the block in
- * @param position position to set the block at
- * @param block the block to set
- * @param notifyAdjacent true to notify physics and what not
- * @return true if block id or data was changed
- */
- public static boolean setSafely(BukkitWorld world, Vector position,
- Block block, boolean notifyAdjacent) {
-
- int x = position.getBlockX();
- int y = position.getBlockY();
- int z = position.getBlockZ();
-
- CraftWorld craftWorld = ((CraftWorld) world.getWorld());
-// TileEntity te = craftWorld.getHandle().getTileEntity(x, y, z);
-// craftWorld.getHandle().tileEntityList.remove(te);
-
- boolean changed = craftWorld.getHandle().setTypeAndData(x, y, z, getNmsBlock(block.getId()), block.getData(), 0);
-
- if (block instanceof BaseBlock) {
- world.copyToWorld(position, (BaseBlock) block);
- }
-
- changed = craftWorld.getHandle().setData(x, y, z, block.getData(), 0) || changed;
- if (changed && notifyAdjacent) {
- craftWorld.getHandle().notify(x, y, z);
- craftWorld.getHandle().update(x, y, z, getNmsBlock(block.getId()));
- }
-
- return changed;
- }
-
- public static boolean hasTileEntity(int type) {
- net.minecraft.server.v1_7_R2.Block nmsBlock = getNmsBlock(type);
- if (nmsBlock == null) {
- return false;
- }
-
- try {
- return nmsBlock_isTileEntityField.getBoolean(nmsBlock); // Once we have the field stord, gets are fast
- } catch (IllegalAccessException e) {
- return false;
- }
- }
-
- public static net.minecraft.server.v1_7_R2.Block getNmsBlock(int type) {
- return net.minecraft.server.v1_7_R2.Block.e(type);
- }
-
- /**
- * Converts from a non-native NMS NBT structure to a native WorldEdit NBT
- * structure.
- *
- * @param foreign non-native NMS NBT structure
- * @return native WorldEdit NBT structure
- */
- private static Tag toNative(NBTBase foreign) {
- // temporary fix since mojang removed names from tags
- // our nbt spec will need to be updated to theirs
- return toNative(NBTBase.getTagName(foreign.getTypeId()), foreign);
- }
-
- /**
- * Converts from a non-native NMS NBT structure to a native WorldEdit NBT
- * structure.
- *
- * @param foreign non-native NMS NBT structure
- * @param name name for the tag, if it has one
- * @return native WorldEdit NBT structure
- */
- @SuppressWarnings("unchecked")
- private static Tag toNative(String name, NBTBase foreign) {
- if (foreign == null) {
- return null;
- }
- if (foreign instanceof NBTTagCompound) {
- Map values = new HashMap();
- Collection