-
-
Notifications
You must be signed in to change notification settings - Fork 18
Add explicit /staffchat toggle on/off command #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| if (args.length >= 1 && args[0].equalsIgnoreCase("toggle")) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) { | ||
|
|
@@ -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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
|
@@ -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; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did AI write this?