package me.yaruma.fightsystem.utils; import com.boydti.fawe.FaweAPI; import com.boydti.fawe.util.EditSessionBuilder; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.bukkit.selections.CuboidSelection; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.world.World; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Location; import org.bukkit.entity.Player; import java.io.File; import java.io.IOException; import java.util.HashSet; import java.util.Set; public class WorldEdit { public static void replace(Player player, int minX, int minY, int minZ, int maxX, int maxY, int maxZ) { World weWorld = new BukkitWorld(player.getWorld()); EditSession editSession = new EditSessionBuilder(weWorld).fastmode(true).build(); CuboidSelection cuboidSelection = new CuboidSelection(player.getWorld(), new Location(player.getWorld(), minX, minY, minZ), new Location(player.getWorld(), maxX, maxY, maxZ)); Set targetObsidian = new HashSet<>(); targetObsidian.add(new BaseBlock(49)); Set targetBedrock = new HashSet<>(); targetBedrock.add(new BaseBlock(7)); try { int tnt = editSession.replaceBlocks(cuboidSelection.getRegionSelector().getRegion(), targetObsidian, new BaseBlock(46)); int slime = editSession.replaceBlocks(cuboidSelection.getRegionSelector().getRegion(), targetBedrock, new BaseBlock(165)); editSession.flushQueue(); } catch (Exception ex){ ex.printStackTrace(); } } public static void pasteSchematic(File file, World world, Vector vector, boolean allowUndo, boolean pasteAir, AffineTransform affineTransform) { try { FaweAPI.load(file).paste(world, vector, allowUndo, pasteAir, affineTransform).flushQueue(); } catch (IOException e) { e.printStackTrace(); } } public static int countBlocks(Player player, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, BaseBlock baseBlock) { World weWorld = new BukkitWorld(player.getWorld()); EditSession editSession = new EditSessionBuilder(weWorld).fastmode(true).build(); CuboidSelection cuboidSelection = new CuboidSelection(player.getWorld(), new Location(player.getWorld(), minX, minY, minZ), new Location(player.getWorld(), maxX, maxY, maxZ)); Set target = new HashSet<>(); target.add(baseBlock); try { return editSession.countBlocks(cuboidSelection.getRegionSelector().getRegion(), target); } catch (IncompleteRegionException e) { e.printStackTrace(); } return 0; } public static void sendPlayerScheamticList(File folder, int currentPage, int filesPerPage, Player player) { File[] listOfFiles = folder.listFiles(); int pages = listOfFiles.length / filesPerPage; int currPage = currentPage; if(currPage > pages) { currPage = 0; } for(int i = currPage * filesPerPage; i < (currPage * filesPerPage) + filesPerPage; i++) { TextComponent schematics = new TextComponent(listOfFiles[i].toString()); schematics.setColor(ChatColor.AQUA); schematics.setBold(true); schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Schematic benutzen...").create())); schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "")); //COMMAND MISSING player.spigot().sendMessage(schematics); TextComponent nextPage = new TextComponent("Naechste Seite"); nextPage.setColor(ChatColor.RED); nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Naechste Seite...").create())); nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "")); //COMMAND MISSING player.spigot().sendMessage(nextPage); } } }