2014-04-27 04:57:45 +00:00
|
|
|
/*
|
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
|
|
|
*
|
2020-08-25 01:31:47 +00:00
|
|
|
* 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
|
2014-04-27 04:57:45 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2020-08-25 01:31:47 +00:00
|
|
|
* 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.
|
2014-04-27 04:57:45 +00:00
|
|
|
*
|
2020-08-25 01:31:47 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2014-04-27 04:57:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldedit.bukkit;
|
|
|
|
|
2021-07-24 15:34:05 +00:00
|
|
|
import com.fastasyncworldedit.bukkit.adapter.IBukkitAdapter;
|
|
|
|
import com.fastasyncworldedit.bukkit.adapter.SimpleBukkitAdapter;
|
2018-08-19 04:41:09 +00:00
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
2018-07-19 02:55:02 +00:00
|
|
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
2018-08-27 16:56:28 +00:00
|
|
|
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
2014-04-28 06:34:39 +00:00
|
|
|
import com.sk89q.worldedit.entity.Entity;
|
2018-07-19 02:55:02 +00:00
|
|
|
import com.sk89q.worldedit.extension.input.ParserContext;
|
2020-01-04 17:34:30 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.Actor;
|
2019-10-23 04:23:52 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.PlayerProxy;
|
2018-12-23 16:19:33 +00:00
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
|
|
|
import com.sk89q.worldedit.math.Vector3;
|
2021-07-14 12:40:20 +00:00
|
|
|
import com.sk89q.worldedit.util.Direction;
|
2014-04-27 04:57:45 +00:00
|
|
|
import com.sk89q.worldedit.util.Location;
|
|
|
|
import com.sk89q.worldedit.world.World;
|
2019-02-16 07:27:00 +00:00
|
|
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
2018-07-19 02:55:02 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BlockState;
|
|
|
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
|
|
|
import com.sk89q.worldedit.world.block.BlockType;
|
2018-08-13 12:29:48 +00:00
|
|
|
import com.sk89q.worldedit.world.entity.EntityType;
|
2018-07-22 05:36:50 +00:00
|
|
|
import com.sk89q.worldedit.world.gamemode.GameMode;
|
2018-07-19 02:55:02 +00:00
|
|
|
import com.sk89q.worldedit.world.item.ItemType;
|
2020-03-24 16:15:24 +00:00
|
|
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
|
|
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
2018-07-19 02:55:02 +00:00
|
|
|
import org.bukkit.Material;
|
2019-02-16 07:27:00 +00:00
|
|
|
import org.bukkit.block.Biome;
|
2021-07-14 12:40:20 +00:00
|
|
|
import org.bukkit.block.BlockFace;
|
2018-07-19 02:55:02 +00:00
|
|
|
import org.bukkit.block.data.BlockData;
|
2020-01-04 17:34:30 +00:00
|
|
|
import org.bukkit.command.CommandSender;
|
2018-08-03 13:01:56 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2018-07-19 02:55:02 +00:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2021-07-24 15:34:05 +00:00
|
|
|
|
2021-07-24 13:52:08 +00:00
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
import javax.annotation.Nullable;
|
2020-10-05 17:41:41 +00:00
|
|
|
import java.util.EnumMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2021-07-14 12:40:20 +00:00
|
|
|
import java.util.Objects;
|
2020-10-05 17:41:41 +00:00
|
|
|
|
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
|
|
|
|
2014-04-27 04:57:45 +00:00
|
|
|
/**
|
|
|
|
* Adapts between Bukkit and WorldEdit equivalent objects.
|
|
|
|
*/
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE start - enum-ized
|
2018-08-27 16:56:28 +00:00
|
|
|
public enum BukkitAdapter {
|
2019-06-06 22:39:51 +00:00
|
|
|
INSTANCE;
|
|
|
|
|
2018-08-27 16:56:28 +00:00
|
|
|
private final IBukkitAdapter adapter;
|
|
|
|
|
|
|
|
BukkitAdapter() {
|
|
|
|
BukkitImplAdapter tmp = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
2021-07-14 12:40:20 +00:00
|
|
|
this.adapter = Objects.requireNonNullElseGet(tmp, SimpleBukkitAdapter::new);
|
2018-08-27 16:56:28 +00:00
|
|
|
}
|
2018-07-19 02:55:02 +00:00
|
|
|
|
2021-07-14 12:40:20 +00:00
|
|
|
private static IBukkitAdapter getAdapter() {
|
2018-08-27 16:56:28 +00:00
|
|
|
return INSTANCE.adapter;
|
2018-07-19 02:55:02 +00:00
|
|
|
}
|
|
|
|
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE end
|
2021-07-14 12:40:20 +00:00
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
private static final ParserContext TO_BLOCK_CONTEXT = new ParserContext();
|
|
|
|
|
|
|
|
static {
|
|
|
|
TO_BLOCK_CONTEXT.setRestricted(false);
|
|
|
|
}
|
|
|
|
|
2019-06-06 22:39:51 +00:00
|
|
|
/**
|
2020-10-05 17:41:41 +00:00
|
|
|
* Checks equality between a WorldEdit BlockType and a Bukkit Material.
|
2019-06-06 22:39:51 +00:00
|
|
|
*
|
|
|
|
* @param blockType The WorldEdit BlockType
|
2021-07-24 15:34:05 +00:00
|
|
|
* @param type The Bukkit Material
|
2019-06-06 22:39:51 +00:00
|
|
|
* @return If they are equal
|
|
|
|
*/
|
2018-07-19 02:55:02 +00:00
|
|
|
public static boolean equals(BlockType blockType, Material type) {
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE start - swapped reference to getAdapter
|
2019-10-23 04:23:52 +00:00
|
|
|
return getAdapter().equals(blockType, type);
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE end
|
2018-07-19 02:55:02 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 22:39:51 +00:00
|
|
|
/**
|
|
|
|
* Convert any WorldEdit world into an equivalent wrapped Bukkit world.
|
|
|
|
*
|
|
|
|
* <p>If a matching world cannot be found, a {@link RuntimeException}
|
|
|
|
* will be thrown.</p>
|
|
|
|
*
|
|
|
|
* @param world the world
|
|
|
|
* @return a wrapped Bukkit world
|
|
|
|
*/
|
2014-07-26 00:29:36 +00:00
|
|
|
public static BukkitWorld asBukkitWorld(World world) {
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE start - logic moved to IBukkitAdapter
|
2019-10-23 04:23:52 +00:00
|
|
|
return getAdapter().asBukkitWorld(world);
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE end
|
2014-07-26 00:29:36 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 22:39:51 +00:00
|
|
|
/**
|
|
|
|
* Create a WorldEdit world from a Bukkit world.
|
|
|
|
*
|
|
|
|
* @param world the Bukkit world
|
|
|
|
* @return a WorldEdit world
|
|
|
|
*/
|
2014-04-27 04:57:45 +00:00
|
|
|
public static World adapt(org.bukkit.World world) {
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE start - logic moved to IBukkitAdapter
|
2019-10-23 04:23:52 +00:00
|
|
|
return getAdapter().adapt(world);
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE end
|
2014-04-28 06:34:39 +00:00
|
|
|
}
|
|
|
|
|
2020-01-04 17:34:30 +00:00
|
|
|
/**
|
2020-10-05 17:41:41 +00:00
|
|
|
* Create a WorldEdit Actor from a Bukkit CommandSender.
|
2020-01-04 17:34:30 +00:00
|
|
|
*
|
|
|
|
* @param sender The Bukkit CommandSender
|
|
|
|
* @return The WorldEdit Actor
|
|
|
|
*/
|
|
|
|
public static Actor adapt(CommandSender sender) {
|
|
|
|
return WorldEditPlugin.getInstance().wrapCommandSender(sender);
|
|
|
|
}
|
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
/**
|
|
|
|
* Create a WorldEdit Player from a Bukkit Player.
|
|
|
|
*
|
|
|
|
* @param player The Bukkit player
|
|
|
|
* @return The WorldEdit player
|
|
|
|
*/
|
|
|
|
public static BukkitPlayer adapt(Player player) {
|
2019-09-21 01:52:35 +00:00
|
|
|
return WorldEditPlugin.getInstance().wrapPlayer(player);
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
|
|
|
|
2020-01-04 17:34:30 +00:00
|
|
|
/**
|
|
|
|
* Create a Bukkit CommandSender from a WorldEdit Actor.
|
|
|
|
*
|
|
|
|
* @param actor The WorldEdit actor
|
|
|
|
* @return The Bukkit command sender
|
|
|
|
*/
|
|
|
|
public static CommandSender adapt(Actor actor) {
|
|
|
|
if (actor instanceof com.sk89q.worldedit.entity.Player) {
|
|
|
|
return adapt((com.sk89q.worldedit.entity.Player) actor);
|
|
|
|
} else if (actor instanceof BukkitBlockCommandSender) {
|
|
|
|
return ((BukkitBlockCommandSender) actor).getSender();
|
|
|
|
}
|
|
|
|
return ((BukkitCommandSender) actor).getSender();
|
|
|
|
}
|
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
/**
|
|
|
|
* Create a Bukkit Player from a WorldEdit Player.
|
|
|
|
*
|
|
|
|
* @param player The WorldEdit player
|
|
|
|
* @return The Bukkit player
|
|
|
|
*/
|
|
|
|
public static Player adapt(com.sk89q.worldedit.entity.Player player) {
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE start - Get player from PlayerProxy instead of BukkitPlayer if null
|
2019-10-23 04:23:52 +00:00
|
|
|
player = PlayerProxy.unwrap(player);
|
2019-10-30 11:26:52 +00:00
|
|
|
return player == null ? null : ((BukkitPlayer) player).getPlayer();
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE end
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a WorldEdit Direction from a Bukkit BlockFace.
|
|
|
|
*
|
|
|
|
* @param face the Bukkit BlockFace
|
|
|
|
* @return a WorldEdit direction
|
|
|
|
*/
|
|
|
|
public static Direction adapt(@Nullable BlockFace face) {
|
|
|
|
if (face == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
switch (face) {
|
2021-07-24 15:34:05 +00:00
|
|
|
case NORTH:
|
|
|
|
return Direction.NORTH;
|
|
|
|
case SOUTH:
|
|
|
|
return Direction.SOUTH;
|
|
|
|
case WEST:
|
|
|
|
return Direction.WEST;
|
|
|
|
case EAST:
|
|
|
|
return Direction.EAST;
|
|
|
|
case DOWN:
|
|
|
|
return Direction.DOWN;
|
2021-07-14 12:40:20 +00:00
|
|
|
case UP:
|
|
|
|
default:
|
|
|
|
return Direction.UP;
|
|
|
|
}
|
2019-09-21 01:52:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a Bukkit world from a WorldEdit world.
|
|
|
|
*
|
|
|
|
* @param world the WorldEdit world
|
|
|
|
* @return a Bukkit world
|
|
|
|
*/
|
|
|
|
public static org.bukkit.World adapt(World world) {
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE start - logic moved to IBukkitAdapter
|
2019-10-23 04:23:52 +00:00
|
|
|
return getAdapter().adapt(world);
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE end
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 22:39:51 +00:00
|
|
|
/**
|
|
|
|
* Create a WorldEdit location from a Bukkit location.
|
|
|
|
*
|
|
|
|
* @param location the Bukkit location
|
|
|
|
* @return a WorldEdit location
|
|
|
|
*/
|
2014-04-27 04:57:45 +00:00
|
|
|
public static Location adapt(org.bukkit.Location location) {
|
2019-06-06 22:39:51 +00:00
|
|
|
checkNotNull(location);
|
2019-09-21 01:52:35 +00:00
|
|
|
Vector3 position = asVector(location);
|
|
|
|
return new com.sk89q.worldedit.util.Location(
|
|
|
|
adapt(location.getWorld()),
|
|
|
|
position,
|
|
|
|
location.getYaw(),
|
2021-07-24 15:34:05 +00:00
|
|
|
location.getPitch()
|
|
|
|
);
|
2014-04-27 04:57:45 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 22:39:51 +00:00
|
|
|
/**
|
|
|
|
* Create a Bukkit location from a WorldEdit location.
|
|
|
|
*
|
|
|
|
* @param location the WorldEdit location
|
|
|
|
* @return a Bukkit location
|
|
|
|
*/
|
2014-04-28 06:34:39 +00:00
|
|
|
public static org.bukkit.Location adapt(Location location) {
|
2019-06-06 22:39:51 +00:00
|
|
|
checkNotNull(location);
|
2019-09-21 01:52:35 +00:00
|
|
|
Vector3 position = location;
|
|
|
|
return new org.bukkit.Location(
|
|
|
|
adapt((World) location.getExtent()),
|
|
|
|
position.getX(), position.getY(), position.getZ(),
|
|
|
|
location.getYaw(),
|
2021-07-24 15:34:05 +00:00
|
|
|
location.getPitch()
|
|
|
|
);
|
2014-04-28 06:34:39 +00:00
|
|
|
}
|
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
/**
|
|
|
|
* Create a Bukkit location from a WorldEdit position with a Bukkit world.
|
|
|
|
*
|
2021-07-24 15:34:05 +00:00
|
|
|
* @param world the Bukkit world
|
2019-07-06 00:46:48 +00:00
|
|
|
* @param position the WorldEdit position
|
|
|
|
* @return a Bukkit location
|
|
|
|
*/
|
2018-12-23 16:19:33 +00:00
|
|
|
public static org.bukkit.Location adapt(org.bukkit.World world, Vector3 position) {
|
2019-09-21 01:52:35 +00:00
|
|
|
checkNotNull(world);
|
|
|
|
checkNotNull(position);
|
|
|
|
return new org.bukkit.Location(
|
|
|
|
world,
|
2021-07-24 15:34:05 +00:00
|
|
|
position.getX(), position.getY(), position.getZ()
|
|
|
|
);
|
2018-12-23 16:19:33 +00:00
|
|
|
}
|
2019-06-06 22:39:51 +00:00
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
/**
|
|
|
|
* Create a Bukkit location from a WorldEdit position with a Bukkit world.
|
|
|
|
*
|
2021-07-24 15:34:05 +00:00
|
|
|
* @param world the Bukkit world
|
2019-07-06 00:46:48 +00:00
|
|
|
* @param position the WorldEdit position
|
|
|
|
* @return a Bukkit location
|
|
|
|
*/
|
2018-12-23 16:19:33 +00:00
|
|
|
public static org.bukkit.Location adapt(org.bukkit.World world, BlockVector3 position) {
|
2019-06-06 22:39:51 +00:00
|
|
|
checkNotNull(world);
|
|
|
|
checkNotNull(position);
|
2019-09-21 01:52:35 +00:00
|
|
|
return new org.bukkit.Location(
|
|
|
|
world,
|
2021-07-24 15:34:05 +00:00
|
|
|
position.getX(), position.getY(), position.getZ()
|
|
|
|
);
|
2014-07-14 19:10:38 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 22:39:51 +00:00
|
|
|
/**
|
|
|
|
* Create a Bukkit location from a WorldEdit location with a Bukkit world.
|
|
|
|
*
|
2021-07-24 15:34:05 +00:00
|
|
|
* @param world the Bukkit world
|
2019-06-06 22:39:51 +00:00
|
|
|
* @param location the WorldEdit location
|
|
|
|
* @return a Bukkit location
|
|
|
|
*/
|
2014-07-15 01:11:38 +00:00
|
|
|
public static org.bukkit.Location adapt(org.bukkit.World world, Location location) {
|
2019-06-06 22:39:51 +00:00
|
|
|
checkNotNull(world);
|
|
|
|
checkNotNull(location);
|
2019-09-21 01:52:35 +00:00
|
|
|
return new org.bukkit.Location(
|
|
|
|
world,
|
|
|
|
location.getX(), location.getY(), location.getZ(),
|
|
|
|
location.getYaw(),
|
2021-07-24 15:34:05 +00:00
|
|
|
location.getPitch()
|
|
|
|
);
|
2014-07-15 01:11:38 +00:00
|
|
|
}
|
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
/**
|
|
|
|
* Create a WorldEdit Vector from a Bukkit location.
|
|
|
|
*
|
|
|
|
* @param location The Bukkit location
|
|
|
|
* @return a WorldEdit vector
|
|
|
|
*/
|
2018-12-23 16:19:33 +00:00
|
|
|
public static Vector3 asVector(org.bukkit.Location location) {
|
2019-07-06 00:46:48 +00:00
|
|
|
checkNotNull(location);
|
|
|
|
return Vector3.at(location.getX(), location.getY(), location.getZ());
|
2018-07-19 02:55:02 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 22:39:51 +00:00
|
|
|
/**
|
2019-07-06 00:46:48 +00:00
|
|
|
* Create a WorldEdit BlockVector from a Bukkit location.
|
2019-06-06 22:39:51 +00:00
|
|
|
*
|
|
|
|
* @param location The Bukkit location
|
|
|
|
* @return a WorldEdit vector
|
|
|
|
*/
|
2018-12-23 16:19:33 +00:00
|
|
|
public static BlockVector3 asBlockVector(org.bukkit.Location location) {
|
2019-06-06 22:39:51 +00:00
|
|
|
checkNotNull(location);
|
2019-07-06 00:46:48 +00:00
|
|
|
return BlockVector3.at(location.getX(), location.getY(), location.getZ());
|
2018-12-23 16:19:33 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 22:39:51 +00:00
|
|
|
/**
|
|
|
|
* Create a WorldEdit entity from a Bukkit entity.
|
|
|
|
*
|
|
|
|
* @param entity the Bukkit entity
|
|
|
|
* @return a WorldEdit entity
|
|
|
|
*/
|
2014-04-28 06:34:39 +00:00
|
|
|
public static Entity adapt(org.bukkit.entity.Entity entity) {
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE start - logic moved to IBukkitAdapter
|
2019-10-23 04:23:52 +00:00
|
|
|
return getAdapter().adapt(entity);
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE end
|
2014-04-28 06:34:39 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 22:39:51 +00:00
|
|
|
/**
|
2020-10-05 17:41:41 +00:00
|
|
|
* Create a Bukkit Material form a WorldEdit ItemType.
|
2019-06-06 22:39:51 +00:00
|
|
|
*
|
|
|
|
* @param itemType The WorldEdit ItemType
|
|
|
|
* @return The Bukkit Material
|
|
|
|
*/
|
2018-07-19 02:55:02 +00:00
|
|
|
public static Material adapt(ItemType itemType) {
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE start - logic moved to IBukkitAdapter
|
2019-10-23 04:23:52 +00:00
|
|
|
return getAdapter().adapt(itemType);
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE end
|
2018-07-19 02:55:02 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 22:39:51 +00:00
|
|
|
/**
|
2020-10-05 17:41:41 +00:00
|
|
|
* Create a Bukkit Material form a WorldEdit BlockType.
|
2019-06-06 22:39:51 +00:00
|
|
|
*
|
|
|
|
* @param blockType The WorldEdit BlockType
|
|
|
|
* @return The Bukkit Material
|
|
|
|
*/
|
2019-09-21 01:52:35 +00:00
|
|
|
public static Material adapt(BlockType blockType) {
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE start - logic moved to IBukkitAdapter
|
2019-10-23 04:23:52 +00:00
|
|
|
return getAdapter().adapt(blockType);
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE end
|
2018-07-19 02:55:02 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 22:39:51 +00:00
|
|
|
/**
|
|
|
|
* Create a WorldEdit GameMode from a Bukkit one.
|
|
|
|
*
|
|
|
|
* @param gameMode Bukkit GameMode
|
|
|
|
* @return WorldEdit GameMode
|
|
|
|
*/
|
2018-07-22 05:36:50 +00:00
|
|
|
public static GameMode adapt(org.bukkit.GameMode gameMode) {
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE start - logic moved to IBukkitAdapter
|
2019-10-23 04:23:52 +00:00
|
|
|
return getAdapter().adapt(gameMode);
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE end
|
2018-07-22 05:36:50 +00:00
|
|
|
}
|
|
|
|
|
2019-02-16 07:27:00 +00:00
|
|
|
/**
|
|
|
|
* Create a WorldEdit BiomeType from a Bukkit one.
|
|
|
|
*
|
|
|
|
* @param biome Bukkit Biome
|
|
|
|
* @return WorldEdit BiomeType
|
|
|
|
*/
|
|
|
|
public static BiomeType adapt(Biome biome) {
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE start - logic moved to IBukkitAdapter
|
2019-10-23 04:23:52 +00:00
|
|
|
return getAdapter().adapt(biome);
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE end
|
2019-02-16 07:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Biome adapt(BiomeType biomeType) {
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE start - logic moved to IBukkitAdapter
|
2019-10-23 04:23:52 +00:00
|
|
|
return getAdapter().adapt(biomeType);
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE end
|
2019-02-16 07:27:00 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 12:29:48 +00:00
|
|
|
/**
|
|
|
|
* Create a WorldEdit EntityType from a Bukkit one.
|
|
|
|
*
|
|
|
|
* @param entityType Bukkit EntityType
|
|
|
|
* @return WorldEdit EntityType
|
|
|
|
*/
|
|
|
|
public static EntityType adapt(org.bukkit.entity.EntityType entityType) {
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE start - logic moved to IBukkitAdapter
|
2019-10-23 04:23:52 +00:00
|
|
|
return getAdapter().adapt(entityType);
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE end
|
2018-08-13 12:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static org.bukkit.entity.EntityType adapt(EntityType entityType) {
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE start - logic moved to IBukkitAdapter
|
2019-10-23 04:23:52 +00:00
|
|
|
return getAdapter().adapt(entityType);
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE end
|
2018-08-13 12:29:48 +00:00
|
|
|
}
|
|
|
|
|
2021-07-24 15:34:05 +00:00
|
|
|
private static final EnumMap<Material, BlockType> materialBlockTypeCache = new EnumMap<>(Material.class);
|
|
|
|
private static final EnumMap<Material, ItemType> materialItemTypeCache = new EnumMap<>(Material.class);
|
2020-03-24 16:15:24 +00:00
|
|
|
|
2019-06-06 22:39:51 +00:00
|
|
|
/**
|
2020-10-05 17:41:41 +00:00
|
|
|
* Converts a Material to a BlockType.
|
2019-06-06 22:39:51 +00:00
|
|
|
*
|
|
|
|
* @param material The material
|
|
|
|
* @return The blocktype
|
|
|
|
*/
|
2020-03-24 16:15:24 +00:00
|
|
|
@Nullable
|
2019-09-21 01:52:35 +00:00
|
|
|
public static BlockType asBlockType(Material material) {
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE start - logic moved to IBukkitAdapter
|
2019-10-23 04:23:52 +00:00
|
|
|
return getAdapter().asBlockType(material);
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE end
|
2018-07-22 05:36:50 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 22:39:51 +00:00
|
|
|
/**
|
2020-10-05 17:41:41 +00:00
|
|
|
* Converts a Material to a ItemType.
|
2019-06-06 22:39:51 +00:00
|
|
|
*
|
|
|
|
* @param material The material
|
|
|
|
* @return The itemtype
|
|
|
|
*/
|
2020-03-24 16:15:24 +00:00
|
|
|
@Nullable
|
2018-07-22 05:36:50 +00:00
|
|
|
public static ItemType asItemType(Material material) {
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE start - logic moved to IBukkitAdapter
|
2019-10-23 04:23:52 +00:00
|
|
|
return getAdapter().asItemType(material);
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE end
|
2018-07-22 05:36:50 +00:00
|
|
|
}
|
2020-03-24 16:15:24 +00:00
|
|
|
|
2021-07-24 15:34:05 +00:00
|
|
|
private static final Int2ObjectMap<BlockState> blockStateCache = new Int2ObjectOpenHashMap<>();
|
|
|
|
private static final Map<String, BlockState> blockStateStringCache = new HashMap<>();
|
2019-06-06 22:39:51 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-05 17:41:41 +00:00
|
|
|
* Create a WorldEdit BlockState from a Bukkit BlockData.
|
2019-06-06 22:39:51 +00:00
|
|
|
*
|
|
|
|
* @param blockData The Bukkit BlockData
|
|
|
|
* @return The WorldEdit BlockState
|
|
|
|
*/
|
2021-07-24 13:52:08 +00:00
|
|
|
public static BlockState adapt(@Nonnull BlockData blockData) {
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE start - logic moved to IBukkitAdapter
|
2018-08-27 16:56:28 +00:00
|
|
|
return getAdapter().adapt(blockData);
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE end
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2020-03-24 16:15:24 +00:00
|
|
|
|
2021-07-24 15:34:05 +00:00
|
|
|
private static final Int2ObjectMap<BlockData> blockDataCache = new Int2ObjectOpenHashMap<>();
|
2020-03-24 16:15:24 +00:00
|
|
|
|
2018-07-19 02:55:02 +00:00
|
|
|
/**
|
2020-10-05 17:41:41 +00:00
|
|
|
* Create a Bukkit BlockData from a WorldEdit BlockStateHolder.
|
2018-07-19 02:55:02 +00:00
|
|
|
*
|
|
|
|
* @param block The WorldEdit BlockStateHolder
|
|
|
|
* @return The Bukkit BlockData
|
|
|
|
*/
|
2021-07-24 13:52:08 +00:00
|
|
|
public static BlockData adapt(@Nonnull BlockStateHolder block) {
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE start - logic moved to IBukkitAdapter
|
2019-07-22 20:42:40 +00:00
|
|
|
return getAdapter().adapt(block);
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE end
|
2018-08-27 16:56:28 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 22:39:51 +00:00
|
|
|
/**
|
2020-10-05 17:41:41 +00:00
|
|
|
* Create a WorldEdit BlockState from a Bukkit ItemStack.
|
2019-06-06 22:39:51 +00:00
|
|
|
*
|
|
|
|
* @param itemStack The Bukkit ItemStack
|
|
|
|
* @return The WorldEdit BlockState
|
|
|
|
*/
|
|
|
|
public static BlockState asBlockState(ItemStack itemStack) throws WorldEditException {
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE start - logic moved to IBukkitAdapter
|
2019-10-23 04:23:52 +00:00
|
|
|
return getAdapter().asBlockState(itemStack);
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE end
|
2018-07-19 02:55:02 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 22:39:51 +00:00
|
|
|
/**
|
2020-10-05 17:41:41 +00:00
|
|
|
* Create a WorldEdit BaseItemStack from a Bukkit ItemStack.
|
2019-06-06 22:39:51 +00:00
|
|
|
*
|
|
|
|
* @param itemStack The Bukkit ItemStack
|
|
|
|
* @return The WorldEdit BaseItemStack
|
|
|
|
*/
|
2018-07-19 02:55:02 +00:00
|
|
|
public static BaseItemStack adapt(ItemStack itemStack) {
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE start - logic moved to IBukkitAdapter
|
2019-10-23 04:23:52 +00:00
|
|
|
return getAdapter().adapt(itemStack);
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE end
|
2018-07-19 02:55:02 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 22:39:51 +00:00
|
|
|
/**
|
2020-10-05 17:41:41 +00:00
|
|
|
* Create a Bukkit ItemStack from a WorldEdit BaseItemStack.
|
2019-06-06 22:39:51 +00:00
|
|
|
*
|
|
|
|
* @param item The WorldEdit BaseItemStack
|
|
|
|
* @return The Bukkit ItemStack
|
|
|
|
*/
|
2018-07-19 02:55:02 +00:00
|
|
|
public static ItemStack adapt(BaseItemStack item) {
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE start - logic moved to IBukkitAdapter
|
2019-10-23 04:23:52 +00:00
|
|
|
return getAdapter().adapt(item);
|
2021-07-14 12:40:20 +00:00
|
|
|
//FAWE end
|
2018-07-19 02:55:02 +00:00
|
|
|
}
|
2020-03-24 16:15:24 +00:00
|
|
|
}
|