diff --git a/src/com/massivecraft/massivecore/mixin/MixinRecipe.java b/src/com/massivecraft/massivecore/mixin/MixinRecipe.java new file mode 100644 index 00000000..23ac8140 --- /dev/null +++ b/src/com/massivecraft/massivecore/mixin/MixinRecipe.java @@ -0,0 +1,49 @@ +package com.massivecraft.massivecore.mixin; + +import com.massivecraft.massivecore.nms.NmsRecipe; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.ShapedRecipe; +import org.bukkit.inventory.ShapelessRecipe; +import org.bukkit.plugin.Plugin; + +public class MixinRecipe extends Mixin +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MixinRecipe d = new MixinRecipe(); + private static MixinRecipe i = d; + public static MixinRecipe get() { return i; } + + // -------------------------------------------- // + // AVAILABLE + // -------------------------------------------- // + + @Override + public boolean isAvailable() + { + return NmsRecipe.get().isAvailable(); + } + + public ShapelessRecipe createShapeless(ItemStack result) + { + return NmsRecipe.get().createShapeless(result); + } + + public ShapelessRecipe createShapeless(ItemStack result, Plugin plugin, String key) + { + return NmsRecipe.get().createShapeless(result, plugin, key); + } + + public ShapedRecipe createShaped(ItemStack result) + { + return NmsRecipe.get().createShaped(result); + } + + public ShapedRecipe createShaped(ItemStack result, Plugin plugin, String key) + { + return NmsRecipe.get().createShaped(result, plugin, key); + } + +} diff --git a/src/com/massivecraft/massivecore/nms/NmsRecipe.java b/src/com/massivecraft/massivecore/nms/NmsRecipe.java new file mode 100644 index 00000000..4bae565b --- /dev/null +++ b/src/com/massivecraft/massivecore/nms/NmsRecipe.java @@ -0,0 +1,51 @@ +package com.massivecraft.massivecore.nms; + +import com.massivecraft.massivecore.mixin.Mixin; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.ShapedRecipe; +import org.bukkit.inventory.ShapelessRecipe; +import org.bukkit.plugin.Plugin; + +public class NmsRecipe extends Mixin +{ + // -------------------------------------------- // + // DEFAULT + // -------------------------------------------- // + + private static NmsRecipe d = new NmsRecipe().setAlternatives( + NmsRecipe112R1P.class, + NmsRecipe17R4P.class + ); + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static NmsRecipe i = d; + public static NmsRecipe get() { return i; } + + // -------------------------------------------- // + // METHODS + // -------------------------------------------- // + + public ShapelessRecipe createShapeless(ItemStack result) + { + throw notImplemented(); + } + + public ShapelessRecipe createShapeless(ItemStack result, Plugin plugin, String key) + { + throw notImplemented(); + } + + public ShapedRecipe createShaped(ItemStack result) + { + throw notImplemented(); + } + + public ShapedRecipe createShaped(ItemStack result, Plugin plugin, String key) + { + throw notImplemented(); + } + +} diff --git a/src/com/massivecraft/massivecore/nms/NmsRecipe112R1P.java b/src/com/massivecraft/massivecore/nms/NmsRecipe112R1P.java new file mode 100644 index 00000000..231ea94d --- /dev/null +++ b/src/com/massivecraft/massivecore/nms/NmsRecipe112R1P.java @@ -0,0 +1,59 @@ +package com.massivecraft.massivecore.nms; + +import com.massivecraft.massivecore.MassiveCore; +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.ShapedRecipe; +import org.bukkit.inventory.ShapelessRecipe; +import org.bukkit.plugin.Plugin; + +import java.util.UUID; + +public class NmsRecipe112R1P extends NmsRecipe +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static NmsRecipe112R1P i = new NmsRecipe112R1P(); + public static NmsRecipe112R1P get() { return i; } + + // -------------------------------------------- // + // SETUP + // -------------------------------------------- // + + @Override + public Object provoke() throws Throwable + { + return new NamespacedKey(MassiveCore.get(), "provocation"); + } + + // -------------------------------------------- // + // METHODS + // -------------------------------------------- // + + @Override + public ShapelessRecipe createShapeless(ItemStack result) + { + return createShapeless(result, MassiveCore.get(), UUID.randomUUID().toString()); + } + + @Override + public ShapelessRecipe createShapeless(ItemStack result, Plugin plugin, String key) + { + return new ShapelessRecipe(new NamespacedKey(plugin, key), result); + } + + @Override + public ShapedRecipe createShaped(ItemStack result) + { + return createShaped(result, MassiveCore.get(), UUID.randomUUID().toString()); + } + + @Override + public ShapedRecipe createShaped(ItemStack result, Plugin plugin, String key) + { + return new ShapedRecipe(new NamespacedKey(plugin, key), result); + } + +} diff --git a/src/com/massivecraft/massivecore/nms/NmsRecipe17R4P.java b/src/com/massivecraft/massivecore/nms/NmsRecipe17R4P.java new file mode 100644 index 00000000..4f1894eb --- /dev/null +++ b/src/com/massivecraft/massivecore/nms/NmsRecipe17R4P.java @@ -0,0 +1,51 @@ +package com.massivecraft.massivecore.nms; + +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.ShapedRecipe; +import org.bukkit.inventory.ShapelessRecipe; +import org.bukkit.plugin.Plugin; + +public class NmsRecipe17R4P extends NmsRecipe +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static NmsRecipe17R4P i = new NmsRecipe17R4P(); + public static NmsRecipe17R4P get() { return i; } + + // -------------------------------------------- // + // METHODS + // -------------------------------------------- // + + @Override + public ShapelessRecipe createShapeless(ItemStack result) + { + // Old way of constructing recipes + return new ShapelessRecipe(result); + } + + @Override + public ShapelessRecipe createShapeless(ItemStack result, Plugin plugin, String key) + { + // This overloaded call is a bit odd backwards from the standard + // This is because it is for ignoring features not yet present + return createShapeless(result); + } + + @Override + public ShapedRecipe createShaped(ItemStack result) + { + // Old way of constructing recipes + return new ShapedRecipe(result); + } + + @Override + public ShapedRecipe createShaped(ItemStack result, Plugin plugin, String key) + { + // This overloaded call is a bit odd backwards from the standard + // This is because it is for ignoring features not yet present + return createShaped(result); + } + +} diff --git a/src/com/massivecraft/massivecore/util/RecipeUtil.java b/src/com/massivecraft/massivecore/util/RecipeUtil.java index d4d5e948..d8e06633 100644 --- a/src/com/massivecraft/massivecore/util/RecipeUtil.java +++ b/src/com/massivecraft/massivecore/util/RecipeUtil.java @@ -1,8 +1,8 @@ package com.massivecraft.massivecore.util; +import com.massivecraft.massivecore.mixin.MixinRecipe; import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ShapelessRecipe; import org.bukkit.inventory.meta.PotionMeta; @@ -72,7 +72,7 @@ public class RecipeUtil @SuppressWarnings("deprecation") public static ShapelessRecipe createShapeless(ItemStack result, Object... objects) { - ShapelessRecipe recipe = new ShapelessRecipe(NamespacedKey.randomKey(), result); + ShapelessRecipe recipe = MixinRecipe.get().createShapeless(result); int quantity = 1; int data = 0;