Skip to content
14 changes: 10 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.6.0</version>
<version>1.6.1</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.20</version>
<version>1.18.22</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -96,11 +96,17 @@
<artifactId>worldedit-bukkit</artifactId>
<version>7.2.0-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>bstats-bukkit</artifactId>
<groupId>org.bstats</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId>
<version>4.1.51.Final</version>
<version>4.1.75.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -112,7 +118,7 @@
<dependency>
<groupId>com.craftmend.openaudiomc</groupId>
<artifactId>OpenAudioMc</artifactId>
<version>6.5.4</version>
<version>6.6.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
8 changes: 4 additions & 4 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.6.0</version>
<version>1.6.1</version>
<repositories>
<repository>
<id>enginehub-maven</id>
Expand All @@ -32,7 +32,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<version>1.18.22</version>
<type>jar</type>
</dependency>
<dependency>
Expand Down Expand Up @@ -61,7 +61,7 @@
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId>
<version>4.1.51.Final</version>
<version>4.1.75.Final</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
Expand All @@ -77,7 +77,7 @@
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>2.2.1</version>
<version>3.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/network/palace/show/ShowPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.PluginLoadOrder;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -37,7 +38,7 @@
* Created by Marc on 12/6/16.
* Updated to be Core free by Tom 07/10/2021
*/
@Plugin(name = "Show", version = "1.6.0")
@Plugin(name = "Show", version = "1.6.1")
@Description(value = "Create Shows in Minecraft with easy to use files!")
@LoadOrder(value = PluginLoadOrder.POSTWORLD)
@Author(value = "Legobuilder0813")
Expand All @@ -52,7 +53,7 @@
@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 {
public class ShowPlugin extends JavaPlugin implements Listener {
@Getter private ArmorStandManager armorStandManager;
@Getter private FountainManager fountainManager;
@Getter private static ShowGenerator showGenerator;
Expand Down Expand Up @@ -103,13 +104,14 @@ public void onEnable() {
}


//has to be loaded after github token
// 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);
this.getServer().getPluginManager().registerEvents(this, this);

// Show Ticker
taskid = Bukkit.getScheduler().runTaskTimer(this, () -> {
Expand All @@ -128,7 +130,7 @@ public void onEnable() {

new UpdateUtil(this, 94141).getVersion(v -> {
if (!this.getDescription().getVersion().equalsIgnoreCase(v)) {
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.AQUA + "[Show] " + 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/");
}
});

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/network/palace/show/actions/BlockAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import network.palace.show.Show;
import network.palace.show.exceptions.ShowParseException;
import network.palace.show.handlers.BlockData;
import network.palace.show.utils.ShowUtil;
import network.palace.show.utils.WorldUtil;
import org.bukkit.Location;
import org.bukkit.Material;
Expand Down
24 changes: 8 additions & 16 deletions src/main/java/network/palace/show/actions/FakeBlockAction.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
package network.palace.show.actions;

import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.WrappedBlockData;
import lombok.Getter;
import lombok.Setter;
import network.palace.show.packets.server.block.WrapperPlayServerBlockChange;
import network.palace.show.Show;
import network.palace.show.exceptions.ShowParseException;
import network.palace.show.handlers.BlockData;
import network.palace.show.utils.MiscUtil;
import network.palace.show.utils.ShowUtil;
import network.palace.show.utils.WorldUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;

/**
Expand All @@ -25,30 +20,27 @@
@SuppressWarnings("deprecation")
public class FakeBlockAction extends ShowAction {
private Location loc;
private Material mat;
private BlockData data;

public FakeBlockAction(Show show, long time) {
super(show, time);
}

public FakeBlockAction(Show show, long time, Location loc, Material mat) {
public FakeBlockAction(Show show, long time, Location loc, BlockData data) {
super(show, time);
this.loc = loc;
this.mat = mat;
this.data = data;
}

@Override
public void play(Player[] nearPlayers) {
try {
WrapperPlayServerBlockChange p = new WrapperPlayServerBlockChange();
p.setLocation(new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
p.setBlockData(WrappedBlockData.createData(mat));
for (Player tp : nearPlayers) {
if (tp != null) MiscUtil.sendPacket(p, tp);
if (tp != null) tp.sendBlockChange(loc, data);
}
} catch (Exception e) {
Bukkit.getLogger().severe("FakeBlockAction -" + ChatColor.RED + "Error sending FakeBlockAction for type (" +
mat.toString() + ") at location " + loc.getX() + "," + loc.getY() + "," + loc.getZ() + " at time " +
data.getMaterial() + ") at location " + loc.getX() + "," + loc.getY() + "," + loc.getZ() + " at time " +
time + " for show " + show.getName());
e.printStackTrace();
}
Expand All @@ -62,7 +54,7 @@ public ShowAction load(String line, String... args) throws ShowParseException {
}
try {
this.loc = loc;
this.mat = Material.valueOf(args[2].toUpperCase());
this.data = ShowUtil.getBlockData(line);
} catch (IllegalArgumentException e) {
throw new ShowParseException(e.getMessage());
}
Expand All @@ -71,6 +63,6 @@ public ShowAction load(String line, String... args) throws ShowParseException {

@Override
protected ShowAction copy(Show show, long time) throws ShowParseException {
return new FakeBlockAction(show, time, loc, mat);
return new FakeBlockAction(show, time, loc, data);
}
}
2 changes: 0 additions & 2 deletions src/main/java/network/palace/show/actions/FountainAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import network.palace.show.Show;
import network.palace.show.ShowPlugin;
import network.palace.show.exceptions.ShowParseException;
import network.palace.show.handlers.BlockData;
import network.palace.show.handlers.Fountain;
import network.palace.show.utils.ShowUtil;
import network.palace.show.utils.WorldUtil;
import org.bukkit.Location;
import org.bukkit.Material;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void handle(CommandSender sender, String[] args) {
bottom = !args[1].equalsIgnoreCase("top");
delayPerLayer = Double.parseDouble(args[2]);
} else {
bottom = false;
bottom = true;
delayPerLayer = 0;
}

Expand All @@ -109,25 +109,26 @@ public void handle(CommandSender sender, String[] args) {
changeInTime = delayPerLayer;
}


// y is startingY, and is incremented by yChange every loop until y is equal to endingY.
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()) {
if (newBlock.getType().equals(oldBlock.getType()) && newBlock.getBlockData().matches(oldBlock.getBlockData())) {
continue;
}
Material material = newBlock.getType();
byte data = newBlock.getData();
FakeBlockAction act = new FakeBlockAction(null, (long) (localTime * 1000));
act.setMat(material);
act.setData(newBlock.getBlockData());
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;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/network/palace/show/enums/BlockDataType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package network.palace.show.enums;

public enum BlockDataType {
STAIRS,
FENCE,
GLASS_PANE,
TRAPDOOR,
DOOR,
SLAB
}
83 changes: 78 additions & 5 deletions src/main/java/network/palace/show/generator/ShowGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
import com.google.gson.JsonObject;
import network.palace.show.ShowPlugin;
import network.palace.show.actions.FakeBlockAction;
import org.bukkit.Bukkit;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.*;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

public class ShowGenerator {
Expand Down Expand Up @@ -54,11 +58,13 @@ public String postGist(List<FakeBlockAction> actions, String name) throws Except
for (FakeBlockAction action : actions) {
Location loc = action.getLoc();
double time = ((int) ((action.getTime() / 1000.0) * 10)) / 10.0;
Material mat = action.getMat();
Material mat = action.getData().getMaterial();
int x = loc.getBlockX();
int y = loc.getBlockY();
int z = loc.getBlockZ();
String actionString = time + "\u0009" + "FakeBlock" + "\u0009" + mat.toString() + "\u0009" + x + "," + y + "," + z;
String actionString = time + "\u0009" + "FakeBlock" + "\u0009" + mat + "\u0009" + x + "," + y + "," + z;
// If data, add to end
if (!Objects.equals(getBlockDataString(action.getData()), "")) actionString += "\u0009" + getBlockDataString(action.getData());
content.append(actionString).append("\n");
}

Expand All @@ -68,8 +74,6 @@ public String postGist(List<FakeBlockAction> actions, String name) throws Except

obj.add("files", files);

System.out.println("SENDING (" + actions.size() + "): " + obj.toString());

Request req = webb.post("https://api.github.com/gists")
.header("Accept", "application/vnd.github.v3+json")
.header("Authorization", "token " + ACCESS_TOKEN)
Expand All @@ -80,4 +84,73 @@ public String postGist(List<FakeBlockAction> actions, String name) throws Except

return response.getString("html_url");
}

/*
Whole Line:
0 1 2 3 4
TIME ACTION MATERIAL COORDS BLOCK_DATA
3.0 FakeBlock AIR 14,5,1 STAIRS:DATA:DATA
.
.
Block Data:
0 1 2 3 4
STAIRS : HALF : FACING : SHAPE -> STAIRS:BOTTOM/TOP:NORTH/EAST/SOUTH/WEST:INNER_LEFT/...
FENCE : FACE -> FENCE:NORTH/EAST/SOUTH/WEST ex) FENCE:NORTH:SOUTH
GLASS_PANE : FACE -> GLASS_PANE:NORTH/EAST/SOUTH/WEST ex) GLASS_PANE:NORTH:SOUTH
TRAPDOOR : HALF : FACING : OPEN -> TRAPDOOR:BOTTOM/TOP:NORTH/EAST/SOUTH/WEST:TRUE/FALSE
DOOR : HALF : FACING : OPEN : HINGE -> DOOR:BOTTOM/TOP:NORTH/EAST/SOUTH/WEST:TRUE/FALSE:LEFT/RIGHT
SLAB : TYPE -> SLAB:TOP/BOTTOM/DOUBLE
*/
private String getBlockDataString(BlockData blockData) {
StringBuilder dataString = new StringBuilder();
if (blockData instanceof Stairs) {
String half = ((Stairs) blockData).getHalf().toString();
String facing = ((Stairs) blockData).getFacing().toString();
String shape = ((Stairs) blockData).getShape().toString();
dataString = new StringBuilder("STAIRS," + half.toUpperCase() + "," + facing.toUpperCase() + "," + shape.toUpperCase());

} else if (blockData instanceof Fence) {
if (((Fence) blockData).getFaces().isEmpty()) return "";
dataString = new StringBuilder("FENCE,");

// True for included
for (BlockFace face : ((Fence) blockData).getFaces()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be switched to a switch case statement to avoid the if else if repetition.

Copy link
Author

@KyGuy2002 KyGuy2002 Apr 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your meaning the whole part, or just the // True for included part?

Im using instanceof so i dont think its possible to do that in a switch statemnt

dataString.append(face.toString().toUpperCase()).append(":");
}

// Remove last character
dataString = new StringBuilder(StringUtils.chop(dataString.toString()));

} else if (blockData instanceof GlassPane) {
if (((GlassPane) blockData).getFaces().isEmpty()) return "";
dataString = new StringBuilder("GLASS_PANE,");

// True for included
for (BlockFace face : ((GlassPane) blockData).getFaces()) {
dataString.append(face.toString().toUpperCase()).append(":");
}

// Remove last character
dataString = new StringBuilder(StringUtils.chop(dataString.toString()));

} else if (blockData instanceof TrapDoor) {
String half = ((TrapDoor) blockData).getHalf().toString();
String facing = ((TrapDoor) blockData).getFacing().toString();
String open = String.valueOf(((TrapDoor) blockData).isOpen());
dataString = new StringBuilder("TRAPDOOR," + half.toUpperCase() + "," + facing.toUpperCase() + "," + open.toUpperCase());

} else if (blockData instanceof Door) {
String half = ((Door) blockData).getHalf().toString();
String facing = ((Door) blockData).getFacing().toString();
String open = String.valueOf(((Door) blockData).isOpen());
String hinge = ((Door) blockData).getHinge().toString();
dataString = new StringBuilder("DOOR," + half.toUpperCase() + "," + facing.toUpperCase() + "," + open.toUpperCase() + "," + hinge.toUpperCase());

} else if (blockData instanceof Slab) {
String type = ((Slab) blockData).getType().toString();
dataString = new StringBuilder("SLAB," + type.toUpperCase());
}

return dataString.toString();
}
}
Loading