Skip to content

Commit

Permalink
Fix issues with ignore & pm commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Brikster committed Jul 29, 2023
1 parent 16d9319 commit 44ff8cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.gson.*;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import ru.mrbrikster.baseplugin.config.Configuration;
import ru.mrbrikster.chatty.Chatty;
Expand Down Expand Up @@ -112,9 +111,9 @@ public Optional<JsonElement> getProperty(Player player, String property) {
}

public boolean isIgnore(CommandSender recipient, CommandSender sender) {
if (sender != null && !(recipient instanceof ConsoleCommandSender)) {
if (sender != null && recipient instanceof Player) {
JsonElement jsonElement = Chatty.instance().getExact(JsonStorage.class)
.getProperty((Player)recipient, "ignore").orElseGet(JsonArray::new);
.getProperty((Player) recipient, "ignore").orElseGet(JsonArray::new);

if (jsonElement.isJsonArray()) {
for (JsonElement ignoreJsonElement : jsonElement.getAsJsonArray()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ public void handle(CommandSender sender, String label, String[] args) {
return;
}

Player ignoreTargetPlayer = Bukkit.getPlayer(args[0]);
String ignoreTarget = ignoreTargetPlayer.getName();

if (sender.getName().equalsIgnoreCase(ignoreTarget)) {
if (sender.getName().equalsIgnoreCase(args[0])) {
sender.sendMessage(Chatty.instance().messages().get("ignore-command.cannot-ignore-yourself")
.replace("{label}", label));
return;
Expand All @@ -78,22 +75,27 @@ public void handle(CommandSender sender, String label, String[] args) {
if (!jsonElement.isJsonArray())
jsonElement = new JsonArray();

if (jsonElement.getAsJsonArray().contains(new JsonPrimitive(ignoreTarget.toLowerCase()))) {
if (jsonElement.getAsJsonArray().contains(new JsonPrimitive(args[0].toLowerCase()))) {
Player targetPlayer = Bukkit.getPlayerExact(args[0]);
sender.sendMessage(Chatty.instance().messages().get("ignore-command.remove-ignore")
.replace("{label}", label).replace("{player}", ignoreTargetPlayer == null
? ignoreTarget
: ignoreTargetPlayer.getName()));
((JsonArray) jsonElement).remove(new JsonPrimitive(ignoreTarget.toLowerCase()));
.replace("{label}", label).replace("{player}", targetPlayer == null
? args[0].toLowerCase()
: targetPlayer.getName()));
((JsonArray) jsonElement).remove(new JsonPrimitive(args[0].toLowerCase()));
} else {
Player ignoreTargetPlayer = Bukkit.getPlayerExact(args[0]);

if (ignoreTargetPlayer == null) {
sender.sendMessage(Chatty.instance().messages().get("ignore-command.player-not-found")
.replace("{label}", label));
return;
}

String ignoreTarget = ignoreTargetPlayer.getName();

sender.sendMessage(Chatty.instance().messages().get("ignore-command.add-ignore")
.replace("{label}", label).replace("{player}", ignoreTargetPlayer.getName()));
jsonElement.getAsJsonArray().add(ignoreTargetPlayer.getName().toLowerCase());
.replace("{label}", label).replace("{player}", ignoreTarget));
jsonElement.getAsJsonArray().add(ignoreTarget.toLowerCase());
}

jsonStorage.setProperty((Player) sender, "ignore", jsonElement);
Expand Down

0 comments on commit 44ff8cd

Please sign in to comment.