use of pizzaaxx.bteconosur.yaml.Configuration in project bteConoSurCore by BTEConoSur.
the class ProjectCommand method onEvent.
@Override
public void onEvent(@NotNull GenericEvent event) {
if (event instanceof MessageReceivedEvent) {
MessageReceivedEvent e = (MessageReceivedEvent) event;
if (e.getMessage().getContentRaw().startsWith("/")) {
String fullCommand = e.getMessage().getContentRaw();
String[] args = fullCommand.replaceFirst("/", "").split(" ");
if (args.length > 0) {
if (args[0].equals("project")) {
if (args.length > 1 && args[1].matches("[a-z]{6}")) {
try {
Project project = new Project(args[1]);
// DIFICULTAD
CompletableFuture.runAsync(() -> {
EmbedBuilder embed = new EmbedBuilder();
if (project.getDifficulty() == Project.Difficulty.DIFICIL) {
embed.setColor(new Color(255, 0, 0));
embed.addField(":tools: Dificultad: ", ":red_circle: Difícil", false);
} else if (project.getDifficulty() == Project.Difficulty.INTERMEDIO) {
embed.setColor(new Color(255, 220, 0));
embed.addField(":tools: Dificultad: ", ":yellow_circle: Intermedio", false);
} else {
embed.setColor(new Color(0, 255, 42));
embed.addField(":tools: Dificultad: ", ":green_circle: Fácil", false);
}
if (project.getOwner() != null) {
embed.setThumbnail("https://mc-heads.net/head/" + project.getOwner().getUniqueId().toString());
}
if (!Objects.equals(project.getName(), project.getId())) {
embed.setTitle("Proyecto \"" + project.getName() + "\" (ID: " + project.getId().toUpperCase() + ")");
} else {
embed.setTitle("Proyecto " + project.getId().toUpperCase());
}
// PAIS
embed.addField(":globe_with_meridians: País:", ":flag_" + project.getCountry().getAbbreviation() + ": " + StringUtils.capitalize(project.getCountry().getName()), false);
if (project.getTag() != null) {
embed.addField(":label: Etiqueta:", project.getTag().toString().toLowerCase().replace("edificios", ":cityscape: Edificios").replace("casas", ":house_with_garden: Casas").replace("departamentos", ":hotel: Departamentos").replace("centros_comerciales", ":shpping_bags: Centros Comerciales").replace("establecimientos", ":hospital: Establecimientos").replace("parques", ":deciduous_tree: Parques").replace("carreteras", ":motorway: Carreteras"), false);
}
// GOOGLE MAPS
double minX = project.getPoints().get(0).getX();
double maxX = project.getPoints().get(0).getX();
double minZ = project.getPoints().get(0).getZ();
double maxZ = project.getPoints().get(0).getZ();
for (BlockVector2D point : project.getPoints()) {
if (point.getX() > maxX) {
maxX = point.getX();
}
if (point.getX() < minX) {
minX = point.getX();
}
if (point.getZ() > maxZ) {
maxZ = point.getZ();
}
if (point.getZ() < minZ) {
minZ = point.getZ();
}
}
Coords2D geoCoord = new Coords2D(new Location(mainWorld, (minX + maxX) / 2, 100, (minZ + maxZ) / 2));
embed.addField(":round_pushpin: Coordenadas:", ("> " + geoCoord.getX() + " " + geoCoord.getHighestY() + " " + geoCoord.getZ()).replace(".5", "").replace(".0", ""), false);
embed.addField(":map: Google Maps:", "https://www.google.com/maps/@" + geoCoord.getLat() + "," + geoCoord.getLon() + ",19z", false);
if (project.getOwner() != null) {
embed.addField(":crown: Líder:", new ServerPlayer(project.getOwner()).getName(), false);
}
if (!project.getMembers().isEmpty()) {
List<String> members = new ArrayList<>();
for (OfflinePlayer player : project.getMembers()) {
members.add(new ServerPlayer(player).getName());
}
embed.addField(":busts_in_silhouette: Miembros:", String.join(", ", members), false);
}
// IMAGE
InputStream file;
try {
file = new URL(project.getImageUrl()).openStream();
} catch (IOException ex) {
ex.printStackTrace();
return;
}
embed.setImage("attachment://map.png");
e.getTextChannel().sendFile(file, "map.png").setEmbeds(embed.build()).reference(e.getMessage()).mentionRepliedUser(false).queue();
});
} catch (Exception exception) {
exception.printStackTrace();
EmbedBuilder error = new EmbedBuilder();
error.setColor(new Color(255, 0, 0));
error.setAuthor("Este proyecto no existe.");
e.getMessage().replyEmbeds(error.build()).mentionRepliedUser(false).queue();
}
} else {
EmbedBuilder error = new EmbedBuilder();
error.setColor(new Color(255, 0, 0));
error.setAuthor("Introduce un proyecto válido.");
e.getMessage().replyEmbeds(error.build()).mentionRepliedUser(false).queue();
}
}
if (args[0].equals("pending")) {
if (YamlManager.getYamlData(pluginFolder, "pending_projects/pending.yml").size() != 0) {
EmbedBuilder pending = new EmbedBuilder();
pending.setColor(new Color(0, 255, 42));
List<String> lines = new ArrayList<>();
List<String> projects = new Configuration(Bukkit.getPluginManager().getPlugin("bteConoSur"), "pending_projects/pending").getStringList("pending");
for (String str : projects) {
try {
Project project = new Project(str);
String line = "• :flag_" + project.getCountry().getAbbreviation() + ": " + project.getId();
if (!Objects.equals(project.getName(), project.getId())) {
line = line + " - " + project.getName();
}
lines.add(line);
} catch (Exception ignored) {
}
}
Collections.sort(lines);
String value = String.join("\n", lines);
pending.addField("Proyectos pendientes de revisión:", value, false);
e.getTextChannel().sendMessageEmbeds(pending.build()).reference(e.getMessage()).mentionRepliedUser(false).queue();
} else {
EmbedBuilder noPending = new EmbedBuilder();
noPending.setColor(new Color(255, 0, 0));
noPending.setAuthor("No hay proyectos pendientes de revisión.");
e.getTextChannel().sendMessageEmbeds(noPending.build()).reference(e.getMessage()).mentionRepliedUser(false).queue();
}
}
}
}
}
}
use of pizzaaxx.bteconosur.yaml.Configuration in project bteConoSurCore by BTEConoSur.
the class Events method onEvent.
@Override
public void onEvent(@NotNull GenericEvent event) {
if (event instanceof MessageReceivedEvent) {
MessageReceivedEvent e = (MessageReceivedEvent) event;
if (e.getTextChannel() == gateway) {
if (!(e.getAuthor().isBot()) && !(e.getMessage().getContentDisplay().startsWith("/"))) {
ChatColor color = ChatColor.getByChar(new Configuration(Bukkit.getPluginManager().getPlugin("bteConoSur"), "discord/chatColors").getString(e.getMember().getRoles().get(0).getId()));
new Chat("global").broadcast("[§bDISCORD§f] §7>> §r" + color + e.getMember().getEffectiveName() + ": §r" + e.getMessage().getContentDisplay());
}
}
}
}
use of pizzaaxx.bteconosur.yaml.Configuration in project bteConoSurCore by BTEConoSur.
the class Config method reload.
public void reload() {
maxProjectsPerPlayer = configuration.getInt("max-project-per-player");
maxProjectPoints = configuration.getInt("max-project-points");
maxProjectMembers = configuration.getInt("max-members-per-project");
ConfigurationSection pointsSection = configuration.getConfigurationSection("points");
points.put(Project.Difficulty.FACIL, pointsSection.getInt("facil"));
points.put(Project.Difficulty.INTERMEDIO, pointsSection.getInt("intermedio"));
points.put(Project.Difficulty.DIFICIL, pointsSection.getInt("dificil"));
ConfigurationSection requestSection = configuration.getConfigurationSection("request");
requestsAr = conoSurBot.getTextChannelById(requestSection.getLong("ar"));
requestsBo = conoSurBot.getTextChannelById(requestSection.getLong("bo"));
requestsCl = conoSurBot.getTextChannelById(requestSection.getLong("cl"));
requestsPy = conoSurBot.getTextChannelById(requestSection.getLong("py"));
requestsPe = conoSurBot.getTextChannelById(requestSection.getLong("pe"));
ConfigurationSection logsSection = configuration.getConfigurationSection("logs");
logsAr = conoSurBot.getTextChannelById(logsSection.getLong("ar"));
logsBo = conoSurBot.getTextChannelById(logsSection.getLong("bo"));
logsCl = conoSurBot.getTextChannelById(logsSection.getLong("cl"));
logsPy = conoSurBot.getTextChannelById(logsSection.getLong("py"));
logsPe = conoSurBot.getTextChannelById(logsSection.getLong("pe"));
gateway = conoSurBot.getTextChannelById(configuration.getString("gateway-channel"));
Configuration colors = new Configuration(Bukkit.getPluginManager().getPlugin("bteConoSur"), "chat/colors");
for (String key : colors.getKeys(false)) {
groupsPrefixes.put(key, "[§" + colors.getString(key) + key.toUpperCase() + "]");
}
}
use of pizzaaxx.bteconosur.yaml.Configuration in project bteConoSurCore by BTEConoSur.
the class Project method delete.
// DELETE PROJECT
public void delete() {
File file = new File(pluginFolder, "projects/" + id + ".yml");
if (file.isFile()) {
file.delete();
}
if (pending) {
Configuration pending = new Configuration(Bukkit.getPluginManager().getPlugin("bteConoSur"), "pending_projects/pending");
if (pending.contains(country.getName())) {
List<String> pendingProjects = pending.getStringList(country.getName());
pendingProjects.remove(id);
pending.set(country.getName(), pendingProjects);
pending.save();
}
}
Configuration tags = new Configuration(Bukkit.getPluginManager().getPlugin("bteConoSur"), "projectTags/tags");
if (tag != null) {
String tagName = tag.toString().toLowerCase();
if (tags.contains(tagName)) {
ConfigurationSection tag = tags.getConfigurationSection(tagName);
// COUNTRY
List<String> country = tag.getStringList(this.country.getName());
country.remove(id);
tag.set(this.country.getName(), country);
tags.set(tagName, tag);
}
}
if (oldTag != null) {
String tagName = oldTag.toString().toLowerCase();
if (tags.contains(tagName)) {
ConfigurationSection tag = tags.getConfigurationSection(tagName);
// COUNTRY
List<String> country = tag.getStringList(this.country.getName());
country.remove(id);
tag.set(this.country.getName(), country);
tags.set(tagName, tag);
}
oldTag = null;
}
tags.save();
if (owner != null) {
ServerPlayer s = new ServerPlayer(owner);
s.getProjectsManager().removeProject(this);
}
for (UUID uuid : members) {
ServerPlayer s = new ServerPlayer(uuid);
s.getProjectsManager().removeProject(this);
}
for (UUID uuid : removedMembers) {
ServerPlayer s = new ServerPlayer(uuid);
s.getProjectsManager().removeProject(this);
removedMembers.clear();
}
Set<ScoreboardManager> insideManagers = new HashSet<>();
for (Player p : getPlayersInRegion("project_" + id)) {
ScoreboardManager manager = new ServerPlayer(p).getScoreboardManager();
if (manager.getType() == ScoreboardManager.ScoreboardType.PROJECT) {
insideManagers.add(manager);
}
}
RegionManager manager = getWorldGuard().getRegionManager(mainWorld);
if (manager.hasRegion("project_" + id)) {
manager.removeRegion("project_" + id);
}
for (ScoreboardManager m : insideManagers) {
m.update();
}
}
use of pizzaaxx.bteconosur.yaml.Configuration in project bteConoSurCore by BTEConoSur.
the class Project method getAvailableProjects.
public static Map<Tag, List<String>> getAvailableProjects(OldCountry country, Difficulty difficulty) {
Map<Tag, List<String>> projects = new HashMap<>();
for (Tag tag : Tag.values()) {
String tagName = tag.toString().toLowerCase();
Configuration tags = new Configuration(Bukkit.getPluginManager().getPlugin("bteConoSur"), "projectTags/tags");
if (tags.contains(tagName)) {
for (String id : tags.getConfigurationSection(tagName).getStringList(country.getName())) {
Project project = new Project(id);
if (project.getOwner() == null && project.getDifficulty() == difficulty) {
projects.get(tag).add(id);
}
}
}
}
return projects;
}
Aggregations