mirror of
https://github.com/LordBoos/boosCooldowns.git
synced 2024-11-22 02:25:49 +01:00
Rewrite JSON text handling and Material handling
Add api-version 1.13
This commit is contained in:
parent
7a2b32a3d2
commit
857291778e
@ -81,7 +81,7 @@ public interface JSONClickAction<T> {
|
||||
|
||||
@Override
|
||||
public String getValueString() {
|
||||
return "\"" + value + "\"";
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -130,7 +130,7 @@ public interface JSONClickAction<T> {
|
||||
|
||||
@Override
|
||||
public String getValueString() {
|
||||
return "\"" + value + "\"";
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -179,7 +179,7 @@ public interface JSONClickAction<T> {
|
||||
|
||||
@Override
|
||||
public String getValueString() {
|
||||
return ("\"" + value + "\"").replace(" ", "%20");
|
||||
return (value).replace(" ", "%20");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,11 @@
|
||||
package com.coloredcarrot.mcapi.json;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import cz.boosik.boosCooldown.BoosCoolDown;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
|
||||
/**
|
||||
* All rights reserved.
|
||||
*
|
||||
@ -45,17 +51,24 @@ public class JSONComponent
|
||||
|
||||
super.generate();
|
||||
|
||||
generatedJSON = generatedJSON.substring(0, generatedJSON.length() - 1);
|
||||
JsonObject json = new JsonParser().parse(generatedJSON).getAsJsonObject();
|
||||
|
||||
if (hoverAction != null) {
|
||||
generatedJSON += ",\"hoverEvent\":{\"action\":\"" + hoverAction.getActionName() + "\",\"value\":\"" + hoverAction.getValueString() + "}";
|
||||
|
||||
JsonObject jsonHover = new JsonObject();
|
||||
jsonHover.addProperty("action", hoverAction.getActionName());
|
||||
jsonHover.addProperty("value", hoverAction.getValueString());
|
||||
json.add("hoverEvent", jsonHover);
|
||||
}
|
||||
|
||||
if (clickAction != null) {
|
||||
generatedJSON += ",\"clickEvent\":{\"action\":\"" + clickAction.getActionName() + "\",\"value\":" + clickAction.getValueString() + "}";
|
||||
JsonObject jsonClick = new JsonObject();
|
||||
jsonClick.addProperty("action", clickAction.getActionName());
|
||||
jsonClick.addProperty("value", clickAction.getValueString());
|
||||
json.add("clickEvent", jsonClick);
|
||||
}
|
||||
|
||||
generatedJSON += "}";
|
||||
generatedJSON = json.toString();
|
||||
|
||||
return this;
|
||||
|
||||
|
@ -2,8 +2,12 @@ package com.coloredcarrot.mcapi.json;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import cz.boosik.boosCooldown.BoosCoolDown;
|
||||
|
||||
/**
|
||||
@ -136,7 +140,7 @@ public interface JSONHoverAction<T> {
|
||||
|
||||
@Override
|
||||
public String getValueString() {
|
||||
return value + "\"";
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -248,50 +252,53 @@ public interface JSONHoverAction<T> {
|
||||
|
||||
@Override
|
||||
public String getValueString() {
|
||||
final String material = value.getData().getItemType().toString().toLowerCase();
|
||||
String value2 = "{id:\\\"minecraft:" + material + "\\\",Damage:" + value.getDurability() + ",Count:" + value.getAmount() + ",tag:{";
|
||||
final String material = value.getType().toString().toLowerCase();
|
||||
final ItemMeta itemMeta = value.getItemMeta();
|
||||
final Integer damage = itemMeta instanceof Damageable ? ((Damageable) itemMeta).getDamage() : null;
|
||||
|
||||
if (value.getItemMeta().hasEnchants()) {
|
||||
value2 += "Enchantments:[";
|
||||
int i = 0;
|
||||
final int size = value.getItemMeta().getEnchants().keySet().size();
|
||||
for (final Enchantment ench : value.getItemMeta().getEnchants().keySet()) {
|
||||
if (i + 1 == size) {
|
||||
value2 += "{lvl:" + value.getItemMeta().getEnchants().get(ench) + ",id:\\\"" + ench.getKey() + "\\\"}";
|
||||
} else {
|
||||
value2 += "{lvl:" + value.getItemMeta().getEnchants().get(ench) + ",id:\\\"" + ench.getKey() + "\\\"},";
|
||||
}
|
||||
i++;
|
||||
}
|
||||
value2 += "],";
|
||||
}
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("id", "minecraft:"+material);
|
||||
json.addProperty("Damage", damage);
|
||||
json.addProperty("Count", value.getAmount());
|
||||
|
||||
value2 += "display:{Name:\\\"" + (value
|
||||
.getItemMeta()
|
||||
.getDisplayName() != null && value
|
||||
.getItemMeta()
|
||||
.getDisplayName() != "" ? value
|
||||
.getItemMeta()
|
||||
.getDisplayName() : toTitleCase(value.getType().toString().toLowerCase())) + "\\\"";
|
||||
JsonObject jsonTag = new JsonObject();
|
||||
|
||||
if (value.getItemMeta().hasLore()) {
|
||||
value2 += ",Lore:[";
|
||||
for (final String lore : value.getItemMeta().getLore()) {
|
||||
value2 = value2 + (value.getItemMeta().getLore().size() == 1 || value
|
||||
.getItemMeta()
|
||||
.getLore()
|
||||
.get(value
|
||||
.getItemMeta()
|
||||
.getLore()
|
||||
.size() - 1) == lore ? ("\\\"" + lore + "\\\"") : ("\\\"" + lore + "\\\","));
|
||||
JsonObject jsonDisplay = new JsonObject();
|
||||
JsonObject jsonName = new JsonObject();
|
||||
jsonName.addProperty("text", itemMeta.getDisplayName() != null && !itemMeta.getDisplayName().equals("") ? itemMeta
|
||||
.getDisplayName() : toTitleCase(value.getType().toString().toLowerCase()));
|
||||
jsonDisplay.addProperty("Name", jsonName.toString());
|
||||
|
||||
if (itemMeta.hasLore()) {
|
||||
JsonArray jsonLore = new JsonArray();
|
||||
|
||||
for (final String lore : itemMeta.getLore()) {
|
||||
JsonObject jsonLoreItem = new JsonObject();
|
||||
jsonLoreItem.addProperty("text", lore);
|
||||
jsonLore.add(jsonLoreItem.toString());
|
||||
}
|
||||
|
||||
value2 += "]";
|
||||
jsonDisplay.add("Lore", jsonLore);
|
||||
}
|
||||
|
||||
value2 += "}}}\"";
|
||||
jsonTag.add("display", jsonDisplay);
|
||||
|
||||
return value2;
|
||||
if (itemMeta.hasEnchants()) {
|
||||
JsonArray jsonEnchantments = new JsonArray();
|
||||
|
||||
for (final Enchantment ench : itemMeta.getEnchants().keySet()) {
|
||||
JsonObject enchantment = new JsonObject();
|
||||
enchantment.addProperty("lvl", itemMeta.getEnchants().get(ench));
|
||||
enchantment.addProperty("id", ench.getKey().toString());
|
||||
jsonEnchantments.add(enchantment);
|
||||
}
|
||||
|
||||
jsonTag.add("Enchantments", jsonEnchantments);
|
||||
}
|
||||
|
||||
json.add("tag", jsonTag);
|
||||
|
||||
return json.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -14,6 +14,7 @@ import com.coloredcarrot.mcapi.json.JSON;
|
||||
import com.coloredcarrot.mcapi.json.JSONColor;
|
||||
import com.coloredcarrot.mcapi.json.JSONComponent;
|
||||
import com.coloredcarrot.mcapi.json.JSONHoverAction;
|
||||
import cz.boosik.boosCooldown.BoosCoolDown;
|
||||
import util.BoosChat;
|
||||
|
||||
public class BoosItemCostManager {
|
||||
@ -74,7 +75,7 @@ public class BoosItemCostManager {
|
||||
}
|
||||
|
||||
public static ItemStack createItemStack(final String item, final int count, final String name, final List<String> lore, final List<String> enchants) {
|
||||
final ItemStack itemStack = new ItemStack(Material.getMaterial(item), count);
|
||||
final ItemStack itemStack = new ItemStack(Material.valueOf(item), count);
|
||||
final ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
if (name != null) {
|
||||
itemMeta.setDisplayName(name);
|
||||
|
@ -1,6 +1,7 @@
|
||||
name: boosCooldowns
|
||||
main: cz.boosik.boosCooldown.BoosCoolDown
|
||||
version: 3.16.1
|
||||
version: 3.16.2
|
||||
api-version: 1.13
|
||||
authors: [LordBoos (boosik)]
|
||||
softdepend: [Vault, PlayerPoints]
|
||||
description: >
|
||||
|
2
pom.xml
2
pom.xml
@ -11,7 +11,7 @@
|
||||
<packaging>pom</packaging>
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
<boosCooldowns.version>3.16.1</boosCooldowns.version>
|
||||
<boosCooldowns.version>3.16.2</boosCooldowns.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<minecraft.version>1.16.1</minecraft.version>
|
||||
|
Loading…
Reference in New Issue
Block a user