Merge pull request #418 from sk89q/string-ids

[WIP] Update WorldEdit to 1.13, and heavily refactor the internals.
This commit is contained in:
Matthew Miller 2018-08-04 11:45:04 +10:00 committed by GitHub
commit 9494c4445a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
523 changed files with 28440 additions and 33424 deletions

View File

@ -35,7 +35,7 @@ buildscript {
allprojects {
group = 'com.sk89q.worldedit'
version = '6.1.10-SNAPSHOT'
version = '7.0.0-SNAPSHOT'
}
if (!project.hasProperty("artifactory_contextUrl")) ext.artifactory_contextUrl = "http://localhost"
@ -87,8 +87,8 @@ subprojects {
ext.internalVersion = version + ";" + gitCommitHash
sourceCompatibility = 1.7
targetCompatibility = 1.7
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
checkstyle.configFile = new File(rootProject.projectDir, "config/checkstyle/checkstyle.xml")
checkstyle.toolVersion = '7.6.1'

Binary file not shown.

View File

@ -1,6 +1,5 @@
#Tue Aug 01 22:20:41 PDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0.2-bin.zip

View File

@ -1,14 +1,16 @@
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'maven'
repositories {
mavenLocal()
maven { url "https://hub.spigotmc.org/nexus/content/groups/public" }
}
dependencies {
compile project(':worldedit-core')
compile 'com.sk89q:dummypermscompat:1.8'
compile 'org.bukkit:bukkit:1.9.4-R0.1-SNAPSHOT' // zzz
compile 'org.bukkit:bukkit:1.13-R0.1-SNAPSHOT' // zzz
testCompile 'org.mockito:mockito-core:1.9.0-rc1'
}
@ -33,10 +35,7 @@ jar {
shadowJar {
dependencies {
include(dependency(':worldedit-core'))
include(dependency('com.google.code.gson:gson:2.2.4'))
}
relocate('com.google.gson', 'com.sk89q.worldedit.internal.gson')
}
build.dependsOn(shadowJar)

View File

@ -82,7 +82,7 @@ public class CommandRegistration {
public boolean unregisterCommands() {
CommandMap commandMap = getCommandMap();
List<String> toRemove = new ArrayList<String>();
List<String> toRemove = new ArrayList<>();
Map<String, org.bukkit.command.Command> knownCommands = ReflectionUtil.getField(commandMap, "knownCommands");
Set<String> aliases = ReflectionUtil.getField(commandMap, "aliases");
if (knownCommands == null || aliases == null) {

View File

@ -50,7 +50,7 @@ public class CommandsManagerRegistration extends CommandRegistration {
}
public boolean registerAll(List<Command> registered) {
List<CommandInfo> toRegister = new ArrayList<CommandInfo>();
List<CommandInfo> toRegister = new ArrayList<>();
for (Command command : registered) {
List<String> permissions = null;
Method cmdMethod = commands.getMethods().get(null).get(command.aliases()[0]);
@ -59,7 +59,7 @@ public class CommandsManagerRegistration extends CommandRegistration {
if (cmdMethod != null && cmdMethod.isAnnotationPresent(CommandPermissions.class)) {
permissions = Arrays.asList(cmdMethod.getAnnotation(CommandPermissions.class).value());
} else if (cmdMethod != null && childMethods != null && !childMethods.isEmpty()) {
permissions = new ArrayList<String>();
permissions = new ArrayList<>();
for (Method m : childMethods.values()) {
if (m.isAnnotationPresent(CommandPermissions.class)) {
permissions.addAll(Arrays.asList(m.getAnnotation(CommandPermissions.class).value()));

View File

@ -19,16 +19,16 @@
package com.sk89q.wepif;
import com.sk89q.util.yaml.YAMLNode;
import com.sk89q.util.yaml.YAMLProcessor;
import org.bukkit.OfflinePlayer;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.sk89q.util.yaml.YAMLNode;
import com.sk89q.util.yaml.YAMLProcessor;
import org.bukkit.OfflinePlayer;
public class ConfigurationPermissionsResolver implements PermissionsResolver {
private YAMLProcessor config;
private Map<String, Set<String>> userPermissionsCache;
@ -52,11 +52,11 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
@Override
public void load() {
userGroups = new HashMap<String, Set<String>>();
userPermissionsCache = new HashMap<String, Set<String>>();
defaultPermissionsCache = new HashSet<String>();
userGroups = new HashMap<>();
userPermissionsCache = new HashMap<>();
defaultPermissionsCache = new HashSet<>();
Map<String, Set<String>> userGroupPermissions = new HashMap<String, Set<String>>();
Map<String, Set<String>> userGroupPermissions = new HashMap<>();
List<String> groupKeys = config.getStringList("permissions.groups", null);
@ -66,7 +66,7 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
config.getStringList("permissions.groups." + key + ".permissions", null);
if (!permissions.isEmpty()) {
Set<String> groupPerms = new HashSet<String>(permissions);
Set<String> groupPerms = new HashSet<>(permissions);
userGroupPermissions.put(key, groupPerms);
if (key.equals("default")) {
@ -80,7 +80,7 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
if (userKeys != null) {
for (String key : userKeys) {
Set<String> permsCache = new HashSet<String>();
Set<String> permsCache = new HashSet<>();
List<String> permissions =
config.getStringList("permissions.users." + key + ".permissions", null);
@ -103,7 +103,7 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
}
userPermissionsCache.put(key.toLowerCase(), permsCache);
userGroups.put(key.toLowerCase(), new HashSet<String>(groups));
userGroups.put(key.toLowerCase(), new HashSet<>(groups));
}
}
}

View File

@ -114,13 +114,13 @@ public class DinnerPermsResolver implements PermissionsResolver {
if (perms == null) {
return new String[0];
}
List<String> groupNames = new ArrayList<String>();
List<String> groupNames = new ArrayList<>();
for (PermissionAttachmentInfo permAttach : perms.getEffectivePermissions()) {
String perm = permAttach.getPermission();
if (!(perm.startsWith(GROUP_PREFIX) && permAttach.getValue())) {
continue;
}
groupNames.add(perm.substring(GROUP_PREFIX.length(), perm.length()));
groupNames.add(perm.substring(GROUP_PREFIX.length()));
}
return groupNames.toArray(new String[groupNames.size()]);
}

View File

@ -66,13 +66,8 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
this.userFile = userFile;
}
@Deprecated
public static boolean filesExists() {
return (new File("perms_groups.txt")).exists() && (new File("perms_users.txt")).exists();
}
public Map<String, Set<String>> loadGroupPermissions() {
Map<String, Set<String>> userGroupPermissions = new HashMap<String, Set<String>>();
Map<String, Set<String>> userGroupPermissions = new HashMap<>();
BufferedReader buff = null;
@ -98,7 +93,7 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
if (parts.length > 1) {
String[] perms = parts[1].split(",");
Set<String> groupPerms = new HashSet<String>(Arrays.asList(perms));
Set<String> groupPerms = new HashSet<>(Arrays.asList(perms));
userGroupPermissions.put(key, groupPerms);
}
}
@ -118,9 +113,9 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
@Override
public void load() {
userGroups = new HashMap<String, Set<String>>();
userPermissionsCache = new HashMap<String, Set<String>>();
defaultPermissionsCache = new HashSet<String>();
userGroups = new HashMap<>();
userPermissionsCache = new HashMap<>();
defaultPermissionsCache = new HashSet<>();
Map<String, Set<String>> userGroupPermissions = loadGroupPermissions();
@ -136,7 +131,7 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
String line;
while ((line = buff.readLine()) != null) {
Set<String> permsCache = new HashSet<String>();
Set<String> permsCache = new HashSet<>();
line = line.trim();
@ -165,7 +160,7 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
}
userPermissionsCache.put(key.toLowerCase(), permsCache);
userGroups.put(key.toLowerCase(), new HashSet<String>(Arrays.asList(groups)));
userGroups.put(key.toLowerCase(), new HashSet<>(Arrays.asList(groups)));
}
}
} catch (IOException e) {

View File

@ -19,6 +19,7 @@
package com.sk89q.wepif;
import com.nijikokun.bukkit.Permissions.Permissions;
import com.sk89q.util.yaml.YAMLProcessor;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
@ -27,7 +28,6 @@ import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import com.nijikokun.bukkit.Permissions.Permissions;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -50,7 +50,7 @@ public class NijiPermissionsResolver implements PermissionsResolver {
Plugin plugin = pluginManager.getPlugin("Permissions");
// Check if plugin is loaded and has Permissions interface
if (plugin == null || !(plugin instanceof Permissions)) {
if (!(plugin instanceof Permissions)) {
return null;
}

View File

@ -22,19 +22,19 @@ package com.sk89q.wepif;
import org.bukkit.OfflinePlayer;
public interface PermissionsProvider {
public boolean hasPermission(String name, String permission);
boolean hasPermission(String name, String permission);
public boolean hasPermission(String worldName, String name, String permission);
boolean hasPermission(String worldName, String name, String permission);
public boolean inGroup(String player, String group);
boolean inGroup(String player, String group);
public String[] getGroups(String player);
String[] getGroups(String player);
public boolean hasPermission(OfflinePlayer player, String permission);
boolean hasPermission(OfflinePlayer player, String permission);
public boolean hasPermission(String worldName, OfflinePlayer player, String permission);
boolean hasPermission(String worldName, OfflinePlayer player, String permission);
public boolean inGroup(OfflinePlayer player, String group);
boolean inGroup(OfflinePlayer player, String group);
public String[] getGroups(OfflinePlayer player);
String[] getGroups(OfflinePlayer player);
}

View File

@ -20,7 +20,7 @@
package com.sk89q.wepif;
public interface PermissionsResolver extends PermissionsProvider {
public void load();
void load();
public String getDetectionMessage();
String getDetectionMessage();
}

View File

@ -86,7 +86,7 @@ public class PermissionsResolverManager implements PermissionsResolver {
private PermissionsResolver permissionResolver;
private YAMLProcessor config;
private Logger logger = Logger.getLogger(getClass().getCanonicalName());
private List<Class<? extends PermissionsResolver>> enabledResolvers = new ArrayList<Class<? extends PermissionsResolver>>();
private List<Class<? extends PermissionsResolver>> enabledResolvers = new ArrayList<>();
@SuppressWarnings("unchecked")
protected Class<? extends PermissionsResolver>[] availableResolvers = new Class[] {
@ -213,7 +213,7 @@ public class PermissionsResolverManager implements PermissionsResolver {
if (!keys.contains("resolvers")) {
//List<String> resolverKeys = config.getKeys("resolvers");
List<String> resolvers = new ArrayList<String>();
List<String> resolvers = new ArrayList<>();
for (Class<?> clazz : availableResolvers) {
resolvers.add(clazz.getSimpleName());
}
@ -221,7 +221,7 @@ public class PermissionsResolverManager implements PermissionsResolver {
config.setProperty("resolvers.enabled", resolvers);
isUpdated = true;
} else {
List<String> disabledResolvers = config.getStringList("resolvers.disabled", new ArrayList<String>());
List<String> disabledResolvers = config.getStringList("resolvers.disabled", new ArrayList<>());
List<String> stagedEnabled = config.getStringList("resolvers.enabled", null);
for (Iterator<String> i = stagedEnabled.iterator(); i.hasNext();) {
String nextName = i.next();

View File

@ -19,22 +19,62 @@
package com.sk89q.worldedit.bukkit;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Function;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import javax.annotation.Nullable;
/**
* Adapts between Bukkit and WorldEdit equivalent objects.
*/
final class BukkitAdapter {
public class BukkitAdapter {
private BukkitAdapter() {
}
private static final ParserContext TO_BLOCK_CONTEXT = new ParserContext();
static {
TO_BLOCK_CONTEXT.setRestricted(false);
}
/**
* Checks equality between a WorldEdit BlockType and a Bukkit Material
*
* @param blockType The WorldEdit BlockType
* @param type The Bukkit Material
* @return If they are equal
*/
public static boolean equals(BlockType blockType, Material type) {
return Objects.equals(blockType.getId(), type.getKey().toString());
}
/**
* Convert any WorldEdit world into an equivalent wrapped Bukkit world.
*
@ -67,6 +107,26 @@ final class BukkitAdapter {
return new BukkitWorld(world);
}
/**
* Create a WorldEdit Player from a Bukkit Player.
*
* @param player The Bukkit player
* @return The WorldEdit player
*/
public static BukkitPlayer adapt(Player player) {
return WorldEditPlugin.getInstance().wrapPlayer(player);
}
/**
* Create a Bukkit Player from a WorldEdit Player.
*
* @param player The WorldEdit player
* @return The Bukkit player
*/
public static Player adapt(com.sk89q.worldedit.entity.Player player) {
return ((BukkitPlayer) player).getPlayer();
}
/**
* Create a Bukkit world from a WorldEdit world.
*
@ -95,7 +155,7 @@ final class BukkitAdapter {
*/
public static Location adapt(org.bukkit.Location location) {
checkNotNull(location);
Vector position = BukkitUtil.toVector(location);
Vector position = asVector(location);
return new com.sk89q.worldedit.util.Location(
adapt(location.getWorld()),
position,
@ -151,6 +211,17 @@ final class BukkitAdapter {
location.getPitch());
}
/**
* Create a WorldEdit Vector from a Bukkit location.
*
* @param location The Bukkit location
* @return a WorldEdit vector
*/
public static Vector asVector(org.bukkit.Location location) {
checkNotNull(location);
return new Vector(location.getX(), location.getY(), location.getZ());
}
/**
* Create a WorldEdit entity from a Bukkit entity.
*
@ -162,4 +233,142 @@ final class BukkitAdapter {
return new BukkitEntity(entity);
}
/**
* Create a Bukkit Material form a WorldEdit ItemType
*
* @param itemType The WorldEdit ItemType
* @return The Bukkit Material
*/
public static Material adapt(ItemType itemType) {
checkNotNull(itemType);
if (!itemType.getId().startsWith("minecraft:")) {
throw new IllegalArgumentException("Bukkit only supports Minecraft items");
}
return Material.getMaterial(itemType.getId().replace("minecraft:", "").toUpperCase());
}
/**
* Create a Bukkit Material form a WorldEdit BlockType
*
* @param blockType The WorldEdit BlockType
* @return The Bukkit Material
*/
public static Material adapt(BlockType blockType) {
checkNotNull(blockType);
if (!blockType.getId().startsWith("minecraft:")) {
throw new IllegalArgumentException("Bukkit only supports Minecraft blocks");
}
return Material.getMaterial(blockType.getId().replace("minecraft:", "").toUpperCase());
}
/**
* Create a WorldEdit GameMode from a Bukkit one.
*
* @param gameMode Bukkit GameMode
* @return WorldEdit GameMode
*/
public static GameMode adapt(org.bukkit.GameMode gameMode) {
checkNotNull(gameMode);
return GameModes.get(gameMode.name().toLowerCase());
}
/**
* Converts a Material to a BlockType
*
* @param material The material
* @return The blocktype
*/
public static BlockType asBlockType(Material material) {
checkNotNull(material);
if (!material.isBlock()) {
throw new IllegalArgumentException(material.getKey().toString() + " is not a block!");
}
return BlockTypes.get(material.getKey().toString());
}
/**
* Converts a Material to a ItemType
*
* @param material The material
* @return The itemtype
*/
public static ItemType asItemType(Material material) {
checkNotNull(material);
if (!material.isItem()) {
throw new IllegalArgumentException(material.getKey().toString() + " is not an item!");
}
return ItemTypes.get(material.getKey().toString());
}
private static Map<String, BlockState> blockStateCache = new HashMap<>();
/**
* Create a WorldEdit BlockState from a Bukkit BlockData
*
* @param blockData The Bukkit BlockData
* @return The WorldEdit BlockState
*/
public static BlockState adapt(BlockData blockData) {
checkNotNull(blockData);
return blockStateCache.computeIfAbsent(blockData.getAsString(), new Function<String, BlockState>() {
@Nullable
@Override
public BlockState apply(@Nullable String input) {
try {
return WorldEdit.getInstance().getBlockFactory().parseFromInput(input, TO_BLOCK_CONTEXT).toImmutableState();
} catch (InputParseException e) {
e.printStackTrace();
return null;
}
}
});
}
/**
* Create a Bukkit BlockData from a WorldEdit BlockStateHolder
*
* @param block The WorldEdit BlockStateHolder
* @return The Bukkit BlockData
*/
public static BlockData adapt(BlockStateHolder block) {
checkNotNull(block);
return Bukkit.createBlockData(block.getAsString());
}
/**
* Create a WorldEdit BlockState from a Bukkit ItemStack
*
* @param itemStack The Bukkit ItemStack
* @return The WorldEdit BlockState
*/
public static BlockState asBlockState(ItemStack itemStack) {
checkNotNull(itemStack);
if (itemStack.getType().isBlock()) {
return adapt(itemStack.getType().createBlockData());
} else {
return BlockTypes.AIR.getDefaultState();
}
}
/**
* Create a WorldEdit BaseItemStack from a Bukkit ItemStack
*
* @param itemStack The Bukkit ItemStack
* @return The WorldEdit BaseItemStack
*/
public static BaseItemStack adapt(ItemStack itemStack) {
checkNotNull(itemStack);
return new BaseItemStack(ItemTypes.get(itemStack.getType().getKey().toString()), itemStack.getAmount());
}
/**
* Create a Bukkit ItemStack from a WorldEdit BaseItemStack
*
* @param item The WorldEdit BaseItemStack
* @return The Bukkit ItemStack
*/
public static ItemStack adapt(BaseItemStack item) {
checkNotNull(item);
return new ItemStack(adapt(item.getType()), item.getAmount());
}
}

View File

@ -25,11 +25,12 @@ import com.sk89q.worldedit.world.biome.BiomeData;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
import org.bukkit.block.Biome;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
/**
* A biome registry for Bukkit.
*/
@ -48,7 +49,7 @@ class BukkitBiomeRegistry implements BiomeRegistry {
public List<BaseBiome> getBiomes() {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
List<BaseBiome> biomes = new ArrayList<BaseBiome>();
List<BaseBiome> biomes = new ArrayList<>();
for (Biome biome : Biome.values()) {
int biomeId = adapter.getBiomeId(biome);
biomes.add(new BaseBiome(biomeId));
@ -65,12 +66,7 @@ class BukkitBiomeRegistry implements BiomeRegistry {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
final Biome bukkitBiome = adapter.getBiome(biome.getId());
return new BiomeData() {
@Override
public String getName() {
return bukkitBiome.name();
}
};
return bukkitBiome::name;
} else {
return null;
}

View File

@ -0,0 +1,78 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.blocks.BlockMaterial;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.registry.BundledBlockRegistry;
import com.sk89q.worldedit.world.registry.PassthroughBlockMaterial;
import org.bukkit.Material;
import java.util.EnumMap;
import java.util.Map;
import javax.annotation.Nullable;
public class BukkitBlockRegistry extends BundledBlockRegistry {
private Map<Material, BukkitBlockMaterial> materialMap = new EnumMap<>(Material.class);
@Nullable
@Override
public BlockMaterial getMaterial(BlockType blockType) {
return materialMap.computeIfAbsent(BukkitAdapter.adapt(blockType),
material -> new BukkitBlockMaterial(BukkitBlockRegistry.super.getMaterial(blockType), material));
}
@Nullable
@Override
public Map<String, ? extends Property> getProperties(BlockType blockType) {
if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) {
return WorldEditPlugin.getInstance().getBukkitImplAdapter().getProperties(blockType);
}
return super.getProperties(blockType);
}
public static class BukkitBlockMaterial extends PassthroughBlockMaterial {
private final Material material;
public BukkitBlockMaterial(@Nullable BlockMaterial material, Material bukkitMaterial) {
super(material);
this.material = bukkitMaterial;
}
@Override
public boolean isSolid() {
return material.isSolid();
}
@Override
public boolean isBurnable() {
return material.isBurnable();
}
@Override
public boolean isTranslucent() {
return material.isTransparent();
}
}
}

View File

@ -19,6 +19,8 @@
package com.sk89q.worldedit.bukkit;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.bukkit.util.CommandInspector;
import com.sk89q.minecraft.util.commands.CommandLocals;
import com.sk89q.worldedit.extension.platform.Actor;
@ -30,8 +32,6 @@ import org.bukkit.command.CommandSender;
import java.util.logging.Logger;
import static com.google.common.base.Preconditions.checkNotNull;
class BukkitCommandInspector implements CommandInspector {
private static final Logger logger = Logger.getLogger(BukkitCommandInspector.class.getCanonicalName());

View File

@ -19,19 +19,20 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.util.auth.AuthorizationException;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.util.auth.AuthorizationException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import javax.annotation.Nullable;
import java.io.File;
import java.util.UUID;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
public class BukkitCommandSender implements Actor {

View File

@ -19,19 +19,20 @@
package com.sk89q.worldedit.bukkit;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.entity.metadata.EntityType;
import com.sk89q.worldedit.entity.metadata.EntityProperties;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.NullWorld;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
/**
* An adapter to adapt a Bukkit entity into a WorldEdit one.
@ -47,7 +48,7 @@ class BukkitEntity implements Entity {
*/
BukkitEntity(org.bukkit.entity.Entity entity) {
checkNotNull(entity);
this.entityRef = new WeakReference<org.bukkit.entity.Entity>(entity);
this.entityRef = new WeakReference<>(entity);
}
@Override
@ -105,8 +106,8 @@ class BukkitEntity implements Entity {
@Override
public <T> T getFacet(Class<? extends T> cls) {
org.bukkit.entity.Entity entity = entityRef.get();
if (entity != null && EntityType.class.isAssignableFrom(cls)) {
return (T) new BukkitEntityType(entity);
if (entity != null && EntityProperties.class.isAssignableFrom(cls)) {
return (T) new BukkitEntityProperties(entity);
} else {
return null;
}

View File

@ -19,7 +19,9 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.entity.metadata.EntityType;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.entity.metadata.EntityProperties;
import com.sk89q.worldedit.util.Enums;
import org.bukkit.entity.Ambient;
import org.bukkit.entity.Animals;
@ -42,16 +44,14 @@ import org.bukkit.entity.Tameable;
import org.bukkit.entity.Villager;
import org.bukkit.entity.minecart.ExplosiveMinecart;
import static com.google.common.base.Preconditions.checkNotNull;
class BukkitEntityType implements EntityType {
class BukkitEntityProperties implements EntityProperties {
private static final org.bukkit.entity.EntityType armorStandType =
Enums.findByValue(org.bukkit.entity.EntityType.class, "ARMOR_STAND");
private final Entity entity;
BukkitEntityType(Entity entity) {
BukkitEntityProperties(Entity entity) {
checkNotNull(entity);
this.entity = entity;
}
@ -138,7 +138,7 @@ class BukkitEntityType implements EntityType {
@Override
public boolean isTagged() {
return entity instanceof LivingEntity && ((LivingEntity) entity).getCustomName() != null;
return entity instanceof LivingEntity && entity.getCustomName() != null;
}
@Override

View File

@ -20,32 +20,34 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extension.platform.AbstractPlayerActor;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import javax.annotation.Nullable;
import java.util.UUID;
public class BukkitPlayer extends LocalPlayer {
import javax.annotation.Nullable;
public class BukkitPlayer extends AbstractPlayerActor {
private Player player;
private WorldEditPlugin plugin;
public BukkitPlayer(WorldEditPlugin plugin, ServerInterface server, Player player) {
public BukkitPlayer(WorldEditPlugin plugin, Player player) {
this.plugin = plugin;
this.player = player;
}
@ -56,15 +58,19 @@ public class BukkitPlayer extends LocalPlayer {
}
@Override
public int getItemInHand() {
ItemStack itemStack = player.getItemInHand();
return itemStack != null ? itemStack.getTypeId() : 0;
public BaseItemStack getItemInHand(HandSide handSide) {
ItemStack itemStack = handSide == HandSide.MAIN_HAND
? player.getInventory().getItemInMainHand()
: player.getInventory().getItemInOffHand();
return BukkitAdapter.adapt(itemStack);
}
@Override
public BaseBlock getBlockInHand() throws WorldEditException {
ItemStack itemStack = player.getItemInHand();
return BukkitUtil.toBlock(getWorld(), itemStack);
public BaseBlock getBlockInHand(HandSide handSide) throws WorldEditException {
ItemStack itemStack = handSide == HandSide.MAIN_HAND
? player.getInventory().getItemInMainHand()
: player.getInventory().getItemInOffHand();
return new BaseBlock(BukkitAdapter.asBlockState(itemStack));
}
@Override
@ -73,25 +79,8 @@ public class BukkitPlayer extends LocalPlayer {
}
@Override
public WorldVector getPosition() {
Location loc = player.getLocation();
return new WorldVector(BukkitUtil.getLocalWorld(loc.getWorld()),
loc.getX(), loc.getY(), loc.getZ());
}
@Override
public double getPitch() {
return player.getLocation().getPitch();
}
@Override
public double getYaw() {
return player.getLocation().getYaw();
}
@Override
public void giveItem(int type, int amt) {
player.getInventory().addItem(new ItemStack(type, amt));
public void giveItem(BaseItemStack itemStack) {
player.getInventory().addItem(BukkitAdapter.adapt(itemStack));
}
@Override
@ -138,6 +127,16 @@ public class BukkitPlayer extends LocalPlayer {
return new BukkitPlayerBlockBag(player);
}
@Override
public GameMode getGameMode() {
return GameModes.get(player.getGameMode().name().toLowerCase());
}
@Override
public void setGameMode(GameMode gameMode) {
player.setGameMode(org.bukkit.GameMode.valueOf(gameMode.getId().toUpperCase()));
}
@Override
public boolean hasPermission(String perm) {
return (!plugin.getLocalConfiguration().noOpPermissions && player.isOp())
@ -146,8 +145,8 @@ public class BukkitPlayer extends LocalPlayer {
}
@Override
public LocalWorld getWorld() {
return BukkitUtil.getLocalWorld(player.getWorld());
public World getWorld() {
return BukkitAdapter.adapt(player.getWorld());
}
@Override
@ -164,11 +163,6 @@ public class BukkitPlayer extends LocalPlayer {
return player;
}
@Override
public boolean hasCreativeMode() {
return player.getGameMode() == GameMode.CREATIVE;
}
@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
if (alwaysGlass || !player.getAllowFlight()) {
@ -188,7 +182,7 @@ public class BukkitPlayer extends LocalPlayer {
@Override
public com.sk89q.worldedit.util.Location getLocation() {
Location nativeLocation = player.getLocation();
Vector position = BukkitUtil.toVector(nativeLocation);
Vector position = BukkitAdapter.asVector(nativeLocation);
return new com.sk89q.worldedit.util.Location(
getWorld(),
position,
@ -235,7 +229,7 @@ public class BukkitPlayer extends LocalPlayer {
// CopyOnWrite list for the list of players, but the Bukkit
// specification doesn't require thread safety (though the
// spec is extremely incomplete)
return Bukkit.getServer().getPlayerExact(name) != null;
return Bukkit.getServer().getPlayer(uuid) != null;
}
@Override

View File

@ -19,14 +19,16 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.extent.inventory.BlockBagException;
import com.sk89q.worldedit.extent.inventory.OutOfBlocksException;
import com.sk89q.worldedit.extent.inventory.OutOfSpaceException;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.sk89q.worldedit.extent.inventory.*;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.ItemType;
public class BukkitPlayerBlockBag extends BlockBag {
@ -61,14 +63,8 @@ public class BukkitPlayerBlockBag extends BlockBag {
}
@Override
public void fetchItem(BaseItem item) throws BlockBagException {
final int id = item.getType();
final int damage = item.getData();
int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
assert(amount == 1);
boolean usesDamageValue = ItemType.usesDamageValue(id);
if (id == BlockID.AIR) {
public void fetchBlock(BlockState blockState) throws BlockBagException {
if (blockState.getBlockType() == BlockTypes.AIR) {
throw new IllegalArgumentException("Can't fetch air block");
}
@ -83,16 +79,11 @@ public class BukkitPlayerBlockBag extends BlockBag {
continue;
}
if (bukkitItem.getTypeId() != id) {
if (!BukkitAdapter.equals(blockState.getBlockType(), bukkitItem.getType())) {
// Type id doesn't fit
continue;
}
if (usesDamageValue && bukkitItem.getDurability() != damage) {
// Damage value doesn't fit.
continue;
}
int currentAmount = bukkitItem.getAmount();
if (currentAmount < 0) {
// Unlimited
@ -116,16 +107,13 @@ public class BukkitPlayerBlockBag extends BlockBag {
}
@Override
public void storeItem(BaseItem item) throws BlockBagException {
final int id = item.getType();
final int damage = item.getData();
int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
assert(amount <= 64);
boolean usesDamageValue = ItemType.usesDamageValue(id);
if (id == BlockID.AIR) {
public void storeBlock(BlockState blockState, int amount) throws BlockBagException {
if (blockState.getBlockType() == BlockTypes.AIR) {
throw new IllegalArgumentException("Can't store air block");
}
if (!blockState.getBlockType().hasItemType()) {
throw new IllegalArgumentException("This block cannot be stored");
}
loadInventory();
@ -144,16 +132,11 @@ public class BukkitPlayerBlockBag extends BlockBag {
continue;
}
if (bukkitItem.getTypeId() != id) {
if (!BukkitAdapter.equals(blockState.getBlockType(), bukkitItem.getType())) {
// Type id doesn't fit
continue;
}
if (usesDamageValue && bukkitItem.getDurability() != damage) {
// Damage value doesn't fit.
continue;
}
int currentAmount = bukkitItem.getAmount();
if (currentAmount < 0) {
// Unlimited
@ -175,11 +158,11 @@ public class BukkitPlayerBlockBag extends BlockBag {
}
if (freeSlot > -1) {
items[freeSlot] = new ItemStack(id, amount);
items[freeSlot] = BukkitAdapter.adapt(new BaseItemStack(blockState.getBlockType().getItemType(), amount));
return;
}
throw new OutOfSpaceException(id);
throw new OutOfSpaceException(blockState.getBlockType());
}
@Override
@ -191,11 +174,11 @@ public class BukkitPlayerBlockBag extends BlockBag {
}
@Override
public void addSourcePosition(WorldVector pos) {
public void addSourcePosition(Location pos) {
}
@Override
public void addSingleSourcePosition(WorldVector pos) {
public void addSingleSourcePosition(Location pos) {
}
}

View File

@ -20,20 +20,27 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
import com.sk89q.worldedit.world.registry.LegacyWorldData;
import com.sk89q.worldedit.world.registry.BlockRegistry;
import com.sk89q.worldedit.world.registry.BundledRegistries;
/**
* World data for the Bukkit platform.
*/
class BukkitWorldData extends LegacyWorldData {
class BukkitRegistries extends BundledRegistries {
private static final BukkitWorldData INSTANCE = new BukkitWorldData();
private static final BukkitRegistries INSTANCE = new BukkitRegistries();
private final BlockRegistry blockRegistry = new BukkitBlockRegistry();
private final BiomeRegistry biomeRegistry = new BukkitBiomeRegistry();
/**
* Create a new instance.
*/
BukkitWorldData() {
BukkitRegistries() {
}
@Override
public BlockRegistry getBlockRegistry() {
return blockRegistry;
}
@Override
@ -46,7 +53,7 @@ class BukkitWorldData extends LegacyWorldData {
*
* @return an instance
*/
public static BukkitWorldData getInstance() {
public static BukkitRegistries getInstance() {
return INSTANCE;
}

View File

@ -22,8 +22,6 @@ package com.sk89q.worldedit.bukkit;
import com.sk89q.bukkit.util.CommandInfo;
import com.sk89q.bukkit.util.CommandRegistration;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
@ -32,30 +30,29 @@ import com.sk89q.worldedit.extension.platform.Preference;
import com.sk89q.worldedit.util.command.CommandMapping;
import com.sk89q.worldedit.util.command.Description;
import com.sk89q.worldedit.util.command.Dispatcher;
import com.sk89q.worldedit.world.registry.Registries;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
public class BukkitServerInterface extends ServerInterface implements MultiUserPlatform {
import javax.annotation.Nullable;
public class BukkitServerInterface implements MultiUserPlatform {
public Server server;
public WorldEditPlugin plugin;
private CommandRegistration dynamicCommands;
private BukkitBiomeRegistry biomes;
private boolean hookingEvents;
public BukkitServerInterface(WorldEditPlugin plugin, Server server) {
this.plugin = plugin;
this.server = server;
this.biomes = new BukkitBiomeRegistry();
dynamicCommands = new CommandRegistration(plugin);
}
@ -64,9 +61,8 @@ public class BukkitServerInterface extends ServerInterface implements MultiUserP
}
@Override
public int resolveItem(String name) {
Material mat = Material.matchMaterial(name);
return mat == null ? 0 : mat.getId();
public Registries getRegistries() {
return BukkitRegistries.getInstance();
}
@Override
@ -86,12 +82,12 @@ public class BukkitServerInterface extends ServerInterface implements MultiUserP
}
@Override
public List<LocalWorld> getWorlds() {
public List<com.sk89q.worldedit.world.World> getWorlds() {
List<World> worlds = server.getWorlds();
List<LocalWorld> ret = new ArrayList<LocalWorld>(worlds.size());
List<com.sk89q.worldedit.world.World> ret = new ArrayList<>(worlds.size());
for (World world : worlds) {
ret.add(BukkitUtil.getLocalWorld(world));
ret.add(BukkitAdapter.adapt(world));
}
return ret;
@ -104,7 +100,7 @@ public class BukkitServerInterface extends ServerInterface implements MultiUserP
return player;
} else {
org.bukkit.entity.Player bukkitPlayer = server.getPlayerExact(player.getName());
return bukkitPlayer != null ? new BukkitPlayer(plugin, this, bukkitPlayer) : null;
return bukkitPlayer != null ? new BukkitPlayer(plugin, bukkitPlayer) : null;
}
}
@ -121,7 +117,7 @@ public class BukkitServerInterface extends ServerInterface implements MultiUserP
@Override
public void registerCommands(Dispatcher dispatcher) {
List<CommandInfo> toRegister = new ArrayList<CommandInfo>();
List<CommandInfo> toRegister = new ArrayList<>();
BukkitCommandInspector inspector = new BukkitCommandInspector(plugin, dispatcher);
for (CommandMapping command : dispatcher.getCommands()) {
@ -163,7 +159,7 @@ public class BukkitServerInterface extends ServerInterface implements MultiUserP
@Override
public Map<Capability, Preference> getCapabilities() {
Map<Capability, Preference> capabilities = new EnumMap<Capability, Preference>(Capability.class);
Map<Capability, Preference> capabilities = new EnumMap<>(Capability.class);
capabilities.put(Capability.CONFIGURATION, Preference.NORMAL);
capabilities.put(Capability.WORLDEDIT_CUI, Preference.NORMAL);
capabilities.put(Capability.GAME_HOOKS, Preference.PREFERRED);
@ -179,9 +175,9 @@ public class BukkitServerInterface extends ServerInterface implements MultiUserP
@Override
public Collection<Actor> getConnectedUsers() {
List<Actor> users = new ArrayList<Actor>();
List<Actor> users = new ArrayList<>();
for (org.bukkit.entity.Player player : Bukkit.getServer().getOnlinePlayers()) {
users.add(new BukkitPlayer(plugin, this, player));
users.add(new BukkitPlayer(plugin, player));
}
return users;
}

View File

@ -1,196 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit;
import java.util.List;
import com.sk89q.worldedit.NotABlockException;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.blocks.ItemID;
import com.sk89q.worldedit.blocks.SkullBlock;
import org.bukkit.DyeColor;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.Item;
import org.bukkit.entity.Painting;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.BlockWorldVector;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Location;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.bukkit.entity.BukkitEntity;
import com.sk89q.worldedit.bukkit.entity.BukkitExpOrb;
import com.sk89q.worldedit.bukkit.entity.BukkitItem;
import com.sk89q.worldedit.bukkit.entity.BukkitPainting;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Dye;
public final class BukkitUtil {
private BukkitUtil() {
}
public static LocalWorld getLocalWorld(World w) {
return new BukkitWorld(w);
}
public static BlockVector toVector(Block block) {
return new BlockVector(block.getX(), block.getY(), block.getZ());
}
public static BlockVector toVector(BlockFace face) {
return new BlockVector(face.getModX(), face.getModY(), face.getModZ());
}
public static BlockWorldVector toWorldVector(Block block) {
return new BlockWorldVector(getLocalWorld(block.getWorld()), block.getX(), block.getY(), block.getZ());
}
public static Vector toVector(org.bukkit.Location loc) {
return new Vector(loc.getX(), loc.getY(), loc.getZ());
}
public static Location toLocation(org.bukkit.Location loc) {
return new Location(
getLocalWorld(loc.getWorld()),
new Vector(loc.getX(), loc.getY(), loc.getZ()),
loc.getYaw(), loc.getPitch()
);
}
public static Vector toVector(org.bukkit.util.Vector vector) {
return new Vector(vector.getX(), vector.getY(), vector.getZ());
}
public static org.bukkit.Location toLocation(WorldVector pt) {
return new org.bukkit.Location(toWorld(pt), pt.getX(), pt.getY(), pt.getZ());
}
public static org.bukkit.Location toLocation(World world, Vector pt) {
return new org.bukkit.Location(world, pt.getX(), pt.getY(), pt.getZ());
}
public static org.bukkit.Location center(org.bukkit.Location loc) {
return new org.bukkit.Location(
loc.getWorld(),
loc.getBlockX() + 0.5,
loc.getBlockY() + 0.5,
loc.getBlockZ() + 0.5,
loc.getPitch(),
loc.getYaw()
);
}
public static Player matchSinglePlayer(Server server, String name) {
List<Player> players = server.matchPlayer(name);
if (players.isEmpty()) {
return null;
}
return players.get(0);
}
public static Block toBlock(BlockWorldVector pt) {
return toWorld(pt).getBlockAt(toLocation(pt));
}
public static World toWorld(WorldVector pt) {
return ((BukkitWorld) pt.getWorld()).getWorld();
}
/**
* Bukkit's Location class has serious problems with floating point
* precision.
*/
@SuppressWarnings("RedundantIfStatement")
public static boolean equals(org.bukkit.Location a, org.bukkit.Location b) {
if (Math.abs(a.getX() - b.getX()) > EQUALS_PRECISION) return false;
if (Math.abs(a.getY() - b.getY()) > EQUALS_PRECISION) return false;
if (Math.abs(a.getZ() - b.getZ()) > EQUALS_PRECISION) return false;
return true;
}
public static final double EQUALS_PRECISION = 0.0001;
public static org.bukkit.Location toLocation(Location location) {
Vector pt = location.getPosition();
return new org.bukkit.Location(
toWorld(location.getWorld()),
pt.getX(), pt.getY(), pt.getZ(),
location.getYaw(), location.getPitch()
);
}
public static World toWorld(final LocalWorld world) {
return ((BukkitWorld) world).getWorld();
}
public static BukkitEntity toLocalEntity(Entity e) {
switch (e.getType()) {
case EXPERIENCE_ORB:
return new BukkitExpOrb(toLocation(e.getLocation()), e.getUniqueId(), ((ExperienceOrb)e).getExperience());
case PAINTING:
Painting paint = (Painting) e;
return new BukkitPainting(toLocation(e.getLocation()), paint.getArt(), paint.getFacing(), e.getUniqueId());
case DROPPED_ITEM:
return new BukkitItem(toLocation(e.getLocation()), ((Item)e).getItemStack(), e.getUniqueId());
default:
return new BukkitEntity(toLocation(e.getLocation()), e.getType(), e.getUniqueId());
}
}
public static BaseBlock toBlock(LocalWorld world, ItemStack itemStack) throws WorldEditException {
final int typeId = itemStack.getTypeId();
switch (typeId) {
case ItemID.INK_SACK:
final Dye materialData = (Dye) itemStack.getData();
if (materialData.getColor() == DyeColor.BROWN) {
return new BaseBlock(BlockID.COCOA_PLANT, -1);
}
break;
case ItemID.HEAD:
return new SkullBlock(0, (byte) itemStack.getDurability());
default:
final BaseBlock baseBlock = BlockType.getBlockForItem(typeId, itemStack.getDurability());
if (baseBlock != null) {
return baseBlock;
}
break;
}
if (world.isValidBlockType(typeId)) {
return new BaseBlock(typeId, -1);
}
throw new NotABlockException(typeId);
}
}

View File

@ -19,24 +19,27 @@
package com.sk89q.worldedit.bukkit;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.blocks.LazyBlock;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.history.change.BlockChange;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.world.AbstractWorld;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.registry.WorldData;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.weather.WeatherType;
import com.sk89q.worldedit.world.weather.WeatherTypes;
import org.bukkit.Effect;
import org.bukkit.Material;
import org.bukkit.TreeType;
import org.bukkit.World;
import org.bukkit.block.Biome;
@ -46,9 +49,7 @@ import org.bukkit.block.Chest;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.DoubleChestInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.EnumMap;
@ -58,13 +59,13 @@ import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
public class BukkitWorld extends LocalWorld {
public class BukkitWorld extends AbstractWorld {
private static final Logger logger = WorldEdit.logger;
private static final Map<Integer, Effect> effects = new HashMap<Integer, Effect>();
private static final Map<Integer, Effect> effects = new HashMap<>();
static {
for (Effect effect : Effect.values()) {
effects.put(effect.getId(), effect);
@ -78,9 +79,8 @@ public class BukkitWorld extends LocalWorld {
*
* @param world the world
*/
@SuppressWarnings("unchecked")
public BukkitWorld(World world) {
this.worldRef = new WeakReference<World>(world);
this.worldRef = new WeakReference<>(world);
}
@Override
@ -88,9 +88,9 @@ public class BukkitWorld extends LocalWorld {
World world = getWorld();
List<Entity> ents = world.getEntities();
List<com.sk89q.worldedit.entity.Entity> entities = new ArrayList<com.sk89q.worldedit.entity.Entity>();
List<com.sk89q.worldedit.entity.Entity> entities = new ArrayList<>();
for (Entity ent : ents) {
if (region.contains(BukkitUtil.toVector(ent.getLocation()))) {
if (region.contains(BukkitAdapter.asVector(ent.getLocation()))) {
entities.add(BukkitAdapter.adapt(ent));
}
}
@ -99,7 +99,7 @@ public class BukkitWorld extends LocalWorld {
@Override
public List<com.sk89q.worldedit.entity.Entity> getEntities() {
List<com.sk89q.worldedit.entity.Entity> list = new ArrayList<com.sk89q.worldedit.entity.Entity>();
List<com.sk89q.worldedit.entity.Entity> list = new ArrayList<>();
for (Entity entity : getWorld().getEntities()) {
list.add(BukkitAdapter.adapt(entity));
}
@ -156,7 +156,7 @@ public class BukkitWorld extends LocalWorld {
@Override
public boolean regenerate(Region region, EditSession editSession) {
BaseBlock[] history = new BaseBlock[16 * 16 * (getMaxY() + 1)];
BlockStateHolder[] history = new BlockStateHolder[16 * 16 * (getMaxY() + 1)];
for (Vector2D chunk : region.getChunks()) {
Vector min = new Vector(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16);
@ -167,7 +167,7 @@ public class BukkitWorld extends LocalWorld {
for (int z = 0; z < 16; ++z) {
Vector pt = min.add(x, y, z);
int index = y * 16 * 16 + z * 16 + x;
history[index] = editSession.getBlock(pt);
history[index] = editSession.getFullBlock(pt);
}
}
}
@ -189,8 +189,7 @@ public class BukkitWorld extends LocalWorld {
if (!region.contains(pt)) {
editSession.smartSetBlock(pt, history[index]);
} else { // Otherwise fool with history
editSession.rememberChange(pt, history[index],
editSession.rawGetBlock(pt));
editSession.getChangeSet().add(new BlockChange(pt.toBlockVector(), history[index], editSession.getFullBlock(pt)));
}
}
}
@ -248,41 +247,11 @@ public class BukkitWorld extends LocalWorld {
return true;
}
@Override
@Deprecated
public boolean generateTree(EditSession editSession, Vector pt) {
return generateTree(TreeGenerator.TreeType.TREE, editSession, pt);
}
@Override
@Deprecated
public boolean generateBigTree(EditSession editSession, Vector pt) {
return generateTree(TreeGenerator.TreeType.BIG_TREE, editSession, pt);
}
@Override
@Deprecated
public boolean generateBirchTree(EditSession editSession, Vector pt) {
return generateTree(TreeGenerator.TreeType.BIRCH, editSession, pt);
}
@Override
@Deprecated
public boolean generateRedwoodTree(EditSession editSession, Vector pt) {
return generateTree(TreeGenerator.TreeType.REDWOOD, editSession, pt);
}
@Override
@Deprecated
public boolean generateTallRedwoodTree(EditSession editSession, Vector pt) {
return generateTree(TreeGenerator.TreeType.TALL_REDWOOD, editSession, pt);
}
/**
* An EnumMap that stores which WorldEdit TreeTypes apply to which Bukkit TreeTypes
*/
private static final EnumMap<TreeGenerator.TreeType, TreeType> treeTypeMapping =
new EnumMap<TreeGenerator.TreeType, TreeType>(TreeGenerator.TreeType.class);
new EnumMap<>(TreeGenerator.TreeType.class);
static {
for (TreeGenerator.TreeType type : TreeGenerator.TreeType.values()) {
@ -316,22 +285,14 @@ public class BukkitWorld extends LocalWorld {
public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector pt) {
World world = getWorld();
TreeType bukkitType = toBukkitTreeType(type);
return type != null && world.generateTree(BukkitUtil.toLocation(world, pt), bukkitType,
return type != null && world.generateTree(BukkitAdapter.adapt(world, pt), bukkitType,
new EditSessionBlockChangeDelegate(editSession));
}
@Override
public void dropItem(Vector pt, BaseItemStack item) {
World world = getWorld();
ItemStack bukkitItem = new ItemStack(item.getType(), item.getAmount(),
item.getData());
world.dropItemNaturally(BukkitUtil.toLocation(world, pt), bukkitItem);
}
@SuppressWarnings("deprecation")
@Override
public boolean isValidBlockType(int type) {
return Material.getMaterial(type) != null && Material.getMaterial(type).isBlock();
world.dropItemNaturally(BukkitAdapter.adapt(world, pt), BukkitAdapter.adapt(item));
}
@Override
@ -383,14 +344,54 @@ public class BukkitWorld extends LocalWorld {
return false;
}
world.playEffect(BukkitUtil.toLocation(world, position), effect, data);
world.playEffect(BukkitAdapter.adapt(world, position), effect, data);
return true;
}
@Override
public WorldData getWorldData() {
return BukkitWorldData.getInstance();
public WeatherType getWeather() {
if (getWorld().isThundering()) {
return WeatherTypes.THUNDER_STORM;
} else if (getWorld().hasStorm()) {
return WeatherTypes.RAIN;
}
return WeatherTypes.CLEAR;
}
@Override
public long getRemainingWeatherDuration() {
return getWorld().getWeatherDuration();
}
@Override
public void setWeather(WeatherType weatherType) {
if (weatherType == WeatherTypes.THUNDER_STORM) {
getWorld().setThundering(true);
} else if (weatherType == WeatherTypes.RAIN) {
getWorld().setStorm(true);
} else {
getWorld().setStorm(false);
getWorld().setThundering(false);
}
}
@Override
public void setWeather(WeatherType weatherType, long duration) {
// Who named these methods...
if (weatherType == WeatherTypes.THUNDER_STORM) {
getWorld().setThundering(true);
getWorld().setThunderDuration((int) duration);
getWorld().setWeatherDuration((int) duration);
} else if (weatherType == WeatherTypes.RAIN) {
getWorld().setStorm(true);
getWorld().setWeatherDuration((int) duration);
} else {
getWorld().setStorm(false);
getWorld().setThundering(false);
getWorld().setWeatherDuration((int) duration);
}
}
@Override
@ -399,33 +400,31 @@ public class BukkitWorld extends LocalWorld {
}
@Override
public BaseBlock getBlock(Vector position) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
return adapter.getBlock(BukkitAdapter.adapt(getWorld(), position));
} else {
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
return new BaseBlock(bukkitBlock.getTypeId(), bukkitBlock.getData());
}
public com.sk89q.worldedit.world.block.BlockState getBlock(Vector position) {
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
return BukkitAdapter.adapt(bukkitBlock.getBlockData());
}
@Override
public boolean setBlock(Vector position, BaseBlock block, boolean notifyAndLight) throws WorldEditException {
public boolean setBlock(Vector position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
return adapter.setBlock(BukkitAdapter.adapt(getWorld(), position), block, notifyAndLight);
} else {
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
return bukkitBlock.setTypeIdAndData(block.getType(), (byte) block.getData(), notifyAndLight);
bukkitBlock.setBlockData(BukkitAdapter.adapt(block), notifyAndLight);
return true;
}
}
@SuppressWarnings("deprecation")
@Override
public BaseBlock getLazyBlock(Vector position) {
World world = getWorld();
Block bukkitBlock = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
return new LazyBlock(bukkitBlock.getTypeId(), bukkitBlock.getData(), this, position);
public BaseBlock getFullBlock(Vector position) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
return adapter.getBlock(BukkitAdapter.adapt(getWorld(), position));
} else {
return new BaseBlock(getBlock(position));
}
}
@Override
@ -450,12 +449,4 @@ public class BukkitWorld extends LocalWorld {
return false;
}
}
/**
* @deprecated Use {@link #setBlock(Vector, BaseBlock, boolean)}
*/
@Deprecated
public boolean setBlock(Vector pt, com.sk89q.worldedit.foundation.Block block, boolean notifyAdjacent) throws WorldEditException {
return setBlock(pt, (BaseBlock) block, notifyAdjacent);
}
}

View File

@ -19,12 +19,12 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.blocks.BlockID;
import org.bukkit.BlockChangeDelegate;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.bukkit.BlockChangeDelegate;
import org.bukkit.block.data.BlockData;
/**
* Proxy class to catch calls to set blocks.
@ -38,36 +38,18 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
}
@Override
public boolean setRawTypeId(int x, int y, int z, int typeId) {
public boolean setBlockData(int x, int y, int z, BlockData blockData) {
try {
return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId));
} catch (MaxChangedBlocksException ex) {
editSession.setBlock(new Vector(x, y, z), BukkitAdapter.adapt(blockData));
} catch (MaxChangedBlocksException e) {
return false;
}
return true;
}
@Override
public boolean setRawTypeIdAndData(int x, int y, int z, int typeId, int data) {
try {
return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId, data));
} catch (MaxChangedBlocksException ex) {
return false;
}
}
@Override
public boolean setTypeId(int x, int y, int z, int typeId) {
return setRawTypeId(x, y, z, typeId);
}
@Override
public boolean setTypeIdAndData(int x, int y, int z, int typeId, int data) {
return setRawTypeIdAndData(x, y, z, typeId, data);
}
@Override
public int getTypeId(int x, int y, int z) {
return editSession.getBlockType(new Vector(x, y, z));
public BlockData getBlockData(int x, int y, int z) {
return BukkitAdapter.adapt(editSession.getBlock(new Vector(x, y, z)));
}
@Override
@ -77,7 +59,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
@Override
public boolean isEmpty(int x, int y, int z) {
return editSession.getBlockType(new Vector(x, y, z)) == BlockID.AIR;
return editSession.getBlock(new Vector(x, y, z)).getBlockType() == BlockTypes.AIR;
}
}

View File

@ -1,48 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.LocalSession;
/**
* @deprecated use the regular API
*/
@Deprecated
public class WorldEditAPI {
private WorldEditPlugin plugin;
public WorldEditAPI(WorldEditPlugin plugin) {
this.plugin = plugin;
}
/**
* Get the session for a player.
*
* @param player the player
* @return a session
*/
public LocalSession getSession(Player player) {
return plugin.getWorldEdit().getSession(
new BukkitPlayer(plugin, plugin.getServerInterface(), player));
}
}

View File

@ -22,10 +22,9 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.internal.LocalWorldAdapter;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World;
import org.bukkit.block.Block;
import org.bukkit.event.Event.Result;
@ -67,7 +66,7 @@ public class WorldEditListener implements Listener {
}
// this will automatically refresh their session, we don't have to do anything
WorldEdit.getInstance().getSession(plugin.wrapPlayer(event.getPlayer()));
WorldEdit.getInstance().getSessionManager().get(plugin.wrapPlayer(event.getPlayer()));
}
/**
@ -120,18 +119,17 @@ public class WorldEditListener implements Listener {
return; // TODO api needs to be able to get either hand depending on event
// for now just ignore all off hand interacts
}
} catch (NoSuchMethodError ignored) {
} catch (NoSuchFieldError ignored) {
} catch (NoSuchMethodError | NoSuchFieldError ignored) {
}
final LocalPlayer player = plugin.wrapPlayer(event.getPlayer());
final Player player = plugin.wrapPlayer(event.getPlayer());
final World world = player.getWorld();
final WorldEdit we = plugin.getWorldEdit();
Action action = event.getAction();
if (action == Action.LEFT_CLICK_BLOCK) {
final Block clickedBlock = event.getClickedBlock();
final WorldVector pos = new WorldVector(LocalWorldAdapter.adapt(world), clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());
final Location pos = new Location(world, clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());
if (we.handleBlockLeftClick(player, pos)) {
event.setCancelled(true);
@ -150,8 +148,7 @@ public class WorldEditListener implements Listener {
} else if (action == Action.RIGHT_CLICK_BLOCK) {
final Block clickedBlock = event.getClickedBlock();
final WorldVector pos = new WorldVector(LocalWorldAdapter.adapt(world), clickedBlock.getX(),
clickedBlock.getY(), clickedBlock.getZ());
final Location pos = new Location(world, clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());
if (we.handleBlockRightClick(player, pos)) {
event.setCancelled(true);

View File

@ -19,23 +19,17 @@
package com.sk89q.worldedit.bukkit;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Joiner;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.wepif.PermissionsResolverManager;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditOperation;
import com.sk89q.worldedit.bukkit.adapter.AdapterLoadException;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplLoader;
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
import com.sk89q.worldedit.bukkit.selections.CylinderSelection;
import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.event.platform.CommandSuggestionEvent;
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
@ -43,21 +37,12 @@ import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.CylinderRegion;
import com.sk89q.worldedit.regions.Polygonal2DRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.util.Java7Detector;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import javax.annotation.Nullable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@ -69,21 +54,19 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
/**
* Plugin for Bukkit.
*/
@SuppressWarnings("deprecation")
public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
private static final Logger log = Logger.getLogger(WorldEditPlugin.class.getCanonicalName());
public static final String CUI_PLUGIN_CHANNEL = "WECUI";
public static final String CUI_PLUGIN_CHANNEL = "worldedit:cui";
private static WorldEditPlugin INSTANCE;
private BukkitImplAdapter bukkitAdapter;
private BukkitServerInterface server;
private final WorldEditAPI api = new WorldEditAPI(this);
private BukkitConfiguration config;
/**
@ -99,12 +82,15 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
WorldEdit worldEdit = WorldEdit.getInstance();
loadConfig(); // Load configuration
PermissionsResolverManager.initialize(this); // Setup permission resolver
loadAdapter(); // Need an adapter to work with special blocks with NBT data
// Setup platform
server = new BukkitServerInterface(this, getServer());
worldEdit.getPlatformManager().register(server);
worldEdit.loadMappings();
loadConfig(); // Load configuration
PermissionsResolverManager.initialize(this); // Setup permission resolver
// Register CUI
getServer().getMessenger().registerIncomingPluginChannel(this, CUI_PLUGIN_CHANNEL, new CUIChannelListener(this));
@ -117,11 +103,6 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
// Forge WorldEdit and there's (probably) not going to be any other
// platforms to be worried about... at the current time of writing
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent());
loadAdapter(); // Need an adapter to work with special blocks with NBT data
// Check Java version
Java7Detector.notifyIfNot8();
}
private void loadConfig() {
@ -169,7 +150,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
@Override
public void onDisable() {
WorldEdit worldEdit = WorldEdit.getInstance();
worldEdit.clearSessions();
worldEdit.getSessionManager().clear();
worldEdit.getPlatformManager().unregister(server);
if (config != null) {
config.unload();
@ -269,7 +250,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
* @return a session
*/
public LocalSession getSession(Player player) {
return WorldEdit.getInstance().getSession(wrapPlayer(player));
return WorldEdit.getInstance().getSessionManager().get(wrapPlayer(player));
}
/**
@ -279,8 +260,8 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
* @return a session
*/
public EditSession createEditSession(Player player) {
LocalPlayer wePlayer = wrapPlayer(player);
LocalSession session = WorldEdit.getInstance().getSession(wePlayer);
com.sk89q.worldedit.entity.Player wePlayer = wrapPlayer(player);
LocalSession session = WorldEdit.getInstance().getSessionManager().get(wePlayer);
BlockBag blockBag = session.getBlockBag(wePlayer);
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory()
@ -297,8 +278,8 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
* @param editSession an edit session
*/
public void remember(Player player, EditSession editSession) {
LocalPlayer wePlayer = wrapPlayer(player);
LocalSession session = WorldEdit.getInstance().getSession(wePlayer);
com.sk89q.worldedit.entity.Player wePlayer = wrapPlayer(player);
LocalSession session = WorldEdit.getInstance().getSessionManager().get(wePlayer);
session.remember(editSession);
editSession.flushQueue();
@ -306,38 +287,6 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
WorldEdit.getInstance().flushBlockBag(wePlayer, editSession);
}
/**
* Wrap an operation into an EditSession.
*
* @param player a player
* @param op the operation
* @throws Throwable on any error
* @deprecated use the regular API
*/
@Deprecated
public void perform(Player player, WorldEditOperation op) throws Throwable {
LocalPlayer wePlayer = wrapPlayer(player);
LocalSession session = WorldEdit.getInstance().getSession(wePlayer);
EditSession editSession = createEditSession(player);
try {
op.run(session, wePlayer, editSession);
} finally {
remember(player, editSession);
}
}
/**
* Get the API.
*
* @return the API
* @deprecated use the regular API
*/
@Deprecated
public WorldEditAPI getAPI() {
return api;
}
/**
* Returns the configuration used by WorldEdit.
*
@ -357,13 +306,13 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
}
/**
* Used to wrap a Bukkit Player as a LocalPlayer.
* Used to wrap a Bukkit Player as a WorldEdit Player.
*
* @param player a player
* @return a wrapped player
*/
public BukkitPlayer wrapPlayer(Player player) {
return new BukkitPlayer(this, this.server, player);
return new BukkitPlayer(this, player);
}
public Actor wrapCommandSender(CommandSender sender) {
@ -374,15 +323,6 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
return new BukkitCommandSender(this, sender);
}
/**
* Get the server interface.
*
* @return the server interface
*/
public ServerInterface getServerInterface() {
return server;
}
BukkitServerInterface getInternalPlatform() {
return server;
}
@ -396,64 +336,6 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
return WorldEdit.getInstance();
}
/**
* Gets the region selection for the player.
*
* @param player aplayer
* @return the selection or null if there was none
*/
public Selection getSelection(Player player) {
if (player == null) {
throw new IllegalArgumentException("Null player not allowed");
}
if (!player.isOnline()) {
throw new IllegalArgumentException("Offline player not allowed");
}
LocalSession session = WorldEdit.getInstance().getSession(wrapPlayer(player));
RegionSelector selector = session.getRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()));
try {
Region region = selector.getRegion();
World world = BukkitAdapter.asBukkitWorld(session.getSelectionWorld()).getWorld();
if (region instanceof CuboidRegion) {
return new CuboidSelection(world, selector, (CuboidRegion) region);
} else if (region instanceof Polygonal2DRegion) {
return new Polygonal2DSelection(world, selector, (Polygonal2DRegion) region);
} else if (region instanceof CylinderRegion) {
return new CylinderSelection(world, selector, (CylinderRegion) region);
} else {
return null;
}
} catch (IncompleteRegionException e) {
return null;
}
}
/**
* Sets the region selection for a player.
*
* @param player the player
* @param selection a selection
*/
public void setSelection(Player player, Selection selection) {
if (player == null) {
throw new IllegalArgumentException("Null player not allowed");
}
if (!player.isOnline()) {
throw new IllegalArgumentException("Offline player not allowed");
}
if (selection == null) {
throw new IllegalArgumentException("Null selection not allowed");
}
LocalSession session = WorldEdit.getInstance().getSession(wrapPlayer(player));
RegionSelector sel = selection.getRegionSelector();
session.setRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()), sel);
session.dispatchCUISelection(wrapPlayer(player));
}
/**
* Gets the instance of this plugin.
*

View File

@ -21,11 +21,15 @@ package com.sk89q.worldedit.bukkit.adapter;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.entity.Entity;
import java.util.Map;
import javax.annotation.Nullable;
/**
@ -33,26 +37,6 @@ import javax.annotation.Nullable;
*/
public interface BukkitImplAdapter {
/**
* Get the block ID for the given material.
*
* <p>Returns 0 if it is not known or it doesn't exist.</p>
*
* @param material the material
* @return the block ID
*/
int getBlockId(Material material);
/**
* Get the material for the given block ID.
*
* <p>Returns {@link Material#AIR} if it is not known or it doesn't exist.</p>
*
* @param id the block ID
* @return the material
*/
Material getMaterial(int id);
/**
* Get the biome ID for the given biome.
*
@ -89,7 +73,7 @@ public interface BukkitImplAdapter {
* @param notifyAndLight notify and light if set
* @return true if a block was likely changed
*/
boolean setBlock(Location location, BaseBlock state, boolean notifyAndLight);
boolean setBlock(Location location, BlockStateHolder state, boolean notifyAndLight);
/**
* Get the state for the given entity.
@ -110,5 +94,11 @@ public interface BukkitImplAdapter {
@Nullable
Entity createEntity(Location location, BaseEntity state);
/**
* Get a map of string -> properties
*
* @param blockType The block type
* @return The properties map
*/
Map<String, ? extends Property> getProperties(BlockType blockType);
}

View File

@ -38,7 +38,7 @@ import java.util.logging.Logger;
public class BukkitImplLoader {
private static final Logger log = Logger.getLogger(BukkitImplLoader.class.getCanonicalName());
private final List<String> adapterCandidates = new ArrayList<String>();
private final List<String> adapterCandidates = new ArrayList<>();
private String customCandidate;
private static final String SEARCH_PACKAGE = "com.sk89q.worldedit.bukkit.adapter.impl";

View File

@ -1,50 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit.entity;
import com.sk89q.worldedit.LocalEntity;
import com.sk89q.worldedit.Location;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import org.bukkit.entity.EntityType;
import java.util.UUID;
public class BukkitEntity extends LocalEntity {
private final EntityType type;
private final UUID entityId;
public BukkitEntity(Location loc, EntityType type, UUID entityId) {
super(loc);
this.type = type;
this.entityId = entityId;
}
public UUID getEntityId() {
return entityId;
}
@Override
public boolean spawn(Location weLoc) {
org.bukkit.Location loc = BukkitUtil.toLocation(weLoc);
return loc.getWorld().spawn(loc, type.getEntityClass()) != null;
}
}

View File

@ -1,49 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit.entity;
import com.sk89q.worldedit.Location;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ExperienceOrb;
import java.util.UUID;
public class BukkitExpOrb extends BukkitEntity {
private final int amount;
public BukkitExpOrb(Location loc, UUID entityId, int amount) {
super(loc, EntityType.EXPERIENCE_ORB, entityId);
this.amount = amount;
}
@Override
public boolean spawn(Location weLoc) {
org.bukkit.Location loc = BukkitUtil.toLocation(weLoc);
ExperienceOrb orb = loc.getWorld().spawn(loc, ExperienceOrb.class);
if (orb != null) {
orb.setExperience(amount);
return true;
}
return false;
}
}

View File

@ -1,110 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit.entity;
import com.sk89q.worldedit.Location;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import org.bukkit.Art;
import org.bukkit.Bukkit;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Painting;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
public class BukkitPainting extends BukkitEntity {
private static final Logger log = Logger.getLogger(BukkitPainting.class.getCanonicalName());
private static int spawnTask = -1;
private static final Deque<QueuedPaintingSpawn> spawnQueue = new ArrayDeque<QueuedPaintingSpawn>();
private class QueuedPaintingSpawn {
private final Location weLoc;
private QueuedPaintingSpawn(Location weLoc) {
this.weLoc = weLoc;
}
public void spawn() {
spawnRaw(weLoc);
}
}
private static class PaintingSpawnRunnable implements Runnable {
@Override
public void run() {
synchronized (spawnQueue) {
QueuedPaintingSpawn spawn;
while ((spawn = spawnQueue.poll()) != null) {
try {
spawn.spawn();
} catch (Throwable t) {
log.log(Level.WARNING, "Failed to spawn painting", t);
continue;
}
}
spawnTask = -1;
}
}
}
private final Art art;
private final BlockFace facingDirection;
public BukkitPainting(Location loc, Art art, BlockFace facingDirection, UUID entityId) {
super(loc, EntityType.PAINTING, entityId);
this.art = art;
this.facingDirection = facingDirection;
}
/**
* Queue the painting to be spawned at the specified location.
* This operation is delayed so that the block changes that may be applied can be applied before the painting spawn is attempted.
*
* @param weLoc The WorldEdit location
* @return Whether the spawn as successful
*/
@Override
public boolean spawn(Location weLoc) {
synchronized (spawnQueue) {
spawnQueue.add(new QueuedPaintingSpawn(weLoc));
if (spawnTask == -1) {
spawnTask = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"), new PaintingSpawnRunnable(), 1L);
}
}
return true;
}
public boolean spawnRaw(Location weLoc) {
org.bukkit.Location loc = BukkitUtil.toLocation(weLoc);
Painting paint = loc.getWorld().spawn(loc, Painting.class);
if (paint != null) {
paint.setFacingDirection(facingDirection, true);
paint.setArt(art, true);
return true;
}
return false;
}
}

View File

@ -1,70 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit.selections;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.regions.selector.limit.PermissiveSelectorLimits;
import org.bukkit.Location;
import org.bukkit.World;
public class CuboidSelection extends RegionSelection {
protected CuboidRegion cuboid;
public CuboidSelection(World world, Location pt1, Location pt2) {
this(world, BukkitUtil.toVector(pt1), BukkitUtil.toVector(pt2));
}
public CuboidSelection(World world, Vector pt1, Vector pt2) {
super(world);
// Validate input
if (pt1 == null) {
throw new IllegalArgumentException("Null point 1 not permitted");
}
if (pt2 == null) {
throw new IllegalArgumentException("Null point 2 not permitted");
}
// Create new selector
CuboidRegionSelector sel = new CuboidRegionSelector(BukkitUtil.getLocalWorld(world));
// set up selector
sel.selectPrimary(pt1, PermissiveSelectorLimits.getInstance());
sel.selectSecondary(pt2, PermissiveSelectorLimits.getInstance());
// set up CuboidSelection
cuboid = sel.getIncompleteRegion();
// set up RegionSelection
setRegionSelector(sel);
setRegion(cuboid);
}
public CuboidSelection(World world, RegionSelector sel, CuboidRegion region) {
super(world, sel, region);
this.cuboid = region;
}
}

View File

@ -1,80 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit.selections;
import com.sk89q.worldedit.regions.selector.CylinderRegionSelector;
import org.bukkit.World;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.regions.CylinderRegion;
import com.sk89q.worldedit.regions.RegionSelector;
/**
* A selection representing a {@link CylinderRegion}
*/
public class CylinderSelection extends RegionSelection {
private CylinderRegion cylRegion;
public CylinderSelection(World world, RegionSelector selector, CylinderRegion region) {
super(world, selector, region);
this.cylRegion = region;
}
public CylinderSelection(World world, BlockVector2D center, BlockVector2D radius, int minY, int maxY) {
super(world);
LocalWorld lWorld = BukkitUtil.getLocalWorld(world);
// Validate input
minY = Math.min(Math.max(0, minY), world.getMaxHeight());
maxY = Math.min(Math.max(0, maxY), world.getMaxHeight());
// Create and set up new selector
CylinderRegionSelector sel = new CylinderRegionSelector(lWorld, center, radius, minY, maxY);
// set up selection
cylRegion = sel.getIncompleteRegion();
// set up RegionSelection
setRegionSelector(sel);
setRegion(cylRegion);
}
/**
* Returns the center vector of the cylinder
*
* @return the center
*/
public BlockVector2D getCenter() {
return cylRegion.getCenter().toVector2D().toBlockVector2D();
}
/**
* Returns the radius vector of the cylinder
*
* @return the radius
*/
public BlockVector2D getRadius() {
return cylRegion.getRadius().toBlockVector2D();
}
}

View File

@ -1,63 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit.selections;
import java.util.Collections;
import java.util.List;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector;
import org.bukkit.World;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.regions.*;
public class Polygonal2DSelection extends RegionSelection {
protected Polygonal2DRegion poly2d;
public Polygonal2DSelection(World world, RegionSelector sel, Polygonal2DRegion region) {
super(world, sel, region);
this.poly2d = region;
}
public Polygonal2DSelection(World world, List<BlockVector2D> 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<BlockVector2D> getNativePoints() {
return Collections.unmodifiableList(poly2d.getPoints());
}
}

View File

@ -1,118 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit.selections;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
import org.bukkit.Location;
import org.bukkit.World;
import static com.sk89q.worldedit.bukkit.BukkitUtil.toLocation;
import static com.sk89q.worldedit.bukkit.BukkitUtil.toVector;
public abstract class RegionSelection implements Selection {
private World world;
private RegionSelector selector;
private Region region;
public RegionSelection(World world) {
this.world = world;
}
public RegionSelection(World world, RegionSelector selector, Region region) {
this.world = world;
this.region = region;
this.selector = selector;
}
protected Region getRegion() {
return region;
}
protected void setRegion(Region region) {
this.region = region;
}
@Override
public RegionSelector getRegionSelector() {
return selector;
}
protected void setRegionSelector(RegionSelector selector) {
this.selector = selector;
}
@Override
public Location getMinimumPoint() {
return toLocation(world, region.getMinimumPoint());
}
@Override
public Vector getNativeMinimumPoint() {
return region.getMinimumPoint();
}
@Override
public Location getMaximumPoint() {
return toLocation(world, region.getMaximumPoint());
}
@Override
public Vector getNativeMaximumPoint() {
return region.getMaximumPoint();
}
@Override
public World getWorld() {
return world;
}
@Override
public int getArea() {
return region.getArea();
}
@Override
public int getWidth() {
return region.getWidth();
}
@Override
public int getHeight() {
return region.getHeight();
}
@Override
public int getLength() {
return region.getLength();
}
@Override
public boolean contains(Location position) {
if (!position.getWorld().equals(world)) {
return false;
}
return region.contains(toVector(position));
}
}

View File

@ -1,113 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit.selections;
import org.bukkit.Location;
import org.bukkit.World;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.RegionSelector;
import javax.annotation.Nullable;
/**
* An abstraction of WorldEdit regions, which do not use Bukkit objects.
*/
public interface Selection {
/**
* Get the lower point of a region.
*
* @return min. point
*/
public Location getMinimumPoint();
/**
* Get the lower point of a region.
*
* @return min. point
*/
public Vector getNativeMinimumPoint();
/**
* Get the upper point of a region.
*
* @return max. point
*/
public Location getMaximumPoint();
/**
* Get the upper point of a region.
*
* @return max. point
*/
public Vector getNativeMaximumPoint();
/**
* Get the region selector. This is for internal use.
*
* @return the region selector
*/
public RegionSelector getRegionSelector();
/**
* Get the world.
*
* @return the world, which may be null
*/
@Nullable
public World getWorld();
/**
* Get the number of blocks in the region.
*
* @return number of blocks
*/
public int getArea();
/**
* Get X-size.
*
* @return width
*/
public int getWidth();
/**
* Get Y-size.
*
* @return height
*/
public int getHeight();
/**
* Get Z-size.
*
* @return length
*/
public int getLength();
/**
* Returns true based on whether the region contains the point,
*
* @param position a vector
* @return true if it is contained
*/
public boolean contains(Location position);
}

View File

@ -30,7 +30,67 @@ limits:
butcher-radius:
default: -1
maximum: -1
disallowed-blocks: [6, 7, 14, 15, 16, 26, 27, 28, 29, 39, 31, 32, 33, 34, 36, 37, 38, 39, 40, 46, 50, 51, 56, 59, 69, 73, 74, 75, 76, 77, 81, 83, 137, 210, 211, 255]
disallowed-blocks:
- "minecraft:oak_sapling"
- "minecraft:jungle_sapling"
- "minecraft:dark_oak_sapling:"
- "minecraft:spruce_sapling"
- "minecraft:birch_sapling"
- "minecraft:acacia_sapling"
- "minecraft:black_bed"
- "minecraft:blue_bed"
- "minecraft:brown_bed"
- "minecraft:cyan_bed"
- "minecraft:gray_bed"
- "minecraft:green_bed"
- "minecraft:light_blue_bed"
- "minecraft:light_gray_bed"
- "minecraft:lime_bed"
- "minecraft:magenta_bed"
- "minecraft:orange_bed"
- "minecraft:pink_bed"
- "minecraft:purple_bed"
- "minecraft:red_bed"
- "minecraft:white_bed"
- "minecraft:yellow_bed"
- "minecraft:powered_rail"
- "minecraft:detector_rail"
- "minecraft:grass"
- "minecraft:dead_bush"
- "minecraft:moving_piston"
- "minecraft:piston_head"
- "minecraft:sunflower"
- "minecraft:rose_bush"
- "minecraft:dandelion"
- "minecraft:poppy"
- "minecraft:brown_mushroom"
- "minecraft:red_mushroom"
- "minecraft:tnt"
- "minecraft:torch"
- "minecraft:fire"
- "minecraft:redstone_wire"
- "minecraft:wheat"
- "minecraft:potatoes"
- "minecraft:carrots"
- "minecraft:melon_stem"
- "minecraft:pumpkin_stem"
- "minecraft:beetroots"
- "minecraft:rail"
- "minecraft:lever"
- "minecraft:redstone_torch"
- "minecraft:redstone_wall_torch"
- "minecraft:repeater"
- "minecraft:comparator"
- "minecraft:stone_button"
- "minecraft:birch_button"
- "minecraft:acacia_button"
- "minecraft:dark_oak_button"
- "minecraft:jungle_button"
- "minecraft:oak_button"
- "minecraft:spruce_button"
- "minecraft:cactus"
- "minecraft:sugar_cane"
- "minecraft:bedrock"
use-inventory:
enable: false
@ -60,7 +120,7 @@ snapshots:
directory:
navigation-wand:
item: 345
item: minecraft:compass
max-distance: 100
scripting:
@ -77,7 +137,7 @@ history:
size: 15
expiration: 10
wand-item: 271
wand-item: minecraft:wooden_axe
shell-save-type:
no-double-slash: false
no-op-permissions: false

View File

@ -2,6 +2,7 @@ name: WorldEdit
main: com.sk89q.worldedit.bukkit.WorldEditPlugin
version: "${internalVersion}"
softdepend: [Spout] #hack to fix trove errors
api-version: 1.13
# Permissions aren't here. Read http://wiki.sk89q.com/wiki/WEPIF/DinnerPerms
# for how WorldEdit permissions actually work.

View File

@ -19,13 +19,15 @@
package com.sk89q.wepif;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.bukkit.Server;
import org.bukkit.plugin.PluginManager;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
public class DinnerPermsResolverTest {
private DinnerPermsResolver resolver;

View File

@ -28,13 +28,17 @@ import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
import java.util.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
public class TestOfflinePermissible implements OfflinePlayer, Permissible {
private boolean op;
private UUID randomUuid = UUID.randomUUID();
private final Map<String, Boolean> assignedPermissions = new HashMap<String, Boolean>();
private final Map<String, Boolean> assignedPermissions = new HashMap<>();
@Override
public boolean isOp() {
@ -101,7 +105,7 @@ public class TestOfflinePermissible implements OfflinePlayer, Permissible {
@Override
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
Set<PermissionAttachmentInfo> ret = new HashSet<PermissionAttachmentInfo>();
Set<PermissionAttachmentInfo> ret = new HashSet<>();
for (Map.Entry<String, Boolean> entry : assignedPermissions.entrySet()) {
ret.add(new PermissionAttachmentInfo(this, entry.getKey(), null, entry.getValue()));
}
@ -141,11 +145,6 @@ public class TestOfflinePermissible implements OfflinePlayer, Permissible {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBanned(boolean b) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isWhitelisted() {
throw new UnsupportedOperationException("Not supported yet.");

View File

@ -28,7 +28,7 @@ public class BukkitWorldTest {
@Test
public void testTreeTypeMapping() {
for (TreeGenerator.TreeType type : TreeGenerator.TreeType.values()) {
Assert.assertFalse("No mapping for: " + type, BukkitWorld.toBukkitTreeType(type) == null);
Assert.assertNotNull("No mapping for: " + type, BukkitWorld.toBukkitTreeType(type));
}
}

View File

@ -1,202 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bags;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.blocks.*;
/**
* @deprecated Block bags are currently not a supported feature of WorldEdit
*/
@SuppressWarnings("deprecation")
@Deprecated
public abstract class BlockBag {
/**
* Stores a block as if it was mined.
*
* @param id the ID of the block
* @throws BlockBagException thrown on a error
* @deprecated Use {@link BlockBag#storeDroppedBlock(int, int)} instead
*/
@Deprecated
public void storeDroppedBlock(int id) throws BlockBagException {
storeDroppedBlock(id, 0);
}
/**
* Stores a block as if it was mined.
*
* @param id the ID of the block
* @param data the data value of the block
* @throws BlockBagException thrown on a error
*/
public void storeDroppedBlock(int id, int data) throws BlockBagException {
BaseItem dropped = BlockType.getBlockBagItem(id, data);
if (dropped == null) return;
if (dropped.getType() == BlockID.AIR) return;
storeItem(dropped);
}
/**
* Sets a block as if it was placed by hand.
*
* @param id the ID of the block
* @throws BlockBagException
* @deprecated Use {@link #fetchPlacedBlock(int,int)} instead
*/
@Deprecated
public void fetchPlacedBlock(int id) throws BlockBagException {
fetchPlacedBlock(id, 0);
}
/**
* Sets a block as if it was placed by hand.
*
* @param id the ID of the block
* @param data the data value of the block
* @throws BlockBagException
*/
public void fetchPlacedBlock(int id, int data) throws BlockBagException {
try {
// Blocks that can't be fetched...
switch (id) {
case BlockID.BEDROCK:
case BlockID.GOLD_ORE:
case BlockID.IRON_ORE:
case BlockID.COAL_ORE:
case BlockID.DIAMOND_ORE:
case BlockID.TNT:
case BlockID.MOB_SPAWNER:
case BlockID.CROPS:
case BlockID.REDSTONE_ORE:
case BlockID.GLOWING_REDSTONE_ORE:
case BlockID.SNOW:
case BlockID.LIGHTSTONE:
case BlockID.PORTAL:
throw new UnplaceableBlockException();
case BlockID.WATER:
case BlockID.STATIONARY_WATER:
case BlockID.LAVA:
case BlockID.STATIONARY_LAVA:
// Override liquids
return;
default:
fetchBlock(id);
break;
}
} catch (OutOfBlocksException e) {
BaseItem placed = BlockType.getBlockBagItem(id, data);
if (placed == null) throw e; // TODO: check
if (placed.getType() == BlockID.AIR) throw e; // TODO: check
fetchItem(placed);
}
}
/**
* Get a block.
*
* Either this method or fetchItem needs to be overridden
*
* @param id the ID of the block
* @throws BlockBagException
*/
public void fetchBlock(int id) throws BlockBagException {
fetchItem(new BaseItem(id));
}
/**
* Get a block.
*
* Either this method or fetchBlock needs to be overridden
*
* @param item the item
* @throws BlockBagException
*/
public void fetchItem(BaseItem item) throws BlockBagException {
fetchBlock(item.getType());
}
/**
* Store a block.
*
* Either this method or storeItem needs to be overridden
*
* @param id the ID of the block
* @throws BlockBagException
*/
public void storeBlock(int id) throws BlockBagException {
storeItem(new BaseItem(id));
}
/**
* Store a block.
*
* Either this method or storeBlock needs to be overridden
*
* @param item the item
* @throws BlockBagException
*/
public void storeItem(BaseItem item) throws BlockBagException {
storeBlock(item.getType());
}
/**
* Checks to see if a block exists without removing it.
*
* @param id the ID of the block
* @return whether the block exists
*/
public boolean peekBlock(int id) {
try {
fetchBlock(id);
storeBlock(id);
return true;
} catch (BlockBagException e) {
return false;
}
}
/**
* Flush any changes. This is called at the end.
*/
public abstract void flushChanges();
/**
* Adds a position to be used a source.
*
* @param position the position of the source
*/
public abstract void addSourcePosition(WorldVector position);
/**
* Adds a position to be used a source.
*
* @param position the position of the source
*/
public abstract void addSingleSourcePosition(WorldVector position);
}

View File

@ -1,111 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.blocks;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.NBTUtils;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.world.storage.InvalidFormatException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Represents a chest block.
*/
public class ChestBlock extends ContainerBlock {
/**
* Construct an empty chest block with the default orientation (data value).
*/
public ChestBlock() {
super(BlockID.CHEST, 27);
}
/**
* Construct an empty chest block with a custom data value.
*
* @param data data indicating the position of the chest
*/
public ChestBlock(int data) {
super(BlockID.CHEST, data, 27);
}
/**
* Construct the chest block with a custom data value and a list of items.
*
* @param data data indicating the position of the chest
* @param items array of items
*/
public ChestBlock(int data, BaseItemStack[] items) {
super(BlockID.CHEST, data, 27);
setItems(items);
}
@Override
public String getNbtId() {
return "Chest";
}
@Override
public CompoundTag getNbtData() {
Map<String, Tag> values = new HashMap<String, Tag>();
values.put("Items", new ListTag(CompoundTag.class, serializeInventory(getItems())));
return new CompoundTag(values);
}
@Override
public void setNbtData(CompoundTag rootTag) {
if (rootTag == null) {
return;
}
Map<String, Tag> values = rootTag.getValue();
Tag t = values.get("id");
if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals("Chest")) {
throw new RuntimeException("'Chest' tile entity expected");
}
List<CompoundTag> items = new ArrayList<CompoundTag>();
try {
for (Tag tag : NBTUtils.getChildTag(values, "Items", ListTag.class).getValue()) {
if (!(tag instanceof CompoundTag)) {
throw new RuntimeException("CompoundTag expected as child tag of Chest's Items");
}
items.add((CompoundTag) tag);
}
setItems(deserializeInventory(items));
} catch (InvalidFormatException e) {
throw new RuntimeException(e);
} catch (DataException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -1,141 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.blocks;
import com.sk89q.jnbt.ByteTag;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.NBTUtils;
import com.sk89q.jnbt.ShortTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.world.DataException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Represents a block that stores items.
*/
public abstract class ContainerBlock extends BaseBlock implements TileEntityBlock {
private BaseItemStack[] items;
public ContainerBlock(int type, int inventorySize) {
super(type);
this.items = new BaseItemStack[inventorySize];
}
public ContainerBlock(int type, int data, int inventorySize) {
super(type, data);
this.items = new BaseItemStack[inventorySize];
}
/**
* Get the list of items.
*
* @return an array of stored items
*/
public BaseItemStack[] getItems() {
return this.items;
}
/**
* Set the list of items.
*
* @param items an array of stored items
*/
public void setItems(BaseItemStack[] items) {
this.items = items;
}
@Override
public boolean hasNbtData() {
return true;
}
public Map<String, Tag> serializeItem(BaseItemStack item) {
Map<String, Tag> data = new HashMap<String, Tag>();
data.put("id", new ShortTag((short) item.getType()));
data.put("Damage", new ShortTag(item.getData()));
data.put("Count", new ByteTag((byte) item.getAmount()));
if (!item.getEnchantments().isEmpty()) {
List<CompoundTag> enchantmentList = new ArrayList<CompoundTag>();
for(Map.Entry<Integer, Integer> entry : item.getEnchantments().entrySet()) {
Map<String, Tag> enchantment = new HashMap<String, Tag>();
enchantment.put("id", new ShortTag(entry.getKey().shortValue()));
enchantment.put("lvl", new ShortTag(entry.getValue().shortValue()));
enchantmentList.add(new CompoundTag(enchantment));
}
Map<String, Tag> auxData = new HashMap<String, Tag>();
auxData.put("ench", new ListTag(CompoundTag.class, enchantmentList));
data.put("tag", new CompoundTag(auxData));
}
return data;
}
public BaseItemStack deserializeItem(Map<String, Tag> data) throws DataException {
short id = NBTUtils.getChildTag(data, "id", ShortTag.class).getValue();
short damage = NBTUtils.getChildTag(data, "Damage", ShortTag.class).getValue();
byte count = NBTUtils.getChildTag(data, "Count", ByteTag.class).getValue();
BaseItemStack stack = new BaseItemStack(id, count, damage);
if (data.containsKey("tag")) {
Map<String, Tag> auxData = NBTUtils.getChildTag(data, "tag", CompoundTag.class).getValue();
ListTag ench = (ListTag)auxData.get("ench");
for(Tag e : ench.getValue()) {
Map<String, Tag> vars = ((CompoundTag) e).getValue();
short enchId = NBTUtils.getChildTag(vars, "id", ShortTag.class).getValue();
short enchLevel = NBTUtils.getChildTag(vars, "lvl", ShortTag.class).getValue();
stack.getEnchantments().put((int) enchId, (int) enchLevel);
}
}
return stack;
}
public BaseItemStack[] deserializeInventory(List<CompoundTag> items) throws DataException {
BaseItemStack[] stacks = new BaseItemStack[items.size()];
for (CompoundTag tag : items) {
Map<String, Tag> item = tag.getValue();
BaseItemStack stack = deserializeItem(item);
byte slot = NBTUtils.getChildTag(item, "Slot", ByteTag.class).getValue();
if (slot >= 0 && slot < stacks.length) {
stacks[slot] = stack;
}
}
return stacks;
}
public List<CompoundTag> serializeInventory(BaseItemStack[] items) {
List<CompoundTag> tags = new ArrayList<CompoundTag>();
for (int i = 0; i < items.length; ++i) {
if (items[i] != null) {
Map<String, Tag> tagData = serializeItem(items[i]);
tagData.put("Slot", new ByteTag((byte) i));
tags.add(new CompoundTag(tagData));
}
}
return tags;
}
}

View File

@ -1,107 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.blocks;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.NBTUtils;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.world.DataException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Represents dispensers.
*/
public class DispenserBlock extends ContainerBlock {
/**
* Construct an empty dispenser block.
*/
public DispenserBlock() {
super(BlockID.DISPENSER, 9);
}
/**
* Construct an empty dispenser block.
*
* @param data data value (orientation)
*/
public DispenserBlock(int data) {
super(BlockID.DISPENSER, data, 9);
}
/**
* Construct a dispenser block with the given orientation and inventory.
*
* @param data data value (orientation)
* @param items array of items in the inventory
*/
public DispenserBlock(int data, BaseItemStack[] items) {
super(BlockID.DISPENSER, data, 9);
this.setItems(items);
}
@Override
public String getNbtId() {
return "Trap";
}
@Override
public CompoundTag getNbtData() {
Map<String, Tag> values = new HashMap<String, Tag>();
values.put("Items", new ListTag(CompoundTag.class, serializeInventory(getItems())));
return new CompoundTag(values);
}
@Override
public void setNbtData(CompoundTag rootTag) {
try {
if (rootTag == null) {
return;
}
Map<String, Tag> values = rootTag.getValue();
Tag t = values.get("id");
if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals("Trap")) {
throw new DataException("'Trap' tile entity expected");
}
List<CompoundTag> items = new ArrayList<CompoundTag>();
for (Tag tag : NBTUtils.getChildTag(values, "Items", ListTag.class).getValue()) {
if (!(tag instanceof CompoundTag)) {
throw new DataException("CompoundTag expected as child tag of Trap Items");
}
items.add((CompoundTag) tag);
}
setItems(deserializeInventory(items));
} catch (DataException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -1,165 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.blocks;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.NBTUtils;
import com.sk89q.jnbt.ShortTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.world.DataException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Represents a furnace block.
*/
public class FurnaceBlock extends ContainerBlock {
private short burnTime;
private short cookTime;
/**
* Construct an empty furnace block with the default orientation.
*
* @param type type ID
*/
public FurnaceBlock(int type) {
super(type, 2);
}
/**
* Construct an empty furnace block with a given orientation.
*
* @param type type ID
* @param data orientation
*/
public FurnaceBlock(int type, int data) {
super(type, data, 2);
}
/**
* Construct an furnace block with a given orientation and inventory.
*
* @param type type ID
* @param data orientation
* @param items inventory items
*/
public FurnaceBlock(int type, int data, BaseItemStack[] items) {
super(type, data, 2);
setItems(items);
}
/**
* Get the burn time.
*
* @return the burn time
*/
public short getBurnTime() {
return burnTime;
}
/**
* Set the burn time.
*
* @param burnTime the burn time
*/
public void setBurnTime(short burnTime) {
this.burnTime = burnTime;
}
/**
* Get the cook time.
*
* @return the cook time
*/
public short getCookTime() {
return cookTime;
}
/**
* Set the cook time.
*
* @param cookTime the cook time to set
*/
public void setCookTime(short cookTime) {
this.cookTime = cookTime;
}
@Override
public String getNbtId() {
return "Furnace";
}
@Override
public CompoundTag getNbtData() {
Map<String, Tag> values = new HashMap<String, Tag>();
values.put("Items", new ListTag(CompoundTag.class, serializeInventory(getItems())));
values.put("BurnTime", new ShortTag(burnTime));
values.put("CookTime", new ShortTag(cookTime));
return new CompoundTag(values);
}
@Override
public void setNbtData(CompoundTag rootTag) {
if (rootTag == null) {
return;
}
try {
Map<String, Tag> values = rootTag.getValue();
Tag t = values.get("id");
if (!(t instanceof StringTag)
|| !((StringTag) t).getValue().equals("Furnace")) {
throw new RuntimeException("'Furnace' tile entity expected");
}
ListTag items = NBTUtils.getChildTag(values, "Items", ListTag.class);
List<CompoundTag> compound = new ArrayList<CompoundTag>();
for (Tag tag : items.getValue()) {
if (!(tag instanceof CompoundTag)) {
throw new RuntimeException("CompoundTag expected as child tag of Furnace Items");
}
compound.add((CompoundTag) tag);
}
setItems(deserializeInventory(compound));
t = values.get("BurnTime");
if (t instanceof ShortTag) {
burnTime = ((ShortTag) t).getValue();
}
t = values.get("CookTime");
if (t instanceof ShortTag) {
cookTime = ((ShortTag) t).getValue();
}
} catch (DataException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -1,100 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.blocks;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.extent.Extent;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* A implementation of a lazy block for {@link Extent#getLazyBlock(Vector)}
* that takes the block's ID and metadata, but will defer loading of NBT
* data until time of access.
*
* <p>NBT data is later loaded using a call to {@link Extent#getBlock(Vector)}
* with a stored {@link Extent} and location.</p>
*
* <p>All mutators on this object will throw an
* {@link UnsupportedOperationException}.</p>
*/
public class LazyBlock extends BaseBlock {
private final Extent extent;
private final Vector position;
private boolean loaded = false;
/**
* Create a new lazy block.
*
* @param type the block type
* @param extent the extent to later load the full block data from
* @param position the position to later load the full block data from
*/
public LazyBlock(int type, Extent extent, Vector position) {
super(type);
checkNotNull(extent);
checkNotNull(position);
this.extent = extent;
this.position = position;
}
/**
* Create a new lazy block.
*
* @param type the block type
* @param data the data value
* @param extent the extent to later load the full block data from
* @param position the position to later load the full block data from
*/
public LazyBlock(int type, int data, Extent extent, Vector position) {
super(type, data);
checkNotNull(extent);
checkNotNull(position);
this.extent = extent;
this.position = position;
}
@Override
public void setId(int id) {
throw new UnsupportedOperationException("This object is immutable");
}
@Override
public void setData(int data) {
throw new UnsupportedOperationException("This object is immutable");
}
@Override
public CompoundTag getNbtData() {
if (!loaded) {
BaseBlock loadedBlock = extent.getBlock(position);
super.setNbtData(loadedBlock.getNbtData());
}
return super.getNbtData();
}
@Override
public void setNbtData(CompoundTag nbtData) {
throw new UnsupportedOperationException("This object is immutable");
}
}

View File

@ -25,7 +25,7 @@ import com.sk89q.jnbt.NBTUtils;
import com.sk89q.jnbt.ShortTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.blocks.metadata.MobType;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.storage.InvalidFormatException;
import java.util.HashMap;
@ -49,41 +49,23 @@ public class MobSpawnerBlock extends BaseBlock implements TileEntityBlock {
private short maxNearbyEntities;
private short requiredPlayerRange;
/**
* Construct the mob spawner block with a pig as the mob type.
*/
public MobSpawnerBlock() {
super(BlockID.MOB_SPAWNER);
this.mobType = MobType.PIG.getName();
}
/**
* Construct the mob spawner block with a given mob type.
*
* @param mobType mob type
*/
public MobSpawnerBlock(String mobType) {
super(BlockID.MOB_SPAWNER);
this.mobType = mobType;
}
/**
* Construct the mob spawner block with a specified data value.
*
* @param data data value
* @param blockState The block state
*/
public MobSpawnerBlock(int data) {
super(BlockID.MOB_SPAWNER, data);
public MobSpawnerBlock(BlockState blockState) {
super(blockState);
}
/**
* Construct the mob spawner block.
*
* @param data data value
* @param blockState The block state
* @param mobType mob type
*/
public MobSpawnerBlock(int data, String mobType) {
super(BlockID.MOB_SPAWNER, data);
public MobSpawnerBlock(BlockState blockState, String mobType) {
super(blockState);
this.mobType = mobType;
}

View File

@ -1,122 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.blocks;
import com.sk89q.jnbt.ByteTag;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import java.util.HashMap;
import java.util.Map;
/**
* A note block.
*/
public class NoteBlock extends BaseBlock implements TileEntityBlock {
private byte note;
/**
* Construct the note block with a data value of 0.
*/
public NoteBlock() {
super(BlockID.NOTE_BLOCK);
this.note = 0;
}
/**
* Construct the note block with a given data value.
*
* @param data data value
*/
public NoteBlock(int data) {
super(BlockID.NOTE_BLOCK, data);
this.note = 0;
}
/**
* Construct the note block with a given data value and note.
*
* @param data data value
* @param note note
*/
public NoteBlock(int data, byte note) {
super(BlockID.NOTE_BLOCK, data);
this.note = note;
}
/**
* Get the note.
*
* @return the note
*/
public byte getNote() {
return note;
}
/**
* Set the note.
*
* @param note the note to set
*/
public void setNote(byte note) {
this.note = note;
}
@Override
public boolean hasNbtData() {
return true;
}
@Override
public String getNbtId() {
return "Music";
}
@Override
public CompoundTag getNbtData() {
Map<String, Tag> values = new HashMap<String, Tag>();
values.put("note", new ByteTag(note));
return new CompoundTag(values);
}
@Override
public void setNbtData(CompoundTag rootTag) {
if (rootTag == null) {
return;
}
Map<String, Tag> values = rootTag.getValue();
Tag t;
t = values.get("id");
if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals("Music")) {
throw new RuntimeException("'Music' tile entity expected");
}
t = values.get("note");
if (t instanceof ByteTag) {
note = ((ByteTag) t).getValue();
}
}
}

View File

@ -23,6 +23,7 @@ import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.util.gson.GsonUtil;
import com.sk89q.worldedit.world.block.BlockState;
import java.util.HashMap;
import java.util.Map;
@ -36,26 +37,14 @@ public class SignBlock extends BaseBlock implements TileEntityBlock {
private static String EMPTY = "{\"text\":\"\"}";
/**
* Construct the sign without text.
*
* @param type type ID
* @param data data value (orientation)
*/
public SignBlock(int type, int data) {
super(type, data);
this.text = new String[] { EMPTY, EMPTY, EMPTY, EMPTY };
}
/**
* Construct the sign with text.
*
* @param type type ID
* @param data data value (orientation)
* @param blockState The block state
* @param text lines of text
*/
public SignBlock(int type, int data, String[] text) {
super(type, data);
public SignBlock(BlockState blockState, String[] text) {
super(blockState);
if (text == null) {
this.text = new String[] { EMPTY, EMPTY, EMPTY, EMPTY };
return;

View File

@ -19,10 +19,10 @@
package com.sk89q.worldedit.blocks;
import com.sk89q.jnbt.ByteTag;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.world.block.BlockState;
import java.util.HashMap;
import java.util.Map;
@ -33,60 +33,25 @@ import java.util.Map;
public class SkullBlock extends BaseBlock implements TileEntityBlock {
private String owner = ""; // notchian
private byte skullType; // stored here for block, in damage value for item
private byte rot; // only matters if block data == 0x1 (on floor)
/**
* Construct the skull block with a default type of skelton.
* @param data data value to set, controls placement
* @param state BlockState to set
*/
public SkullBlock(int data) {
this(data, (byte) 0);
}
/**
* Construct the skull block with a given type.
* 0 - skeleton
* 1 - wither skelly
* 2 - zombie
* 3 - human
* 4 - creeper
* @param data data value to set, controls placement
* @param type type of skull
*/
public SkullBlock(int data, byte type) {
this(data, type, (byte) 0);
}
/**
* Construct the skull block with a given type and rotation.
* @param data data value to set, controls placement
* @param type type of skull
* @param rot rotation (if on floor)
*/
public SkullBlock(int data, byte type, byte rot) {
super(BlockID.HEAD, data);
if (type < (byte) 0 || type > (byte) 4) {
this.skullType = (byte) 0;
} else {
this.skullType = type;
}
this.rot = rot;
public SkullBlock(BlockState state) {
super(state);
this.owner = "";
}
/**
* Construct the skull block with a given rotation and owner.
* The type is assumed to be player unless owner is null or empty.
* @param data data value to set, controls placement
* @param rot rotation of skull
* @param blockState BlockState to set
* @param owner name of player
*/
public SkullBlock(int data, byte rot, String owner) {
super(BlockID.HEAD, data);
this.rot = rot;
public SkullBlock(BlockState blockState, String owner) {
super(blockState);
this.setOwner(owner);
if (owner == null || owner.isEmpty()) this.skullType = (byte) 0;
}
/**
@ -100,7 +65,6 @@ public class SkullBlock extends BaseBlock implements TileEntityBlock {
if (owner.length() > 16 || owner.isEmpty()) this.owner = "";
else this.owner = owner;
}
if (this.owner != null && !this.owner.isEmpty()) this.skullType = (byte) 3;
}
/**
@ -111,38 +75,6 @@ public class SkullBlock extends BaseBlock implements TileEntityBlock {
return owner;
}
/**
* Get the type of skull.
* @return the skullType
*/
public byte getSkullType() {
return skullType;
}
/**
* Set the type of skull;
* @param skullType the skullType to set
*/
public void setSkullType(byte skullType) {
this.skullType = skullType;
}
/**
* Get rotation of skull. This only means anything if the block data is 1.
* @return the rotation
*/
public byte getRot() {
return rot;
}
/**
* Set the rotation of skull.
* @param rot the rotation to set
*/
public void setRot(byte rot) {
this.rot = rot;
}
@Override
public boolean hasNbtData() {
return true;
@ -155,11 +87,9 @@ public class SkullBlock extends BaseBlock implements TileEntityBlock {
@Override
public CompoundTag getNbtData() {
Map<String, Tag> values = new HashMap<String, Tag>();
values.put("SkullType", new ByteTag(skullType));
Map<String, Tag> values = new HashMap<>();
if (owner == null) owner = "";
values.put("ExtraType", new StringTag( owner));
values.put("Rot", new ByteTag(rot));
values.put("ExtraType", new StringTag(owner));
return new CompoundTag(values);
}
@ -178,17 +108,9 @@ public class SkullBlock extends BaseBlock implements TileEntityBlock {
throw new RuntimeException("'Skull' tile entity expected");
}
t = values.get("SkullType");
if (t instanceof ByteTag) {
skullType = ((ByteTag) t).getValue();
}
t = values.get("ExtraType");
if (t != null && t instanceof StringTag) {
if (t instanceof StringTag) {
owner = ((StringTag) t).getValue();
}
t = values.get("Rot");
if (t instanceof ByteTag) {
rot = ((ByteTag) t).getValue();
}
}
}

View File

@ -1,34 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.data;
/**
* @deprecated Switch to {@link com.sk89q.worldedit.world.DataException}
*/
@Deprecated
public class DataException extends com.sk89q.worldedit.world.DataException {
public DataException(String msg) {
super(msg);
}
public DataException() {
}
}

View File

@ -1,42 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.foundation;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* @deprecated Use {@link BaseBlock}
*/
@Deprecated
public abstract class Block {
public abstract int getId();
public abstract void setId(int id);
public abstract int getData();
public abstract void setData(int data);
public abstract void setIdAndData(int id, int data);
public abstract boolean hasWildcardData();
}

View File

@ -1,35 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.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) {
}
}

View File

@ -1,73 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
/**
* @deprecated Use {@link com.sk89q.worldedit.function.mask.BlockMask}
*/
@Deprecated
public class BlockMask extends AbstractMask {
private final Set<BaseBlock> blocks;
public BlockMask() {
blocks = new HashSet<BaseBlock>();
}
public BlockMask(Set<BaseBlock> types) {
this.blocks = types;
}
public BlockMask(BaseBlock... block) {
blocks = new HashSet<BaseBlock>();
for (BaseBlock b : block) {
add(b);
}
}
public BlockMask(BaseBlock block) {
this();
add(block);
}
public void add(BaseBlock block) {
blocks.add(block);
}
public void addAll(Collection<BaseBlock> blocks) {
blocks.addAll(blocks);
}
@Override
public boolean matches(EditSession editSession, Vector position) {
BaseBlock block = editSession.getBlock(position);
return blocks.contains(block)
|| blocks.contains(new BaseBlock(block.getType(), -1));
}
}

View File

@ -1,84 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.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<Mask> masks = new ArrayList<Mask>();
public CombinedMask() {
}
public CombinedMask(Mask mask) {
add(mask);
}
public CombinedMask(Mask ...mask) {
for (Mask m : mask) {
add(m);
}
}
public CombinedMask(List<Mask> masks) {
this.masks.addAll(masks);
}
public void add(Mask mask) {
masks.add(mask);
}
public boolean remove(Mask mask) {
return masks.remove(mask);
}
public boolean has(Mask mask) {
return masks.contains(mask);
}
@Override
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
for (Mask mask : masks) {
mask.prepare(session, player, target);
}
}
@Override
public boolean matches(EditSession editSession, Vector position) {
for (Mask mask : masks) {
if (!mask.matches(editSession, position)) {
return false;
}
}
return true;
}
}

View File

@ -1,35 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockID;
/**
* @deprecated See {@link com.sk89q.worldedit.function.mask.ExistingBlockMask}
*/
@Deprecated
public class ExistingBlockMask extends AbstractMask {
@Override
public boolean matches(EditSession editSession, Vector position) {
return editSession.getBlockType(position) != BlockID.AIR;
}
}

View File

@ -1,64 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.Blocks;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
* @deprecated See {@link com.sk89q.worldedit.function.mask.FuzzyBlockMask}
*/
@Deprecated
public class FuzzyBlockMask extends AbstractMask {
private final Set<BaseBlock> filter;
/**
* Create a new fuzzy block mask.
*
* @param filter a list of block types to match
*/
public FuzzyBlockMask(Set<BaseBlock> filter) {
this.filter = filter;
}
/**
* Create a new fuzzy block mask.
*
* @param block a list of block types to match
*/
public FuzzyBlockMask(BaseBlock... block) {
Set<BaseBlock> filter = new HashSet<BaseBlock>();
Collections.addAll(filter, block);
this.filter = filter;
}
@Override
public boolean matches(EditSession editSession, Vector position) {
BaseBlock compare = new BaseBlock(editSession.getBlockType(position), editSession.getBlockData(position));
return Blocks.containsFuzzy(filter, compare);
}
}

View File

@ -1,54 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
/**
* @deprecated Use {@link com.sk89q.worldedit.function.mask.Mask}
*/
@Deprecated
public interface Mask {
/**
* Called one time before each edit session.
*
* @param session a session
* @param player a player
* @param target target of the brush, null if not a brush mask
*/
void prepare(LocalSession session, LocalPlayer player, Vector target);
/**
* Given a block position, this method returns true if the block at
* that position matches the filter. Block information is not provided
* as getting a BaseBlock has unneeded overhead in most block querying
* situations (enumerating a chest's contents is a waste, for example).
*
* @param editSession an instance
* @param position the position to check
* @return true if it matches
*/
boolean matches(EditSession editSession, Vector position);
}

View File

@ -1,35 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockType;
/**
* @deprecated See {@link com.sk89q.worldedit.function.mask.SolidBlockMask}
*/
@Deprecated
public class SolidBlockMask extends AbstractMask {
@Override
public boolean matches(EditSession editSession, Vector position) {
return !BlockType.canPassThrough(editSession.getBlockType(position), editSession.getBlockData(position));
}
}

View File

@ -1,76 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.function.mask.MaskIntersection;
import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.function.mask.OffsetMask;
import java.util.Set;
/**
* @deprecated Use {@link OffsetMask} with {@link MaskIntersection} and {@link Masks#negate(com.sk89q.worldedit.function.mask.Mask)}
*/
@Deprecated
public class UnderOverlayMask extends AbstractMask {
private final int yMod;
private Mask mask;
@Deprecated
public UnderOverlayMask(Set<Integer> ids, boolean overlay) {
this(new BlockTypeMask(ids), overlay);
}
public UnderOverlayMask(Mask mask, boolean overlay) {
this.yMod = overlay ? -1 : 1;
this.mask = mask;
}
@Deprecated
public void addAll(Set<Integer> ids) {
if (mask instanceof BlockMask) {
final BlockMask blockTypeMask = (BlockMask) mask;
for (Integer id : ids) {
blockTypeMask.add(new BaseBlock(id));
}
} else if (mask instanceof ExistingBlockMask) {
final BlockMask blockMask = new BlockMask();
for (int type : ids) {
blockMask.add(new BaseBlock(type));
}
mask = blockMask;
}
}
@Override
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
mask.prepare(session, player, target);
}
@Override
public boolean matches(EditSession editSession, Vector position) {
return !mask.matches(editSession, position) && mask.matches(editSession, position.add(0, yMod, 0));
}
}

View File

@ -1,51 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.patterns;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* @deprecated See {@link com.sk89q.worldedit.function.pattern.Pattern}
*/
@Deprecated
public interface Pattern {
/**
* Get a block for a position. This return value of this method does
* not have to be consistent for the same position.
*
* @param position the position where a block is needed
* @return a block
*/
public BaseBlock next(Vector position);
/**
* Get a block for a position. This return value of this method does
* not have to be consistent for the same position.
*
* @param x the X coordinate
* @param y the Y coordinate
* @param z the Z coordinate
* @return a block
*/
public BaseBlock next(int x, int y, int z);
}

View File

@ -1,82 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.patterns;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.function.pattern.RandomPattern;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
* @deprecated See {@link RandomPattern}
*/
@Deprecated
public class RandomFillPattern implements Pattern {
private static final Random random = new Random();
private List<BlockChance> blocks;
/**
* Construct the object.
*
* @param blocks a list of blocks
*/
public RandomFillPattern(List<BlockChance> blocks) {
double max = 0;
for (BlockChance block : blocks) {
max += block.getChance();
}
List<BlockChance> finalBlocks = new ArrayList<BlockChance>();
double i = 0;
for (BlockChance block : blocks) {
double v = block.getChance() / max;
i += v;
finalBlocks.add(new BlockChance(block.getBlock(), i));
}
this.blocks = finalBlocks;
}
@Override
public BaseBlock next(Vector position) {
double r = random.nextDouble();
for (BlockChance block : blocks) {
if (r <= block.getChance()) {
return block.getBlock();
}
}
throw new RuntimeException("ProportionalFillPattern");
}
@Override
public BaseBlock next(int x, int y, int z) {
return next(null);
}
}

View File

@ -1,44 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.extension.platform.Actor;
abstract class AbstractLegacyRegionSelector implements RegionSelector {
@Deprecated
public final void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector position) {
explainPrimarySelection((Actor) player, session, position);
}
@Deprecated
public final void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector position) {
explainSecondarySelection((Actor) player, session, position);
}
@Deprecated
public final void explainRegionAdjust(LocalPlayer player, LocalSession session) {
explainRegionAdjust((Actor) player, session);
}
}

View File

@ -1,29 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.internal.cui.CUIRegion;
/**
* @deprecated This class only exists as to not break binary compatibility
*/
@Deprecated
public abstract class ConvexPolyhedralRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
}

View File

@ -1,29 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.internal.cui.CUIRegion;
/**
* @deprecated This class only exists as to not break binary compatibility
*/
@Deprecated
public abstract class CuboidRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
}

View File

@ -1,29 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.internal.cui.CUIRegion;
/**
* @deprecated This class only exists as to not break binary compatibility
*/
@Deprecated
public abstract class CylinderRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
}

View File

@ -1,29 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.internal.cui.CUIRegion;
/**
* @deprecated This class only exists as to not break binary compatibility
*/
@Deprecated
public abstract class EllipsoidRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
}

View File

@ -1,29 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.internal.cui.CUIRegion;
/**
* @deprecated This class only exists as to not break binary compatibility
*/
@Deprecated
public abstract class ExtendingCuboidRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
}

View File

@ -1,37 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.internal.cui.CUIRegion;
/**
* @deprecated This class only exists as to not break binary compatibility
*/
@Deprecated
public abstract class Polygonal2DRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
/**
* Get the number of points.
*
* @return the number of points
*/
public abstract int getPointCount();
}

View File

@ -1,29 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.internal.cui.CUIRegion;
/**
* @deprecated This class only exists as to not break binary compatibility
*/
@Deprecated
public abstract class SphereRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
}

View File

@ -72,7 +72,7 @@ public final class CompoundTag extends Tag {
* @return the builder
*/
public CompoundTagBuilder createBuilder() {
return new CompoundTagBuilder(new HashMap<String, Tag>(value));
return new CompoundTagBuilder(new HashMap<>(value));
}
/**

View File

@ -19,11 +19,11 @@
package com.sk89q.jnbt;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.HashMap;
import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Helps create compound tags.
*/
@ -35,7 +35,7 @@ public class CompoundTagBuilder {
* Create a new instance.
*/
CompoundTagBuilder() {
this.entries = new HashMap<String, Tag>();
this.entries = new HashMap<>();
}
/**
@ -189,7 +189,7 @@ public class CompoundTagBuilder {
* @return the new compound tag
*/
public CompoundTag build() {
return new CompoundTag(new HashMap<String, Tag>(entries));
return new CompoundTag(new HashMap<>(entries));
}
/**

View File

@ -19,12 +19,12 @@
package com.sk89q.jnbt;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
/**
* The {@code TAG_List} tag.
@ -79,11 +79,10 @@ public final class ListTag extends Tag {
*/
@Nullable
public Tag getIfExists(int index) {
try {
return value.get(index);
} catch (NoSuchElementException e) {
if (index >= value.size()) {
return null;
}
return value.get(index);
}
/**

View File

@ -19,13 +19,13 @@
package com.sk89q.jnbt;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Helps create list tags.
*/
@ -42,7 +42,7 @@ public class ListTagBuilder {
ListTagBuilder(Class<? extends Tag> type) {
checkNotNull(type);
this.type = type;
this.entries = new ArrayList<Tag>();
this.entries = new ArrayList<>();
}
/**
@ -80,7 +80,7 @@ public class ListTagBuilder {
* @return the new list tag
*/
public ListTag build() {
return new ListTag(type, new ArrayList<Tag>(entries));
return new ListTag(type, new ArrayList<>(entries));
}
/**

View File

@ -128,7 +128,7 @@ public final class NBTInputStream implements Closeable {
int childType = is.readByte();
length = is.readInt();
List<Tag> tagList = new ArrayList<Tag>();
List<Tag> tagList = new ArrayList<>();
for (int i = 0; i < length; ++i) {
Tag tag = readTagPayload(childType, depth + 1);
if (tag instanceof EndTag) {
@ -139,7 +139,7 @@ public final class NBTInputStream implements Closeable {
return new ListTag(NBTUtils.getTypeClass(childType), tagList);
case NBTConstants.TYPE_COMPOUND:
Map<String, Tag> tagMap = new HashMap<String, Tag>();
Map<String, Tag> tagMap = new HashMap<>();
while (true) {
NamedTag namedTag = readNamedTag(depth + 1);
Tag tag = namedTag.getTag();

View File

@ -19,6 +19,8 @@
package com.sk89q.jnbt;
import static com.google.common.base.Preconditions.checkNotNull;
import java.io.Closeable;
import java.io.DataOutputStream;
import java.io.IOException;
@ -26,8 +28,6 @@ import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* This class writes <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
* {@code Tag} objects to an underlying {@code OutputStream}.

View File

@ -19,13 +19,13 @@
package com.sk89q.jnbt;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.world.storage.InvalidFormatException;
import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* A class which contains NBT-related utility methods.
*

View File

@ -34,8 +34,8 @@ public class CommandContext {
protected final List<Integer> originalArgIndices;
protected final String[] originalArgs;
protected final Set<Character> booleanFlags = new HashSet<Character>();
protected final Map<Character, String> valueFlags = new HashMap<Character, String>();
protected final Set<Character> booleanFlags = new HashSet<>();
protected final Map<Character, String> valueFlags = new HashMap<>();
protected final SuggestionContext suggestionContext;
protected final CommandLocals locals;
@ -103,8 +103,8 @@ public class CommandContext {
SuggestionContext suggestionContext = SuggestionContext.hangingValue();
// Eliminate empty args and combine multiword args first
List<Integer> argIndexList = new ArrayList<Integer>(args.length);
List<String> argList = new ArrayList<String>(args.length);
List<Integer> argIndexList = new ArrayList<>(args.length);
List<String> argList = new ArrayList<>(args.length);
for (int i = 1; i < args.length; ++i) {
isHanging = false;
@ -152,8 +152,8 @@ public class CommandContext {
// Then flags
this.originalArgIndices = new ArrayList<Integer>(argIndexList.size());
this.parsedArgs = new ArrayList<String>(argList.size());
this.originalArgIndices = new ArrayList<>(argIndexList.size());
this.parsedArgs = new ArrayList<>(argList.size());
if (parseFlags) {
for (int nextArg = 0; nextArg < argList.size(); ) {

View File

@ -19,16 +19,17 @@
package com.sk89q.minecraft.util.commands;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
public class CommandException extends Exception {
private List<String> commandStack = new ArrayList<String>();
private List<String> commandStack = new ArrayList<>();
public CommandException() {
super();

View File

@ -24,7 +24,7 @@ import java.util.Map;
public class CommandLocals {
private final Map<Object, Object> locals = new HashMap<Object, Object>();
private final Map<Object, Object> locals = new HashMap<>();
public boolean containsKey(Object key) {
return locals.containsKey(key);

View File

@ -72,18 +72,18 @@ public abstract class CommandsManager<T> {
* the key of the command name (one for each alias) with the
* method.
*/
protected Map<Method, Map<String, Method>> commands = new HashMap<Method, Map<String, Method>>();
protected Map<Method, Map<String, Method>> commands = new HashMap<>();
/**
* Used to store the instances associated with a method.
*/
protected Map<Method, Object> instances = new HashMap<Method, Object>();
protected Map<Method, Object> instances = new HashMap<>();
/**
* Mapping of commands (not including aliases) with a description. This
* is only for top level commands.
*/
protected Map<String, String> descs = new HashMap<String, String>();
protected Map<String, String> descs = new HashMap<>();
/**
* Stores the injector used to getInstance.
@ -94,7 +94,7 @@ public abstract class CommandsManager<T> {
* Mapping of commands (not including aliases) with a description. This
* is only for top level commands.
*/
protected Map<String, String> helpMessages = new HashMap<String, String>();
protected Map<String, String> helpMessages = new HashMap<>();
/**
* Register an class that contains commands (denoted by {@link Command}.
@ -141,11 +141,7 @@ public abstract class CommandsManager<T> {
Object obj = getInjector().getInstance(cls);
return registerMethods(cls, parent, obj);
}
} catch (InvocationTargetException e) {
logger.log(Level.SEVERE, "Failed to register commands", e);
} catch (IllegalAccessException e) {
logger.log(Level.SEVERE, "Failed to register commands", e);
} catch (InstantiationException e) {
} catch (InvocationTargetException | InstantiationException | IllegalAccessException e) {
logger.log(Level.SEVERE, "Failed to register commands", e);
}
return null;
@ -161,14 +157,14 @@ public abstract class CommandsManager<T> {
*/
private List<Command> registerMethods(Class<?> cls, Method parent, Object obj) {
Map<String, Method> map;
List<Command> registered = new ArrayList<Command>();
List<Command> registered = new ArrayList<>();
// Make a new hash map to cache the commands for this class
// as looking up methods via reflection is fairly slow
if (commands.containsKey(parent)) {
map = commands.get(parent);
} else {
map = new HashMap<String, Method>();
map = new HashMap<>();
commands.put(parent, map);
}
@ -359,7 +355,7 @@ public abstract class CommandsManager<T> {
command.append("<");
Set<String> allowedCommands = new HashSet<String>();
Set<String> allowedCommands = new HashSet<>();
for (Map.Entry<String, Method> entry : map.entrySet()) {
Method childMethod = entry.getValue();
@ -479,10 +475,10 @@ public abstract class CommandsManager<T> {
String[] newArgs = new String[args.length - level];
System.arraycopy(args, level, newArgs, 0, args.length - level);
final Set<Character> valueFlags = new HashSet<Character>();
final Set<Character> valueFlags = new HashSet<>();
char[] flags = cmd.flags().toCharArray();
Set<Character> newFlags = new HashSet<Character>();
Set<Character> newFlags = new HashSet<>();
for (int i = 0; i < flags.length; ++i) {
if (flags.length > i + 1 && flags[i + 1] == ':') {
valueFlags.add(flags[i]);
@ -526,9 +522,7 @@ public abstract class CommandsManager<T> {
public void invokeMethod(Method parent, String[] args, T player, Method method, Object instance, Object[] methodArgs, int level) throws CommandException {
try {
method.invoke(instance, methodArgs);
} catch (IllegalArgumentException e) {
logger.log(Level.SEVERE, "Failed to execute command", e);
} catch (IllegalAccessException e) {
} catch (IllegalArgumentException | IllegalAccessException e) {
logger.log(Level.SEVERE, "Failed to execute command", e);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof CommandException) {

Some files were not shown because too many files have changed in this diff Show More