From 546827cd5ab4ef435128027bc69ef0f52d530444 Mon Sep 17 00:00:00 2001 From: Video Date: Sun, 13 Nov 2022 23:20:46 -0700 Subject: [PATCH] Resolves FS-320 and fixes FS-471 --- .../command/Command_nickgradient.java | 7 +++- .../command/Command_nicknyan.java | 35 +++++++++---------- .../command/Command_nickrainbow.java | 7 +++- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickgradient.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickgradient.java index 3fba2d4f..402459c5 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickgradient.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickgradient.java @@ -15,10 +15,15 @@ import org.bukkit.entity.Player; @CommandParameters(description = "Essentials Interface Command - Rainbowify your nickname.", usage = "/ ", aliases = "nickgr") public class Command_nickgradient extends FreedomCommand { - @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { + if (!server.getPluginManager().isPluginEnabled("Essentials")) + { + msg("Essentials is not enabled on this server."); + return true; + } + if (args.length != 3) { return false; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nicknyan.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nicknyan.java index 706b54d5..251680cf 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nicknyan.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nicknyan.java @@ -2,20 +2,25 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.Arrays; @CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Essentials Interface Command - Randomize the colors of your nickname.", usage = "/ < | off>") public class Command_nicknyan extends FreedomCommand { - @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { + if (!server.getPluginManager().isPluginEnabled("Essentials")) + { + msg("Essentials is not enabled on this server."); + return true; + } + if (args.length != 1) { return false; @@ -41,32 +46,24 @@ public class Command_nicknyan extends FreedomCommand return true; } - for (Player player : Bukkit.getOnlinePlayers()) + + if (server.getOnlinePlayers().stream().anyMatch(player -> player != playerSender + && (player.getName().equalsIgnoreCase(nickPlain) + || ChatColor.stripColor(plugin.esb.getNickname(player.getName())).trim().equalsIgnoreCase(nickPlain)))) { - if (player == playerSender) - { - continue; - } - if (player.getName().equalsIgnoreCase(nickPlain) || ChatColor.stripColor(player.getDisplayName()).trim().equalsIgnoreCase(nickPlain)) - { - msg("That nickname is already in use."); - return true; - } + msg("That nickname is already in use."); + return true; } final StringBuilder newNick = new StringBuilder(); - - final char[] chars = nickPlain.toCharArray(); - for (char c : chars) - { - newNick.append(FUtil.randomChatColor()).append(c); - } + Arrays.stream(nickPlain.chars().toArray()).forEach(character -> newNick.append(FUtil.randomChatColor()) + .append(Character.toString(character))); newNick.append(ChatColor.WHITE); plugin.esb.setNickname(sender.getName(), newNick.toString()); - msg("Your nickname is now: " + newNick.toString()); + msg("Your nickname is now: " + newNick); return true; } } \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickrainbow.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickrainbow.java index d82b4f30..94de311f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickrainbow.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickrainbow.java @@ -12,10 +12,15 @@ import org.bukkit.entity.Player; @CommandParameters(description = "Essentials Interface Command - Rainbowify your nickname.", usage = "/ ") public class Command_nickrainbow extends FreedomCommand { - @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { + if (!server.getPluginManager().isPluginEnabled("Essentials")) + { + msg("Essentials is not enabled on this server."); + return true; + } + if (args.length != 1) { return false;