Permalink
Browse files

Add fallback for getting shield basecolor

  • Loading branch information...
PseudoKnight committed Aug 26, 2018
1 parent 7c14e6a commit bd2a6a2000ea538b1f01467e09b94d6ccfeba7f1
@@ -5,6 +5,7 @@
import com.laytonsmith.abstraction.bukkit.BukkitMCPattern;
import com.laytonsmith.abstraction.enums.MCDyeColor;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCDyeColor;
import org.bukkit.DyeColor;
import org.bukkit.block.Banner;
import org.bukkit.block.banner.Pattern;
@@ -22,7 +23,12 @@ public BukkitMCBanner(Banner block) {
@Override
public MCDyeColor getBaseColor() {
return BukkitMCDyeColor.getConvertor().getAbstractedEnum(b.getBaseColor());
DyeColor c = b.getBaseColor();
if(c != null) {
return BukkitMCDyeColor.getConvertor().getAbstractedEnum(c);
}
// fallback method in case basecolor is incorrectly null
return MCDyeColor.valueOf(b.getType().name().replace("_BANNER", ""));
}
@Override
@@ -443,6 +443,7 @@ public Construct itemMeta(MCItemStack is, Target t) {
ma.set("inventory", box, t);
} else if(bs instanceof MCBanner) {
MCBanner banner = (MCBanner) bs;
ma.set("basecolor", banner.getBaseColor().name(), t);
CArray patterns = new CArray(t, banner.numberOfPatterns());
for(MCPattern p : banner.getPatterns()) {
CArray pattern = CArray.GetAssociativeArray(t);
@@ -709,10 +710,21 @@ public MCItemMeta itemMeta(Construct c, MCMaterial mat, Target t) throws ConfigR
}
} else if(bs instanceof MCBanner) {
MCBanner banner = (MCBanner) bs;
banner.setBaseColor(MCDyeColor.WHITE);
if(ma.containsKey("basecolor")) {
MCDyeColor base = MCDyeColor.valueOf(ma.get("basecolor", t).val().toUpperCase());
banner.addPattern(StaticLayer.GetConvertor().GetPattern(base, MCPatternShape.BASE));
String baseString = ma.get("basecolor", t).val().toUpperCase();
try {
MCDyeColor base = MCDyeColor.valueOf(baseString);
banner.setBaseColor(base);
} catch (IllegalArgumentException ex) {
if(baseString.equals("SILVER")) {
// convert old DyeColor
banner.setBaseColor(MCDyeColor.LIGHT_GRAY);
} else {
throw ex;
}
}
} else {
banner.setBaseColor(MCDyeColor.WHITE);
}
if(ma.containsKey("patterns")) {
CArray array = ArgumentValidation.getArray(ma.get("patterns", t), t);

0 comments on commit bd2a6a2

Please sign in to comment.