Messages containing URLs won't be formatted to keep the original URL; clicking on the channel identifier (ex. [g]) will now copy the message.
This commit is contained in:
parent
d7be9fbe30
commit
d30126e1cf
6 changed files with 95 additions and 81 deletions
Binary file not shown.
|
@ -25,6 +25,7 @@ public class MaybeOfflinePlayer {
|
||||||
// public int Tables = 10;
|
// public int Tables = 10;
|
||||||
public Channel CurrentChannel = Channel.GlobalChat;
|
public Channel CurrentChannel = Channel.GlobalChat;
|
||||||
public int FCount;
|
public int FCount;
|
||||||
|
public boolean SendingLink = false;
|
||||||
|
|
||||||
public UUID UUID;
|
public UUID UUID;
|
||||||
|
|
||||||
|
|
|
@ -161,65 +161,93 @@ public class PlayerListener implements Listener { // 2015.07.16.
|
||||||
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event
|
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event
|
||||||
.getPlayer().getUniqueId());
|
.getPlayer().getUniqueId());
|
||||||
String message = event.getMessage(); // 2015.08.08.
|
String message = event.getMessage();
|
||||||
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
|
message = message.replace("\"", "''");
|
||||||
String color = ""; // 2015.08.17.
|
|
||||||
if (message.matches("(?i).*" + Pattern.quote(p.getName()) + ".*")) {
|
// URLs
|
||||||
if (NotificationSound == null)
|
String[] parts = message.split("\\s+");
|
||||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
boolean hadurls = false;
|
||||||
else
|
for (String item : parts)
|
||||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
try {
|
||||||
(float) NotificationPitch); // 2015.08.14.
|
URL url = new URL(item);
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
|
message = message
|
||||||
.getUniqueId());
|
.replace(
|
||||||
color = String.format("§%x", (mp.GetFlairColor() == 0x00 ? 0xb
|
item,
|
||||||
: mp.GetFlairColor())); // TODO: Quiz queue
|
String.format(
|
||||||
|
"\",\"color\":\"%s\"},{\"text\":\"%s\",\"color\":\"%s\",\"underlined\":\"true\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open URL\",\"color\":\"blue\"}]}}},{\"text\":\"",
|
||||||
|
(greentext ? "green"
|
||||||
|
: player.CurrentChannel.Color),
|
||||||
|
url, (greentext ? "green"
|
||||||
|
: player.CurrentChannel.Color),
|
||||||
|
url));
|
||||||
|
hadurls = true;
|
||||||
|
// System.out.println("URL: " + url);
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
message = message.replaceAll(
|
if (!hadurls) {
|
||||||
"(?i)" + Pattern.quote(p.getName()),
|
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
|
||||||
color
|
String color = ""; // 2015.08.17.
|
||||||
+ p.getName()
|
if (message.matches("(?i).*" + Pattern.quote(p.getName())
|
||||||
+ (greentext ? "§a"
|
+ ".*")) {
|
||||||
: player.CurrentChannel.DisplayName
|
if (NotificationSound == null)
|
||||||
.substring(0, 2)));
|
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f,
|
||||||
}
|
0.5f); // 2015.08.12.
|
||||||
for (String n : nicknames.keySet()) {
|
else
|
||||||
Player p = null;
|
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||||
String nwithoutformatting = new String(n);
|
(float) NotificationPitch); // 2015.08.14.
|
||||||
int index;
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer
|
||||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
.AddPlayerIfNeeded(p.getUniqueId());
|
||||||
nwithoutformatting = nwithoutformatting.replace("§k"
|
color = String.format(
|
||||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
"§%x",
|
||||||
// for
|
(mp.GetFlairColor() == 0x00 ? 0xb : mp
|
||||||
// one
|
.GetFlairColor())); // TODO: Quiz queue
|
||||||
// random
|
}
|
||||||
// char
|
|
||||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
|
||||||
nwithoutformatting = nwithoutformatting.replace("§"
|
|
||||||
+ nwithoutformatting.charAt(index + 1), "");
|
|
||||||
if (message.matches("(?i).*" + Pattern.quote(nwithoutformatting)
|
|
||||||
+ ".*")) {
|
|
||||||
p = Bukkit.getPlayer(nicknames.get(n));
|
|
||||||
if (NotificationSound == null)
|
|
||||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
|
||||||
else
|
|
||||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
|
||||||
(float) NotificationPitch); // 2015.08.14.
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); // 2015.08.17.
|
|
||||||
}
|
|
||||||
if (p != null) {
|
|
||||||
message = message.replaceAll(
|
message = message.replaceAll(
|
||||||
"(?i)" + Pattern.quote(nwithoutformatting),
|
"(?i)" + Pattern.quote(p.getName()),
|
||||||
n
|
color
|
||||||
|
+ p.getName()
|
||||||
+ (greentext ? "§a"
|
+ (greentext ? "§a"
|
||||||
: player.CurrentChannel.DisplayName
|
: player.CurrentChannel.DisplayName
|
||||||
.substring(0, 2)));
|
.substring(0, 2)));
|
||||||
}
|
}
|
||||||
|
for (String n : nicknames.keySet()) {
|
||||||
|
Player p = null;
|
||||||
|
String nwithoutformatting = new String(n);
|
||||||
|
int index;
|
||||||
|
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||||
|
nwithoutformatting = nwithoutformatting.replace("§k"
|
||||||
|
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||||
|
// for
|
||||||
|
// one
|
||||||
|
// random
|
||||||
|
// char
|
||||||
|
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||||
|
nwithoutformatting = nwithoutformatting.replace("§"
|
||||||
|
+ nwithoutformatting.charAt(index + 1), "");
|
||||||
|
if (message.matches("(?i).*"
|
||||||
|
+ Pattern.quote(nwithoutformatting) + ".*")) {
|
||||||
|
p = Bukkit.getPlayer(nicknames.get(n));
|
||||||
|
if (NotificationSound == null)
|
||||||
|
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f,
|
||||||
|
0.5f); // 2015.08.12.
|
||||||
|
else
|
||||||
|
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||||
|
(float) NotificationPitch); // 2015.08.14.
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); // 2015.08.17.
|
||||||
|
}
|
||||||
|
if (p != null) {
|
||||||
|
message = message.replaceAll(
|
||||||
|
"(?i)" + Pattern.quote(nwithoutformatting),
|
||||||
|
n
|
||||||
|
+ (greentext ? "§a"
|
||||||
|
: player.CurrentChannel.DisplayName
|
||||||
|
.substring(0, 2)));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
event.setMessage(message);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* event.setFormat(event .getFormat() .replace( "{rptag}",
|
* event.setFormat(event .getFormat() .replace( "{rptag}",
|
||||||
* (player.RPMode ? (ShowRPTag ? "§2[RP]§r" : "") : "§8[OOC]§r"))
|
* (player.RPMode ? (ShowRPTag ? "§2[RP]§r" : "") : "§8[OOC]§r"))
|
||||||
|
@ -234,9 +262,11 @@ public class PlayerListener implements Listener { // 2015.07.16.
|
||||||
|
|
||||||
StringBuilder json = new StringBuilder();
|
StringBuilder json = new StringBuilder();
|
||||||
json.append("[\"\",");
|
json.append("[\"\",");
|
||||||
json.append(String.format("{\"text\":\"[%s]%s <\"},",
|
json.append(String
|
||||||
player.CurrentChannel.DisplayName, (!player.RPMode ? "[OOC]"
|
.format("{\"text\":\"[%s]%s\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"Copy message\",\"color\":\"blue\"}},clickEvent:{\"action\":\"suggest_command\",\"value\":\"%s\"}},",
|
||||||
: "")));
|
player.CurrentChannel.DisplayName,
|
||||||
|
(!player.RPMode ? "[OOC]" : ""), event.getMessage()));
|
||||||
|
json.append("{\"text\":\" <\"},");
|
||||||
json.append(String.format("{\"text\":\"%s%s\",", event.getPlayer()
|
json.append(String.format("{\"text\":\"%s%s\",", event.getPlayer()
|
||||||
.getDisplayName(), player.GetFormattedFlair()));
|
.getDisplayName(), player.GetFormattedFlair()));
|
||||||
json.append("\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[");
|
json.append("\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[");
|
||||||
|
@ -266,40 +296,22 @@ public class PlayerListener implements Listener { // 2015.07.16.
|
||||||
String original = event.getMessage().substring(index + 1, index2);
|
String original = event.getMessage().substring(index + 1, index2);
|
||||||
list.add(original);
|
list.add(original);
|
||||||
}
|
}
|
||||||
String finalstring = event.getMessage().replace("\"", "''");
|
|
||||||
for (String original : list)
|
|
||||||
// Hashtags
|
|
||||||
finalstring = finalstring
|
|
||||||
.replace(
|
|
||||||
"#" + original,
|
|
||||||
String.format(
|
|
||||||
"\",\"color\":\"%s\"},{\"text\":\"#%s\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}},{\"text\":\"",
|
|
||||||
(greentext ? "green"
|
|
||||||
: player.CurrentChannel.Color),
|
|
||||||
original, original));
|
|
||||||
|
|
||||||
String[] parts = finalstring.split("\\s+");
|
if (!hadurls) {
|
||||||
|
for (String original : list)
|
||||||
// URLs
|
// Hashtags
|
||||||
for (String item : parts)
|
message = message
|
||||||
try {
|
|
||||||
URL url = new URL(item);
|
|
||||||
finalstring = finalstring
|
|
||||||
.replace(
|
.replace(
|
||||||
item,
|
"#" + original,
|
||||||
String.format(
|
String.format(
|
||||||
"\",\"color\":\"%s\"},{\"text\":\"%s\",\"color\":\"%s\",\"underlined\":\"true\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open URL\",\"color\":\"blue\"}]}}},{\"text\":\"",
|
"\",\"color\":\"%s\"},{\"text\":\"#%s\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}},{\"text\":\"",
|
||||||
(greentext ? "green"
|
(greentext ? "green"
|
||||||
: player.CurrentChannel.Color),
|
: player.CurrentChannel.Color),
|
||||||
url, (greentext ? "green"
|
original, original));
|
||||||
: player.CurrentChannel.Color),
|
}
|
||||||
url));
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
json.append(String.format("{\"text\":\"%s\",\"color\":\"%s\"}]",
|
json.append(String.format("{\"text\":\"%s\",\"color\":\"%s\"}]",
|
||||||
finalstring, (greentext ? "green"
|
message, (greentext ? "green" : player.CurrentChannel.Color)));
|
||||||
: player.CurrentChannel.Color)));
|
|
||||||
if (player.CurrentChannel.equals(Channel.TownChat)
|
if (player.CurrentChannel.equals(Channel.TownChat)
|
||||||
|| player.CurrentChannel.equals(Channel.NationChat))
|
|| player.CurrentChannel.equals(Channel.NationChat))
|
||||||
// for (Resident resident :
|
// for (Resident resident :
|
||||||
|
@ -513,7 +525,8 @@ public class PlayerListener implements Listener { // 2015.07.16.
|
||||||
String.format("[%s] <%s%s> %s",
|
String.format("[%s] <%s%s> %s",
|
||||||
player.CurrentChannel.DisplayName, event
|
player.CurrentChannel.DisplayName, event
|
||||||
.getPlayer().getDisplayName(), player
|
.getPlayer().getDisplayName(), player
|
||||||
.GetFormattedFlair(), message));
|
.GetFormattedFlair(), event
|
||||||
|
.getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue