Skip to content

Commit

Permalink
idk what's changed but now full recursive getResourceAsStream works
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbeMiglio committed Aug 31, 2023
1 parent 1c54f03 commit ab10a6f
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 27 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Development builds are always available at: **https://ci.codemc.io/job/AlbeMigli
<dependency>
<groupId>it.mycraft</groupId>
<artifactId>powerlib-<YOUR-PLATFORM></artifactId>
<version>1.2.9</version>
<version>1.2.10</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -61,7 +61,7 @@ repositories {
}
dependencies {
compileOnly 'it.mycraft:powerlib-<YOUR-PLATFORM>:1.2.9'
compileOnly 'it.mycraft:powerlib-<YOUR-PLATFORM>:1.2.10'
}
```

Expand All @@ -82,7 +82,7 @@ your plugin and rename its packages:
<dependency>
<groupId>it.mycraft</groupId>
<artifactId>powerlib-<YOUR-PLATFORM></artifactId>
<version>1.2.9</version>
<version>1.2.10</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>powerlib</artifactId>
<groupId>it.mycraft</groupId>
<version>1.2.9</version>
<version>1.2.10</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion bukkit-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>it.mycraft</groupId>
<artifactId>powerlib</artifactId>
<version>1.2.9</version>
<version>1.2.10</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion bukkit-plugin/src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#
# PowerLib v1.2.9
# PowerLib v1.2.10
#
check-for-updates: true
2 changes: 1 addition & 1 deletion bukkit-plugin/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PowerLib
authors: [AlbeMiglio, FranFrau]
main: it.mycraft.powerlib.bukkit.PowerLibPlugin
version: 1.2.9
version: 1.2.10
2 changes: 1 addition & 1 deletion bukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>it.mycraft</groupId>
<artifactId>powerlib</artifactId>
<version>1.2.9</version>
<version>1.2.10</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.mycraft.powerlib.bukkit.config;

import it.mycraft.powerlib.common.chat.Message;
import it.mycraft.powerlib.common.configuration.ConfigManager;
import it.mycraft.powerlib.common.configuration.Configuration;
import it.mycraft.powerlib.common.configuration.ConfigurationProvider;
Expand Down Expand Up @@ -62,7 +63,7 @@ public Configuration get(String file) {
* @return The new file
*/
public Configuration create(String file, String source) {
File resourcePath = new File(folder + "/" + file);
File resourcePath = new File(folder + File.separator + file);
if (!resourcePath.exists()) {
createYAML(file, source, false);
}
Expand All @@ -86,7 +87,7 @@ public void save(String file) {
}
try {
ConfigurationProvider.getProvider(YamlConfiguration.class)
.save(config, new File(folder + "/" + file));
.save(config, new File(folder + File.separator + file));
} catch (IOException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Exception encountered while saving a yaml file! Please contact an administrator!");
}
Expand Down Expand Up @@ -123,7 +124,7 @@ public void reloadAll() {
private Configuration load(String file) {
try {
return ConfigurationProvider.getProvider(YamlConfiguration.class)
.load(new File(folder + "/" + file));
.load(new File(folder + File.separator + file));
} catch (IOException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Exception encountered while loading a yaml file! Please contact an administrator!");
return null;
Expand All @@ -149,22 +150,24 @@ private void put(String file, Configuration config) {
*/
private void createYAML(String resourcePath, String source, boolean replace) {
try {
File file = new File(folder + "/" + resourcePath);
File file = new File(folder + File.separator + resourcePath);
if (!file.getParentFile().exists() || !file.exists()) {
file.getParentFile().mkdir();
file.getParentFile().mkdirs();
if (file.createNewFile()) {
replace = true;
}
if (file.length() == 0) {
replace = true;
}
if (replace) {
Files.copy(getResourceAsStream(source),
file.toPath(), StandardCopyOption.REPLACE_EXISTING);
Files.copy(getResourceAsStream(source), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
} else Files.copy(getResourceAsStream(source), file.toPath());
}
} catch (IOException | ClassNotFoundException | URISyntaxException e) {
Bukkit.getLogger().log(Level.SEVERE, "Exception encountered while creating a yaml file! Please contact an administrator!");
new Message("&cException encountered while creating a yaml file! Please contact an administrator!",
"&cError message: %msg")
.addPlaceHolder("%msg", e.getMessage())
.sendConsole();
}
}

Expand All @@ -174,14 +177,17 @@ private void createYAML(String resourcePath, boolean replace) {


private InputStream getResourceAsStream(String name) throws ClassNotFoundException, URISyntaxException, IOException {

try (ZipFile file = new ZipFile(pluginJar);
ZipInputStream zip = new ZipInputStream(pluginJar.toURL().openStream())) {
boolean stop = false;
while (!stop) {
ZipEntry e = zip.getNextEntry();
if (e == null) {
stop = true;
} else if (e.getName().equals(name)) {
continue;
}
if (e.getName().equals(name)) {
return cloneInputStream(file.getInputStream(e));
}
}
Expand Down
2 changes: 1 addition & 1 deletion bungee-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>powerlib</artifactId>
<groupId>it.mycraft</groupId>
<version>1.2.9</version>
<version>1.2.10</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion bungee-plugin/src/main/resources/bungee.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ name: PowerLib
author: AlbeMiglio
authors: [AlbeMiglio, FranFrau]
main: it.mycraft.powerlib.bungee.PowerLibPlugin
version: 1.2.9
version: 1.2.10
2 changes: 1 addition & 1 deletion bungee-plugin/src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#
# PowerLib v1.2.9
# PowerLib v1.2.10
#
check-for-updates: true
2 changes: 1 addition & 1 deletion bungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>powerlib</artifactId>
<groupId>it.mycraft</groupId>
<version>1.2.9</version>
<version>1.2.10</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>powerlib</artifactId>
<groupId>it.mycraft</groupId>
<version>1.2.9</version>
<version>1.2.10</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>it.mycraft</groupId>
<artifactId>powerlib</artifactId>
<packaging>pom</packaging>
<version>1.2.9</version>
<version>1.2.10</version>
<licenses>
<license>
<name>MIT License</name>
Expand Down
2 changes: 1 addition & 1 deletion velocity-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>powerlib</artifactId>
<groupId>it.mycraft</groupId>
<version>1.2.9</version>
<version>1.2.10</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.nio.file.Path;

@Getter
@Plugin(id = "powerlib", name = "PowerLib", version = "1.2.9", authors = {"AlbeMiglio", "FranFrau"})
@Plugin(id = "powerlib", name = "PowerLib", version = "1.2.10", authors = {"AlbeMiglio", "FranFrau"})
public class PowerLibPlugin {

private ProxyServer proxy;
Expand Down
2 changes: 1 addition & 1 deletion velocity-plugin/src/main/resources/velocity-plugin.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{"id":"powerlib","name":"PowerLib","version":"1.2.9","authors":["AlbeMiglio","FranFrau"],
{"id":"powerlib","name":"PowerLib","version":"1.2.10","authors":["AlbeMiglio","FranFrau"],
"dependencies":[],"main":"it.mycraft.powerlib.velocity.PowerLibPlugin"}
2 changes: 1 addition & 1 deletion velocity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>powerlib</artifactId>
<groupId>it.mycraft</groupId>
<version>1.2.9</version>
<version>1.2.10</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down

0 comments on commit ab10a6f

Please sign in to comment.