2013-07-11 06:29:46 +02:00
|
|
|
package net.citizensnpcs.trait;
|
|
|
|
|
|
|
|
import org.bukkit.entity.Horse;
|
|
|
|
import org.bukkit.entity.Horse.Color;
|
|
|
|
import org.bukkit.entity.Horse.Style;
|
2013-07-30 05:15:51 +02:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2013-07-11 06:29:46 +02:00
|
|
|
|
2016-01-07 15:25:09 +01:00
|
|
|
import net.citizensnpcs.api.persistence.Persist;
|
|
|
|
import net.citizensnpcs.api.trait.Trait;
|
|
|
|
import net.citizensnpcs.api.trait.TraitName;
|
|
|
|
|
|
|
|
@TraitName("horsemodifiers")
|
2013-07-11 06:29:46 +02:00
|
|
|
public class HorseModifiers extends Trait {
|
2013-07-30 05:15:51 +02:00
|
|
|
@Persist("armor")
|
|
|
|
private ItemStack armor = null;
|
2013-07-11 06:29:46 +02:00
|
|
|
@Persist("carryingChest")
|
|
|
|
private boolean carryingChest;
|
|
|
|
@Persist("color")
|
|
|
|
private Color color = Color.CREAMY;
|
2013-07-30 05:15:51 +02:00
|
|
|
@Persist("saddle")
|
|
|
|
private ItemStack saddle = null;
|
2013-07-11 06:29:46 +02:00
|
|
|
@Persist("style")
|
|
|
|
private Style style = Style.NONE;
|
|
|
|
|
|
|
|
public HorseModifiers() {
|
|
|
|
super("horsemodifiers");
|
|
|
|
}
|
|
|
|
|
2016-04-05 19:32:38 +02:00
|
|
|
public ItemStack getArmor() {
|
|
|
|
return armor;
|
|
|
|
}
|
|
|
|
|
2013-07-11 06:29:46 +02:00
|
|
|
public Color getColor() {
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2016-04-05 19:32:38 +02:00
|
|
|
public ItemStack getSaddle() {
|
|
|
|
return saddle;
|
|
|
|
}
|
|
|
|
|
2013-07-11 06:29:46 +02:00
|
|
|
public Style getStyle() {
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSpawn() {
|
|
|
|
updateModifiers();
|
|
|
|
}
|
|
|
|
|
2013-07-30 05:15:51 +02:00
|
|
|
@Override
|
|
|
|
public void run() {
|
2013-11-05 12:29:18 +01:00
|
|
|
if (npc.getEntity() instanceof Horse) {
|
|
|
|
Horse horse = (Horse) npc.getEntity();
|
2013-07-30 05:15:51 +02:00
|
|
|
saddle = horse.getInventory().getSaddle();
|
|
|
|
armor = horse.getInventory().getArmor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-05 19:32:38 +02:00
|
|
|
public void setArmor(ItemStack armor) {
|
|
|
|
this.armor = armor;
|
|
|
|
}
|
|
|
|
|
2013-07-11 06:29:46 +02:00
|
|
|
public void setCarryingChest(boolean carryingChest) {
|
|
|
|
this.carryingChest = carryingChest;
|
|
|
|
updateModifiers();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setColor(Horse.Color color) {
|
|
|
|
this.color = color;
|
|
|
|
updateModifiers();
|
|
|
|
}
|
|
|
|
|
2016-04-05 19:32:38 +02:00
|
|
|
public void setSaddle(ItemStack saddle) {
|
|
|
|
this.saddle = saddle;
|
|
|
|
}
|
|
|
|
|
2013-07-11 06:29:46 +02:00
|
|
|
public void setStyle(Horse.Style style) {
|
|
|
|
this.style = style;
|
|
|
|
updateModifiers();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateModifiers() {
|
2013-11-05 12:29:18 +01:00
|
|
|
if (npc.getEntity() instanceof Horse) {
|
|
|
|
Horse horse = (Horse) npc.getEntity();
|
2013-07-11 06:29:46 +02:00
|
|
|
horse.setColor(color);
|
|
|
|
horse.setStyle(style);
|
2013-07-30 05:15:51 +02:00
|
|
|
horse.getInventory().setArmor(armor);
|
|
|
|
horse.getInventory().setSaddle(saddle);
|
2013-07-11 06:29:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|