From 558741e58783783588857f38d7d32ce40ea56114 Mon Sep 17 00:00:00 2001 From: Eric Date: Sat, 7 May 2016 15:35:34 +0200 Subject: [PATCH] Re-added broadcast messages They work a bit different now. They are still only shown on startup, on join or when a player checks for updates, but also if no update is available. Also the player needs the permission "shopchest.broadcast" in order to get the message. --- config.yml | 2 -- plugin.yml | 5 ++++- src/de/epiceric/shopchest/Commands.java | 4 ++++ src/de/epiceric/shopchest/ShopChest.java | 11 +++++++++++ .../epiceric/shopchest/event/NotifyUpdate.java | 4 ++++ .../epiceric/shopchest/utils/UpdateChecker.java | 17 +++++++++++++++++ 6 files changed, 40 insertions(+), 3 deletions(-) diff --git a/config.yml b/config.yml index ad957b7..fb2dbe0 100644 --- a/config.yml +++ b/config.yml @@ -48,8 +48,6 @@ hopper-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 diff --git a/plugin.yml b/plugin.yml index 55a113a..9b37362 100644 --- a/plugin.yml +++ b/plugin.yml @@ -63,4 +63,7 @@ permissions: default: op shopchest.limits: description: Allows you to view shop limits. - default: true \ No newline at end of file + default: true + shopchest.broadcast: + description: Allows you to get broadcast messages. + default: op \ No newline at end of file diff --git a/src/de/epiceric/shopchest/Commands.java b/src/de/epiceric/shopchest/Commands.java index b4c00b4..aa87673 100644 --- a/src/de/epiceric/shopchest/Commands.java +++ b/src/de/epiceric/shopchest/Commands.java @@ -212,6 +212,10 @@ public class Commands extends BukkitCommand { player.sendMessage(Config.update_check_error()); } + if (perm.has(player, "shopchest.broadcast")) { + if (Config.enable_broadcast()) ShopChest.broadcast = uc.getBroadcast(); + if (!ShopChest.broadcast.equals("")) player.sendMessage(ShopChest.broadcast); + } } diff --git a/src/de/epiceric/shopchest/ShopChest.java b/src/de/epiceric/shopchest/ShopChest.java index fa81e27..f7e8c5a 100644 --- a/src/de/epiceric/shopchest/ShopChest.java +++ b/src/de/epiceric/shopchest/ShopChest.java @@ -56,6 +56,7 @@ public class ShopChest extends JavaPlugin{ public static boolean isUpdateNeeded = false; public static String latestVersion = ""; public static String downloadLink = ""; + public static String broadcast = ""; public static Utils utils; @@ -191,6 +192,8 @@ public class ShopChest extends JavaPlugin{ UpdateChecker uc = new UpdateChecker(this, getDescription().getWebsite()); UpdateCheckerResult result = uc.updateNeeded(); + if (Config.enable_broadcast()) broadcast = uc.getBroadcast(); + Bukkit.getConsoleSender().sendMessage("[ShopChest] " + Config.checking_update()); if(result == UpdateCheckerResult.TRUE) { latestVersion = uc.getVersion(); @@ -223,6 +226,14 @@ public class ShopChest extends JavaPlugin{ isUpdateNeeded = false; Bukkit.getConsoleSender().sendMessage("[ShopChest] " + Config.update_check_error()); } + + for (Player p : getServer().getOnlinePlayers()) { + if (perm.has(p, "shopchest.broadcast")) { + if (!broadcast.equals("")) p.sendMessage(broadcast); + } + } + + if (!broadcast.equals("")) Bukkit.getConsoleSender().sendMessage("[ShopChest] " + broadcast); File itemNamesFile = new File(getDataFolder(), "item_names.txt"); diff --git a/src/de/epiceric/shopchest/event/NotifyUpdate.java b/src/de/epiceric/shopchest/event/NotifyUpdate.java index 51ab594..146e3bb 100644 --- a/src/de/epiceric/shopchest/event/NotifyUpdate.java +++ b/src/de/epiceric/shopchest/event/NotifyUpdate.java @@ -38,6 +38,10 @@ public class NotifyUpdate implements Listener { } } + if (perm.has(p, "shopchest.broadcast")) { + if (!ShopChest.broadcast.equals("")) p.sendMessage(ShopChest.broadcast); + } + } } diff --git a/src/de/epiceric/shopchest/utils/UpdateChecker.java b/src/de/epiceric/shopchest/utils/UpdateChecker.java index 83f8038..52ac2ca 100644 --- a/src/de/epiceric/shopchest/utils/UpdateChecker.java +++ b/src/de/epiceric/shopchest/utils/UpdateChecker.java @@ -44,6 +44,23 @@ public class UpdateChecker { } } + public String getBroadcast() { + try { + Connection con = Jsoup.connect("http://textuploader.com/5b51f/raw"); + con.userAgent("Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0"); + + Document doc = con.get(); + + String broadcast = doc.text(); + + if (!broadcast.equals("/")) + return broadcast; + + } catch (Exception | Error e) {} + + return ""; + } + public String getVersion() { return version; }