mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-02 21:41:45 +01:00
Merge branch 'develop' of https://github.com/BentoBoxWorld/BentoBox.git into develop
This commit is contained in:
commit
a0d2320a04
@ -6,6 +6,7 @@ import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.web.catalog.CatalogEntry;
|
||||
import world.bentobox.githubapi4java.GitHub;
|
||||
import world.bentobox.githubapi4java.objects.GitHubGist;
|
||||
|
||||
@ -23,8 +24,8 @@ public class WebManager {
|
||||
|
||||
private @NonNull BentoBox plugin;
|
||||
private @Nullable GitHub gitHub;
|
||||
private @NonNull List<JsonObject> addonsCatalog;
|
||||
private @NonNull List<JsonObject> gamemodesCatalog;
|
||||
private @NonNull List<CatalogEntry> addonsCatalog;
|
||||
private @NonNull List<CatalogEntry> gamemodesCatalog;
|
||||
|
||||
public WebManager(@NonNull BentoBox plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -62,8 +63,8 @@ public class WebManager {
|
||||
.replace("\n", "").replace("\\", "");
|
||||
|
||||
JsonObject catalog = new JsonParser().parse(catalogContent).getAsJsonObject();
|
||||
catalog.getAsJsonArray("gamemodes").forEach(gamemode -> gamemodesCatalog.add(gamemode.getAsJsonObject()));
|
||||
catalog.getAsJsonArray("addons").forEach(addon -> addonsCatalog.add(addon.getAsJsonObject()));
|
||||
catalog.getAsJsonArray("gamemodes").forEach(gamemode -> gamemodesCatalog.add(new CatalogEntry(gamemode.getAsJsonObject())));
|
||||
catalog.getAsJsonArray("addons").forEach(addon -> addonsCatalog.add(new CatalogEntry(addon.getAsJsonObject())));
|
||||
} catch (Exception e) {
|
||||
plugin.logError("An error occurred when downloading or parsing data from GitHub...");
|
||||
plugin.logStacktrace(e);
|
||||
@ -77,7 +78,7 @@ public class WebManager {
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@NonNull
|
||||
public List<JsonObject> getAddonsCatalog() {
|
||||
public List<CatalogEntry> getAddonsCatalog() {
|
||||
return addonsCatalog;
|
||||
}
|
||||
|
||||
@ -87,7 +88,7 @@ public class WebManager {
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@NonNull
|
||||
public List<JsonObject> getGamemodesCatalog() {
|
||||
public List<CatalogEntry> getGamemodesCatalog() {
|
||||
return gamemodesCatalog;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package world.bentobox.bentobox.panels;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -10,6 +9,7 @@ import world.bentobox.bentobox.api.panels.PanelItem;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.web.catalog.CatalogEntry;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -46,7 +46,7 @@ public class CatalogPanel {
|
||||
.name(user.getTranslation(LOCALE_REF + "views.addons.name"))
|
||||
.description(user.getTranslation(LOCALE_REF + "views.addons.description"));
|
||||
|
||||
List<JsonObject> catalog;
|
||||
List<CatalogEntry> catalog;
|
||||
if (view == View.GAMEMODES) {
|
||||
catalog = plugin.getWebManager().getGamemodesCatalog();
|
||||
// Make the gamemodes button glow
|
||||
@ -74,21 +74,14 @@ public class CatalogPanel {
|
||||
if (catalog.isEmpty()) {
|
||||
looksEmpty(builder, user);
|
||||
} else {
|
||||
for (JsonObject addon : catalog) {
|
||||
for (CatalogEntry addon : catalog) {
|
||||
PanelItemBuilder itemBuilder = new PanelItemBuilder();
|
||||
|
||||
Material icon = Material.getMaterial(addon.get("icon").getAsString());
|
||||
if (icon == null) {
|
||||
icon = Material.PAPER;
|
||||
}
|
||||
|
||||
String name = addon.get("name").getAsString();
|
||||
itemBuilder.icon(icon)
|
||||
.name(ChatColor.WHITE + name);
|
||||
itemBuilder.icon(addon.getIcon()).name(ChatColor.WHITE + addon.getName());
|
||||
|
||||
// If the addon is already installed, then tell the user it's already installed
|
||||
String install;
|
||||
if (plugin.getAddonsManager().getAddonByName(name).isPresent()) {
|
||||
if (plugin.getAddonsManager().getAddonByName(addon.getName()).isPresent()) {
|
||||
itemBuilder.glow(true);
|
||||
install = user.getTranslation(LOCALE_REF + "icon.already-installed");
|
||||
} else {
|
||||
@ -96,18 +89,17 @@ public class CatalogPanel {
|
||||
}
|
||||
|
||||
itemBuilder.description(user.getTranslation(LOCALE_REF + "icon.description-template",
|
||||
"[topic]", StringUtils.capitalize(addon.get("topic").getAsString()),
|
||||
"[topic]", StringUtils.capitalize(addon.getTopic()),
|
||||
"[install]", install,
|
||||
"[description]", addon.get("description").getAsString()));
|
||||
"[description]", "WIP"));
|
||||
|
||||
// Set the link to the latest release
|
||||
String repository = addon.get("repository").getAsString();
|
||||
itemBuilder.clickHandler((panel, user1, clickType, slot) -> {
|
||||
user1.sendRawMessage(ChatColor.GRAY + "" + ChatColor.ITALIC + "https://github.com/" + repository + "/releases/latest");
|
||||
user1.sendRawMessage(ChatColor.GRAY + "" + ChatColor.ITALIC + "https://github.com/" + addon.getRepository() + "/releases/latest");
|
||||
return true;
|
||||
});
|
||||
|
||||
builder.item(addon.get("slot").getAsInt(), itemBuilder.build());
|
||||
builder.item(addon.getSlot(), itemBuilder.build());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,64 @@
|
||||
package world.bentobox.bentobox.web.catalog;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import org.bukkit.Material;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Poslovitch
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public class CatalogEntry {
|
||||
|
||||
private int slot;
|
||||
/**
|
||||
* Defaults to {@link Material#PAPER}.
|
||||
*/
|
||||
private @NonNull Material icon;
|
||||
private @NonNull String name;
|
||||
private @Nullable String topic;
|
||||
private @NonNull List<String> tags = new ArrayList<>();
|
||||
private @NonNull String repository;
|
||||
|
||||
public CatalogEntry(@NonNull JsonObject object) {
|
||||
this.slot = object.get("slot").getAsInt();
|
||||
Material material = Material.getMaterial(object.get("icon").getAsString());
|
||||
this.icon = (material != null) ? material : Material.PAPER;
|
||||
this.name = object.get("name").getAsString();
|
||||
this.repository = object.get("repository").getAsString();
|
||||
this.topic = object.get("topic").getAsString();
|
||||
}
|
||||
|
||||
public int getSlot() {
|
||||
return slot;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Material getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getTopic() {
|
||||
return topic;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getRepository() {
|
||||
return repository;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user