From 6c460f02c54b5bf0c34d2215b65fb1143d57bc1c Mon Sep 17 00:00:00 2001 From: sk89q Date: Wed, 2 Apr 2014 20:03:52 -0700 Subject: [PATCH] Split up source files into several source directories. --- pom.xml | 363 ++- .../sk89q/wepif/DinnerPermsResolverTest.java | 0 .../sk89q/wepif/TestOfflinePermissible.java | 0 .../worldedit/bukkit/BukkitWorldTest.java | 0 .../com/sk89q/bukkit/util/CommandInfo.java | 0 .../bukkit/util/CommandRegistration.java | 0 .../util/CommandsManagerRegistration.java | 0 .../bukkit/util/DynamicPluginCommand.java | 0 .../util/DynamicPluginCommandHelpTopic.java | 0 .../util/FallbackRegistrationListener.java | 0 .../ConfigurationPermissionsResolver.java | 340 +-- .../com/sk89q/wepif/DinnerPermsResolver.java | 0 .../wepif/FlatFilePermissionsResolver.java | 474 +-- .../com/sk89q/wepif/GroupManagerResolver.java | 0 .../sk89q/wepif/NijiPermissionsResolver.java | 322 +- .../sk89q/wepif/PermissionsExResolver.java | 0 .../com/sk89q/wepif/PermissionsProvider.java | 80 +- .../com/sk89q/wepif/PermissionsResolver.java | 52 +- .../wepif/PermissionsResolverManager.java | 596 ++-- .../wepif/PluginPermissionsResolver.java | 190 +- .../sk89q/wepif/WEPIFRuntimeException.java | 62 +- .../com/sk89q/wepif/bPermissionsResolver.java | 0 .../worldedit/bukkit/BukkitBiomeType.java | 0 .../worldedit/bukkit/BukkitBiomeTypes.java | 0 .../worldedit/bukkit/BukkitCommandSender.java | 268 +- .../worldedit/bukkit/BukkitConfiguration.java | 0 .../sk89q/worldedit/bukkit/BukkitPlayer.java | 342 +-- .../bukkit/BukkitPlayerBlockBag.java | 456 +-- .../bukkit/BukkitServerInterface.java | 250 +- .../sk89q/worldedit/bukkit/BukkitUtil.java | 390 +-- .../sk89q/worldedit/bukkit/BukkitWorld.java | 2656 ++++++++--------- .../worldedit/bukkit/CUIChannelListener.java | 0 .../worldedit/bukkit/DefaultNmsBlock.java | 872 +++--- .../EditSessionBlockChangeDelegate.java | 152 +- .../com/sk89q/worldedit/bukkit/NmsBlock.java | 82 +- .../sk89q/worldedit/bukkit/SessionTimer.java | 102 +- .../sk89q/worldedit/bukkit/WorldEditAPI.java | 84 +- .../worldedit/bukkit/WorldEditListener.java | 356 +-- .../worldedit/bukkit/WorldEditPlugin.java | 849 +++--- .../worldedit/bukkit/entity/BukkitEntity.java | 0 .../worldedit/bukkit/entity/BukkitExpOrb.java | 0 .../worldedit/bukkit/entity/BukkitItem.java | 0 .../bukkit/entity/BukkitPainting.java | 0 .../bukkit/selections/CuboidSelection.java | 134 +- .../selections/Polygonal2DSelection.java | 124 +- .../bukkit/selections/RegionSelection.java | 212 +- .../bukkit/selections/Selection.java | 210 +- src/{main => bukkit}/resources/config.yml | 144 +- .../resources/nmsblocks/CBXNmsBlock_145.class | Bin .../resources/nmsblocks/CBXNmsBlock_146.class | Bin .../resources/nmsblocks/CBXNmsBlock_147.class | Bin .../resources/nmsblocks/CBXNmsBlock_15.class | Bin .../resources/nmsblocks/CBXNmsBlock_152.class | Bin .../resources/nmsblocks/CBXNmsBlock_161.class | Bin .../resources/nmsblocks/CBXNmsBlock_162.class | Bin .../resources/nmsblocks/CBXNmsBlock_164.class | Bin .../resources/nmsblocks/CBXNmsBlock_172.class | Bin .../resources/nmsblocks/CBXNmsBlock_175.class | Bin .../nmsblocks/CBXNmsBlock_prePackage.class | Bin .../nmsblocks/CBXNmsBlock_v152_2.class | Bin .../nmsblocks/MCPCPlusXNmsBlock_147.class | Bin .../nmsblocks/MCPCPlusXNmsBlock_151dv.class | Bin .../nmsblocks/MCPCPlusXNmsBlock_162.class | Bin .../nmsblocks/MCPCPlusXNmsBlock_164.class | Bin src/{main => bukkit}/resources/plugin.yml | 0 .../sk89q/worldedit/masks/AbstractMask.java | 32 +- .../sk89q/worldedit/masks/BiomeTypeMask.java | 0 .../com/sk89q/worldedit/masks/BlockMask.java | 0 .../sk89q/worldedit/masks/BlockTypeMask.java | 104 +- .../sk89q/worldedit/masks/CombinedMask.java | 168 +- .../worldedit/masks/DynamicRegionMask.java | 0 .../worldedit/masks/ExistingBlockMask.java | 70 +- .../sk89q/worldedit/masks/FuzzyBlockMask.java | 0 .../masks/InvertedBlockTypeMask.java | 108 +- .../sk89q/worldedit/masks/InvertedMask.java | 0 .../java/com/sk89q/worldedit/masks/Mask.java | 106 +- .../com/sk89q/worldedit/masks/RandomMask.java | 0 .../com/sk89q/worldedit/masks/RegionMask.java | 82 +- .../sk89q/worldedit/masks/SolidBlockMask.java | 32 +- .../worldedit/masks/UnderOverlayMask.java | 0 .../sk89q/worldedit/patterns/BlockChance.java | 0 .../worldedit/patterns/ClipboardPattern.java | 150 +- .../com/sk89q/worldedit/patterns/Pattern.java | 0 .../worldedit/patterns/RandomFillPattern.java | 0 .../patterns/SingleBlockPattern.java | 0 85 files changed, 5577 insertions(+), 5437 deletions(-) rename src/{test => bukkit-test}/java/com/sk89q/wepif/DinnerPermsResolverTest.java (100%) rename src/{test => bukkit-test}/java/com/sk89q/wepif/TestOfflinePermissible.java (100%) rename src/{test => bukkit-test}/java/com/sk89q/worldedit/bukkit/BukkitWorldTest.java (100%) rename src/{main => bukkit}/java/com/sk89q/bukkit/util/CommandInfo.java (100%) rename src/{main => bukkit}/java/com/sk89q/bukkit/util/CommandRegistration.java (100%) rename src/{main => bukkit}/java/com/sk89q/bukkit/util/CommandsManagerRegistration.java (100%) rename src/{main => bukkit}/java/com/sk89q/bukkit/util/DynamicPluginCommand.java (100%) rename src/{main => bukkit}/java/com/sk89q/bukkit/util/DynamicPluginCommandHelpTopic.java (100%) rename src/{main => bukkit}/java/com/sk89q/bukkit/util/FallbackRegistrationListener.java (100%) rename src/{main => bukkit}/java/com/sk89q/wepif/ConfigurationPermissionsResolver.java (97%) rename src/{main => bukkit}/java/com/sk89q/wepif/DinnerPermsResolver.java (100%) rename src/{main => bukkit}/java/com/sk89q/wepif/FlatFilePermissionsResolver.java (96%) rename src/{main => bukkit}/java/com/sk89q/wepif/GroupManagerResolver.java (100%) rename src/{main => bukkit}/java/com/sk89q/wepif/NijiPermissionsResolver.java (97%) rename src/{main => bukkit}/java/com/sk89q/wepif/PermissionsExResolver.java (100%) rename src/{main => bukkit}/java/com/sk89q/wepif/PermissionsProvider.java (97%) rename src/{main => bukkit}/java/com/sk89q/wepif/PermissionsResolver.java (97%) rename src/{main => bukkit}/java/com/sk89q/wepif/PermissionsResolverManager.java (97%) rename src/{main => bukkit}/java/com/sk89q/wepif/PluginPermissionsResolver.java (97%) rename src/{main => bukkit}/java/com/sk89q/wepif/WEPIFRuntimeException.java (97%) rename src/{main => bukkit}/java/com/sk89q/wepif/bPermissionsResolver.java (100%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/BukkitBiomeType.java (100%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/BukkitBiomeTypes.java (100%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java (96%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/BukkitConfiguration.java (100%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java (96%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java (96%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java (97%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/BukkitUtil.java (97%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/BukkitWorld.java (97%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/CUIChannelListener.java (100%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/DefaultNmsBlock.java (97%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java (97%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/NmsBlock.java (95%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/SessionTimer.java (96%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/WorldEditAPI.java (96%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/WorldEditListener.java (97%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java (93%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/entity/BukkitEntity.java (100%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/entity/BukkitExpOrb.java (100%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/entity/BukkitItem.java (100%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/entity/BukkitPainting.java (100%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/selections/CuboidSelection.java (96%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/selections/Polygonal2DSelection.java (97%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/selections/RegionSelection.java (96%) rename src/{main => bukkit}/java/com/sk89q/worldedit/bukkit/selections/Selection.java (95%) rename src/{main => bukkit}/resources/config.yml (96%) rename src/{main => bukkit}/resources/nmsblocks/CBXNmsBlock_145.class (100%) rename src/{main => bukkit}/resources/nmsblocks/CBXNmsBlock_146.class (100%) rename src/{main => bukkit}/resources/nmsblocks/CBXNmsBlock_147.class (100%) rename src/{main => bukkit}/resources/nmsblocks/CBXNmsBlock_15.class (100%) rename src/{main => bukkit}/resources/nmsblocks/CBXNmsBlock_152.class (100%) rename src/{main => bukkit}/resources/nmsblocks/CBXNmsBlock_161.class (100%) rename src/{main => bukkit}/resources/nmsblocks/CBXNmsBlock_162.class (100%) rename src/{main => bukkit}/resources/nmsblocks/CBXNmsBlock_164.class (100%) rename src/{main => bukkit}/resources/nmsblocks/CBXNmsBlock_172.class (100%) rename src/{main => bukkit}/resources/nmsblocks/CBXNmsBlock_175.class (100%) rename src/{main => bukkit}/resources/nmsblocks/CBXNmsBlock_prePackage.class (100%) rename src/{main => bukkit}/resources/nmsblocks/CBXNmsBlock_v152_2.class (100%) rename src/{main => bukkit}/resources/nmsblocks/MCPCPlusXNmsBlock_147.class (100%) rename src/{main => bukkit}/resources/nmsblocks/MCPCPlusXNmsBlock_151dv.class (100%) rename src/{main => bukkit}/resources/nmsblocks/MCPCPlusXNmsBlock_162.class (100%) rename src/{main => bukkit}/resources/nmsblocks/MCPCPlusXNmsBlock_164.class (100%) rename src/{main => bukkit}/resources/plugin.yml (100%) rename src/{main => legacy}/java/com/sk89q/worldedit/masks/AbstractMask.java (96%) rename src/{main => legacy}/java/com/sk89q/worldedit/masks/BiomeTypeMask.java (100%) rename src/{main => legacy}/java/com/sk89q/worldedit/masks/BlockMask.java (100%) rename src/{main => legacy}/java/com/sk89q/worldedit/masks/BlockTypeMask.java (96%) rename src/{main => legacy}/java/com/sk89q/worldedit/masks/CombinedMask.java (96%) rename src/{main => legacy}/java/com/sk89q/worldedit/masks/DynamicRegionMask.java (100%) rename src/{main => legacy}/java/com/sk89q/worldedit/masks/ExistingBlockMask.java (97%) rename src/{main => legacy}/java/com/sk89q/worldedit/masks/FuzzyBlockMask.java (100%) rename src/{main => legacy}/java/com/sk89q/worldedit/masks/InvertedBlockTypeMask.java (96%) rename src/{main => legacy}/java/com/sk89q/worldedit/masks/InvertedMask.java (100%) rename src/{main => legacy}/java/com/sk89q/worldedit/masks/Mask.java (97%) rename src/{main => legacy}/java/com/sk89q/worldedit/masks/RandomMask.java (100%) rename src/{main => legacy}/java/com/sk89q/worldedit/masks/RegionMask.java (96%) rename src/{main => legacy}/java/com/sk89q/worldedit/masks/SolidBlockMask.java (96%) rename src/{main => legacy}/java/com/sk89q/worldedit/masks/UnderOverlayMask.java (100%) rename src/{main => legacy}/java/com/sk89q/worldedit/patterns/BlockChance.java (100%) rename src/{main => legacy}/java/com/sk89q/worldedit/patterns/ClipboardPattern.java (96%) rename src/{main => legacy}/java/com/sk89q/worldedit/patterns/Pattern.java (100%) rename src/{main => legacy}/java/com/sk89q/worldedit/patterns/RandomFillPattern.java (100%) rename src/{main => legacy}/java/com/sk89q/worldedit/patterns/SingleBlockPattern.java (100%) diff --git a/pom.xml b/pom.xml index 4b1beca4a..923889ae5 100644 --- a/pom.xml +++ b/pom.xml @@ -1,17 +1,27 @@ - + 4.0.0 com.sk89q worldedit - 5.7-SNAPSHOT + 6.0.0-SNAPSHOT jar - - + + + + UTF-8 + + + + WorldEdit 2010 http://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 - + YouTrack http://youtrack.sk89q.com - + - Jenkins - http://build.sk89q.com + TeamCity + http://builds.enginehub.org - + scm:git:git://github.com/sk89q/worldedit.git scm:git:git@github.com:sk89q/worldedit.git https://github.com/sk89q/worldedit master - + Developer Discussion https://groups.google.com/d/forum/sk-dev-discuss - + + + sk89q-docs-upload ftp://sk89q-maven-deploy/worldedit/ + + maven.sk89q.com http://maven.sk89q.com/artifactory/libs-release-local @@ -65,99 +83,89 @@ http://maven.sk89q.com/artifactory/libs-snapshot-local - - - UTF-8 - - + + + - sk89q-repo + maven.sk89q.com http://maven.sk89q.com/repo/ - - bukkit-repo - http://repo.bukkit.org/content/groups/public - - + - + + de.schlichtherle truezip 6.8.3 - compile + compile jar - - + + + rhino js 1.7R2 - compile + compile jar - - - 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.9 jar + compile true + com.google.guava guava - 10.0.1 - compile + 10.0.1 + compile jar - - - org.bukkit - craftbukkit - 1.7.5-R0.1-SNAPSHOT - compile + + + + com.sk89q + jchronic + 0.2.4a + compile jar - true - - + + + org.mockito mockito-core 1.9.0-rc1 test jar - - + + + install ${basedir}/src/main/java/ - + + org.apache.maven.wagon wagon-ftp @@ -165,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 + + + + ${basedir}/src/legacy/java/ + + + + + + + org.apache.maven.plugins maven-compiler-plugin @@ -203,6 +206,7 @@ + org.apache.maven.plugins maven-jar-plugin @@ -224,6 +228,7 @@ + maven-assembly-plugin 2.2-beta-2 @@ -241,6 +246,7 @@ + org.apache.maven.plugins maven-shade-plugin @@ -262,6 +268,7 @@ + org.apache.maven.plugins maven-release-plugin @@ -273,6 +280,7 @@ + org.apache.maven.plugins maven-surefire-plugin @@ -284,12 +292,14 @@ + org.apache.maven.plugins maven-site-plugin 3.1 + org.apache.maven.plugins maven-project-info-reports-plugin @@ -303,7 +313,8 @@ - + + org.apache.maven.plugins maven-javadoc-plugin @@ -314,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 + + + + ${basedir}/src/bukkit/java/ + + + + + add-bukkit-test-sources + generate-sources + + add-test-source + + + + ${basedir}/src/bukkit-test/java/ + + + + + + + + + + forge @@ -349,10 +492,14 @@ - + attach-docs - + @@ -368,7 +515,7 @@ - + org.apache.maven.plugins maven-javadoc-plugin @@ -385,18 +532,22 @@ - - + + spout - + spout-repo http://nexus.spout.org/content/groups/public/ - + org.spout @@ -430,7 +581,7 @@ 1.5 - add-sources + add-spout-sources generate-sources add-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[] 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 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[] 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 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 96% rename from src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java rename to src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java index b7ad8fe88..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.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(); - } -} +// $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 96% rename from src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java rename to src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java index ae8fb2e49..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.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); - } -} +// $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 96% rename from src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java rename to src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java index 80c47678d..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.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) { - } -} +// $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 97% rename from src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java rename to src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index a53cd12d0..2ea7d9f3b 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -1,1328 +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 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 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 nmsClass = (Class) 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) 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, 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 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 nmsClass = (Class) 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) 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, 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); + } +} 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 66bf9c996..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.world.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 foreignKeys = null; - - if (compoundMapField == null) { - try { - // Method name may change! - foreignKeys = ((NBTTagCompound) foreign).c(); - } catch (Throwable t) { - try { - logger.warning("WorldEdit: Couldn't get NBTTagCompound.c(), " + - "so we're going to try to get at the 'map' field directly from now on"); - - if (compoundMapField == null) { - compoundMapField = NBTTagCompound.class.getDeclaredField("map"); - compoundMapField.setAccessible(true); - } - } catch (Throwable e) { - // Can't do much beyond this - throw new RuntimeException(e); - } - } - } - - if (compoundMapField != null) { - try { - foreignKeys = ((HashMap) compoundMapField.get(foreign)).keySet(); - } catch (Throwable e) { - // Can't do much beyond this - throw new RuntimeException(e); - } - } - - for (Object obj : foreignKeys) { - String key = (String) obj; - NBTBase base = (NBTBase) ((NBTTagCompound) foreign).get(key); - values.put(key, toNative(key, base)); - } - return new CompoundTag(name, values); - } else if (foreign instanceof NBTTagByte) { - return new ByteTag(name, ((NBTTagByte) foreign).f()); // getByte - } else if (foreign instanceof NBTTagByteArray) { - return new ByteArrayTag(name, - ((NBTTagByteArray) foreign).c()); // data - } else if (foreign instanceof NBTTagDouble) { - return new DoubleTag(name, - ((NBTTagDouble) foreign).g()); // getDouble - } else if (foreign instanceof NBTTagFloat) { - return new FloatTag(name, ((NBTTagFloat) foreign).h()); // getFloat - } else if (foreign instanceof NBTTagInt) { - return new IntTag(name, ((NBTTagInt) foreign).d()); // getInt - } else if (foreign instanceof NBTTagIntArray) { - return new IntArrayTag(name, - ((NBTTagIntArray) foreign).c()); // data - } else if (foreign instanceof NBTTagList) { - try { - return transmorgifyList(name, (NBTTagList) foreign); - } catch (NoSuchFieldException e) { - } catch (SecurityException e) { - } catch (IllegalArgumentException e) { - } catch (IllegalAccessException e) {} - return new ListTag(name, ByteTag.class, new ArrayList()); - } else if (foreign instanceof NBTTagLong) { - return new LongTag(name, ((NBTTagLong) foreign).c()); // getLong - } else if (foreign instanceof NBTTagShort) { - return new ShortTag(name, ((NBTTagShort) foreign).e()); // getShort - } else if (foreign instanceof NBTTagString) { - return new StringTag(name, - ((NBTTagString) foreign).a_()); // data - } else if (foreign instanceof NBTTagEnd) { - return new EndTag(); - } else { - throw new IllegalArgumentException("Don't know how to make native " - + foreign.getClass().getCanonicalName()); - } - } - - private static ListTag transmorgifyList(String name, NBTTagList foreign) - throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - List values = new ArrayList(); - int type = foreign.d(); - Field listField = NBTTagList.class.getDeclaredField("list"); - listField.setAccessible(true); - List foreignList; - foreignList = (List) listField.get(foreign); - for (int i = 0; i < foreign.size(); i++) { - NBTBase element = (NBTBase) foreignList.get(i); - values.add(toNative(null, element)); // list elements shouldn't have names - } - Class cls = NBTConstants.getClassFromType(type); - return new ListTag(name, cls, values); - } - - /** - * Converts a WorldEdit-native NBT structure to a NMS structure. - * - * @param foreign structure to convert - * @return non-native structure - */ - private static NBTBase fromNative(Tag foreign) { - if (foreign == null) { - return null; - } - if (foreign instanceof CompoundTag) { - NBTTagCompound tag = new NBTTagCompound(); - for (Map.Entry entry : ((CompoundTag) foreign) - .getValue().entrySet()) { - tag.set(entry.getKey(), fromNative(entry.getValue())); - } - return tag; - } else if (foreign instanceof ByteTag) { - return new NBTTagByte(((ByteTag) foreign).getValue()); - } else if (foreign instanceof ByteArrayTag) { - return new NBTTagByteArray(((ByteArrayTag) foreign).getValue()); - } else if (foreign instanceof DoubleTag) { - return new NBTTagDouble(((DoubleTag) foreign).getValue()); - } else if (foreign instanceof FloatTag) { - return new NBTTagFloat(((FloatTag) foreign).getValue()); - } else if (foreign instanceof IntTag) { - return new NBTTagInt(((IntTag) foreign).getValue()); - } else if (foreign instanceof IntArrayTag) { - return new NBTTagIntArray(((IntArrayTag) foreign).getValue()); - } else if (foreign instanceof ListTag) { - NBTTagList tag = new NBTTagList(); - ListTag foreignList = (ListTag) foreign; - for (Tag t : foreignList.getValue()) { - tag.add(fromNative(t)); - } - return tag; - } else if (foreign instanceof LongTag) { - return new NBTTagLong(((LongTag) foreign).getValue()); - } else if (foreign instanceof ShortTag) { - return new NBTTagShort(((ShortTag) foreign).getValue()); - } else if (foreign instanceof StringTag) { - return new NBTTagString(((StringTag) foreign).getValue()); - } else if (foreign instanceof EndTag) { - try { - Method tagMaker = NBTBase.class.getDeclaredMethod("createTag", byte.class); - tagMaker.setAccessible(true); - return (NBTBase) tagMaker.invoke(null, (byte) 0); - } catch (Exception e) { - return null; - } - } else { - throw new IllegalArgumentException("Don't know how to make NMS " - + foreign.getClass().getCanonicalName()); - } - } - - public static boolean isValidBlockType(int type) throws NoClassDefFoundError { - return type == 0 || (type >= 1 && net.minecraft.server.v1_7_R2.Block.e(type) != null); - } - -} +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.world.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 foreignKeys = null; + + if (compoundMapField == null) { + try { + // Method name may change! + foreignKeys = ((NBTTagCompound) foreign).c(); + } catch (Throwable t) { + try { + logger.warning("WorldEdit: Couldn't get NBTTagCompound.c(), " + + "so we're going to try to get at the 'map' field directly from now on"); + + if (compoundMapField == null) { + compoundMapField = NBTTagCompound.class.getDeclaredField("map"); + compoundMapField.setAccessible(true); + } + } catch (Throwable e) { + // Can't do much beyond this + throw new RuntimeException(e); + } + } + } + + if (compoundMapField != null) { + try { + foreignKeys = ((HashMap) compoundMapField.get(foreign)).keySet(); + } catch (Throwable e) { + // Can't do much beyond this + throw new RuntimeException(e); + } + } + + for (Object obj : foreignKeys) { + String key = (String) obj; + NBTBase base = (NBTBase) ((NBTTagCompound) foreign).get(key); + values.put(key, toNative(key, base)); + } + return new CompoundTag(name, values); + } else if (foreign instanceof NBTTagByte) { + return new ByteTag(name, ((NBTTagByte) foreign).f()); // getByte + } else if (foreign instanceof NBTTagByteArray) { + return new ByteArrayTag(name, + ((NBTTagByteArray) foreign).c()); // data + } else if (foreign instanceof NBTTagDouble) { + return new DoubleTag(name, + ((NBTTagDouble) foreign).g()); // getDouble + } else if (foreign instanceof NBTTagFloat) { + return new FloatTag(name, ((NBTTagFloat) foreign).h()); // getFloat + } else if (foreign instanceof NBTTagInt) { + return new IntTag(name, ((NBTTagInt) foreign).d()); // getInt + } else if (foreign instanceof NBTTagIntArray) { + return new IntArrayTag(name, + ((NBTTagIntArray) foreign).c()); // data + } else if (foreign instanceof NBTTagList) { + try { + return transmorgifyList(name, (NBTTagList) foreign); + } catch (NoSuchFieldException e) { + } catch (SecurityException e) { + } catch (IllegalArgumentException e) { + } catch (IllegalAccessException e) {} + return new ListTag(name, ByteTag.class, new ArrayList()); + } else if (foreign instanceof NBTTagLong) { + return new LongTag(name, ((NBTTagLong) foreign).c()); // getLong + } else if (foreign instanceof NBTTagShort) { + return new ShortTag(name, ((NBTTagShort) foreign).e()); // getShort + } else if (foreign instanceof NBTTagString) { + return new StringTag(name, + ((NBTTagString) foreign).a_()); // data + } else if (foreign instanceof NBTTagEnd) { + return new EndTag(); + } else { + throw new IllegalArgumentException("Don't know how to make native " + + foreign.getClass().getCanonicalName()); + } + } + + private static ListTag transmorgifyList(String name, NBTTagList foreign) + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + List values = new ArrayList(); + int type = foreign.d(); + Field listField = NBTTagList.class.getDeclaredField("list"); + listField.setAccessible(true); + List foreignList; + foreignList = (List) listField.get(foreign); + for (int i = 0; i < foreign.size(); i++) { + NBTBase element = (NBTBase) foreignList.get(i); + values.add(toNative(null, element)); // list elements shouldn't have names + } + Class cls = NBTConstants.getClassFromType(type); + return new ListTag(name, cls, values); + } + + /** + * Converts a WorldEdit-native NBT structure to a NMS structure. + * + * @param foreign structure to convert + * @return non-native structure + */ + private static NBTBase fromNative(Tag foreign) { + if (foreign == null) { + return null; + } + if (foreign instanceof CompoundTag) { + NBTTagCompound tag = new NBTTagCompound(); + for (Map.Entry entry : ((CompoundTag) foreign) + .getValue().entrySet()) { + tag.set(entry.getKey(), fromNative(entry.getValue())); + } + return tag; + } else if (foreign instanceof ByteTag) { + return new NBTTagByte(((ByteTag) foreign).getValue()); + } else if (foreign instanceof ByteArrayTag) { + return new NBTTagByteArray(((ByteArrayTag) foreign).getValue()); + } else if (foreign instanceof DoubleTag) { + return new NBTTagDouble(((DoubleTag) foreign).getValue()); + } else if (foreign instanceof FloatTag) { + return new NBTTagFloat(((FloatTag) foreign).getValue()); + } else if (foreign instanceof IntTag) { + return new NBTTagInt(((IntTag) foreign).getValue()); + } else if (foreign instanceof IntArrayTag) { + return new NBTTagIntArray(((IntArrayTag) foreign).getValue()); + } else if (foreign instanceof ListTag) { + NBTTagList tag = new NBTTagList(); + ListTag foreignList = (ListTag) foreign; + for (Tag t : foreignList.getValue()) { + tag.add(fromNative(t)); + } + return tag; + } else if (foreign instanceof LongTag) { + return new NBTTagLong(((LongTag) foreign).getValue()); + } else if (foreign instanceof ShortTag) { + return new NBTTagShort(((ShortTag) foreign).getValue()); + } else if (foreign instanceof StringTag) { + return new NBTTagString(((StringTag) foreign).getValue()); + } else if (foreign instanceof EndTag) { + try { + Method tagMaker = NBTBase.class.getDeclaredMethod("createTag", byte.class); + tagMaker.setAccessible(true); + return (NBTBase) tagMaker.invoke(null, (byte) 0); + } catch (Exception e) { + return null; + } + } else { + throw new IllegalArgumentException("Don't know how to make NMS " + + foreign.getClass().getCanonicalName()); + } + } + + public static boolean isValidBlockType(int type) throws NoClassDefFoundError { + return type == 0 || (type >= 1 && net.minecraft.server.v1_7_R2.Block.e(type) != null); + } + +} diff --git a/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java similarity index 97% rename from src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java rename to src/bukkit/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java index 2a8bae6c4..7d6d6d457 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java +++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java @@ -1,76 +1,76 @@ -// $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.blocks.BlockID; -import org.bukkit.BlockChangeDelegate; -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.blocks.BaseBlock; - -/** - * Proxy class to catch calls to set blocks. - * - * @author sk89q - */ -public class EditSessionBlockChangeDelegate implements BlockChangeDelegate { - private EditSession editSession; - - public EditSessionBlockChangeDelegate(EditSession editSession) { - this.editSession = editSession; - } - - public boolean setRawTypeId(int x, int y, int z, int typeId) { - try { - return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId)); - } catch (MaxChangedBlocksException ex) { - return false; - } - } - - public boolean setRawTypeIdAndData(int x, int y, int z, int typeId, int data) { - try { - return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId, data)); - } catch (MaxChangedBlocksException ex) { - return false; - } - } - - public boolean setTypeId(int x, int y, int z, int typeId) { - return setRawTypeId(x, y, z, typeId); - } - - public boolean setTypeIdAndData(int x, int y, int z, int typeId, int data) { - return setRawTypeIdAndData(x, y, z, typeId, data); - } - - public int getTypeId(int x, int y, int z) { - return editSession.getBlockType(new Vector(x, y, z)); - } - - public int getHeight() { - return editSession.getWorld().getMaxY() + 1; - } - - public boolean isEmpty(int x, int y, int z) { - return editSession.getBlockType(new Vector(x, y, z)) == BlockID.AIR; - } -} +// $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.blocks.BlockID; +import org.bukkit.BlockChangeDelegate; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.blocks.BaseBlock; + +/** + * Proxy class to catch calls to set blocks. + * + * @author sk89q + */ +public class EditSessionBlockChangeDelegate implements BlockChangeDelegate { + private EditSession editSession; + + public EditSessionBlockChangeDelegate(EditSession editSession) { + this.editSession = editSession; + } + + public boolean setRawTypeId(int x, int y, int z, int typeId) { + try { + return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId)); + } catch (MaxChangedBlocksException ex) { + return false; + } + } + + public boolean setRawTypeIdAndData(int x, int y, int z, int typeId, int data) { + try { + return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId, data)); + } catch (MaxChangedBlocksException ex) { + return false; + } + } + + public boolean setTypeId(int x, int y, int z, int typeId) { + return setRawTypeId(x, y, z, typeId); + } + + public boolean setTypeIdAndData(int x, int y, int z, int typeId, int data) { + return setRawTypeIdAndData(x, y, z, typeId, data); + } + + public int getTypeId(int x, int y, int z) { + return editSession.getBlockType(new Vector(x, y, z)); + } + + public int getHeight() { + return editSession.getWorld().getMaxY() + 1; + } + + public boolean isEmpty(int x, int y, int z) { + return editSession.getBlockType(new Vector(x, y, z)) == BlockID.AIR; + } +} diff --git a/src/main/java/com/sk89q/worldedit/bukkit/NmsBlock.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/NmsBlock.java similarity index 95% rename from src/main/java/com/sk89q/worldedit/bukkit/NmsBlock.java rename to src/bukkit/java/com/sk89q/worldedit/bukkit/NmsBlock.java index 46bd635b0..8ee32c4d0 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/NmsBlock.java +++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/NmsBlock.java @@ -1,42 +1,42 @@ -package com.sk89q.worldedit.bukkit; - -import org.bukkit.World; - -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.foundation.Block; - -public abstract class NmsBlock extends BaseBlock { - - protected NmsBlock(int type) { - super(type); - } - - protected NmsBlock(int type, int data) { - super(type, data); - } - - public static boolean verify() { - return false; - } - - public static NmsBlock get(World world, Vector vector, int type, int data) { - return null; - } - - public static boolean set(World world, Vector vector, Block block) { - return false; - } - - public static boolean setSafely(World world, Vector vector, Block block, boolean notify) { - return false; - } - - public static boolean hasTileEntity(int type) { - return false; - } - - public static boolean isValidBlockType(int type) { - return false; - } +package com.sk89q.worldedit.bukkit; + +import org.bukkit.World; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.foundation.Block; + +public abstract class NmsBlock extends BaseBlock { + + protected NmsBlock(int type) { + super(type); + } + + protected NmsBlock(int type, int data) { + super(type, data); + } + + public static boolean verify() { + return false; + } + + public static NmsBlock get(World world, Vector vector, int type, int data) { + return null; + } + + public static boolean set(World world, Vector vector, Block block) { + return false; + } + + public static boolean setSafely(World world, Vector vector, Block block, boolean notify) { + return false; + } + + public static boolean hasTileEntity(int type) { + return false; + } + + public static boolean isValidBlockType(int type) { + return false; + } } \ No newline at end of file diff --git a/src/main/java/com/sk89q/worldedit/bukkit/SessionTimer.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/SessionTimer.java similarity index 96% rename from src/main/java/com/sk89q/worldedit/bukkit/SessionTimer.java rename to src/bukkit/java/com/sk89q/worldedit/bukkit/SessionTimer.java index 6932af4b3..b2add99d6 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/SessionTimer.java +++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/SessionTimer.java @@ -1,51 +1,51 @@ -// $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.worldedit.bukkit; - -import org.bukkit.Server; -import org.bukkit.entity.Player; -import com.sk89q.worldedit.SessionCheck; -import com.sk89q.worldedit.WorldEdit; - -/** - * Used to remove expired sessions in Bukkit. - * - * @author sk89q - */ -public class SessionTimer implements Runnable { - - private WorldEdit worldEdit; - private SessionCheck checker; - - public SessionTimer(WorldEdit worldEdit, final Server server) { - this.worldEdit = worldEdit; - this.checker = new SessionCheck() { - public boolean isOnlinePlayer(String name) { - Player player = server.getPlayer(name); - return player != null && player.isOnline(); - } - }; - } - - public void run() { - worldEdit.flushExpiredSessions(checker); - } - -} +// $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.worldedit.bukkit; + +import org.bukkit.Server; +import org.bukkit.entity.Player; +import com.sk89q.worldedit.SessionCheck; +import com.sk89q.worldedit.WorldEdit; + +/** + * Used to remove expired sessions in Bukkit. + * + * @author sk89q + */ +public class SessionTimer implements Runnable { + + private WorldEdit worldEdit; + private SessionCheck checker; + + public SessionTimer(WorldEdit worldEdit, final Server server) { + this.worldEdit = worldEdit; + this.checker = new SessionCheck() { + public boolean isOnlinePlayer(String name) { + Player player = server.getPlayer(name); + return player != null && player.isOnline(); + } + }; + } + + public void run() { + worldEdit.flushExpiredSessions(checker); + } + +} diff --git a/src/main/java/com/sk89q/worldedit/bukkit/WorldEditAPI.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/WorldEditAPI.java similarity index 96% rename from src/main/java/com/sk89q/worldedit/bukkit/WorldEditAPI.java rename to src/bukkit/java/com/sk89q/worldedit/bukkit/WorldEditAPI.java index d85f49457..c302ff31a 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/WorldEditAPI.java +++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/WorldEditAPI.java @@ -1,42 +1,42 @@ -// $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.entity.Player; -import com.sk89q.worldedit.LocalSession; - -public class WorldEditAPI { - private WorldEditPlugin plugin; - - public WorldEditAPI(WorldEditPlugin plugin) { - this.plugin = plugin; - } - - /** - * Get the session for a player. - * - * @param player - * @return - */ - public LocalSession getSession(Player player) { - return plugin.getWorldEdit().getSession( - new BukkitPlayer(plugin, plugin.getServerInterface(), player)); - } -} +// $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.entity.Player; +import com.sk89q.worldedit.LocalSession; + +public class WorldEditAPI { + private WorldEditPlugin plugin; + + public WorldEditAPI(WorldEditPlugin plugin) { + this.plugin = plugin; + } + + /** + * Get the session for a player. + * + * @param player + * @return + */ + public LocalSession getSession(Player player) { + return plugin.getWorldEdit().getSession( + new BukkitPlayer(plugin, plugin.getServerInterface(), player)); + } +} diff --git a/src/main/java/com/sk89q/worldedit/bukkit/WorldEditListener.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/WorldEditListener.java similarity index 97% rename from src/main/java/com/sk89q/worldedit/bukkit/WorldEditListener.java rename to src/bukkit/java/com/sk89q/worldedit/bukkit/WorldEditListener.java index 4b1dccb8a..590cc0c31 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/WorldEditListener.java +++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/WorldEditListener.java @@ -1,178 +1,178 @@ -/* - * WorldEdit - * Copyright (C) 2012 sk89q - * - * 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 . - */ - -// $Id$ - -package com.sk89q.worldedit.bukkit; - -import org.bukkit.Bukkit; -import org.bukkit.block.Block; -import org.bukkit.event.Event.Result; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerGameModeChangeEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerQuitEvent; - -import com.sk89q.util.StringUtil; -import com.sk89q.worldedit.LocalPlayer; -import com.sk89q.worldedit.LocalWorld; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.WorldVector; - -/** - * Handles all events thrown in relation to a Player - */ -public class WorldEditListener implements Listener { - - private WorldEditPlugin plugin; - private boolean ignoreLeftClickAir = false; - - /** - * Called when a player plays an animation, such as an arm swing - * - * @param event Relevant event details - */ - - /** - * Construct the object; - * - * @param plugin - */ - public WorldEditListener(WorldEditPlugin plugin) { - this.plugin = plugin; - } - - /** - * Called when a player leaves a server - * - * @param event Relevant event details - */ - @EventHandler - public void onPlayerQuit(PlayerQuitEvent event) { - plugin.getWorldEdit().markExpire(plugin.wrapPlayer(event.getPlayer())); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onGamemode(PlayerGameModeChangeEvent event) { - // this will automatically refresh their sesssion, we don't have to do anything - WorldEdit.getInstance().getSession(plugin.wrapPlayer(event.getPlayer())); - } - - /** - * Called when a player attempts to use a command - * - * @param event Relevant event details - */ - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { - String[] split = event.getMessage().split(" "); - - if (split.length > 0) { - split = plugin.getWorldEdit().commandDetection(split); - split[0] = "/" + split[0]; - } - - final String newMessage = StringUtil.joinString(split, " "); - - if (!newMessage.equals(event.getMessage())) { - event.setMessage(newMessage); - plugin.getServer().getPluginManager().callEvent(event); - if (!event.isCancelled()) { - if (event.getMessage().length() > 0) { - plugin.getServer().dispatchCommand(event.getPlayer(), - event.getMessage().substring(1)); - } - event.setCancelled(true); - } - } - } - - /** - * Called when a player interacts - * - * @param event Relevant event details - */ - @EventHandler - public void onPlayerInteract(PlayerInteractEvent event) { - if (event.useItemInHand() == Result.DENY) { - return; - } - - final LocalPlayer player = plugin.wrapPlayer(event.getPlayer()); - final LocalWorld world = player.getWorld(); - final WorldEdit we = plugin.getWorldEdit(); - - Action action = event.getAction(); - if (action == Action.LEFT_CLICK_BLOCK) { - final Block clickedBlock = event.getClickedBlock(); - final WorldVector pos = new WorldVector(world, clickedBlock.getX(), - clickedBlock.getY(), clickedBlock.getZ()); - - if (we.handleBlockLeftClick(player, pos)) { - event.setCancelled(true); - } - - if (we.handleArmSwing(player)) { - event.setCancelled(true); - } - - if (!ignoreLeftClickAir) { - final int taskId = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - @Override - public void run() { - ignoreLeftClickAir = false; - } - }, 2); - - if (taskId != -1) { - ignoreLeftClickAir = true; - } - } - } else if (action == Action.LEFT_CLICK_AIR) { - if (ignoreLeftClickAir) { - return; - } - - if (we.handleArmSwing(player)) { - event.setCancelled(true); - } - - - } else if (action == Action.RIGHT_CLICK_BLOCK) { - final Block clickedBlock = event.getClickedBlock(); - final WorldVector pos = new WorldVector(world, clickedBlock.getX(), - clickedBlock.getY(), clickedBlock.getZ()); - - if (we.handleBlockRightClick(player, pos)) { - event.setCancelled(true); - } - - if (we.handleRightClick(player)) { - event.setCancelled(true); - } - } else if (action == Action.RIGHT_CLICK_AIR) { - if (we.handleRightClick(player)) { - event.setCancelled(true); - } - } - } -} +/* + * WorldEdit + * Copyright (C) 2012 sk89q + * + * 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 . + */ + +// $Id$ + +package com.sk89q.worldedit.bukkit; + +import org.bukkit.Bukkit; +import org.bukkit.block.Block; +import org.bukkit.event.Event.Result; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerGameModeChangeEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import com.sk89q.util.StringUtil; +import com.sk89q.worldedit.LocalPlayer; +import com.sk89q.worldedit.LocalWorld; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.WorldVector; + +/** + * Handles all events thrown in relation to a Player + */ +public class WorldEditListener implements Listener { + + private WorldEditPlugin plugin; + private boolean ignoreLeftClickAir = false; + + /** + * Called when a player plays an animation, such as an arm swing + * + * @param event Relevant event details + */ + + /** + * Construct the object; + * + * @param plugin + */ + public WorldEditListener(WorldEditPlugin plugin) { + this.plugin = plugin; + } + + /** + * Called when a player leaves a server + * + * @param event Relevant event details + */ + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + plugin.getWorldEdit().markExpire(plugin.wrapPlayer(event.getPlayer())); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onGamemode(PlayerGameModeChangeEvent event) { + // this will automatically refresh their sesssion, we don't have to do anything + WorldEdit.getInstance().getSession(plugin.wrapPlayer(event.getPlayer())); + } + + /** + * Called when a player attempts to use a command + * + * @param event Relevant event details + */ + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) + public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { + String[] split = event.getMessage().split(" "); + + if (split.length > 0) { + split = plugin.getWorldEdit().commandDetection(split); + split[0] = "/" + split[0]; + } + + final String newMessage = StringUtil.joinString(split, " "); + + if (!newMessage.equals(event.getMessage())) { + event.setMessage(newMessage); + plugin.getServer().getPluginManager().callEvent(event); + if (!event.isCancelled()) { + if (event.getMessage().length() > 0) { + plugin.getServer().dispatchCommand(event.getPlayer(), + event.getMessage().substring(1)); + } + event.setCancelled(true); + } + } + } + + /** + * Called when a player interacts + * + * @param event Relevant event details + */ + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + if (event.useItemInHand() == Result.DENY) { + return; + } + + final LocalPlayer player = plugin.wrapPlayer(event.getPlayer()); + final LocalWorld world = player.getWorld(); + final WorldEdit we = plugin.getWorldEdit(); + + Action action = event.getAction(); + if (action == Action.LEFT_CLICK_BLOCK) { + final Block clickedBlock = event.getClickedBlock(); + final WorldVector pos = new WorldVector(world, clickedBlock.getX(), + clickedBlock.getY(), clickedBlock.getZ()); + + if (we.handleBlockLeftClick(player, pos)) { + event.setCancelled(true); + } + + if (we.handleArmSwing(player)) { + event.setCancelled(true); + } + + if (!ignoreLeftClickAir) { + final int taskId = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + ignoreLeftClickAir = false; + } + }, 2); + + if (taskId != -1) { + ignoreLeftClickAir = true; + } + } + } else if (action == Action.LEFT_CLICK_AIR) { + if (ignoreLeftClickAir) { + return; + } + + if (we.handleArmSwing(player)) { + event.setCancelled(true); + } + + + } else if (action == Action.RIGHT_CLICK_BLOCK) { + final Block clickedBlock = event.getClickedBlock(); + final WorldVector pos = new WorldVector(world, clickedBlock.getX(), + clickedBlock.getY(), clickedBlock.getZ()); + + if (we.handleBlockRightClick(player, pos)) { + event.setCancelled(true); + } + + if (we.handleRightClick(player)) { + event.setCancelled(true); + } + } else if (action == Action.RIGHT_CLICK_AIR) { + if (we.handleRightClick(player)) { + event.setCancelled(true); + } + } + } +} diff --git a/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java similarity index 93% rename from src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java rename to src/bukkit/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index 40640be9f..fa490ccf3 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -1,430 +1,419 @@ -// $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.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Enumeration; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; -import java.util.logging.Handler; -import java.util.zip.ZipEntry; - -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -import com.sk89q.util.yaml.YAMLProcessor; -import com.sk89q.wepif.PermissionsResolverManager; -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.IncompleteRegionException; -import com.sk89q.worldedit.LocalPlayer; -import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.ServerInterface; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.WorldEditOperation; -import com.sk89q.worldedit.extent.inventory.BlockBag; -import com.sk89q.worldedit.bukkit.selections.CuboidSelection; -import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection; -import com.sk89q.worldedit.bukkit.selections.Selection; -import com.sk89q.worldedit.regions.CuboidRegion; -import com.sk89q.worldedit.regions.Polygonal2DRegion; -import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.regions.RegionSelector; - -/** - * Plugin for Bukkit. - * - * @author sk89q - */ -public class WorldEditPlugin extends JavaPlugin { - - /** - * The name of the CUI's plugin channel registration - */ - public static final String CUI_PLUGIN_CHANNEL = "WECUI"; - - /** - * The server interface that all server-related API goes through. - */ - private BukkitServerInterface server; - /** - * Main WorldEdit instance. - */ - private WorldEdit controller; - /** - * Deprecated API. - */ - private WorldEditAPI api; - - /** - * Holds the configuration for WorldEdit. - */ - private BukkitConfiguration config; - - /** - * Called on plugin enable. - */ - @Override - public void onEnable() { - final String pluginYmlVersion = getDescription().getVersion(); - final String manifestVersion = WorldEdit.getVersion(); - - if (!manifestVersion.equalsIgnoreCase(pluginYmlVersion)) { - WorldEdit.setVersion(manifestVersion + " (" + pluginYmlVersion + ")"); - } - - // Make the data folders that WorldEdit uses - getDataFolder().mkdirs(); - File targetDir = new File(getDataFolder() + File.separator + "nmsblocks"); - targetDir.mkdir(); - copyNmsBlockClasses(targetDir); - - // Create the default configuration file - createDefaultConfiguration("config.yml"); - - // Set up configuration and such, including the permissions - // resolver - config = new BukkitConfiguration(new YAMLProcessor(new File(getDataFolder(), "config.yml"), true), this); - PermissionsResolverManager.initialize(this); - - // Load the configuration - config.load(); - - // Setup interfaces - server = new BukkitServerInterface(this, getServer()); - controller = new WorldEdit(server, config); - WorldEdit.logger.setParent(Bukkit.getLogger()); - api = new WorldEditAPI(this); - getServer().getMessenger().registerIncomingPluginChannel(this, CUI_PLUGIN_CHANNEL, new CUIChannelListener(this)); - getServer().getMessenger().registerOutgoingPluginChannel(this, CUI_PLUGIN_CHANNEL); - // Now we can register events! - getServer().getPluginManager().registerEvents(new WorldEditListener(this), this); - - getServer().getScheduler().runTaskTimerAsynchronously(this, - new SessionTimer(controller, getServer()), 120, 120); - } - - private void copyNmsBlockClasses(File target) { - try { - JarFile jar = new JarFile(getFile()); - @SuppressWarnings("rawtypes") - Enumeration entries = jar.entries(); - while (entries.hasMoreElements()) { - JarEntry jarEntry = (JarEntry) entries.nextElement(); - if (!jarEntry.getName().startsWith("nmsblocks") || jarEntry.isDirectory()) continue; - - File file = new File(target + File.separator + jarEntry.getName().replace("nmsblocks", "")); - if (file.exists()) continue; - - InputStream is = jar.getInputStream(jarEntry); - FileOutputStream fos = new FileOutputStream(file); - - fos = new FileOutputStream(file); - byte[] buf = new byte[8192]; - int length = 0; - while ((length = is.read(buf)) > 0) { - fos.write(buf, 0, length); - } - fos.close(); - is.close(); - } - } catch (Throwable e) {} - } - - /** - * Called on plugin disable. - */ - @Override - public void onDisable() { - controller.clearSessions(); - for (Handler h : controller.commandLogger.getHandlers()) { - h.close(); - } - config.unload(); - server.unregisterCommands(); - this.getServer().getScheduler().cancelTasks(this); - } - - /** - * Loads and reloads all configuration. - */ - protected void loadConfiguration() { - config.unload(); - config.load(); - getPermissionsResolver().load(); - } - - /** - * Create a default configuration file from the .jar. - * - * @param name - */ - protected void createDefaultConfiguration(String name) { - File actual = new File(getDataFolder(), name); - if (!actual.exists()) { - InputStream input = - null; - try { - JarFile file = new JarFile(getFile()); - ZipEntry copy = file.getEntry("defaults/" + name); - if (copy == null) throw new FileNotFoundException(); - input = file.getInputStream(copy); - } catch (IOException e) { - getLogger().severe("Unable to read default configuration: " + name); - } - if (input != null) { - FileOutputStream output = null; - - try { - output = new FileOutputStream(actual); - byte[] buf = new byte[8192]; - int length = 0; - while ((length = input.read(buf)) > 0) { - output.write(buf, 0, length); - } - - getLogger().info("Default configuration file written: " + name); - } catch (IOException e) { - e.printStackTrace(); - } finally { - try { - if (input != null) { - input.close(); - } - } catch (IOException e) {} - - try { - if (output != null) { - output.close(); - } - } catch (IOException e) {} - } - } - } - } - - /** - * Called on WorldEdit command. - */ - @Override - public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd, - String commandLabel, String[] args) { - - // Add the command to the array because the underlying command handling - // code of WorldEdit expects it - String[] split = new String[args.length + 1]; - System.arraycopy(args, 0, split, 1, args.length); - split[0] = "/" + cmd.getName(); - - controller.handleCommand(wrapCommandSender(sender), split); - - return true; - } - - /** - * Gets the session for the player. - * - * @param player - * @return - */ - public LocalSession getSession(Player player) { - return controller.getSession(wrapPlayer(player)); - } - - /** - * Gets the session for the player. - * - * @param player - * @return - */ - public EditSession createEditSession(Player player) { - LocalPlayer wePlayer = wrapPlayer(player); - LocalSession session = controller.getSession(wePlayer); - BlockBag blockBag = session.getBlockBag(wePlayer); - - EditSession editSession = controller.getEditSessionFactory() - .getEditSession(wePlayer.getWorld(), session.getBlockChangeLimit(), blockBag, wePlayer); - editSession.enableQueue(); - - return editSession; - } - - /** - * Remember an edit session. - * - * @param player - * @param editSession - */ - public void remember(Player player, EditSession editSession) { - LocalPlayer wePlayer = wrapPlayer(player); - LocalSession session = controller.getSession(wePlayer); - - session.remember(editSession); - editSession.flushQueue(); - - controller.flushBlockBag(wePlayer, editSession); - } - - /** - * Wrap an operation into an EditSession. - * - * @param player - * @param op - * @throws Throwable - */ - public void perform(Player player, WorldEditOperation op) - throws Throwable { - LocalPlayer wePlayer = wrapPlayer(player); - LocalSession session = controller.getSession(wePlayer); - - EditSession editSession = createEditSession(player); - try { - op.run(session, wePlayer, editSession); - } finally { - remember(player, editSession); - } - } - - /** - * Get the API. - * - * @return - */ - @Deprecated - public WorldEditAPI getAPI() { - return api; - } - - /** - * Returns the configuration used by WorldEdit. - * - * @return - */ - public BukkitConfiguration getLocalConfiguration() { - return config; - } - - /** - * Get the permissions resolver in use. - * - * @return - */ - public PermissionsResolverManager getPermissionsResolver() { - return PermissionsResolverManager.getInstance(); - } - - /** - * Used to wrap a Bukkit Player as a LocalPlayer. - * - * @param player - * @return - */ - public BukkitPlayer wrapPlayer(Player player) { - return new BukkitPlayer(this, this.server, player); - } - - public LocalPlayer wrapCommandSender(CommandSender sender) { - if (sender instanceof Player) { - return wrapPlayer((Player) sender); - } - - return new BukkitCommandSender(this, this.server, sender); - } - - /** - * Get the server interface. - * - * @return - */ - public ServerInterface getServerInterface() { - return server; - } - - /** - * Get WorldEdit. - * - * @return - */ - public WorldEdit getWorldEdit() { - return controller; - } - - /** - * Gets the region selection for the player. - * - * @param player - * @return the selection or null if there was none - */ - public Selection getSelection(Player player) { - if (player == null) { - throw new IllegalArgumentException("Null player not allowed"); - } - if (!player.isOnline()) { - throw new IllegalArgumentException("Offline player not allowed"); - } - - LocalSession session = controller.getSession(wrapPlayer(player)); - RegionSelector selector = session.getRegionSelector(BukkitUtil.getLocalWorld(player.getWorld())); - - try { - Region region = selector.getRegion(); - World world = ((BukkitWorld) session.getSelectionWorld()).getWorld(); - - if (region instanceof CuboidRegion) { - return new CuboidSelection(world, selector, (CuboidRegion) region); - } else if (region instanceof Polygonal2DRegion) { - return new Polygonal2DSelection(world, selector, (Polygonal2DRegion) region); - } else { - return null; - } - } catch (IncompleteRegionException e) { - return null; - } - } - - /** - * Sets the region selection for a player. - * - * @param player - * @param selection - */ - public void setSelection(Player player, Selection selection) { - if (player == null) { - throw new IllegalArgumentException("Null player not allowed"); - } - if (!player.isOnline()) { - throw new IllegalArgumentException("Offline player not allowed"); - } - if (selection == null) { - throw new IllegalArgumentException("Null selection not allowed"); - } - - LocalSession session = controller.getSession(wrapPlayer(player)); - RegionSelector sel = selection.getRegionSelector(); - session.setRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()), sel); - session.dispatchCUISelection(wrapPlayer(player)); - } -} +// $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.util.yaml.YAMLProcessor; +import com.sk89q.wepif.PermissionsResolverManager; +import com.sk89q.worldedit.*; +import com.sk89q.worldedit.bukkit.selections.CuboidSelection; +import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection; +import com.sk89q.worldedit.bukkit.selections.Selection; +import com.sk89q.worldedit.extent.inventory.BlockBag; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.regions.Polygonal2DRegion; +import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.regions.RegionSelector; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.*; +import java.util.Enumeration; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import java.util.logging.Handler; +import java.util.zip.ZipEntry; + +/** + * Plugin for Bukkit. + * + * @author sk89q + */ +public class WorldEditPlugin extends JavaPlugin { + + /** + * The name of the CUI's plugin channel registration + */ + public static final String CUI_PLUGIN_CHANNEL = "WECUI"; + + /** + * The server interface that all server-related API goes through. + */ + private BukkitServerInterface server; + /** + * Main WorldEdit instance. + */ + private WorldEdit controller; + /** + * Deprecated API. + */ + private WorldEditAPI api; + + /** + * Holds the configuration for WorldEdit. + */ + private BukkitConfiguration config; + + /** + * Called on plugin enable. + */ + @Override + public void onEnable() { + final String pluginYmlVersion = getDescription().getVersion(); + final String manifestVersion = WorldEdit.getVersion(); + + if (!manifestVersion.equalsIgnoreCase(pluginYmlVersion)) { + WorldEdit.setVersion(manifestVersion + " (" + pluginYmlVersion + ")"); + } + + // Make the data folders that WorldEdit uses + getDataFolder().mkdirs(); + File targetDir = new File(getDataFolder() + File.separator + "nmsblocks"); + targetDir.mkdir(); + copyNmsBlockClasses(targetDir); + + // Create the default configuration file + createDefaultConfiguration("config.yml"); + + // Set up configuration and such, including the permissions + // resolver + config = new BukkitConfiguration(new YAMLProcessor(new File(getDataFolder(), "config.yml"), true), this); + PermissionsResolverManager.initialize(this); + + // Load the configuration + config.load(); + + // Setup interfaces + server = new BukkitServerInterface(this, getServer()); + controller = new WorldEdit(server, config); + WorldEdit.logger.setParent(Bukkit.getLogger()); + api = new WorldEditAPI(this); + getServer().getMessenger().registerIncomingPluginChannel(this, CUI_PLUGIN_CHANNEL, new CUIChannelListener(this)); + getServer().getMessenger().registerOutgoingPluginChannel(this, CUI_PLUGIN_CHANNEL); + // Now we can register events! + getServer().getPluginManager().registerEvents(new WorldEditListener(this), this); + + getServer().getScheduler().runTaskTimerAsynchronously(this, + new SessionTimer(controller, getServer()), 120, 120); + } + + private void copyNmsBlockClasses(File target) { + try { + JarFile jar = new JarFile(getFile()); + @SuppressWarnings("rawtypes") + Enumeration entries = jar.entries(); + while (entries.hasMoreElements()) { + JarEntry jarEntry = (JarEntry) entries.nextElement(); + if (!jarEntry.getName().startsWith("nmsblocks") || jarEntry.isDirectory()) continue; + + File file = new File(target + File.separator + jarEntry.getName().replace("nmsblocks", "")); + if (file.exists()) continue; + + InputStream is = jar.getInputStream(jarEntry); + FileOutputStream fos = new FileOutputStream(file); + + fos = new FileOutputStream(file); + byte[] buf = new byte[8192]; + int length = 0; + while ((length = is.read(buf)) > 0) { + fos.write(buf, 0, length); + } + fos.close(); + is.close(); + } + } catch (Throwable e) {} + } + + /** + * Called on plugin disable. + */ + @Override + public void onDisable() { + controller.clearSessions(); + for (Handler h : controller.commandLogger.getHandlers()) { + h.close(); + } + config.unload(); + server.unregisterCommands(); + this.getServer().getScheduler().cancelTasks(this); + } + + /** + * Loads and reloads all configuration. + */ + protected void loadConfiguration() { + config.unload(); + config.load(); + getPermissionsResolver().load(); + } + + /** + * Create a default configuration file from the .jar. + * + * @param name + */ + protected void createDefaultConfiguration(String name) { + File actual = new File(getDataFolder(), name); + if (!actual.exists()) { + InputStream input = + null; + try { + JarFile file = new JarFile(getFile()); + ZipEntry copy = file.getEntry("defaults/" + name); + if (copy == null) throw new FileNotFoundException(); + input = file.getInputStream(copy); + } catch (IOException e) { + getLogger().severe("Unable to read default configuration: " + name); + } + if (input != null) { + FileOutputStream output = null; + + try { + output = new FileOutputStream(actual); + byte[] buf = new byte[8192]; + int length = 0; + while ((length = input.read(buf)) > 0) { + output.write(buf, 0, length); + } + + getLogger().info("Default configuration file written: " + name); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if (input != null) { + input.close(); + } + } catch (IOException e) {} + + try { + if (output != null) { + output.close(); + } + } catch (IOException e) {} + } + } + } + } + + /** + * Called on WorldEdit command. + */ + @Override + public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd, + String commandLabel, String[] args) { + + // Add the command to the array because the underlying command handling + // code of WorldEdit expects it + String[] split = new String[args.length + 1]; + System.arraycopy(args, 0, split, 1, args.length); + split[0] = "/" + cmd.getName(); + + controller.handleCommand(wrapCommandSender(sender), split); + + return true; + } + + /** + * Gets the session for the player. + * + * @param player + * @return + */ + public LocalSession getSession(Player player) { + return controller.getSession(wrapPlayer(player)); + } + + /** + * Gets the session for the player. + * + * @param player + * @return + */ + public EditSession createEditSession(Player player) { + LocalPlayer wePlayer = wrapPlayer(player); + LocalSession session = controller.getSession(wePlayer); + BlockBag blockBag = session.getBlockBag(wePlayer); + + EditSession editSession = controller.getEditSessionFactory() + .getEditSession(wePlayer.getWorld(), session.getBlockChangeLimit(), blockBag, wePlayer); + editSession.enableQueue(); + + return editSession; + } + + /** + * Remember an edit session. + * + * @param player + * @param editSession + */ + public void remember(Player player, EditSession editSession) { + LocalPlayer wePlayer = wrapPlayer(player); + LocalSession session = controller.getSession(wePlayer); + + session.remember(editSession); + editSession.flushQueue(); + + controller.flushBlockBag(wePlayer, editSession); + } + + /** + * Wrap an operation into an EditSession. + * + * @param player + * @param op + * @throws Throwable + */ + public void perform(Player player, WorldEditOperation op) + throws Throwable { + LocalPlayer wePlayer = wrapPlayer(player); + LocalSession session = controller.getSession(wePlayer); + + EditSession editSession = createEditSession(player); + try { + op.run(session, wePlayer, editSession); + } finally { + remember(player, editSession); + } + } + + /** + * Get the API. + * + * @return + */ + @Deprecated + public WorldEditAPI getAPI() { + return api; + } + + /** + * Returns the configuration used by WorldEdit. + * + * @return + */ + public BukkitConfiguration getLocalConfiguration() { + return config; + } + + /** + * Get the permissions resolver in use. + * + * @return + */ + public PermissionsResolverManager getPermissionsResolver() { + return PermissionsResolverManager.getInstance(); + } + + /** + * Used to wrap a Bukkit Player as a LocalPlayer. + * + * @param player + * @return + */ + public BukkitPlayer wrapPlayer(Player player) { + return new BukkitPlayer(this, this.server, player); + } + + public LocalPlayer wrapCommandSender(CommandSender sender) { + if (sender instanceof Player) { + return wrapPlayer((Player) sender); + } + + return new BukkitCommandSender(this, this.server, sender); + } + + /** + * Get the server interface. + * + * @return + */ + public ServerInterface getServerInterface() { + return server; + } + + /** + * Get WorldEdit. + * + * @return + */ + public WorldEdit getWorldEdit() { + return controller; + } + + /** + * Gets the region selection for the player. + * + * @param player + * @return the selection or null if there was none + */ + public Selection getSelection(Player player) { + if (player == null) { + throw new IllegalArgumentException("Null player not allowed"); + } + if (!player.isOnline()) { + throw new IllegalArgumentException("Offline player not allowed"); + } + + LocalSession session = controller.getSession(wrapPlayer(player)); + RegionSelector selector = session.getRegionSelector(BukkitUtil.getLocalWorld(player.getWorld())); + + try { + Region region = selector.getRegion(); + World world = ((BukkitWorld) session.getSelectionWorld()).getWorld(); + + if (region instanceof CuboidRegion) { + return new CuboidSelection(world, selector, (CuboidRegion) region); + } else if (region instanceof Polygonal2DRegion) { + return new Polygonal2DSelection(world, selector, (Polygonal2DRegion) region); + } else { + return null; + } + } catch (IncompleteRegionException e) { + return null; + } + } + + /** + * Sets the region selection for a player. + * + * @param player + * @param selection + */ + public void setSelection(Player player, Selection selection) { + if (player == null) { + throw new IllegalArgumentException("Null player not allowed"); + } + if (!player.isOnline()) { + throw new IllegalArgumentException("Offline player not allowed"); + } + if (selection == null) { + throw new IllegalArgumentException("Null selection not allowed"); + } + + LocalSession session = controller.getSession(wrapPlayer(player)); + RegionSelector sel = selection.getRegionSelector(); + session.setRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()), sel); + session.dispatchCUISelection(wrapPlayer(player)); + } +} diff --git a/src/main/java/com/sk89q/worldedit/bukkit/entity/BukkitEntity.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/entity/BukkitEntity.java similarity index 100% rename from src/main/java/com/sk89q/worldedit/bukkit/entity/BukkitEntity.java rename to src/bukkit/java/com/sk89q/worldedit/bukkit/entity/BukkitEntity.java diff --git a/src/main/java/com/sk89q/worldedit/bukkit/entity/BukkitExpOrb.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/entity/BukkitExpOrb.java similarity index 100% rename from src/main/java/com/sk89q/worldedit/bukkit/entity/BukkitExpOrb.java rename to src/bukkit/java/com/sk89q/worldedit/bukkit/entity/BukkitExpOrb.java diff --git a/src/main/java/com/sk89q/worldedit/bukkit/entity/BukkitItem.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/entity/BukkitItem.java similarity index 100% rename from src/main/java/com/sk89q/worldedit/bukkit/entity/BukkitItem.java rename to src/bukkit/java/com/sk89q/worldedit/bukkit/entity/BukkitItem.java diff --git a/src/main/java/com/sk89q/worldedit/bukkit/entity/BukkitPainting.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/entity/BukkitPainting.java similarity index 100% rename from src/main/java/com/sk89q/worldedit/bukkit/entity/BukkitPainting.java rename to src/bukkit/java/com/sk89q/worldedit/bukkit/entity/BukkitPainting.java diff --git a/src/main/java/com/sk89q/worldedit/bukkit/selections/CuboidSelection.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/selections/CuboidSelection.java similarity index 96% rename from src/main/java/com/sk89q/worldedit/bukkit/selections/CuboidSelection.java rename to src/bukkit/java/com/sk89q/worldedit/bukkit/selections/CuboidSelection.java index 857689af2..4f7a7fb2c 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/selections/CuboidSelection.java +++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/selections/CuboidSelection.java @@ -1,67 +1,67 @@ -// $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.worldedit.bukkit.selections; - -import org.bukkit.Location; -import org.bukkit.World; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.bukkit.BukkitUtil; -import com.sk89q.worldedit.regions.*; - -public class CuboidSelection extends RegionSelection { - - protected CuboidRegion cuboid; - - public CuboidSelection(World world, Location pt1, Location pt2) { - this(world, BukkitUtil.toVector(pt1), BukkitUtil.toVector(pt2)); - } - - public CuboidSelection(World world, Vector pt1, Vector pt2) { - super(world); - - // Validate input - if (pt1 == null) { - throw new IllegalArgumentException("Null point 1 not permitted"); - } - - if (pt2 == null) { - throw new IllegalArgumentException("Null point 2 not permitted"); - } - - // Create new selector - CuboidRegionSelector sel = new CuboidRegionSelector(BukkitUtil.getLocalWorld(world)); - - // set up selector - sel.selectPrimary(pt1); - sel.selectSecondary(pt2); - - // set up CuboidSelection - cuboid = sel.getIncompleteRegion(); - - // set up RegionSelection - setRegionSelector(sel); - setRegion(cuboid); - } - - public CuboidSelection(World world, RegionSelector sel, CuboidRegion region) { - super(world, sel, region); - this.cuboid = region; - } -} +// $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.worldedit.bukkit.selections; + +import org.bukkit.Location; +import org.bukkit.World; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.bukkit.BukkitUtil; +import com.sk89q.worldedit.regions.*; + +public class CuboidSelection extends RegionSelection { + + protected CuboidRegion cuboid; + + public CuboidSelection(World world, Location pt1, Location pt2) { + this(world, BukkitUtil.toVector(pt1), BukkitUtil.toVector(pt2)); + } + + public CuboidSelection(World world, Vector pt1, Vector pt2) { + super(world); + + // Validate input + if (pt1 == null) { + throw new IllegalArgumentException("Null point 1 not permitted"); + } + + if (pt2 == null) { + throw new IllegalArgumentException("Null point 2 not permitted"); + } + + // Create new selector + CuboidRegionSelector sel = new CuboidRegionSelector(BukkitUtil.getLocalWorld(world)); + + // set up selector + sel.selectPrimary(pt1); + sel.selectSecondary(pt2); + + // set up CuboidSelection + cuboid = sel.getIncompleteRegion(); + + // set up RegionSelection + setRegionSelector(sel); + setRegion(cuboid); + } + + public CuboidSelection(World world, RegionSelector sel, CuboidRegion region) { + super(world, sel, region); + this.cuboid = region; + } +} diff --git a/src/main/java/com/sk89q/worldedit/bukkit/selections/Polygonal2DSelection.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/selections/Polygonal2DSelection.java similarity index 97% rename from src/main/java/com/sk89q/worldedit/bukkit/selections/Polygonal2DSelection.java rename to src/bukkit/java/com/sk89q/worldedit/bukkit/selections/Polygonal2DSelection.java index 6a6107add..b51b0afab 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/selections/Polygonal2DSelection.java +++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/selections/Polygonal2DSelection.java @@ -1,62 +1,62 @@ -// $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.worldedit.bukkit.selections; - -import java.util.Collections; -import java.util.List; - -import com.sk89q.worldedit.LocalWorld; -import org.bukkit.World; -import com.sk89q.worldedit.BlockVector2D; -import com.sk89q.worldedit.bukkit.BukkitUtil; -import com.sk89q.worldedit.regions.*; - -public class Polygonal2DSelection extends RegionSelection { - - protected Polygonal2DRegion poly2d; - - public Polygonal2DSelection(World world, RegionSelector sel, Polygonal2DRegion region) { - super(world, sel, region); - this.poly2d = region; - } - - public Polygonal2DSelection(World world, List points, int minY, int maxY) { - super(world); - LocalWorld lWorld = BukkitUtil.getLocalWorld(world); - - // Validate input - minY = Math.min(Math.max(0, minY), world.getMaxHeight()); - maxY = Math.min(Math.max(0, maxY), world.getMaxHeight()); - - // Create and set up new selector - Polygonal2DRegionSelector sel = new Polygonal2DRegionSelector(lWorld, points, minY, maxY); - - // set up CuboidSelection - poly2d = sel.getIncompleteRegion(); - - // set up RegionSelection - setRegionSelector(sel); - setRegion(poly2d); - } - - public List getNativePoints() { - return Collections.unmodifiableList(poly2d.getPoints()); - } -} +// $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.worldedit.bukkit.selections; + +import java.util.Collections; +import java.util.List; + +import com.sk89q.worldedit.LocalWorld; +import org.bukkit.World; +import com.sk89q.worldedit.BlockVector2D; +import com.sk89q.worldedit.bukkit.BukkitUtil; +import com.sk89q.worldedit.regions.*; + +public class Polygonal2DSelection extends RegionSelection { + + protected Polygonal2DRegion poly2d; + + public Polygonal2DSelection(World world, RegionSelector sel, Polygonal2DRegion region) { + super(world, sel, region); + this.poly2d = region; + } + + public Polygonal2DSelection(World world, List points, int minY, int maxY) { + super(world); + LocalWorld lWorld = BukkitUtil.getLocalWorld(world); + + // Validate input + minY = Math.min(Math.max(0, minY), world.getMaxHeight()); + maxY = Math.min(Math.max(0, maxY), world.getMaxHeight()); + + // Create and set up new selector + Polygonal2DRegionSelector sel = new Polygonal2DRegionSelector(lWorld, points, minY, maxY); + + // set up CuboidSelection + poly2d = sel.getIncompleteRegion(); + + // set up RegionSelection + setRegionSelector(sel); + setRegion(poly2d); + } + + public List getNativePoints() { + return Collections.unmodifiableList(poly2d.getPoints()); + } +} diff --git a/src/main/java/com/sk89q/worldedit/bukkit/selections/RegionSelection.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/selections/RegionSelection.java similarity index 96% rename from src/main/java/com/sk89q/worldedit/bukkit/selections/RegionSelection.java rename to src/bukkit/java/com/sk89q/worldedit/bukkit/selections/RegionSelection.java index a50f28878..10fbaa962 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/selections/RegionSelection.java +++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/selections/RegionSelection.java @@ -1,106 +1,106 @@ -// $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.worldedit.bukkit.selections; - -import static com.sk89q.worldedit.bukkit.BukkitUtil.toLocation; -import static com.sk89q.worldedit.bukkit.BukkitUtil.toVector; -import org.bukkit.Location; -import org.bukkit.World; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.regions.RegionSelector; - -public abstract class RegionSelection implements Selection { - - private World world; - private RegionSelector selector; - private Region region; - - public RegionSelection(World world) { - this.world = world; - } - - public RegionSelection(World world, RegionSelector selector, Region region) { - this.world = world; - this.region = region; - this.selector = selector; - } - - protected Region getRegion() { - return region; - } - - protected void setRegion(Region region) { - this.region = region; - } - - public RegionSelector getRegionSelector() { - return selector; - } - - protected void setRegionSelector(RegionSelector selector) { - this.selector = selector; - } - - public Location getMinimumPoint() { - return toLocation(world, region.getMinimumPoint()); - } - - public Vector getNativeMinimumPoint() { - return region.getMinimumPoint(); - } - - public Location getMaximumPoint() { - return toLocation(world, region.getMaximumPoint()); - } - - public Vector getNativeMaximumPoint() { - return region.getMaximumPoint(); - } - - public World getWorld() { - return world; - } - - public int getArea() { - return region.getArea(); - } - - public int getWidth() { - return region.getWidth(); - } - - public int getHeight() { - return region.getHeight(); - } - - public int getLength() { - return region.getLength(); - } - - public boolean contains(Location pt) { - if (!pt.getWorld().equals(world)) { - return false; - } - - return region.contains(toVector(pt)); - } - -} +// $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.worldedit.bukkit.selections; + +import static com.sk89q.worldedit.bukkit.BukkitUtil.toLocation; +import static com.sk89q.worldedit.bukkit.BukkitUtil.toVector; +import org.bukkit.Location; +import org.bukkit.World; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.regions.RegionSelector; + +public abstract class RegionSelection implements Selection { + + private World world; + private RegionSelector selector; + private Region region; + + public RegionSelection(World world) { + this.world = world; + } + + public RegionSelection(World world, RegionSelector selector, Region region) { + this.world = world; + this.region = region; + this.selector = selector; + } + + protected Region getRegion() { + return region; + } + + protected void setRegion(Region region) { + this.region = region; + } + + public RegionSelector getRegionSelector() { + return selector; + } + + protected void setRegionSelector(RegionSelector selector) { + this.selector = selector; + } + + public Location getMinimumPoint() { + return toLocation(world, region.getMinimumPoint()); + } + + public Vector getNativeMinimumPoint() { + return region.getMinimumPoint(); + } + + public Location getMaximumPoint() { + return toLocation(world, region.getMaximumPoint()); + } + + public Vector getNativeMaximumPoint() { + return region.getMaximumPoint(); + } + + public World getWorld() { + return world; + } + + public int getArea() { + return region.getArea(); + } + + public int getWidth() { + return region.getWidth(); + } + + public int getHeight() { + return region.getHeight(); + } + + public int getLength() { + return region.getLength(); + } + + public boolean contains(Location pt) { + if (!pt.getWorld().equals(world)) { + return false; + } + + return region.contains(toVector(pt)); + } + +} diff --git a/src/main/java/com/sk89q/worldedit/bukkit/selections/Selection.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/selections/Selection.java similarity index 95% rename from src/main/java/com/sk89q/worldedit/bukkit/selections/Selection.java rename to src/bukkit/java/com/sk89q/worldedit/bukkit/selections/Selection.java index baa4c039e..4cf324172 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/selections/Selection.java +++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/selections/Selection.java @@ -1,105 +1,105 @@ -// $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.worldedit.bukkit.selections; - -import org.bukkit.Location; -import org.bukkit.World; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.regions.RegionSelector; - -public interface Selection { - /** - * Get the lower point of a region. - * - * @return min. point - */ - public Location getMinimumPoint(); - - /** - * Get the lower point of a region. - * - * @return min. point - */ - public Vector getNativeMinimumPoint(); - - /** - * Get the upper point of a region. - * - * @return max. point - */ - public Location getMaximumPoint(); - - /** - * Get the upper point of a region. - * - * @return max. point - */ - public Vector getNativeMaximumPoint(); - - /** - * Get the region selector. This is for internal use. - * - * @return - */ - public RegionSelector getRegionSelector(); - - /** - * Get the world. - * - * @return - */ - public World getWorld(); - - /** - * Get the number of blocks in the region. - * - * @return number of blocks - */ - public int getArea(); - - /** - * Get X-size. - * - * @return width - */ - public int getWidth(); - - /** - * Get Y-size. - * - * @return height - */ - public int getHeight(); - - /** - * Get Z-size. - * - * @return length - */ - public int getLength(); - - /** - * Returns true based on whether the region contains the point, - * - * @param pt - * @return - */ - public boolean contains(Location pt); -} +// $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.worldedit.bukkit.selections; + +import org.bukkit.Location; +import org.bukkit.World; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.regions.RegionSelector; + +public interface Selection { + /** + * Get the lower point of a region. + * + * @return min. point + */ + public Location getMinimumPoint(); + + /** + * Get the lower point of a region. + * + * @return min. point + */ + public Vector getNativeMinimumPoint(); + + /** + * Get the upper point of a region. + * + * @return max. point + */ + public Location getMaximumPoint(); + + /** + * Get the upper point of a region. + * + * @return max. point + */ + public Vector getNativeMaximumPoint(); + + /** + * Get the region selector. This is for internal use. + * + * @return + */ + public RegionSelector getRegionSelector(); + + /** + * Get the world. + * + * @return + */ + public World getWorld(); + + /** + * Get the number of blocks in the region. + * + * @return number of blocks + */ + public int getArea(); + + /** + * Get X-size. + * + * @return width + */ + public int getWidth(); + + /** + * Get Y-size. + * + * @return height + */ + public int getHeight(); + + /** + * Get Z-size. + * + * @return length + */ + public int getLength(); + + /** + * Returns true based on whether the region contains the point, + * + * @param pt + * @return + */ + public boolean contains(Location pt); +} diff --git a/src/main/resources/config.yml b/src/bukkit/resources/config.yml similarity index 96% rename from src/main/resources/config.yml rename to src/bukkit/resources/config.yml index f4c7c2981..913a0decc 100644 --- a/src/main/resources/config.yml +++ b/src/bukkit/resources/config.yml @@ -1,72 +1,72 @@ -# -# WorldEdit's configuration file -# -# About editing this file: -# - DO NOT USE TABS. You MUST use spaces or Bukkit will complain. If -# you use an editor like Notepad++ (recommended for Windows users), you -# must configure it to "replace tabs with spaces." In Notepad++, this can -# be changed in Settings > Preferences > Language Menu. -# - Don't get rid of the indents. They are indented so some entries are -# in categories (like "max-blocks-changed" is in the "limits" -# category. -# - If you want to check the format of this file before putting it -# into WorldEdit, paste it into http://yaml-online-parser.appspot.com/ -# and see if it gives "ERROR:". -# - Lines starting with # are commentsand so they are ignored. -# - -limits: - allow-extra-data-values: false - max-blocks-changed: - default: -1 - maximum: -1 - max-polygonal-points: - default: -1 - maximum: 20 - max-radius: -1 - max-super-pickaxe-size: 5 - max-brush-radius: 5 - butcher-radius: - default: -1 - maximum: -1 - disallowed-blocks: [6, 7, 14, 15, 16, 26, 27, 28, 29, 39, 31, 32, 33, 34, 36, 37, 38, 39, 40, 46, 50, 51, 56, 59, 69, 73, 74, 75, 76, 77, 81, 83] - -use-inventory: - enable: false - allow-override: true - creative-mode-overrides: false - -logging: - log-commands: false - file: worldedit.log - -super-pickaxe: - drop-items: true - many-drop-items: false - -snapshots: - directory: - -navigation-wand: - item: 345 - max-distance: 100 - -scripting: - timeout: 3000 - dir: craftscripts - -saving: - dir: schematics - -files: - allow-symbolic-links: false - -history: - size: 15 - expiration: 10 - -wand-item: 271 -shell-save-type: -no-double-slash: false -no-op-permissions: false -debug: false +# +# WorldEdit's configuration file +# +# About editing this file: +# - DO NOT USE TABS. You MUST use spaces or Bukkit will complain. If +# you use an editor like Notepad++ (recommended for Windows users), you +# must configure it to "replace tabs with spaces." In Notepad++, this can +# be changed in Settings > Preferences > Language Menu. +# - Don't get rid of the indents. They are indented so some entries are +# in categories (like "max-blocks-changed" is in the "limits" +# category. +# - If you want to check the format of this file before putting it +# into WorldEdit, paste it into http://yaml-online-parser.appspot.com/ +# and see if it gives "ERROR:". +# - Lines starting with # are commentsand so they are ignored. +# + +limits: + allow-extra-data-values: false + max-blocks-changed: + default: -1 + maximum: -1 + max-polygonal-points: + default: -1 + maximum: 20 + max-radius: -1 + max-super-pickaxe-size: 5 + max-brush-radius: 5 + butcher-radius: + default: -1 + maximum: -1 + disallowed-blocks: [6, 7, 14, 15, 16, 26, 27, 28, 29, 39, 31, 32, 33, 34, 36, 37, 38, 39, 40, 46, 50, 51, 56, 59, 69, 73, 74, 75, 76, 77, 81, 83] + +use-inventory: + enable: false + allow-override: true + creative-mode-overrides: false + +logging: + log-commands: false + file: worldedit.log + +super-pickaxe: + drop-items: true + many-drop-items: false + +snapshots: + directory: + +navigation-wand: + item: 345 + max-distance: 100 + +scripting: + timeout: 3000 + dir: craftscripts + +saving: + dir: schematics + +files: + allow-symbolic-links: false + +history: + size: 15 + expiration: 10 + +wand-item: 271 +shell-save-type: +no-double-slash: false +no-op-permissions: false +debug: false diff --git a/src/main/resources/nmsblocks/CBXNmsBlock_145.class b/src/bukkit/resources/nmsblocks/CBXNmsBlock_145.class similarity index 100% rename from src/main/resources/nmsblocks/CBXNmsBlock_145.class rename to src/bukkit/resources/nmsblocks/CBXNmsBlock_145.class diff --git a/src/main/resources/nmsblocks/CBXNmsBlock_146.class b/src/bukkit/resources/nmsblocks/CBXNmsBlock_146.class similarity index 100% rename from src/main/resources/nmsblocks/CBXNmsBlock_146.class rename to src/bukkit/resources/nmsblocks/CBXNmsBlock_146.class diff --git a/src/main/resources/nmsblocks/CBXNmsBlock_147.class b/src/bukkit/resources/nmsblocks/CBXNmsBlock_147.class similarity index 100% rename from src/main/resources/nmsblocks/CBXNmsBlock_147.class rename to src/bukkit/resources/nmsblocks/CBXNmsBlock_147.class diff --git a/src/main/resources/nmsblocks/CBXNmsBlock_15.class b/src/bukkit/resources/nmsblocks/CBXNmsBlock_15.class similarity index 100% rename from src/main/resources/nmsblocks/CBXNmsBlock_15.class rename to src/bukkit/resources/nmsblocks/CBXNmsBlock_15.class diff --git a/src/main/resources/nmsblocks/CBXNmsBlock_152.class b/src/bukkit/resources/nmsblocks/CBXNmsBlock_152.class similarity index 100% rename from src/main/resources/nmsblocks/CBXNmsBlock_152.class rename to src/bukkit/resources/nmsblocks/CBXNmsBlock_152.class diff --git a/src/main/resources/nmsblocks/CBXNmsBlock_161.class b/src/bukkit/resources/nmsblocks/CBXNmsBlock_161.class similarity index 100% rename from src/main/resources/nmsblocks/CBXNmsBlock_161.class rename to src/bukkit/resources/nmsblocks/CBXNmsBlock_161.class diff --git a/src/main/resources/nmsblocks/CBXNmsBlock_162.class b/src/bukkit/resources/nmsblocks/CBXNmsBlock_162.class similarity index 100% rename from src/main/resources/nmsblocks/CBXNmsBlock_162.class rename to src/bukkit/resources/nmsblocks/CBXNmsBlock_162.class diff --git a/src/main/resources/nmsblocks/CBXNmsBlock_164.class b/src/bukkit/resources/nmsblocks/CBXNmsBlock_164.class similarity index 100% rename from src/main/resources/nmsblocks/CBXNmsBlock_164.class rename to src/bukkit/resources/nmsblocks/CBXNmsBlock_164.class diff --git a/src/main/resources/nmsblocks/CBXNmsBlock_172.class b/src/bukkit/resources/nmsblocks/CBXNmsBlock_172.class similarity index 100% rename from src/main/resources/nmsblocks/CBXNmsBlock_172.class rename to src/bukkit/resources/nmsblocks/CBXNmsBlock_172.class diff --git a/src/main/resources/nmsblocks/CBXNmsBlock_175.class b/src/bukkit/resources/nmsblocks/CBXNmsBlock_175.class similarity index 100% rename from src/main/resources/nmsblocks/CBXNmsBlock_175.class rename to src/bukkit/resources/nmsblocks/CBXNmsBlock_175.class diff --git a/src/main/resources/nmsblocks/CBXNmsBlock_prePackage.class b/src/bukkit/resources/nmsblocks/CBXNmsBlock_prePackage.class similarity index 100% rename from src/main/resources/nmsblocks/CBXNmsBlock_prePackage.class rename to src/bukkit/resources/nmsblocks/CBXNmsBlock_prePackage.class diff --git a/src/main/resources/nmsblocks/CBXNmsBlock_v152_2.class b/src/bukkit/resources/nmsblocks/CBXNmsBlock_v152_2.class similarity index 100% rename from src/main/resources/nmsblocks/CBXNmsBlock_v152_2.class rename to src/bukkit/resources/nmsblocks/CBXNmsBlock_v152_2.class diff --git a/src/main/resources/nmsblocks/MCPCPlusXNmsBlock_147.class b/src/bukkit/resources/nmsblocks/MCPCPlusXNmsBlock_147.class similarity index 100% rename from src/main/resources/nmsblocks/MCPCPlusXNmsBlock_147.class rename to src/bukkit/resources/nmsblocks/MCPCPlusXNmsBlock_147.class diff --git a/src/main/resources/nmsblocks/MCPCPlusXNmsBlock_151dv.class b/src/bukkit/resources/nmsblocks/MCPCPlusXNmsBlock_151dv.class similarity index 100% rename from src/main/resources/nmsblocks/MCPCPlusXNmsBlock_151dv.class rename to src/bukkit/resources/nmsblocks/MCPCPlusXNmsBlock_151dv.class diff --git a/src/main/resources/nmsblocks/MCPCPlusXNmsBlock_162.class b/src/bukkit/resources/nmsblocks/MCPCPlusXNmsBlock_162.class similarity index 100% rename from src/main/resources/nmsblocks/MCPCPlusXNmsBlock_162.class rename to src/bukkit/resources/nmsblocks/MCPCPlusXNmsBlock_162.class diff --git a/src/main/resources/nmsblocks/MCPCPlusXNmsBlock_164.class b/src/bukkit/resources/nmsblocks/MCPCPlusXNmsBlock_164.class similarity index 100% rename from src/main/resources/nmsblocks/MCPCPlusXNmsBlock_164.class rename to src/bukkit/resources/nmsblocks/MCPCPlusXNmsBlock_164.class diff --git a/src/main/resources/plugin.yml b/src/bukkit/resources/plugin.yml similarity index 100% rename from src/main/resources/plugin.yml rename to src/bukkit/resources/plugin.yml diff --git a/src/main/java/com/sk89q/worldedit/masks/AbstractMask.java b/src/legacy/java/com/sk89q/worldedit/masks/AbstractMask.java similarity index 96% rename from src/main/java/com/sk89q/worldedit/masks/AbstractMask.java rename to src/legacy/java/com/sk89q/worldedit/masks/AbstractMask.java index 05525fe9b..07ba3c176 100644 --- a/src/main/java/com/sk89q/worldedit/masks/AbstractMask.java +++ b/src/legacy/java/com/sk89q/worldedit/masks/AbstractMask.java @@ -1,16 +1,16 @@ -package com.sk89q.worldedit.masks; - -import com.sk89q.worldedit.LocalPlayer; -import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; - -/** - * @deprecated Switch to {@link com.sk89q.worldedit.function.mask.AbstractMask} - */ -@Deprecated -public abstract class AbstractMask implements Mask { - @Override - public void prepare(LocalSession session, LocalPlayer player, Vector target) { - } - -} +package com.sk89q.worldedit.masks; + +import com.sk89q.worldedit.LocalPlayer; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.Vector; + +/** + * @deprecated Switch to {@link com.sk89q.worldedit.function.mask.AbstractMask} + */ +@Deprecated +public abstract class AbstractMask implements Mask { + @Override + public void prepare(LocalSession session, LocalPlayer player, Vector target) { + } + +} diff --git a/src/main/java/com/sk89q/worldedit/masks/BiomeTypeMask.java b/src/legacy/java/com/sk89q/worldedit/masks/BiomeTypeMask.java similarity index 100% rename from src/main/java/com/sk89q/worldedit/masks/BiomeTypeMask.java rename to src/legacy/java/com/sk89q/worldedit/masks/BiomeTypeMask.java diff --git a/src/main/java/com/sk89q/worldedit/masks/BlockMask.java b/src/legacy/java/com/sk89q/worldedit/masks/BlockMask.java similarity index 100% rename from src/main/java/com/sk89q/worldedit/masks/BlockMask.java rename to src/legacy/java/com/sk89q/worldedit/masks/BlockMask.java diff --git a/src/main/java/com/sk89q/worldedit/masks/BlockTypeMask.java b/src/legacy/java/com/sk89q/worldedit/masks/BlockTypeMask.java similarity index 96% rename from src/main/java/com/sk89q/worldedit/masks/BlockTypeMask.java rename to src/legacy/java/com/sk89q/worldedit/masks/BlockTypeMask.java index 5a9dee9fc..c4df2671c 100644 --- a/src/main/java/com/sk89q/worldedit/masks/BlockTypeMask.java +++ b/src/legacy/java/com/sk89q/worldedit/masks/BlockTypeMask.java @@ -1,52 +1,52 @@ -// $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.worldedit.masks; - -import java.util.Set; -import com.sk89q.worldedit.blocks.BaseBlock; - -/** - * A filter that matches blocks based on block types. - * - * @deprecated replaced by {@link #BlockMask} - * @author sk89q - */ -@Deprecated -public class BlockTypeMask extends BlockMask { - public BlockTypeMask() { - super(); - } - - public BlockTypeMask(Set types) { - super(); - for (int type : types) { - add(type); - } - } - - public BlockTypeMask(int type) { - this(); - add(type); - } - - public void add(int type) { - add(new BaseBlock(type)); - } -} +// $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.worldedit.masks; + +import java.util.Set; +import com.sk89q.worldedit.blocks.BaseBlock; + +/** + * A filter that matches blocks based on block types. + * + * @deprecated replaced by {@link #BlockMask} + * @author sk89q + */ +@Deprecated +public class BlockTypeMask extends BlockMask { + public BlockTypeMask() { + super(); + } + + public BlockTypeMask(Set types) { + super(); + for (int type : types) { + add(type); + } + } + + public BlockTypeMask(int type) { + this(); + add(type); + } + + public void add(int type) { + add(new BaseBlock(type)); + } +} diff --git a/src/main/java/com/sk89q/worldedit/masks/CombinedMask.java b/src/legacy/java/com/sk89q/worldedit/masks/CombinedMask.java similarity index 96% rename from src/main/java/com/sk89q/worldedit/masks/CombinedMask.java rename to src/legacy/java/com/sk89q/worldedit/masks/CombinedMask.java index 2a8b0ecd8..48b7c8d42 100644 --- a/src/main/java/com/sk89q/worldedit/masks/CombinedMask.java +++ b/src/legacy/java/com/sk89q/worldedit/masks/CombinedMask.java @@ -1,84 +1,84 @@ -// $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.worldedit.masks; - -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.LocalPlayer; -import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.function.mask.MaskIntersection; - -import java.util.ArrayList; -import java.util.List; - -/** - * @deprecated See {@link MaskIntersection} - */ -@Deprecated -public class CombinedMask extends AbstractMask { - private final List masks = new ArrayList(); - - public CombinedMask() { - } - - public CombinedMask(Mask mask) { - add(mask); - } - - public CombinedMask(Mask ...mask) { - for (Mask m : mask) { - add(m); - } - } - - public CombinedMask(List masks) { - this.masks.addAll(masks); - } - - public void add(Mask mask) { - masks.add(mask); - } - - public boolean remove(Mask mask) { - return masks.remove(mask); - } - - public boolean has(Mask mask) { - return masks.contains(mask); - } - - @Override - public void prepare(LocalSession session, LocalPlayer player, Vector target) { - for (Mask mask : masks) { - mask.prepare(session, player, target); - } - } - - @Override - public boolean matches(EditSession editSession, Vector pos) { - for (Mask mask : masks) { - if (!mask.matches(editSession, pos)) { - return false; - } - } - - return true; - } -} +// $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.worldedit.masks; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalPlayer; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.function.mask.MaskIntersection; + +import java.util.ArrayList; +import java.util.List; + +/** + * @deprecated See {@link MaskIntersection} + */ +@Deprecated +public class CombinedMask extends AbstractMask { + private final List masks = new ArrayList(); + + public CombinedMask() { + } + + public CombinedMask(Mask mask) { + add(mask); + } + + public CombinedMask(Mask ...mask) { + for (Mask m : mask) { + add(m); + } + } + + public CombinedMask(List masks) { + this.masks.addAll(masks); + } + + public void add(Mask mask) { + masks.add(mask); + } + + public boolean remove(Mask mask) { + return masks.remove(mask); + } + + public boolean has(Mask mask) { + return masks.contains(mask); + } + + @Override + public void prepare(LocalSession session, LocalPlayer player, Vector target) { + for (Mask mask : masks) { + mask.prepare(session, player, target); + } + } + + @Override + public boolean matches(EditSession editSession, Vector pos) { + for (Mask mask : masks) { + if (!mask.matches(editSession, pos)) { + return false; + } + } + + return true; + } +} diff --git a/src/main/java/com/sk89q/worldedit/masks/DynamicRegionMask.java b/src/legacy/java/com/sk89q/worldedit/masks/DynamicRegionMask.java similarity index 100% rename from src/main/java/com/sk89q/worldedit/masks/DynamicRegionMask.java rename to src/legacy/java/com/sk89q/worldedit/masks/DynamicRegionMask.java diff --git a/src/main/java/com/sk89q/worldedit/masks/ExistingBlockMask.java b/src/legacy/java/com/sk89q/worldedit/masks/ExistingBlockMask.java similarity index 97% rename from src/main/java/com/sk89q/worldedit/masks/ExistingBlockMask.java rename to src/legacy/java/com/sk89q/worldedit/masks/ExistingBlockMask.java index 09c4231d0..c258314db 100644 --- a/src/main/java/com/sk89q/worldedit/masks/ExistingBlockMask.java +++ b/src/legacy/java/com/sk89q/worldedit/masks/ExistingBlockMask.java @@ -1,35 +1,35 @@ -// $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.worldedit.masks; - -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.blocks.BlockID; - -/** - * @deprecated See {@link com.sk89q.worldedit.function.mask.ExistingBlockMask} - */ -@Deprecated -public class ExistingBlockMask extends AbstractMask { - @Override - public boolean matches(EditSession editSession, Vector pos) { - return editSession.getBlockType(pos) != BlockID.AIR; - } -} +// $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.worldedit.masks; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.blocks.BlockID; + +/** + * @deprecated See {@link com.sk89q.worldedit.function.mask.ExistingBlockMask} + */ +@Deprecated +public class ExistingBlockMask extends AbstractMask { + @Override + public boolean matches(EditSession editSession, Vector pos) { + return editSession.getBlockType(pos) != BlockID.AIR; + } +} diff --git a/src/main/java/com/sk89q/worldedit/masks/FuzzyBlockMask.java b/src/legacy/java/com/sk89q/worldedit/masks/FuzzyBlockMask.java similarity index 100% rename from src/main/java/com/sk89q/worldedit/masks/FuzzyBlockMask.java rename to src/legacy/java/com/sk89q/worldedit/masks/FuzzyBlockMask.java diff --git a/src/main/java/com/sk89q/worldedit/masks/InvertedBlockTypeMask.java b/src/legacy/java/com/sk89q/worldedit/masks/InvertedBlockTypeMask.java similarity index 96% rename from src/main/java/com/sk89q/worldedit/masks/InvertedBlockTypeMask.java rename to src/legacy/java/com/sk89q/worldedit/masks/InvertedBlockTypeMask.java index 9fef49649..da30fa917 100644 --- a/src/main/java/com/sk89q/worldedit/masks/InvertedBlockTypeMask.java +++ b/src/legacy/java/com/sk89q/worldedit/masks/InvertedBlockTypeMask.java @@ -1,54 +1,54 @@ -// $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.worldedit.masks; - -import java.util.Set; -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; - -/** - * A block type mask that only matches blocks that are not in the list. - * - * @author sk89q - */ -@Deprecated -public class InvertedBlockTypeMask extends BlockTypeMask { - public InvertedBlockTypeMask() { - } - - /** - * @param types - */ - public InvertedBlockTypeMask(Set types) { - super(types); - } - - /** - * @param type - */ - public InvertedBlockTypeMask(int type) { - super(type); - } - - @Override - public boolean matches(EditSession editSession, Vector pos) { - return !super.matches(editSession, pos); - } -} +// $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.worldedit.masks; + +import java.util.Set; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.Vector; + +/** + * A block type mask that only matches blocks that are not in the list. + * + * @author sk89q + */ +@Deprecated +public class InvertedBlockTypeMask extends BlockTypeMask { + public InvertedBlockTypeMask() { + } + + /** + * @param types + */ + public InvertedBlockTypeMask(Set types) { + super(types); + } + + /** + * @param type + */ + public InvertedBlockTypeMask(int type) { + super(type); + } + + @Override + public boolean matches(EditSession editSession, Vector pos) { + return !super.matches(editSession, pos); + } +} diff --git a/src/main/java/com/sk89q/worldedit/masks/InvertedMask.java b/src/legacy/java/com/sk89q/worldedit/masks/InvertedMask.java similarity index 100% rename from src/main/java/com/sk89q/worldedit/masks/InvertedMask.java rename to src/legacy/java/com/sk89q/worldedit/masks/InvertedMask.java diff --git a/src/main/java/com/sk89q/worldedit/masks/Mask.java b/src/legacy/java/com/sk89q/worldedit/masks/Mask.java similarity index 97% rename from src/main/java/com/sk89q/worldedit/masks/Mask.java rename to src/legacy/java/com/sk89q/worldedit/masks/Mask.java index aab2b8b36..0cca79f59 100644 --- a/src/main/java/com/sk89q/worldedit/masks/Mask.java +++ b/src/legacy/java/com/sk89q/worldedit/masks/Mask.java @@ -1,53 +1,53 @@ -// $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.worldedit.masks; - -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.LocalPlayer; -import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; - -/** - * @deprecated Use {@link com.sk89q.worldedit.function.mask.Mask} - */ -@Deprecated -public interface Mask { - - /** - * Called one time before each edit session. - * - * @param session - * @param player - * @param target target of the brush, null if not a brush mask - */ - void prepare(LocalSession session, LocalPlayer player, Vector target); - - /** - * Given a block position, this method returns true if the block at - * that position matches the filter. Block information is not provided - * as getting a BaseBlock has unneeded overhead in most block querying - * situations (enumerating a chest's contents is a waste, for example). - * - * @param editSession - * @param pos - * @return - */ - boolean matches(EditSession editSession, Vector pos); -} +// $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.worldedit.masks; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalPlayer; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.Vector; + +/** + * @deprecated Use {@link com.sk89q.worldedit.function.mask.Mask} + */ +@Deprecated +public interface Mask { + + /** + * Called one time before each edit session. + * + * @param session + * @param player + * @param target target of the brush, null if not a brush mask + */ + void prepare(LocalSession session, LocalPlayer player, Vector target); + + /** + * Given a block position, this method returns true if the block at + * that position matches the filter. Block information is not provided + * as getting a BaseBlock has unneeded overhead in most block querying + * situations (enumerating a chest's contents is a waste, for example). + * + * @param editSession + * @param pos + * @return + */ + boolean matches(EditSession editSession, Vector pos); +} diff --git a/src/main/java/com/sk89q/worldedit/masks/RandomMask.java b/src/legacy/java/com/sk89q/worldedit/masks/RandomMask.java similarity index 100% rename from src/main/java/com/sk89q/worldedit/masks/RandomMask.java rename to src/legacy/java/com/sk89q/worldedit/masks/RandomMask.java diff --git a/src/main/java/com/sk89q/worldedit/masks/RegionMask.java b/src/legacy/java/com/sk89q/worldedit/masks/RegionMask.java similarity index 96% rename from src/main/java/com/sk89q/worldedit/masks/RegionMask.java rename to src/legacy/java/com/sk89q/worldedit/masks/RegionMask.java index a8e1e65fc..978f2fe54 100644 --- a/src/main/java/com/sk89q/worldedit/masks/RegionMask.java +++ b/src/legacy/java/com/sk89q/worldedit/masks/RegionMask.java @@ -1,41 +1,41 @@ -// $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.worldedit.masks; - -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.regions.Region; - -/** - * @deprecated See {@link com.sk89q.worldedit.function.mask.RegionMask} - */ -@Deprecated -public class RegionMask extends AbstractMask { - private final Region region; - - public RegionMask(Region region) { - this.region = region.clone(); - } - - @Override - public boolean matches(EditSession editSession, Vector pos) { - return region.contains(pos); - } -} +// $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.worldedit.masks; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.regions.Region; + +/** + * @deprecated See {@link com.sk89q.worldedit.function.mask.RegionMask} + */ +@Deprecated +public class RegionMask extends AbstractMask { + private final Region region; + + public RegionMask(Region region) { + this.region = region.clone(); + } + + @Override + public boolean matches(EditSession editSession, Vector pos) { + return region.contains(pos); + } +} diff --git a/src/main/java/com/sk89q/worldedit/masks/SolidBlockMask.java b/src/legacy/java/com/sk89q/worldedit/masks/SolidBlockMask.java similarity index 96% rename from src/main/java/com/sk89q/worldedit/masks/SolidBlockMask.java rename to src/legacy/java/com/sk89q/worldedit/masks/SolidBlockMask.java index fda252825..c41f91e81 100644 --- a/src/main/java/com/sk89q/worldedit/masks/SolidBlockMask.java +++ b/src/legacy/java/com/sk89q/worldedit/masks/SolidBlockMask.java @@ -1,16 +1,16 @@ -package com.sk89q.worldedit.masks; - -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.blocks.BlockType; - -/** - * @deprecated See {@link com.sk89q.worldedit.function.mask.SolidBlockMask} - */ -@Deprecated -public class SolidBlockMask extends AbstractMask { - @Override - public boolean matches(EditSession editSession, Vector pos) { - return !BlockType.canPassThrough(editSession.getBlockType(pos), editSession.getBlockData(pos)); - } -} +package com.sk89q.worldedit.masks; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.blocks.BlockType; + +/** + * @deprecated See {@link com.sk89q.worldedit.function.mask.SolidBlockMask} + */ +@Deprecated +public class SolidBlockMask extends AbstractMask { + @Override + public boolean matches(EditSession editSession, Vector pos) { + return !BlockType.canPassThrough(editSession.getBlockType(pos), editSession.getBlockData(pos)); + } +} diff --git a/src/main/java/com/sk89q/worldedit/masks/UnderOverlayMask.java b/src/legacy/java/com/sk89q/worldedit/masks/UnderOverlayMask.java similarity index 100% rename from src/main/java/com/sk89q/worldedit/masks/UnderOverlayMask.java rename to src/legacy/java/com/sk89q/worldedit/masks/UnderOverlayMask.java diff --git a/src/main/java/com/sk89q/worldedit/patterns/BlockChance.java b/src/legacy/java/com/sk89q/worldedit/patterns/BlockChance.java similarity index 100% rename from src/main/java/com/sk89q/worldedit/patterns/BlockChance.java rename to src/legacy/java/com/sk89q/worldedit/patterns/BlockChance.java diff --git a/src/main/java/com/sk89q/worldedit/patterns/ClipboardPattern.java b/src/legacy/java/com/sk89q/worldedit/patterns/ClipboardPattern.java similarity index 96% rename from src/main/java/com/sk89q/worldedit/patterns/ClipboardPattern.java rename to src/legacy/java/com/sk89q/worldedit/patterns/ClipboardPattern.java index cbef1935e..2efaf4601 100644 --- a/src/main/java/com/sk89q/worldedit/patterns/ClipboardPattern.java +++ b/src/legacy/java/com/sk89q/worldedit/patterns/ClipboardPattern.java @@ -1,75 +1,75 @@ -// $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.patterns; - -import com.sk89q.worldedit.*; -import com.sk89q.worldedit.blocks.BaseBlock; - -/** - * Pattern that repeats the clipboard. - * - * @author sk89q - */ -public class ClipboardPattern implements Pattern { - /** - * Clipboard. - */ - private CuboidClipboard clipboard; - /** - * Size of the clipboard. - */ - private Vector size; - - /** - * Construct the object. - * - * @param clipboard - */ - public ClipboardPattern(CuboidClipboard clipboard) { - this.clipboard = clipboard; - this.size = clipboard.getSize(); - } - - /** - * Get next block. - * - * @param pos - * @return - */ - public BaseBlock next(Vector pos) { - return next(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); - } - - /** - * Get next block. - * - * @param x - * @param y - * @param z - * @return - */ - public BaseBlock next(int x, int y, int z) { - int xp = Math.abs(x) % size.getBlockX(); - int yp = Math.abs(y) % size.getBlockY(); - int zp = Math.abs(z) % size.getBlockZ(); - - return clipboard.getPoint(new Vector(xp, yp, zp)); - } -} +// $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.patterns; + +import com.sk89q.worldedit.*; +import com.sk89q.worldedit.blocks.BaseBlock; + +/** + * Pattern that repeats the clipboard. + * + * @author sk89q + */ +public class ClipboardPattern implements Pattern { + /** + * Clipboard. + */ + private CuboidClipboard clipboard; + /** + * Size of the clipboard. + */ + private Vector size; + + /** + * Construct the object. + * + * @param clipboard + */ + public ClipboardPattern(CuboidClipboard clipboard) { + this.clipboard = clipboard; + this.size = clipboard.getSize(); + } + + /** + * Get next block. + * + * @param pos + * @return + */ + public BaseBlock next(Vector pos) { + return next(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); + } + + /** + * Get next block. + * + * @param x + * @param y + * @param z + * @return + */ + public BaseBlock next(int x, int y, int z) { + int xp = Math.abs(x) % size.getBlockX(); + int yp = Math.abs(y) % size.getBlockY(); + int zp = Math.abs(z) % size.getBlockZ(); + + return clipboard.getPoint(new Vector(xp, yp, zp)); + } +} diff --git a/src/main/java/com/sk89q/worldedit/patterns/Pattern.java b/src/legacy/java/com/sk89q/worldedit/patterns/Pattern.java similarity index 100% rename from src/main/java/com/sk89q/worldedit/patterns/Pattern.java rename to src/legacy/java/com/sk89q/worldedit/patterns/Pattern.java diff --git a/src/main/java/com/sk89q/worldedit/patterns/RandomFillPattern.java b/src/legacy/java/com/sk89q/worldedit/patterns/RandomFillPattern.java similarity index 100% rename from src/main/java/com/sk89q/worldedit/patterns/RandomFillPattern.java rename to src/legacy/java/com/sk89q/worldedit/patterns/RandomFillPattern.java diff --git a/src/main/java/com/sk89q/worldedit/patterns/SingleBlockPattern.java b/src/legacy/java/com/sk89q/worldedit/patterns/SingleBlockPattern.java similarity index 100% rename from src/main/java/com/sk89q/worldedit/patterns/SingleBlockPattern.java rename to src/legacy/java/com/sk89q/worldedit/patterns/SingleBlockPattern.java