Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,36 @@ public class ManageStaffChatCommand implements CommandExecutor, TabCompleter {
public ManageStaffChatCommand(StaffChatPlugin plugin) {
this.plugin = plugin;
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@NullOr String option = (args.length >= 1) ? args[0].toLowerCase(Locale.ROOT) : null;


// 1. Handle your new "toggle" command first

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did AI write this?

if (args.length >= 1 && args[0].equalsIgnoreCase("toggle")) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you adding toggle functionality to /managestaffchat?

if (!(sender instanceof Player)) {
sender.sendMessage("Only players can use this command.");
return true;
}
Player player = (Player) sender;
if (args.length >= 2) {
String state = args[1].toLowerCase(Locale.ROOT);
if (state.equals("yes") || state.equals("on")) {
plugin.data().getOrCreateProfile(player).receivesStaffChatMessages(true);
player.sendMessage(colorful("&9StaffChat &fenabled."));
} else if (state.equals("no") || state.equals("off")) {
plugin.data().getOrCreateProfile(player).receivesStaffChatMessages(false);
player.sendMessage(colorful("&9StaffChat &fdisabled."));
} else {
player.sendMessage(colorful("&cUsage: /staffchat toggle <yes|no>"));
}
} else {
player.sendMessage(colorful("&cUsage: /staffchat toggle <yes|no>"));
}
return true;
}

// 2. Handle your existing logic
if (option == null || HELP_ALIASES.contains(option)) {
usage(sender, label);
} else if (RELOAD_ALIASES.contains(option)) {
Expand All @@ -76,29 +101,27 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
"&9&lDiscordSRV-Staff-Chat&f: &7&oUnknown arguments: " + String.join(" ", args)
));
}

return true;
}

@Override
public @NullOr List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
@NullOr List<String> suggestions = null;

if (args.length <= 0) {
suggestions = new ArrayList<>(ALL_OPTION_ALIASES);
} else if (args.length == 1) {
String last = args[0].toLowerCase(Locale.ROOT);

suggestions =
ALL_OPTION_ALIASES.stream()
.filter(option -> option.contains(last))
.collect(Collectors.toCollection(ArrayList::new));
// 1. Handle the "toggle" subcommand
if (args.length == 1) {
return List.of("toggle").stream()
.filter(option -> option.startsWith(args[0].toLowerCase(Locale.ROOT)))
.collect(Collectors.toList());
}

if (suggestions != null) {
suggestions.sort(String.CASE_INSENSITIVE_ORDER);

// 2. Handle the "yes/no" selection after "toggle"
else if (args.length == 2 && args[0].equalsIgnoreCase("toggle")) {
return List.of("yes", "no").stream()
.filter(option -> option.startsWith(args[1].toLowerCase(Locale.ROOT)))
.collect(Collectors.toList());
}
return suggestions;

return null; // Or return original list if you have other completions

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire file should really remain unchanged.

}

private void usage(CommandSender sender, String label) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,62 @@
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import com.rezzedup.discordsrv.staffchat.StaffChatPlugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
Comment on lines +31 to +36

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These things are already imported.

import java.util.Locale;
import static com.rezzedup.discordsrv.staffchat.util.Strings.colorful;

public class StaffChatCommand implements CommandExecutor {
private final StaffChatPlugin plugin;

public StaffChatCommand(StaffChatPlugin plugin) {
this.plugin = plugin;
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
// 1. NEW TOGGLE LOGIC
if (args.length >= 1 && args[0].equalsIgnoreCase("toggle")) {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players can use this command.");
return true;
}

Player player = (Player) sender;
// Get the profile
var profile = plugin.data().getOrCreateProfile(player);

if (args.length >= 2) {
String state = args[1].toLowerCase(Locale.ROOT);

if (state.equals("yes") || state.equals("on")) {
profile.automaticStaffChat(true); // Explicitly ENABLE
player.sendMessage(colorful("&9StaffChat &fenabled."));
} else if (state.equals("no") || state.equals("off")) {
profile.automaticStaffChat(false); // Explicitly DISABLE
player.sendMessage(colorful("&9StaffChat &fdisabled."));
} else {
player.sendMessage(colorful("&cUsage: /staffchat toggle <yes|no>"));
}
} else {
player.sendMessage(colorful("&cUsage: /staffchat toggle <yes|no>"));
}
return true; // Stop here
}

// 2. EXISTING LOGIC
if (args.length <= 0) {
// Show usage to console (only players can enable auto chat)
if (!(sender instanceof Player)) {
return false;
}
plugin.data().getOrCreateProfile((Player) sender).toggleAutomaticStaffChat();
} else {
String message = String.join(" ", args);

if (sender instanceof Player) {
plugin.submitMessageFromPlayer((Player) sender, message);
} else if (sender instanceof ConsoleCommandSender) {
Expand All @@ -55,7 +92,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
sender.sendMessage("Unsupported command sender type: " + sender.getClass().getSimpleName());
}
}

return true;
}
}