Permalink
Browse files

Address a couple shield and banner meta issues.

Notably there's a spigot bug with shield specific meta that prevents us from getting and setting colors and patterns. This makes it fail gracefully without destroying all meta on the item. This also fixes a missing color conversion for silver banners.
  • Loading branch information...
PseudoKnight committed Aug 23, 2018
1 parent 63a411b commit 6ed53589a1ea3f989a66cceb5d283e2de81b39b6
@@ -1,13 +1,14 @@
package com.laytonsmith.abstraction.blocks;
import com.laytonsmith.abstraction.MCPattern;
import com.laytonsmith.abstraction.enums.MCDyeColor;
import java.util.List;
public interface MCBanner extends MCBlockState {
MCDyeColor getBaseColor();
void setBaseColor(MCDyeColor color);
int numberOfPatterns();
List<MCPattern> getPatterns();
void addPattern(MCPattern pattern);
}
@@ -18,8 +18,9 @@ public BukkitMCBlockStateMeta(BlockStateMeta meta) {
public MCBlockState getBlockState() {
try {
return BukkitConvertor.BukkitGetCorrectBlockState(bsm.getBlockState());
} catch (IllegalStateException ex) {
} catch (IllegalStateException | NullPointerException ex) {
// BlockStateMeta that cannot get a BlockState
// or a broken implementation
return null;
}
}
@@ -3,6 +3,8 @@
import com.laytonsmith.abstraction.MCPattern;
import com.laytonsmith.abstraction.blocks.MCBanner;
import com.laytonsmith.abstraction.bukkit.BukkitMCPattern;
import com.laytonsmith.abstraction.enums.MCDyeColor;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCDyeColor;
import org.bukkit.block.Banner;
import org.bukkit.block.banner.Pattern;
@@ -18,6 +20,16 @@ public BukkitMCBanner(Banner block) {
b = block;
}
@Override
public MCDyeColor getBaseColor() {
return BukkitMCDyeColor.getConvertor().getAbstractedEnum(b.getBaseColor());
}
@Override
public void setBaseColor(MCDyeColor color) {
b.setBaseColor(BukkitMCDyeColor.getConvertor().getConcreteEnum(color));
}
@Override
public int numberOfPatterns() {
return b.numberOfPatterns();
@@ -439,6 +439,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());
CArray patterns = new CArray(t, banner.numberOfPatterns());
for(MCPattern p : banner.getPatterns()) {
CArray pattern = CArray.GetAssociativeArray(t);
@@ -701,6 +702,10 @@ public MCItemMeta itemMeta(Construct c, MCMaterial mat, Target t) throws ConfigR
MCBanner banner = (MCBanner) bs;
if(ma.containsKey("patterns")) {
CArray array = ArgumentValidation.getArray(ma.get("patterns", t), t);
if(ma.containsKey("basecolor")) {
MCDyeColor base = MCDyeColor.valueOf(ma.get("basecolor", t).val().toUpperCase());
banner.setBaseColor(base);
}
for(String key : array.stringKeySet()) {
CArray pattern = ArgumentValidation.getArray(array.get(key, t), t);
MCPatternShape shape = MCPatternShape.valueOf(pattern.get("shape", t).val().toUpperCase());
@@ -907,8 +912,18 @@ public MCItemMeta itemMeta(Construct c, MCMaterial mat, Target t) throws ConfigR
for(String key : array.stringKeySet()) {
CArray pattern = ArgumentValidation.getArray(array.get(key, t), t);
MCPatternShape shape = MCPatternShape.valueOf(pattern.get("shape", t).val().toUpperCase());
MCDyeColor color = MCDyeColor.valueOf(pattern.get("color", t).val().toUpperCase());
((MCBannerMeta) meta).addPattern(StaticLayer.GetConvertor().GetPattern(color, shape));
String color = pattern.get("color", t).val().toUpperCase();
try {
MCDyeColor dyecolor = MCDyeColor.valueOf(color);
((MCBannerMeta) meta).addPattern(StaticLayer.GetConvertor().GetPattern(dyecolor, shape));
} catch (IllegalArgumentException ex) {
if(color.equals("SILVER")) {
// convert old DyeColor
((MCBannerMeta) meta).addPattern(StaticLayer.GetConvertor().GetPattern(MCDyeColor.LIGHT_GRAY, shape));
} else {
throw ex;
}
}
}
}
} else if(meta instanceof MCMapMeta) {
@@ -50,8 +50,9 @@ public static String docs() {
+ "<li>Player Skulls - \"owner\" (string)</li>"
+ "<li>Potions - \"potions\" (array of custom potion effects (see get_peffect()),"
+ " \"base\" (an array with the keys \"type\", \"extended\", and \"upgraded\")</li>"
+ "<li>Banners - \"basecolor\" (string), \"patterns\" (an array of pattern arrays, each with the keys"
+ "<li>Banners - \"patterns\" (an array of pattern arrays, each with the keys"
+ " \"shape\" and \"color\")</li>"
+ "<li>Shields - \"basecolor\" (string), and \"patterns\" like in Banners."
+ "<li>Fireworks - \"firework\" (array with strength (int), \"effects\" (array of effect arrays (see Example)))</li>"
+ "<li>Firework Charges - \"effect\" (single Firework effect array)</li>"
+ "<li>Storage Blocks - \"inventory\" (an array of item arrays)</li>"

0 comments on commit 6ed5358

Please sign in to comment.