Split up source files into several source directories.

This commit is contained in:
sk89q
2014-04-02 20:03:52 -07:00
parent 469cb8c8b3
commit 6c460f02c5
85 changed files with 5577 additions and 5437 deletions

View File

@ -1,87 +0,0 @@
package com.sk89q.worldedit.bukkit;
import java.util.Locale;
import org.bukkit.block.Biome;
import com.sk89q.worldedit.BiomeType;
public enum BukkitBiomeType implements BiomeType {
SWAMPLAND(Biome.SWAMPLAND),
FOREST(Biome.FOREST),
TAIGA(Biome.TAIGA),
DESERT(Biome.DESERT),
PLAINS(Biome.PLAINS),
HELL(Biome.HELL),
SKY(Biome.SKY),
RIVER(Biome.RIVER),
EXTREME_HILLS(Biome.EXTREME_HILLS),
OCEAN(Biome.OCEAN),
FROZEN_OCEAN(Biome.FROZEN_OCEAN),
FROZEN_RIVER(Biome.FROZEN_RIVER),
ICE_PLAINS(Biome.ICE_PLAINS),
ICE_MOUNTAINS(Biome.ICE_MOUNTAINS),
MUSHROOM_ISLAND(Biome.MUSHROOM_ISLAND),
MUSHROOM_SHORE(Biome.MUSHROOM_SHORE),
BEACH(Biome.BEACH),
DESERT_HILLS(Biome.DESERT_HILLS),
FOREST_HILLS(Biome.FOREST_HILLS),
TAIGA_HILLS(Biome.TAIGA_HILLS),
SMALL_MOUNTAINS(Biome.SMALL_MOUNTAINS),
JUNGLE(Biome.JUNGLE),
JUNGLE_HILLS(Biome.JUNGLE_HILLS),
JUNGLE_EDGE(Biome.JUNGLE_EDGE),
DEEP_OCEAN(Biome.DEEP_OCEAN),
STONE_BEACH(Biome.STONE_BEACH),
COLD_BEACH(Biome.COLD_BEACH),
BIRCH_FOREST(Biome.BIRCH_FOREST),
BIRCH_FOREST_HILLS(Biome.BIRCH_FOREST_HILLS),
ROOFED_FOREST(Biome.ROOFED_FOREST),
COLD_TAIGA(Biome.COLD_TAIGA),
COLD_TAIGA_HILLS(Biome.COLD_TAIGA_HILLS),
MEGA_TAIGA(Biome.MEGA_TAIGA),
MEGA_TAIGA_HILLS(Biome.MEGA_TAIGA_HILLS),
EXTREME_HILLS_PLUS(Biome.EXTREME_HILLS_PLUS),
SAVANNA(Biome.SAVANNA),
SAVANNA_PLATEAU(Biome.SAVANNA_PLATEAU),
MESA(Biome.MESA),
MESA_PLATEAU_FOREST(Biome.MESA_PLATEAU_FOREST),
MESA_PLATEAU(Biome.MESA_PLATEAU),
SUNFLOWER_PLAINS(Biome.SUNFLOWER_PLAINS),
DESERT_MOUNTAINS(Biome.DESERT_MOUNTAINS),
FLOWER_FOREST(Biome.FLOWER_FOREST),
TAIGA_MOUNTAINS(Biome.TAIGA_MOUNTAINS),
SWAMPLAND_MOUNTAINS(Biome.SWAMPLAND_MOUNTAINS),
ICE_PLAINS_SPIKES(Biome.ICE_PLAINS_SPIKES),
JUNGLE_MOUNTAINS(Biome.JUNGLE_MOUNTAINS),
JUNGLE_EDGE_MOUNTAINS(Biome.JUNGLE_EDGE_MOUNTAINS),
COLD_TAIGA_MOUNTAINS(Biome.COLD_TAIGA_MOUNTAINS),
SAVANNA_MOUNTAINS(Biome.SAVANNA_MOUNTAINS),
SAVANNA_PLATEAU_MOUNTAINS(Biome.SAVANNA_PLATEAU_MOUNTAINS),
MESA_BRYCE(Biome.MESA_BRYCE),
MESA_PLATEAU_FOREST_MOUNTAINS(Biome.MESA_PLATEAU_FOREST_MOUNTAINS),
MESA_PLATEAU_MOUNTAINS(Biome.MESA_PLATEAU_MOUNTAINS),
BIRCH_FOREST_MOUNTAINS(Biome.BIRCH_FOREST_MOUNTAINS),
BIRCH_FOREST_HILLS_MOUNTAINS(Biome.BIRCH_FOREST_HILLS_MOUNTAINS),
ROOFED_FOREST_MOUNTAINS(Biome.ROOFED_FOREST_MOUNTAINS),
MEGA_SPRUCE_TAIGA(Biome.MEGA_SPRUCE_TAIGA),
EXTREME_HILLS_MOUNTAINS(Biome.EXTREME_HILLS_MOUNTAINS),
EXTREME_HILLS_PLUS_MOUNTAINS(Biome.EXTREME_HILLS_PLUS_MOUNTAINS),
MEGA_SPRUCE_TAIGA_HILLS(Biome.MEGA_SPRUCE_TAIGA_HILLS);
private Biome bukkitBiome;
private BukkitBiomeType(Biome biome) {
this.bukkitBiome = biome;
}
@Override
public String getName() {
return name().toLowerCase(Locale.ENGLISH);
}
public Biome getBukkitBiome() {
return bukkitBiome;
}
}

View File

@ -1,40 +0,0 @@
package com.sk89q.worldedit.bukkit;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import com.sk89q.worldedit.BiomeType;
import com.sk89q.worldedit.BiomeTypes;
import com.sk89q.worldedit.UnknownBiomeTypeException;
public class BukkitBiomeTypes implements BiomeTypes {
public BukkitBiomeTypes() {
}
@Override
public boolean has(String name) {
try {
BukkitBiomeType.valueOf(name.toUpperCase(Locale.ENGLISH));
return true;
} catch (IllegalArgumentException exc) {
return false;
}
}
@Override
public BiomeType get(String name) throws UnknownBiomeTypeException {
try {
return BukkitBiomeType.valueOf(name.toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException exc) {
throw new UnknownBiomeTypeException(name);
}
}
@Override
public List<BiomeType> all() {
return Arrays.<BiomeType>asList(BukkitBiomeType.values());
}
}

View File

@ -1,134 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.PlayerNeededException;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.extent.inventory.BlockBag;
public class BukkitCommandSender extends LocalPlayer {
private CommandSender sender;
private WorldEditPlugin plugin;
public BukkitCommandSender(WorldEditPlugin plugin, ServerInterface server, CommandSender sender) {
super(server);
this.plugin = plugin;
this.sender = sender;
}
@Override
public String getName() {
return sender.getName();
}
@Override
public void printRaw(String msg) {
for (String part : msg.split("\n")) {
sender.sendMessage(part);
}
}
@Override
public void print(String msg) {
for (String part : msg.split("\n")) {
sender.sendMessage("\u00A7d" + part);
}
}
@Override
public void printDebug(String msg) {
for (String part : msg.split("\n")) {
sender.sendMessage("\u00A77" + part);
}
}
@Override
public void printError(String msg) {
for (String part : msg.split("\n")) {
sender.sendMessage("\u00A7c" + part);
}
}
@Override
public String[] getGroups() {
return new String[0];
}
@Override
public boolean hasPermission(String perm) {
if (!plugin.getLocalConfiguration().noOpPermissions && sender.isOp()) {
return true;
}
return plugin.getPermissionsResolver().hasPermission(null, sender.getName(), perm);
}
@Override
public boolean isPlayer() {
return sender instanceof Player;
}
@Override
public int getItemInHand() {
throw new PlayerNeededException();
}
@Override
public WorldVector getPosition() {
throw new PlayerNeededException();
}
@Override
public LocalWorld getWorld() {
throw new PlayerNeededException();
}
@Override
public double getPitch() {
throw new PlayerNeededException();
}
@Override
public double getYaw() {
throw new PlayerNeededException();
}
@Override
public void giveItem(int type, int amt) {
throw new PlayerNeededException();
}
@Override
public void setPosition(Vector pos, float pitch, float yaw) {
throw new PlayerNeededException();
}
@Override
public BlockBag getInventoryBlockBag() {
throw new PlayerNeededException();
}
}

View File

@ -1,70 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2011 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.worldedit.util.YAMLConfiguration;
import java.io.File;
/**
* YAMLConfiguration but with setting for no op permissions and plugin root data folder
*/
public class BukkitConfiguration extends YAMLConfiguration {
public boolean noOpPermissions = false;
private final WorldEditPlugin plugin;
public BukkitConfiguration(YAMLProcessor config, WorldEditPlugin plugin) {
super(config, plugin.getLogger());
this.plugin = plugin;
}
@Override
public void load() {
super.load();
noOpPermissions = config.getBoolean("no-op-permissions", false);
migrateLegacyFolders();
}
private void migrateLegacyFolders() {
migrate(scriptsDir, "craftscripts");
migrate(saveDir, "schematics");
migrate("drawings", "draw.js images");
}
private void migrate(String file, String name) {
File fromDir = new File(".", file);
File toDir = new File(getWorkingDirectory(), file);
if (fromDir.exists() & !toDir.exists()) {
if (fromDir.renameTo(toDir)) {
plugin.getLogger().info("Migrated " + name + " folder '" + file +
"' from server root to plugin data folder.");
} else {
plugin.getLogger().warning("Error while migrating " + name + " folder!");
}
}
}
@Override
public File getWorkingDirectory() {
return plugin.getDataFolder();
}
}

View File

@ -1,171 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.internal.cui.CUIEvent;
public class BukkitPlayer extends LocalPlayer {
private Player player;
private WorldEditPlugin plugin;
public BukkitPlayer(WorldEditPlugin plugin, ServerInterface server, Player player) {
super(server);
this.plugin = plugin;
this.player = player;
}
@Override
public int getItemInHand() {
ItemStack itemStack = player.getItemInHand();
return itemStack != null ? itemStack.getTypeId() : 0;
}
public BaseBlock getBlockInHand() throws WorldEditException {
ItemStack itemStack = player.getItemInHand();
return BukkitUtil.toBlock(getWorld(), itemStack);
}
@Override
public String getName() {
return player.getName();
}
@Override
public WorldVector getPosition() {
Location loc = player.getLocation();
return new WorldVector(BukkitUtil.getLocalWorld(loc.getWorld()),
loc.getX(), loc.getY(), loc.getZ());
}
@Override
public double getPitch() {
return player.getLocation().getPitch();
}
@Override
public double getYaw() {
return player.getLocation().getYaw();
}
@Override
public void giveItem(int type, int amt) {
player.getInventory().addItem(new ItemStack(type, amt));
}
@Override
public void printRaw(String msg) {
for (String part : msg.split("\n")) {
player.sendMessage(part);
}
}
@Override
public void print(String msg) {
for (String part : msg.split("\n")) {
player.sendMessage("\u00A7d" + part);
}
}
@Override
public void printDebug(String msg) {
for (String part : msg.split("\n")) {
player.sendMessage("\u00A77" + part);
}
}
@Override
public void printError(String msg) {
for (String part : msg.split("\n")) {
player.sendMessage("\u00A7c" + part);
}
}
@Override
public void setPosition(Vector pos, float pitch, float yaw) {
player.teleport(new Location(player.getWorld(), pos.getX(), pos.getY(),
pos.getZ(), yaw, pitch));
}
@Override
public String[] getGroups() {
return plugin.getPermissionsResolver().getGroups(player);
}
@Override
public BlockBag getInventoryBlockBag() {
return new BukkitPlayerBlockBag(player);
}
@Override
public boolean hasPermission(String perm) {
return (!plugin.getLocalConfiguration().noOpPermissions && player.isOp())
|| plugin.getPermissionsResolver().hasPermission(
player.getWorld().getName(), player, perm);
}
@Override
public LocalWorld getWorld() {
return BukkitUtil.getLocalWorld(player.getWorld());
}
@Override
public void dispatchCUIEvent(CUIEvent event) {
String[] params = event.getParameters();
String send = event.getTypeId();
if (params.length > 0) {
send = send + "|" + StringUtil.joinString(params, "|");
}
player.sendPluginMessage(plugin, WorldEditPlugin.CUI_PLUGIN_CHANNEL, send.getBytes(CUIChannelListener.UTF_8_CHARSET));
}
public Player getPlayer() {
return player;
}
@Override
public boolean hasCreativeMode() {
return player.getGameMode() == GameMode.CREATIVE;
}
@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
if (alwaysGlass || !player.getAllowFlight()) {
super.floatAt(x, y, z, alwaysGlass);
return;
}
setPosition(new Vector(x + 0.5, y, z + 0.5));
player.setFlying(true);
}
}

View File

@ -1,228 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.WorldVector;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.sk89q.worldedit.extent.inventory.*;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.ItemType;
public class BukkitPlayerBlockBag extends BlockBag {
/**
* Player instance.
*/
private Player player;
/**
* The player's inventory;
*/
private ItemStack[] items;
/**
* Construct the object.
*
* @param player
*/
public BukkitPlayerBlockBag(Player player) {
this.player = player;
}
/**
* Loads inventory on first use.
*/
private void loadInventory() {
if (items == null) {
items = player.getInventory().getContents();
}
}
/**
* Get the player.
*
* @return
*/
public Player getPlayer() {
return player;
}
/**
* Get a block.
*
* @param id
*/
@Override
public void fetchItem(BaseItem item) throws BlockBagException {
final int id = item.getType();
final int damage = item.getData();
int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
assert(amount == 1);
boolean usesDamageValue = ItemType.usesDamageValue(id);
if (id == BlockID.AIR) {
throw new IllegalArgumentException("Can't fetch air block");
}
loadInventory();
boolean found = false;
for (int slot = 0; slot < items.length; ++slot) {
ItemStack bukkitItem = items[slot];
if (bukkitItem == null) {
continue;
}
if (bukkitItem.getTypeId() != id) {
// Type id doesn't fit
continue;
}
if (usesDamageValue && bukkitItem.getDurability() != damage) {
// Damage value doesn't fit.
continue;
}
int currentAmount = bukkitItem.getAmount();
if (currentAmount < 0) {
// Unlimited
return;
}
if (currentAmount > 1) {
bukkitItem.setAmount(currentAmount - 1);
found = true;
} else {
items[slot] = null;
found = true;
}
break;
}
if (!found) {
throw new OutOfBlocksException();
}
}
/**
* Store a block.
*
* @param id
*/
@Override
public void storeItem(BaseItem item) throws BlockBagException {
final int id = item.getType();
final int damage = item.getData();
int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
assert(amount <= 64);
boolean usesDamageValue = ItemType.usesDamageValue(id);
if (id == BlockID.AIR) {
throw new IllegalArgumentException("Can't store air block");
}
loadInventory();
int freeSlot = -1;
for (int slot = 0; slot < items.length; ++slot) {
ItemStack bukkitItem = items[slot];
if (bukkitItem == null) {
// Delay using up a free slot until we know there are no stacks
// of this item to merge into
if (freeSlot == -1) {
freeSlot = slot;
}
continue;
}
if (bukkitItem.getTypeId() != id) {
// Type id doesn't fit
continue;
}
if (usesDamageValue && bukkitItem.getDurability() != damage) {
// Damage value doesn't fit.
continue;
}
int currentAmount = bukkitItem.getAmount();
if (currentAmount < 0) {
// Unlimited
return;
}
if (currentAmount >= 64) {
// Full stack
continue;
}
int spaceLeft = 64 - currentAmount;
if (spaceLeft >= amount) {
bukkitItem.setAmount(currentAmount + amount);
return;
}
bukkitItem.setAmount(64);
amount -= spaceLeft;
}
if (freeSlot > -1) {
items[freeSlot] = new ItemStack(id, amount);
return;
}
throw new OutOfSpaceException(id);
}
/**
* Flush any changes. This is called at the end.
*/
@Override
public void flushChanges() {
if (items != null) {
player.getInventory().setContents(items);
items = null;
}
}
/**
* Adds a position to be used a source.
*
* @param pos
*/
@Override
public void addSourcePosition(WorldVector pos) {
}
/**
* Adds a position to be used a source.
*
* @param pos
*/
@Override
public void addSingleSourcePosition(WorldVector pos) {
}
}

View File

@ -1,125 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.sk89q.bukkit.util.CommandInfo;
import com.sk89q.bukkit.util.CommandRegistration;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.CommandsManager;
import com.sk89q.worldedit.LocalPlayer;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
import com.sk89q.worldedit.BiomeTypes;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.ServerInterface;
public class BukkitServerInterface extends ServerInterface {
public Server server;
public WorldEditPlugin plugin;
private CommandRegistration dynamicCommands;
private BukkitBiomeTypes biomes;
public BukkitServerInterface(WorldEditPlugin plugin, Server server) {
this.plugin = plugin;
this.server = server;
this.biomes = new BukkitBiomeTypes();
dynamicCommands = new CommandRegistration(plugin);
}
@Override
public int resolveItem(String name) {
Material mat = Material.matchMaterial(name);
return mat == null ? 0 : mat.getId();
}
@Override
public boolean isValidMobType(String type) {
final EntityType entityType = EntityType.fromName(type);
return entityType != null && entityType.isAlive();
}
@Override
public void reload() {
plugin.loadConfiguration();
}
@Override
public BiomeTypes getBiomes() {
return biomes;
}
@Override
public int schedule(long delay, long period, Runnable task) {
return Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, task, delay, period);
}
@Override
public List<LocalWorld> getWorlds() {
List<World> worlds = server.getWorlds();
List<LocalWorld> ret = new ArrayList<LocalWorld>(worlds.size());
for (World world : worlds) {
ret.add(BukkitUtil.getLocalWorld(world));
}
return ret;
}
@Override
public void onCommandRegistration(List<Command> commands, CommandsManager<LocalPlayer> manager) {
List<CommandInfo> toRegister = new ArrayList<CommandInfo>();
for (Command command : commands) {
List<String> permissions = null;
Method cmdMethod = manager.getMethods().get(null).get(command.aliases()[0]);
Map<String, Method> childMethods = manager.getMethods().get(cmdMethod);
if (cmdMethod != null && cmdMethod.isAnnotationPresent(CommandPermissions.class)) {
permissions = Arrays.asList(cmdMethod.getAnnotation(CommandPermissions.class).value());
} else if (cmdMethod != null && childMethods != null && childMethods.size() > 0) {
permissions = new ArrayList<String>();
for (Method m : childMethods.values()) {
if (m.isAnnotationPresent(CommandPermissions.class)) {
permissions.addAll(Arrays.asList(m.getAnnotation(CommandPermissions.class).value()));
}
}
}
toRegister.add(new CommandInfo(command.usage(), command.desc(), command.aliases(), commands, permissions == null ? null : permissions.toArray(new String[permissions.size()])));
}
dynamicCommands.register(toRegister);
}
public void unregisterCommands() {
dynamicCommands.unregisterCommands();
}
}

View File

@ -1,195 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <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 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.size() == 0) {
return null;
}
return players.get(0);
}
public static Block toBlock(BlockWorldVector pt) {
return toWorld(pt).getBlockAt(toLocation(pt));
}
public static World toWorld(WorldVector pt) {
return ((BukkitWorld) pt.getWorld()).getWorld();
}
/**
* Bukkit's Location class has serious problems with floating point
* precision.
*/
@SuppressWarnings("RedundantIfStatement")
public static boolean equals(org.bukkit.Location a, org.bukkit.Location b) {
if (Math.abs(a.getX() - b.getX()) > EQUALS_PRECISION) return false;
if (Math.abs(a.getY() - b.getY()) > EQUALS_PRECISION) return false;
if (Math.abs(a.getZ() - b.getZ()) > EQUALS_PRECISION) return false;
return true;
}
public static final double EQUALS_PRECISION = 0.0001;
public static org.bukkit.Location toLocation(Location location) {
Vector pt = location.getPosition();
return new org.bukkit.Location(
toWorld(location.getWorld()),
pt.getX(), pt.getY(), pt.getZ(),
location.getYaw(), location.getPitch()
);
}
public static World toWorld(final LocalWorld world) {
return ((BukkitWorld) world).getWorld();
}
public static BukkitEntity toLocalEntity(Entity e) {
switch (e.getType()) {
case EXPERIENCE_ORB:
return new BukkitExpOrb(toLocation(e.getLocation()), e.getUniqueId(), ((ExperienceOrb)e).getExperience());
case PAINTING:
Painting paint = (Painting) e;
return new BukkitPainting(toLocation(e.getLocation()), paint.getArt(), paint.getFacing(), e.getUniqueId());
case DROPPED_ITEM:
return new BukkitItem(toLocation(e.getLocation()), ((Item)e).getItemStack(), e.getUniqueId());
default:
return new BukkitEntity(toLocation(e.getLocation()), e.getType(), e.getUniqueId());
}
}
public static BaseBlock toBlock(LocalWorld world, ItemStack itemStack) throws WorldEditException {
final int typeId = itemStack.getTypeId();
switch (typeId) {
case ItemID.INK_SACK:
final Dye materialData = (Dye) itemStack.getData();
if (materialData.getColor() == DyeColor.BROWN) {
return new BaseBlock(BlockID.COCOA_PLANT, -1);
}
break;
case ItemID.HEAD:
return new SkullBlock(0, (byte) itemStack.getDurability());
default:
final BaseBlock baseBlock = BlockType.getBlockForItem(typeId, itemStack.getDurability());
if (baseBlock != null) {
return baseBlock;
}
break;
}
if (world.isValidBlockType(typeId)) {
return new BaseBlock(typeId, -1);
}
throw new NotABlockException(typeId);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,49 +0,0 @@
/*
* WorldEdit
* Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.LocalSession;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import java.nio.charset.Charset;
/**
* Handles incoming WorldEditCui init message
* @author zml2008
*/
public class CUIChannelListener implements PluginMessageListener {
public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8");
private final WorldEditPlugin plugin;
public CUIChannelListener(WorldEditPlugin plugin) {
this.plugin = plugin;
}
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
LocalSession session = plugin.getSession(player);
if (session.hasCUISupport()) { // Already initialized
return;
}
String text = new String(message, UTF_8_CHARSET);
session.handleCUIInitializationMessage(text);
}
}

View File

@ -1,436 +0,0 @@
package com.sk89q.worldedit.bukkit;
// $Id$
/*
* This file is a part of WorldEdit.
* Copyright (c) sk89q <http://www.sk89q.com>
* Copyright (c) the WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
import com.sk89q.jnbt.*;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.TileEntityBlock;
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.foundation.Block;
import net.minecraft.server.v1_7_R2.*;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_7_R2.CraftWorld;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
import java.util.logging.Logger;
/**
* A blind handler of blocks with TileEntity data that directly access Minecraft's
* classes through CraftBukkit.
* </p>
* Usage of this class may break terribly in the future, and therefore usage should
* be trapped in a handler for {@link Throwable}.
*/
public class DefaultNmsBlock extends NmsBlock {
private static final Logger logger = WorldEdit.logger;
private static Field compoundMapField;
private static final Field nmsBlock_isTileEntityField; // The field is deobfuscated but the method isn't. No idea why.
private NBTTagCompound nbtData = null;
static {
Field field;
try {
field = net.minecraft.server.v1_7_R2.Block.class.getDeclaredField("isTileEntity");
field.setAccessible(true);
} catch (NoSuchFieldException e) {
// logger.severe("Could not find NMS block tile entity field!");
field = null;
}
nmsBlock_isTileEntityField = field;
}
public static boolean verify() {
return nmsBlock_isTileEntityField != null;
}
/**
* Create a new instance with a given type ID, data value, and previous
* {@link TileEntityBlock}-implementing object.
*
* @param type block type ID
* @param data data value
* @param tileEntityBlock tile entity block
*/
public DefaultNmsBlock(int type, int data, TileEntityBlock tileEntityBlock) {
super(type, data);
nbtData = (NBTTagCompound) fromNative(tileEntityBlock.getNbtData());
}
/**
* Create a new instance with a given type ID, data value, and raw
* {@link NBTTagCompound} copy.
*
* @param type block type ID
* @param data data value
* @param nbtData raw NBT data
*/
public DefaultNmsBlock(int type, int data, NBTTagCompound nbtData) {
super(type, data);
this.nbtData = nbtData;
}
/**
* Build a {@link NBTTagCompound} that has valid coordinates.
*
* @param pt coordinates to set
* @return the tag compound
*/
private NBTTagCompound getNmsData(Vector pt) {
if (nbtData == null) {
return null;
}
nbtData.set("x", new NBTTagInt(pt.getBlockX()));
nbtData.set("y", new NBTTagInt(pt.getBlockY()));
nbtData.set("z", new NBTTagInt(pt.getBlockZ()));
return nbtData;
}
@Override
public boolean hasNbtData() {
return nbtData != null;
}
@Override
public String getNbtId() {
if (nbtData == null) {
return "";
}
return nbtData.getString("id");
}
@Override
public CompoundTag getNbtData() {
if (nbtData == null) {
return new CompoundTag(getNbtId(),
new HashMap<String, Tag>());
}
return (CompoundTag) toNative(nbtData);
}
@Override
public void setNbtData(CompoundTag tag) throws DataException {
if (tag == null) {
this.nbtData = null;
}
this.nbtData = (NBTTagCompound) fromNative(tag);
}
/**
* Build an instance from the given information.
*
* @param world world to get the block from
* @param position position to get the block at
* @param type type ID of block
* @param data data value of block
* @return the block, or null
*/
public static DefaultNmsBlock get(World world, Vector position, int type, int data) {
if (!hasTileEntity(type)) {
return null;
}
TileEntity te = ((CraftWorld) world).getHandle().getTileEntity(
position.getBlockX(), position.getBlockY(), position.getBlockZ());
if (te != null) {
NBTTagCompound tag = new NBTTagCompound();
te.b(tag); // Load data
return new DefaultNmsBlock(type, data, tag);
}
return null;
}
/**
* Set an instance or a {@link TileEntityBlock} to the given position.
*
* @param world world to set the block in
* @param position position to set the block at
* @param block the block to set
* @return true if tile entity data was copied to the world
*/
public static boolean set(World world, Vector position, BaseBlock block) {
NBTTagCompound data = null;
if (!hasTileEntity(world.getBlockTypeIdAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()))) {
return false;
}
if (block instanceof DefaultNmsBlock) {
DefaultNmsBlock nmsProxyBlock = (DefaultNmsBlock) block;
data = nmsProxyBlock.getNmsData(position);
} else if (block instanceof TileEntityBlock) {
DefaultNmsBlock nmsProxyBlock = new DefaultNmsBlock(
block.getId(), block.getData(), block);
data = nmsProxyBlock.getNmsData(position);
}
if (data != null) {
TileEntity te = ((CraftWorld) world).getHandle().getTileEntity(
position.getBlockX(), position.getBlockY(), position.getBlockZ());
if (te != null) {
te.a(data); // Load data
return true;
}
}
return false;
}
/**
* Tries to set a block 'safely', as in setting the block data to the location, and
* then triggering physics only at the end.
*
* @param world world to set the block in
* @param position position to set the block at
* @param block the block to set
* @param notifyAdjacent true to notify physics and what not
* @return true if block id or data was changed
*/
public static boolean setSafely(BukkitWorld world, Vector position,
Block block, boolean notifyAdjacent) {
int x = position.getBlockX();
int y = position.getBlockY();
int z = position.getBlockZ();
CraftWorld craftWorld = ((CraftWorld) world.getWorld());
// TileEntity te = craftWorld.getHandle().getTileEntity(x, y, z);
// craftWorld.getHandle().tileEntityList.remove(te);
boolean changed = craftWorld.getHandle().setTypeAndData(x, y, z, getNmsBlock(block.getId()), block.getData(), 0);
if (block instanceof BaseBlock) {
world.copyToWorld(position, (BaseBlock) block);
}
changed = craftWorld.getHandle().setData(x, y, z, block.getData(), 0) || changed;
if (changed && notifyAdjacent) {
craftWorld.getHandle().notify(x, y, z);
craftWorld.getHandle().update(x, y, z, getNmsBlock(block.getId()));
}
return changed;
}
public static boolean hasTileEntity(int type) {
net.minecraft.server.v1_7_R2.Block nmsBlock = getNmsBlock(type);
if (nmsBlock == null) {
return false;
}
try {
return nmsBlock_isTileEntityField.getBoolean(nmsBlock); // Once we have the field stord, gets are fast
} catch (IllegalAccessException e) {
return false;
}
}
public static net.minecraft.server.v1_7_R2.Block getNmsBlock(int type) {
return net.minecraft.server.v1_7_R2.Block.e(type);
}
/**
* Converts from a non-native NMS NBT structure to a native WorldEdit NBT
* structure.
*
* @param foreign non-native NMS NBT structure
* @return native WorldEdit NBT structure
*/
private static Tag toNative(NBTBase foreign) {
// temporary fix since mojang removed names from tags
// our nbt spec will need to be updated to theirs
return toNative(NBTBase.getTagName(foreign.getTypeId()), foreign);
}
/**
* Converts from a non-native NMS NBT structure to a native WorldEdit NBT
* structure.
*
* @param foreign non-native NMS NBT structure
* @param name name for the tag, if it has one
* @return native WorldEdit NBT structure
*/
@SuppressWarnings("unchecked")
private static Tag toNative(String name, NBTBase foreign) {
if (foreign == null) {
return null;
}
if (foreign instanceof NBTTagCompound) {
Map<String, Tag> values = new HashMap<String, Tag>();
Collection<Object> foreignKeys = null;
if (compoundMapField == null) {
try {
// Method name may change!
foreignKeys = ((NBTTagCompound) foreign).c();
} catch (Throwable t) {
try {
logger.warning("WorldEdit: Couldn't get NBTTagCompound.c(), " +
"so we're going to try to get at the 'map' field directly from now on");
if (compoundMapField == null) {
compoundMapField = NBTTagCompound.class.getDeclaredField("map");
compoundMapField.setAccessible(true);
}
} catch (Throwable e) {
// Can't do much beyond this
throw new RuntimeException(e);
}
}
}
if (compoundMapField != null) {
try {
foreignKeys = ((HashMap<Object, Object>) compoundMapField.get(foreign)).keySet();
} catch (Throwable e) {
// Can't do much beyond this
throw new RuntimeException(e);
}
}
for (Object obj : foreignKeys) {
String key = (String) obj;
NBTBase base = (NBTBase) ((NBTTagCompound) foreign).get(key);
values.put(key, toNative(key, base));
}
return new CompoundTag(name, values);
} else if (foreign instanceof NBTTagByte) {
return new ByteTag(name, ((NBTTagByte) foreign).f()); // getByte
} else if (foreign instanceof NBTTagByteArray) {
return new ByteArrayTag(name,
((NBTTagByteArray) foreign).c()); // data
} else if (foreign instanceof NBTTagDouble) {
return new DoubleTag(name,
((NBTTagDouble) foreign).g()); // getDouble
} else if (foreign instanceof NBTTagFloat) {
return new FloatTag(name, ((NBTTagFloat) foreign).h()); // getFloat
} else if (foreign instanceof NBTTagInt) {
return new IntTag(name, ((NBTTagInt) foreign).d()); // getInt
} else if (foreign instanceof NBTTagIntArray) {
return new IntArrayTag(name,
((NBTTagIntArray) foreign).c()); // data
} else if (foreign instanceof NBTTagList) {
try {
return transmorgifyList(name, (NBTTagList) foreign);
} catch (NoSuchFieldException e) {
} catch (SecurityException e) {
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {}
return new ListTag(name, ByteTag.class, new ArrayList<ByteTag>());
} else if (foreign instanceof NBTTagLong) {
return new LongTag(name, ((NBTTagLong) foreign).c()); // getLong
} else if (foreign instanceof NBTTagShort) {
return new ShortTag(name, ((NBTTagShort) foreign).e()); // getShort
} else if (foreign instanceof NBTTagString) {
return new StringTag(name,
((NBTTagString) foreign).a_()); // data
} else if (foreign instanceof NBTTagEnd) {
return new EndTag();
} else {
throw new IllegalArgumentException("Don't know how to make native "
+ foreign.getClass().getCanonicalName());
}
}
private static ListTag transmorgifyList(String name, NBTTagList foreign)
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
List<Tag> values = new ArrayList<Tag>();
int type = foreign.d();
Field listField = NBTTagList.class.getDeclaredField("list");
listField.setAccessible(true);
List foreignList;
foreignList = (List) listField.get(foreign);
for (int i = 0; i < foreign.size(); i++) {
NBTBase element = (NBTBase) foreignList.get(i);
values.add(toNative(null, element)); // list elements shouldn't have names
}
Class<? extends Tag> cls = NBTConstants.getClassFromType(type);
return new ListTag(name, cls, values);
}
/**
* Converts a WorldEdit-native NBT structure to a NMS structure.
*
* @param foreign structure to convert
* @return non-native structure
*/
private static NBTBase fromNative(Tag foreign) {
if (foreign == null) {
return null;
}
if (foreign instanceof CompoundTag) {
NBTTagCompound tag = new NBTTagCompound();
for (Map.Entry<String, Tag> entry : ((CompoundTag) foreign)
.getValue().entrySet()) {
tag.set(entry.getKey(), fromNative(entry.getValue()));
}
return tag;
} else if (foreign instanceof ByteTag) {
return new NBTTagByte(((ByteTag) foreign).getValue());
} else if (foreign instanceof ByteArrayTag) {
return new NBTTagByteArray(((ByteArrayTag) foreign).getValue());
} else if (foreign instanceof DoubleTag) {
return new NBTTagDouble(((DoubleTag) foreign).getValue());
} else if (foreign instanceof FloatTag) {
return new NBTTagFloat(((FloatTag) foreign).getValue());
} else if (foreign instanceof IntTag) {
return new NBTTagInt(((IntTag) foreign).getValue());
} else if (foreign instanceof IntArrayTag) {
return new NBTTagIntArray(((IntArrayTag) foreign).getValue());
} else if (foreign instanceof ListTag) {
NBTTagList tag = new NBTTagList();
ListTag foreignList = (ListTag) foreign;
for (Tag t : foreignList.getValue()) {
tag.add(fromNative(t));
}
return tag;
} else if (foreign instanceof LongTag) {
return new NBTTagLong(((LongTag) foreign).getValue());
} else if (foreign instanceof ShortTag) {
return new NBTTagShort(((ShortTag) foreign).getValue());
} else if (foreign instanceof StringTag) {
return new NBTTagString(((StringTag) foreign).getValue());
} else if (foreign instanceof EndTag) {
try {
Method tagMaker = NBTBase.class.getDeclaredMethod("createTag", byte.class);
tagMaker.setAccessible(true);
return (NBTBase) tagMaker.invoke(null, (byte) 0);
} catch (Exception e) {
return null;
}
} else {
throw new IllegalArgumentException("Don't know how to make NMS "
+ foreign.getClass().getCanonicalName());
}
}
public static boolean isValidBlockType(int type) throws NoClassDefFoundError {
return type == 0 || (type >= 1 && net.minecraft.server.v1_7_R2.Block.e(type) != null);
}
}

View File

@ -1,76 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.blocks.BlockID;
import org.bukkit.BlockChangeDelegate;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* Proxy class to catch calls to set blocks.
*
* @author sk89q
*/
public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
private EditSession editSession;
public EditSessionBlockChangeDelegate(EditSession editSession) {
this.editSession = editSession;
}
public boolean setRawTypeId(int x, int y, int z, int typeId) {
try {
return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId));
} catch (MaxChangedBlocksException ex) {
return false;
}
}
public boolean setRawTypeIdAndData(int x, int y, int z, int typeId, int data) {
try {
return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId, data));
} catch (MaxChangedBlocksException ex) {
return false;
}
}
public boolean setTypeId(int x, int y, int z, int typeId) {
return setRawTypeId(x, y, z, typeId);
}
public boolean setTypeIdAndData(int x, int y, int z, int typeId, int data) {
return setRawTypeIdAndData(x, y, z, typeId, data);
}
public int getTypeId(int x, int y, int z) {
return editSession.getBlockType(new Vector(x, y, z));
}
public int getHeight() {
return editSession.getWorld().getMaxY() + 1;
}
public boolean isEmpty(int x, int y, int z) {
return editSession.getBlockType(new Vector(x, y, z)) == BlockID.AIR;
}
}

View File

@ -1,42 +0,0 @@
package com.sk89q.worldedit.bukkit;
import org.bukkit.World;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.foundation.Block;
public abstract class NmsBlock extends BaseBlock {
protected NmsBlock(int type) {
super(type);
}
protected NmsBlock(int type, int data) {
super(type, data);
}
public static boolean verify() {
return false;
}
public static NmsBlock get(World world, Vector vector, int type, int data) {
return null;
}
public static boolean set(World world, Vector vector, Block block) {
return false;
}
public static boolean setSafely(World world, Vector vector, Block block, boolean notify) {
return false;
}
public static boolean hasTileEntity(int type) {
return false;
}
public static boolean isValidBlockType(int type) {
return false;
}
}

View File

@ -1,51 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.SessionCheck;
import com.sk89q.worldedit.WorldEdit;
/**
* Used to remove expired sessions in Bukkit.
*
* @author sk89q
*/
public class SessionTimer implements Runnable {
private WorldEdit worldEdit;
private SessionCheck checker;
public SessionTimer(WorldEdit worldEdit, final Server server) {
this.worldEdit = worldEdit;
this.checker = new SessionCheck() {
public boolean isOnlinePlayer(String name) {
Player player = server.getPlayer(name);
return player != null && player.isOnline();
}
};
}
public void run() {
worldEdit.flushExpiredSessions(checker);
}
}

View File

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

View File

@ -1,178 +0,0 @@
/*
* WorldEdit
* Copyright (C) 2012 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// $Id$
package com.sk89q.worldedit.bukkit;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.event.Event.Result;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldVector;
/**
* Handles all events thrown in relation to a Player
*/
public class WorldEditListener implements Listener {
private WorldEditPlugin plugin;
private boolean ignoreLeftClickAir = false;
/**
* Called when a player plays an animation, such as an arm swing
*
* @param event Relevant event details
*/
/**
* Construct the object;
*
* @param plugin
*/
public WorldEditListener(WorldEditPlugin plugin) {
this.plugin = plugin;
}
/**
* Called when a player leaves a server
*
* @param event Relevant event details
*/
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
plugin.getWorldEdit().markExpire(plugin.wrapPlayer(event.getPlayer()));
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onGamemode(PlayerGameModeChangeEvent event) {
// this will automatically refresh their sesssion, we don't have to do anything
WorldEdit.getInstance().getSession(plugin.wrapPlayer(event.getPlayer()));
}
/**
* Called when a player attempts to use a command
*
* @param event Relevant event details
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
String[] split = event.getMessage().split(" ");
if (split.length > 0) {
split = plugin.getWorldEdit().commandDetection(split);
split[0] = "/" + split[0];
}
final String newMessage = StringUtil.joinString(split, " ");
if (!newMessage.equals(event.getMessage())) {
event.setMessage(newMessage);
plugin.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
if (event.getMessage().length() > 0) {
plugin.getServer().dispatchCommand(event.getPlayer(),
event.getMessage().substring(1));
}
event.setCancelled(true);
}
}
}
/**
* Called when a player interacts
*
* @param event Relevant event details
*/
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.useItemInHand() == Result.DENY) {
return;
}
final LocalPlayer player = plugin.wrapPlayer(event.getPlayer());
final LocalWorld world = player.getWorld();
final WorldEdit we = plugin.getWorldEdit();
Action action = event.getAction();
if (action == Action.LEFT_CLICK_BLOCK) {
final Block clickedBlock = event.getClickedBlock();
final WorldVector pos = new WorldVector(world, clickedBlock.getX(),
clickedBlock.getY(), clickedBlock.getZ());
if (we.handleBlockLeftClick(player, pos)) {
event.setCancelled(true);
}
if (we.handleArmSwing(player)) {
event.setCancelled(true);
}
if (!ignoreLeftClickAir) {
final int taskId = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
ignoreLeftClickAir = false;
}
}, 2);
if (taskId != -1) {
ignoreLeftClickAir = true;
}
}
} else if (action == Action.LEFT_CLICK_AIR) {
if (ignoreLeftClickAir) {
return;
}
if (we.handleArmSwing(player)) {
event.setCancelled(true);
}
} else if (action == Action.RIGHT_CLICK_BLOCK) {
final Block clickedBlock = event.getClickedBlock();
final WorldVector pos = new WorldVector(world, clickedBlock.getX(),
clickedBlock.getY(), clickedBlock.getZ());
if (we.handleBlockRightClick(player, pos)) {
event.setCancelled(true);
}
if (we.handleRightClick(player)) {
event.setCancelled(true);
}
} else if (action == Action.RIGHT_CLICK_AIR) {
if (we.handleRightClick(player)) {
event.setCancelled(true);
}
}
}
}

View File

@ -1,430 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Handler;
import java.util.zip.ZipEntry;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.wepif.PermissionsResolverManager;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditOperation;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Polygonal2DRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
/**
* Plugin for Bukkit.
*
* @author sk89q
*/
public class WorldEditPlugin extends JavaPlugin {
/**
* The name of the CUI's plugin channel registration
*/
public static final String CUI_PLUGIN_CHANNEL = "WECUI";
/**
* The server interface that all server-related API goes through.
*/
private BukkitServerInterface server;
/**
* Main WorldEdit instance.
*/
private WorldEdit controller;
/**
* Deprecated API.
*/
private WorldEditAPI api;
/**
* Holds the configuration for WorldEdit.
*/
private BukkitConfiguration config;
/**
* Called on plugin enable.
*/
@Override
public void onEnable() {
final String pluginYmlVersion = getDescription().getVersion();
final String manifestVersion = WorldEdit.getVersion();
if (!manifestVersion.equalsIgnoreCase(pluginYmlVersion)) {
WorldEdit.setVersion(manifestVersion + " (" + pluginYmlVersion + ")");
}
// Make the data folders that WorldEdit uses
getDataFolder().mkdirs();
File targetDir = new File(getDataFolder() + File.separator + "nmsblocks");
targetDir.mkdir();
copyNmsBlockClasses(targetDir);
// Create the default configuration file
createDefaultConfiguration("config.yml");
// Set up configuration and such, including the permissions
// resolver
config = new BukkitConfiguration(new YAMLProcessor(new File(getDataFolder(), "config.yml"), true), this);
PermissionsResolverManager.initialize(this);
// Load the configuration
config.load();
// Setup interfaces
server = new BukkitServerInterface(this, getServer());
controller = new WorldEdit(server, config);
WorldEdit.logger.setParent(Bukkit.getLogger());
api = new WorldEditAPI(this);
getServer().getMessenger().registerIncomingPluginChannel(this, CUI_PLUGIN_CHANNEL, new CUIChannelListener(this));
getServer().getMessenger().registerOutgoingPluginChannel(this, CUI_PLUGIN_CHANNEL);
// Now we can register events!
getServer().getPluginManager().registerEvents(new WorldEditListener(this), this);
getServer().getScheduler().runTaskTimerAsynchronously(this,
new SessionTimer(controller, getServer()), 120, 120);
}
private void copyNmsBlockClasses(File target) {
try {
JarFile jar = new JarFile(getFile());
@SuppressWarnings("rawtypes")
Enumeration entries = jar.entries();
while (entries.hasMoreElements()) {
JarEntry jarEntry = (JarEntry) entries.nextElement();
if (!jarEntry.getName().startsWith("nmsblocks") || jarEntry.isDirectory()) continue;
File file = new File(target + File.separator + jarEntry.getName().replace("nmsblocks", ""));
if (file.exists()) continue;
InputStream is = jar.getInputStream(jarEntry);
FileOutputStream fos = new FileOutputStream(file);
fos = new FileOutputStream(file);
byte[] buf = new byte[8192];
int length = 0;
while ((length = is.read(buf)) > 0) {
fos.write(buf, 0, length);
}
fos.close();
is.close();
}
} catch (Throwable e) {}
}
/**
* Called on plugin disable.
*/
@Override
public void onDisable() {
controller.clearSessions();
for (Handler h : controller.commandLogger.getHandlers()) {
h.close();
}
config.unload();
server.unregisterCommands();
this.getServer().getScheduler().cancelTasks(this);
}
/**
* Loads and reloads all configuration.
*/
protected void loadConfiguration() {
config.unload();
config.load();
getPermissionsResolver().load();
}
/**
* Create a default configuration file from the .jar.
*
* @param name
*/
protected void createDefaultConfiguration(String name) {
File actual = new File(getDataFolder(), name);
if (!actual.exists()) {
InputStream input =
null;
try {
JarFile file = new JarFile(getFile());
ZipEntry copy = file.getEntry("defaults/" + name);
if (copy == null) throw new FileNotFoundException();
input = file.getInputStream(copy);
} catch (IOException e) {
getLogger().severe("Unable to read default configuration: " + name);
}
if (input != null) {
FileOutputStream output = null;
try {
output = new FileOutputStream(actual);
byte[] buf = new byte[8192];
int length = 0;
while ((length = input.read(buf)) > 0) {
output.write(buf, 0, length);
}
getLogger().info("Default configuration file written: " + name);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (input != null) {
input.close();
}
} catch (IOException e) {}
try {
if (output != null) {
output.close();
}
} catch (IOException e) {}
}
}
}
}
/**
* Called on WorldEdit command.
*/
@Override
public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd,
String commandLabel, String[] args) {
// Add the command to the array because the underlying command handling
// code of WorldEdit expects it
String[] split = new String[args.length + 1];
System.arraycopy(args, 0, split, 1, args.length);
split[0] = "/" + cmd.getName();
controller.handleCommand(wrapCommandSender(sender), split);
return true;
}
/**
* Gets the session for the player.
*
* @param player
* @return
*/
public LocalSession getSession(Player player) {
return controller.getSession(wrapPlayer(player));
}
/**
* Gets the session for the player.
*
* @param player
* @return
*/
public EditSession createEditSession(Player player) {
LocalPlayer wePlayer = wrapPlayer(player);
LocalSession session = controller.getSession(wePlayer);
BlockBag blockBag = session.getBlockBag(wePlayer);
EditSession editSession = controller.getEditSessionFactory()
.getEditSession(wePlayer.getWorld(), session.getBlockChangeLimit(), blockBag, wePlayer);
editSession.enableQueue();
return editSession;
}
/**
* Remember an edit session.
*
* @param player
* @param editSession
*/
public void remember(Player player, EditSession editSession) {
LocalPlayer wePlayer = wrapPlayer(player);
LocalSession session = controller.getSession(wePlayer);
session.remember(editSession);
editSession.flushQueue();
controller.flushBlockBag(wePlayer, editSession);
}
/**
* Wrap an operation into an EditSession.
*
* @param player
* @param op
* @throws Throwable
*/
public void perform(Player player, WorldEditOperation op)
throws Throwable {
LocalPlayer wePlayer = wrapPlayer(player);
LocalSession session = controller.getSession(wePlayer);
EditSession editSession = createEditSession(player);
try {
op.run(session, wePlayer, editSession);
} finally {
remember(player, editSession);
}
}
/**
* Get the API.
*
* @return
*/
@Deprecated
public WorldEditAPI getAPI() {
return api;
}
/**
* Returns the configuration used by WorldEdit.
*
* @return
*/
public BukkitConfiguration getLocalConfiguration() {
return config;
}
/**
* Get the permissions resolver in use.
*
* @return
*/
public PermissionsResolverManager getPermissionsResolver() {
return PermissionsResolverManager.getInstance();
}
/**
* Used to wrap a Bukkit Player as a LocalPlayer.
*
* @param player
* @return
*/
public BukkitPlayer wrapPlayer(Player player) {
return new BukkitPlayer(this, this.server, player);
}
public LocalPlayer wrapCommandSender(CommandSender sender) {
if (sender instanceof Player) {
return wrapPlayer((Player) sender);
}
return new BukkitCommandSender(this, this.server, sender);
}
/**
* Get the server interface.
*
* @return
*/
public ServerInterface getServerInterface() {
return server;
}
/**
* Get WorldEdit.
*
* @return
*/
public WorldEdit getWorldEdit() {
return controller;
}
/**
* Gets the region selection for the player.
*
* @param player
* @return the selection or null if there was none
*/
public Selection getSelection(Player player) {
if (player == null) {
throw new IllegalArgumentException("Null player not allowed");
}
if (!player.isOnline()) {
throw new IllegalArgumentException("Offline player not allowed");
}
LocalSession session = controller.getSession(wrapPlayer(player));
RegionSelector selector = session.getRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()));
try {
Region region = selector.getRegion();
World world = ((BukkitWorld) session.getSelectionWorld()).getWorld();
if (region instanceof CuboidRegion) {
return new CuboidSelection(world, selector, (CuboidRegion) region);
} else if (region instanceof Polygonal2DRegion) {
return new Polygonal2DSelection(world, selector, (Polygonal2DRegion) region);
} else {
return null;
}
} catch (IncompleteRegionException e) {
return null;
}
}
/**
* Sets the region selection for a player.
*
* @param player
* @param selection
*/
public void setSelection(Player player, Selection selection) {
if (player == null) {
throw new IllegalArgumentException("Null player not allowed");
}
if (!player.isOnline()) {
throw new IllegalArgumentException("Offline player not allowed");
}
if (selection == null) {
throw new IllegalArgumentException("Null selection not allowed");
}
LocalSession session = controller.getSession(wrapPlayer(player));
RegionSelector sel = selection.getRegionSelector();
session.setRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()), sel);
session.dispatchCUISelection(wrapPlayer(player));
}
}

View File

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

View File

@ -1,104 +0,0 @@
/*
* WorldEdit
* Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <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;
/**
* @author zml2008
*/
public class BukkitPainting extends BukkitEntity {
private static int spawnTask = -1;
private static final Deque<QueuedPaintingSpawn> spawnQueue = new ArrayDeque<QueuedPaintingSpawn>();
private class QueuedPaintingSpawn {
private final Location weLoc;
public 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) {
t.printStackTrace();
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
*/
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,67 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <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.bukkit.BukkitUtil;
import com.sk89q.worldedit.regions.*;
public class CuboidSelection extends RegionSelection {
protected CuboidRegion cuboid;
public CuboidSelection(World world, Location pt1, Location pt2) {
this(world, BukkitUtil.toVector(pt1), BukkitUtil.toVector(pt2));
}
public CuboidSelection(World world, Vector pt1, Vector pt2) {
super(world);
// Validate input
if (pt1 == null) {
throw new IllegalArgumentException("Null point 1 not permitted");
}
if (pt2 == null) {
throw new IllegalArgumentException("Null point 2 not permitted");
}
// Create new selector
CuboidRegionSelector sel = new CuboidRegionSelector(BukkitUtil.getLocalWorld(world));
// set up selector
sel.selectPrimary(pt1);
sel.selectSecondary(pt2);
// set up CuboidSelection
cuboid = sel.getIncompleteRegion();
// set up RegionSelection
setRegionSelector(sel);
setRegion(cuboid);
}
public CuboidSelection(World world, RegionSelector sel, CuboidRegion region) {
super(world, sel, region);
this.cuboid = region;
}
}

View File

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

View File

@ -1,105 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <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;
public interface Selection {
/**
* Get the lower point of a region.
*
* @return min. point
*/
public Location getMinimumPoint();
/**
* Get the lower point of a region.
*
* @return min. point
*/
public Vector getNativeMinimumPoint();
/**
* Get the upper point of a region.
*
* @return max. point
*/
public Location getMaximumPoint();
/**
* Get the upper point of a region.
*
* @return max. point
*/
public Vector getNativeMaximumPoint();
/**
* Get the region selector. This is for internal use.
*
* @return
*/
public RegionSelector getRegionSelector();
/**
* Get the world.
*
* @return
*/
public World getWorld();
/**
* Get the number of blocks in the region.
*
* @return number of blocks
*/
public int getArea();
/**
* Get X-size.
*
* @return width
*/
public int getWidth();
/**
* Get Y-size.
*
* @return height
*/
public int getHeight();
/**
* Get Z-size.
*
* @return length
*/
public int getLength();
/**
* Returns true based on whether the region contains the point,
*
* @param pt
* @return
*/
public boolean contains(Location pt);
}

View File

@ -1,16 +0,0 @@
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,31 +0,0 @@
package com.sk89q.worldedit.masks;
import java.util.HashSet;
import java.util.Set;
import com.sk89q.worldedit.BiomeType;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
public class BiomeTypeMask extends AbstractMask {
private final Set<BiomeType> biomes;
public BiomeTypeMask() {
this(new HashSet<BiomeType>());
}
public BiomeTypeMask(Set<BiomeType> biomes) {
this.biomes = biomes;
}
public boolean matches2D(EditSession editSession, Vector2D pos) {
BiomeType biome = editSession.getWorld().getBiome(pos);
return biomes.contains(biome);
}
@Override
public boolean matches(EditSession editSession, Vector pos) {
return matches2D(editSession, pos.toVector2D());
}
}

View File

@ -1,54 +0,0 @@
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 pos) {
BaseBlock block = editSession.getBlock(pos);
return blocks.contains(block)
|| blocks.contains(new BaseBlock(block.getType(), -1));
}
}

View File

@ -1,52 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.masks;
import java.util.Set;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* A filter that matches blocks based on block types.
*
* @deprecated replaced by {@link #BlockMask}
* @author sk89q
*/
@Deprecated
public class BlockTypeMask extends BlockMask {
public BlockTypeMask() {
super();
}
public BlockTypeMask(Set<Integer> types) {
super();
for (int type : types) {
add(type);
}
}
public BlockTypeMask(int type) {
this();
add(type);
}
public void add(int type) {
add(new BaseBlock(type));
}
}

View File

@ -1,84 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <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 pos) {
for (Mask mask : masks) {
if (!mask.matches(editSession, pos)) {
return false;
}
}
return true;
}
}

View File

@ -1,26 +0,0 @@
package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.Region;
public class DynamicRegionMask extends AbstractMask {
private Region region;
@Override
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
try {
region = session.getSelection(player.getWorld());
} catch (IncompleteRegionException exc) {
region = null;
}
}
@Override
public boolean matches(EditSession editSession, Vector pos) {
return region == null || region.contains(pos);
}
}

View File

@ -1,35 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <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 pos) {
return editSession.getBlockType(pos) != 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 General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <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.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>();
for (BaseBlock b : block) {
filter.add(b);
}
this.filter = filter;
}
@Override
public boolean matches(EditSession editSession, Vector pos) {
BaseBlock compare = new BaseBlock(editSession.getBlockType(pos), editSession.getBlockData(pos));
return BaseBlock.containsFuzzy(filter, compare);
}
}

View File

@ -1,54 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.masks;
import java.util.Set;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
/**
* A block type mask that only matches blocks that are not in the list.
*
* @author sk89q
*/
@Deprecated
public class InvertedBlockTypeMask extends BlockTypeMask {
public InvertedBlockTypeMask() {
}
/**
* @param types
*/
public InvertedBlockTypeMask(Set<Integer> types) {
super(types);
}
/**
* @param type
*/
public InvertedBlockTypeMask(int type) {
super(type);
}
@Override
public boolean matches(EditSession editSession, Vector pos) {
return !super.matches(editSession, pos);
}
}

View File

@ -1,32 +0,0 @@
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.Masks;
/**
* @deprecated See {@link Masks#negate(com.sk89q.worldedit.function.mask.Mask)}
*/
@Deprecated
public class InvertedMask extends AbstractMask {
private final Mask mask;
public InvertedMask(Mask mask) {
this.mask = mask;
}
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
mask.prepare(session, player, target);
}
@Override
public boolean matches(EditSession editSession, Vector pos) {
return !mask.matches(editSession, pos);
}
public Mask getInvertedMask() {
return mask;
}
}

View File

@ -1,53 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <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
* @param player
* @param target target of the brush, null if not a brush mask
*/
void prepare(LocalSession session, LocalPlayer player, Vector target);
/**
* Given a block position, this method returns true if the block at
* that position matches the filter. Block information is not provided
* as getting a BaseBlock has unneeded overhead in most block querying
* situations (enumerating a chest's contents is a waste, for example).
*
* @param editSession
* @param pos
* @return
*/
boolean matches(EditSession editSession, Vector pos);
}

View File

@ -1,22 +0,0 @@
package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.function.mask.NoiseFilter;
/**
* @deprecated See {@link NoiseFilter}
*/
@Deprecated
public class RandomMask extends AbstractMask {
private final double ratio;
public RandomMask(double ratio) {
this.ratio = ratio;
}
@Override
public boolean matches(EditSession editSession, Vector pos) {
return Math.random() < ratio;
}
}

View File

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

View File

@ -1,16 +0,0 @@
package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockType;
/**
* @deprecated See {@link com.sk89q.worldedit.function.mask.SolidBlockMask}
*/
@Deprecated
public class SolidBlockMask extends AbstractMask {
@Override
public boolean matches(EditSession editSession, Vector pos) {
return !BlockType.canPassThrough(editSession.getBlockType(pos), editSession.getBlockData(pos));
}
}

View File

@ -1,73 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <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 java.util.Set;
/**
*
* @author 1337
*/
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 pos) {
return !mask.matches(editSession, pos) && mask.matches(editSession, pos.add(0, yMod, 0));
}
}

View File

@ -1,62 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.patterns;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* @deprecated Will be removed in the future -- there is no replacement
*/
@Deprecated
public class BlockChance {
/**
* Block.
*/
private BaseBlock block;
/**
* Chance. Can be any positive value.
*/
private double chance;
/**
* Construct the object.
*
* @param block
* @param chance
*/
public BlockChance(BaseBlock block, double chance) {
this.block = block;
this.chance = chance;
}
/**
* @return the block
*/
public BaseBlock getBlock() {
return block;
}
/**
* @return the chance
*/
public double getChance() {
return chance;
}
}

View File

@ -1,75 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.patterns;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* Pattern that repeats the clipboard.
*
* @author sk89q
*/
public class ClipboardPattern implements Pattern {
/**
* Clipboard.
*/
private CuboidClipboard clipboard;
/**
* Size of the clipboard.
*/
private Vector size;
/**
* Construct the object.
*
* @param clipboard
*/
public ClipboardPattern(CuboidClipboard clipboard) {
this.clipboard = clipboard;
this.size = clipboard.getSize();
}
/**
* Get next block.
*
* @param pos
* @return
*/
public BaseBlock next(Vector pos) {
return next(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
}
/**
* Get next block.
*
* @param x
* @param y
* @param z
* @return
*/
public BaseBlock next(int x, int y, int z) {
int xp = Math.abs(x) % size.getBlockX();
int yp = Math.abs(y) % size.getBlockY();
int zp = Math.abs(z) % size.getBlockZ();
return clipboard.getPoint(new Vector(xp, yp, zp));
}
}

View File

@ -1,47 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <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 pos
* @return
*/
public BaseBlock next(Vector pos);
/**
* Get a block for a position. This return value of this method does
* not have to be consistent for the same position.
*
* @param pos
* @return
*/
public BaseBlock next(int x, int y, int z);
}

View File

@ -1,90 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <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 {
/**
* Random number generator.
*/
private static final Random random = new Random();
/**
* Blocks and their proportions.
*/
private List<BlockChance> blocks;
/**
* Construct the object.
*
* @param 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;
}
/**
* Get next block.
*
* @param pos
* @return
*/
public BaseBlock next(Vector pos) {
double r = random.nextDouble();
for (BlockChance block : blocks) {
if (r <= block.getChance()) {
return block.getBlock();
}
}
throw new RuntimeException("ProportionalFillPattern");
}
public BaseBlock next(int x, int y, int z) {
return next(null);
}
}

View File

@ -1,67 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.patterns;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.function.pattern.BlockPattern;
/**
* @deprecated See {@link BlockPattern}
*/
@Deprecated
public class SingleBlockPattern implements Pattern {
/**
* Block type.
*/
private BaseBlock block;
/**
* Construct the object.
*
* @param block
*/
public SingleBlockPattern(BaseBlock block) {
this.block = block;
}
/**
* Get next block.
*
* @param pos
* @return
*/
public BaseBlock next(Vector pos) {
return block;
}
public BaseBlock next(int x, int y, int z) {
return block;
}
/**
* Get the block.
*
* @return
*/
public BaseBlock getBlock() {
return block;
}
}