mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-22 18:32:24 +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
|
# Set whether the shop's chest should be protected by explosions
|
||||||
explosion-protection: true
|
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
|
# Set the currency symbol after price values
|
||||||
currency-symbol: $
|
currency-symbol: $
|
||||||
|
|
||||||
|
@ -182,9 +182,10 @@ public class Commands extends BukkitCommand {
|
|||||||
player.sendMessage(Config.checking_update());
|
player.sendMessage(Config.checking_update());
|
||||||
|
|
||||||
UpdateChecker uc = new UpdateChecker(ShopChest.getInstance(), ShopChest.getInstance().getDescription().getWebsite());
|
UpdateChecker uc = new UpdateChecker(ShopChest.getInstance(), ShopChest.getInstance().getDescription().getWebsite());
|
||||||
if (uc.updateNeeded()) {
|
if (uc.updateNeeded(player)) {
|
||||||
ShopChest.latestVersion = uc.getVersion();
|
ShopChest.latestVersion = uc.getVersion();
|
||||||
ShopChest.downloadLink = uc.getLink();
|
ShopChest.downloadLink = uc.getLink();
|
||||||
|
ShopChest.broadcast = uc.getBroadcast();
|
||||||
ShopChest.isUpdateNeeded = true;
|
ShopChest.isUpdateNeeded = true;
|
||||||
|
|
||||||
JsonBuilder jb;
|
JsonBuilder jb;
|
||||||
@ -204,6 +205,8 @@ public class Commands extends BukkitCommand {
|
|||||||
player.sendMessage(Config.no_new_update());
|
player.sendMessage(Config.no_new_update());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ShopChest.broadcast != null && Config.enable_broadcast()) player.sendMessage(ShopChest.broadcast);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reload(Player player) {
|
private void reload(Player player) {
|
||||||
|
@ -57,6 +57,7 @@ public class ShopChest extends JavaPlugin{
|
|||||||
public static boolean isUpdateNeeded = false;
|
public static boolean isUpdateNeeded = false;
|
||||||
public static String latestVersion = "";
|
public static String latestVersion = "";
|
||||||
public static String downloadLink = "";
|
public static String downloadLink = "";
|
||||||
|
public static String broadcast = null;
|
||||||
|
|
||||||
public static Utils utils;
|
public static Utils utils;
|
||||||
|
|
||||||
@ -189,14 +190,15 @@ public class ShopChest extends JavaPlugin{
|
|||||||
|
|
||||||
instance = this;
|
instance = this;
|
||||||
|
|
||||||
|
|
||||||
if (uc == null) uc = new UpdateChecker(this, getDescription().getWebsite());
|
if (uc == null) uc = new UpdateChecker(this, getDescription().getWebsite());
|
||||||
logger.info("Checking for Updates");
|
logger.info("Checking for Updates");
|
||||||
if(uc.updateNeeded()) {
|
if(uc.updateNeeded(Bukkit.getConsoleSender())) {
|
||||||
latestVersion = uc.getVersion();
|
latestVersion = uc.getVersion();
|
||||||
downloadLink = uc.getLink();
|
downloadLink = uc.getLink();
|
||||||
|
broadcast = uc.getBroadcast();
|
||||||
isUpdateNeeded = true;
|
isUpdateNeeded = true;
|
||||||
Bukkit.getConsoleSender().sendMessage("[ShopChest] " + ChatColor.GOLD + "New version available: " + ChatColor.RED + latestVersion);
|
Bukkit.getConsoleSender().sendMessage("[ShopChest] " + ChatColor.GOLD + "New version available: " + ChatColor.RED + latestVersion);
|
||||||
|
if (broadcast != null && Config.enable_broadcast()) Bukkit.getConsoleSender().sendMessage("[ShopChest] " + broadcast);
|
||||||
} else {
|
} else {
|
||||||
logger.info("No new version available");
|
logger.info("No new version available");
|
||||||
isUpdateNeeded = false;
|
isUpdateNeeded = false;
|
||||||
@ -214,7 +216,7 @@ public class ShopChest extends JavaPlugin{
|
|||||||
default: return;
|
default: return;
|
||||||
}
|
}
|
||||||
jb.sendJson(p);
|
jb.sendJson(p);
|
||||||
|
if (broadcast != null && Config.enable_broadcast()) p.sendMessage(broadcast);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 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 hopper_protection() {return plugin.getConfig().getBoolean("hopper-protection");}
|
||||||
public static boolean explosion_protection() {return plugin.getConfig().getBoolean("explosion-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 double maximal_distance() {return plugin.getConfig().getDouble("maximal-distance");}
|
||||||
public static int default_limit() {return plugin.getConfig().getInt("shop-limits.default");}
|
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.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
|
||||||
import org.yi.acru.bukkit.Lockette.Lockette;
|
import org.yi.acru.bukkit.Lockette.Lockette;
|
||||||
|
|
||||||
import com.griefcraft.model.Protection;
|
import com.griefcraft.model.Protection;
|
||||||
|
@ -35,6 +35,7 @@ public class NotifyUpdate implements Listener {
|
|||||||
default: return;
|
default: return;
|
||||||
}
|
}
|
||||||
jb.sendJson(p);
|
jb.sendJson(p);
|
||||||
|
if (ShopChest.broadcast != null && Config.enable_broadcast()) p.sendMessage(ShopChest.broadcast);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package de.epiceric.shopchest.utils;
|
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.Connection;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
@ -14,13 +15,14 @@ public class UpdateChecker {
|
|||||||
private String url;
|
private String url;
|
||||||
private String version;
|
private String version;
|
||||||
private String link;
|
private String link;
|
||||||
|
private String broadcast;
|
||||||
|
|
||||||
public UpdateChecker(ShopChest plugin, String url) {
|
public UpdateChecker(ShopChest plugin, String url) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateNeeded() {
|
public boolean updateNeeded(CommandSender sender) {
|
||||||
try {
|
try {
|
||||||
Connection con = Jsoup.connect("http://textuploader.com/all1l/raw");
|
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");
|
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];
|
version = doc.text().split("\\|")[0];
|
||||||
link = url + "download?version=" + doc.text().split("\\|")[1];
|
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);
|
return !plugin.getDescription().getVersion().equals(version);
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception | Error e) {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,4 +52,8 @@ public class UpdateChecker {
|
|||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getBroadcast() {
|
||||||
|
return broadcast;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user