Various fixes and features

This commit is contained in:
fullwall 2019-11-28 16:10:35 +08:00
parent 94733ddb81
commit d0dcb235b3
12 changed files with 137 additions and 26 deletions

View File

@ -2010,15 +2010,17 @@ public class NPCCommands {
}
firstWasPlayer = true;
}
try {
int id = args.getInteger(2);
NPC toNPC = CitizensAPI.getNPCRegistry().getById(id);
if (toNPC != null) {
to = toNPC.getEntity();
}
} catch (NumberFormatException e) {
if (!firstWasPlayer) {
to = Bukkit.getPlayerExact(args.getString(2));
if (args.argsLength() == 3) {
try {
int id = args.getInteger(2);
NPC toNPC = CitizensAPI.getNPCRegistry().getById(id);
if (toNPC != null) {
to = toNPC.getEntity();
}
} catch (NumberFormatException e) {
if (!firstWasPlayer) {
to = Bukkit.getPlayerExact(args.getString(2));
}
}
}
if (from == null)

View File

@ -4,7 +4,9 @@ import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@ -43,7 +45,14 @@ public class FollowTrait extends Trait {
@EventHandler
private void onEntityDamage(EntityDamageByEntityEvent event) {
if (isActive() && event.getEntity().equals(player)) {
npc.getNavigator().setTarget(event.getDamager(), true);
Entity damager = event.getDamager();
if (event.getEntity() instanceof Projectile) {
Projectile projectile = (Projectile) event.getEntity();
if (projectile.getShooter() instanceof Entity) {
damager = (Entity) projectile.getShooter();
}
}
npc.getNavigator().setTarget(damager, true);
}
}

View File

@ -23,7 +23,9 @@ public class Messages {
public static final String BEHAVIOURS_REMOVED = "citizens.commands.npc.behaviour.removed";
public static final String CANNOT_TELEPORT_ACROSS_WORLDS = "citizens.commands.npc.tphere.multiworld-not-allowed";
public static final String CAT_COLLAR_COLOR_SET = "citizens.commands.npc.cat.collar-color-set";
public static final String CAT_STARTED_LYING = "citizens.commands.npc.cat.lying-start";
public static final String CAT_STARTED_SITTING = "citizens.commands.npc.cat.sitting-start";
public static final String CAT_STOPPED_LYING = "citizens.commands.npc.cat.lying-stop";
public static final String CAT_STOPPED_SITTING = "citizens.commands.npc.cat.sitting-stop";
public static final String CAT_TYPE_SET = "citizens.commands.npc.cat.type-set";
public static final String CHAT_TRIGGER_PROMPT = "citizens.editors.waypoints.triggers.chat.prompt";
@ -135,6 +137,7 @@ public class Messages {
public static final String INVALID_HORSE_STYLE = "citizens.commands.npc.horse.invalid-style";
public static final String INVALID_HORSE_VARIANT = "citizens.commands.npc.horse.invalid-variant";
public static final String INVALID_LLAMA_COLOR = "citizens.commands.npc.llama.invalid-color";
public static final String INVALID_MUSHROOM_COW_VARIANT = "citizens.commands.npc.mushroomcow.invalid-variant";
public static final String INVALID_OCELOT_TYPE = "citizens.commands.npc.ocelot.invalid-type";
public static final String INVALID_PANDA_GENE = "citizens.commands.npc.panda.invalid-gene";
public static final String INVALID_PARROT_VARIANT = "citizens.commands.npc.parrot.invalid-variant";
@ -188,6 +191,7 @@ public class Messages {
public static final String MOUNT_NPC_MUST_BE_SPAWNED = "citizens.commands.npc.mount.must-be-spawned";
public static final String MOVETO_FORMAT = "citizens.commands.npc.moveto.format";
public static final String MOVETO_TELEPORTED = "citizens.commands.npc.moveto.teleported";
public static final String MUSHROOM_COW_VARIANT_SET = "citizens.commands.npc.mushroomcow.variant-set";
public static final String NAMEPLATE_VISIBILITY_TOGGLED = "citizens.commands.npc.nameplate.toggled";
public static final String NO_HORSE_MODIFIERS_GIVEN = "citizens.commands.npc.horse.no-modifiers";
public static final String NO_NPC_WITH_ID_FOUND = "citizens.commands.npc.spawn.missing-npc-id";

View File

@ -30,6 +30,8 @@ citizens.commands.npc.cat.invalid-collar-color=Invalid collar color specified. V
citizens.commands.npc.cat.collar-color-set=Collar color set to [[{0}]].
citizens.commands.npc.cat.sitting-start=[[{0}]] started sitting.
citizens.commands.npc.cat.sitting-stop=[[{0}]] stopped sitting.
citizens.commands.npc.cat.lying-start=[[{0}]] started lying down.
citizens.commands.npc.cat.lying-stop=[[{0}]] stopped lying down.
citizens.commands.npc.cat.type-set=Type set to [[{0}]].
citizens.commands.npc.collidable.set=[[{0}]] will now collide with entities.
citizens.commands.npc.collidable.unset=[[{0}]] will no longer collide with entities.
@ -103,6 +105,8 @@ citizens.commands.npc.mount.failed=Couldn''t mount [[{0}]].
citizens.commands.npc.mount.must-be-spawned=Couldn''t mount [[{0}]]. Make sure that the destination NPC ID is correct and it is spawned.
citizens.commands.npc.moveto.format=Format is x:y:z(:world) or x y z( world).
citizens.commands.npc.moveto.teleported=[[{0}]] teleported to [[{1}]].
citizens.commands.npc.mushroomcow.invalid-variant=Invalid variant. Valid values are: [[{0}]].
citizens.commands.npc.mushroomcow.variant-set=[[{0}]]''s variant set to [[{1}]].
citizens.commands.npc.nameplate.toggled=Nameplate visibility toggled.
citizens.commands.npc.ocelot.invalid-type=Invalid ocelot type. Valid types are: [[{0}]].
citizens.commands.npc.owner.already-owner={0} is already the owner of [[{1}]].
@ -267,11 +271,11 @@ citizens.editors.text.invalid-range=Invalid range.
citizens.editors.text.invalid-delay=Invalid delay.
citizens.editors.text.random-talker-set=[[Random talking]] set to [[{0}]].
citizens.editors.text.range-set=[[Range]] set to [[{0}]].
citizens.editors.text.delay-set=[[Delay]] set to [[{0}]] ticks.
citizens.editors.text.delay-set=[[Delay]] set to [[{0}]] seconds.
citizens.editors.text.realistic-looking-set=[[Realistic looking]] set to [[{0}]].
citizens.editors.text.remove-prompt=Enter the index of the entry you wish to remove or [[page]] to view more pages.
citizens.editors.text.removed-entry=[[Removed]] entry at index [[{0}]].
citizens.editors.text.start-prompt=Type [[add]] to add an entry, [[edit]] to edit entries, [[remove]] to remove entries, [[close]] to toggle the NPC as a close talker, [[item]] to set the item in hand pattern, [[range]] to set the talking range, [[delay]] to set the talking delay in ticks and [[random]] to toggle the NPC as a random talker. Type [[help]] to show this again.
citizens.editors.text.start-prompt=Type [[add]] to add an entry, [[edit]] to edit entries, [[remove]] to remove entries, [[close]] to toggle the NPC as a close talker, [[item]] to set the item in hand pattern, [[range]] to set the talking range, [[delay]] to set the talking delay in seconds and [[random]] to toggle the NPC as a random talker. Type [[help]] to show this again.
citizens.editors.text.talk-item-set=[[Talk item pattern]] set to [[{0}]].
citizens.editors.waypoints.wander.range-set=Wander range set to xrange [[{0}]] and yrange [[{1}]].
citizens.editors.waypoints.wander.begin=<b>Entered the wander waypoint editor.<br> Type [[xrange <number>]] or [[yrange <number>]] to modify the random wander range. Type [[regions]] to enter the region editor.<br>Type [[delay <ticks>]] to delay the NPC between wanders.

View File

@ -17,6 +17,7 @@ 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;
import net.citizensnpcs.api.util.Colorizer;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Util;
@ -38,7 +39,7 @@ public class Commands {
trait.setColor(color);
}
if (args.hasValueFlag("title")) {
trait.setTitle(args.getFlag("title"));
trait.setTitle(Colorizer.parseColors(args.getFlag("title")));
}
if (args.hasValueFlag("visible")) {
trait.setVisible(Boolean.parseBoolean(args.getFlag("visible")));

View File

@ -18,6 +18,7 @@ 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;
import net.citizensnpcs.api.util.Colorizer;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Util;
@ -38,7 +39,7 @@ public class Commands {
trait.setColor(color);
}
if (args.hasValueFlag("title")) {
trait.setTitle(args.getFlag("title"));
trait.setTitle(Colorizer.parseColors(args.getFlag("title")));
}
if (args.hasValueFlag("visible")) {
trait.setVisible(Boolean.parseBoolean(args.getFlag("visible")));

View File

@ -19,6 +19,7 @@ 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;
import net.citizensnpcs.api.util.Colorizer;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Util;
@ -39,7 +40,7 @@ public class Commands {
trait.setColor(color);
}
if (args.hasValueFlag("title")) {
trait.setTitle(args.getFlag("title"));
trait.setTitle(Colorizer.parseColors(args.getFlag("title")));
}
if (args.hasValueFlag("visible")) {
trait.setVisible(Boolean.parseBoolean(args.getFlag("visible")));

View File

@ -20,6 +20,7 @@ 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;
import net.citizensnpcs.api.util.Colorizer;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Util;
@ -40,7 +41,7 @@ public class Commands {
trait.setColor(color);
}
if (args.hasValueFlag("title")) {
trait.setTitle(args.getFlag("title"));
trait.setTitle(Colorizer.parseColors(args.getFlag("title")));
}
if (args.hasValueFlag("visible")) {
trait.setVisible(Boolean.parseBoolean(args.getFlag("visible")));

View File

@ -6,12 +6,15 @@ import org.bukkit.entity.Cat;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
@TraitName("cattrait")
public class CatTrait extends Trait {
@Persist
private DyeColor collarColor = null;
@Persist
private boolean lying = false;
@Persist
private boolean sitting = false;
@Persist
private Cat.Type type = Cat.Type.BLACK;
@ -20,6 +23,10 @@ public class CatTrait extends Trait {
super("cattrait");
}
public boolean isLyingDown() {
return lying;
}
@Override
public void run() {
if (npc.isSpawned() && npc.getEntity() instanceof Cat) {
@ -29,6 +36,7 @@ public class CatTrait extends Trait {
if (collarColor != null) {
cat.setCollarColor(collarColor);
}
NMSImpl.setLyingDown(cat, lying);
}
}
@ -36,6 +44,10 @@ public class CatTrait extends Trait {
this.collarColor = color;
}
public void setLyingDown(boolean lying) {
this.lying = lying;
}
public void setSitting(boolean sitting) {
this.sitting = sitting;
}

View File

@ -10,6 +10,7 @@ import org.bukkit.entity.Cat;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Fox;
import org.bukkit.entity.Llama.Color;
import org.bukkit.entity.MushroomCow;
import org.bukkit.entity.Panda;
import org.bukkit.entity.Parrot.Variant;
import org.bukkit.entity.TropicalFish.Pattern;
@ -26,6 +27,7 @@ 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;
import net.citizensnpcs.api.util.Colorizer;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.trait.VillagerProfession;
import net.citizensnpcs.util.Messages;
@ -48,7 +50,7 @@ public class Commands {
}
if (args.hasValueFlag("title")) {
trait.setTitle(args.getFlag("title"));
trait.setTitle(Colorizer.parseColors(args.getFlag("title")));
}
if (args.hasValueFlag("visible")) {
trait.setVisible(Boolean.parseBoolean(args.getFlag("visible")));
@ -67,12 +69,12 @@ public class Commands {
@Command(
aliases = { "npc" },
usage = "cat (-s/-n) --type type --ccolor collar color",
usage = "cat (-s/-n/-l) --type type --ccolor collar color",
desc = "Sets cat modifiers",
modifiers = { "cat" },
min = 1,
max = 1,
flags = "sn",
flags = "snl",
permission = "citizens.npc.cat")
@Requirements(selected = true, ownership = true, types = EntityType.CAT)
public void cat(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
@ -97,10 +99,15 @@ public class Commands {
}
if (args.hasFlag('s')) {
trait.setSitting(true);
output += ' ' + Messaging.tr(Messages.CAT_STARTED_SITTING);
output += ' ' + Messaging.tr(Messages.CAT_STARTED_SITTING, npc.getName());
} else if (args.hasFlag('n')) {
trait.setSitting(false);
output += ' ' + Messaging.tr(Messages.CAT_STOPPED_SITTING);
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());
@ -182,6 +189,34 @@ public class Commands {
}
}
@Command(
aliases = { "npc" },
usage = "mcow (--variant [variant])",
desc = "Sets mushroom cow modifiers.",
modifiers = { "mcow", "mushroomcow" },
min = 1,
max = 1,
permission = "citizens.npc.mushroomcow")
@Requirements(selected = true, ownership = true, types = { EntityType.SHULKER })
public void mushroomcow(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
MushroomCowTrait trait = npc.getTrait(MushroomCowTrait.class);
boolean hasArg = false;
if (args.hasValueFlag("variant")) {
MushroomCow.Variant variant = Util.matchEnum(MushroomCow.Variant.values(), args.getFlag("variant"));
if (variant == null) {
Messaging.sendErrorTr(sender, Messages.INVALID_MUSHROOM_COW_VARIANT,
Util.listValuesPretty(MushroomCow.Variant.values()));
return;
}
trait.setVariant(variant);
Messaging.sendTr(sender, Messages.MUSHROOM_COW_VARIANT_SET, npc.getName(), variant);
hasArg = true;
}
if (!hasArg) {
throw new CommandUsageException();
}
}
@Command(
aliases = { "npc" },
usage = "panda --gene (main gene) --hgene (hidden gene)",

View File

@ -0,0 +1,34 @@
package net.citizensnpcs.nms.v1_14_R1.trait;
import org.bukkit.entity.MushroomCow;
import org.bukkit.entity.MushroomCow.Variant;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
@TraitName("mushroomcowtrait")
public class MushroomCowTrait extends Trait {
@Persist("variant")
private Variant variant;
public MushroomCowTrait() {
super("mushroomcowtrait");
}
@Override
public void onSpawn() {
setVariant(variant);
}
@Override
public void run() {
if (variant != null && npc.getEntity() instanceof MushroomCow) {
((MushroomCow) npc.getEntity()).setVariant(variant);
}
}
public void setVariant(Variant variant) {
this.variant = variant;
}
}

View File

@ -33,6 +33,7 @@ import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftWither;
import org.bukkit.craftbukkit.v1_14_R1.event.CraftEventFactory;
import org.bukkit.entity.Cat;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.LivingEntity;
@ -178,6 +179,7 @@ import net.citizensnpcs.nms.v1_14_R1.trait.CatTrait;
import net.citizensnpcs.nms.v1_14_R1.trait.Commands;
import net.citizensnpcs.nms.v1_14_R1.trait.FoxTrait;
import net.citizensnpcs.nms.v1_14_R1.trait.LlamaTrait;
import net.citizensnpcs.nms.v1_14_R1.trait.MushroomCowTrait;
import net.citizensnpcs.nms.v1_14_R1.trait.PandaTrait;
import net.citizensnpcs.nms.v1_14_R1.trait.ParrotTrait;
import net.citizensnpcs.nms.v1_14_R1.trait.PhantomTrait;
@ -195,7 +197,6 @@ import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.NMSBridge;
import net.citizensnpcs.util.PlayerAnimation;
import net.citizensnpcs.util.PlayerUpdateTask;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_14_R1.AdvancementDataPlayer;
import net.minecraft.server.v1_14_R1.AttributeInstance;
@ -215,6 +216,7 @@ import net.minecraft.server.v1_14_R1.Enchantments;
import net.minecraft.server.v1_14_R1.EnderDragonBattle;
import net.minecraft.server.v1_14_R1.Entity;
import net.minecraft.server.v1_14_R1.EntityBird;
import net.minecraft.server.v1_14_R1.EntityCat;
import net.minecraft.server.v1_14_R1.EntityEnderDragon;
import net.minecraft.server.v1_14_R1.EntityFish;
import net.minecraft.server.v1_14_R1.EntityFishSchool;
@ -299,7 +301,7 @@ public class NMSImpl implements NMSBridge {
} else if (!handle.world.getPlayers().contains(handle)) {
((List) handle.world.getPlayers()).add(handle);
}
PlayerUpdateTask.addOrRemove(entity, remove);
// PlayerUpdateTask.addOrRemove(entity, remove);
}
@Override
@ -625,15 +627,16 @@ public class NMSImpl implements NMSBridge {
@Override
public void load(CommandManager manager) {
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(BossBarTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(CatTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(FoxTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(LlamaTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(MushroomCowTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(ParrotTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(BossBarTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(ShulkerTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(PandaTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(PhantomTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(PufferFishTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(ShulkerTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(TropicalFishTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(VillagerTrait.class));
manager.register(Commands.class);
@ -1060,7 +1063,7 @@ public class NMSImpl implements NMSBridge {
@Override
public void setWitherCharged(Wither wither, boolean charged) {
EntityWither handle = ((CraftWither) wither).getHandle();
handle.q(charged ? 20 : 0);
handle.r(charged ? 20 : 0);
}
@Override
@ -1642,6 +1645,10 @@ public class NMSImpl implements NMSBridge {
}
}
public static void setLyingDown(Cat cat, boolean lying) {
((EntityCat) getHandle(cat)).u(lying);
}
public static void setNotInSchool(EntityFish entity) {
try {
if (ENTITY_FISH_NUM_IN_SCHOOL != null) {