Implement UnsafeValues for give command. Addresses BUKKIT-5286

This commit is contained in:
Wesley Wolfe 2014-01-14 22:38:03 -06:00
parent 81919478fc
commit 05ed0a3139
2 changed files with 43 additions and 2 deletions

View File

@ -61,6 +61,7 @@ import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.UnsafeValues;
import org.bukkit.Warning.WarningState; import org.bukkit.Warning.WarningState;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
@ -93,6 +94,7 @@ import org.bukkit.craftbukkit.scoreboard.CraftScoreboardManager;
import org.bukkit.craftbukkit.updater.AutoUpdater; import org.bukkit.craftbukkit.updater.AutoUpdater;
import org.bukkit.craftbukkit.updater.BukkitDLUpdaterService; import org.bukkit.craftbukkit.updater.BukkitDLUpdaterService;
import org.bukkit.craftbukkit.util.CraftIconCache; import org.bukkit.craftbukkit.util.CraftIconCache;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.util.DatFileFilter; import org.bukkit.craftbukkit.util.DatFileFilter;
import org.bukkit.craftbukkit.util.Versioning; import org.bukkit.craftbukkit.util.Versioning;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -1460,4 +1462,10 @@ public final class CraftServer implements Server {
public int getIdleTimeout() { public int getIdleTimeout() {
return console.aq(); // Should be getIdleTimeout return console.aq(); // Should be getIdleTimeout
} }
@Deprecated
@Override
public UnsafeValues getUnsafe() {
return CraftMagicNumbers.INSTANCE;
}
} }

View File

@ -1,11 +1,23 @@
package org.bukkit.craftbukkit.util; package org.bukkit.craftbukkit.util;
import java.util.List;
import net.minecraft.server.Block; import net.minecraft.server.Block;
import net.minecraft.server.Blocks; import net.minecraft.server.Blocks;
import net.minecraft.server.Item; 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() {} private CraftMagicNumbers() {}
public static Block getBlock(org.bukkit.block.Block block) { public static Block getBlock(org.bukkit.block.Block block) {
@ -67,4 +79,25 @@ public final class CraftMagicNumbers {
return block; 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;
}
} }