mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-22 15:22:11 +01:00
Add /npc villager for 1.14
This commit is contained in:
parent
1028a3fabb
commit
74836f6cc3
@ -141,6 +141,7 @@ public class Messages {
|
||||
public static final String INVALID_TRIGGER_TELEPORT_FORMAT = "citizens.editors.waypoints.triggers.teleport.invalid-format";
|
||||
public static final String INVALID_TROPICALFISH_COLOR = "citizens.commands.npc.tropicalfish.invalid-color";
|
||||
public static final String INVALID_TROPICALFISH_PATTERN = "citizens.commands.npc.tropicalfish.invalid-pattern";
|
||||
public static final String INVALID_VILLAGER_TYPE = "citizens.commands.npc.villager.invalid-type";
|
||||
public static final String ITEM_SET = "citizens.commands.npc.item.item-set";
|
||||
public static final String LEASHABLE_SET = "citizens.commands.npc.leashable.set";
|
||||
public static final String LEASHABLE_STOPPED = "citizens.commands.npc.leashable.stopped";
|
||||
@ -309,6 +310,8 @@ public class Messages {
|
||||
public static final String TROPICALFISH_PATTERN_SET = "citizens.commands.npc.tropicalfish.pattern-set";
|
||||
public static final String UNKNOWN_COMMAND = "citizens.commands.unknown-command";
|
||||
public static final String UNKNOWN_MATERIAL = "citizens.commands.npc.item.unknown-material";
|
||||
public static final String VILLAGER_LEVEL_SET = "citizens.commands.npc.villager.level-set";
|
||||
public static final String VILLAGER_TYPE_SET = "citizens.commands.npc.villager.type-set";
|
||||
public static final String VULNERABLE_SET = "citizens.commands.npc.vulnerable.set";
|
||||
public static final String VULNERABLE_STOPPED = "citizens.commands.npc.vulnerable.stopped";
|
||||
public static final String WANDER_WAYPOINTS_ADDED_REGION = "citizens.editors.waypoints.wander.added-region";
|
||||
|
@ -185,6 +185,9 @@ citizens.commands.npc.vulnerable.set=[[{0}]] is now vulnerable.
|
||||
citizens.commands.npc.vulnerable.stopped=[[{0}]] is no longer vulnerable.
|
||||
citizens.commands.npc.wolf.unknown-collar-color=[[{0}]] is not an RGB-formatted collar color or the name of a DyeColor.
|
||||
citizens.commands.npc.wolf.collar-color-unsupported=[[{0}]] is not a RGB color code that can be used on a wolf''s collar.
|
||||
citizens.commands.npc.villager.level-set=Level set to [[{0}]].
|
||||
citizens.commands.npc.villager.invalid-type=Invalid villager type. Valid types are: [[{0}]].
|
||||
citizens.commands.npc.villager.type-set=Type set to [[{0}]].
|
||||
citizens.commands.npc.zombiemod.villager-set=[[{0}]] is now a villager.
|
||||
citizens.commands.npc.zombiemod.villager-unset=[[{0}]] is no longer a villager.
|
||||
citizens.commands.npc.zombiemod.baby-set=[[{0}]] is now a baby.
|
||||
|
@ -13,7 +13,10 @@ import org.bukkit.entity.Llama.Color;
|
||||
import org.bukkit.entity.Panda;
|
||||
import org.bukkit.entity.Parrot.Variant;
|
||||
import org.bukkit.entity.TropicalFish.Pattern;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.entity.Villager.Profession;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@ -24,6 +27,7 @@ import net.citizensnpcs.api.command.exception.CommandException;
|
||||
import net.citizensnpcs.api.command.exception.CommandUsageException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.util.Messaging;
|
||||
import net.citizensnpcs.trait.VillagerProfession;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.Util;
|
||||
|
||||
@ -367,4 +371,48 @@ public class Commands {
|
||||
throw new CommandUsageException();
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "villager (--level level) (--type type) (--profession profession)",
|
||||
desc = "Sets phantom modifiers",
|
||||
modifiers = { "phantom" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "citizens.npc.villager")
|
||||
@Requirements(selected = true, ownership = true, types = EntityType.VILLAGER)
|
||||
public void villager(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
VillagerTrait trait = npc.getTrait(VillagerTrait.class);
|
||||
String output = "";
|
||||
if (args.hasValueFlag("level")) {
|
||||
if (args.getFlagInteger("level") < 0) {
|
||||
throw new CommandUsageException();
|
||||
}
|
||||
trait.setLevel(args.getFlagInteger("level"));
|
||||
output += Messaging.tr(Messages.VILLAGER_LEVEL_SET, args.getFlagInteger("level"));
|
||||
}
|
||||
if (args.hasValueFlag("type")) {
|
||||
Villager.Type type = Util.matchEnum(Villager.Type.values(), args.getFlag("type"));
|
||||
if (type == null) {
|
||||
throw new CommandException(Messages.INVALID_VILLAGER_TYPE,
|
||||
Util.listValuesPretty(Villager.Type.values()));
|
||||
}
|
||||
trait.setLevel(args.getFlagInteger("type"));
|
||||
output += Messaging.tr(Messages.VILLAGER_TYPE_SET, args.getFlagInteger("type"));
|
||||
}
|
||||
if (args.hasValueFlag("profession")) {
|
||||
Profession parsed = Util.matchEnum(Profession.values(), args.getFlag("profession"));
|
||||
if (parsed == null) {
|
||||
throw new CommandException(Messages.INVALID_PROFESSION, args.getString(1),
|
||||
Joiner.on(',').join(Profession.values()));
|
||||
}
|
||||
npc.getTrait(VillagerProfession.class).setProfession(parsed);
|
||||
output += Messaging.tr(Messages.PROFESSION_SET, npc.getName(), args.getFlag("profession"));
|
||||
}
|
||||
if (!output.isEmpty()) {
|
||||
Messaging.send(sender, output);
|
||||
} else {
|
||||
throw new CommandUsageException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
package net.citizensnpcs.nms.v1_14_R1.trait;
|
||||
|
||||
import org.bukkit.entity.Villager;
|
||||
|
||||
import net.citizensnpcs.api.persistence.Persist;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.trait.TraitName;
|
||||
|
||||
@TraitName("villagertrait")
|
||||
public class VillagerTrait extends Trait {
|
||||
@Persist
|
||||
private int level;
|
||||
@Persist
|
||||
private Villager.Type type;
|
||||
|
||||
public VillagerTrait() {
|
||||
super("villagertrait");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!(npc.getEntity() instanceof Villager))
|
||||
return;
|
||||
if (type != null) {
|
||||
((Villager) npc.getEntity()).setVillagerType(type);
|
||||
}
|
||||
((Villager) npc.getEntity()).setVillagerLevel(level);
|
||||
}
|
||||
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public void setType(Villager.Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
@ -184,6 +184,7 @@ import net.citizensnpcs.nms.v1_14_R1.trait.PhantomTrait;
|
||||
import net.citizensnpcs.nms.v1_14_R1.trait.PufferFishTrait;
|
||||
import net.citizensnpcs.nms.v1_14_R1.trait.ShulkerTrait;
|
||||
import net.citizensnpcs.nms.v1_14_R1.trait.TropicalFishTrait;
|
||||
import net.citizensnpcs.nms.v1_14_R1.trait.VillagerTrait;
|
||||
import net.citizensnpcs.npc.EntityControllers;
|
||||
import net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator;
|
||||
import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator;
|
||||
@ -603,6 +604,7 @@ public class NMSImpl implements NMSBridge {
|
||||
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(PhantomTrait.class));
|
||||
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(PufferFishTrait.class));
|
||||
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(TropicalFishTrait.class));
|
||||
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(VillagerTrait.class));
|
||||
manager.register(Commands.class);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user