parent
b9781f19f0
commit
def4a846b2
3 changed files with 16 additions and 143 deletions
|
@ -1,16 +1,22 @@
|
|||
package buttondevteam.core;
|
||||
|
||||
import buttondevteam.lib.architecture.ButtonPlugin;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.ICommand2MC;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
@CommandClass
|
||||
public class ChromaCommand extends ICommand2MC {
|
||||
@Command2.Subcommand //TODO: Main permissions (groups) like 'mod'
|
||||
public void reload(CommandSender sender) {
|
||||
if (MainPlugin.Instance.tryReloadConfig())
|
||||
sender.sendMessage("§bCore config reloaded.");
|
||||
@Command2.Subcommand
|
||||
public void reload(CommandSender sender, @Command2.OptionalArg Plugin plugin) {
|
||||
if(plugin==null)
|
||||
plugin=MainPlugin.Instance;
|
||||
if(!(plugin instanceof ButtonPlugin))
|
||||
plugin.reloadConfig();
|
||||
else if (((ButtonPlugin) plugin).tryReloadConfig())
|
||||
sender.sendMessage("§b"+plugin.getName()+" config reloaded.");
|
||||
else
|
||||
sender.sendMessage("§cFailed to reload config. Check console.");
|
||||
}
|
||||
|
|
|
@ -155,21 +155,6 @@ public class MainPlugin extends ButtonPlugin {
|
|||
logger.info("Saving player data...");
|
||||
TBMCPlayerBase.savePlayers();
|
||||
logger.info("Player data saved.");
|
||||
new Thread(() -> {
|
||||
File[] files = PluginUpdater.updatedir.listFiles();
|
||||
if (files == null)
|
||||
return;
|
||||
logger.info("Updating " + files.length + " plugins...");
|
||||
for (File file : files) {
|
||||
try {
|
||||
Files.move(file.toPath(), new File("plugins", file.getName()).toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
logger.info("Updated " + file.getName());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
logger.info("Update complete!");
|
||||
}).start();
|
||||
}
|
||||
|
||||
private boolean setupPermissions() {
|
||||
|
|
|
@ -17,19 +17,17 @@ import java.util.List;
|
|||
import java.util.Optional;
|
||||
|
||||
public class PluginUpdater {
|
||||
private PluginUpdater() {
|
||||
}
|
||||
|
||||
public static final File updatedir = new File("TBMC", "pluginupdates");
|
||||
private final File updatedir = Bukkit.getServer().getUpdateFolderFile();
|
||||
/**
|
||||
* See {@link TBMCCoreAPI#UpdatePlugin(String, CommandSender, String)}
|
||||
*/
|
||||
public static boolean UpdatePlugin(String name, CommandSender sender, String branch) {
|
||||
public boolean UpdatePlugin(String name, CommandSender sender, String branch) {
|
||||
if (!updatedir.exists() && !updatedir.mkdirs()) {
|
||||
error(sender, "Failed to create update directory!");
|
||||
return false;
|
||||
}
|
||||
info(sender, "Checking plugin name...");
|
||||
/*info(sender, "Checking plugin name...");
|
||||
List<String> plugins = GetPluginNames();
|
||||
String correctname = null;
|
||||
for (String plugin : plugins) {
|
||||
|
@ -58,62 +56,10 @@ public class PluginUpdater {
|
|||
return false;
|
||||
}
|
||||
info(sender, "Updating TBMC plugin: " + correctname + " from " + correctbranch.get());
|
||||
return updatePluginJitPack(sender, correctname, correctbranch.get());
|
||||
}
|
||||
|
||||
private static boolean updatePluginJitPack(CommandSender sender, String correctname,
|
||||
String correctbranch) {
|
||||
/*URL url;
|
||||
File result = new File(updatedir, correctname + ".jar");
|
||||
try {
|
||||
url = new URL("https://jitpack.io/com/github/TBMCPlugins/"
|
||||
+ (correctname.equals("ButtonCore") ? "ButtonCore/ButtonCore" : correctname) + "/"
|
||||
+ correctbranch + "-SNAPSHOT/" + correctname + "-" + correctbranch + "-SNAPSHOT.jar"); // ButtonCore exception required since it hosts Towny as well
|
||||
FileUtils.copyURLToFile(url, result);
|
||||
if (!result.exists() || result.length() < 25) {
|
||||
result.delete();
|
||||
error(sender, "The downloaded JAR for " + correctname + " from " + correctbranch
|
||||
+ " is too small (smnaller than 25 bytes). Am I downloading from the right place?");
|
||||
return false;
|
||||
} else {
|
||||
info(sender, "Updating plugin " + correctname + " from " + correctbranch + " done!");
|
||||
return updatePluginJitPack(sender, correctname, correctbranch.get());*/
|
||||
info(sender, "Not implemented");
|
||||
return true;
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
error(sender,
|
||||
"Can't find JAR for " + correctname + " from " + correctbranch
|
||||
+ ", the build probably failed. Build log (scroll to bottom):" + "\n"
|
||||
+ "https://jitpack.io/com/github/TBMCPlugins/" + correctname + "/" + correctbranch
|
||||
+ "-SNAPSHOT/build.log\nIf you'd like to rebuild the same commit, go to:\nhttps://jitpack.io/#TBMCPlugins/"
|
||||
+ correctname + "\nAnd delete the newest build.");
|
||||
} catch (IOException e) {
|
||||
error(sender, "IO error while updating " + correctname + "\n" + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
error(sender, "Unknown error while updating " + correctname + ": " + e); - TODO: Either add Commons or don't use FileUtils
|
||||
}*/
|
||||
info(sender, "Plugin updating is currently not supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if pom.xml is not present for the project.
|
||||
*
|
||||
* @param pluginname
|
||||
* Does not have to match case
|
||||
* @param branch
|
||||
* Does not have to match case
|
||||
*/
|
||||
public static boolean isNotMaven(String pluginname, String branch) {
|
||||
try {
|
||||
return TBMCCoreAPI
|
||||
.DownloadString(
|
||||
"https://raw.githubusercontent.com/TBMCPlugins/" + pluginname + "/" + branch + "/pom.xml")
|
||||
.equals("404: Not Found\n");
|
||||
} catch (IOException e1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static void error(CommandSender sender, String message) {
|
||||
if (!sender.equals(Bukkit.getConsoleSender()))
|
||||
|
@ -126,68 +72,4 @@ public class PluginUpdater {
|
|||
Bukkit.getLogger().info(message);
|
||||
sender.sendMessage("§b" + message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all the repository names from the GitHub organization.
|
||||
*
|
||||
* @return A list of names
|
||||
*/
|
||||
public static List<String> GetPluginNames() {
|
||||
List<String> ret = new ArrayList<>();
|
||||
try {
|
||||
String resp = TBMCCoreAPI.DownloadString("https://api.github.com/orgs/" + "TBMCPlugins" + "/repos"); //TODO: PluginUpdater
|
||||
JsonArray arr = new JsonParser().parse(resp).getAsJsonArray();
|
||||
for (JsonElement obj : arr) {
|
||||
JsonObject jobj = obj.getAsJsonObject();
|
||||
ret.add(jobj.get("name").getAsString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all the branches from the plugin repository.
|
||||
*
|
||||
* @return A list of names
|
||||
*/
|
||||
public static List<String> GetPluginBranches(String plugin) {
|
||||
List<String> ret = new ArrayList<>();
|
||||
try {
|
||||
String resp = TBMCCoreAPI
|
||||
.DownloadString("https://api.github.com/repos/TBMCPlugins/" + plugin + "/branches");
|
||||
JsonArray arr = new JsonParser().parse(resp).getAsJsonArray();
|
||||
for (JsonElement obj : arr) {
|
||||
JsonObject jobj = obj.getAsJsonObject();
|
||||
ret.add(jobj.get("name").getAsString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static class UpdatedEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private final JsonObject data;
|
||||
|
||||
public UpdatedEvent(JsonObject data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public JsonObject getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue