Continue the great purge

This commit is contained in:
Matthew Miller
2018-06-16 15:29:48 +10:00
parent c537a2e948
commit 20bf6e079b
63 changed files with 313 additions and 2190 deletions

View File

@ -20,32 +20,31 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extension.platform.AbstractPlayerActor;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.world.World;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import javax.annotation.Nullable;
import java.util.UUID;
public class BukkitPlayer extends LocalPlayer {
import javax.annotation.Nullable;
public class BukkitPlayer extends AbstractPlayerActor {
private Player player;
private WorldEditPlugin plugin;
public BukkitPlayer(WorldEditPlugin plugin, ServerInterface server, Player player) {
public BukkitPlayer(WorldEditPlugin plugin, Player player) {
this.plugin = plugin;
this.player = player;
}
@ -73,9 +72,9 @@ public class BukkitPlayer extends LocalPlayer {
}
@Override
public WorldVector getPosition() {
public com.sk89q.worldedit.util.Location getPosition() {
Location loc = player.getLocation();
return new WorldVector(BukkitUtil.getLocalWorld(loc.getWorld()),
return new com.sk89q.worldedit.util.Location(BukkitUtil.getWorld(loc.getWorld()),
loc.getX(), loc.getY(), loc.getZ());
}
@ -146,8 +145,8 @@ public class BukkitPlayer extends LocalPlayer {
}
@Override
public LocalWorld getWorld() {
return BukkitUtil.getLocalWorld(player.getWorld());
public World getWorld() {
return BukkitUtil.getWorld(player.getWorld());
}
@Override

View File

@ -19,14 +19,17 @@
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;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.extent.inventory.BlockBagException;
import com.sk89q.worldedit.extent.inventory.OutOfBlocksException;
import com.sk89q.worldedit.extent.inventory.OutOfSpaceException;
import com.sk89q.worldedit.util.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class BukkitPlayerBlockBag extends BlockBag {
@ -191,11 +194,11 @@ public class BukkitPlayerBlockBag extends BlockBag {
}
@Override
public void addSourcePosition(WorldVector pos) {
public void addSourcePosition(Location pos) {
}
@Override
public void addSingleSourcePosition(WorldVector pos) {
public void addSingleSourcePosition(Location pos) {
}
}

View File

@ -22,8 +22,6 @@ package com.sk89q.worldedit.bukkit;
import com.sk89q.bukkit.util.CommandInfo;
import com.sk89q.bukkit.util.CommandRegistration;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
@ -38,14 +36,15 @@ import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
public class BukkitServerInterface extends ServerInterface implements MultiUserPlatform {
import javax.annotation.Nullable;
public class BukkitServerInterface implements MultiUserPlatform {
public Server server;
public WorldEditPlugin plugin;
private CommandRegistration dynamicCommands;
@ -86,12 +85,12 @@ public class BukkitServerInterface extends ServerInterface implements MultiUserP
}
@Override
public List<LocalWorld> getWorlds() {
public List<com.sk89q.worldedit.world.World> getWorlds() {
List<World> worlds = server.getWorlds();
List<LocalWorld> ret = new ArrayList<LocalWorld>(worlds.size());
List<com.sk89q.worldedit.world.World> ret = new ArrayList<>(worlds.size());
for (World world : worlds) {
ret.add(BukkitUtil.getLocalWorld(world));
ret.add(BukkitUtil.getWorld(world));
}
return ret;
@ -104,7 +103,7 @@ public class BukkitServerInterface extends ServerInterface implements MultiUserP
return player;
} else {
org.bukkit.entity.Player bukkitPlayer = server.getPlayerExact(player.getName());
return bukkitPlayer != null ? new BukkitPlayer(plugin, this, bukkitPlayer) : null;
return bukkitPlayer != null ? new BukkitPlayer(plugin, bukkitPlayer) : null;
}
}
@ -181,7 +180,7 @@ public class BukkitServerInterface extends ServerInterface implements MultiUserP
public Collection<Actor> getConnectedUsers() {
List<Actor> users = new ArrayList<Actor>();
for (org.bukkit.entity.Player player : Bukkit.getServer().getOnlinePlayers()) {
users.add(new BukkitPlayer(plugin, this, player));
users.add(new BukkitPlayer(plugin, player));
}
return users;
}

View File

@ -19,45 +19,34 @@
package com.sk89q.worldedit.bukkit;
import java.util.List;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.NotABlockException;
import com.sk89q.worldedit.Vector;
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 com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.util.Location;
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;
import java.util.List;
public final class BukkitUtil {
private BukkitUtil() {
}
public static LocalWorld getLocalWorld(World w) {
public static com.sk89q.worldedit.world.World getWorld(World w) {
return new BukkitWorld(w);
}
@ -69,17 +58,13 @@ public final class BukkitUtil {
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()),
getWorld(loc.getWorld()),
new Vector(loc.getX(), loc.getY(), loc.getZ()),
loc.getYaw(), loc.getPitch()
);
@ -89,10 +74,6 @@ public final class BukkitUtil {
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());
}
@ -116,14 +97,6 @@ public final class BukkitUtil {
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.
@ -139,33 +112,19 @@ public final class BukkitUtil {
public static final double EQUALS_PRECISION = 0.0001;
public static org.bukkit.Location toLocation(Location location) {
Vector pt = location.getPosition();
Vector pt = location.toVector();
return new org.bukkit.Location(
toWorld(location.getWorld()),
toWorld(location.getExtent()),
pt.getX(), pt.getY(), pt.getZ(),
location.getYaw(), location.getPitch()
);
}
public static World toWorld(final LocalWorld world) {
public static World toWorld(final Extent 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 {
public static BaseBlock toBlock(com.sk89q.worldedit.world.World world, ItemStack itemStack) throws WorldEditException {
final int typeId = itemStack.getTypeId();
switch (typeId) {

View File

@ -19,9 +19,10 @@
package com.sk89q.worldedit.bukkit;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEdit;
@ -33,6 +34,7 @@ import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.world.AbstractWorld;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.registry.WorldData;
import org.bukkit.Effect;
@ -48,7 +50,6 @@ import org.bukkit.inventory.DoubleChestInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.EnumMap;
@ -58,13 +59,13 @@ import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
public class BukkitWorld extends LocalWorld {
public class BukkitWorld extends AbstractWorld {
private static final Logger logger = WorldEdit.logger;
private static final Map<Integer, Effect> effects = new HashMap<Integer, Effect>();
private static final Map<Integer, Effect> effects = new HashMap<>();
static {
for (Effect effect : Effect.values()) {
effects.put(effect.getId(), effect);
@ -80,7 +81,7 @@ public class BukkitWorld extends LocalWorld {
*/
@SuppressWarnings("unchecked")
public BukkitWorld(World world) {
this.worldRef = new WeakReference<World>(world);
this.worldRef = new WeakReference<>(world);
}
@Override
@ -88,7 +89,7 @@ public class BukkitWorld extends LocalWorld {
World world = getWorld();
List<Entity> ents = world.getEntities();
List<com.sk89q.worldedit.entity.Entity> entities = new ArrayList<com.sk89q.worldedit.entity.Entity>();
List<com.sk89q.worldedit.entity.Entity> entities = new ArrayList<>();
for (Entity ent : ents) {
if (region.contains(BukkitUtil.toVector(ent.getLocation()))) {
entities.add(BukkitAdapter.adapt(ent));
@ -99,7 +100,7 @@ public class BukkitWorld extends LocalWorld {
@Override
public List<com.sk89q.worldedit.entity.Entity> getEntities() {
List<com.sk89q.worldedit.entity.Entity> list = new ArrayList<com.sk89q.worldedit.entity.Entity>();
List<com.sk89q.worldedit.entity.Entity> list = new ArrayList<>();
for (Entity entity : getWorld().getEntities()) {
list.add(BukkitAdapter.adapt(entity));
}
@ -282,7 +283,7 @@ public class BukkitWorld extends LocalWorld {
* An EnumMap that stores which WorldEdit TreeTypes apply to which Bukkit TreeTypes
*/
private static final EnumMap<TreeGenerator.TreeType, TreeType> treeTypeMapping =
new EnumMap<TreeGenerator.TreeType, TreeType>(TreeGenerator.TreeType.class);
new EnumMap<>(TreeGenerator.TreeType.class);
static {
for (TreeGenerator.TreeType type : TreeGenerator.TreeType.values()) {

View File

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

View File

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

View File

@ -19,16 +19,15 @@
package com.sk89q.worldedit.bukkit;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Joiner;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.wepif.PermissionsResolverManager;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditOperation;
import com.sk89q.worldedit.bukkit.adapter.AdapterLoadException;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplLoader;
@ -49,7 +48,6 @@ import com.sk89q.worldedit.regions.Polygonal2DRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.util.Java7Detector;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@ -57,7 +55,6 @@ import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import javax.annotation.Nullable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@ -69,12 +66,11 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
/**
* Plugin for Bukkit.
*/
@SuppressWarnings("deprecation")
public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
private static final Logger log = Logger.getLogger(WorldEditPlugin.class.getCanonicalName());
@ -83,7 +79,6 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
private BukkitImplAdapter bukkitAdapter;
private BukkitServerInterface server;
private final WorldEditAPI api = new WorldEditAPI(this);
private BukkitConfiguration config;
/**
@ -279,8 +274,8 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
* @return a session
*/
public EditSession createEditSession(Player player) {
LocalPlayer wePlayer = wrapPlayer(player);
LocalSession session = WorldEdit.getInstance().getSession(wePlayer);
com.sk89q.worldedit.entity.Player wePlayer = wrapPlayer(player);
LocalSession session = WorldEdit.getInstance().getSessionManager().get(wePlayer);
BlockBag blockBag = session.getBlockBag(wePlayer);
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory()
@ -297,8 +292,8 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
* @param editSession an edit session
*/
public void remember(Player player, EditSession editSession) {
LocalPlayer wePlayer = wrapPlayer(player);
LocalSession session = WorldEdit.getInstance().getSession(wePlayer);
com.sk89q.worldedit.entity.Player wePlayer = wrapPlayer(player);
LocalSession session = WorldEdit.getInstance().getSessionManager().get(wePlayer);
session.remember(editSession);
editSession.flushQueue();
@ -306,38 +301,6 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
WorldEdit.getInstance().flushBlockBag(wePlayer, editSession);
}
/**
* Wrap an operation into an EditSession.
*
* @param player a player
* @param op the operation
* @throws Throwable on any error
* @deprecated use the regular API
*/
@Deprecated
public void perform(Player player, WorldEditOperation op) throws Throwable {
LocalPlayer wePlayer = wrapPlayer(player);
LocalSession session = WorldEdit.getInstance().getSession(wePlayer);
EditSession editSession = createEditSession(player);
try {
op.run(session, wePlayer, editSession);
} finally {
remember(player, editSession);
}
}
/**
* Get the API.
*
* @return the API
* @deprecated use the regular API
*/
@Deprecated
public WorldEditAPI getAPI() {
return api;
}
/**
* Returns the configuration used by WorldEdit.
*
@ -357,13 +320,13 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
}
/**
* Used to wrap a Bukkit Player as a LocalPlayer.
* Used to wrap a Bukkit Player as a WorldEdit Player.
*
* @param player a player
* @return a wrapped player
*/
public BukkitPlayer wrapPlayer(Player player) {
return new BukkitPlayer(this, this.server, player);
return new BukkitPlayer(this, player);
}
public Actor wrapCommandSender(CommandSender sender) {
@ -374,15 +337,6 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
return new BukkitCommandSender(this, sender);
}
/**
* Get the server interface.
*
* @return the server interface
*/
public ServerInterface getServerInterface() {
return server;
}
BukkitServerInterface getInternalPlatform() {
return server;
}
@ -411,7 +365,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
}
LocalSession session = WorldEdit.getInstance().getSession(wrapPlayer(player));
RegionSelector selector = session.getRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()));
RegionSelector selector = session.getRegionSelector(BukkitUtil.getWorld(player.getWorld()));
try {
Region region = selector.getRegion();
@ -450,7 +404,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
LocalSession session = WorldEdit.getInstance().getSession(wrapPlayer(player));
RegionSelector sel = selection.getRegionSelector();
session.setRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()), sel);
session.setRegionSelector(BukkitUtil.getWorld(player.getWorld()), sel);
session.dispatchCUISelection(wrapPlayer(player));
}

View File

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

View File

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

View File

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

View File

@ -49,7 +49,7 @@ public class CuboidSelection extends RegionSelection {
}
// Create new selector
CuboidRegionSelector sel = new CuboidRegionSelector(BukkitUtil.getLocalWorld(world));
CuboidRegionSelector sel = new CuboidRegionSelector(BukkitUtil.getWorld(world));
// set up selector
sel.selectPrimary(pt1, PermissiveSelectorLimits.getInstance());

View File

@ -23,7 +23,6 @@ import com.sk89q.worldedit.regions.selector.CylinderRegionSelector;
import org.bukkit.World;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.regions.CylinderRegion;
import com.sk89q.worldedit.regions.RegionSelector;
@ -42,7 +41,7 @@ public class CylinderSelection extends RegionSelection {
public CylinderSelection(World world, BlockVector2D center, BlockVector2D radius, int minY, int maxY) {
super(world);
LocalWorld lWorld = BukkitUtil.getLocalWorld(world);
com.sk89q.worldedit.world.World lWorld = BukkitUtil.getWorld(world);
// Validate input
minY = Math.min(Math.max(0, minY), world.getMaxHeight());

View File

@ -22,7 +22,6 @@ package com.sk89q.worldedit.bukkit.selections;
import java.util.Collections;
import java.util.List;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector;
import org.bukkit.World;
import com.sk89q.worldedit.BlockVector2D;
@ -40,7 +39,7 @@ public class Polygonal2DSelection extends RegionSelection {
public Polygonal2DSelection(World world, List<BlockVector2D> points, int minY, int maxY) {
super(world);
LocalWorld lWorld = BukkitUtil.getLocalWorld(world);
com.sk89q.worldedit.world.World lWorld = BukkitUtil.getWorld(world);
// Validate input
minY = Math.min(Math.max(0, minY), world.getMaxHeight());