Skip to content

Commit

Permalink
hopefully this works
Browse files Browse the repository at this point in the history
  • Loading branch information
smashyalts committed Feb 26, 2024
1 parent cf8d496 commit f2dce7e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 5 deletions.
10 changes: 8 additions & 2 deletions chunky-dedicated/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<aws.java.sdk.version>2.24.10</aws.java.sdk.version>
</properties>

<build>
Expand All @@ -24,8 +25,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -75,6 +76,11 @@
<version>1.20.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.1000</version>
</dependency>
<dependency>
<groupId>org.popcraft</groupId>
<artifactId>chunky-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
package com.funniray.chunkydedicated;

import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.Bucket;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.plugin.java.JavaPlugin;
import org.popcraft.chunky.api.ChunkyAPI;

public final class ChunkyDedicated extends JavaPlugin {
import java.io.*;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;

public final class ChunkyDedicated extends JavaPlugin {
String sourceFile = "world";
FileOutputStream fos = new FileOutputStream("compressed.zip");
ZipOutputStream zipOut = new ZipOutputStream(fos);
ChunkyAPI chunky;

public ChunkyDedicated() throws FileNotFoundException {
}

@Override
public void onEnable() {
saveDefaultConfig();
// Plugin startup logic
chunky = getServer().getServicesManager().load(ChunkyAPI.class);

if (chunky == null) {
getLogger().severe("Chunky is not loaded, disabling...");
getServer().getPluginManager().disablePlugin(this);

return;
}

Expand All @@ -34,6 +52,56 @@ public void onEnable() {
return;
}
getLogger().info("All tasks finished, closing server...");
File fileToZip = new File(sourceFile);
FileInputStream fis = null;
try {
fis = new FileInputStream(fileToZip);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
ZipEntry zipEntry = new ZipEntry(fileToZip.getName());
try {
zipOut.putNextEntry(zipEntry);
} catch (IOException e) {
throw new RuntimeException(e);
}

byte[] bytes = new byte[1024];
int length;
while(true) {
try {
if (!((length = fis.read(bytes)) >= 0)) break;
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
zipOut.write(bytes, 0, length);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

try {
zipOut.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
fis.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
fos.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
AmazonS3 s3 = AmazonS3ClientBuilder.standard()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("https://" + getConfig().get("cloudflare-account-id") + ".r2.cloudflarestorage.com", "auto"))
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(getConfig().get("cloudflare-access-key").toString(), getConfig().get("cloudflare-secret-key").toString())))
.build();

s3.putObject(getConfig().get("bucket-name").toString(), "compressed.zip", new File("compressed.zip"));
getServer().shutdown();
});
}
Expand Down
3 changes: 3 additions & 0 deletions chunky-dedicated/src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cloudflare-access-key: ""
cloudflare-account-id: ""
cloudflare-secret-key: ""

0 comments on commit f2dce7e

Please sign in to comment.