Skip to content

Commit

Permalink
Various fixes and features
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Nov 28, 2019
1 parent 94733dd commit d0dcb23
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 26 deletions.
20 changes: 11 additions & 9 deletions main/src/main/java/net/citizensnpcs/commands/NPCCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -2010,15 +2010,17 @@ public void tpto(CommandContext args, CommandSender sender, NPC npc) throws Comm
}
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)
Expand Down
11 changes: 10 additions & 1 deletion main/src/main/java/net/citizensnpcs/trait/FollowTrait.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

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;

Expand Down Expand Up @@ -43,7 +45,14 @@ public boolean isEnabled() {
@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);
}
}

Expand Down
4 changes: 4 additions & 0 deletions main/src/main/java/net/citizensnpcs/util/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down
8 changes: 6 additions & 2 deletions main/src/main/resources/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}]].
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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.Colorizer;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Util;
Expand All @@ -38,7 +39,7 @@ public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws C
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")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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.Colorizer;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Util;
Expand All @@ -38,7 +39,7 @@ public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws C
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")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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.Colorizer;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Util;
Expand All @@ -39,7 +40,7 @@ public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws C
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")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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.Colorizer;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Util;
Expand All @@ -40,7 +41,7 @@ public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws C
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")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
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;
Expand All @@ -20,6 +23,10 @@ public CatTrait() {
super("cattrait");
}

public boolean isLyingDown() {
return lying;
}

@Override
public void run() {
if (npc.isSpawned() && npc.getEntity() instanceof Cat) {
Expand All @@ -29,13 +36,18 @@ public void run() {
if (collarColor != null) {
cat.setCollarColor(collarColor);
}
NMSImpl.setLyingDown(cat, lying);
}
}

public void setCollarColor(DyeColor color) {
this.collarColor = color;
}

public void setLyingDown(boolean lying) {
this.lying = lying;
}

public void setSitting(boolean sitting) {
this.sitting = sitting;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;
Expand All @@ -26,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.Colorizer;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.trait.VillagerProfession;
import net.citizensnpcs.util.Messages;
Expand All @@ -48,7 +50,7 @@ public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws C
}

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")));
Expand All @@ -67,12 +69,12 @@ public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws C

@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 {
Expand All @@ -97,10 +99,15 @@ public void cat(CommandContext args, CommandSender sender, NPC npc) throws Comma
}
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());
Expand Down Expand Up @@ -182,6 +189,34 @@ public void llama(CommandContext args, CommandSender sender, NPC npc) throws Com
}
}

@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)",
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading

0 comments on commit d0dcb23

Please sign in to comment.