mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-22 10:22:29 +00:00
Added update message broadcast
This commit is contained in:
parent
20d3814aac
commit
ca2185a7a6
@ -47,6 +47,11 @@ hopper-protection: true
|
||||
# Set whether the shop's chest should be protected by explosions
|
||||
explosion-protection: true
|
||||
|
||||
# Set whether broadcast messages should be enabled
|
||||
# The messages are sent to every player who have permission to get update notifications.
|
||||
# They are sent each time the update checker checks for an update below the message whether an update is available.
|
||||
enable-broadcast: true
|
||||
|
||||
# Set the currency symbol after price values
|
||||
currency-symbol: $
|
||||
|
||||
|
@ -182,9 +182,10 @@ public class Commands extends BukkitCommand {
|
||||
player.sendMessage(Config.checking_update());
|
||||
|
||||
UpdateChecker uc = new UpdateChecker(ShopChest.getInstance(), ShopChest.getInstance().getDescription().getWebsite());
|
||||
if (uc.updateNeeded()) {
|
||||
if (uc.updateNeeded(player)) {
|
||||
ShopChest.latestVersion = uc.getVersion();
|
||||
ShopChest.downloadLink = uc.getLink();
|
||||
ShopChest.broadcast = uc.getBroadcast();
|
||||
ShopChest.isUpdateNeeded = true;
|
||||
|
||||
JsonBuilder jb;
|
||||
@ -204,6 +205,8 @@ public class Commands extends BukkitCommand {
|
||||
player.sendMessage(Config.no_new_update());
|
||||
}
|
||||
|
||||
if (ShopChest.broadcast != null && Config.enable_broadcast()) player.sendMessage(ShopChest.broadcast);
|
||||
|
||||
}
|
||||
|
||||
private void reload(Player player) {
|
||||
|
@ -57,6 +57,7 @@ public class ShopChest extends JavaPlugin{
|
||||
public static boolean isUpdateNeeded = false;
|
||||
public static String latestVersion = "";
|
||||
public static String downloadLink = "";
|
||||
public static String broadcast = null;
|
||||
|
||||
public static Utils utils;
|
||||
|
||||
@ -189,14 +190,15 @@ public class ShopChest extends JavaPlugin{
|
||||
|
||||
instance = this;
|
||||
|
||||
|
||||
if (uc == null) uc = new UpdateChecker(this, getDescription().getWebsite());
|
||||
logger.info("Checking for Updates");
|
||||
if(uc.updateNeeded()) {
|
||||
if(uc.updateNeeded(Bukkit.getConsoleSender())) {
|
||||
latestVersion = uc.getVersion();
|
||||
downloadLink = uc.getLink();
|
||||
broadcast = uc.getBroadcast();
|
||||
isUpdateNeeded = true;
|
||||
Bukkit.getConsoleSender().sendMessage("[ShopChest] " + ChatColor.GOLD + "New version available: " + ChatColor.RED + latestVersion);
|
||||
if (broadcast != null && Config.enable_broadcast()) Bukkit.getConsoleSender().sendMessage("[ShopChest] " + broadcast);
|
||||
} else {
|
||||
logger.info("No new version available");
|
||||
isUpdateNeeded = false;
|
||||
@ -212,12 +214,12 @@ public class ShopChest extends JavaPlugin{
|
||||
case "v1_8_R3": jb = new JsonBuilder_1_8_R3(Config.update_available(latestVersion)); break;
|
||||
case "v1_9_R1": jb = new JsonBuilder_1_9_R1(Config.update_available(latestVersion)); break;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
jb.sendJson(p);
|
||||
|
||||
if (broadcast != null && Config.enable_broadcast()) p.sendMessage(broadcast);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File itemNamesFile = new File(getDataFolder(), "item_names.txt");
|
||||
|
||||
|
@ -20,6 +20,7 @@ public class Config {
|
||||
public static boolean buy_greater_or_equal_sell() {return plugin.getConfig().getBoolean("buy-greater-or-equal-sell");}
|
||||
public static boolean hopper_protection() {return plugin.getConfig().getBoolean("hopper-protection");}
|
||||
public static boolean explosion_protection() {return plugin.getConfig().getBoolean("explosion-protection)");}
|
||||
public static boolean enable_broadcast() {return plugin.getConfig().getBoolean("enable-broadcast)");}
|
||||
|
||||
public static double maximal_distance() {return plugin.getConfig().getDouble("maximal-distance");}
|
||||
public static int default_limit() {return plugin.getConfig().getInt("shop-limits.default");}
|
||||
|
@ -18,7 +18,6 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.yi.acru.bukkit.Lockette.Lockette;
|
||||
|
||||
import com.griefcraft.model.Protection;
|
||||
|
@ -35,6 +35,7 @@ public class NotifyUpdate implements Listener {
|
||||
default: return;
|
||||
}
|
||||
jb.sendJson(p);
|
||||
if (ShopChest.broadcast != null && Config.enable_broadcast()) p.sendMessage(ShopChest.broadcast);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.epiceric.shopchest.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.jsoup.Connection;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
@ -14,13 +15,14 @@ public class UpdateChecker {
|
||||
private String url;
|
||||
private String version;
|
||||
private String link;
|
||||
private String broadcast;
|
||||
|
||||
public UpdateChecker(ShopChest plugin, String url) {
|
||||
this.plugin = plugin;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public boolean updateNeeded() {
|
||||
public boolean updateNeeded(CommandSender sender) {
|
||||
try {
|
||||
Connection con = Jsoup.connect("http://textuploader.com/all1l/raw");
|
||||
con.userAgent("Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0");
|
||||
@ -30,11 +32,14 @@ public class UpdateChecker {
|
||||
version = doc.text().split("\\|")[0];
|
||||
link = url + "download?version=" + doc.text().split("\\|")[1];
|
||||
|
||||
if (doc.text().split("\\|").length == 3) {
|
||||
broadcast = doc.text().split("\\|")[2];
|
||||
}
|
||||
|
||||
return !plugin.getDescription().getVersion().equals(version);
|
||||
|
||||
|
||||
} catch (Exception | Error e) {
|
||||
Bukkit.getConsoleSender().sendMessage("[ShopChest] " + ChatColor.RED + "Error while checking for updates");
|
||||
sender.sendMessage((sender instanceof ConsoleCommandSender ? "[ShopChest] " : "") + ChatColor.RED + "Error while checking for updates");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -47,4 +52,8 @@ public class UpdateChecker {
|
||||
return link;
|
||||
}
|
||||
|
||||
public String getBroadcast() {
|
||||
return broadcast;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user