1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 11:45:51 +00:00

Merge pull request #544 from Poslovitch/settings-panel

Improved Settings & Contributors panels
This commit is contained in:
TheBusyBiscuit 2017-12-21 15:06:27 +01:00 committed by GitHub
commit 4f0aeed504
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 16 deletions

View File

@ -1,11 +1,16 @@
package me.mrCookieSlime.Slimefun.GitHub; package me.mrCookieSlime.Slimefun.GitHub;
/**
* Represents a contributor on Slimefun4's GitHub repository.
*
* @since 4.1.6
*/
public class Contributor { public class Contributor {
public String name; private String name;
public String job; private String job;
public String profile; private String profile;
public int commits; private int commits;
public Contributor(String name, String job, int commits) { public Contributor(String name, String job, int commits) {
this.name = name; this.name = name;
@ -13,4 +18,47 @@ public class Contributor {
this.commits = commits; this.commits = commits;
} }
/**
* Returns the name of this contributor.
*
* @return the name of this contributor
* @since 4.2.0
*/
public String getName() { return this.name; }
/**
* Returns the job of this contributor.
* It can be {@code Author} or {@code Head Artist}.
*
* @return the job of this contributor
* @since 4.2.0
*/
public String getJob() { return this.job; }
/**
* Returns the link to the GitHub profile of this contributor.
*
* @return the GitHub profile of this contributor.
* @since 4.2.0
*/
public String getProfile() { return this.profile; }
/**
* Returns the number of commits to the Slimefun4's repository of this contributor.
*
* @return the number of commits of this contributor.
* @since 4.2.0
*/
public int getCommits() { return this.commits; }
/**
* Sets the link to the GitHub profile of this contributor.
*
* @param profile the link to the GitHub profile of this contributor
*
* @since 4.2.0
*/
protected void setProfile(String profile) {
this.profile = profile;
}
} }

View File

@ -26,7 +26,7 @@ public class GitHubSetup {
if (!name.equals("invalid-email-address")) { if (!name.equals("invalid-email-address")) {
Contributor contributor = new Contributor(name, job, commits); Contributor contributor = new Contributor(name, job, commits);
contributor.profile = profile; contributor.setProfile(profile);
SlimefunGuide.contributors.add(contributor); SlimefunGuide.contributors.add(contributor);
} }
} }
@ -64,6 +64,7 @@ public class GitHubSetup {
JsonObject object = element.getAsJsonObject(); JsonObject object = element.getAsJsonObject();
SlimefunGuide.issues = object.get("open_issues_count").getAsInt(); SlimefunGuide.issues = object.get("open_issues_count").getAsInt();
SlimefunGuide.forks = object.get("forks").getAsInt(); SlimefunGuide.forks = object.get("forks").getAsInt();
SlimefunGuide.stars = object.get("stargazers_count").getAsInt();
SlimefunGuide.last_update = IntegerFormat.parseGitHubDate(object.get("pushed_at").getAsString()); SlimefunGuide.last_update = IntegerFormat.parseGitHubDate(object.get("pushed_at").getAsString());
} }

View File

@ -9,6 +9,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.SkullItem;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -63,6 +64,11 @@ public class SlimefunGuide {
public static List<Contributor> contributors = new ArrayList<Contributor>(); public static List<Contributor> contributors = new ArrayList<Contributor>();
public static int issues = 0; public static int issues = 0;
public static int forks = 0; public static int forks = 0;
/**
* Represents the number of stars on the Slimefun4 GitHub repository.
* @since 4.2.0
*/
public static int stars = 0;
public static int code_bytes = 0; public static int code_bytes = 0;
public static Date last_update = new Date(); public static Date last_update = new Date();
@ -201,7 +207,7 @@ public class SlimefunGuide {
}); });
try { try {
menu.addItem(4, new CustomItem(new MaterialData(Material.REDSTONE_COMPARATOR), "&eSource Code", "", "&7Bytes of Code: &6" + IntegerFormat.formatBigNumber(code_bytes), "&7Last Update: &a" + IntegerFormat.timeDelta(last_update) + " ago", "&7Forks: &e" + forks, "", "&7&oSlimefun 4 is a community project,", "&7&othe source code is available on GitHub", "&7&oand if you want to keep this Plugin alive,", "&7&othen please consider contributing to it", "", "&7\u21E8 Click to go to GitHub")); menu.addItem(4, new CustomItem(new MaterialData(Material.REDSTONE_COMPARATOR), "&eSource Code", "", "&7Bytes of Code: &6" + IntegerFormat.formatBigNumber(code_bytes), "&7Last Update: &a" + IntegerFormat.timeDelta(last_update) + " ago", "&7Forks: &e" + forks, "&7Stars: &e" + stars, "", "&7&oSlimefun 4 is a community project,", "&7&othe source code is available on GitHub", "&7&oand if you want to keep this Plugin alive,", "&7&othen please consider contributing to it", "", "&7\u21E8 Click to go to GitHub"));
menu.addMenuClickHandler(4, new MenuClickHandler() { menu.addMenuClickHandler(4, new MenuClickHandler() {
@Override @Override
@ -274,22 +280,21 @@ public class SlimefunGuide {
double total = 0; double total = 0;
for (Contributor contributor: contributors) { for (Contributor contributor: contributors) {
total += contributor.commits; total += contributor.getCommits();
} }
for (final Contributor contributor: contributors) { for (final Contributor contributor: contributors) {
ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); ItemStack skull = new SkullItem("&a" + contributor.getName(), contributor.getName());
ItemMeta meta = skull.getItemMeta(); ItemMeta meta = skull.getItemMeta();
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&a" + contributor.name));
if (contributor.commits > 0) { if (contributor.getCommits() > 0) {
double percentage = DoubleHandler.fixDouble((contributor.commits * 100.0) / total, 2); double percentage = DoubleHandler.fixDouble((contributor.getCommits() * 100.0) / total, 2);
meta.setLore(Arrays.asList("", ChatColor.translateAlternateColorCodes('&', "&7Role: &r" + contributor.job), ChatColor.translateAlternateColorCodes('&', "&7Contribution: &r" + percentage + "%"), "", ChatColor.translateAlternateColorCodes('&', "&7\u21E8 Click to view my GitHub profile"))); meta.setLore(Arrays.asList("", ChatColor.translateAlternateColorCodes('&', "&7Role: &r" + contributor.getJob()), ChatColor.translateAlternateColorCodes('&', "&7Contributions: &r" + contributor.getCommits() + " commits &7(&r" + percentage + "%&7)"), "", ChatColor.translateAlternateColorCodes('&', "&7\u21E8 Click to view my GitHub profile")));
} }
else { else {
meta.setLore(Arrays.asList("", ChatColor.translateAlternateColorCodes('&', "&7Role: &r" + contributor.job))); meta.setLore(Arrays.asList("", ChatColor.translateAlternateColorCodes('&', "&7Role: &r" + contributor.getJob())));
} }
skull.setItemMeta(meta); skull.setItemMeta(meta);
@ -299,10 +304,10 @@ public class SlimefunGuide {
@Override @Override
public boolean onClick(Player p, int arg1, ItemStack arg2, ClickAction arg3) { public boolean onClick(Player p, int arg1, ItemStack arg2, ClickAction arg3) {
if (contributor.commits > 0) { if (contributor.getCommits() > 0) {
p.closeInventory(); p.closeInventory();
p.sendMessage(""); p.sendMessage("");
p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7&o" + contributor.profile)); p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7&o" + contributor.getProfile()));
p.sendMessage(""); p.sendMessage("");
} }
return false; return false;