From f06aa659cc7a7d683d3981aac5b8093ba0299527 Mon Sep 17 00:00:00 2001 From: Tom Roman Date: Mon, 29 Nov 2021 20:10:32 +0000 Subject: [PATCH] Showgen commands functional with worldedit 7 --- dependency-reduced-pom.xml | 8 +- pom.xml | 6 +- .../java/network/palace/show/ShowPlugin.java | 39 ++++- .../network/palace/show/TerrainManager.java | 89 +++++----- .../palace/show/commands/ShowgenCommand.java | 51 ++++++ .../commands/showgen/GenerateCommand.java | 162 ++++++++++++++++++ .../commands/showgen/SetCornerCommand.java | 36 ++++ .../commands/showgen/SetInitialCommand.java | 46 +++++ .../palace/show/generator/ShowGenerator.java | 12 +- src/main/resources/config.yml | 2 + 10 files changed, 390 insertions(+), 61 deletions(-) create mode 100644 src/main/java/network/palace/show/commands/ShowgenCommand.java create mode 100644 src/main/java/network/palace/show/commands/showgen/GenerateCommand.java create mode 100644 src/main/java/network/palace/show/commands/showgen/SetCornerCommand.java create mode 100644 src/main/java/network/palace/show/commands/showgen/SetInitialCommand.java create mode 100644 src/main/resources/config.yml diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index 1698fdf..45118e2 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -3,7 +3,7 @@ 4.0.0 network.palace Show - 1.5.8 + 1.6.0 ${project.artifactId} @@ -82,7 +82,7 @@ org.projectlombok lombok - 1.18.12 + 1.18.20 compile @@ -94,7 +94,7 @@ com.sk89q.worldedit worldedit-bukkit - 6.1.4-SNAPSHOT + 7.2.0-SNAPSHOT provided @@ -117,8 +117,8 @@ + 1.8 1.8 UTF-8 - 1.8 diff --git a/pom.xml b/pom.xml index 34c9f14..419677c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ network.palace Show - 1.5.8 + 1.6.0 enginehub-maven @@ -32,7 +32,7 @@ org.projectlombok lombok - 1.18.12 + 1.18.20 jar @@ -43,7 +43,7 @@ com.sk89q.worldedit worldedit-bukkit - 6.1.4-SNAPSHOT + 7.2.0-SNAPSHOT provided diff --git a/src/main/java/network/palace/show/ShowPlugin.java b/src/main/java/network/palace/show/ShowPlugin.java index 58a907f..46e7012 100644 --- a/src/main/java/network/palace/show/ShowPlugin.java +++ b/src/main/java/network/palace/show/ShowPlugin.java @@ -16,6 +16,7 @@ import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; @@ -26,6 +27,9 @@ import org.bukkit.plugin.java.annotation.plugin.*; import org.bukkit.plugin.java.annotation.plugin.author.Author; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.URL; import java.util.HashMap; import java.util.Map; @@ -33,7 +37,7 @@ * Created by Marc on 12/6/16. * Updated to be Core free by Tom 07/10/2021 */ -@Plugin(name = "Show", version = "1.5.8") +@Plugin(name = "Show", version = "1.6.0") @Description(value = "Create Shows in Minecraft with easy to use files!") @LoadOrder(value = PluginLoadOrder.POSTWORLD) @Author(value = "Legobuilder0813") @@ -47,7 +51,7 @@ @ApiVersion(value = ApiVersion.Target.v1_13) @Command(name = "show", desc = "Main show command", permission = "show.main", permissionMessage = "You do not have permission!", usage = "/show [list|start|stop]") @Command(name = "showdebug", desc = "Showdebug command", permission = "show.debug", permissionMessage = "You do not have permission!", usage = "/showdebug") - +@Command(name = "showgen", desc = "Showgen commands", permission = "show.showgen", permissionMessage = "You do not have permission!", usage = "/showgen") public class ShowPlugin extends JavaPlugin { @Getter private ArmorStandManager armorStandManager; @Getter private FountainManager fountainManager; @@ -57,6 +61,8 @@ public class ShowPlugin extends JavaPlugin { @Getter private final boolean isMinecraftGreaterOrEqualTo11_2 = MinecraftVersion.getCurrentVersion().getMinor() >= 12; @Getter private static AudioApi audioApi; @Getter private static OpenAudioMcSpigot openAudioMcSpigot; + @Getter private String githubToken; + @Getter private String serverIp; private static ShowPlugin instance; private static final HashMap shows = new HashMap<>(); @@ -71,7 +77,6 @@ public void onEnable() { instance = this; armorStandManager = new ArmorStandManager(); fountainManager = new FountainManager(); - showGenerator = new ShowGenerator(); buildUtil = new BuildUtil(); softNPCManager = new SoftNPCManager(); audioApi = AudioApi.getInstance(); @@ -80,6 +85,28 @@ public void onEnable() { this.getCommand("show").setExecutor(new ShowCommand()); this.getCommand("showdebug").setExecutor(new ShowDebugCommand()); + FileConfiguration config = this.getConfig(); + this.saveDefaultConfig(); + if (config.getString("github.token") != null) { + githubToken = config.getString("github.token"); + this.getCommand("showgen").setExecutor(new ShowgenCommand()); + Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "[Show] Showgen has been enabled in show!"); + } else { + Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[Show] Showgen will not be running in Show! To enable it, add a github token to the config!"); + } + try { + URL whatismyip = new URL("http://checkip.amazonaws.com"); + BufferedReader in = new BufferedReader(new InputStreamReader(whatismyip.openStream())); + serverIp = in.readLine(); + } catch (Exception e) { + Bukkit.getLogger().warning("Show could not obtain this machines IP. This is only used when generating gists so not essential"); + } + + + //has to be loaded after github token + showGenerator = new ShowGenerator(); + + this.getServer().getPluginManager().registerEvents(fountainManager, this); this.getServer().getPluginManager().registerEvents(new PlayerInteract(), this); this.getServer().getPluginManager().registerEvents(new ChunkListener(), this); @@ -101,12 +128,12 @@ public void onEnable() { new UpdateUtil(this, 94141).getVersion(v -> { if (!this.getDescription().getVersion().equalsIgnoreCase(v)) { - Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "A New update is available for Show! It is always recommended that you upgrade! Link: https://www.spigotmc.org/resources/show-make-huge-spectaculars-in-minecraft.94141/"); + Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[Show] A New update is available for Show! It is always recommended that you upgrade! Link: https://www.spigotmc.org/resources/show-make-huge-spectaculars-in-minecraft.94141/"); } }); - Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Show is now enabled!"); - Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Huge shoutout to Legobuilder0813 for making this work for The Palace Network. Time to let your awesome code shine"); + Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "[Show] Show is now enabled!"); + Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "[Show] Huge shoutout to Legobuilder0813 for making this work for The Palace Network. Time to let your awesome code shine"); } @Override diff --git a/src/main/java/network/palace/show/TerrainManager.java b/src/main/java/network/palace/show/TerrainManager.java index fba44e6..605fa5c 100644 --- a/src/main/java/network/palace/show/TerrainManager.java +++ b/src/main/java/network/palace/show/TerrainManager.java @@ -1,48 +1,48 @@ package network.palace.show; import com.sk89q.worldedit.*; +import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.bukkit.WorldEditPlugin; -import com.sk89q.worldedit.data.DataException; +import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; -import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader; +import com.sk89q.worldedit.extent.clipboard.io.*; +import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.Operations; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.schematic.SchematicFormat; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.util.io.Closer; -import com.sk89q.worldedit.util.io.file.FilenameException; -import com.sk89q.worldedit.world.registry.WorldData; import network.palace.show.utils.ShowUtil; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; +import java.io.*; +import java.util.Objects; @SuppressWarnings("deprecation") public class TerrainManager { - private final WorldEdit we; private final LocalSession localSession; private final EditSession editSession; - private final LocalPlayer localPlayer; + private final Player localPlayer; + private final WorldEdit we; /** * Constructor * - * @param wep the WorldEdit plugin instance + * @param wep the WorldEdit plugin instance * @param player the player to work with */ public TerrainManager(WorldEditPlugin wep, Player player) { + LocalSession worldEditSession = WorldEdit.getInstance().getSessionManager().get(BukkitAdapter.adapt(player)); we = wep.getWorldEdit(); - localPlayer = wep.wrapPlayer(player); - localSession = we.getSession(localPlayer); - editSession = localSession.createEditSession(localPlayer); + localSession = worldEditSession; + localPlayer = player; + editSession = worldEditSession.createEditSession(BukkitAdapter.adapt(player)); } /** @@ -55,7 +55,7 @@ public TerrainManager(WorldEditPlugin wep, World world) { we = wep.getWorldEdit(); localPlayer = null; localSession = new LocalSession(we.getConfiguration()); - editSession = new EditSession(new BukkitWorld(world), we.getConfiguration().maxChangeLimit); + editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(world)); } /** @@ -66,17 +66,23 @@ public TerrainManager(WorldEditPlugin wep, World world) { * @param l1 one corner of the region to save * @param l2 the corner of the region to save, opposite to l1 */ - public void saveTerrain(File saveFile, Location l1, Location l2) throws FilenameException, DataException, IOException { - Vector min = getMin(l1, l2); - Vector max = getMax(l1, l2); + public void saveTerrain(File saveFile, Location l1, Location l2) throws WorldEditException, IOException { + BlockVector3 min = getMin(l1, l2); + BlockVector3 max = getMax(l1, l2); + + saveFile = we.getSafeSaveFile(BukkitAdapter.adapt(localPlayer), saveFile.getParentFile(), saveFile.getName(), ".schematic", ".schematic"); - saveFile = we.getSafeSaveFile(localPlayer, saveFile.getParentFile(), saveFile.getName(), ".schematic", ".schematic"); + CuboidRegion region = new CuboidRegion(BukkitAdapter.adapt(Objects.requireNonNull(l1.getWorld())), min, max); + BlockArrayClipboard clipboard = new BlockArrayClipboard(region); - editSession.enableQueue(); - CuboidClipboard clipboard = new CuboidClipboard(max.subtract(min).add(new Vector(1, 1, 1)), min); - clipboard.copy(editSession); - SchematicFormat.MCEDIT.save(clipboard, saveFile); - editSession.flushQueue(); + EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(region.getWorld(), -1); + + ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint()); + forwardExtentCopy.setCopyingEntities(true); + Operations.complete(forwardExtentCopy); + try (ClipboardWriter writer = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(saveFile))) { + writer.write(clipboard); + } } public void loadSchematic(WorldEditPlugin wep, String fileName, Location loc, boolean noAir) throws Exception { @@ -86,34 +92,29 @@ public void loadSchematic(WorldEditPlugin wep, String fileName, Location loc, bo ShowUtil.logDebug("Schematics", "Tried to load Schematic " + fileName + " but does not exist!"); return; } - Closer closer = Closer.create(); - FileInputStream fis = closer.register(new FileInputStream(f)); - BufferedInputStream bis = closer.register(new BufferedInputStream(fis)); - ClipboardReader reader = ClipboardFormat.SCHEMATIC.getReader(bis); - WorldData worldData = new BukkitWorld(loc.getWorld()).getWorldData(); - Clipboard clipboard = reader.read(worldData); - localSession.setClipboard(new ClipboardHolder(clipboard, worldData)); - Region region = clipboard.getRegion(); - Vector to = new Vector(loc.getX(), loc.getY(), loc.getZ()); - Operation operation = localSession.getClipboard().createPaste(editSession, editSession.getWorld() - .getWorldData()).to(to).ignoreAirBlocks(noAir).build(); - Operations.completeLegacy(operation); - fis.close(); - bis.close(); + ClipboardFormat format = ClipboardFormats.findByFile(f); + try (ClipboardReader reader = format.getReader(new FileInputStream(f))) { + Clipboard clipboard = reader.read(); + localSession.setClipboard(new ClipboardHolder(clipboard)); + Region region = clipboard.getRegion(); + BlockVector3 to = BlockVector3.at(loc.getX(), loc.getY(), loc.getZ()); + Operation operation = localSession.getClipboard().createPaste(editSession).to(to).ignoreAirBlocks(noAir).build(); + Operations.completeLegacy(operation); + } } public void loadSchematic(WorldEditPlugin wep, String fileName, boolean noAir) throws Exception { loadSchematic(wep, fileName, null, noAir); } - private Vector getMin(Location l1, Location l2) { - return new Vector(Math.min(l1.getBlockX(), l2.getBlockX()), Math.min(l1.getBlockY(), l2.getBlockY()), + private BlockVector3 getMin(Location l1, Location l2) { + return BlockVector3.at(Math.min(l1.getBlockX(), l2.getBlockX()), Math.min(l1.getBlockY(), l2.getBlockY()), Math.min(l1.getBlockZ(), l2.getBlockZ()) ); } - private Vector getMax(Location l1, Location l2) { - return new Vector(Math.max(l1.getBlockX(), l2.getBlockX()), Math.max(l1.getBlockY(), l2.getBlockY()), + private BlockVector3 getMax(Location l1, Location l2) { + return BlockVector3.at(Math.max(l1.getBlockX(), l2.getBlockX()), Math.max(l1.getBlockY(), l2.getBlockY()), Math.max(l1.getBlockZ(), l2.getBlockZ()) ); } diff --git a/src/main/java/network/palace/show/commands/ShowgenCommand.java b/src/main/java/network/palace/show/commands/ShowgenCommand.java new file mode 100644 index 0000000..852797a --- /dev/null +++ b/src/main/java/network/palace/show/commands/ShowgenCommand.java @@ -0,0 +1,51 @@ +package network.palace.show.commands; + +import network.palace.show.commands.showgen.GenerateCommand; +import network.palace.show.commands.showgen.SetCornerCommand; +import network.palace.show.commands.showgen.SetInitialCommand; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; + +public class ShowgenCommand implements CommandExecutor { + + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (args.length == 0) { + sender.sendMessage(ChatColor.GREEN + "ShowGen Commands:"); + sender.sendMessage(ChatColor.AQUA + "/showgen generate [action] [bottom/top] [delay per layer] [timestamp]" + ChatColor.GREEN + "- Generate blocks of show actions with one command"); + sender.sendMessage(ChatColor.AQUA + "/showgen setcorner x,y,z" + ChatColor.GREEN + "- Set the location of the final north-west-bottom corner to help give real coordinate values"); + sender.sendMessage(ChatColor.AQUA + "/showgen setinitialscene " + ChatColor.GREEN + "- Set the initial scene for a generator session"); + return true; + } + + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "You must be a player to run this command!"); + } + + switch (args[0]) { + case "generate": + String[] newArgs = Arrays.copyOfRange(args, 1, args.length); + new GenerateCommand().handle(sender, newArgs); + break; + case "setcorner": + new SetCornerCommand().handle(sender, args); + break; + case "setinitialscene": + new SetInitialCommand().handle(sender); + break; + default: + sender.sendMessage(ChatColor.GREEN + "ShowGen Commands:"); + sender.sendMessage(ChatColor.AQUA + "/showgen generate [action] [bottom/top] [delay per layer] [timestamp]" + ChatColor.GREEN + "- Generate blocks of show actions with one command"); + sender.sendMessage(ChatColor.AQUA + "/showgen setcorner x,y,z" + ChatColor.GREEN + "- Set the location of the final north-west-bottom corner to help give real coordinate values"); + sender.sendMessage(ChatColor.AQUA + "/showgen setinitialscene " + ChatColor.GREEN + "- Set the initial scene for a generator session"); + break; + } + return true; + } +} diff --git a/src/main/java/network/palace/show/commands/showgen/GenerateCommand.java b/src/main/java/network/palace/show/commands/showgen/GenerateCommand.java new file mode 100644 index 0000000..a429c00 --- /dev/null +++ b/src/main/java/network/palace/show/commands/showgen/GenerateCommand.java @@ -0,0 +1,162 @@ +package network.palace.show.commands.showgen; + +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.Region; +import network.palace.show.ShowPlugin; +import network.palace.show.actions.FakeBlockAction; +import network.palace.show.generator.GeneratorSession; +import org.bukkit.*; +import org.bukkit.block.Block; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class GenerateCommand { + + public void handle(CommandSender sender, String[] args) { + Player player = (Player) sender; + GeneratorSession session = ShowPlugin.getShowGenerator().getOrCreateSession(player.getUniqueId()); + if (args.length < 2 || args.length == 3 || args.length > 4) { + player.sendMessage(ChatColor.RED + "/showgen generate [action] [timestamp]"); + player.sendMessage(ChatColor.RED + "OR"); + player.sendMessage(ChatColor.RED + "/showgen generate [action] [bottom/top] [delay per layer] [timestamp]"); + return; + } + + boolean layered = args.length >= 4; + + String action = args[0]; + double time; + try { + time = Double.parseDouble(args[layered ? 3 : 1]); + } catch (NumberFormatException e) { + player.sendMessage(ChatColor.RED + args[1] + " is not a number!"); + return; + } + if (args[0].equalsIgnoreCase("fakeblock")) { + if (session.getInitialScene() == null) { + player.sendMessage(ChatColor.RED + "You must set an initial scene before running this command! Use /showgen setinitialscene"); + return; + } + if (session.getCorner() == null) { + player.sendMessage(ChatColor.RED + "You must set the location of the final north-west-bottom corner to generate proper coordinates!"); + return; + } + GeneratorSession.ShowSelection initialScene = session.getInitialScene(); + Location corner = session.getCorner(); + + LocalSession worldEditSession = WorldEdit.getInstance().getSessionManager().get(BukkitAdapter.adapt(player)); + + try { + Region selection = worldEditSession.getSelection(worldEditSession.getSelectionWorld()); + + if (selection == null) { + player.sendMessage(ChatColor.RED + "You need to select the blocks for the second scene with your WorldEdit wand before running this command!"); + return; + } + + World world = BukkitAdapter.asBukkitWorld(selection.getWorld()).getWorld(); + BlockVector3 maxVec = selection.getMaximumPoint(); + BlockVector3 minVec = selection.getMinimumPoint(); + Location finalMax = new Location(world, maxVec.getX(), maxVec.getY(), maxVec.getZ()); + Location finalMin = new Location(world, minVec.getX(), minVec.getY(), minVec.getZ()); + + GeneratorSession.ShowSelection finalScene = new GeneratorSession.ShowSelection(finalMax, finalMin); + + if (!finalScene.equalSize(initialScene)) { + player.sendMessage(ChatColor.RED + "Your initial scene is not the same size as your current scene! They must be equal in order to generate the differences in their blocks."); + return; + } + + boolean bottom; + double delayPerLayer; + + if (layered) { + bottom = !args[1].equalsIgnoreCase("top"); + delayPerLayer = Double.parseDouble(args[2]); + } else { + bottom = false; + delayPerLayer = 0; + } + + player.sendMessage(ChatColor.GREEN + "Generating a list of " + args[0].toLowerCase() + " changes at time " + time + " between scene 1 at " + initialScene.toString() + " and scene 2 at " + finalScene.toString()); + Bukkit.getScheduler().runTaskAsynchronously(ShowPlugin.getInstance(), () -> { + List actions = new ArrayList<>(); + + double localTime = time; + + int startingY; + int endingY; + int yChange; + double changeInTime; + + if (!layered) { + startingY = 0; + endingY = initialScene.getYLength(); + yChange = 1; + changeInTime = 0; + } else { + startingY = bottom ? 0 : initialScene.getYLength(); + endingY = bottom ? initialScene.getYLength() : 0; + yChange = bottom ? 1 : -1; + changeInTime = delayPerLayer; + } + + for (int y = startingY; compare(y, endingY, !bottom); y += yChange) { + for (int x = 0; x < initialScene.getXLength(); x++) { + for (int z = 0; z < initialScene.getZLength(); z++) { + Block oldBlock = initialScene.getBlock(x, y, z); + Block newBlock = finalScene.getBlock(x, y, z); + if (newBlock.getType().equals(oldBlock.getType()) && newBlock.getData() == oldBlock.getData()) { + continue; + } + Material material = newBlock.getType(); + byte data = newBlock.getData(); + FakeBlockAction act = new FakeBlockAction(null, (long) (localTime * 1000)); + act.setMat(material); + act.setLoc(new Location(corner.getWorld(), corner.getBlockX() + x, corner.getBlockY() + y, corner.getBlockZ() + z)); + actions.add(act); + } + } + localTime += changeInTime; + } + + if (actions.isEmpty()) { + player.sendMessage(ChatColor.RED + "There aren't any differences between the two selected regions!"); + return; + } + + String date = new SimpleDateFormat("MM_dd_yyyy_HH:mm:ss").format(new Date()); + + String url; + try { + url = ShowPlugin.getShowGenerator().postGist(actions, finalMax.getWorld().getName() + "_" + date + "_" + player.getName()); + } catch (Exception e) { + e.printStackTrace(); + player.sendMessage(ChatColor.RED + "There was an error creating a GitHub Gist with the list of actions!"); + return; + } + player.sendMessage(ChatColor.GREEN + "Finished with a list of " + actions.size() + " actions! View the actions here: " + url); + }); + } catch (Exception e) { + player.sendMessage(ChatColor.RED + "Error! Did you select the whole region?"); + e.printStackTrace(); + } + + + return; + } + player.sendMessage(ChatColor.RED + "The show generator doesn't currently support '" + args[0] + "' actions."); + } + + private boolean compare(int x, int y, boolean inverted) { + return inverted == (x >= y); + } +} diff --git a/src/main/java/network/palace/show/commands/showgen/SetCornerCommand.java b/src/main/java/network/palace/show/commands/showgen/SetCornerCommand.java new file mode 100644 index 0000000..2733637 --- /dev/null +++ b/src/main/java/network/palace/show/commands/showgen/SetCornerCommand.java @@ -0,0 +1,36 @@ +package network.palace.show.commands.showgen; + +import network.palace.show.ShowPlugin; +import network.palace.show.generator.GeneratorSession; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class SetCornerCommand { + + public void handle(CommandSender sender, String[] args) { + Player player = (Player) sender; + if (args.length < 2) { + player.sendMessage(ChatColor.RED + "/showgen setcorner x,y,z"); + return; + } + String[] locData = args[1].split(","); + if (locData.length < 3) { + player.sendMessage(ChatColor.RED + "/showgen setcorner x,y,z"); + return; + } + try { + int x = Integer.parseInt(locData[0]); + int y = Integer.parseInt(locData[1]); + int z = Integer.parseInt(locData[2]); + World w = player.getWorld(); + GeneratorSession session = ShowPlugin.getShowGenerator().getOrCreateSession(player.getUniqueId()); + session.setCorner(new Location(w, x, y, z)); + player.sendMessage(ChatColor.GREEN + "Set north-west-bottom corner to " + x + "," + y + "," + z + "!"); + } catch (NumberFormatException e) { + player.sendMessage(ChatColor.RED + "Are you sure those are all numbers?"); + } + } +} diff --git a/src/main/java/network/palace/show/commands/showgen/SetInitialCommand.java b/src/main/java/network/palace/show/commands/showgen/SetInitialCommand.java new file mode 100644 index 0000000..203489f --- /dev/null +++ b/src/main/java/network/palace/show/commands/showgen/SetInitialCommand.java @@ -0,0 +1,46 @@ +package network.palace.show.commands.showgen; + +import com.sk89q.worldedit.IncompleteRegionException; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.Region; +import network.palace.show.ShowPlugin; +import network.palace.show.generator.GeneratorSession; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class SetInitialCommand { + + public void handle(CommandSender sender) { + Player player = (Player) sender; + GeneratorSession session = ShowPlugin.getShowGenerator().getOrCreateSession(player.getUniqueId()); + + LocalSession worldEditSession = WorldEdit.getInstance().getSessionManager().get(BukkitAdapter.adapt(player)); + try { + Region selection = worldEditSession.getSelection(worldEditSession.getSelectionWorld()); + + if (selection == null) { + player.sendMessage(ChatColor.RED + "Make a selection with a WorldEdit wand, then run this command!"); + return; + } + + World world = BukkitAdapter.asBukkitWorld(selection.getWorld()).getWorld(); + BlockVector3 maxVec = selection.getMaximumPoint(); + BlockVector3 minVec = selection.getMinimumPoint(); + Location max = new Location(world, maxVec.getX(), maxVec.getY(), maxVec.getZ()); + Location min = new Location(world, minVec.getX(), minVec.getY(), minVec.getZ()); + session.setInitialScene(new GeneratorSession.ShowSelection(max, min)); + player.sendMessage(ChatColor.GREEN + "The initial scene has been set!"); + } catch (Exception e) { + player.sendMessage(ChatColor.RED + "Error! Did you select the whole region?"); + e.printStackTrace(); + } + + } + +} diff --git a/src/main/java/network/palace/show/generator/ShowGenerator.java b/src/main/java/network/palace/show/generator/ShowGenerator.java index 1da246c..30fcf92 100644 --- a/src/main/java/network/palace/show/generator/ShowGenerator.java +++ b/src/main/java/network/palace/show/generator/ShowGenerator.java @@ -1,5 +1,6 @@ package network.palace.show.generator; +import com.goebl.david.Request; import com.goebl.david.Webb; import com.google.gson.JsonObject; import network.palace.show.ShowPlugin; @@ -14,7 +15,7 @@ import java.util.UUID; public class ShowGenerator { - private static final String ACCESS_TOKEN = "550a319f2ef3b2e0d489a761b6e12ea88f7f8b4f"; + private final String ACCESS_TOKEN = ShowPlugin.getInstance().getGithubToken(); private HashMap generatorSessions = new HashMap<>(); public GeneratorSession getSession(UUID uuid) { @@ -42,7 +43,7 @@ public String postGist(List actions, String name) throws Except Webb webb = Webb.create(); JsonObject obj = new JsonObject(); - obj.addProperty("description", "Generated by Show v" + ShowPlugin.getInstance().getDescription().getVersion() + " on " + Bukkit.getServerName() + " at " + System.currentTimeMillis()); + obj.addProperty("description", "Generated by Show v" + ShowPlugin.getInstance().getDescription().getVersion() + " on " + ShowPlugin.getInstance().getServerIp() + " at " + System.currentTimeMillis()); obj.addProperty("public", "false"); JsonObject files = new JsonObject(); @@ -69,11 +70,14 @@ public String postGist(List actions, String name) throws Except System.out.println("SENDING (" + actions.size() + "): " + obj.toString()); - JSONObject response = webb.post("https://api.github.com/gists") + Request req = webb.post("https://api.github.com/gists") .header("Accept", "application/vnd.github.v3+json") .header("Authorization", "token " + ACCESS_TOKEN) .header("Content-Type", "application/json") - .body(obj).asJsonObject().getBody(); + .body(obj); + + JSONObject response = req.asJsonObject().getBody(); + return response.getString("html_url"); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..182440d --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,2 @@ +github: + token: \ No newline at end of file