Skip to content

Commit f06aa65

Browse files
committed
Showgen commands functional with worldedit 7
1 parent 55cab47 commit f06aa65

File tree

10 files changed

+390
-61
lines changed

10 files changed

+390
-61
lines changed

dependency-reduced-pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>network.palace</groupId>
55
<artifactId>Show</artifactId>
6-
<version>1.5.8</version>
6+
<version>1.6.0</version>
77
<build>
88
<finalName>${project.artifactId}</finalName>
99
<plugins>
@@ -82,7 +82,7 @@
8282
<dependency>
8383
<groupId>org.projectlombok</groupId>
8484
<artifactId>lombok</artifactId>
85-
<version>1.18.12</version>
85+
<version>1.18.20</version>
8686
<scope>compile</scope>
8787
</dependency>
8888
<dependency>
@@ -94,7 +94,7 @@
9494
<dependency>
9595
<groupId>com.sk89q.worldedit</groupId>
9696
<artifactId>worldedit-bukkit</artifactId>
97-
<version>6.1.4-SNAPSHOT</version>
97+
<version>7.2.0-SNAPSHOT</version>
9898
<scope>provided</scope>
9999
</dependency>
100100
<dependency>
@@ -117,8 +117,8 @@
117117
</dependency>
118118
</dependencies>
119119
<properties>
120+
<maven.compiler.target>1.8</maven.compiler.target>
120121
<maven.compiler.source>1.8</maven.compiler.source>
121122
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
122-
<maven.compiler.target>1.8</maven.compiler.target>
123123
</properties>
124124
</project>

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>network.palace</groupId>
88
<artifactId>Show</artifactId>
9-
<version>1.5.8</version>
9+
<version>1.6.0</version>
1010
<repositories>
1111
<repository>
1212
<id>enginehub-maven</id>
@@ -32,7 +32,7 @@
3232
<dependency>
3333
<groupId>org.projectlombok</groupId>
3434
<artifactId>lombok</artifactId>
35-
<version>1.18.12</version>
35+
<version>1.18.20</version>
3636
<type>jar</type>
3737
</dependency>
3838
<dependency>
@@ -43,7 +43,7 @@
4343
<dependency>
4444
<groupId>com.sk89q.worldedit</groupId>
4545
<artifactId>worldedit-bukkit</artifactId>
46-
<version>6.1.4-SNAPSHOT</version>
46+
<version>7.2.0-SNAPSHOT</version>
4747
<scope>provided</scope>
4848
</dependency>
4949
<dependency>

src/main/java/network/palace/show/ShowPlugin.java

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.bstats.bukkit.Metrics;
1717
import org.bukkit.Bukkit;
1818
import org.bukkit.ChatColor;
19+
import org.bukkit.configuration.file.FileConfiguration;
1920
import org.bukkit.entity.Player;
2021
import org.bukkit.event.EventHandler;
2122
import org.bukkit.event.player.PlayerJoinEvent;
@@ -26,14 +27,17 @@
2627
import org.bukkit.plugin.java.annotation.plugin.*;
2728
import org.bukkit.plugin.java.annotation.plugin.author.Author;
2829

30+
import java.io.BufferedReader;
31+
import java.io.InputStreamReader;
32+
import java.net.URL;
2933
import java.util.HashMap;
3034
import java.util.Map;
3135

3236
/**
3337
* Created by Marc on 12/6/16.
3438
* Updated to be Core free by Tom 07/10/2021
3539
*/
36-
@Plugin(name = "Show", version = "1.5.8")
40+
@Plugin(name = "Show", version = "1.6.0")
3741
@Description(value = "Create Shows in Minecraft with easy to use files!")
3842
@LoadOrder(value = PluginLoadOrder.POSTWORLD)
3943
@Author(value = "Legobuilder0813")
@@ -47,7 +51,7 @@
4751
@ApiVersion(value = ApiVersion.Target.v1_13)
4852
@Command(name = "show", desc = "Main show command", permission = "show.main", permissionMessage = "You do not have permission!", usage = "/show [list|start|stop]")
4953
@Command(name = "showdebug", desc = "Showdebug command", permission = "show.debug", permissionMessage = "You do not have permission!", usage = "/showdebug")
50-
54+
@Command(name = "showgen", desc = "Showgen commands", permission = "show.showgen", permissionMessage = "You do not have permission!", usage = "/showgen")
5155
public class ShowPlugin extends JavaPlugin {
5256
@Getter private ArmorStandManager armorStandManager;
5357
@Getter private FountainManager fountainManager;
@@ -57,6 +61,8 @@ public class ShowPlugin extends JavaPlugin {
5761
@Getter private final boolean isMinecraftGreaterOrEqualTo11_2 = MinecraftVersion.getCurrentVersion().getMinor() >= 12;
5862
@Getter private static AudioApi audioApi;
5963
@Getter private static OpenAudioMcSpigot openAudioMcSpigot;
64+
@Getter private String githubToken;
65+
@Getter private String serverIp;
6066
private static ShowPlugin instance;
6167
private static final HashMap<String, Show> shows = new HashMap<>();
6268

@@ -71,7 +77,6 @@ public void onEnable() {
7177
instance = this;
7278
armorStandManager = new ArmorStandManager();
7379
fountainManager = new FountainManager();
74-
showGenerator = new ShowGenerator();
7580
buildUtil = new BuildUtil();
7681
softNPCManager = new SoftNPCManager();
7782
audioApi = AudioApi.getInstance();
@@ -80,6 +85,28 @@ public void onEnable() {
8085
this.getCommand("show").setExecutor(new ShowCommand());
8186
this.getCommand("showdebug").setExecutor(new ShowDebugCommand());
8287

88+
FileConfiguration config = this.getConfig();
89+
this.saveDefaultConfig();
90+
if (config.getString("github.token") != null) {
91+
githubToken = config.getString("github.token");
92+
this.getCommand("showgen").setExecutor(new ShowgenCommand());
93+
Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "[Show] Showgen has been enabled in show!");
94+
} else {
95+
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[Show] Showgen will not be running in Show! To enable it, add a github token to the config!");
96+
}
97+
try {
98+
URL whatismyip = new URL("http://checkip.amazonaws.com");
99+
BufferedReader in = new BufferedReader(new InputStreamReader(whatismyip.openStream()));
100+
serverIp = in.readLine();
101+
} catch (Exception e) {
102+
Bukkit.getLogger().warning("Show could not obtain this machines IP. This is only used when generating gists so not essential");
103+
}
104+
105+
106+
//has to be loaded after github token
107+
showGenerator = new ShowGenerator();
108+
109+
83110
this.getServer().getPluginManager().registerEvents(fountainManager, this);
84111
this.getServer().getPluginManager().registerEvents(new PlayerInteract(), this);
85112
this.getServer().getPluginManager().registerEvents(new ChunkListener(), this);
@@ -101,12 +128,12 @@ public void onEnable() {
101128

102129
new UpdateUtil(this, 94141).getVersion(v -> {
103130
if (!this.getDescription().getVersion().equalsIgnoreCase(v)) {
104-
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/");
131+
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/");
105132
}
106133
});
107134

108-
Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Show is now enabled!");
109-
Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Huge shoutout to Legobuilder0813 for making this work for The Palace Network. Time to let your awesome code shine");
135+
Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "[Show] Show is now enabled!");
136+
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");
110137
}
111138

112139
@Override

src/main/java/network/palace/show/TerrainManager.java

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
package network.palace.show;
22

33
import com.sk89q.worldedit.*;
4+
import com.sk89q.worldedit.bukkit.BukkitAdapter;
45
import com.sk89q.worldedit.bukkit.BukkitWorld;
56
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
6-
import com.sk89q.worldedit.data.DataException;
7+
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
78
import com.sk89q.worldedit.extent.clipboard.Clipboard;
8-
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
9-
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
9+
import com.sk89q.worldedit.extent.clipboard.io.*;
10+
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
1011
import com.sk89q.worldedit.function.operation.Operation;
1112
import com.sk89q.worldedit.function.operation.Operations;
13+
import com.sk89q.worldedit.math.BlockVector3;
14+
import com.sk89q.worldedit.regions.CuboidRegion;
1215
import com.sk89q.worldedit.regions.Region;
13-
import com.sk89q.worldedit.schematic.SchematicFormat;
1416
import com.sk89q.worldedit.session.ClipboardHolder;
1517
import com.sk89q.worldedit.util.io.Closer;
16-
import com.sk89q.worldedit.util.io.file.FilenameException;
17-
import com.sk89q.worldedit.world.registry.WorldData;
1818
import network.palace.show.utils.ShowUtil;
1919
import org.bukkit.Location;
2020
import org.bukkit.World;
2121
import org.bukkit.entity.Player;
22+
import org.bukkit.util.Vector;
2223

23-
import java.io.BufferedInputStream;
24-
import java.io.File;
25-
import java.io.FileInputStream;
26-
import java.io.IOException;
24+
import java.io.*;
25+
import java.util.Objects;
2726

2827
@SuppressWarnings("deprecation")
2928
public class TerrainManager {
30-
private final WorldEdit we;
3129
private final LocalSession localSession;
3230
private final EditSession editSession;
33-
private final LocalPlayer localPlayer;
31+
private final Player localPlayer;
32+
private final WorldEdit we;
3433

3534
/**
3635
* Constructor
3736
*
38-
* @param wep the WorldEdit plugin instance
37+
* @param wep the WorldEdit plugin instance
3938
* @param player the player to work with
4039
*/
4140
public TerrainManager(WorldEditPlugin wep, Player player) {
41+
LocalSession worldEditSession = WorldEdit.getInstance().getSessionManager().get(BukkitAdapter.adapt(player));
4242
we = wep.getWorldEdit();
43-
localPlayer = wep.wrapPlayer(player);
44-
localSession = we.getSession(localPlayer);
45-
editSession = localSession.createEditSession(localPlayer);
43+
localSession = worldEditSession;
44+
localPlayer = player;
45+
editSession = worldEditSession.createEditSession(BukkitAdapter.adapt(player));
4646
}
4747

4848
/**
@@ -55,7 +55,7 @@ public TerrainManager(WorldEditPlugin wep, World world) {
5555
we = wep.getWorldEdit();
5656
localPlayer = null;
5757
localSession = new LocalSession(we.getConfiguration());
58-
editSession = new EditSession(new BukkitWorld(world), we.getConfiguration().maxChangeLimit);
58+
editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(world));
5959
}
6060

6161
/**
@@ -66,17 +66,23 @@ public TerrainManager(WorldEditPlugin wep, World world) {
6666
* @param l1 one corner of the region to save
6767
* @param l2 the corner of the region to save, opposite to l1
6868
*/
69-
public void saveTerrain(File saveFile, Location l1, Location l2) throws FilenameException, DataException, IOException {
70-
Vector min = getMin(l1, l2);
71-
Vector max = getMax(l1, l2);
69+
public void saveTerrain(File saveFile, Location l1, Location l2) throws WorldEditException, IOException {
70+
BlockVector3 min = getMin(l1, l2);
71+
BlockVector3 max = getMax(l1, l2);
72+
73+
saveFile = we.getSafeSaveFile(BukkitAdapter.adapt(localPlayer), saveFile.getParentFile(), saveFile.getName(), ".schematic", ".schematic");
7274

73-
saveFile = we.getSafeSaveFile(localPlayer, saveFile.getParentFile(), saveFile.getName(), ".schematic", ".schematic");
75+
CuboidRegion region = new CuboidRegion(BukkitAdapter.adapt(Objects.requireNonNull(l1.getWorld())), min, max);
76+
BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
7477

75-
editSession.enableQueue();
76-
CuboidClipboard clipboard = new CuboidClipboard(max.subtract(min).add(new Vector(1, 1, 1)), min);
77-
clipboard.copy(editSession);
78-
SchematicFormat.MCEDIT.save(clipboard, saveFile);
79-
editSession.flushQueue();
78+
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(region.getWorld(), -1);
79+
80+
ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
81+
forwardExtentCopy.setCopyingEntities(true);
82+
Operations.complete(forwardExtentCopy);
83+
try (ClipboardWriter writer = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(saveFile))) {
84+
writer.write(clipboard);
85+
}
8086
}
8187

8288
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
8692
ShowUtil.logDebug("Schematics", "Tried to load Schematic " + fileName + " but does not exist!");
8793
return;
8894
}
89-
Closer closer = Closer.create();
90-
FileInputStream fis = closer.register(new FileInputStream(f));
91-
BufferedInputStream bis = closer.register(new BufferedInputStream(fis));
92-
ClipboardReader reader = ClipboardFormat.SCHEMATIC.getReader(bis);
93-
WorldData worldData = new BukkitWorld(loc.getWorld()).getWorldData();
94-
Clipboard clipboard = reader.read(worldData);
95-
localSession.setClipboard(new ClipboardHolder(clipboard, worldData));
96-
Region region = clipboard.getRegion();
97-
Vector to = new Vector(loc.getX(), loc.getY(), loc.getZ());
98-
Operation operation = localSession.getClipboard().createPaste(editSession, editSession.getWorld()
99-
.getWorldData()).to(to).ignoreAirBlocks(noAir).build();
100-
Operations.completeLegacy(operation);
101-
fis.close();
102-
bis.close();
95+
ClipboardFormat format = ClipboardFormats.findByFile(f);
96+
try (ClipboardReader reader = format.getReader(new FileInputStream(f))) {
97+
Clipboard clipboard = reader.read();
98+
localSession.setClipboard(new ClipboardHolder(clipboard));
99+
Region region = clipboard.getRegion();
100+
BlockVector3 to = BlockVector3.at(loc.getX(), loc.getY(), loc.getZ());
101+
Operation operation = localSession.getClipboard().createPaste(editSession).to(to).ignoreAirBlocks(noAir).build();
102+
Operations.completeLegacy(operation);
103+
}
103104
}
104105

105106
public void loadSchematic(WorldEditPlugin wep, String fileName, boolean noAir) throws Exception {
106107
loadSchematic(wep, fileName, null, noAir);
107108
}
108109

109-
private Vector getMin(Location l1, Location l2) {
110-
return new Vector(Math.min(l1.getBlockX(), l2.getBlockX()), Math.min(l1.getBlockY(), l2.getBlockY()),
110+
private BlockVector3 getMin(Location l1, Location l2) {
111+
return BlockVector3.at(Math.min(l1.getBlockX(), l2.getBlockX()), Math.min(l1.getBlockY(), l2.getBlockY()),
111112
Math.min(l1.getBlockZ(), l2.getBlockZ())
112113
);
113114
}
114115

115-
private Vector getMax(Location l1, Location l2) {
116-
return new Vector(Math.max(l1.getBlockX(), l2.getBlockX()), Math.max(l1.getBlockY(), l2.getBlockY()),
116+
private BlockVector3 getMax(Location l1, Location l2) {
117+
return BlockVector3.at(Math.max(l1.getBlockX(), l2.getBlockX()), Math.max(l1.getBlockY(), l2.getBlockY()),
117118
Math.max(l1.getBlockZ(), l2.getBlockZ())
118119
);
119120
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package network.palace.show.commands;
2+
3+
import network.palace.show.commands.showgen.GenerateCommand;
4+
import network.palace.show.commands.showgen.SetCornerCommand;
5+
import network.palace.show.commands.showgen.SetInitialCommand;
6+
import org.bukkit.ChatColor;
7+
import org.bukkit.command.Command;
8+
import org.bukkit.command.CommandExecutor;
9+
import org.bukkit.command.CommandSender;
10+
import org.bukkit.entity.Player;
11+
import org.jetbrains.annotations.NotNull;
12+
13+
import java.util.Arrays;
14+
15+
public class ShowgenCommand implements CommandExecutor {
16+
17+
@Override
18+
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
19+
if (args.length == 0) {
20+
sender.sendMessage(ChatColor.GREEN + "ShowGen Commands:");
21+
sender.sendMessage(ChatColor.AQUA + "/showgen generate [action] [bottom/top] [delay per layer] [timestamp]" + ChatColor.GREEN + "- Generate blocks of show actions with one command");
22+
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");
23+
sender.sendMessage(ChatColor.AQUA + "/showgen setinitialscene " + ChatColor.GREEN + "- Set the initial scene for a generator session");
24+
return true;
25+
}
26+
27+
if (!(sender instanceof Player)) {
28+
sender.sendMessage(ChatColor.RED + "You must be a player to run this command!");
29+
}
30+
31+
switch (args[0]) {
32+
case "generate":
33+
String[] newArgs = Arrays.copyOfRange(args, 1, args.length);
34+
new GenerateCommand().handle(sender, newArgs);
35+
break;
36+
case "setcorner":
37+
new SetCornerCommand().handle(sender, args);
38+
break;
39+
case "setinitialscene":
40+
new SetInitialCommand().handle(sender);
41+
break;
42+
default:
43+
sender.sendMessage(ChatColor.GREEN + "ShowGen Commands:");
44+
sender.sendMessage(ChatColor.AQUA + "/showgen generate [action] [bottom/top] [delay per layer] [timestamp]" + ChatColor.GREEN + "- Generate blocks of show actions with one command");
45+
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");
46+
sender.sendMessage(ChatColor.AQUA + "/showgen setinitialscene " + ChatColor.GREEN + "- Set the initial scene for a generator session");
47+
break;
48+
}
49+
return true;
50+
}
51+
}

0 commit comments

Comments
 (0)