mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-29 14:15:50 +01:00
Add item args to /npc create and /npc item, remove Nameable reference
This commit is contained in:
parent
ede598cc9b
commit
ac387b2de4
@ -598,7 +598,7 @@ public class NPCCommands {
|
|||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "npc" },
|
aliases = { "npc" },
|
||||||
usage = "create [name] ((-b(aby),u(nspawned),s(ilent),t(emporary)) --at [x:y:z:world] --type [type] --trait ['trait1, trait2...'] --registry [registry name])",
|
usage = "create [name] ((-b(aby),u(nspawned),s(ilent),t(emporary)) --at [x:y:z:world] --type [type] --item (item) --trait ['trait1, trait2...'] --registry [registry name])",
|
||||||
desc = "Create a new NPC",
|
desc = "Create a new NPC",
|
||||||
flags = "bust",
|
flags = "bust",
|
||||||
modifiers = { "create" },
|
modifiers = { "create" },
|
||||||
@ -607,7 +607,8 @@ public class NPCCommands {
|
|||||||
@Requirements
|
@Requirements
|
||||||
public void create(CommandContext args, CommandSender sender, NPC npc, @Flag("at") Location at,
|
public void create(CommandContext args, CommandSender sender, NPC npc, @Flag("at") Location at,
|
||||||
@Flag(value = "type", defValue = "PLAYER") EntityType type, @Flag("trait") String traits,
|
@Flag(value = "type", defValue = "PLAYER") EntityType type, @Flag("trait") String traits,
|
||||||
@Flag("template") String templateName, @Flag("registry") String registryName) throws CommandException {
|
@Flag("item") String item, @Flag("template") String templateName, @Flag("registry") String registryName)
|
||||||
|
throws CommandException {
|
||||||
String name = Colorizer.parseColors(args.getJoinedStrings(1).trim());
|
String name = Colorizer.parseColors(args.getJoinedStrings(1).trim());
|
||||||
if (args.hasValueFlag("type")) {
|
if (args.hasValueFlag("type")) {
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
@ -643,7 +644,18 @@ public class NPCCommands {
|
|||||||
registry = temporaryRegistry;
|
registry = temporaryRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
npc = registry.createNPC(type, name);
|
if (item != null) {
|
||||||
|
ItemStack stack = new ItemStack(Material.STONE, 1);
|
||||||
|
try {
|
||||||
|
Bukkit.getUnsafe().modifyItemStack(stack, item);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
npc = registry.createNPCUsingItem(type, name, stack);
|
||||||
|
} else {
|
||||||
|
npc = registry.createNPC(type, name);
|
||||||
|
}
|
||||||
|
|
||||||
String msg = "Created [[" + npc.getName() + "]] (ID [[" + npc.getId() + "]])";
|
String msg = "Created [[" + npc.getName() + "]] (ID [[" + npc.getId() + "]])";
|
||||||
|
|
||||||
int age = 0;
|
int age = 0;
|
||||||
@ -1164,7 +1176,7 @@ public class NPCCommands {
|
|||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "npc" },
|
aliases = { "npc" },
|
||||||
usage = "item (item) (amount) (data)",
|
usage = "item (item) (metadata) (-h(and))",
|
||||||
desc = "Sets the NPC's item",
|
desc = "Sets the NPC's item",
|
||||||
modifiers = { "item", },
|
modifiers = { "item", },
|
||||||
min = 1,
|
min = 1,
|
||||||
@ -1172,13 +1184,19 @@ public class NPCCommands {
|
|||||||
flags = "h",
|
flags = "h",
|
||||||
permission = "citizens.npc.item")
|
permission = "citizens.npc.item")
|
||||||
@Requirements(selected = true, ownership = true)
|
@Requirements(selected = true, ownership = true)
|
||||||
public void item(CommandContext args, CommandSender sender, NPC npc, @Arg(1) Material mat, @Arg(2) Integer amount,
|
public void item(CommandContext args, CommandSender sender, NPC npc, @Arg(1) Material mat, @Arg(2) String modify)
|
||||||
@Arg(3) Byte data) throws CommandException {
|
throws CommandException {
|
||||||
EntityType type = npc.getOrAddTrait(MobType.class).getType();
|
EntityType type = npc.getOrAddTrait(MobType.class).getType();
|
||||||
if (!type.name().contains("ITEM_FRAME") && type != EntityType.DROPPED_ITEM && type != EntityType.FALLING_BLOCK)
|
if (!type.name().contains("ITEM_FRAME") && type != EntityType.DROPPED_ITEM && type != EntityType.FALLING_BLOCK)
|
||||||
throw new CommandException(CommandMessages.REQUIREMENTS_INVALID_MOB_TYPE);
|
throw new CommandException(CommandMessages.REQUIREMENTS_INVALID_MOB_TYPE);
|
||||||
ItemStack stack = args.hasFlag('h') ? ((Player) sender).getItemInHand()
|
ItemStack stack = args.hasFlag('h') ? ((Player) sender).getItemInHand() : new ItemStack(mat, 1);
|
||||||
: new ItemStack(mat, amount == null ? 1 : amount, data == null ? 0 : data);
|
if (modify != null) {
|
||||||
|
try {
|
||||||
|
Bukkit.getUnsafe().modifyItemStack(stack, modify);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
if (mat == null && !args.hasFlag('h'))
|
if (mat == null && !args.hasFlag('h'))
|
||||||
throw new CommandException(Messages.UNKNOWN_MATERIAL);
|
throw new CommandException(Messages.UNKNOWN_MATERIAL);
|
||||||
npc.setItemProvider(() -> stack);
|
npc.setItemProvider(() -> stack);
|
||||||
|
@ -7,7 +7,6 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Nameable;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
@ -510,8 +509,6 @@ public class CitizensNPC extends AbstractNPC {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateCustomName() {
|
public void updateCustomName() {
|
||||||
if (!(getEntity() instanceof Nameable))
|
|
||||||
return;
|
|
||||||
if (minecraftComponentCache != null) {
|
if (minecraftComponentCache != null) {
|
||||||
NMS.setCustomName(getEntity(), minecraftComponentCache);
|
NMS.setCustomName(getEntity(), minecraftComponentCache);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user