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.
This commit is contained in:
Eric 2016-05-07 22:50:26 +02:00
parent 5f5fd05e6c
commit 54b0f42eaf
5 changed files with 29 additions and 11 deletions

View File

@ -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);
}
}
}
}

View File

@ -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");

View File

@ -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");}

View File

@ -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);
}
}
}
}

View File

@ -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() {