Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Ethan
ScholarAPI
Commits
59fdc35d
Commit
59fdc35d
authored
Mar 10, 2021
by
Adam
👻
Browse files
Initial commit
parents
Pipeline
#1939
failed with stages
in 40 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
202 additions
and
0 deletions
+202
-0
.gitignore
.gitignore
+9
-0
pom.xml
pom.xml
+79
-0
src/main/java/com/kasprr/resourcepackapi/DownloadManager.java
...main/java/com/kasprr/resourcepackapi/DownloadManager.java
+5
-0
src/main/java/com/kasprr/resourcepackapi/ResourcePackAPI.java
...main/java/com/kasprr/resourcepackapi/ResourcePackAPI.java
+104
-0
src/main/resources/plugin.yml
src/main/resources/plugin.yml
+5
-0
No files found.
.gitignore
0 → 100644
View file @
59fdc35d
/bin/
/target/
/.settings/
/.idea/
/.m2/
.classpath
.project
ResourcePackAPI.iml
\ No newline at end of file
pom.xml
0 → 100644
View file @
59fdc35d
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.kasprr
</groupId>
<artifactId>
ResourcePackAPI
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<packaging>
jar
</packaging>
<name>
ResourcePackAPI
</name>
<properties>
<java.version>
1.8
</java.version>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
3.8.1
</version>
<configuration>
<source>
${java.version}
</source>
<target>
${java.version}
</target>
</configuration>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-shade-plugin
</artifactId>
<version>
3.2.4
</version>
<executions>
<execution>
<phase>
package
</phase>
<goals>
<goal>
shade
</goal>
</goals>
<configuration>
<createDependencyReducedPom>
false
</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>
src/main/resources
</directory>
<filtering>
true
</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>
spigotmc-repo
</id>
<url>
https://hub.spigotmc.org/nexus/content/repositories/snapshots/
</url>
</repository>
<repository>
<id>
sonatype
</id>
<url>
https://oss.sonatype.org/content/groups/public/
</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>
org.spigotmc
</groupId>
<artifactId>
spigot-api
</artifactId>
<version>
1.16.5-R0.1-SNAPSHOT
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
net.lingala.zip4j
</groupId>
<artifactId>
zip4j
</artifactId>
<version>
2.7.0
</version>
</dependency>
</dependencies>
</project>
src/main/java/com/kasprr/resourcepackapi/DownloadManager.java
0 → 100644
View file @
59fdc35d
package
com.kasprr.resourcepackapi
;
public
class
DownloadManager
{
}
src/main/java/com/kasprr/resourcepackapi/ResourcePackAPI.java
0 → 100644
View file @
59fdc35d
package
com.kasprr.resourcepackapi
;
import
org.bukkit.Bukkit
;
import
org.bukkit.ChatColor
;
import
org.bukkit.plugin.java.JavaPlugin
;
import
java.io.*
;
import
java.net.MalformedURLException
;
import
java.nio.channels.Channels
;
import
java.nio.channels.FileChannel
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.Properties
;
import
java.net.URL
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipInputStream
;
import
static
java
.
nio
.
file
.
StandardOpenOption
.
CREATE
;
import
static
java
.
nio
.
file
.
StandardOpenOption
.
WRITE
;
public
final
class
ResourcePackAPI
extends
JavaPlugin
{
@Override
public
void
onEnable
()
{
String
packName
=
"serverpack"
;
URL
packURL
=
getResourcePackUrl
();
Path
path2
=
Paths
.
get
(
getDataFolder
()
+
"/packs/"
+
packName
);
System
.
out
.
println
(
packURL
.
getFile
());
downloadAndUnzipResourcePack
(
packURL
,
path2
);
}
public
static
boolean
isUrlValid
(
String
url
)
{
try
{
new
URL
(
url
).
toURI
();
return
true
;
}
catch
(
Exception
e
)
{
return
false
;
}
}
public
static
URL
getResourcePackUrl
()
{
BufferedReader
reader
;
Properties
props
=
new
Properties
();
String
packUrlString
=
null
;
// Get resource pack URL from server.properties
try
{
reader
=
new
BufferedReader
(
new
FileReader
(
"server.properties"
));
props
.
load
(
reader
);
reader
.
close
();
packUrlString
=
props
.
getProperty
(
"resource-pack"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
// Validate and convert URL
URL
packUrl
=
null
;
if
(
isUrlValid
(
packUrlString
)
&&
packUrlString
!=
null
)
{
try
{
packUrl
=
new
URL
(
packUrlString
);
Bukkit
.
getConsoleSender
().
sendMessage
(
ChatColor
.
GREEN
+
"URL VALID"
);
}
catch
(
MalformedURLException
e
)
{
e
.
printStackTrace
();
}
}
else
{
// TODO: probably throw some exception here?
Bukkit
.
getConsoleSender
().
sendMessage
(
ChatColor
.
DARK_RED
+
"URL INVALID"
);
}
return
packUrl
;
}
// public static void downloadResourcePack(URL url, File path) {
// try {
// ReadableByteChannel rbc = Channels.newChannel(url.openStream());
// FileOutputStream fileOS = new FileOutputStream(path);
// FileChannel writeChannel = fileOS.getChannel();
// writeChannel.transferFrom(rbc, 0, Long.MAX_VALUE);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
public
static
void
downloadAndUnzipResourcePack
(
URL
url
,
Path
extractPath
)
{
try
(
ZipInputStream
zipInputStream
=
new
ZipInputStream
(
Channels
.
newInputStream
(
Channels
.
newChannel
(
url
.
openStream
()))))
{
if
(!
Files
.
exists
(
extractPath
))
{
Files
.
createDirectory
(
extractPath
);
}
for
(
ZipEntry
entry
=
zipInputStream
.
getNextEntry
();
entry
!=
null
;
entry
=
zipInputStream
.
getNextEntry
())
{
Path
unzippedFilePath
=
extractPath
.
resolve
(
entry
.
getName
());
if
(
entry
.
isDirectory
())
{
Files
.
createDirectory
(
unzippedFilePath
);
}
else
try
(
FileChannel
fileChannel
=
FileChannel
.
open
(
unzippedFilePath
,
WRITE
,
CREATE
))
{
fileChannel
.
transferFrom
(
Channels
.
newChannel
(
zipInputStream
),
0
,
Long
.
MAX_VALUE
);
}
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
\ No newline at end of file
src/main/resources/plugin.yml
0 → 100644
View file @
59fdc35d
name
:
ResourcePackAPI
version
:
${project.version}
main
:
com.kasprr.resourcepackapi.ResourcePackAPI
api-version
:
1.16
authors
:
[
Kasprr
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment