mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-30 22:53:24 +01:00
Add ability to edit sheep via the equipment editor. This address CITIZENS-5.
This commit is contained in:
parent
8e955deff0
commit
8683d6b033
@ -10,12 +10,12 @@ import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public abstract class Editor implements Listener {
|
||||
private static final Map<String, Editor> editing = new HashMap<String, Editor>();
|
||||
|
||||
public abstract void begin();
|
||||
|
||||
public abstract void end();
|
||||
|
||||
private static final Map<String, Editor> editing = new HashMap<String, Editor>();
|
||||
|
||||
private static void enter(Player player, Editor editor) {
|
||||
editor.begin();
|
||||
player.getServer().getPluginManager()
|
||||
|
@ -25,9 +25,6 @@ public class EquipmentEditor extends Editor {
|
||||
public void begin() {
|
||||
Messaging.send(player, "<b>Entered the equipment editor!");
|
||||
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,10 +49,9 @@ public abstract class CitizensNPC extends AbstractNPC {
|
||||
if (traits.containsKey(trait.getClass()))
|
||||
runnables.remove(traits.get(trait.getClass()));
|
||||
}
|
||||
if (trait instanceof Listener) {
|
||||
Bukkit.getPluginManager().registerEvents((Listener) trait, null);
|
||||
if (trait instanceof Listener)
|
||||
// TODO: insert plugin instance somehow
|
||||
}
|
||||
Bukkit.getPluginManager().registerEvents((Listener) trait, Bukkit.getPluginManager().getPlugin("Citizens"));
|
||||
|
||||
traits.put(trait.getClass(), trait);
|
||||
}
|
||||
|
@ -17,7 +17,9 @@ import net.citizensnpcs.api.trait.trait.Spawned;
|
||||
import net.citizensnpcs.trait.CurrentLocation;
|
||||
import net.citizensnpcs.trait.LookClose;
|
||||
import net.citizensnpcs.trait.Powered;
|
||||
import net.citizensnpcs.trait.Sheared;
|
||||
import net.citizensnpcs.trait.VillagerProfession;
|
||||
import net.citizensnpcs.trait.WoolColor;
|
||||
import net.citizensnpcs.trait.text.Text;
|
||||
import net.citizensnpcs.trait.waypoint.Waypoints;
|
||||
|
||||
@ -27,17 +29,19 @@ public class CitizensTraitManager implements TraitManager {
|
||||
|
||||
public CitizensTraitManager() {
|
||||
// Register Citizens traits
|
||||
registerTrait(new TraitFactory(CurrentLocation.class).withName("location"));
|
||||
registerTrait(new TraitFactory(Equipment.class).withName("equipment"));
|
||||
registerTrait(new TraitFactory(Inventory.class).withName("inventory"));
|
||||
registerTrait(new TraitFactory(LookClose.class).withName("look-close"));
|
||||
registerTrait(new TraitFactory(MobType.class).withName("type"));
|
||||
registerTrait(new TraitFactory(Owner.class).withName("owner"));
|
||||
registerTrait(new TraitFactory(Powered.class).withName("powered"));
|
||||
registerTrait(new TraitFactory(Sheared.class).withName("sheared"));
|
||||
registerTrait(new TraitFactory(Spawned.class).withName("spawned"));
|
||||
registerTrait(new TraitFactory(CurrentLocation.class).withName("location"));
|
||||
registerTrait(new TraitFactory(Text.class).withName("text"));
|
||||
registerTrait(new TraitFactory(VillagerProfession.class).withName("profession"));
|
||||
registerTrait(new TraitFactory(Waypoints.class).withName("waypoints"));
|
||||
registerTrait(new TraitFactory(WoolColor.class).withName("wool-color"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,7 +26,7 @@ public class CitizensBlazeNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntityBlazeNPC(World world, NPC npc) {
|
||||
|
@ -26,7 +26,7 @@ public class CitizensCaveSpiderNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntityCaveSpiderNPC(World world, NPC npc) {
|
||||
|
@ -26,7 +26,7 @@ public class CitizensChickenNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntityChickenNPC(World world, NPC npc) {
|
||||
|
@ -26,7 +26,7 @@ public class CitizensCowNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntityCowNPC(World world, NPC npc) {
|
||||
|
@ -27,7 +27,7 @@ public class CitizensCreeperNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntityCreeperNPC(World world, NPC npc) {
|
||||
|
@ -26,7 +26,7 @@ public class CitizensEnderDragonNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntityEnderDragonNPC(World world, NPC npc) {
|
||||
|
@ -64,7 +64,7 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntityEndermanNPC(World world, NPC npc) {
|
||||
|
@ -26,7 +26,7 @@ public class CitizensGhastNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntityGhastNPC(World world, NPC npc) {
|
||||
|
@ -26,7 +26,7 @@ public class CitizensGiantNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntityGiantNPC(World world, NPC npc) {
|
||||
|
@ -26,7 +26,7 @@ public class CitizensIronGolemNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntityIronGolemNPC(World world, NPC npc) {
|
||||
|
@ -26,7 +26,7 @@ public class CitizensMagmaCubeNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntityMagmaCubeNPC(World world, NPC npc) {
|
||||
|
@ -26,7 +26,7 @@ public class CitizensMushroomCowNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntityMushroomCowNPC(World world, NPC npc) {
|
||||
|
@ -26,7 +26,7 @@ public class CitizensOcelotNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntityOcelotNPC(World world, NPC npc) {
|
||||
|
@ -27,7 +27,7 @@ public class CitizensPigNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntityPigNPC(World world, NPC npc) {
|
||||
|
@ -26,7 +26,7 @@ public class CitizensPigZombieNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntityPigZombieNPC(World world, NPC npc) {
|
||||
|
@ -1,16 +1,25 @@
|
||||
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.Sheared;
|
||||
import net.citizensnpcs.trait.WoolColor;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
import net.minecraft.server.EntitySheep;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Sheep;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class CitizensSheepNPC extends CitizensMobNPC {
|
||||
public class CitizensSheepNPC extends CitizensMobNPC implements Equipable {
|
||||
|
||||
public CitizensSheepNPC(CitizensNPCManager manager, int id, String name) {
|
||||
super(manager, id, name, EntitySheepNPC.class);
|
||||
@ -21,12 +30,40 @@ public class CitizensSheepNPC extends CitizensMobNPC {
|
||||
return (Sheep) getHandle().getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equip(Player equipper) {
|
||||
ItemStack hand = equipper.getItemInHand();
|
||||
if (hand.getType() == Material.SHEARS) {
|
||||
Messaging.send(equipper, StringHelper.wrap(getName()) + " is "
|
||||
+ (getTrait(Sheared.class).toggle() ? "now" : "no longer") + " sheared.");
|
||||
} else if (hand.getType() == Material.INK_SACK) {
|
||||
if (getBukkitEntity().getColor() == DyeColor.getByData((byte) (15 - hand.getData().getData())))
|
||||
return;
|
||||
|
||||
DyeColor color = DyeColor.getByData((byte) (15 - hand.getData().getData()));
|
||||
getTrait(WoolColor.class).setColor(color);
|
||||
Messaging.send(
|
||||
equipper,
|
||||
StringHelper.wrap(getName()) + " is now "
|
||||
+ StringHelper.wrap(color.name().toLowerCase().replace("_", " ")) + ".");
|
||||
|
||||
if (hand.getAmount() > 1)
|
||||
hand.setAmount(hand.getAmount() - 1);
|
||||
else
|
||||
hand = null;
|
||||
equipper.setItemInHand(hand);
|
||||
} else {
|
||||
getTrait(WoolColor.class).setColor(DyeColor.WHITE);
|
||||
Messaging.send(equipper, StringHelper.wrap(getName()) + " is now " + StringHelper.wrap("white") + ".");
|
||||
}
|
||||
}
|
||||
|
||||
public static class EntitySheepNPC extends EntitySheep implements NPCHandle {
|
||||
private final NPC npc;
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntitySheepNPC(World world, NPC npc) {
|
||||
|
@ -26,7 +26,7 @@ public class CitizensSilverfishNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntitySilverfishNPC(World world, NPC npc) {
|
||||
|
@ -26,7 +26,7 @@ public class CitizensSkeletonNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntitySkeletonNPC(World world, NPC npc) {
|
||||
|
@ -26,7 +26,7 @@ public class CitizensSlimeNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntitySlimeNPC(World world, NPC npc) {
|
||||
|
@ -26,7 +26,7 @@ public class CitizensSnowmanNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntitySnowmanNPC(World world, NPC npc) {
|
||||
|
@ -26,7 +26,7 @@ public class CitizensSpiderNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntitySpiderNPC(World world, NPC npc) {
|
||||
|
@ -26,7 +26,7 @@ public class CitizensSquidNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntitySquidNPC(World world, NPC npc) {
|
||||
|
@ -26,7 +26,7 @@ public class CitizensVillagerNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntityVillagerNPC(World world, NPC npc) {
|
||||
|
@ -26,7 +26,7 @@ public class CitizensWolfNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntityWolfNPC(World world, NPC npc) {
|
||||
|
@ -26,7 +26,7 @@ public class CitizensZombieNPC extends CitizensMobNPC {
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return this.npc;
|
||||
return npc;
|
||||
}
|
||||
|
||||
public EntityZombieNPC(World world, NPC npc) {
|
||||
|
@ -33,8 +33,7 @@ public class Powered extends Trait implements Toggleable {
|
||||
@Override
|
||||
public boolean toggle() {
|
||||
powered = !powered;
|
||||
if (npc.getBukkitEntity() instanceof Creeper)
|
||||
((Creeper) npc.getBukkitEntity()).setPowered(powered);
|
||||
((Creeper) npc.getBukkitEntity()).setPowered(powered);
|
||||
return powered;
|
||||
}
|
||||
|
||||
|
58
src/main/java/net/citizensnpcs/trait/Sheared.java
Normal file
58
src/main/java/net/citizensnpcs/trait/Sheared.java
Normal file
@ -0,0 +1,58 @@
|
||||
package net.citizensnpcs.trait;
|
||||
|
||||
import org.bukkit.entity.Sheep;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerShearEntityEvent;
|
||||
|
||||
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 Sheared extends Trait implements Toggleable, Listener {
|
||||
private boolean sheared;
|
||||
private final NPC npc;
|
||||
|
||||
public Sheared(NPC npc) {
|
||||
this.npc = npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(DataKey key) throws NPCLoadException {
|
||||
sheared = key.getBoolean("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(DataKey key) {
|
||||
key.setBoolean("", sheared);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNPCSpawn() {
|
||||
// TODO Get rid of instanceof's, add
|
||||
// TraitFactory.withTypes(EntityType...) or similar
|
||||
if (npc.getBukkitEntity() instanceof Sheep)
|
||||
((Sheep) npc.getBukkitEntity()).setSheared(sheared);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean toggle() {
|
||||
sheared = !sheared;
|
||||
((Sheep) npc.getBukkitEntity()).setSheared(sheared);
|
||||
return sheared;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerShearEntityEvent(PlayerShearEntityEvent event) {
|
||||
// TODO: Complete trait/plugin system
|
||||
if (CitizensAPI.getNPCManager().isNPC(event.getEntity()))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Sheared{" + sheared + "}";
|
||||
}
|
||||
}
|
59
src/main/java/net/citizensnpcs/trait/WoolColor.java
Normal file
59
src/main/java/net/citizensnpcs/trait/WoolColor.java
Normal file
@ -0,0 +1,59 @@
|
||||
package net.citizensnpcs.trait;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.entity.Sheep;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.SheepDyeWoolEvent;
|
||||
|
||||
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 WoolColor extends Trait implements Listener {
|
||||
private DyeColor color = DyeColor.WHITE;
|
||||
private final NPC npc;
|
||||
|
||||
public WoolColor(NPC npc) {
|
||||
this.npc = npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(DataKey key) throws NPCLoadException {
|
||||
try {
|
||||
color = DyeColor.valueOf(key.getString(""));
|
||||
} catch (Exception ex) {
|
||||
color = DyeColor.WHITE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNPCSpawn() {
|
||||
if (npc.getBukkitEntity() instanceof Sheep)
|
||||
((Sheep) npc.getBukkitEntity()).setColor(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(DataKey key) {
|
||||
key.setString("", color.name());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onSheepDyeWool(SheepDyeWoolEvent event) {
|
||||
// TODO: Complete trait/plugin system
|
||||
if (CitizensAPI.getNPCManager().isNPC(event.getEntity()))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public void setColor(DyeColor color) {
|
||||
this.color = color;
|
||||
((Sheep) npc.getBukkitEntity()).setColor(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WoolColor{" + color.name() + "}";
|
||||
}
|
||||
}
|
@ -71,10 +71,6 @@ public class StringHelper {
|
||||
return ChatColor.YELLOW + string.toString() + ChatColor.GREEN;
|
||||
}
|
||||
|
||||
public static String wrap(Object string, ChatColor after) {
|
||||
return ChatColor.YELLOW + string.toString() + after;
|
||||
}
|
||||
|
||||
public static String wrapHeader(Object string) {
|
||||
return "<a>=====[ " + string.toString() + "<a> ]=====";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user