if statements. if (!getConfig().isXYcommand-allowed) { sender.sendMessage("This command is currently not available"); }
@JoloCodeBrahs Use HashSets or List to store a player's name as a string. Adding or removing the objects from it is pretty much toggling on and off.
Can i get a better example lets say with fly command so i will have an idea how to remake it with other commands? @Henzz @mcdorli
@JoloCodeBrahs Using this from one of my old plugins. Let's say the recipients are our players who are permitted to fly. joinChannel() = Toggle on leaveChannel() = Toggle off Code: package main.java.net.bigbadcraft.localonly; import java.util.List; import org.bukkit.entity.Player; public class LocalChat { private List<String> recipients; public LocalChat(List<String> recipients) { this.recipients = recipients; } public void joinChannel(Player player) { recipients.add(player.getName()); } public void leaveChannel(Player player) { recipients.remove(player.getName()); } public boolean isInChannel(Player player) { return recipients.contains(player.getName()) ? true : false; } public List<String> getRecipients() { return recipients; } } And with the commands you can use if statement checks to verify if a player is in the list or not. In this case you'd replace the messages with fly mode code. Code: package main.java.net.bigbadcraft.localonly.commands; import main.java.net.bigbadcraft.localonly.LocalOnly; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.entity.Player; public class LocalCommand extends BaseCommand { private LocalOnly instance; public LocalCommand(LocalOnly instance) { this.instance = instance; } public void run(Player player, Command command, String[] args) { if (args.length == 0) { if (instance.localChat.isInChannel(player)) { player.sendMessage(ChatColor.YELLOW + "You are already in your local channel."); } else { instance.localChat.joinChannel(player); player.sendMessage(ChatColor.YELLOW + "You have joined your local channel."); } } } }