2019-12-11 17:13:54 +01:00
|
|
|
package net.citizensnpcs.trait.versioned;
|
2019-04-24 15:01:22 +02:00
|
|
|
|
2019-05-07 14:02:14 +02:00
|
|
|
import org.bukkit.DyeColor;
|
2022-07-09 19:53:34 +02:00
|
|
|
import org.bukkit.command.CommandSender;
|
2019-04-24 15:01:22 +02:00
|
|
|
import org.bukkit.entity.Cat;
|
2022-07-09 19:53:34 +02:00
|
|
|
import org.bukkit.entity.EntityType;
|
2020-01-11 05:41:46 +01:00
|
|
|
import org.bukkit.entity.Ocelot.Type;
|
2019-04-24 15:01:22 +02:00
|
|
|
|
2022-07-09 19:53:34 +02:00
|
|
|
import net.citizensnpcs.api.command.Command;
|
|
|
|
import net.citizensnpcs.api.command.CommandContext;
|
2022-09-06 20:11:07 +02:00
|
|
|
import net.citizensnpcs.api.command.Flag;
|
2022-07-09 19:53:34 +02:00
|
|
|
import net.citizensnpcs.api.command.Requirements;
|
|
|
|
import net.citizensnpcs.api.command.exception.CommandException;
|
|
|
|
import net.citizensnpcs.api.command.exception.CommandUsageException;
|
|
|
|
import net.citizensnpcs.api.npc.NPC;
|
2019-04-24 15:01:22 +02:00
|
|
|
import net.citizensnpcs.api.persistence.Persist;
|
|
|
|
import net.citizensnpcs.api.trait.Trait;
|
|
|
|
import net.citizensnpcs.api.trait.TraitName;
|
2022-07-09 19:53:34 +02:00
|
|
|
import net.citizensnpcs.api.util.Messaging;
|
|
|
|
import net.citizensnpcs.util.Messages;
|
2019-12-11 17:13:54 +01:00
|
|
|
import net.citizensnpcs.util.NMS;
|
2022-07-09 19:53:34 +02:00
|
|
|
import net.citizensnpcs.util.Util;
|
2019-04-24 15:01:22 +02:00
|
|
|
|
|
|
|
@TraitName("cattrait")
|
|
|
|
public class CatTrait extends Trait {
|
2020-02-14 15:48:40 +01:00
|
|
|
@Persist
|
|
|
|
private DyeColor collarColor = null;
|
|
|
|
@Persist
|
|
|
|
private boolean lying = false;
|
|
|
|
@Persist
|
|
|
|
private boolean sitting = false;
|
|
|
|
@Persist
|
|
|
|
private Cat.Type type = Cat.Type.BLACK;
|
2020-01-11 05:41:46 +01:00
|
|
|
|
2020-02-14 15:48:40 +01:00
|
|
|
public CatTrait() {
|
|
|
|
super("cattrait");
|
|
|
|
}
|
2020-01-11 05:41:46 +01:00
|
|
|
|
2020-02-14 15:48:40 +01:00
|
|
|
public boolean isLyingDown() {
|
|
|
|
return lying;
|
|
|
|
}
|
2020-01-11 05:41:46 +01:00
|
|
|
|
2020-02-14 15:48:40 +01:00
|
|
|
@Override
|
|
|
|
public void run() {
|
2020-05-07 10:29:45 +02:00
|
|
|
if (!(npc.getEntity() instanceof Cat))
|
|
|
|
return;
|
|
|
|
Cat cat = (Cat) npc.getEntity();
|
|
|
|
cat.setSitting(sitting);
|
|
|
|
cat.setCatType(type);
|
|
|
|
if (collarColor != null) {
|
|
|
|
cat.setCollarColor(collarColor);
|
2020-02-14 15:48:40 +01:00
|
|
|
}
|
2020-05-07 10:29:45 +02:00
|
|
|
NMS.setLyingDown(cat, lying);
|
2020-02-14 15:48:40 +01:00
|
|
|
}
|
2020-01-11 05:41:46 +01:00
|
|
|
|
2020-02-14 15:48:40 +01:00
|
|
|
public void setCollarColor(DyeColor color) {
|
2023-11-05 13:58:37 +01:00
|
|
|
collarColor = color;
|
2020-02-14 15:48:40 +01:00
|
|
|
}
|
2020-01-11 05:41:46 +01:00
|
|
|
|
2020-02-14 15:48:40 +01:00
|
|
|
public void setLyingDown(boolean lying) {
|
|
|
|
this.lying = lying;
|
|
|
|
}
|
2020-01-11 05:41:46 +01:00
|
|
|
|
2020-02-14 15:48:40 +01:00
|
|
|
public void setSitting(boolean sitting) {
|
|
|
|
this.sitting = sitting;
|
|
|
|
}
|
2020-01-11 05:41:46 +01:00
|
|
|
|
2020-02-14 15:48:40 +01:00
|
|
|
public void setType(Cat.Type type) {
|
2023-06-14 17:45:36 +02:00
|
|
|
if (type == null) {
|
|
|
|
type = Cat.Type.BLACK;
|
|
|
|
}
|
2020-02-14 15:48:40 +01:00
|
|
|
this.type = type;
|
|
|
|
}
|
2020-01-11 05:41:46 +01:00
|
|
|
|
2020-02-14 15:48:40 +01:00
|
|
|
public void setType(Type type2) {
|
2023-06-14 17:45:36 +02:00
|
|
|
if (type2 == null) {
|
2023-11-05 13:58:37 +01:00
|
|
|
type = Cat.Type.BLACK;
|
2023-06-14 17:45:36 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-02-14 15:48:40 +01:00
|
|
|
switch (type2) {
|
|
|
|
case WILD_OCELOT:
|
2023-11-05 13:58:37 +01:00
|
|
|
type = Cat.Type.CALICO;
|
2020-02-14 15:48:40 +01:00
|
|
|
break;
|
|
|
|
case BLACK_CAT:
|
2023-11-05 13:58:37 +01:00
|
|
|
type = Cat.Type.BLACK;
|
2020-02-14 15:48:40 +01:00
|
|
|
break;
|
|
|
|
case RED_CAT:
|
2023-11-05 13:58:37 +01:00
|
|
|
type = Cat.Type.RED;
|
2020-02-14 15:48:40 +01:00
|
|
|
break;
|
|
|
|
case SIAMESE_CAT:
|
2023-11-05 13:58:37 +01:00
|
|
|
type = Cat.Type.SIAMESE;
|
2020-02-14 15:48:40 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-07-09 19:53:34 +02:00
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "npc" },
|
|
|
|
usage = "cat (-s/-n/-l) --type type --ccolor collar color",
|
2024-02-29 18:03:30 +01:00
|
|
|
desc = "",
|
2022-07-09 19:53:34 +02:00
|
|
|
modifiers = { "cat" },
|
|
|
|
min = 1,
|
|
|
|
max = 1,
|
|
|
|
flags = "snl",
|
|
|
|
permission = "citizens.npc.cat")
|
|
|
|
@Requirements(selected = true, ownership = true, types = EntityType.CAT)
|
2022-09-06 20:11:07 +02:00
|
|
|
public static void cat(CommandContext args, CommandSender sender, NPC npc, @Flag("ccolor") DyeColor ccolor,
|
|
|
|
@Flag("type") Cat.Type type) throws CommandException {
|
2022-07-09 19:53:34 +02:00
|
|
|
CatTrait trait = npc.getOrAddTrait(CatTrait.class);
|
|
|
|
String output = "";
|
|
|
|
if (args.hasValueFlag("type")) {
|
2023-11-05 13:58:37 +01:00
|
|
|
if (type == null)
|
2022-07-09 19:53:34 +02:00
|
|
|
throw new CommandUsageException(Messages.INVALID_CAT_TYPE, Util.listValuesPretty(Cat.Type.values()));
|
|
|
|
trait.setType(type);
|
|
|
|
output += ' ' + Messaging.tr(Messages.CAT_TYPE_SET, args.getFlag("type"));
|
|
|
|
}
|
|
|
|
if (args.hasValueFlag("ccolor")) {
|
2023-11-05 13:58:37 +01:00
|
|
|
if (ccolor == null)
|
2022-07-09 19:53:34 +02:00
|
|
|
throw new CommandUsageException(Messages.INVALID_CAT_COLLAR_COLOR,
|
|
|
|
Util.listValuesPretty(DyeColor.values()));
|
2022-09-06 20:11:07 +02:00
|
|
|
trait.setCollarColor(ccolor);
|
2022-07-09 19:53:34 +02:00
|
|
|
output += ' ' + Messaging.tr(Messages.CAT_COLLAR_COLOR_SET, args.getFlag("ccolor"));
|
|
|
|
}
|
|
|
|
if (args.hasFlag('s')) {
|
|
|
|
trait.setSitting(true);
|
|
|
|
output += ' ' + Messaging.tr(Messages.CAT_STARTED_SITTING, npc.getName());
|
|
|
|
} else if (args.hasFlag('n')) {
|
|
|
|
trait.setSitting(false);
|
|
|
|
output += ' ' + Messaging.tr(Messages.CAT_STOPPED_SITTING, npc.getName());
|
|
|
|
}
|
|
|
|
if (args.hasFlag('l')) {
|
|
|
|
trait.setLyingDown(!trait.isLyingDown());
|
|
|
|
output += ' ' + Messaging.tr(trait.isLyingDown() ? Messages.CAT_STARTED_LYING : Messages.CAT_STOPPED_LYING,
|
|
|
|
npc.getName());
|
|
|
|
}
|
|
|
|
if (!output.isEmpty()) {
|
|
|
|
Messaging.send(sender, output.trim());
|
2023-11-05 13:58:37 +01:00
|
|
|
} else
|
2022-07-09 19:53:34 +02:00
|
|
|
throw new CommandUsageException();
|
|
|
|
}
|
2019-04-24 15:01:22 +02:00
|
|
|
}
|