Implement UnsafeValues for give command. Addresses BUKKIT-5286
By: Wesley Wolfe <weswolf@aol.com>
This commit is contained in:
@@ -1,11 +1,23 @@
|
||||
package org.bukkit.craftbukkit.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.server.Block;
|
||||
import net.minecraft.server.Blocks;
|
||||
import net.minecraft.server.Item;
|
||||
import org.bukkit.Material;
|
||||
import net.minecraft.server.MojangsonParser;
|
||||
import net.minecraft.server.NBTTagCompound;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.UnsafeValues;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public final class CraftMagicNumbers implements UnsafeValues {
|
||||
public static final UnsafeValues INSTANCE = new CraftMagicNumbers();
|
||||
|
||||
public final class CraftMagicNumbers {
|
||||
private CraftMagicNumbers() {}
|
||||
|
||||
public static Block getBlock(org.bukkit.block.Block block) {
|
||||
@@ -67,4 +79,25 @@ public final class CraftMagicNumbers {
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material getMaterialFromInternalName(String name) {
|
||||
return getMaterial((Item) Item.REGISTRY.a(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabCompleteInternalMaterialName(String token, List<String> completions) {
|
||||
return StringUtil.copyPartialMatches(token, Item.REGISTRY.b(), completions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack modifyItemStack(ItemStack stack, String arguments) {
|
||||
net.minecraft.server.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
||||
|
||||
nmsStack.setTag((NBTTagCompound) MojangsonParser.a(arguments));
|
||||
|
||||
stack.setItemMeta(CraftItemStack.getItemMeta(nmsStack));
|
||||
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user