From 54b0f42eafb9d40e898069d361cfc5aa84c8d2e0 Mon Sep 17 00:00:00 2001 From: Eric Date: Sat, 7 May 2016 22:50:26 +0200 Subject: [PATCH] Allow multiline broadcast messages Apparently the new-line character isn't detected so I had to make a workaround with a custom new-line character (#n) where it could split the lines. --- src/de/epiceric/shopchest/Commands.java | 6 +++++- src/de/epiceric/shopchest/ShopChest.java | 16 ++++++++++++---- src/de/epiceric/shopchest/config/Config.java | 2 +- .../epiceric/shopchest/event/NotifyUpdate.java | 6 +++++- .../epiceric/shopchest/utils/UpdateChecker.java | 10 ++++++---- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/de/epiceric/shopchest/Commands.java b/src/de/epiceric/shopchest/Commands.java index a3d05e6..a1876ba 100644 --- a/src/de/epiceric/shopchest/Commands.java +++ b/src/de/epiceric/shopchest/Commands.java @@ -167,7 +167,11 @@ public class Commands extends BukkitCommand { if (perm.has(player, "shopchest.broadcast")) { if (Config.enable_broadcast()) ShopChest.broadcast = uc.getBroadcast(); - if (!ShopChest.broadcast.equals("")) player.sendMessage(ShopChest.broadcast); + if (ShopChest.broadcast != null) { + for (String message : ShopChest.broadcast) { + player.sendMessage(message); + } + } } } diff --git a/src/de/epiceric/shopchest/ShopChest.java b/src/de/epiceric/shopchest/ShopChest.java index 156d164..64f0f8e 100644 --- a/src/de/epiceric/shopchest/ShopChest.java +++ b/src/de/epiceric/shopchest/ShopChest.java @@ -56,7 +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 String[] broadcast = null; public static Utils utils; @@ -190,7 +190,7 @@ public class ShopChest extends JavaPlugin{ 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(); @@ -226,11 +226,19 @@ public class ShopChest extends JavaPlugin{ for (Player p : getServer().getOnlinePlayers()) { if (perm.has(p, "shopchest.broadcast")) { - if (!broadcast.equals("")) p.sendMessage(broadcast); + if (broadcast != null) { + for (String message : broadcast) { + p.sendMessage(message); + } + } } } - if (!broadcast.equals("")) Bukkit.getConsoleSender().sendMessage("[ShopChest] " + broadcast); + if (broadcast != null) { + for (String message : broadcast) { + Bukkit.getConsoleSender().sendMessage("[ShopChest] " + message); + } + } File itemNamesFile = new File(getDataFolder(), "item_names.txt"); diff --git a/src/de/epiceric/shopchest/config/Config.java b/src/de/epiceric/shopchest/config/Config.java index aee7412..889b74e 100644 --- a/src/de/epiceric/shopchest/config/Config.java +++ b/src/de/epiceric/shopchest/config/Config.java @@ -20,7 +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 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");} diff --git a/src/de/epiceric/shopchest/event/NotifyUpdate.java b/src/de/epiceric/shopchest/event/NotifyUpdate.java index 146e3bb..c63827c 100644 --- a/src/de/epiceric/shopchest/event/NotifyUpdate.java +++ b/src/de/epiceric/shopchest/event/NotifyUpdate.java @@ -39,7 +39,11 @@ public class NotifyUpdate implements Listener { } if (perm.has(p, "shopchest.broadcast")) { - if (!ShopChest.broadcast.equals("")) p.sendMessage(ShopChest.broadcast); + if (ShopChest.broadcast != null) { + for (String message : ShopChest.broadcast) { + p.sendMessage(message); + } + } } } diff --git a/src/de/epiceric/shopchest/utils/UpdateChecker.java b/src/de/epiceric/shopchest/utils/UpdateChecker.java index 52ac2ca..3b1f0cd 100644 --- a/src/de/epiceric/shopchest/utils/UpdateChecker.java +++ b/src/de/epiceric/shopchest/utils/UpdateChecker.java @@ -44,7 +44,7 @@ public class UpdateChecker { } } - public String getBroadcast() { + 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"); @@ -52,13 +52,15 @@ public class UpdateChecker { Document doc = con.get(); String broadcast = doc.text(); - + + String[] messages = broadcast.split("#n"); + if (!broadcast.equals("/")) - return broadcast; + return messages; } catch (Exception | Error e) {} - return ""; + return null; } public String getVersion() {