Skip to content

Commit

Permalink
Add /npc item
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Dec 17, 2013
1 parent fed5c8c commit 187fa0b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/main/java/net/citizensnpcs/commands/NPCCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import net.citizensnpcs.npc.EntityControllers;
import net.citizensnpcs.npc.NPCSelector;
import net.citizensnpcs.npc.Template;
import net.citizensnpcs.npc.entity.nonliving.FallingBlockController.FallingBlockNPC;
import net.citizensnpcs.trait.Age;
import net.citizensnpcs.trait.Anchors;
import net.citizensnpcs.trait.Controllable;
Expand All @@ -58,6 +59,7 @@
import org.bukkit.DyeColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.CommandSender;
Expand All @@ -68,6 +70,7 @@
import org.bukkit.entity.Horse.Color;
import org.bukkit.entity.Horse.Style;
import org.bukkit.entity.Horse.Variant;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -561,6 +564,37 @@ public void id(CommandContext args, CommandSender sender, NPC npc) {
Messaging.send(sender, npc.getId());
}

@Command(
aliases = { "npc" },
usage = "item [item]",
desc = "Sets the NPC's item",
modifiers = { "item", },
min = 1,
max = 2,
flags = "",
permission = "citizens.npc.item")
@Requirements(selected = true, ownership = true, types = { EntityType.DROPPED_ITEM, EntityType.ITEM_FRAME,
EntityType.FALLING_BLOCK })
public void item(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
Material mat = Material.getMaterial(args.getString(1));
if (mat == null)
throw new CommandException(Messages.UNKNOWN_MATERIAL);
switch (npc.getEntity().getType()) {
case DROPPED_ITEM:
((org.bukkit.entity.Item) npc.getEntity()).getItemStack().setType(mat);
break;
case ITEM_FRAME:
((ItemFrame) npc.getEntity()).getItem().setType(mat);
break;
case FALLING_BLOCK:
((FallingBlockNPC) npc.getEntity()).setType(mat);
break;
default:
break;
}
Messaging.sendTr(sender, Messages.ITEM_SET, Util.prettyEnum(mat));
}

@Command(
aliases = { "npc" },
usage = "leashable",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import net.minecraft.server.v1_7_R1.World;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_7_R1.CraftServer;
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftFallingSand;
import org.bukkit.craftbukkit.v1_7_R1.util.CraftMagicNumbers;
import org.bukkit.entity.FallingBlock;
import org.bukkit.util.Vector;

Expand Down Expand Up @@ -105,5 +107,14 @@ public FallingBlockNPC(EntityFallingBlockNPC entity) {
public NPC getNPC() {
return npc;
}

public void setType(Material material) {
EntityFallingBlock e = (EntityFallingBlock) entity;
e.id = CraftMagicNumbers.getBlock(material);
if (npc.isSpawned()) {
npc.despawn();
npc.spawn(npc.getStoredLocation());
}
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/net/citizensnpcs/util/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public class Messages {
public static final String INVALID_SKELETON_TYPE = "citizens.commands.npc.skeletontype.invalid-type";
public static final String INVALID_SPAWN_LOCATION = "citizens.commands.npc.create.invalid-location";
public static final String INVALID_TRIGGER_TELEPORT_FORMAT = "citizens.editors.waypoints.triggers.teleport.invalid-format";
public static final String ITEM_SET = "citizens.commands.npc.item.item-set";
public static final String LEASHABLE_SET = "citizens.commands.npc.leashable.set";
public static final String LEASHABLE_STOPPED = "citizens.commands.npc.leashable.stopped";
public static final String LINEAR_WAYPOINT_EDITOR_ADDED_WAYPOINT = "citizens.editors.waypoints.linear.added-waypoint";
Expand Down Expand Up @@ -229,6 +230,7 @@ public class Messages {
public static final String TRAITS_FAILED_TO_CHANGE = "citizens.commands.trait.failed-to-change";
public static final String TRAITS_REMOVED = "citizens.commands.trait.removed";
public static final String UNKNOWN_COMMAND = "citizens.commands.unknown-command";
public static final String UNKNOWN_MATERIAL = "citizens.commands.npc.item.unknown-material";
public static final String VULNERABLE_SET = "citizens.commands.npc.vulnerable.set";
public static final String VULNERABLE_STOPPED = "citizens.commands.npc.vulnerable.stopped";
public static final String WAYPOINT_PROVIDER_SET = "citizens.waypoints.set-provider";
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ citizens.commands.npc.horse.describe=The horse''s color is [[{0}]], the type is
citizens.commands.npc.horse.invalid-color=Invalid horse color given. Valid colors are: [[{0}]].
citizens.commands.npc.horse.invalid-type=Invalid horse type given. Valid types are: [[{0}]].
citizens.commands.npc.horse.invalid-style=Invalid horse style given. Valid styles are: [[{0}]].
citizens.commands.npc.item.item-set=NPC item set to [[{0}]].
citizens.commands.npc.item.unknown-material=Unknown material given.
citizens.commands.npc.leashable.set=[[{0}]] is now leashable.
citizens.commands.npc.leashable.stopped=[[{0}]] is no longer leashable.
citizens.commands.npc.lookclose.set=[[{0}]] will now rotate when players are nearby.
Expand Down

0 comments on commit 187fa0b

Please sign in to comment.