Fixed double quotes and Tablist flairs
This commit is contained in:
parent
d5050d0c30
commit
4dc5004e7c
6 changed files with 38 additions and 21 deletions
Binary file not shown.
|
@ -59,14 +59,22 @@ public class PlayerListener implements Listener { // 2015.07.16.
|
||||||
if (essentials == null)
|
if (essentials == null)
|
||||||
essentials = ((Essentials) Bukkit.getPluginManager().getPlugin(
|
essentials = ((Essentials) Bukkit.getPluginManager().getPlugin(
|
||||||
"Essentials"));
|
"Essentials"));
|
||||||
Player p = event.getPlayer();
|
final Player p = event.getPlayer();
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
|
||||||
.getUniqueId());
|
.getUniqueId());
|
||||||
mp.PlayerName = p.getName(); // 2015.10.17. 0:58
|
mp.PlayerName = p.getName();
|
||||||
if (!mp.FlairState.equals(FlairStates.NoComment))
|
if (!mp.FlairState.equals(FlairStates.NoComment)) {
|
||||||
// if (false)
|
PluginMain.ConfirmUserMessage(mp);
|
||||||
PluginMain.ConfirmUserMessage(mp); // 2015.08.09.
|
Timer timer = new Timer();
|
||||||
else { // 2015.07.20.
|
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
p.setPlayerListName(p.getName() + mp.GetFormattedFlair());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
tt.mp = mp;
|
||||||
|
timer.schedule(tt, 1000);
|
||||||
|
} else {
|
||||||
Timer timer = new Timer();
|
Timer timer = new Timer();
|
||||||
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
|
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -183,17 +191,24 @@ 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();
|
String formattedmessage = event.getMessage();
|
||||||
message = message.replace("\"", "\\\"");
|
formattedmessage = formattedmessage.replace("\\", "\\\\"); // It's
|
||||||
message = message.replace("\\", "\\\\");
|
// really
|
||||||
|
// important
|
||||||
|
// to escape
|
||||||
|
// the
|
||||||
|
// slashes
|
||||||
|
// first
|
||||||
|
formattedmessage = formattedmessage.replace("\"", "\\\"");
|
||||||
|
String suggestmsg = formattedmessage;
|
||||||
|
|
||||||
// URLs
|
// URLs
|
||||||
String[] parts = message.split("\\s+");
|
String[] parts = formattedmessage.split("\\s+");
|
||||||
boolean hadurls = false;
|
boolean hadurls = false;
|
||||||
for (String item : parts)
|
for (String item : parts)
|
||||||
try {
|
try {
|
||||||
URL url = new URL(item);
|
URL url = new URL(item);
|
||||||
message = message
|
formattedmessage = formattedmessage
|
||||||
.replace(
|
.replace(
|
||||||
item,
|
item,
|
||||||
String.format(
|
String.format(
|
||||||
|
@ -211,8 +226,8 @@ public class PlayerListener implements Listener { // 2015.07.16.
|
||||||
if (!hadurls) {
|
if (!hadurls) {
|
||||||
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
|
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
|
||||||
String color = ""; // 2015.08.17.
|
String color = ""; // 2015.08.17.
|
||||||
if (message.matches("(?i).*" + Pattern.quote(p.getName())
|
if (formattedmessage.matches("(?i).*"
|
||||||
+ ".*")) {
|
+ Pattern.quote(p.getName()) + ".*")) {
|
||||||
if (NotificationSound == null)
|
if (NotificationSound == null)
|
||||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f,
|
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f,
|
||||||
0.5f); // 2015.08.12.
|
0.5f); // 2015.08.12.
|
||||||
|
@ -227,7 +242,7 @@ public class PlayerListener implements Listener { // 2015.07.16.
|
||||||
.GetFlairColor()));
|
.GetFlairColor()));
|
||||||
}
|
}
|
||||||
|
|
||||||
message = message.replaceAll(
|
formattedmessage = formattedmessage.replaceAll(
|
||||||
"(?i)" + Pattern.quote(p.getName()),
|
"(?i)" + Pattern.quote(p.getName()),
|
||||||
color
|
color
|
||||||
+ p.getName()
|
+ p.getName()
|
||||||
|
@ -249,7 +264,7 @@ public class PlayerListener implements Listener { // 2015.07.16.
|
||||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||||
nwithoutformatting = nwithoutformatting.replace("§"
|
nwithoutformatting = nwithoutformatting.replace("§"
|
||||||
+ nwithoutformatting.charAt(index + 1), "");
|
+ nwithoutformatting.charAt(index + 1), "");
|
||||||
if (message.matches("(?i).*"
|
if (formattedmessage.matches("(?i).*"
|
||||||
+ Pattern.quote(nwithoutformatting) + ".*")) {
|
+ Pattern.quote(nwithoutformatting) + ".*")) {
|
||||||
p = Bukkit.getPlayer(nicknames.get(n));
|
p = Bukkit.getPlayer(nicknames.get(n));
|
||||||
if (NotificationSound == null)
|
if (NotificationSound == null)
|
||||||
|
@ -261,7 +276,7 @@ public class PlayerListener implements Listener { // 2015.07.16.
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); // 2015.08.17.
|
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); // 2015.08.17.
|
||||||
}
|
}
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
message = message.replaceAll(
|
formattedmessage = formattedmessage.replaceAll(
|
||||||
"(?i)" + Pattern.quote(nwithoutformatting),
|
"(?i)" + Pattern.quote(nwithoutformatting),
|
||||||
n
|
n
|
||||||
+ (greentext ? "§a"
|
+ (greentext ? "§a"
|
||||||
|
@ -288,8 +303,7 @@ public class PlayerListener implements Listener { // 2015.07.16.
|
||||||
json.append(String
|
json.append(String
|
||||||
.format("{\"text\":\"[%s]%s\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"Copy message\",\"color\":\"blue\"}},clickEvent:{\"action\":\"suggest_command\",\"value\":\"%s\"}},",
|
.format("{\"text\":\"[%s]%s\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"Copy message\",\"color\":\"blue\"}},clickEvent:{\"action\":\"suggest_command\",\"value\":\"%s\"}},",
|
||||||
player.CurrentChannel.DisplayName,
|
player.CurrentChannel.DisplayName,
|
||||||
(!player.RPMode ? "[OOC]" : ""), event.getMessage()
|
(!player.RPMode ? "[OOC]" : ""), suggestmsg));
|
||||||
.replace("\"", "\\\"")));
|
|
||||||
json.append("{\"text\":\" <\"},");
|
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()));
|
||||||
|
@ -326,7 +340,7 @@ public class PlayerListener implements Listener { // 2015.07.16.
|
||||||
if (!hadurls) {
|
if (!hadurls) {
|
||||||
for (String original : list)
|
for (String original : list)
|
||||||
// Hashtags
|
// Hashtags
|
||||||
message = message
|
formattedmessage = formattedmessage
|
||||||
.replace(
|
.replace(
|
||||||
"#" + original,
|
"#" + original,
|
||||||
String.format(
|
String.format(
|
||||||
|
@ -337,7 +351,9 @@ public class PlayerListener implements Listener { // 2015.07.16.
|
||||||
}
|
}
|
||||||
|
|
||||||
json.append(String.format("{\"text\":\"%s\",\"color\":\"%s\"}]",
|
json.append(String.format("{\"text\":\"%s\",\"color\":\"%s\"}]",
|
||||||
message, (greentext ? "green" : player.CurrentChannel.Color)));
|
formattedmessage, (greentext ? "green"
|
||||||
|
: player.CurrentChannel.Color)));
|
||||||
|
//System.out.println(formattedmessage); // TO!DO: TMP
|
||||||
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 :
|
||||||
|
@ -545,6 +561,7 @@ public class PlayerListener implements Listener { // 2015.07.16.
|
||||||
} else
|
} else
|
||||||
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
||||||
String.format("tellraw @a %s", json.toString()));
|
String.format("tellraw @a %s", json.toString()));
|
||||||
|
//System.out.println("JSON: " + json); // TO!DO: TMP
|
||||||
PluginMain.Instance
|
PluginMain.Instance
|
||||||
.getServer()
|
.getServer()
|
||||||
.getConsoleSender()
|
.getConsoleSender()
|
||||||
|
@ -671,7 +688,7 @@ public class PlayerListener implements Listener { // 2015.07.16.
|
||||||
if (town.hasNation()) {
|
if (town.hasNation()) {
|
||||||
Resident res = tu.getResidentMap().get(
|
Resident res = tu.getResidentMap().get(
|
||||||
event.getPlayer().getName());
|
event.getPlayer().getName());
|
||||||
if (res != null && res.hasTown()) { // TODO: Fix
|
if (res != null && res.hasTown()) {
|
||||||
Town town2 = res.getTown();
|
Town town2 = res.getTown();
|
||||||
if (town2.hasNation()) {
|
if (town2.hasNation()) {
|
||||||
if (town.getNation().getEnemies()
|
if (town.getNation().getEnemies()
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue