mirror of
https://github.com/plexusorg/Fossil.git
synced 2025-07-05 09:56:41 +00:00
Initial commit
This commit is contained in:
62
src/main/java/dev/plex/fossil/Fossil.java
Normal file
62
src/main/java/dev/plex/fossil/Fossil.java
Normal file
@ -0,0 +1,62 @@
|
||||
package dev.plex.fossil;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
|
||||
public final class Fossil extends JavaPlugin {
|
||||
|
||||
public static Fossil plugin;
|
||||
public static Server server;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
server = plugin.getServer();
|
||||
getCommand("fossil").setExecutor(new FossilCommand());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
}
|
||||
|
||||
public void downloadFile(String url, File output, boolean verbose) throws java.lang.Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
final var website = new URL(url);
|
||||
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
|
||||
FileOutputStream fos = new FileOutputStream(output);
|
||||
fos.getChannel().transferFrom(rbc, 0, 1 << 24);
|
||||
fos.close();
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
getLogger().info("Downloaded " + url + " to " + output + ".");
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException ex)
|
||||
{
|
||||
getLogger().info(url + " does not exist.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getPlugin(String pluginName)
|
||||
{
|
||||
return "https://fossil.plex.us.org/" + getNMSVersion() + "/" + pluginName + ".jar";
|
||||
// Example: https://updater.telesphoreo.me/v1_14_R1/WorldEdit.jar
|
||||
}
|
||||
|
||||
public String getNMSVersion()
|
||||
{
|
||||
return Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||
}
|
||||
}
|
57
src/main/java/dev/plex/fossil/FossilCommand.java
Normal file
57
src/main/java/dev/plex/fossil/FossilCommand.java
Normal file
@ -0,0 +1,57 @@
|
||||
package dev.plex.fossil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class FossilCommand implements CommandExecutor, IFossil {
|
||||
private final List<String> FILES = plugin.getConfig().getStringList("plugins");
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(Component.text("This server is running Fossil to keep plugins in sync."));
|
||||
sender.sendMessage(Component.text("Source code available at https://github.com/plexusorg/Fossil"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length > 1) {
|
||||
if (!sender.hasPermission("fossil.update")) {
|
||||
sender.sendMessage(Component.text("You do not have permission to use this command!").color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(Component.text("Updating server plugins").color(NamedTextColor.GRAY));
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
for (final String url : FILES) {
|
||||
logger.info("Downloading: " + url);
|
||||
|
||||
File file = new File("./plugins/update/" + url.substring(url.lastIndexOf("/") + 1));
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
plugin.downloadFile(url, file, true);
|
||||
}
|
||||
sender.sendMessage(Component.text("Successfully updated. Restart the server to apply changes.").color(NamedTextColor.GRAY));
|
||||
} catch (Exception ex) {
|
||||
logger.severe(ex.toString());
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
8
src/main/java/dev/plex/fossil/IFossil.java
Normal file
8
src/main/java/dev/plex/fossil/IFossil.java
Normal file
@ -0,0 +1,8 @@
|
||||
package dev.plex.fossil;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public interface IFossil {
|
||||
Fossil plugin = Fossil.plugin;
|
||||
Logger logger = plugin.getLogger();
|
||||
}
|
16
src/main/resources/config.yml
Normal file
16
src/main/resources/config.yml
Normal file
@ -0,0 +1,16 @@
|
||||
plugins:
|
||||
- CoreProtect
|
||||
- DiscordSRV
|
||||
- DrMap
|
||||
- LibsDisguises
|
||||
- EssentialsX
|
||||
- EssentialsXSpawn
|
||||
- Plex-FAWE
|
||||
- ItemizerX
|
||||
- LibsDisguises
|
||||
- LuckPerms
|
||||
- Plan
|
||||
- ProtocolLib
|
||||
- spark
|
||||
- Vault
|
||||
- WorldGuard
|
4
src/main/resources/plugin.yml
Normal file
4
src/main/resources/plugin.yml
Normal file
@ -0,0 +1,4 @@
|
||||
name: Fossil
|
||||
version: '${version}'
|
||||
main: dev.plex.fossil.Fossil
|
||||
api-version: 1.20
|
Reference in New Issue
Block a user