Skip to content

Commit

Permalink
Add new commands for new 1.14 API
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed May 7, 2019
1 parent 244e8dd commit 483c25f
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 5 deletions.
3 changes: 2 additions & 1 deletion main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java
Expand Up @@ -281,8 +281,9 @@ public boolean spawn(Location at, SpawnReason reason) {
public void update() {
try {
super.update();
if (!isSpawned())
if (!isSpawned()) {
return;
}
if (data().get(NPC.SWIMMING_METADATA, true)) {
NMS.trySwim(getEntity());
}
Expand Down
10 changes: 10 additions & 0 deletions main/src/main/java/net/citizensnpcs/util/Messages.java
Expand Up @@ -21,6 +21,7 @@ public class Messages {
public static final String BEHAVIOURS_ADDED = "citizens.commands.npc.behaviour.added";
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_SITTING = "citizens.commands.npc.cat.sitting-start";
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";
Expand Down Expand Up @@ -88,6 +89,13 @@ public class Messages {
public static final String FOLLOW_PLAYER_NOT_INGAME = "citizens.commands.npc.follow.player-not-ingame";
public static final String FOLLOW_SET = "citizens.commands.npc.follow.set";
public static final String FOLLOW_UNSET = "citizens.commands.npc.follow.unset";
public static final String FOX_CROUCHING_SET = "citizens.commands.npc.fox.crouching-set";
public static final String FOX_CROUCHING_UNSET = "citizens.commands.npc.fox.crouching-unset";
public static final String FOX_SITTING_SET = "citizens.commands.npc.fox.sitting-set";
public static final String FOX_SITTING_UNSET = "citizens.commands.npc.fox.sitting-unset";
public static final String FOX_SLEEPING_SET = "citizens.commands.npc.fox.sleeping-set";
public static final String FOX_SLEEPING_UNSET = "citizens.commands.npc.fox.sleeping-unset";
public static final String FOX_TYPE_SET = "citizens.commands.npc.fox.fox-type-set";
public static final String FROM_ENTITY_NOT_FOUND = "citizens.commands.npc.tpto.from-not-found";
public static final String GAMEMODE_DESCRIBE = "citizens.commands.npc.gamemode.describe";
public static final String GAMEMODE_INVALID = "citizens.commands.npc.gamemode.invalid";
Expand All @@ -110,8 +118,10 @@ public class Messages {
public static final String INVALID_AGE = "citizens.commands.npc.age.invalid-age";
public static final String INVALID_ANCHOR_NAME = "citizens.commands.npc.anchor.invalid-name";
public static final String INVALID_ANIMATION = "citizens.editors.waypoints.triggers.animation.invalid-animation";
public static final String INVALID_CAT_COLLAR_COLOR = "citizens.commands.npc.cat.invalid-collar-color";
public static final String INVALID_CAT_TYPE = "citizens.commands.npc.cat.invalid-type";
public static final String INVALID_ENTITY_TYPE = "citizens.commands.npc.type.invalid";
public static final String INVALID_FOX_TYPE = "citizens.commands.npc.fox.invalid-fox-type";
public static final String INVALID_HORSE_COLOR = "citizens.commands.npc.horse.invalid-color";
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";
Expand Down
10 changes: 10 additions & 0 deletions main/src/main/resources/messages_en.properties
Expand Up @@ -26,6 +26,8 @@ citizens.commands.npc.behaviour.added=Behaviours added.
citizens.commands.npc.behaviour.help=The scripts argument is a comma-separated list of file names. Scripts will be loaded automatically and run every tick. Use the [[-r]] flag to remove behaviours.
citizens.commands.npc.behaviour.removed=Behaviours removed.
citizens.commands.npc.cat.invalid-type=Invalid type specified. Valid types are [[{0}]].
citizens.commands.npc.cat.invalid-collar-color=Invalid collar color specified. Valid types are [[{0}]].
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.type-set=Type set to [[{0}]].
Expand All @@ -43,6 +45,14 @@ citizens.commands.npc.create.no-player-for-spawn=No player could be found by tha
citizens.commands.npc.despawn.despawned=You despawned [[{0}]].
citizens.commands.npc.flyable.set=[[{0}]] is now flyable.
citizens.commands.npc.flyable.unset=[[{0}]] is no longer flyable.
citizens.commands.npc.fox.crouching-set=[[{0}]] is now crouching.
citizens.commands.npc.fox.crouching-unset=[[{0}]] is no longer crouching.
citizens.commands.npc.fox.sitting-set=[[{0}]] is now sitting.
citizens.commands.npc.fox.sitting-unset=[[{0}]] is no longer sitting.
citizens.commands.npc.fox.sleeping-set=[[{0}]] is now sleeping.
citizens.commands.npc.fox.sleeping-unset=[[{0}]] is no longer sleeping.
citizens.commands.npc.fox.fox-type-set=Fox type set to [[{0}]].
citizens.commands.npc.fox.invalid-fox-type=Invalid fox type specified. Valid types are [[{0}]].
citizens.commands.npc.follow.set=[[{0}]] is now following [[{1}]].
citizens.commands.npc.follow.unset=[[{0}]] is no longer following anyone.
citizens.commands.npc.gamemode.describe={0}''s gamemode is [[{1}]].
Expand Down
@@ -1,5 +1,6 @@
package net.citizensnpcs.nms.v1_14_R1.trait;

import org.bukkit.DyeColor;
import org.bukkit.entity.Cat;

import net.citizensnpcs.api.persistence.Persist;
Expand All @@ -8,6 +9,8 @@

@TraitName("cattrait")
public class CatTrait extends Trait {
@Persist
private DyeColor collarColor = null;
@Persist
private boolean sitting = false;
@Persist
Expand All @@ -23,9 +26,16 @@ public void run() {
Cat cat = (Cat) npc.getEntity();
cat.setSitting(sitting);
cat.setCatType(type);
if (collarColor != null) {
cat.setCollarColor(collarColor);
}
}
}

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

public void setSitting(boolean sitting) {
this.sitting = sitting;
}
Expand Down
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.command.CommandSender;
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.Panda;
import org.bukkit.entity.Parrot.Variant;
Expand Down Expand Up @@ -41,6 +42,7 @@ public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws C
BarColor color = Util.matchEnum(BarColor.values(), args.getFlag("color"));
trait.setColor(color);
}

if (args.hasValueFlag("title")) {
trait.setTitle(args.getFlag("title"));
}
Expand All @@ -61,7 +63,7 @@ public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws C

@Command(
aliases = { "npc" },
usage = "cat (-s/-n) --type type",
usage = "cat (-s/-n) --type type --ccolor collar color",
desc = "Sets cat modifiers",
modifiers = { "cat" },
min = 1,
Expand All @@ -72,16 +74,22 @@ public void cat(CommandContext args, CommandSender sender, NPC npc) throws Comma
CatTrait trait = npc.getTrait(CatTrait.class);
String output = "";
if (args.hasValueFlag("type")) {
if (args.getFlagInteger("size") <= 0) {
throw new CommandUsageException();
}
Cat.Type type = Util.matchEnum(Cat.Type.values(), args.getFlag("type"));
if (type == null) {
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")) {
DyeColor color = Util.matchEnum(DyeColor.values(), args.getFlag("ccolor"));
if (color == null) {
throw new CommandUsageException(Messages.INVALID_CAT_COLLAR_COLOR,
Util.listValuesPretty(DyeColor.values()));
}
trait.setCollarColor(color);
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);
Expand All @@ -96,6 +104,48 @@ public void cat(CommandContext args, CommandSender sender, NPC npc) throws Comma
}
}

@Command(
aliases = { "npc" },
usage = "fox --type type --sleeping [true|false] --sitting [true|false] --crouching [true|false]",
desc = "Sets fox modifiers",
modifiers = { "fox" },
min = 1,
max = 1,
permission = "citizens.npc.fox")
@Requirements(selected = true, ownership = true, types = EntityType.FOX)
public void fox(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
FoxTrait trait = npc.getTrait(FoxTrait.class);
String output = "";
if (args.hasValueFlag("type")) {
Fox.Type type = Util.matchEnum(Fox.Type.values(), args.getFlag("type"));
if (type == null) {
throw new CommandUsageException(Messages.INVALID_FOX_TYPE, Util.listValuesPretty(Fox.Type.values()));
}
trait.setType(type);
output += ' ' + Messaging.tr(Messages.FOX_TYPE_SET, args.getFlag("type"));
}
if (args.hasValueFlag("sleeping")) {
boolean sleeping = Boolean.parseBoolean(args.getFlag("sleeping"));
trait.setSleeping(sleeping);
output += ' ' + Messaging.tr(sleeping ? Messages.FOX_SLEEPING_SET : Messages.FOX_SLEEPING_UNSET);
}
if (args.hasValueFlag("sitting")) {
boolean sitting = Boolean.parseBoolean(args.getFlag("sitting"));
trait.setSitting(sitting);
output += ' ' + Messaging.tr(sitting ? Messages.FOX_SITTING_SET : Messages.FOX_SITTING_UNSET);
}
if (args.hasValueFlag("crouching")) {
boolean crouching = Boolean.parseBoolean(args.getFlag("crouching"));
trait.setCrouching(crouching);
output += ' ' + Messaging.tr(crouching ? Messages.FOX_CROUCHING_SET : Messages.FOX_CROUCHING_UNSET);
}
if (!output.isEmpty()) {
Messaging.send(sender, output.trim());
} else {
throw new CommandUsageException();
}
}

@Command(
aliases = { "npc" },
usage = "llama (--color color) (--strength strength)",
Expand Down
@@ -0,0 +1,50 @@
package net.citizensnpcs.nms.v1_14_R1.trait;

import org.bukkit.entity.Fox;

import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;

@TraitName("foxtrait")
public class FoxTrait extends Trait {
@Persist
private boolean crouching = false;
@Persist
private boolean sitting = false;
@Persist
private boolean sleeping = false;
@Persist
private Fox.Type type = Fox.Type.RED;

public FoxTrait() {
super("foxtrait");
}

@Override
public void run() {
if (npc.isSpawned() && npc.getEntity() instanceof Fox) {
Fox fox = (Fox) npc.getEntity();
fox.setSitting(sitting);
fox.setCrouching(crouching);
fox.setSleeping(sleeping);
fox.setFoxType(type);
}
}

public void setCrouching(boolean crouching) {
this.crouching = crouching;
}

public void setSitting(boolean sitting) {
this.sitting = sitting;
}

public void setSleeping(boolean sleeping) {
this.sleeping = sleeping;
}

public void setType(Fox.Type type) {
this.type = type;
}
}
Expand Up @@ -593,6 +593,7 @@ public boolean isOnGround(org.bukkit.entity.Entity entity) {
@Override
public void load(CommandManager manager) {
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(ParrotTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(BossBarTrait.class));
Expand Down

0 comments on commit 483c25f

Please sign in to comment.