mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-24 11:38:26 +01:00
Added ability to equip Pig NPCs with saddles. This addresses CITIZENS-6.
This commit is contained in:
parent
114c83ecdd
commit
d042ff8b3b
@ -23,6 +23,7 @@ import net.citizensnpcs.trait.Age;
|
||||
import net.citizensnpcs.trait.CurrentLocation;
|
||||
import net.citizensnpcs.trait.LookClose;
|
||||
import net.citizensnpcs.trait.Powered;
|
||||
import net.citizensnpcs.trait.Saddle;
|
||||
import net.citizensnpcs.trait.VillagerProfession;
|
||||
import net.citizensnpcs.trait.text.Text;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
@ -125,6 +126,7 @@ public class NPCCommands {
|
||||
npc.getTrait(MobType.class).setType(type.toString());
|
||||
npc.addTrait(traitManager.getTrait(LookClose.class, npc));
|
||||
npc.addTrait(traitManager.getTrait(Text.class, npc));
|
||||
npc.addTrait(traitManager.getTrait(Saddle.class, npc));
|
||||
|
||||
npc.spawn(player.getLocation());
|
||||
|
||||
|
@ -18,6 +18,7 @@ import net.citizensnpcs.trait.Age;
|
||||
import net.citizensnpcs.trait.CurrentLocation;
|
||||
import net.citizensnpcs.trait.LookClose;
|
||||
import net.citizensnpcs.trait.Powered;
|
||||
import net.citizensnpcs.trait.Saddle;
|
||||
import net.citizensnpcs.trait.Sheared;
|
||||
import net.citizensnpcs.trait.VillagerProfession;
|
||||
import net.citizensnpcs.trait.WoolColor;
|
||||
@ -38,6 +39,7 @@ public class CitizensTraitManager implements TraitManager {
|
||||
registerTrait(new TraitFactory(MobType.class).withName("type"));
|
||||
registerTrait(new TraitFactory(Owner.class).withName("owner"));
|
||||
registerTrait(new TraitFactory(Powered.class).withName("powered"));
|
||||
registerTrait(new TraitFactory(Saddle.class).withName("saddle"));
|
||||
registerTrait(new TraitFactory(Sheared.class).withName("sheared"));
|
||||
registerTrait(new TraitFactory(Spawned.class).withName("spawned"));
|
||||
registerTrait(new TraitFactory(Text.class).withName("text"));
|
||||
|
@ -1,17 +1,24 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.editor.Equipable;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.citizensnpcs.trait.Saddle;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
import net.minecraft.server.EntityPig;
|
||||
import net.minecraft.server.EntityWeatherLighting;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Pig;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class CitizensPigNPC extends CitizensMobNPC {
|
||||
public class CitizensPigNPC extends CitizensMobNPC implements Equipable {
|
||||
|
||||
public CitizensPigNPC(CitizensNPCManager manager, int id, String name) {
|
||||
super(manager, id, name, EntityPigNPC.class);
|
||||
@ -22,6 +29,25 @@ public class CitizensPigNPC extends CitizensMobNPC {
|
||||
return (Pig) getHandle().getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equip(Player equipper) {
|
||||
ItemStack hand = equipper.getItemInHand();
|
||||
if (hand.getType() == Material.SADDLE) {
|
||||
if (!getBukkitEntity().hasSaddle()) {
|
||||
getTrait(Saddle.class).toggle();
|
||||
equipper.setItemInHand(null);
|
||||
Messaging.send(equipper, StringHelper.wrap(getName()) + " is now saddled.");
|
||||
}
|
||||
} else {
|
||||
if (getBukkitEntity().hasSaddle()) {
|
||||
equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(),
|
||||
new ItemStack(Material.SADDLE, 1));
|
||||
getTrait(Saddle.class).toggle();
|
||||
Messaging.send(equipper, StringHelper.wrap(getName()) + " is no longer saddled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class EntityPigNPC extends EntityPig implements NPCHandle {
|
||||
private final NPC npc;
|
||||
|
||||
|
56
src/main/java/net/citizensnpcs/trait/Saddle.java
Normal file
56
src/main/java/net/citizensnpcs/trait/Saddle.java
Normal file
@ -0,0 +1,56 @@
|
||||
package net.citizensnpcs.trait;
|
||||
|
||||
import org.bukkit.entity.Pig;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
|
||||
public class Saddle extends Trait implements Toggleable, Listener {
|
||||
private boolean saddle;
|
||||
private final NPC npc;
|
||||
|
||||
public Saddle(NPC npc) {
|
||||
this.npc = npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(DataKey key) throws NPCLoadException {
|
||||
saddle = key.getBoolean("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(DataKey key) {
|
||||
key.setBoolean("", saddle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNPCSpawn() {
|
||||
if (npc.getBukkitEntity() instanceof Pig)
|
||||
((Pig) npc.getBukkitEntity()).setSaddle(saddle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean toggle() {
|
||||
saddle = !saddle;
|
||||
((Pig) npc.getBukkitEntity()).setSaddle(saddle);
|
||||
return saddle;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
// TODO: Complete trait/plugin system
|
||||
if (CitizensAPI.getNPCManager().isNPC(event.getRightClicked()))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Saddle{" + saddle + "}";
|
||||
}
|
||||
}
|
@ -38,6 +38,7 @@ public class VillagerProfession extends Trait {
|
||||
|
||||
public void setProfession(Profession profession) {
|
||||
this.profession = profession;
|
||||
((Villager) npc.getBukkitEntity()).setProfession(profession);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user