com.sk89q.worldedit.bukkit.BukkitAdapter Java Examples
The following examples show how to use
com.sk89q.worldedit.bukkit.BukkitAdapter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RadiationCommandHandler.java From CraftserveRadiation with Apache License 2.0 | 6 votes |
private boolean define(Player player, RegionContainer container, String regionId, int radius) { Objects.requireNonNull(player, "player"); Objects.requireNonNull(container, "container"); Objects.requireNonNull(regionId, "regionId"); World world = BukkitAdapter.adapt(player.getWorld()); RegionManager regionManager = container.get(world); if (regionManager == null) { player.sendMessage(ChatColor.RED + "Sorry, region manager for world " + world.getName() + " is not currently accessible."); return false; } BlockVector3 origin = BukkitAdapter.asBlockVector(player.getLocation()); this.define(regionManager, this.createCuboid(regionId, origin, radius)); this.flagGlobal(regionManager, true); return true; }
Example #2
Source File: HookWorldGuard_V7_0.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
public static boolean allowsMobCombat(Location location) { WorldGuard api = getAPI(); WorldGuardPlatform platform = api.getPlatform(); RegionContainer container = platform.getRegionContainer(); RegionQuery query = container.createQuery(); com.sk89q.worldedit.util.Location weLocation = BukkitAdapter.adapt(location); if(MOB_COMBAT_FLAG instanceof StateFlag) { StateFlag mobCombatFlag = (StateFlag) MOB_COMBAT_FLAG; State state = query.queryState(weLocation, null, mobCombatFlag); return (state != State.DENY); } return true; }
Example #3
Source File: HookWorldGuard_V7_0.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
public static boolean allowsTagging(Location location) { WorldGuard api = getAPI(); WorldGuardPlatform platform = api.getPlatform(); RegionContainer container = platform.getRegionContainer(); RegionQuery query = container.createQuery(); if(NO_TAGGING_FLAG instanceof BooleanFlag) { BooleanFlag noTaggingFlag = (BooleanFlag) NO_TAGGING_FLAG; com.sk89q.worldedit.util.Location weLocation = BukkitAdapter.adapt(location); Boolean value = query.queryValue(weLocation, null, noTaggingFlag); return (value == null || !value); } return true; }
Example #4
Source File: NPCRegionCondition.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
@Override protected Boolean execute(String playerID) throws QuestRuntimeException { NPC npc = CitizensAPI.getNPCRegistry().getById(ID); if (npc == null) { throw new QuestRuntimeException("NPC with ID " + ID + " does not exist"); } Entity npcEntity = npc.getEntity(); if (npcEntity == null) return false; Player player = PlayerConverter.getPlayer(playerID); WorldGuardPlatform worldguardPlatform = WorldGuard.getInstance().getPlatform(); RegionManager manager = worldguardPlatform.getRegionContainer().get(BukkitAdapter.adapt(player.getWorld())); if (manager == null) { return false; } ApplicableRegionSet set = manager.getApplicableRegions(BlockVector3.at(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ())); for (ProtectedRegion compare : set) { if (compare.equals(region)) return true; } return false; }
Example #5
Source File: WorldEditUtils.java From WorldGuardExtraFlagsPlugin with MIT License | 6 votes |
public static org.bukkit.Location toLocation(Object location) { if (WorldEditUtils.legacyToLocationMethod != null) { try { return (org.bukkit.Location)WorldEditUtils.legacyToLocationMethod.invoke(null, location); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new RuntimeException("Unsupported WorldEdit version"); } } else { return BukkitAdapter.adapt((Location)location); } }
Example #6
Source File: RegionObjective.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
/** * Return true if location is inside region * * @param loc Location to Check * @return boolean True if in region */ private boolean isInsideRegion(Location loc) { if (loc == null || loc.getWorld() == null) { return false; } WorldGuardPlatform worldguardPlatform = WorldGuard.getInstance().getPlatform(); RegionManager manager = worldguardPlatform.getRegionContainer().get(BukkitAdapter.adapt(loc.getWorld())); if (manager == null) { return false; } ProtectedRegion region = manager.getRegion(name); if (region == null) { return false; } return region.contains(BukkitAdapter.asBlockVector(loc)); }
Example #7
Source File: RegionCondition.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
@Override protected Boolean execute(String playerID) { Player player = PlayerConverter.getPlayer(playerID); WorldGuardPlatform worldguardPlatform = WorldGuard.getInstance().getPlatform(); RegionManager manager = worldguardPlatform.getRegionContainer().get(BukkitAdapter.adapt(player.getWorld())); if (manager == null) { return false; } ProtectedRegion region = manager.getRegion(name); ApplicableRegionSet set = manager.getApplicableRegions(BlockVector3.at(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ())); for (ProtectedRegion compare : set) { if (compare.equals(region)) return true; } return false; }
Example #8
Source File: WorldGuardHook.java From Skript with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("null") @Override public Collection<? extends Region> getRegionsAt_i(@Nullable final Location l) { final ArrayList<Region> r = new ArrayList<>(); if (l == null) // Working around possible cause of issue #280 return Collections.emptyList(); if (l.getWorld() == null) return Collections.emptyList(); WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform(); RegionManager manager = platform.getRegionContainer().get(BukkitAdapter.adapt(l.getWorld())); if (manager == null) return r; ApplicableRegionSet applicable = manager.getApplicableRegions(BukkitAdapter.asBlockVector(l)); if (applicable == null) return r; for (ProtectedRegion region : applicable) r.add(new WorldGuardRegion(l.getWorld(), region)); return r; }
Example #9
Source File: WorldGuard7FAWEHook.java From Skript with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("null") @Override public Collection<? extends Region> getRegionsAt_i(@Nullable final Location l) { final ArrayList<Region> r = new ArrayList<>(); if (l == null) // Working around possible cause of issue #280 return Collections.emptyList(); if (l.getWorld() == null) return Collections.emptyList(); RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery(); if (query == null) return r; ApplicableRegionSet applicable = query.getApplicableRegions(BukkitAdapter.adapt(l)); if (applicable == null) return r; final Iterator<ProtectedRegion> i = applicable.iterator(); while (i.hasNext()) r.add(new WorldGuardRegion(l.getWorld(), i.next())); return r; }
Example #10
Source File: Spigot_v1_16_R1.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Override public BaseBlock getBlock(Location location) { checkNotNull(location); CraftWorld craftWorld = ((CraftWorld) location.getWorld()); int x = location.getBlockX(); int y = location.getBlockY(); int z = location.getBlockZ(); final WorldServer handle = craftWorld.getHandle(); Chunk chunk = handle.getChunkAt(x >> 4, z >> 4); final BlockPosition blockPos = new BlockPosition(x, y, z); final IBlockData blockData = chunk.getType(blockPos); int internalId = Block.getCombinedId(blockData); BlockState state = BlockStateIdAccess.getBlockStateById(internalId); if (state == null) { org.bukkit.block.Block bukkitBlock = location.getBlock(); state = BukkitAdapter.adapt(bukkitBlock.getBlockData()); } // Read the NBT data TileEntity te = chunk.a(blockPos, Chunk.EnumTileEntityState.CHECK); if (te != null) { NBTTagCompound tag = new NBTTagCompound(); readTileEntityIntoTag(te, tag); // Load data return state.toBaseBlock((CompoundTag) toNative(tag)); } return state.toBaseBlock(); }
Example #11
Source File: WorldGuardApi.java From ClaimChunk with MIT License | 5 votes |
static boolean _isAllowedClaim(ClaimChunk claimChunk, Chunk chunk) { try { // Generate a region in the given chunk to get all intersecting regions int bx = chunk.getX() << 4; int bz = chunk.getZ() << 4; BlockVector3 pt1 = BlockVector3.at(bx, 0, bz); BlockVector3 pt2 = BlockVector3.at(bx + 15, 256, bz + 15); ProtectedCuboidRegion region = new ProtectedCuboidRegion("_", pt1, pt2); RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(chunk.getWorld())); // No regions in this world, claiming should be determined by the config if (regionManager == null) { return claimChunk.chConfig().getBool("worldguard", "allowClaimingInNonGuardedWorlds"); } // If any regions in the given chunk deny chunk claiming, false is returned for (ProtectedRegion regionIn : regionManager.getApplicableRegions(region)) { StateFlag.State flag = regionIn.getFlag(FLAG_CHUNK_CLAIM); if (flag == StateFlag.State.DENY) return false; } // No objections return true; } catch (Exception e) { e.printStackTrace(); } // An error occurred, better to be on the safe side so false is returned return false; }
Example #12
Source File: PasteSchematicEvent.java From BetonQuest with GNU General Public License v3.0 | 5 votes |
@Override protected Void execute(String playerID) throws QuestRuntimeException { try { Location location = loc.getLocation(playerID); ClipboardFormat format = ClipboardFormats.findByFile(file); if (format == null) { throw new IOException("Unknown Schematic Format"); } Clipboard clipboard; try (ClipboardReader reader = format.getReader(new FileInputStream(file))) { clipboard = reader.read(); } try (EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(BukkitAdapter.adapt(location.getWorld()), -1)) { Operation operation = new ClipboardHolder(clipboard) .createPaste(editSession) .to(BukkitAdapter.asBlockVector(location)) .ignoreAirBlocks(noAir) .build(); Operations.complete(operation); } } catch (IOException | WorldEditException e) { LogUtils.getLogger().log(Level.WARNING, "Error while pasting a schematic: " + e.getMessage()); LogUtils.logThrowable(e); } return null; }
Example #13
Source File: WorldEditHandler7_beta_1.java From AreaShop with GNU General Public License v3.0 | 5 votes |
@Override public WorldEditSelection getPlayerSelection(Player player) { try { Region region = pluginInterface.getWorldEdit().getSession(player).getSelection(BukkitAdapter.adapt(player.getWorld())); return new WorldEditSelection( player.getWorld(), BukkitAdapter.adapt(player.getWorld(), region.getMinimumPoint()), BukkitAdapter.adapt(player.getWorld(), region.getMaximumPoint()) ); } catch (IncompleteRegionException e) { return null; } }
Example #14
Source File: FastAsyncWorldEditHandler.java From AreaShop with GNU General Public License v3.0 | 5 votes |
@Override public WorldEditSelection getPlayerSelection(Player player) { try { Region region = pluginInterface.getWorldEdit().getSession(player).getSelection(BukkitAdapter.adapt(player.getWorld())); return new WorldEditSelection( player.getWorld(), BukkitAdapter.adapt(player.getWorld(), region.getMinimumPoint()), BukkitAdapter.adapt(player.getWorld(), region.getMaximumPoint()) ); } catch (IncompleteRegionException e) { return null; } }
Example #15
Source File: WorldEditHandler7_beta_4.java From AreaShop with GNU General Public License v3.0 | 5 votes |
@Override public WorldEditSelection getPlayerSelection(Player player) { try { Region region = pluginInterface.getWorldEdit().getSession(player).getSelection(BukkitAdapter.adapt(player.getWorld())); return new WorldEditSelection( player.getWorld(), BukkitAdapter.adapt(player.getWorld(), region.getMinimumPoint()), BukkitAdapter.adapt(player.getWorld(), region.getMaximumPoint()) ); } catch (IncompleteRegionException e) { return null; } }
Example #16
Source File: WorldNativeAccess_v1_16_R1.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Override public IBlockData toNative(BlockState state) { int stateId = BlockStateIdAccess.getBlockStateId(state); return BlockStateIdAccess.isValidInternalId(stateId) ? Block.getByCombinedId(stateId) : ((CraftBlockData) BukkitAdapter.adapt(state)).getState(); }
Example #17
Source File: RadiationCommandHandler.java From CraftserveRadiation with Apache License 2.0 | 5 votes |
private boolean onSafe(Player sender, String label, String[] args) { String usage = ChatColor.RED + "/" + label + " safe <radius>"; if (args.length == 1) { sender.sendMessage(ChatColor.RED + "Provide safe-from-radiation zone radius in the first argument. Radius will be relative to your current position."); sender.sendMessage(usage); return true; } int radius; try { radius = Integer.parseInt(args[1]); } catch (NumberFormatException e) { sender.sendMessage(ChatColor.RED + "Number was expected, but " + args[1] + " was provided."); sender.sendMessage(ChatColor.RED + usage); return true; } if (radius <= 0) { sender.sendMessage(ChatColor.RED + "Radius must be positive."); sender.sendMessage(ChatColor.RED + usage); return true; } RegionContainer container = this.worldGuardMatcher.getRegionContainer(); if (container == null) { sender.sendMessage(ChatColor.RED + "Sorry, region container is not currently accessible."); return true; } if (this.define(sender, container, REGION_ID, radius)) { BlockVector2 origin = BukkitAdapter.asBlockVector(sender.getLocation()).toBlockVector2(); sender.sendMessage(ChatColor.GREEN + "A new safe-from-radiation zone has been created in radius " + radius + " at the origin at " + origin + " in world " + sender.getWorld().getName() + "."); } return true; }
Example #18
Source File: Spigot_v1_16_R1.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Override public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) { final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); final BaseItemStack weStack = new BaseItemStack(BukkitAdapter.asItemType(itemStack.getType()), itemStack.getAmount()); weStack.setNbtData(((CompoundTag) toNative(nmsStack.getTag()))); return weStack; }
Example #19
Source File: Spigot_v1_16_R1.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean simulateItemUse(org.bukkit.World world, BlockVector3 position, BaseItem item, Direction face) { CraftWorld craftWorld = (CraftWorld) world; WorldServer worldServer = craftWorld.getHandle(); ItemStack stack = CraftItemStack.asNMSCopy(BukkitAdapter.adapt(item instanceof BaseItemStack ? ((BaseItemStack) item) : new BaseItemStack(item.getType(), item.getNbtData(), 1))); stack.setTag((NBTTagCompound) fromNative(item.getNbtData())); FakePlayer_v1_16_R1 fakePlayer; try { fakePlayer = fakePlayers.get(worldServer); } catch (ExecutionException ignored) { return false; } fakePlayer.a(EnumHand.MAIN_HAND, stack); fakePlayer.setLocation(position.getBlockX(), position.getBlockY(), position.getBlockZ(), (float) face.toVector().toYaw(), (float) face.toVector().toPitch()); final BlockPosition blockPos = new BlockPosition(position.getBlockX(), position.getBlockY(), position.getBlockZ()); final Vec3D blockVec = Vec3D.b(blockPos); final EnumDirection enumFacing = adapt(face); MovingObjectPositionBlock rayTrace = new MovingObjectPositionBlock(blockVec, enumFacing, blockPos, false); ItemActionContext context = new ItemActionContext(fakePlayer, EnumHand.MAIN_HAND, rayTrace); EnumInteractionResult result = stack.placeItem(context, EnumHand.MAIN_HAND); if (result != EnumInteractionResult.SUCCESS) { if (worldServer.getType(blockPos).interact(worldServer, fakePlayer, EnumHand.MAIN_HAND, rayTrace).a()) { result = EnumInteractionResult.SUCCESS; } else { result = stack.getItem().a(worldServer, fakePlayer, EnumHand.MAIN_HAND).a(); } } return result == EnumInteractionResult.SUCCESS; }
Example #20
Source File: WorldNativeAccess_v1_15_R2.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Override public IBlockData toNative(com.sk89q.worldedit.world.block.BlockState state) { int stateId = BlockStateIdAccess.getBlockStateId(state); return BlockStateIdAccess.isValidInternalId(stateId) ? Block.getByCombinedId(stateId) : ((CraftBlockData) BukkitAdapter.adapt(state)).getState(); }
Example #21
Source File: Spigot_v1_15_R2.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Override public BaseBlock getBlock(Location location) { checkNotNull(location); CraftWorld craftWorld = ((CraftWorld) location.getWorld()); int x = location.getBlockX(); int y = location.getBlockY(); int z = location.getBlockZ(); final WorldServer handle = craftWorld.getHandle(); Chunk chunk = handle.getChunkAt(x >> 4, z >> 4); final BlockPosition blockPos = new BlockPosition(x, y, z); final IBlockData blockData = chunk.getType(blockPos); int internalId = Block.getCombinedId(blockData); BlockState state = BlockStateIdAccess.getBlockStateById(internalId); if (state == null) { org.bukkit.block.Block bukkitBlock = location.getBlock(); state = BukkitAdapter.adapt(bukkitBlock.getBlockData()); } // Read the NBT data TileEntity te = chunk.a(blockPos, Chunk.EnumTileEntityState.CHECK); if (te != null) { NBTTagCompound tag = new NBTTagCompound(); readTileEntityIntoTag(te, tag); // Load data return state.toBaseBlock((CompoundTag) toNative(tag)); } return state.toBaseBlock(); }
Example #22
Source File: Spigot_v1_15_R2.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Override public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) { final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); final BaseItemStack weStack = new BaseItemStack(BukkitAdapter.asItemType(itemStack.getType()), itemStack.getAmount()); weStack.setNbtData(((CompoundTag) toNative(nmsStack.getTag()))); return weStack; }
Example #23
Source File: Spigot_v1_15_R2.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean simulateItemUse(org.bukkit.World world, BlockVector3 position, BaseItem item, Direction face) { CraftWorld craftWorld = (CraftWorld) world; WorldServer worldServer = craftWorld.getHandle(); ItemStack stack = CraftItemStack.asNMSCopy(BukkitAdapter.adapt(item instanceof BaseItemStack ? ((BaseItemStack) item) : new BaseItemStack(item.getType(), item.getNbtData(), 1))); stack.setTag((NBTTagCompound) fromNative(item.getNbtData())); FakePlayer_v1_15_R2 fakePlayer; try { fakePlayer = fakePlayers.get(worldServer); } catch (ExecutionException ignored) { return false; } fakePlayer.a(EnumHand.MAIN_HAND, stack); fakePlayer.setLocation(position.getBlockX(), position.getBlockY(), position.getBlockZ(), (float) face.toVector().toYaw(), (float) face.toVector().toPitch()); final BlockPosition blockPos = new BlockPosition(position.getBlockX(), position.getBlockY(), position.getBlockZ()); final Vec3D blockVec = new Vec3D(blockPos); final EnumDirection enumFacing = adapt(face); MovingObjectPositionBlock rayTrace = new MovingObjectPositionBlock(blockVec, enumFacing, blockPos, false); ItemActionContext context = new ItemActionContext(fakePlayer, EnumHand.MAIN_HAND, rayTrace); EnumInteractionResult result = stack.placeItem(context, EnumHand.MAIN_HAND); if (result != EnumInteractionResult.SUCCESS) { if (worldServer.getType(blockPos).interact(worldServer, fakePlayer, EnumHand.MAIN_HAND, rayTrace).a()) { result = EnumInteractionResult.SUCCESS; } else { result = stack.getItem().a(worldServer, fakePlayer, EnumHand.MAIN_HAND).a(); } } return result == EnumInteractionResult.SUCCESS; }
Example #24
Source File: Spigot_v1_14_R4.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Override public BaseBlock getBlock(Location location) { checkNotNull(location); CraftWorld craftWorld = ((CraftWorld) location.getWorld()); int x = location.getBlockX(); int y = location.getBlockY(); int z = location.getBlockZ(); final WorldServer handle = craftWorld.getHandle(); Chunk chunk = handle.getChunkAt(x >> 4, z >> 4); final BlockPosition blockPos = new BlockPosition(x, y, z); final IBlockData blockData = chunk.getType(blockPos); int internalId = Block.getCombinedId(blockData); BlockState state = BlockStateIdAccess.getBlockStateById(internalId); if (state == null) { org.bukkit.block.Block bukkitBlock = location.getBlock(); state = BukkitAdapter.adapt(bukkitBlock.getBlockData()); } // Read the NBT data TileEntity te = chunk.a(blockPos, Chunk.EnumTileEntityState.CHECK); if (te != null) { NBTTagCompound tag = new NBTTagCompound(); readTileEntityIntoTag(te, tag); // Load data return state.toBaseBlock((CompoundTag) toNative(tag)); } return state.toBaseBlock(); }
Example #25
Source File: Spigot_v1_14_R4.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Override public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) { final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); final BaseItemStack weStack = new BaseItemStack(BukkitAdapter.asItemType(itemStack.getType()), itemStack.getAmount()); weStack.setNbtData(((CompoundTag) toNative(nmsStack.getTag()))); return weStack; }
Example #26
Source File: Spigot_v1_14_R4.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean simulateItemUse(org.bukkit.World world, BlockVector3 position, BaseItem item, Direction face) { CraftWorld craftWorld = (CraftWorld) world; WorldServer worldServer = craftWorld.getHandle(); ItemStack stack = CraftItemStack.asNMSCopy(BukkitAdapter.adapt(item instanceof BaseItemStack ? ((BaseItemStack) item) : new BaseItemStack(item.getType(), item.getNbtData(), 1))); stack.setTag((NBTTagCompound) fromNative(item.getNbtData())); FakePlayer_v1_14_R4 fakePlayer; try { fakePlayer = fakePlayers.get(worldServer); } catch (ExecutionException ignored) { return false; } fakePlayer.a(EnumHand.MAIN_HAND, stack); fakePlayer.setLocation(position.getBlockX(), position.getBlockY(), position.getBlockZ(), (float) face.toVector().toYaw(), (float) face.toVector().toPitch()); final BlockPosition blockPos = new BlockPosition(position.getBlockX(), position.getBlockY(), position.getBlockZ()); final Vec3D blockVec = new Vec3D(blockPos); final EnumDirection enumFacing = adapt(face); MovingObjectPositionBlock rayTrace = new MovingObjectPositionBlock(blockVec, enumFacing, blockPos, false); ItemActionContext context = new ItemActionContext(fakePlayer, EnumHand.MAIN_HAND, rayTrace); EnumInteractionResult result = stack.placeItem(context, EnumHand.MAIN_HAND); if (result != EnumInteractionResult.SUCCESS) { if (worldServer.getType(blockPos).interact(worldServer, fakePlayer, EnumHand.MAIN_HAND, rayTrace)) { result = EnumInteractionResult.SUCCESS; } else { result = stack.getItem().a(worldServer, fakePlayer, EnumHand.MAIN_HAND).a(); } } return result == EnumInteractionResult.SUCCESS; }
Example #27
Source File: WorldNativeAccess_v1_14_R4.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Override public IBlockData toNative(com.sk89q.worldedit.world.block.BlockState state) { int stateId = BlockStateIdAccess.getBlockStateId(state); return BlockStateIdAccess.isValidInternalId(stateId) ? Block.getByCombinedId(stateId) : ((CraftBlockData) BukkitAdapter.adapt(state)).getState(); }
Example #28
Source File: Spigot_v1_13_R2_2.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Override public BaseBlock getBlock(Location location) { checkNotNull(location); CraftWorld craftWorld = ((CraftWorld) location.getWorld()); int x = location.getBlockX(); int y = location.getBlockY(); int z = location.getBlockZ(); final WorldServer handle = craftWorld.getHandle(); Chunk chunk = handle.getChunkAt(x >> 4, z >> 4); final IBlockData blockData = chunk.getBlockData(x, y, z); int internalId = Block.getCombinedId(blockData); BlockState state = BlockStateIdAccess.getBlockStateById(internalId); if (state == null) { org.bukkit.block.Block bukkitBlock = location.getBlock(); state = BukkitAdapter.adapt(bukkitBlock.getBlockData()); } // Read the NBT data TileEntity te = handle.getTileEntity(new BlockPosition(x, y, z)); if (te != null) { NBTTagCompound tag = new NBTTagCompound(); readTileEntityIntoTag(te, tag); // Load data return state.toBaseBlock((CompoundTag) toNative(tag)); } return state.toBaseBlock(); }
Example #29
Source File: Spigot_v1_13_R2_2.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Override public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) { final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); final BaseItemStack weStack = new BaseItemStack(BukkitAdapter.asItemType(itemStack.getType()), itemStack.getAmount()); weStack.setNbtData(((CompoundTag) toNative(nmsStack.getTag()))); return weStack; }
Example #30
Source File: WorldNativeAccess_v1_13_R2_2.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Override public IBlockData toNative(com.sk89q.worldedit.world.block.BlockState state) { int stateId = BlockStateIdAccess.getBlockStateId(state); return BlockStateIdAccess.isValidInternalId(stateId) ? Block.getByCombinedId(stateId) : ((CraftBlockData) BukkitAdapter.adapt(state)).getState(); }