com.sk89q.worldedit.bukkit.BukkitWorld Java Examples
The following examples show how to use
com.sk89q.worldedit.bukkit.BukkitWorld.
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: SchematicHelper.java From FunnyGuilds with Apache License 2.0 | 8 votes |
public static boolean pasteSchematic(File schematicFile, Location location, boolean withAir) { try { Vector pasteLocation = new Vector(location.getX(), location.getY(), location.getZ()); World pasteWorld = new BukkitWorld(location.getWorld()); WorldData pasteWorldData = pasteWorld.getWorldData(); Clipboard clipboard = ClipboardFormat.SCHEMATIC.getReader(new FileInputStream(schematicFile)).read(pasteWorldData); ClipboardHolder clipboardHolder = new ClipboardHolder(clipboard, pasteWorldData); EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(pasteWorld, -1); Operation operation = clipboardHolder .createPaste(editSession, pasteWorldData) .to(pasteLocation) .ignoreAirBlocks(!withAir) .build(); Operations.completeLegacy(operation); return true; } catch (IOException | MaxChangedBlocksException e) { FunnyGuilds.getInstance().getPluginLogger().error("Could not paste schematic: " + schematicFile.getAbsolutePath(), e); return false; } }
Example #2
Source File: WorldEdit6.java From IridiumSkyblock with GNU General Public License v2.0 | 6 votes |
@Override public void paste(File file, Location location, Island island) { try { EditSession editSession = (com.sk89q.worldedit.EditSession) EditSession.newInstance(new BukkitWorld(location.getWorld()), 999999999); editSession.enableQueue(); SchematicFormat schematic = SchematicFormat.getFormat(file); CuboidClipboard clipboard = schematic.load(file); clipboard.paste(editSession, BukkitUtil.toVector(location.clone().add(clipboard.getWidth() / 2.00, clipboard.getHeight() / 2.00, clipboard.getLength() / 2.00)), true); flush.invoke(editSession); } catch (Exception e) { IridiumSkyblock.getInstance().getLogger().warning("Failed to paste schematic using worldedit"); IridiumSkyblock.schematic.paste(file, location, island); } }
Example #3
Source File: SchematicHandler8.java From UhcCore with GNU General Public License v3.0 | 6 votes |
public static ArrayList<Integer> pasteSchematic(Location loc, String path) throws Exception{ WorldEditPlugin we = (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"); Bukkit.getLogger().info("[UhcCore] Pasting "+path); File schematic = new File(path); EditSession session = we.getWorldEdit().getEditSessionFactory().getEditSession(new BukkitWorld(loc.getWorld()), -1); CuboidClipboard clipboard = MCEditSchematicFormat.getFormat(schematic).load(schematic); clipboard.paste(session, new Vector(loc.getBlockX(),loc.getBlockY(),loc.getBlockZ()), false); ArrayList<Integer> dimensions = new ArrayList<>(); dimensions.add(clipboard.getHeight()); dimensions.add(clipboard.getLength()); dimensions.add(clipboard.getWidth()); Bukkit.getLogger().info("[UhcCore] Successfully pasted '"+path+"' at "+loc.getBlockX()+" "+loc.getBlockY()+" "+loc.getBlockZ()); return dimensions; }
Example #4
Source File: WorldEditFlagHandler.java From WorldGuardExtraFlagsPlugin with MIT License | 6 votes |
public WorldEditFlagHandler(World world, Extent extent, Player player) { super(extent); this.weWorld = world; if (world instanceof BukkitWorld) { this.world = ((BukkitWorld)world).getWorld(); } else { this.world = Bukkit.getWorld(world.getName()); } this.player = Bukkit.getPlayer(player.getUniqueId()); }
Example #5
Source File: WorldEditClear.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
@Override protected boolean execute() { while (!regions.isEmpty()) { final Region region = regions.remove(0); final EditSession editSession = WorldEditHandler.createEditSession( new BukkitWorld(world), region.getArea() * 255); editSession.setReorderMode(EditSession.ReorderMode.MULTI_STAGE); editSession.setFastMode(true); try { editSession.setBlocks(region, BlockTypes.AIR.getDefaultState()); } catch (MaxChangedBlocksException e) { log.log(Level.INFO, "Warning: we got MaxChangedBlocks from WE, please increase it!"); } editSession.flushSession(); if (!tick()) { break; } } return regions.isEmpty(); }
Example #6
Source File: WorldEditFlagHandler.java From WorldGuardExtraFlagsPlugin with MIT License | 5 votes |
protected WorldEditFlagHandler(World world, Extent extent, Player player) { super(extent); if (world instanceof BukkitWorld) { this.world = ((BukkitWorld)world).getWorld(); } else { this.world = Bukkit.getWorld(world.getName()); } this.player = Bukkit.getPlayer(player.getUniqueId()); }
Example #7
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)); }
Example #8
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 #9
Source File: WEHook.java From RedProtect with GNU General Public License v3.0 | 5 votes |
public static void setSelectionFromRP(Player p, Location pos1, Location pos2) { WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); BukkitWorld ws = new BukkitWorld(p.getWorld()); if (worldEdit.getSession(p) == null || !worldEdit.getSession(p).isSelectionDefined(ws)) { setSelection(ws, p, pos1, pos2); } else { worldEdit.getSession(p).getRegionSelector(ws).clear(); RedProtect.get().lang.sendMessage(p, RedProtect.get().lang.get("cmdmanager.region.select-we.hide")); } worldEdit.getSession(p).dispatchCUISelection(worldEdit.wrapPlayer(p)); }
Example #10
Source File: Game.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
public Game(HeavySpleef heavySpleef, String name, World world) { this.heavySpleef = heavySpleef; this.name = name; this.world = world; this.worldEditWorld = new BukkitWorld(world); this.i18n = I18NManager.getGlobal(); this.ingamePlayers = Sets.newLinkedHashSet(); this.deadPlayers = Lists.newArrayList(); this.eventBus = heavySpleef.getGlobalEventBus().newChildBus(); this.statisticRecorder = new StatisticRecorder(heavySpleef, heavySpleef.getLogger()); this.regeneratorFactory = new FloorRegeneratorFactory(); this.killedPlayers = Lists.newArrayList(); this.killedLobbyPlayers = Lists.newArrayList(); eventBus.registerListener(statisticRecorder); setGameState(GameState.WAITING); DefaultConfig configuration = heavySpleef.getConfiguration(ConfigType.DEFAULT_CONFIG); FlagManager.GamePropertyBundle defaults = new FlagManager.DefaultGamePropertyBundle(configuration.getProperties()); this.flagManager = new FlagManager(heavySpleef.getPlugin(), defaults); this.extensionManager = heavySpleef.getExtensionRegistry().newManagerInstance(eventBus); this.deathzones = Maps.newHashMap(); this.blocksBroken = HashBiMap.create(); this.killDetector = new DefaultKillDetector(); this.queuedPlayers = new LinkedList<SpleefPlayer>(); this.spawnLocationQueue = new LinkedList<Location>(); //Concurrent map for database schematics this.floors = new ConcurrentHashMap<String, Floor>(); WorldEditHook hook = (WorldEditHook) heavySpleef.getHookManager().getHook(HookReference.WORLDEDIT); WorldEdit worldEdit = hook.getWorldEdit(); this.editSessionFactory = worldEdit.getEditSessionFactory(); GeneralSection generalSection = configuration.getGeneralSection(); this.joinRequester = new JoinRequester(this, heavySpleef.getPvpTimerManager()); this.joinRequester.setPvpTimerMode(generalSection.getPvpTimer() > 0); }
Example #11
Source File: WorldEditHandler.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
public static void loadIslandSchematic(final File file, final Location origin, PlayerPerk playerPerk) { log.finer("Trying to load schematic " + file); if (file == null || !file.exists() || !file.canRead()) { LogUtil.log(Level.WARNING, "Unable to load schematic " + file); } boolean noAir = false; BlockVector3 to = BlockVector3.at(origin.getBlockX(), origin.getBlockY(), origin.getBlockZ()); EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(origin.getWorld()), -1); editSession.setFastMode(true); ProtectedRegion region = WorldGuardHandler.getIslandRegionAt(origin); if (region != null) { editSession.setMask(new RegionMask(getRegion(origin.getWorld(), region))); } try { ClipboardFormat clipboardFormat = ClipboardFormats.findByFile(file); try (InputStream in = new FileInputStream(file)) { Clipboard clipboard = clipboardFormat.getReader(in).read(); Operation operation = new ClipboardHolder(clipboard) .createPaste(editSession) .to(to) .ignoreAirBlocks(noAir) .build(); Operations.completeBlindly(operation); } editSession.flushSession(); } catch (IOException e) { log.log(Level.INFO, "Unable to paste schematic " + file, e); } }
Example #12
Source File: WorldEditClearFlatlandTask.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
public WorldEditClearFlatlandTask(final uSkyBlock plugin, final CommandSender commandSender, final Region region, final String format) { super(plugin); setOnCompletion(() -> { String duration = TimeUtil.millisAsString(WorldEditClearFlatlandTask.this.getTimeElapsed()); log(Level.INFO, String.format("Region %s was cleared in %s", region.toString(), duration)); commandSender.sendMessage(String.format(format, duration)); }); this.plugin = plugin; innerChunks = WorldEditHandler.getInnerChunks(region); borderRegions = WorldEditHandler.getBorderRegions(region); bukkitWorld = new BukkitWorld(plugin.getWorldManager().getWorld()); minY = Math.min(region.getMinimumPoint().getBlockY(), region.getMaximumPoint().getBlockY()); maxY = Math.max(region.getMinimumPoint().getBlockY(), region.getMaximumPoint().getBlockY()); maxBlocks = 2*Math.max(region.getLength(), region.getWidth())*16*(maxY-minY); }
Example #13
Source File: DeathzoneCommands.java From HeavySpleef with GNU General Public License v3.0 | 4 votes |
@Command(name = "adddeathzone", permission = Permissions.PERMISSION_ADD_DEATHZONE, minArgs = 1, descref = Messages.Help.Description.ADDDEATHZONE, usage = "/spleef adddeathzone <Game> [Deathzone-Name]") @PlayerOnly public void onCommandAddDeathzone(CommandContext context, HeavySpleef heavySpleef) throws CommandException { SpleefPlayer player = heavySpleef.getSpleefPlayer(context.getSender()); String gameName = context.getString(0); GameManager manager = heavySpleef.getGameManager(); CommandValidate.isTrue(manager.hasGame(gameName), i18n.getVarString(Messages.Command.GAME_DOESNT_EXIST) .setVariable("game", gameName) .toString()); Game game = manager.getGame(gameName); WorldEditPlugin plugin = (WorldEditPlugin) heavySpleef.getHookManager().getHook(HookReference.WORLDEDIT).getPlugin(); com.sk89q.worldedit.entity.Player bukkitPlayer = plugin.wrapPlayer(player.getBukkitPlayer()); World world = new BukkitWorld(player.getBukkitPlayer().getWorld()); LocalSession session = plugin.getWorldEdit().getSessionManager().get(bukkitPlayer); RegionSelector selector = session.getRegionSelector(world); Region region; try { region = selector.getRegion().clone(); } catch (IncompleteRegionException e) { player.sendMessage(i18n.getString(Messages.Command.DEFINE_FULL_WORLDEDIT_REGION)); return; } validateSelectedRegion(region); String deathzoneName = context.argsLength() > 1 ? context.getString(1) : generateUniqueDeathzoneName(game); game.addDeathzone(deathzoneName, region); player.sendMessage(i18n.getVarString(Messages.Command.DEATHZONE_ADDED) .setVariable("deathzonename", deathzoneName) .toString()); //Save the game heavySpleef.getDatabaseHandler().saveGame(game, null); }
Example #14
Source File: Spigot_v1_13_R2_2.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 4 votes |
@Override public boolean regenerate(org.bukkit.World bukkitWorld, Region region, EditSession editSession) { WorldServer originalWorld = ((CraftWorld) bukkitWorld).getHandle(); File saveFolder = Files.createTempDir(); // register this just in case something goes wrong // normally it should be deleted at the end of this method saveFolder.deleteOnExit(); saveFolder.deleteOnExit(); try { Environment env = bukkitWorld.getEnvironment(); ChunkGenerator gen = bukkitWorld.getGenerator(); MinecraftServer server = originalWorld.getServer().getServer(); WorldData newWorldData = new WorldData(originalWorld.worldData.a((NBTTagCompound) null), server.dataConverterManager, getDataVersion(), null); newWorldData.checkName("worldeditregentempworld"); WorldNBTStorage saveHandler = new WorldNBTStorage(saveFolder, originalWorld.getDataManager().getDirectory().getName(), server, server.dataConverterManager); try (WorldServer freshWorld = new WorldServer(server, saveHandler, new PersistentCollection(saveHandler), newWorldData, originalWorld.worldProvider.getDimensionManager(), originalWorld.methodProfiler, env, gen)) { freshWorld.savingDisabled = true; // Pre-gen all the chunks // We need to also pull one more chunk in every direction CuboidRegion expandedPreGen = new CuboidRegion(region.getMinimumPoint().subtract(16, 0, 16), region.getMaximumPoint().add(16, 0, 16)); for (BlockVector2 chunk : expandedPreGen.getChunks()) { freshWorld.getChunkAt(chunk.getBlockX(), chunk.getBlockZ()); } CraftWorld craftWorld = freshWorld.getWorld(); BukkitWorld from = new BukkitWorld(craftWorld); for (BlockVector3 vec : region) { editSession.setBlock(vec, from.getFullBlock(vec)); } } } catch (MaxChangedBlocksException e) { throw new RuntimeException(e); } finally { saveFolder.delete(); try { Map<String, org.bukkit.World> map = (Map<String, org.bukkit.World>) serverWorldsField.get(Bukkit.getServer()); map.remove("worldeditregentempworld"); } catch (IllegalAccessException ignored) { } } return true; }
Example #15
Source File: WorldGuardHandler.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
private static RegionManager getRegionManager(World world) { return getWorldGuard().getRegionContainer().get(new BukkitWorld(world)); }
Example #16
Source File: WorldEditHandler.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
public static Region getRegion(World skyWorld, ProtectedRegion region) { return new CuboidRegion(new BukkitWorld(skyWorld), region.getMinimumPoint(), region.getMaximumPoint()); }
Example #17
Source File: FAWEAdaptor.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
private synchronized EditSession getEditSession(PlayerPerk playerPerk, Location origin) { return createEditSession(new BukkitWorld(origin.getWorld()), -1); }
Example #18
Source File: WEHook.java From RedProtect with GNU General Public License v3.0 | 4 votes |
public static void regenRegion(final Region region, final World world, final Location p1, final Location p2, final int delay, final CommandSender sender, final boolean remove) { Bukkit.getScheduler().scheduleSyncDelayedTask(RedProtect.get(), () -> { if (RedProtect.get().getUtil().stopRegen) { return; } RegionSelector regs = new LocalSession().getRegionSelector(new BukkitWorld(world)); regs.selectPrimary(BlockVector3.at(p1.getX(), p1.getY(), p1.getZ()), null); regs.selectSecondary(BlockVector3.at(p2.getX(), p2.getY(), p2.getZ()), null); com.sk89q.worldedit.regions.Region wReg; try { wReg = regs.getRegion(); } catch (IncompleteRegionException e1) { e1.printStackTrace(); return; } try (EditSession eSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(world), -1)) { eSessions.put(region.getID(), eSession); int delayCount = 1 + delay / 10; com.sk89q.worldedit.world.World wRegWorld = wReg.getWorld(); if (wRegWorld == null) return; if (sender != null) { if (wRegWorld.regenerate(wReg, eSession)) { RedProtect.get().lang.sendMessage(sender, "[" + delayCount + "]" + " &aRegion " + region.getID().split("@")[0] + " regenerated with success!"); } else { RedProtect.get().lang.sendMessage(sender, "[" + delayCount + "]" + " &cTheres an error when regen the region " + region.getID().split("@")[0] + "!"); } } else { if (wRegWorld.regenerate(wReg, eSession)) { eSession.setMask(null); RedProtect.get().logger.warning("[" + delayCount + "]" + " &aRegion " + region.getID().split("@")[0] + " regenerated with success!"); } else { RedProtect.get().logger.warning("[" + delayCount + "]" + " &cTheres an error when regen the region " + region.getID().split("@")[0] + "!"); } } if (remove) { region.notifyRemove(); RedProtect.get().rm.remove(region, region.getWorld()); } if (delayCount % 50 == 0) { RedProtect.get().rm.saveAll(true); } if (RedProtect.get().config.configRoot().purge.regen.stop_server_every > 0 && delayCount > RedProtect.get().config.configRoot().purge.regen.stop_server_every) { Bukkit.getScheduler().cancelTasks(RedProtect.get()); RedProtect.get().rm.saveAll(false); Bukkit.getServer().shutdown(); } } }, delay); }
Example #19
Source File: WEHook.java From RedProtect with GNU General Public License v3.0 | 4 votes |
public static void setSelectionRP(Player p, Location pos1, Location pos2) { BukkitWorld ws = new BukkitWorld(p.getWorld()); setSelection(ws, p, pos1, pos2); }