Skip to content

Commit

Permalink
Merge pull request #44 from josemmo/develop
Browse files Browse the repository at this point in the history
v1.2.3
  • Loading branch information
josemmo authored Jun 15, 2022
2 parents e7dfc2e + 90e0f94 commit 267946a
Show file tree
Hide file tree
Showing 10 changed files with 357 additions and 268 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
steps:
# Download code from repository
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

# Setup Java
- name: Setup JDK
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
Expand Down
17 changes: 11 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,27 @@ jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 8
continue-on-error: ${{ matrix.version == '1.19' }}
strategy:
fail-fast: false
matrix:
flavor: ['bukkit', 'spigot', 'paper', 'purpur']
version: ['1.18.1', '1.18', '1.17.1', '1.17', '1.16.5', '1.16.4', '1.16.3', '1.16.2', '1.16.1']
version: ['1.19', '1.18.2', '1.17.1', '1.16.5']
steps:
# Download code from repository
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

# Setup Java
- name: Setup JDK
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: ${{ startsWith(matrix.version, '1.16') && '11' || (startsWith(matrix.version, '1.17') && '16' || '17') }}

# Setup Node.js
- name: Setup Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '16'

Expand Down Expand Up @@ -53,7 +54,7 @@ jobs:
build=$(curl "https://papermc.io/api/v2/projects/paper/versions/$VERSION" | jq '.builds[-1]')
url="https://papermc.io/api/v2/projects/paper/versions/$VERSION/builds/$build/downloads/paper-$VERSION-$build.jar"
elif [ $FLAVOR == "purpur" ]; then
url="https://api.pl3x.net/v2/purpur/$VERSION/latest/download"
url="https://api.purpurmc.org/v2/purpur/$VERSION/latest/download"
fi
mkdir ./server && cd ./server
wget -nv "$url" -O server.jar
Expand All @@ -70,7 +71,11 @@ jobs:
# Install dependencies
- name: Install plugin dependencies
run: |
url="https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/target/ProtocolLib.jar"
if [ $VERSION == "1.19" ]; then
url="https://ci.dmulloy2.net/job/ProtocolLib/lastStableBuild/artifact/target/ProtocolLib.jar"
else
url="https://github.com/dmulloy2/ProtocolLib/releases/download/4.8.0/ProtocolLib.jar"
fi
mkdir -p ./server/plugins
wget -q "$url" -O ./server/plugins/ProtocolLib.jar
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Here are the Minecraft distributions where Yamipa should be able to run:
|------------------:|:-----------:|:------:|:-------:|
| 1.16.x ||||
| 1.17 & 1.17.1 ||||
| 1.18 & 1.18.1 ||||
| 1.18 & 1.18.x ||||
| 1.19 ||||

## Configuration
Yamipa is ready-to-go right out of the box. By default, it creates the following files and directories under the
Expand Down Expand Up @@ -123,7 +124,7 @@ Images from this plugin have a set of boolean attributes called "flags" that mod
By default, images placed with the "/image place" command only have the `ANIM` flag.
Similarly, image items issued with the "/image give" command have `ANIM`, `REMO` and `DROP` flags.

Default flags can be modified through the "<flag>" argument.
Default flags can be modified through the "flags" argument.
To add a flag to the default ones use "+{FLAG_NAME}" (e.g. `+GLOW`), and to remove it use "-{FLAG_NAME}" (e.g. `-ANIM`).
You can modify multiple flags separating them with commas (e.g. `+GLOW,-ANIM`).

Expand Down
402 changes: 205 additions & 197 deletions automata/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion automata/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"start": "node index.js"
},
"dependencies": {
"mineflayer": "^3.15.0",
"mineflayer": "^4.1.0",
"rcon-client": "^4.2.3"
}
}
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>io.josemmo.bukkit.plugin</groupId>
<artifactId>YamipaPlugin</artifactId>
<version>1.2.2</version>
<version>1.2.3</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand All @@ -33,13 +33,13 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<version>1.19-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.8.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -51,7 +51,7 @@
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>2.2.1</version>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
Expand Down
63 changes: 56 additions & 7 deletions src/main/java/io/josemmo/bukkit/plugin/commands/ImageCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.bukkit.plugin.PluginDescriptionFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.imageio.ImageIO;
import java.awt.Dimension;
import java.io.IOException;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -43,7 +44,7 @@ public static void showHelp(@NotNull CommandSender s, @NotNull String commandNam
s.sendMessage(ChatColor.AQUA + cmd + " download <url> <filename>" + ChatColor.RESET + " - Download image");
}
if (s.hasPermission("yamipa.give")) {
s.sendMessage(ChatColor.AQUA + cmd + " give <p> <filename> <#> <w> [<h>] [<f>]" + ChatColor.RESET + " - Give image items");
s.sendMessage(ChatColor.AQUA + cmd + " give <p> <filename> <#> <w> [<h>] [<f>]" + ChatColor.RESET + " - Give items");
}
if (s.hasPermission("yamipa.list")) {
s.sendMessage(ChatColor.AQUA + cmd + " list [<page>]" + ChatColor.RESET + " - List all images");
Expand Down Expand Up @@ -87,7 +88,7 @@ public static void listImages(@NotNull CommandSender sender, int page) {
}
}

public static void downloadImage(@NotNull CommandSender sender, @NotNull String url, @NotNull String filename) {
public static void downloadImage(@NotNull CommandSender sender, @NotNull String rawUrl, @NotNull String filename) {
YamipaPlugin plugin = YamipaPlugin.getInstance();

// Validate destination file
Expand All @@ -102,20 +103,68 @@ public static void downloadImage(@NotNull CommandSender sender, @NotNull String
return;
}

// Download remote URL
// Validate and fix remote URL
URL url;
String referrer = null;
try {
url = new URL(rawUrl);

// Giphy.com
if (url.getHost().equals("giphy.com")) {
String path = url.getPath();
String id = path.substring(path.lastIndexOf('-')+1);
url = new URL("https://media.giphy.com/media/" + id + "/giphy.gif");
referrer = "https://giphy.com/";
}

// Imgur.com
if (url.getHost().equals("imgur.com")) {
String[] parts = url.getPath().replaceAll("^/|/$", "").split("/");
if (parts.length == 2 && (parts[0].equals("a") || parts[0].equals("gallery"))) {
url = new URL("https://imgur.com/a/" + parts[1] + "/zip");
referrer = "https://imgur.com/a/" + parts[1];
} else {
url = new URL("https://imgur.com/download/" + parts[parts.length-1] + "/");
referrer = "https://imgur.com/" + parts[parts.length-1];
}
}
} catch (MalformedURLException e) {
sender.sendMessage(ChatColor.RED + "The remote URL is not valid");
return;
}

// Download and validate remote file
final URL finalUrl = url;
final String finalReferrer = referrer;
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {
URLConnection conn = new URL(url).openConnection();
URLConnection conn = finalUrl.openConnection();
PluginDescriptionFile desc = plugin.getDescription();
conn.setRequestProperty("Accept", "*/*");
conn.setRequestProperty("User-Agent", desc.getName() + "/" + desc.getVersion());
if (finalReferrer != null) {
conn.setRequestProperty("Referer", finalReferrer);
}

// Download file
sender.sendMessage("Downloading file...");
Files.copy(conn.getInputStream(), destPath);

// Validate downloaded file
if (ImageIO.read(destPath.toFile()) == null) {
throw new IllegalArgumentException("The downloaded file is not a valid image");
}

// Notify sender
sender.sendMessage(ChatColor.GREEN + "Done!");
} catch (MalformedURLException e) {
sender.sendMessage(ChatColor.RED + "The remote URL is not valid");
} catch (IOException e) {
sender.sendMessage(ChatColor.RED + "An error occurred trying to download the remote file");
plugin.warning("Failed to download file from \"" + url + "\": " + e.getClass().getName());
plugin.warning("Failed to download file from \"" + finalUrl + "\": " + e.getClass().getName());
} catch (IllegalArgumentException e) {
if (Files.exists(destPath) && !destPath.toFile().delete()) {
plugin.warning("Failed to delete corrupted file \"" + destPath + "\"");
}
sender.sendMessage(ChatColor.RED + e.getMessage());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import io.josemmo.bukkit.plugin.utils.Internals;
import org.bukkit.entity.EntityType;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;

public class SpawnEntityPacket extends PacketContainer {
private static final boolean ROTATION_AS_BYTES;
private static final int DATA_INDEX;

static {
if (Internals.MINECRAFT_VERSION < 19) {
ROTATION_AS_BYTES = false;
DATA_INDEX = 6;
} else {
DATA_INDEX = 4;
ROTATION_AS_BYTES = true;
}
}

public SpawnEntityPacket() {
super(PacketType.Play.Server.SPAWN_ENTITY);
getIntegers()
Expand All @@ -28,14 +42,20 @@ public SpawnEntityPacket() {
}

public @NotNull SpawnEntityPacket setRotation(int pitch, int yaw) {
getIntegers()
.write(4, pitch)
.write(5, yaw);
if (ROTATION_AS_BYTES) {
getBytes()
.write(0, (byte) pitch)
.write(1, (byte) yaw);
} else {
getIntegers()
.write(4, pitch)
.write(5, yaw);
}
return this;
}

public @NotNull SpawnEntityPacket setData(int data) {
getIntegers().write(6, data);
getIntegers().write(DATA_INDEX, data);
return this;
}

Expand Down
Loading

0 comments on commit 267946a

Please sign in to comment.