mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-10 03:52:45 +01: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:
parent
c0e5d3fbf0
commit
bac44d80a6
4 changed files with 61 additions and 8 deletions
|
@ -692,4 +692,12 @@ public final class Bukkit {
|
||||||
public static int getIdleTimeout() {
|
public static int getIdleTimeout() {
|
||||||
return server.getIdleTimeout();
|
return server.getIdleTimeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Server#getUnsafe()
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static UnsafeValues getUnsafe() {
|
||||||
|
return server.getUnsafe();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -799,4 +799,10 @@ public interface Server extends PluginMessageRecipient {
|
||||||
* @return the idle timeout in minutes
|
* @return the idle timeout in minutes
|
||||||
*/
|
*/
|
||||||
public int getIdleTimeout();
|
public int getIdleTimeout();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see UnsafeValues
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
UnsafeValues getUnsafe();
|
||||||
}
|
}
|
||||||
|
|
27
paper-api/src/main/java/org/bukkit/UnsafeValues.java
Normal file
27
paper-api/src/main/java/org/bukkit/UnsafeValues.java
Normal file
|
@ -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);
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package org.bukkit.command.defaults;
|
package org.bukkit.command.defaults;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -14,6 +15,7 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.util.StringUtil;
|
import org.bukkit.util.StringUtil;
|
||||||
|
|
||||||
|
import com.google.common.base.Joiner;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
public class GiveCommand extends VanillaCommand {
|
public class GiveCommand extends VanillaCommand {
|
||||||
|
@ -47,6 +49,10 @@ public class GiveCommand extends VanillaCommand {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
Material material = Material.matchMaterial(args[1]);
|
Material material = Material.matchMaterial(args[1]);
|
||||||
|
|
||||||
|
if (material == null) {
|
||||||
|
material = Bukkit.getUnsafe().getMaterialFromInternalName(args[1]);
|
||||||
|
}
|
||||||
|
|
||||||
if (material != null) {
|
if (material != null) {
|
||||||
int amount = 1;
|
int amount = 1;
|
||||||
short data = 0;
|
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 + ")");
|
Command.broadcastCommandMessage(sender, "Gave " + player.getName() + " some " + material.getId() + " (" + material + ")");
|
||||||
} else {
|
} else {
|
||||||
|
@ -86,7 +103,7 @@ public class GiveCommand extends VanillaCommand {
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
final String arg = args[1];
|
final String arg = args[1];
|
||||||
final List<String> materials = GiveCommand.materials;
|
final List<String> materials = GiveCommand.materials;
|
||||||
List<String> completion = null;
|
List<String> completion = new ArrayList<String>();
|
||||||
|
|
||||||
final int size = materials.size();
|
final int size = materials.size();
|
||||||
int i = Collections.binarySearch(materials, arg, String.CASE_INSENSITIVE_ORDER);
|
int i = Collections.binarySearch(materials, arg, String.CASE_INSENSITIVE_ORDER);
|
||||||
|
@ -99,18 +116,13 @@ public class GiveCommand extends VanillaCommand {
|
||||||
for ( ; i < size; i++) {
|
for ( ; i < size; i++) {
|
||||||
String material = materials.get(i);
|
String material = materials.get(i);
|
||||||
if (StringUtil.startsWithIgnoreCase(material, arg)) {
|
if (StringUtil.startsWithIgnoreCase(material, arg)) {
|
||||||
if (completion == null) {
|
|
||||||
completion = new ArrayList<String>();
|
|
||||||
}
|
|
||||||
completion.add(material);
|
completion.add(material);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (completion != null) {
|
return Bukkit.getUnsafe().tabCompleteInternalMaterialName(arg, completion);
|
||||||
return completion;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ImmutableList.of();
|
return ImmutableList.of();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue