package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; import me.totalfreedom.totalfreedommod.command.handling.SourceType; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.List; import java.util.Map; @CommandPermissions(permission = "links", source = SourceType.BOTH) @CommandParameters(description = "See TotalFreedom's social media links.", usage = "/", aliases = "link") public class Command_links extends FreedomCommand { @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { YamlConfiguration config = plugin.config.configuration; ConfigurationSection section = config.getConfigurationSection("social_links"); if (section != null) { Map values = section.getValues(false); List lines = new ArrayList<>(); values.keySet() .stream() .filter(key -> values.get(key) instanceof String) .forEach(key -> { String link = (String) values.get(key); lines.add(ChatColor.GOLD + "- " + key + ": " + ChatColor.AQUA + link); }); msg("Social Media Links:", ChatColor.AQUA); sender.sendMessage(lines.toArray(new String[0])); return true; } else { msg("There are no links added in the configuration file.", ChatColor.RED); } return true; } }