v3.14.2.0

This commit is contained in:
rockyhawk64 2020-12-08 11:38:03 +11:00
parent e8c3d434cf
commit 16fc049660
6 changed files with 123 additions and 14 deletions

View File

@ -20,6 +20,9 @@ config:
input-message:
- '%cp-tag%&aEnter Input for Command'
- '&cType &4%cp-args% &cto Cancel the command'
updater:
auto-update: true
minor-updates-only: true
format:
tag: '&6[&bCommandPanels&6]'
perms: '&cNo permission.'

View File

@ -1,4 +1,4 @@
version: 3.14.1.5
version: 3.14.2.0
main: me.rockyhawk.commandpanels.CommandPanels
name: CommandPanels
author: RockyHawk
@ -69,6 +69,8 @@ permissions:
default: op
commandpanel.version:
default: true
commandpanel.update:
default: op
commandpanel.addons:
default: true
commandpanel.editor:

View File

@ -213,6 +213,9 @@ public class CommandPanels extends JavaPlugin {
}
public void onDisable() {
if (Objects.requireNonNull(this.config.getString("config.updater.auto-update")).equalsIgnoreCase("true")) {
updater.autoUpdatePlugin(this.getFile().getName());
}
Bukkit.getLogger().info("RockyHawk's CommandPanels Plugin Disabled, aww man.");
}
@ -565,6 +568,9 @@ public class CommandPanels extends JavaPlugin {
if (p.hasPermission("commandpanel.version")) {
p.sendMessage(ChatColor.GOLD + "/cpv " + ChatColor.WHITE + "Display the current version.");
}
if (p.hasPermission("commandpanel.update")) {
p.sendMessage(ChatColor.GOLD + "/cpv [version:latest:cancel]" + ChatColor.WHITE + "Download an update upon server reload/restart.");
}
if (p.hasPermission("commandpanel.edit")) {
p.sendMessage(ChatColor.GOLD + "/cpe [panel] " + ChatColor.WHITE + "Edit a panel with the Panel Editor.");
}

View File

@ -15,20 +15,35 @@ public class Commandpanelversion implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (label.equalsIgnoreCase("cpv") || label.equalsIgnoreCase("commandpanelversion") || label.equalsIgnoreCase("cpanelv")) {
if (sender.hasPermission("commandpanel.version")) {
//version command
sender.sendMessage(plugin.papi(plugin.tag));
sender.sendMessage(ChatColor.GREEN + "This Version " + ChatColor.GRAY + plugin.getDescription().getVersion());
sender.sendMessage(ChatColor.GREEN + "Latest Version " + ChatColor.GRAY + plugin.updater.githubNewUpdate(false));
sender.sendMessage(ChatColor.GRAY + "-------------------");
sender.sendMessage(ChatColor.GREEN + "Developer " + ChatColor.GRAY + "RockyHawk");
sender.sendMessage(ChatColor.GREEN + "Command " + ChatColor.GRAY + "/cp");
if(args.length == 0) {
if (sender.hasPermission("commandpanel.version")) {
//version command
sender.sendMessage(plugin.papi(plugin.tag));
sender.sendMessage(ChatColor.GREEN + "This Version " + ChatColor.GRAY + plugin.getDescription().getVersion());
sender.sendMessage(ChatColor.GREEN + "Latest Version " + ChatColor.GRAY + plugin.updater.githubNewUpdate(false));
sender.sendMessage(ChatColor.GRAY + "-------------------");
sender.sendMessage(ChatColor.GREEN + "Developer " + ChatColor.GRAY + "RockyHawk");
sender.sendMessage(ChatColor.GREEN + "Command " + ChatColor.GRAY + "/cp");
} else {
sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.perms")));
}
}else if(args.length == 1){
if (sender.hasPermission("commandpanel.update")) {
if (args[0].equals("cancel")) {
plugin.updater.downloadVersionManually = null;
sender.sendMessage(plugin.papi(plugin.tag + ChatColor.GREEN + "Will not download a new version on reload or restart."));
} else {
plugin.updater.downloadVersionManually = args[0];
sender.sendMessage(plugin.papi(plugin.tag + ChatColor.GREEN + "Downloading version " + ChatColor.GRAY + args[0] + ChatColor.GREEN + " upon server reload or restart."));
}
}else{
sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.perms")));
}
}else{
sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.perms")));
sender.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "Usage: /cpv [update]"));
}
return true;
}
sender.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "Usage: /cpv"));
return true;
}
}

View File

@ -13,6 +13,7 @@ import org.bukkit.event.block.Action;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.*;
import org.bukkit.inventory.ItemStack;
@ -36,6 +37,8 @@ public class UtilsOpenWithItem implements Listener {
Player p = (Player)e.getWhoClicked();
//get the item clicked, then loop through panel names after action isn't nothing
if(e.getAction() == InventoryAction.NOTHING){return;}
if(e.getSlot() == -999){return;}
if(e.getClickedInventory().getType() != InventoryType.PLAYER){return;}
if(plugin.hotbar.stationaryExecute(e.getSlot(),p,true)){
e.setCancelled(true);
p.updateInventory();

View File

@ -4,11 +4,11 @@ import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Objects;
import java.util.logging.Level;
public class Updater {
CommandPanels plugin;
@ -16,6 +16,10 @@ public class Updater {
this.plugin = pl;
}
//if this is set to something, it will download that version on restart
//can be a version number, 'latest' or 'cancel'
public String downloadVersionManually = null;
public String githubNewUpdate(boolean sendMessages){
HttpURLConnection connection;
String gitVersion;
@ -60,4 +64,80 @@ public class Updater {
}
return null;
}
//the pluginFileName can only be obtained from the main class
public void autoUpdatePlugin(String pluginFileName){
String latestVersion = githubNewUpdate(false);
String thisVersion = plugin.getDescription().getVersion();
if(downloadVersionManually != null) {
if (downloadVersionManually.equals("latest")) {
downloadFile(latestVersion, pluginFileName);
}else{
downloadFile(downloadVersionManually, pluginFileName);
}
return;
}
if(latestVersion.equals(thisVersion)){
//no need to update
return;
}
if(Objects.equals(plugin.config.getString("config.updater.minor-updates-only"), "true")){
//only update versions that will not break
if(thisVersion.split("\\.")[1].equals(latestVersion.split("\\.")[1]) && thisVersion.split("\\.")[0].equals(latestVersion.split("\\.")[0])){
//the first and second number of the version is the same, updates: [major.major.minor.minor]
downloadFile(latestVersion,pluginFileName);
}
}else{
downloadFile(latestVersion,pluginFileName);
}
}
private void downloadFile(String latestVersion, String pluginFileName) {
BufferedInputStream in = null;
FileOutputStream fout = null;
try {
this.plugin.getLogger().info("Downloading new update: " + "v" + latestVersion);
URL fileUrl = new URL("https://github.com/rockyhawk64/CommandPanels/releases/download/" + latestVersion + "/Command.Panels.jar");
int fileLength = fileUrl.openConnection().getContentLength();
in = new BufferedInputStream(fileUrl.openStream());
fout = new FileOutputStream(new File(new File(".").getAbsolutePath() + "/plugins/", pluginFileName));
byte[] data = new byte[1024];
long downloaded = 0L;
int count;
while((count = in.read(data, 0, 1024)) != -1) {
downloaded += count;
fout.write(data, 0, count);
int percent = (int)(downloaded * 100L / (long)fileLength);
if (percent % 10 == 0) {
this.plugin.getLogger().info("Downloading update: " + percent + "% of " + fileLength + " bytes.");
}
}
this.plugin.getLogger().info("Finished updating.");
} catch (Exception var22) {
this.plugin.getLogger().log(Level.WARNING, "Could not download update.", var22);
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException var21) {
this.plugin.getLogger().log(Level.SEVERE, null, var21);
}
try {
if (fout != null) {
fout.close();
}
} catch (IOException var20) {
this.plugin.getLogger().log(Level.SEVERE, null, var20);
}
}
}
}