Permalink
Browse files

Convert legacy spawnegg meta to new item types

  • Loading branch information...
PseudoKnight committed Aug 14, 2018
1 parent 035360a commit e450ce66d39b6be0d2152da21fdeb58e47c24f62

This file was deleted.

Oops, something went wrong.
@@ -67,7 +67,6 @@
import com.laytonsmith.abstraction.enums.MCPotionType;
import com.laytonsmith.abstraction.enums.MCRecipeType;
import com.laytonsmith.abstraction.enums.MCTone;
import com.laytonsmith.abstraction.enums.MCVersion;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCLegacyMaterial;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCDyeColor;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCEntityType;
@@ -77,7 +76,6 @@
import com.laytonsmith.commandhelper.CommandHelperPlugin;
import com.laytonsmith.core.CHLog;
import com.laytonsmith.core.LogLevel;
import com.laytonsmith.core.Static;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.environments.CommandHelperEnvironment;
import com.laytonsmith.core.environments.Environment;
@@ -136,7 +134,6 @@
import org.bukkit.inventory.meta.MapMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.inventory.meta.SpawnEggMeta;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.potion.PotionData;
import org.yaml.snakeyaml.Yaml;
@@ -537,13 +534,6 @@ public static MCBlockState BukkitGetCorrectBlockState(BlockState bs) {
}
public static MCItemMeta BukkitGetCorrectMeta(ItemMeta im) {
MCVersion version = Static.getServer().getMinecraftVersion();
if(version.gte(MCVersion.MC1_11_X) && im instanceof SpawnEggMeta) {
if(version.lt(MCVersion.MC1_13)) {
return new BukkitMCSpawnEggMeta((SpawnEggMeta) im);
}
return new BukkitMCItemMeta(im);
}
if(im instanceof BlockStateMeta) {
return new BukkitMCBlockStateMeta((BlockStateMeta) im);
}

This file was deleted.

Oops, something went wrong.
@@ -33,7 +33,6 @@
import com.laytonsmith.abstraction.MCShapedRecipe;
import com.laytonsmith.abstraction.MCShapelessRecipe;
import com.laytonsmith.abstraction.MCSkullMeta;
import com.laytonsmith.abstraction.MCSpawnEggMeta;
import com.laytonsmith.abstraction.MCWorld;
import com.laytonsmith.abstraction.StaticLayer;
import com.laytonsmith.abstraction.blocks.MCBlockState;
@@ -256,7 +255,7 @@ public MCItemStack item(Construct i, Target t, boolean legacy) {
}
CArray item = (CArray) i;
String mat;
MCItemStack ret = null;
MCItemStack ret;
int data = 0;
int qty = 1;
@@ -271,7 +270,9 @@ public MCItemStack item(Construct i, Target t, boolean legacy) {
data = Static.getInt32(item.get("data", t), t);
}
if(legacy || item.containsKey("type")) {
legacy = legacy || item.containsKey("type");
if(legacy) {
// Do legacy item conversion
MCMaterial material;
if(item.containsKey("name")) {
@@ -308,6 +309,21 @@ public MCItemStack item(Construct i, Target t, boolean legacy) {
if(material == null) {
throw new CREFormatException("Could not convert legacy item from " + mat + ":" + data, t);
}
// convert legacy meta to material
if(material.getName().equals("PIG_SPAWN_EGG") && item.containsKey("meta")) {
Construct meta = item.get("meta", t);
if(meta instanceof CArray && ((CArray) meta).containsKey("spawntype")) {
Construct spawntype = ((CArray) meta).get("spawntype", t);
if(!(spawntype instanceof CNull)) {
MCMaterial newmaterial = StaticLayer.GetMaterial(spawntype.val().toUpperCase() + "_SPAWN_EGG");
if(newmaterial != null) {
material = newmaterial;
}
}
}
}
ret = StaticLayer.GetItemStack(material, data, qty);
CHLog.GetLogger().w(CHLog.Tags.DEPRECATION, "Converted \"" + mat + ":" + data + "\"" + " to "
+ material.getName(), t);
@@ -546,13 +562,6 @@ public Construct itemMeta(MCItemStack is, Target t) {
if(dyeColor != null) {
ma.set("basecolor", new CString(dyeColor.toString(), t), t);
}
} else if(meta instanceof MCSpawnEggMeta) {
MCEntityType spawntype = ((MCSpawnEggMeta) meta).getSpawnedType();
if(spawntype == null) {
ma.set("spawntype", CNull.NULL, t);
} else {
ma.set("spawntype", new CString(spawntype.name(), t), t);
}
} else if(meta instanceof MCMapMeta) {
MCMapMeta mm = ((MCMapMeta) meta);
MCColor mapcolor = mm.getColor();
@@ -888,13 +897,6 @@ public MCItemMeta itemMeta(Construct c, MCMaterial mat, Target t) throws ConfigR
((MCBannerMeta) meta).addPattern(StaticLayer.GetConvertor().GetPattern(color, shape));
}
}
} else if(meta instanceof MCSpawnEggMeta) {
if(ma.containsKey("spawntype")) {
Construct spawntype = ma.get("spawntype", t);
if(spawntype instanceof CString) {
((MCSpawnEggMeta) meta).setSpawnedType(MCEntityType.valueOf(spawntype.val().toUpperCase()));
}
}
} else if(meta instanceof MCMapMeta && Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_11)) {
if(ma.containsKey("color")) {
Construct ci = ma.get("color", t);

0 comments on commit e450ce6

Please sign in to comment.