Made it possible to make other users glow and stop glowing
This commit is contained in:
parent
4a3658c11d
commit
70004084f1
|
|
@ -5,6 +5,7 @@ import com.alttd.playerutils.commands.playerutils_subcommands.*;
|
|||
import com.alttd.playerutils.config.Messages;
|
||||
import com.alttd.playerutils.event_listeners.RotateBlockEvent;
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.command.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
|
@ -51,7 +52,7 @@ public class PlayerUtilsCommand implements CommandExecutor, TabExecutor {
|
|||
return false;
|
||||
|
||||
if (!commandSender.hasPermission(subCommand.getPermission())) {
|
||||
commandSender.sendMiniMessage(Messages.GENERIC.NO_PERMISSION, null);
|
||||
commandSender.sendMiniMessage(Messages.GENERIC.NO_PERMISSION, Placeholder.parsed("permission", subCommand.getPermission()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.alttd.playerutils.util.Logger;
|
|||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
|
@ -28,13 +29,21 @@ public class Glow extends SubCommand {
|
|||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
commandSender.sendMiniMessage(Messages.GENERIC.PLAYER_ONLY, null);
|
||||
if (args.length != 2 && args.length != 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean otherPlayer = args.length == 3;
|
||||
Optional<Player> playerFromArg = getTargetPlayer(commandSender, args);
|
||||
if (playerFromArg.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length != 2) {
|
||||
return false;
|
||||
Player player = playerFromArg.get();
|
||||
|
||||
if (args[1].equalsIgnoreCase("off")) {
|
||||
turnOffGlow(commandSender, player, otherPlayer);
|
||||
return true;
|
||||
}
|
||||
|
||||
Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard();
|
||||
|
|
@ -43,12 +52,6 @@ public class Glow extends SubCommand {
|
|||
.filter(team -> team.hasPlayer(player))
|
||||
.forEach(team -> team.removePlayer(player));
|
||||
|
||||
if (args[1].equalsIgnoreCase("off")) {
|
||||
commandSender.sendMiniMessage(Messages.GLOW.GLOW_OFF, null);
|
||||
player.setGlowing(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
Optional<DyeColor> any = Arrays.stream(DyeColor.values()).filter(chatColor -> chatColor.name().equalsIgnoreCase(args[1])).findAny();
|
||||
if (any.isEmpty()) {
|
||||
commandSender.sendMiniMessage(getHelpMessage(), null);
|
||||
|
|
@ -65,22 +68,59 @@ public class Glow extends SubCommand {
|
|||
team.color(namedTextColor);
|
||||
}
|
||||
|
||||
turnOnGlow(commandSender, player, team, dyeColor, otherPlayer);
|
||||
return true;
|
||||
}
|
||||
|
||||
private Optional<Player> getTargetPlayer(CommandSender commandSender, String[] args) {
|
||||
if (args.length == 2) {
|
||||
if (!(commandSender instanceof Player commandPlayer)) {
|
||||
commandSender.sendMiniMessage(Messages.GENERIC.PLAYER_ONLY, null);
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(commandPlayer);
|
||||
}
|
||||
|
||||
if (!commandSender.hasPermission(getPermission() + ".other")) {
|
||||
commandSender.sendMiniMessage(Messages.GENERIC.NO_PERMISSION, Placeholder.parsed("permission", getPermission() + ".other"));
|
||||
return Optional.empty();
|
||||
}
|
||||
Optional<? extends Player> any = Bukkit.getOnlinePlayers().stream().filter(offlinePlayer -> offlinePlayer.getName().equalsIgnoreCase(args[2])).findAny();
|
||||
if (any.isPresent()) {
|
||||
return Optional.of(any.get());
|
||||
} else {
|
||||
commandSender.sendMiniMessage(Messages.GENERIC.PLAYER_NOT_FOUND, Placeholder.parsed("player", args[2]));
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private void turnOffGlow(CommandSender commandSender, Player player, boolean otherPlayer) {
|
||||
player.sendMiniMessage(Messages.GLOW.GLOW_OFF, null);
|
||||
player.setGlowing(false);
|
||||
if (otherPlayer) {
|
||||
commandSender.sendMiniMessage(Messages.GLOW.GLOW_OFF_FOR_PLAYER, Placeholder.component("player", player.name()));
|
||||
}
|
||||
}
|
||||
|
||||
private void turnOnGlow(CommandSender commandSender, Player player, Team team, DyeColor dyeColor, boolean otherPlayer) {
|
||||
if (team.getScoreboard() == null) {
|
||||
commandSender.sendMiniMessage(Messages.GLOW.UNABLE_TO_GET_SCOREBOARD, null);
|
||||
logger.warning("Unable to get scoreboard for team");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
// if (!team.hasEntry(player.getName())) {
|
||||
// team.addEntry(player.getName());
|
||||
// }
|
||||
if (!team.hasPlayer(player))
|
||||
team.addPlayer(player);
|
||||
player.setScoreboard(team.getScoreboard());
|
||||
|
||||
player.setGlowing(true);
|
||||
commandSender.sendMiniMessage(Messages.GLOW.GLOW_ON, Placeholder.parsed("color", dyeColor.name()));
|
||||
return true;
|
||||
player.sendMiniMessage(Messages.GLOW.GLOW_ON, Placeholder.parsed("color", dyeColor.name()));
|
||||
if (otherPlayer) {
|
||||
commandSender.sendMiniMessage(Messages.GLOW.GLOW_ON_FOR_PLAYER, TagResolver.resolver(
|
||||
Placeholder.parsed("color", dyeColor.name()),
|
||||
Placeholder.component("player", player.name())
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -93,6 +133,9 @@ public class Glow extends SubCommand {
|
|||
if (args.length == 2) {
|
||||
return Arrays.stream(DyeColor.values()).map(Enum::name).collect(Collectors.toList());
|
||||
}
|
||||
if (args.length == 3) {
|
||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).toList();
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,13 +50,15 @@ public class Messages extends AbstractConfig {
|
|||
public static class GENERIC {
|
||||
private static final String prefix = "generic.";
|
||||
|
||||
public static String NO_PERMISSION = "<red>You don't have permission for this command</red>";
|
||||
public static String NO_PERMISSION = "<red><hover:show_text:'<red><permission></red>'>You don't have permission for this command</hover></red>";
|
||||
public static String PLAYER_ONLY = "<red>This command can only be executed as a player</red>";
|
||||
public static String PLAYER_NOT_FOUND = "<red>Unable to find online player <player></red>";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
NO_PERMISSION = config.getString(prefix, "no-permission", NO_PERMISSION);
|
||||
PLAYER_ONLY = config.getString(prefix, "player-only", PLAYER_ONLY);
|
||||
PLAYER_NOT_FOUND = config.getString(prefix, "player-only", PLAYER_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -66,6 +68,8 @@ public class Messages extends AbstractConfig {
|
|||
public static String GLOW_OFF = "<green>Glow turned off</green>";
|
||||
public static String GLOW_ON = "<green>Glow turned on, you are now glowing <color></green>";
|
||||
public static String UNABLE_TO_GET_SCOREBOARD = "<red>Unable to get scoreboard for team</red>";
|
||||
public static String GLOW_OFF_FOR_PLAYER = "<green>Glow turned off for <player></green>";
|
||||
public static String GLOW_ON_FOR_PLAYER = "<green>Glow turned on for <player> they are now glowing <color></green>";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user