mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-14 11:45:52 -07:00
Modify give command to support 1.7 features. Fixes BUKKIT-5286
Necessary additions include an interface to add internal value conversions that are inappropriate for proper API design. This acts as a substitute for properly formed, user-friendly commands in an effort to maintain relatively vanilla behavior. By: Wesley Wolfe <weswolf@aol.com>
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user