#525: Add contributors plugin.yml field.

Unlike "authors", names listed under the "contributors" field will not be named when AuthorNagExceptions are thrown. This makes a clear distinction between authorship and contributors as most contributions do not warrant the status of "author".

By: Parker Hawke <hawkeboyz2@hotmail.com>
This commit is contained in:
Bukkit/Spigot 2020-07-22 18:17:07 +10:00
parent 2b0e21f46d
commit 4e44fa11b3
2 changed files with 59 additions and 8 deletions

View File

@ -91,23 +91,26 @@ public class VersionCommand extends BukkitCommand {
if (!desc.getAuthors().isEmpty()) { if (!desc.getAuthors().isEmpty()) {
if (desc.getAuthors().size() == 1) { if (desc.getAuthors().size() == 1) {
sender.sendMessage("Author: " + getAuthors(desc)); sender.sendMessage("Author: " + getNameList(desc.getAuthors()));
} else { } else {
sender.sendMessage("Authors: " + getAuthors(desc)); sender.sendMessage("Authors: " + getNameList(desc.getAuthors()));
} }
} }
if (!desc.getContributors().isEmpty()) {
sender.sendMessage("Contributors: " + getNameList(desc.getContributors()));
}
} }
@NotNull @NotNull
private String getAuthors(@NotNull final PluginDescriptionFile desc) { private String getNameList(@NotNull final List<String> names) {
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
List<String> authors = desc.getAuthors();
for (int i = 0; i < authors.size(); i++) { for (int i = 0; i < names.size(); i++) {
if (result.length() > 0) { if (result.length() > 0) {
result.append(ChatColor.WHITE); result.append(ChatColor.WHITE);
if (i < authors.size() - 1) { if (i < names.size() - 1) {
result.append(", "); result.append(", ");
} else { } else {
result.append(" and "); result.append(" and ");
@ -115,7 +118,7 @@ public class VersionCommand extends BukkitCommand {
} }
result.append(ChatColor.GREEN); result.append(ChatColor.GREEN);
result.append(authors.get(i)); result.append(names.get(i));
} }
return result.toString(); return result.toString();

View File

@ -78,6 +78,10 @@ import org.yaml.snakeyaml.nodes.Tag;
* </tr><tr> * </tr><tr>
* <td><code>author</code><br><code>authors</code></td> * <td><code>author</code><br><code>authors</code></td>
* <td>{@link #getAuthors()}</td> * <td>{@link #getAuthors()}</td>
* <td>The plugin authors</td>
* </tr><tr>
* <td><code>contributors</code></td>
* <td>{@link #getContributors()}</td>
* <td>The plugin contributors</td> * <td>The plugin contributors</td>
* </tr><tr> * </tr><tr>
* <td><code>description</code></td> * <td><code>description</code></td>
@ -142,6 +146,7 @@ import org.yaml.snakeyaml.nodes.Tag;
*# name is displayed first *# name is displayed first
*author: CaptainInflamo *author: CaptainInflamo
*authors: [Cogito, verrier, EvilSeph] *authors: [Cogito, verrier, EvilSeph]
*contributors: [Choco, md_5]
*website: http://www.curse.com/server-mods/minecraft/myplugin *website: http://www.curse.com/server-mods/minecraft/myplugin
* *
*main: com.captaininflamo.bukkit.inferno.Inferno *main: com.captaininflamo.bukkit.inferno.Inferno
@ -233,6 +238,7 @@ public final class PluginDescriptionFile {
private Map<String, Map<String, Object>> commands = ImmutableMap.of(); private Map<String, Map<String, Object>> commands = ImmutableMap.of();
private String description = null; private String description = null;
private List<String> authors = null; private List<String> authors = null;
private List<String> contributors = null;
private String website = null; private String website = null;
private String prefix = null; private String prefix = null;
private PluginLoadOrder order = PluginLoadOrder.POSTWORLD; private PluginLoadOrder order = PluginLoadOrder.POSTWORLD;
@ -434,7 +440,7 @@ public final class PluginDescriptionFile {
* <li>Gives credit to the developer. * <li>Gives credit to the developer.
* <li>Used in some server error messages to provide helpful feedback on * <li>Used in some server error messages to provide helpful feedback on
* who to contact when an error occurs. * who to contact when an error occurs.
* <li>A bukkit.org forum handle or email address is recommended. * <li>A SpigotMC forum handle or email address is recommended.
* <li>Is displayed when a user types <code>/version PluginName</code> * <li>Is displayed when a user types <code>/version PluginName</code>
* <li><code>authors</code> must be in <a * <li><code>authors</code> must be in <a
* href="http://en.wikipedia.org/wiki/YAML#Lists">YAML list * href="http://en.wikipedia.org/wiki/YAML#Lists">YAML list
@ -464,6 +470,30 @@ public final class PluginDescriptionFile {
return authors; return authors;
} }
/**
* Gives the list of contributors for the plugin.
* <ul>
* <li>Gives credit to those that have contributed to the plugin, though
* not enough so to warrant authorship.
* <li>Unlike {@link #getAuthors()}, contributors will not be mentioned in
* server error messages as a means of contact.
* <li>A SpigotMC forum handle or email address is recommended.
* <li>Is displayed when a user types <code>/version PluginName</code>
* <li><code>contributors</code> must be in <a
* href="http://en.wikipedia.org/wiki/YAML#Lists">YAML list
* format</a>.
* </ul>
* <p>
* Example:
* <blockquote><pre>authors: [Choco, md_5]</pre></blockquote>
*
* @return an immutable list of the plugin's contributors
*/
@NotNull
public List<String> getContributors() {
return contributors;
}
/** /**
* Gives the plugin's or plugin's author's website. * Gives the plugin's or plugin's author's website.
* <ul> * <ul>
@ -1057,6 +1087,20 @@ public final class PluginDescriptionFile {
authors = ImmutableList.<String>of(); authors = ImmutableList.<String>of();
} }
if (map.get("contributors") != null) {
ImmutableList.Builder<String> contributorsBuilder = ImmutableList.<String>builder();
try {
for (Object o : (Iterable<?>) map.get("contributors")) {
contributorsBuilder.add(o.toString());
}
} catch (ClassCastException ex) {
throw new InvalidDescriptionException(ex, "contributors are of wrong type");
}
contributors = contributorsBuilder.build();
} else {
contributors = ImmutableList.<String>of();
}
if (map.get("default-permission") != null) { if (map.get("default-permission") != null) {
try { try {
defaultPerm = PermissionDefault.getByName(map.get("default-permission").toString()); defaultPerm = PermissionDefault.getByName(map.get("default-permission").toString());
@ -1149,6 +1193,10 @@ public final class PluginDescriptionFile {
map.put("authors", authors); map.put("authors", authors);
} }
if (contributors != null) {
map.put("contributors", contributors);
}
if (apiVersion != null) { if (apiVersion != null) {
map.put("api-version", apiVersion); map.put("api-version", apiVersion);
} }