mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-23 19:16:34 +01:00
Added ability to equip the carried material for Enderman. This addresses CITIZENS-7.
This commit is contained in:
parent
0c70b28803
commit
d4113c1984
@ -17,8 +17,8 @@
|
||||
<classpath>
|
||||
<pathelement path="${lib}" />
|
||||
<pathelement location="${lib}/bukkit-1.2.3-R0.2-SNAPSHOT.jar" />
|
||||
<pathelement location="${lib}/craftbukkit-1.2.3-R0.2-SNAPSHOT.jar" />
|
||||
<pathelement location="${lib}/CitizensAPI.jar" />
|
||||
<pathelement location="${lib}/craftbukkit-1.2.3-R0.2-SNAPSHOT.jar" />
|
||||
</classpath>
|
||||
</javac>
|
||||
<antcall target="distcore" />
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -12,7 +12,6 @@ import net.citizensnpcs.api.event.CitizensReloadEvent;
|
||||
import net.citizensnpcs.api.exception.NPCException;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.npc.character.CharacterManager;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.api.util.DatabaseStorage;
|
||||
import net.citizensnpcs.api.util.Storage;
|
||||
@ -60,10 +59,6 @@ public class Citizens extends JavaPlugin {
|
||||
private Storage saves; // TODO: refactor this into an NPCStore (remove
|
||||
// dependency on Storage).
|
||||
|
||||
public CharacterManager getCharacterManager() {
|
||||
return characterManager;
|
||||
}
|
||||
|
||||
public CommandManager getCommandManager() {
|
||||
return commands;
|
||||
}
|
||||
@ -255,8 +250,8 @@ public class Citizens extends JavaPlugin {
|
||||
if (!key.keyExists("name"))
|
||||
throw new NPCLoadException("Could not find a name for the NPC with ID '" + id + "'.");
|
||||
|
||||
NPC npc = npcManager.createNPC(EntityType.valueOf(key.getString("traits.type").toUpperCase()), id,
|
||||
key.getString("name"), null);
|
||||
NPC npc = npcManager.createNPC(EntityType.valueOf(key.getString("traits.type").toUpperCase()), id, key
|
||||
.getString("name"), null);
|
||||
try {
|
||||
((CitizensNPC) npc).load(key);
|
||||
} catch (NPCException ex) {
|
||||
|
@ -28,6 +28,8 @@ import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
public class CommandManager {
|
||||
|
||||
/*
|
||||
@ -95,17 +97,23 @@ public class CommandManager {
|
||||
if (cmdRequirements != null) {
|
||||
NPC npc = (NPC) methodArgs[2];
|
||||
|
||||
// Requirements
|
||||
if (cmdRequirements.selected() && npc == null)
|
||||
throw new RequirementMissingException("You must have an NPC selected to execute that command.");
|
||||
|
||||
if (cmdRequirements.ownership() && npc != null
|
||||
&& !npc.getTrait(Owner.class).getOwner().equals(player.getName())
|
||||
&& !player.hasPermission("citizens.admin"))
|
||||
throw new RequirementMissingException("You must be the owner of this NPC to execute that command.");
|
||||
if (cmdRequirements.type() != EntityType.UNKNOWN
|
||||
&& !cmdRequirements.type().name().equals(npc.getTrait(MobType.class).getType()))
|
||||
throw new RequirementMissingException("The NPC must be of the type '"
|
||||
+ cmdRequirements.type().name().toLowerCase().replace('_', '-')
|
||||
+ "' in order for you to use that command.");
|
||||
|
||||
Set<EntityType> types = Sets.newHashSet(cmdRequirements.types());
|
||||
if (!types.contains(EntityType.UNKNOWN)) {
|
||||
EntityType type = EntityType.valueOf(npc.getTrait(MobType.class).getType());
|
||||
if (!types.contains(type)) {
|
||||
throw new RequirementMissingException("The NPC cannot be the mob type '"
|
||||
+ type.name().toLowerCase().replace('_', '-') + "' to use that command.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,5 +12,5 @@ public @interface Requirements {
|
||||
|
||||
boolean selected() default false;
|
||||
|
||||
EntityType type() default EntityType.UNKNOWN;
|
||||
EntityType[] types() default { EntityType.UNKNOWN };
|
||||
}
|
@ -16,38 +16,39 @@ import org.bukkit.entity.Player;
|
||||
public class EditorCommands {
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "equip",
|
||||
desc = "Toggle the equipment editor",
|
||||
modifiers = { "equip" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.edit.equip")
|
||||
@Requirements(selected = true, ownership = true, type = EntityType.PLAYER)
|
||||
aliases = { "npc" },
|
||||
usage = "equip",
|
||||
desc = "Toggle the equipment editor",
|
||||
modifiers = { "equip" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.edit.equip")
|
||||
@Requirements(selected = true, ownership = true, types = { EntityType.ENDERMAN, EntityType.PLAYER, EntityType.PIG,
|
||||
EntityType.SHEEP })
|
||||
public void equip(CommandContext args, Player player, NPC npc) {
|
||||
Editor.enterOrLeave(player, new EquipmentEditor(player, npc));
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "path",
|
||||
desc = "Toggle the waypoint editor",
|
||||
modifiers = { "path" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.edit.path")
|
||||
aliases = { "npc" },
|
||||
usage = "path",
|
||||
desc = "Toggle the waypoint editor",
|
||||
modifiers = { "path" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.edit.path")
|
||||
public void path(CommandContext args, Player player, NPC npc) {
|
||||
Editor.enterOrLeave(player, npc.getTrait(Waypoints.class).getEditor(player));
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "text",
|
||||
desc = "Toggle the text editor",
|
||||
modifiers = { "text" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.edit.text")
|
||||
aliases = { "npc" },
|
||||
usage = "text",
|
||||
desc = "Toggle the text editor",
|
||||
modifiers = { "text" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.edit.text")
|
||||
public void text(CommandContext args, Player player, NPC npc) {
|
||||
Editor.enterOrLeave(player, npc.getTrait(Text.class).getEditor(player));
|
||||
}
|
||||
|
8
src/main/java/net/citizensnpcs/editor/Equipable.java
Normal file
8
src/main/java/net/citizensnpcs/editor/Equipable.java
Normal file
@ -0,0 +1,8 @@
|
||||
package net.citizensnpcs.editor;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface Equipable {
|
||||
|
||||
public void equip(Player equipper);
|
||||
}
|
@ -2,17 +2,15 @@ package net.citizensnpcs.editor;
|
||||
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.trait.trait.Equipment;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class EquipmentEditor extends Editor {
|
||||
private final NPC npc;
|
||||
@ -26,9 +24,10 @@ public class EquipmentEditor extends Editor {
|
||||
@Override
|
||||
public void begin() {
|
||||
Messaging.send(player, "<b>Entered the equipment editor!");
|
||||
Messaging.send(player, "<e>Right click <a>to equip armor and items.");
|
||||
Messaging.send(player, "<e>Right click <a>while <e>crouching <a>to equip armor in the NPC's hand.");
|
||||
Messaging.send(player, "<e>Right click <a>with an <e>empty hand <a>to remove all armor and items.");
|
||||
Messaging.send(player, "<e>Right click <a>to equip the NPC!");
|
||||
Messaging.send(player, "<e>Right click <a>with an <e>empty hand <a>to reset all items.");
|
||||
Messaging.send(player,
|
||||
"<a>If the NPC is <e>human<a>, <e>right click <a>while <e>crouching <a>to equip armor its hand.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,67 +48,10 @@ public class EquipmentEditor extends Editor {
|
||||
|| !event.getPlayer().equals(player))
|
||||
return;
|
||||
|
||||
ItemStack hand = player.getItemInHand();
|
||||
Equipment trait = npc.getTrait(Equipment.class);
|
||||
int slot = 0;
|
||||
// First, determine the slot to edit
|
||||
switch (hand.getType()) {
|
||||
case PUMPKIN:
|
||||
case JACK_O_LANTERN:
|
||||
case LEATHER_HELMET:
|
||||
case CHAINMAIL_HELMET:
|
||||
case GOLD_HELMET:
|
||||
case IRON_HELMET:
|
||||
case DIAMOND_HELMET:
|
||||
if (!player.isSneaking())
|
||||
slot = 1;
|
||||
break;
|
||||
case LEATHER_CHESTPLATE:
|
||||
case CHAINMAIL_CHESTPLATE:
|
||||
case GOLD_CHESTPLATE:
|
||||
case IRON_CHESTPLATE:
|
||||
case DIAMOND_CHESTPLATE:
|
||||
if (!player.isSneaking())
|
||||
slot = 2;
|
||||
break;
|
||||
case LEATHER_LEGGINGS:
|
||||
case CHAINMAIL_LEGGINGS:
|
||||
case GOLD_LEGGINGS:
|
||||
case IRON_LEGGINGS:
|
||||
case DIAMOND_LEGGINGS:
|
||||
if (!player.isSneaking())
|
||||
slot = 3;
|
||||
break;
|
||||
case LEATHER_BOOTS:
|
||||
case CHAINMAIL_BOOTS:
|
||||
case GOLD_BOOTS:
|
||||
case IRON_BOOTS:
|
||||
case DIAMOND_BOOTS:
|
||||
if (!player.isSneaking())
|
||||
slot = 4;
|
||||
break;
|
||||
case AIR:
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (trait.get(i) != null && trait.get(i).getType() != Material.AIR) {
|
||||
player.getWorld().dropItemNaturally(npc.getBukkitEntity().getLocation(), trait.get(i));
|
||||
trait.set(i, null);
|
||||
}
|
||||
}
|
||||
Messaging.send(player, "<e>" + npc.getName() + " <a>had all of its items removed.");
|
||||
}
|
||||
// Now edit the equipment based on the slot
|
||||
if (trait.get(slot) != null && trait.get(slot).getType() != Material.AIR)
|
||||
player.getWorld().dropItemNaturally(npc.getBukkitEntity().getLocation(), trait.get(slot));
|
||||
CitizensNPC handle = (CitizensNPC) npc;
|
||||
if (!(handle instanceof Equipable))
|
||||
return;
|
||||
|
||||
ItemStack set = hand;
|
||||
if (set != null && set.getType() != Material.AIR) {
|
||||
if (hand.getAmount() > 1)
|
||||
hand.setAmount(hand.getAmount() - 1);
|
||||
else
|
||||
hand = null;
|
||||
player.setItemInHand(hand);
|
||||
set.setAmount(1);
|
||||
}
|
||||
trait.set(slot, set);
|
||||
((Equipable) handle).equip(event.getPlayer());
|
||||
}
|
||||
}
|
@ -1,15 +1,22 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.trait.trait.Equipment;
|
||||
import net.citizensnpcs.editor.Equipable;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
|
||||
import net.minecraft.server.EntityEnderman;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Enderman;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
public class CitizensEndermanNPC extends CitizensMobNPC {
|
||||
public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable {
|
||||
|
||||
public CitizensEndermanNPC(CitizensNPCManager manager, int id, String name) {
|
||||
super(manager, id, name, EntityEndermanNPC.class);
|
||||
@ -20,6 +27,37 @@ public class CitizensEndermanNPC extends CitizensMobNPC {
|
||||
return (Enderman) getHandle().getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equip(Player equipper) {
|
||||
ItemStack hand = equipper.getItemInHand();
|
||||
if (!hand.getType().isBlock()) {
|
||||
Messaging.sendError(equipper, "Invalid block!");
|
||||
return;
|
||||
}
|
||||
|
||||
MaterialData carried = getBukkitEntity().getCarriedMaterial();
|
||||
if (carried.getItemType() == Material.AIR) {
|
||||
if (hand.getType() == Material.AIR) {
|
||||
Messaging.sendError(equipper, "Invalid block!");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(), carried.toItemStack(1));
|
||||
getBukkitEntity().setCarriedMaterial(hand.getData());
|
||||
}
|
||||
|
||||
ItemStack set = hand;
|
||||
if (set.getType() != Material.AIR) {
|
||||
if (hand.getAmount() > 1)
|
||||
hand.setAmount(hand.getAmount() - 1);
|
||||
else
|
||||
hand = null;
|
||||
equipper.setItemInHand(hand);
|
||||
set.setAmount(1);
|
||||
}
|
||||
getTrait(Equipment.class).set(0, set);
|
||||
}
|
||||
|
||||
public static class EntityEndermanNPC extends EntityEnderman {
|
||||
|
||||
public EntityEndermanNPC(World world) {
|
||||
|
@ -1,19 +1,24 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.trait.trait.Equipment;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.editor.Equipable;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
import net.minecraft.server.EntityLiving;
|
||||
import net.minecraft.server.ItemInWorldManager;
|
||||
import net.minecraft.server.WorldServer;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class CitizensHumanNPC extends CitizensNPC {
|
||||
public class CitizensHumanNPC extends CitizensNPC implements Equipable {
|
||||
|
||||
public CitizensHumanNPC(CitizensNPCManager manager, int id, String name) {
|
||||
super(manager, id, name);
|
||||
@ -22,8 +27,8 @@ public class CitizensHumanNPC extends CitizensNPC {
|
||||
@Override
|
||||
protected EntityLiving createHandle(Location loc) {
|
||||
WorldServer ws = ((CraftWorld) loc.getWorld()).getHandle();
|
||||
EntityHumanNPC handle = new EntityHumanNPC(ws.getServer().getServer(), ws,
|
||||
StringHelper.parseColors(getFullName()), new ItemInWorldManager(ws));
|
||||
EntityHumanNPC handle = new EntityHumanNPC(ws.getServer().getServer(), ws, StringHelper
|
||||
.parseColors(getFullName()), new ItemInWorldManager(ws));
|
||||
handle.removeFromPlayerMap(getFullName());
|
||||
handle.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
|
||||
return handle;
|
||||
@ -59,4 +64,70 @@ public class CitizensHumanNPC extends CitizensNPC {
|
||||
mcEntity.move(0, -0.1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equip(Player equipper) {
|
||||
ItemStack hand = equipper.getItemInHand();
|
||||
Equipment trait = getTrait(Equipment.class);
|
||||
int slot = 0;
|
||||
// First, determine the slot to edit
|
||||
switch (hand.getType()) {
|
||||
case PUMPKIN:
|
||||
case JACK_O_LANTERN:
|
||||
case LEATHER_HELMET:
|
||||
case CHAINMAIL_HELMET:
|
||||
case GOLD_HELMET:
|
||||
case IRON_HELMET:
|
||||
case DIAMOND_HELMET:
|
||||
if (!equipper.isSneaking())
|
||||
slot = 1;
|
||||
break;
|
||||
case LEATHER_CHESTPLATE:
|
||||
case CHAINMAIL_CHESTPLATE:
|
||||
case GOLD_CHESTPLATE:
|
||||
case IRON_CHESTPLATE:
|
||||
case DIAMOND_CHESTPLATE:
|
||||
if (!equipper.isSneaking())
|
||||
slot = 2;
|
||||
break;
|
||||
case LEATHER_LEGGINGS:
|
||||
case CHAINMAIL_LEGGINGS:
|
||||
case GOLD_LEGGINGS:
|
||||
case IRON_LEGGINGS:
|
||||
case DIAMOND_LEGGINGS:
|
||||
if (!equipper.isSneaking())
|
||||
slot = 3;
|
||||
break;
|
||||
case LEATHER_BOOTS:
|
||||
case CHAINMAIL_BOOTS:
|
||||
case GOLD_BOOTS:
|
||||
case IRON_BOOTS:
|
||||
case DIAMOND_BOOTS:
|
||||
if (!equipper.isSneaking())
|
||||
slot = 4;
|
||||
break;
|
||||
case AIR:
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (trait.get(i) != null && trait.get(i).getType() != Material.AIR) {
|
||||
equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(), trait.get(i));
|
||||
trait.set(i, null);
|
||||
}
|
||||
}
|
||||
Messaging.send(equipper, "<e>" + getName() + " <a>had all of its items removed.");
|
||||
}
|
||||
// Now edit the equipment based on the slot
|
||||
if (trait.get(slot) != null && trait.get(slot).getType() != Material.AIR)
|
||||
equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(), trait.get(slot));
|
||||
|
||||
ItemStack set = hand;
|
||||
if (set != null && set.getType() != Material.AIR) {
|
||||
if (hand.getAmount() > 1)
|
||||
hand.setAmount(hand.getAmount() - 1);
|
||||
else
|
||||
hand = null;
|
||||
equipper.setItemInHand(hand);
|
||||
set.setAmount(1);
|
||||
}
|
||||
trait.set(slot, set);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user