-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added protocolLib dependency + auto download
- Loading branch information
Showing
4 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/main/java/xyz/prismenetwork/kelpmodloader/Dependency/DependencyManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package xyz.prismenetwork.kelpmodloader.Dependency; | ||
|
||
import java.util.HashMap; | ||
|
||
public class DependencyManager { | ||
public static HashMap<String, String> dependency = new HashMap<>(); | ||
public static void check() { | ||
//List of all dependency | ||
dependency.put("ProtocolLib", "https://github.com/dmulloy2/ProtocolLib/releases/latest/download/ProtocolLib.jar"); | ||
|
||
dependency.forEach((n, l) -> { | ||
Downloader.download(n, l); | ||
}); | ||
|
||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/xyz/prismenetwork/kelpmodloader/Dependency/Downloader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package xyz.prismenetwork.kelpmodloader.Dependency; | ||
|
||
import xyz.prismenetwork.kelpmodloader.KelpModLoader; | ||
|
||
import java.io.File; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.StandardCopyOption; | ||
|
||
public class Downloader { | ||
static File pluginFolder = KelpModLoader.getPlugin(KelpModLoader.class).getDataFolder().getParentFile(); | ||
public static void download(String name, String link) { | ||
|
||
if (KelpModLoader.getPlugin(KelpModLoader.class).getServer().getPluginManager().getPlugin(name)!=null) return; | ||
|
||
KelpModLoader.getPlugin(KelpModLoader.class).getLogger().warning(name + " is not installed, downloading ProtocolLib from " + link); | ||
|
||
try { | ||
InputStream in = new URL(link).openStream(); | ||
Files.copy(in, Path.of(pluginFolder.getPath() + "/"+ name + ".jar"), StandardCopyOption.REPLACE_EXISTING); | ||
|
||
KelpModLoader.getInstance.getPluginLoader().loadPlugin(new File(pluginFolder.getPath() + "/" + name + ".jar")); | ||
|
||
} catch (Exception e) { | ||
KelpModLoader.getPlugin(KelpModLoader.class).getLogger().warning("Could not download protocolLib:"); | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
} |
8 changes: 7 additions & 1 deletion
8
src/main/java/xyz/prismenetwork/kelpmodloader/KelpModLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters