Fix packet manager for essentials
This commit is contained in:
1 parent
cc891bce78
commit
21e9c645d7
2 files changed
+24
-50
No files matched your search
@@ -158,71 +158,45 @@ public class JSONManipulator {
|
||||
continue;
|
||||
}
|
||||
if (element.isJsonObject()) {
|
||||
JsonElement text = element.getAsJsonObject().get("text");
|
||||
if(text != null && ChatManager.containsSeparator(text.getAsString())) {
|
||||
if(!ChatManager.containsSeparatorEnd(text.getAsString())) // if the separator doesn't end in the same string as it's begin
|
||||
JsonObject o = element.getAsJsonObject();
|
||||
JsonElement text = o.get("text");
|
||||
if(text != null && !text.getAsString().isEmpty()) {
|
||||
if (ChatManager.containsSeparator(text.getAsString()) && !ChatManager.containsSeparatorEnd(text.getAsString())) // if the separator doesn't end in the same string as it's begin
|
||||
separator = true;
|
||||
if(!ChatManager.containsSeparator(o.toString())) {
|
||||
addParsedStringToArray(text.getAsString(), replacer, o, tooltip);
|
||||
}
|
||||
}
|
||||
ChatItem.debug("Parsing object " + element.toString());
|
||||
addParsedJsonObjectToArray(element.getAsJsonObject(), replacer, tooltip);
|
||||
if (o.has("extra") && !o.get("extra").getAsJsonArray().isEmpty()) {
|
||||
JsonArray jar = o.get("extra").getAsJsonArray();
|
||||
JsonArray tmpArray = parseArray(jar, tooltip);
|
||||
if (!tmpArray.isEmpty()) {
|
||||
o.add("extra", tmpArray);
|
||||
replacer.add(o);
|
||||
}
|
||||
ChatItem.debug("[addParsedJsonObjectToArray] " + jar + " parsed " + tmpArray + " into " + replacer);
|
||||
}
|
||||
|
||||
} else if (element.isJsonArray()) {
|
||||
JsonArray jar = element.getAsJsonArray();
|
||||
if (jar.size() != 0) {
|
||||
jar = parseArray(element.getAsJsonArray(), tooltip);
|
||||
replacer.set(i, jar);
|
||||
if (!jar.isEmpty()) {
|
||||
replacer.set(i, parseArray(element.getAsJsonArray(), tooltip));
|
||||
}
|
||||
} else if(element.isJsonPrimitive()) {
|
||||
if(ChatManager.containsSeparator(element.getAsString())) {
|
||||
if(!ChatManager.containsSeparatorEnd(element.getAsString())) // if the separator doesn't end in the same string as it's begin
|
||||
separator = true;
|
||||
addParsedStringToArray(element.getAsString(), replacer, element, tooltip);
|
||||
}
|
||||
} else
|
||||
replacer.add(element); // add basic element
|
||||
}
|
||||
}
|
||||
return replacer;
|
||||
}
|
||||
|
||||
private void addParsedJsonObjectToArray(JsonObject o, JsonArray rep, JsonElement tooltip) {
|
||||
JsonElement text = o.get("text");
|
||||
if (text == null) {
|
||||
JsonElement el = o.get("extra");
|
||||
if (el != null) {
|
||||
JsonArray jar = el.getAsJsonArray();
|
||||
if (jar.size() != 0) {
|
||||
JsonArray tmpArray = parseArray(jar, tooltip);
|
||||
if (!tmpArray.isEmpty())
|
||||
o.add("extra", tmpArray);
|
||||
else
|
||||
o.remove("extra");
|
||||
} else {
|
||||
o.remove("extra");
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
if (text.getAsString().isEmpty()) {
|
||||
JsonElement el = o.get("extra");
|
||||
if (el != null) {
|
||||
JsonArray jar = el.getAsJsonArray();
|
||||
if (!jar.isEmpty()) {
|
||||
JsonArray tmpArray = parseArray(jar, tooltip);
|
||||
if (!tmpArray.isEmpty())
|
||||
o.add("extra", tmpArray);
|
||||
else
|
||||
o.remove("extra");
|
||||
} else {
|
||||
o.remove("extra");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addParsedStringToArray(text.getAsString(), rep, o, tooltip);
|
||||
}
|
||||
|
||||
private void addParsedStringToArray(String msg, JsonArray rep, JsonElement o, JsonElement tooltip) {
|
||||
if (!ChatManager.containsSeparator(msg)) {
|
||||
rep.add(o);
|
||||
rep.add(o.deepCopy());
|
||||
return;
|
||||
}
|
||||
ChatItem.debug("[JSONManipulator] Parsed string " + msg + ", rep: " + rep);
|
||||
|
||||
@@ -36,7 +36,7 @@ public class PaperListener implements Listener {
|
||||
return manage.getStorage();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onChat(AsyncChatEvent e) {
|
||||
if (ChatManager.isTestingEnabled() && !ChatManager.isTesting("paper"))
|
||||
return;
|
||||
@@ -84,7 +84,7 @@ public class PaperListener implements Listener {
|
||||
for (String s : slot.getPlaceholders()) {
|
||||
message = message.replaceText(TextReplacementConfig.builder().matchLiteral(s).replacement(like).build());
|
||||
}
|
||||
if (ChatItem.getInstance().getConfig().getBoolean("manager-config.paper.send-ourself", true) || Bukkit.getPluginManager().isPluginEnabled("Essentials")) {
|
||||
if (ChatItem.getInstance().getConfig().getBoolean("manager-config.paper.send-ourself", true)) {
|
||||
for (Audience a : e.viewers().isEmpty() ? Bukkit.getOnlinePlayers() : e.viewers())
|
||||
a.sendMessage(e.renderer().render(p, p.displayName(), message, a));
|
||||
e.setCancelled(true);
|
||||
|
||||
Reference in new issue
Block a user