Create Mixin for recipe construction
This should help reduce errors found in older servers.
This commit is contained in:
parent
11add07090
commit
f2ca8e007b
49
src/com/massivecraft/massivecore/mixin/MixinRecipe.java
Normal file
49
src/com/massivecraft/massivecore/mixin/MixinRecipe.java
Normal file
@ -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);
|
||||
}
|
||||
|
||||
}
|
51
src/com/massivecraft/massivecore/nms/NmsRecipe.java
Normal file
51
src/com/massivecraft/massivecore/nms/NmsRecipe.java
Normal file
@ -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();
|
||||
}
|
||||
|
||||
}
|
59
src/com/massivecraft/massivecore/nms/NmsRecipe112R1P.java
Normal file
59
src/com/massivecraft/massivecore/nms/NmsRecipe112R1P.java
Normal file
@ -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);
|
||||
}
|
||||
|
||||
}
|
51
src/com/massivecraft/massivecore/nms/NmsRecipe17R4P.java
Normal file
51
src/com/massivecraft/massivecore/nms/NmsRecipe17R4P.java
Normal file
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user