summaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/bukkit/Bukkit.java8
-rw-r--r--src/main/java/org/bukkit/Server.java6
-rw-r--r--src/main/java/org/bukkit/UnsafeValues.java27
-rw-r--r--src/main/java/org/bukkit/command/defaults/GiveCommand.java28
4 files changed, 61 insertions, 8 deletions
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index b173ac7a..db57b6d5 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -692,4 +692,12 @@ public final class Bukkit {
public static int getIdleTimeout() {
return server.getIdleTimeout();
}
+
+ /**
+ * @see Server#getUnsafe()
+ */
+ @Deprecated
+ public static UnsafeValues getUnsafe() {
+ return server.getUnsafe();
+ }
}
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index 5c9d2c7a..57e7b30b 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -799,4 +799,10 @@ public interface Server extends PluginMessageRecipient {
* @return the idle timeout in minutes
*/
public int getIdleTimeout();
+
+ /**
+ * @see UnsafeValues
+ */
+ @Deprecated
+ UnsafeValues getUnsafe();
}
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
new file mode 100644
index 00000000..a6c7a6ba
--- /dev/null
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -0,0 +1,27 @@
+package org.bukkit;
+
+import java.util.List;
+
+import org.bukkit.inventory.ItemStack;
+
+/**
+ * This interface provides value conversions that may be specific to a
+ * runtime, or have arbitrary meaning (read: magic values).
+ * <p>
+ * Their existence and behavior is not guaranteed across future versions. They
+ * may be poorly named, throw exceptions, have misleading parameters, or any
+ * other bad programming practice.
+ * <p>
+ * This interface is unsupported and only for internal use.
+ *
+ * @deprecated Unsupported & internal use only
+ */
+@Deprecated
+public interface UnsafeValues {
+
+ Material getMaterialFromInternalName(String name);
+
+ List<String> tabCompleteInternalMaterialName(String token, List<String> completions);
+
+ ItemStack modifyItemStack(ItemStack stack, String arguments);
+}
diff --git a/src/main/java/org/bukkit/command/defaults/GiveCommand.java b/src/main/java/org/bukkit/command/defaults/GiveCommand.java
index 9eba11dc..14f27be9 100644
--- a/src/main/java/org/bukkit/command/defaults/GiveCommand.java
+++ b/src/main/java/org/bukkit/command/defaults/GiveCommand.java
@@ -1,6 +1,7 @@
package org.bukkit.command.defaults;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -14,6 +15,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.StringUtil;
+import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
public class GiveCommand extends VanillaCommand {
@@ -47,6 +49,10 @@ public class GiveCommand extends VanillaCommand {
if (player != null) {
Material material = Material.matchMaterial(args[1]);
+ if (material == null) {
+ material = Bukkit.getUnsafe().getMaterialFromInternalName(args[1]);
+ }
+
if (material != null) {
int amount = 1;
short data = 0;
@@ -61,7 +67,18 @@ public class GiveCommand extends VanillaCommand {
}
}
- player.getInventory().addItem(new ItemStack(material, amount, data));
+ ItemStack stack = new ItemStack(material, amount, data);
+
+ if (args.length >= 5) {
+ try {
+ stack = Bukkit.getUnsafe().modifyItemStack(stack, Joiner.on(' ').join(Arrays.asList(args).subList(4, args.length)));
+ } catch (Throwable t) {
+ player.sendMessage("Not a valid tag");
+ return true;
+ }
+ }
+
+ player.getInventory().addItem(stack);
Command.broadcastCommandMessage(sender, "Gave " + player.getName() + " some " + material.getId() + " (" + material + ")");
} else {
@@ -86,7 +103,7 @@ public class GiveCommand extends VanillaCommand {
if (args.length == 2) {
final String arg = args[1];
final List<String> materials = GiveCommand.materials;
- List<String> completion = null;
+ List<String> completion = new ArrayList<String>();
final int size = materials.size();
int i = Collections.binarySearch(materials, arg, String.CASE_INSENSITIVE_ORDER);
@@ -99,18 +116,13 @@ public class GiveCommand extends VanillaCommand {
for ( ; i < size; i++) {
String material = materials.get(i);
if (StringUtil.startsWithIgnoreCase(material, arg)) {
- if (completion == null) {
- completion = new ArrayList<String>();
- }
completion.add(material);
} else {
break;
}
}
- if (completion != null) {
- return completion;
- }
+ return Bukkit.getUnsafe().tabCompleteInternalMaterialName(arg, completion);
}
return ImmutableList.of();
}