2018-09-07 04:35:38 +02:00
|
|
|
package me.libraryaddict.disguise.utilities.parser.params.types.custom;
|
|
|
|
|
2019-12-31 07:35:21 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
2018-09-07 04:35:38 +02:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by libraryaddict on 7/09/2018.
|
|
|
|
*/
|
|
|
|
public class ParamInfoItemStackArray extends ParamInfoItemStack {
|
|
|
|
public ParamInfoItemStackArray(Class paramClass, String name, String valueType, String description,
|
|
|
|
Enum[] possibleValues) {
|
|
|
|
super(paramClass, name, valueType, description, possibleValues);
|
|
|
|
}
|
|
|
|
|
2018-10-24 00:20:21 +02:00
|
|
|
@Override
|
|
|
|
public boolean canReturnNull() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-07 04:35:38 +02:00
|
|
|
@Override
|
|
|
|
public Set<String> getEnums(String tabComplete) {
|
|
|
|
String beginning = tabComplete.substring(0, tabComplete.contains(",") ? tabComplete.lastIndexOf(",") + 1 : 0);
|
|
|
|
String end = tabComplete.substring(tabComplete.contains(",") ? tabComplete.lastIndexOf(",") + 1 : 0);
|
|
|
|
|
|
|
|
Set<String> toReturn = new LinkedHashSet<>();
|
|
|
|
|
|
|
|
for (String material : super.getEnums(null)) {
|
|
|
|
if (!material.toLowerCase().startsWith(end.toLowerCase()))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
toReturn.add(beginning + material);
|
|
|
|
}
|
|
|
|
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
|
2019-12-31 07:35:21 +01:00
|
|
|
@Override
|
|
|
|
public String toString(Object object) {
|
2020-01-02 05:10:36 +01:00
|
|
|
ItemStack[] stacks = (ItemStack[]) object;
|
|
|
|
|
|
|
|
String returns = "";
|
|
|
|
|
|
|
|
for (int i = 0; i < stacks.length; i++) {
|
|
|
|
if (i > 0) {
|
|
|
|
returns += ",";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stacks[i] == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
String toString = super.toString(stacks[i]);
|
|
|
|
|
|
|
|
// If we can't parse to simple
|
|
|
|
if (toString.startsWith("{")) {
|
|
|
|
return DisguiseUtilities.getGson().toJson(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
returns += toString;
|
|
|
|
}
|
|
|
|
|
|
|
|
return returns;
|
2019-12-31 07:35:21 +01:00
|
|
|
}
|
|
|
|
|
2018-09-07 04:35:38 +02:00
|
|
|
@Override
|
|
|
|
public Object fromString(String string) {
|
2020-02-15 07:56:06 +01:00
|
|
|
if (string.startsWith("[") && string.endsWith("]")) {
|
2019-12-31 07:35:21 +01:00
|
|
|
try {
|
|
|
|
return DisguiseUtilities.getGson().fromJson(string, ItemStack[].class);
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-07 04:35:38 +02:00
|
|
|
String[] split = string.split(",", -1);
|
|
|
|
|
|
|
|
if (split.length != 4) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse to itemstack array
|
|
|
|
ItemStack[] items = new ItemStack[4];
|
|
|
|
|
|
|
|
for (int a = 0; a < 4; a++) {
|
2018-09-23 01:02:53 +02:00
|
|
|
items[a] = parseToItemstack(split[a].split(":"));
|
2018-09-07 04:35:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
}
|