Skip to content

Commit

Permalink
Showgen commands functional with worldedit 7
Browse files Browse the repository at this point in the history
  • Loading branch information
CubitsDev committed Nov 29, 2021
1 parent 55cab47 commit f06aa65
Show file tree
Hide file tree
Showing 10 changed files with 390 additions and 61 deletions.
8 changes: 4 additions & 4 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>network.palace</groupId>
<artifactId>Show</artifactId>
<version>1.5.8</version>
<version>1.6.0</version>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
Expand Down Expand Up @@ -82,7 +82,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<version>1.18.20</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -94,7 +94,7 @@
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>6.1.4-SNAPSHOT</version>
<version>7.2.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -117,8 +117,8 @@
</dependency>
</dependencies>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>network.palace</groupId>
<artifactId>Show</artifactId>
<version>1.5.8</version>
<version>1.6.0</version>
<repositories>
<repository>
<id>enginehub-maven</id>
Expand All @@ -32,7 +32,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<version>1.18.20</version>
<type>jar</type>
</dependency>
<dependency>
Expand All @@ -43,7 +43,7 @@
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>6.1.4-SNAPSHOT</version>
<version>7.2.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
39 changes: 33 additions & 6 deletions src/main/java/network/palace/show/ShowPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,14 +27,17 @@
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;

/**
* 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")
Expand All @@ -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;
Expand All @@ -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<String, Show> shows = new HashMap<>();

Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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
Expand Down
89 changes: 45 additions & 44 deletions src/main/java/network/palace/show/TerrainManager.java
Original file line number Diff line number Diff line change
@@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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 {
Expand All @@ -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())
);
}
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/network/palace/show/commands/ShowgenCommand.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading

0 comments on commit f06aa65

Please sign in to comment.