com.sk89q.worldedit.math.BlockVector3 Java Examples
The following examples show how to use
com.sk89q.worldedit.math.BlockVector3.
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: WorldGuardHandler.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
public static boolean isIslandIntersectingSpawn(Location islandLocation) { log.entering(CN, "isIslandIntersectingSpawn", islandLocation); try { int r = Settings.general_spawnSize; if (r == 0) { return false; } ProtectedRegion spawn = new ProtectedCuboidRegion("spawn", BlockVector3.at(-r, 0, -r), BlockVector3.at(r, 255, r)); ProtectedCuboidRegion islandRegion = getIslandRegion(islandLocation); return !islandRegion.getIntersectingRegions(Collections.singletonList(spawn)).isEmpty(); } catch (Exception e) { log.log(Level.SEVERE, "Unable to locate intersecting regions", e); return false; } finally { log.exiting(CN, "isIslandIntersectingSpawn"); } }
Example #2
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 #3
Source File: FAWEAdaptor.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
@Override public void loadIslandSchematic(final File file, final Location origin, final PlayerPerk playerPerk) { plugin.async(() -> { log.finer("Trying to load schematic " + file); if (file == null || !file.exists() || !file.canRead()) { LogUtil.log(Level.WARNING, "Unable to load schematic " + file); } BlockVector3 to = BlockVector3.at(origin.getBlockX(), origin.getBlockY(), origin.getBlockZ()); EditSession editSession = getEditSession(playerPerk, origin); try { ClipboardFormats .findByFile(file) .load(file) .paste(editSession, to, false); editSession.flushQueue(); } catch (IOException e) { log.log(Level.INFO, "Unable to paste schematic " + file, e); } }); }
Example #4
Source File: WorldEditHook.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@Subscribe public void wrapForLogging(EditSessionEvent event) { event.setExtent(new AbstractDelegateExtent(event.getExtent()) { @Override public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 pos, T block) throws WorldEditException { if (block.getBlockType().getMaterial().isAir()) { World world = Bukkit.getWorld(event.getWorld().getName()); if (world != null) { Location l = new Location(world, pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); if (BlockStorage.hasBlockInfo(l)) { BlockStorage.clearBlockInfo(l); } } } return getExtent().setBlock(pos, block); } }); }
Example #5
Source File: RegionCommand.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
private void showRegion(Player player, int y, BlockVector3 minP, BlockVector3 maxP) { World world = player.getWorld(); List<Location> points = new ArrayList<>(); for (int x = minP.getBlockX(); x <= maxP.getBlockX(); x+=dash) { points.add(new Location(world, x+0.5d, y, minP.getBlockZ()+0.5d)); } for (int z = minP.getBlockZ(); z <= maxP.getBlockZ(); z+=dash) { points.add(new Location(world, maxP.getBlockX()+0.5d, y, z+0.5d)); } for (int x = maxP.getBlockX(); x >= minP.getBlockX(); x-=dash) { points.add(new Location(world, x+0.5d, y, maxP.getBlockZ()+0.5d)); } for (int z = maxP.getBlockZ(); z >= minP.getBlockZ(); z-=dash) { points.add(new Location(world, minP.getBlockX()+0.5d, y, z+0.5d)); } addAnimation(player, points); }
Example #6
Source File: WorldGuardSevenCommunicator.java From WorldGuardExtraFlagsPlugin with MIT License | 6 votes |
@Override public boolean doUnloadChunkFlagCheck(org.bukkit.World world, Chunk chunk) { for (ProtectedRegion region : this.getRegionContainer().get(world).getApplicableRegions(new ProtectedCuboidRegion("UnloadChunkFlagTester", BlockVector3.at(chunk.getX() * 16, 0, chunk.getZ() * 16), BlockVector3.at(chunk.getX() * 16 + 15, 256, chunk.getZ() * 16 + 15)))) { if (region.getFlag(Flags.CHUNK_UNLOAD) == State.DENY) { if (WorldGuardSevenCommunicator.supportsForceLoad) { chunk.setForceLoaded(true); chunk.load(true); return true; } return false; } } return true; }
Example #7
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 #8
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 #9
Source File: Spigot_v1_16_R1.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void sendFakeNBT(Player player, BlockVector3 pos, CompoundTag nbtData) { ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutTileEntityData( new BlockPosition(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()), 7, (NBTTagCompound) fromNative(nbtData) )); }
Example #10
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 #11
Source File: WorldGuardHandler.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
public static ProtectedCuboidRegion getIslandRegion(Location islandLocation) { int r = Settings.island_radius; BlockVector3 islandCenter = BlockVector3.at(islandLocation.getBlockX(), 0, islandLocation.getBlockZ()); return new ProtectedCuboidRegion( String.format("%d,%disland", islandCenter.getBlockX(), islandLocation.getBlockZ()), getProtectionVectorLeft(islandLocation), getProtectionVectorRight(islandLocation)); }
Example #12
Source File: WorldGuardHandler7_beta_2.java From AreaShop with GNU General Public License v3.0 | 5 votes |
@Override public Set<ProtectedRegion> getApplicableRegionsSet(Location location) { Set<ProtectedRegion> result = new HashSet<>(); BlockVector3 vector = BlockVector3.at(location.getX(), location.getY(), location.getZ()); for(ProtectedRegion region : getRegionManager(location.getWorld()).getRegions().values()) { if(region.contains(vector)) { result.add(region); } } return result; }
Example #13
Source File: WorldEditHandlerTest.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@Test public void testBorderXPosMax() { Region region = new CuboidRegion(BlockVector3.at(0,0,0), BlockVector3.at(16, 15, 15)); Set<Region> borderRegions = WorldEditHandler.getBorderRegions(region); Set<Region> expected = new HashSet<>(Arrays.<Region>asList( new CuboidRegion(BlockVector3.at(16,0,0), BlockVector3.at(16,15,15)) )); verifySame(borderRegions, expected); }
Example #14
Source File: WorldEditHandlerTest.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@Test public void testBorderXPosMin() { Region region = new CuboidRegion(BlockVector3.at(15,0,0), BlockVector3.at(31, 15, 15)); Set<Region> borderRegions = WorldEditHandler.getBorderRegions(region); Set<Region> expected = new HashSet<>(Arrays.<Region>asList( new CuboidRegion(BlockVector3.at(15,0,0), BlockVector3.at(15,15,15)) )); verifySame(borderRegions, expected); }
Example #15
Source File: WorldEditHandlerTest.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@Test public void testBorderXNegMax() { Region region = new CuboidRegion(BlockVector3.at(-16,0,-16), BlockVector3.at(0, 15, -1)); Set<Region> borderRegions = WorldEditHandler.getBorderRegions(region); Set<Region> expected = new HashSet<>(Arrays.<Region>asList( new CuboidRegion(BlockVector3.at(0,0,-16), BlockVector3.at(0,15,-1)) )); verifySame(borderRegions, expected); }
Example #16
Source File: WorldEditHandlerTest.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@Test public void testBorderXNegMin() { Region region = new CuboidRegion(BlockVector3.at(-17,0,-16), BlockVector3.at(-1, 15, -1)); Set<Region> borderRegions = WorldEditHandler.getBorderRegions(region); Set<Region> expected = new HashSet<>(Arrays.<Region>asList( new CuboidRegion(BlockVector3.at(-17,0,-16), BlockVector3.at(-17,15,-1)) )); verifySame(borderRegions, expected); }
Example #17
Source File: WorldEditHandlerTest.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@Test public void testBorderZPos() { Region region = new CuboidRegion(BlockVector3.at(0,0,0), BlockVector3.at(15, 15, 16)); Set<Region> borderRegions = WorldEditHandler.getBorderRegions(region); Set<Region> expected = new HashSet<>(Arrays.<Region>asList( new CuboidRegion(BlockVector3.at(0,0,16), BlockVector3.at(15,15,16)) )); verifySame(borderRegions, expected); }
Example #18
Source File: WorldEditHandlerTest.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
/** * <pre> * +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+ * | | | | | | | | | | | * | | | | | | | | | | | * | | |x=======================x B | | | | * +-----+-----+|----+-----+-----+-----+|----+-----+-----+-----+ * | | || | | | || | | | | * | | || | | | || | | | | * +-----+-----+|----+-----+-----+-----+|----+-----+-----+-----+ * | | || | | | || | | | | * | | || | | 0,0 | || | | | | * +-----+-----+|----+-----0-----+-----+|----+-----+-----+-----+ * | | || | | | || | | | | * | | || | | | || | | | | * +-----+-----+|----+-----+-----+-----+|----+-----+-----+-----+ * | | || A | | | || | | | | * | | |x=======================x | | | | * +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+ * A = -31, -31 * B = 32, 32 * </pre> * @throws Exception */ @Test public void testGetBorderRegionsUnaligned4Quadrants() throws Exception { Region region = new CuboidRegion(BlockVector3.at(-31,0,-31), BlockVector3.at(32, 15, 32)); Set<Region> borderRegions = WorldEditHandler.getBorderRegions(region); Set<Region> expectedBorder = new HashSet<>(Arrays.<Region>asList( new CuboidRegion(BlockVector3.at(-16,0,32), BlockVector3.at(31,15,32)), new CuboidRegion(BlockVector3.at(-16,0,-31), BlockVector3.at(31,15,-17)), new CuboidRegion(BlockVector3.at(-31,0,-31), BlockVector3.at(-17,15,32)), new CuboidRegion(BlockVector3.at(32,0,-31), BlockVector3.at(32,15,32)) )); Set<BlockVector2> expectedInner = new HashSet<>(); for (int x = -1; x <= 1; x++) { for (int z = -1; z <= 1; z++) { expectedInner.add(BlockVector2.at(x, z)); } } Set<BlockVector2> expectedOuter = new HashSet<>(); for (int x = -2; x <= 2; x++) { for (int z = -2; z <= 2; z++) { expectedOuter.add(BlockVector2.at(x, z)); } } verifySame(borderRegions, expectedBorder); assertThat(WorldEditHandler.getInnerChunks(region), is(expectedInner)); assertThat(WorldEditHandler.getOuterChunks(region), is(expectedOuter)); }
Example #19
Source File: WorldEditHandlerTest.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@Test public void testGetBorderRegionsAligned4Quadrants() throws Exception { Region region = new CuboidRegion(BlockVector3.at(-64,0,-64), BlockVector3.at(63, 15, 63)); Set<Region> borderRegions = WorldEditHandler.getBorderRegions(region); Set<Region> expectedBorder = new HashSet<>(Arrays.<Region>asList()); Set<BlockVector2> expectedInner = new HashSet<>(); for (int x = -4; x <= 3; x++) { for (int z = -4; z <= 3; z++) { expectedInner.add(BlockVector2.at(x, z)); } } verifySame(borderRegions, expectedBorder); assertThat(WorldEditHandler.getInnerChunks(region), is(expectedInner)); assertThat(WorldEditHandler.getOuterChunks(region), is(expectedInner)); }
Example #20
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 #21
Source File: RadiationCommandHandler.java From CraftserveRadiation with Apache License 2.0 | 5 votes |
private ProtectedCuboidRegion createCuboid(String regionId, BlockVector3 origin, int radius) { Objects.requireNonNull(regionId, "regionId"); Objects.requireNonNull(origin, "origin"); BlockVector3 min = origin.subtract(radius, 0, radius).withY(0); BlockVector3 max = origin.add(radius, 0, radius).withY(255); return new ProtectedCuboidRegion(regionId, min, max); }
Example #22
Source File: WorldEdit7.java From IridiumSkyblock with GNU General Public License v2.0 | 5 votes |
@Override public void paste(File file, Location location, Island island) { try { ClipboardFormat format = ClipboardFormats.findByFile(file); ClipboardReader reader = format.getReader(new FileInputStream(file)); Clipboard clipboard = reader.read(); try (EditSession editSession = com.sk89q.worldedit.WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(location.getWorld()), -1)) { Operation operation = new ClipboardHolder(clipboard) .createPaste(editSession) .to(BlockVector3.at(location.getX(), location.getY(), location.getZ())) .copyEntities(true) .ignoreAirBlocks(true) .build(); Operations.complete(operation); } } catch (Exception e) { IridiumSkyblock.getInstance().getLogger().warning("Failed to paste schematic using worldedit"); IridiumSkyblock.schematic.paste(file, location, island); } }
Example #23
Source File: SchematicHandler13.java From UhcCore with GNU General Public License v3.0 | 5 votes |
public static ArrayList<Integer> pasteSchematic(Location loc, String path) throws Exception{ Bukkit.getLogger().info("[UhcCore] Pasting "+path); File schematic = new File(path); World world = BukkitAdapter.adapt(loc.getWorld()); ClipboardFormat format = ClipboardFormats.findByFile(schematic); ClipboardReader reader = format.getReader(new FileInputStream(schematic)); Clipboard clipboard = reader.read(); EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1); enableWatchdog(editSession); Operation operation = new ClipboardHolder(clipboard) .createPaste(editSession) .to(BlockVector3.at(loc.getX(), loc.getY(), loc.getZ())) .ignoreAirBlocks(false) .build(); Operations.complete(operation); editSession.flushSession(); ArrayList<Integer> dimensions = new ArrayList<>(); dimensions.add(clipboard.getDimensions().getY()); dimensions.add(clipboard.getDimensions().getX()); dimensions.add(clipboard.getDimensions().getZ()); Bukkit.getLogger().info("[UhcCore] Successfully pasted '"+path+"' at "+loc.getBlockX()+" "+loc.getBlockY()+" "+loc.getBlockZ()); return dimensions; }
Example #24
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 #25
Source File: Spigot_v1_13_R2_2.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void sendFakeNBT(org.bukkit.entity.Player player, BlockVector3 pos, CompoundTag nbtData) { ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutTileEntityData( new BlockPosition(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()), 7, (NBTTagCompound) fromNative(nbtData) )); }
Example #26
Source File: WorldEditFlagHandler.java From WorldGuardExtraFlagsPlugin with MIT License | 5 votes |
@Override public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { ApplicableRegionSet regions = WorldGuard.getInstance().getPlatform().getRegionContainer().get(this.weWorld).getApplicableRegions(location); State state = WorldGuardUtils.queryState(this.player, this.world, regions.getRegions(), Flags.WORLDEDIT); if (state != State.DENY) { return super.setBlock(location, block); } return false; }
Example #27
Source File: WorldGuardSevenCommunicator.java From WorldGuardExtraFlagsPlugin with MIT License | 5 votes |
@Override public void doUnloadChunkFlagCheck(org.bukkit.World world) { for (ProtectedRegion region : this.getRegionContainer().get(world).getRegions().values()) { if (region.getFlag(Flags.CHUNK_UNLOAD) == State.DENY) { System.out.println("Loading chunks for region " + region.getId() + " located in " + world.getName() + " due to chunk-unload flag being deny"); BlockVector3 min = region.getMinimumPoint(); BlockVector3 max = region.getMaximumPoint(); for(int x = min.getBlockX() >> 4; x <= max.getBlockX() >> 4; x++) { for(int z = min.getBlockZ() >> 4; z <= max.getBlockZ() >> 4; z++) { world.getChunkAt(x, z).load(true); if (WorldGuardSevenCommunicator.supportsForceLoad) { world.getChunkAt(x, z).setForceLoaded(true); } } } } } }
Example #28
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 #29
Source File: Spigot_v1_14_R4.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void sendFakeNBT(Player player, BlockVector3 pos, CompoundTag nbtData) { ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutTileEntityData( new BlockPosition(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()), 7, (NBTTagCompound) fromNative(nbtData) )); }
Example #30
Source File: WEHook.java From RedProtect with GNU General Public License v3.0 | 5 votes |
private static void setSelection(BukkitWorld ws, Player p, Location pos1, Location pos2) { WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); RegionSelector regs = worldEdit.getSession(p).getRegionSelector(ws); regs.selectPrimary(BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()), null); regs.selectSecondary(BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ()), null); worldEdit.getSession(p).setRegionSelector(ws, regs); worldEdit.getSession(p).dispatchCUISelection(worldEdit.wrapPlayer(p)); }