Add some 1.13 traits, fix an issues with backwards API compatibility

This commit is contained in:
fullwall 2018-07-20 21:57:45 +08:00
parent dfb5b90b38
commit 9adf755b8b
9 changed files with 224 additions and 4 deletions

View File

@ -1,5 +1,8 @@
package net.citizensnpcs.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.citizensnpcs.api.command.Command;
import net.citizensnpcs.api.command.CommandContext;
import net.citizensnpcs.api.command.Requirements;
@ -10,9 +13,6 @@ import net.citizensnpcs.editor.EquipmentEditor;
import net.citizensnpcs.trait.text.Text;
import net.citizensnpcs.trait.waypoint.Waypoints;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@Requirements(selected = true, ownership = true)
public class EditorCommands {
@Command(

View File

@ -119,6 +119,8 @@ public class Messages {
public static final String INVALID_SOUND = "citizens.commands.npc.sound.invalid-sound";
public static final String INVALID_SPAWN_LOCATION = "citizens.commands.npc.create.invalid-location";
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 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";
@ -184,6 +186,7 @@ public class Messages {
public static final String PATHFINDING_OPTIONS_DISTANCE_MARGIN_SET = "citizens.commands.npc.pathopt.distance-margin-set";
public static final String PATHFINDING_OPTIONS_STATIONARY_TICKS_SET = "citizens.commands.npc.pathopt.stationary-ticks-set";
public static final String PATHFINDING_RANGE_SET = "citizens.commands.npc.pathfindingrange.set";
public static final String PHANTOM_STATE_SET = "citizens.commands.npc.phantom.phantom-set";
public static final String PLAYER_NOT_FOUND_FOR_SPAWN = "citizens.commands.npc.create.no-player-for-spawn";
public static final String POSE_ADDED = "citizens.commands.npc.pose.added";
public static final String POSE_ALREADY_EXISTS = "citizens.commands.npc.pose.already-exists";
@ -192,6 +195,7 @@ public class Messages {
public static final String POWERED_SET = "citizens.commands.npc.powered.set";
public static final String POWERED_STOPPED = "citizens.commands.npc.powered.stopped";
public static final String PROFESSION_SET = "citizens.commands.npc.profession.set";
public static final String PUFFERFISH_STATE_SET = "citizens.commands.npc.pufferfish.state-set";
public static final String RABBIT_TYPE_SET = "citizens.commands.npc.rabbittype.type-set";
public static final String REMOVE_INCORRECT_SYNTAX = "citizens.commands.npc.remove.incorrect-syntax";
public static final String REMOVED_ALL_NPCS = "citizens.commands.npc.remove.removed-all";
@ -272,6 +276,9 @@ public class Messages {
public static final String TRAITS_FAILED_TO_ADD = "citizens.commands.trait.failed-to-add";
public static final String TRAITS_FAILED_TO_CHANGE = "citizens.commands.trait.failed-to-change";
public static final String TRAITS_REMOVED = "citizens.commands.trait.removed";
public static final String TROPICALFISH_BODY_COLOR_SET = "citizens.commands.npc.tropicalfish.body-color-set";
public static final String TROPICALFISH_PATTERN_COLOR_SET = "citizens.commands.npc.tropicalfish.pattern-color-set";
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 VULNERABLE_SET = "citizens.commands.npc.vulnerable.set";

View File

@ -19,6 +19,7 @@ import com.google.common.base.Splitter;
import net.citizensnpcs.api.event.NPCCollisionEvent;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.SpigotUtil;
public class Util {
// Static class for small (emphasis small) utility methods
@ -178,7 +179,8 @@ public class Util {
if (parts.contains("*"))
return true;
for (String part : Splitter.on(',').split(parts)) {
if (Material.matchMaterial(part, true) == player.getInventory().getItemInMainHand().getType()) {
if ((SpigotUtil.isUsing1_13API() ? Material.matchMaterial(part, true)
: Material.matchMaterial(part)) == player.getInventory().getItemInMainHand().getType()) {
return true;
}
}

View File

@ -99,8 +99,15 @@ citizens.commands.npc.pose.missing=The pose [[{0}]] does not exist.
citizens.commands.npc.pose.removed=Pose removed.
citizens.commands.npc.powered.set=[[{0}]] will now be powered.
citizens.commands.npc.powered.stopped=[[{0}]] will no longer be powered.
citizens.commands.npc.phantom.phantom-set=Size set to [[{0}]].
citizens.commands.npc.tropicalfish.invalid-color=Invalid fish color. Valid colors are: [[{0}]]
citizens.commands.npc.tropicalfish.invalid-pattern=Invalid fish pattern. Valid patterns are: [[{0}]]
citizens.commands.npc.tropicalfish.body-color-set=Body color set to [[{0}]].
citizens.commands.npc.tropicalfish.pattern-color-set=Pattern color set to [[{0}]].
citizens.commands.npc.tropicalfish.pattern-set=Pattern set to [[{0}]].
citizens.commands.npc.profession.invalid-profession=[[{0}]] is not a valid profession. Try one of the following: [[{1}]].
citizens.commands.npc.profession.set=[[{0}]] is now a [[{1}]].
citizens.commands.npc.pufferfish.state-set=State set to [[{0}]].
citizens.commands.npc.rabbittype.invalid-type=Invalid rabbit type. Try one of the following: [[{0}]].
citizens.commands.npc.rabbittype.type-set=[[{0}]]''s rabbit type has been set to [[{1}]]
citizens.commands.npc.remove.npcs-removed=NPCs removed.

View File

@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Llama.Color;
import org.bukkit.entity.Parrot.Variant;
import org.bukkit.entity.TropicalFish.Pattern;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
@ -114,6 +115,54 @@ public class Commands {
}
}
@Command(
aliases = { "npc" },
usage = "phantom (--size size)",
desc = "Sets phantom modifiers",
modifiers = { "phantom" },
min = 1,
max = 1,
permission = "citizens.npc.phantom")
@Requirements(selected = true, ownership = true, types = EntityType.PHANTOM)
public void phantom(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
PhantomTrait trait = npc.getTrait(PhantomTrait.class);
String output = "";
if (args.hasValueFlag("size")) {
if (args.getFlagInteger("size") <= 0) {
throw new CommandUsageException();
}
trait.setSize(args.getFlagInteger("size"));
output += Messaging.tr(Messages.PHANTOM_STATE_SET, args.getFlagInteger("size"));
}
if (!output.isEmpty()) {
Messaging.send(sender, output);
} else {
throw new CommandUsageException();
}
}
@Command(
aliases = { "npc" },
usage = "pufferfish (--state state)",
desc = "Sets pufferfish modifiers",
modifiers = { "pufferfish" },
min = 1,
max = 1,
permission = "citizens.npc.pufferfish")
@Requirements(selected = true, ownership = true, types = EntityType.PUFFERFISH)
public void pufferfish(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
PufferFishTrait trait = npc.getTrait(PufferFishTrait.class);
String output = "";
if (args.hasValueFlag("state")) {
int state = Math.min(Math.max(args.getFlagInteger("state"), 0), 3);
trait.setPuffState(state);
output += Messaging.tr(Messages.PUFFERFISH_STATE_SET, state);
}
if (!output.isEmpty()) {
Messaging.send(sender, output);
}
}
@Command(
aliases = { "npc" },
usage = "shulker (--peek [peek] --color [color])",
@ -146,4 +195,50 @@ public class Commands {
throw new CommandUsageException();
}
}
@Command(
aliases = { "npc" },
usage = "tfish (--body color) (--pattern pattern) (--patterncolor color)",
desc = "Sets tropical fish modifiers",
modifiers = { "tfish" },
min = 1,
max = 1,
permission = "citizens.npc.tropicalfish")
@Requirements(selected = true, ownership = true, types = EntityType.TROPICAL_FISH)
public void tropicalfish(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
TropicalFishTrait trait = npc.getTrait(TropicalFishTrait.class);
String output = "";
if (args.hasValueFlag("body")) {
DyeColor color = Util.matchEnum(DyeColor.values(), args.getFlag("body"));
if (color == null) {
throw new CommandException(Messages.INVALID_TROPICALFISH_COLOR,
Util.listValuesPretty(DyeColor.values()));
}
trait.setBodyColor(color);
output += Messaging.tr(Messages.TROPICALFISH_BODY_COLOR_SET, Util.prettyEnum(color));
}
if (args.hasValueFlag("patterncolor")) {
DyeColor color = Util.matchEnum(DyeColor.values(), args.getFlag("patterncolor"));
if (color == null) {
throw new CommandException(Messages.INVALID_TROPICALFISH_COLOR,
Util.listValuesPretty(DyeColor.values()));
}
trait.setPatternColor(color);
output += Messaging.tr(Messages.TROPICALFISH_PATTERN_COLOR_SET, Util.prettyEnum(color));
}
if (args.hasValueFlag("pattern")) {
Pattern pattern = Util.matchEnum(Pattern.values(), args.getFlag("pattern"));
if (pattern == null) {
throw new CommandException(Messages.INVALID_TROPICALFISH_PATTERN,
Util.listValuesPretty(Pattern.values()));
}
trait.setPattern(pattern);
output += Messaging.tr(Messages.TROPICALFISH_PATTERN_SET, Util.prettyEnum(pattern));
}
if (!output.isEmpty()) {
Messaging.send(sender, output);
} else {
throw new CommandUsageException();
}
}
}

View File

@ -0,0 +1,29 @@
package net.citizensnpcs.nms.v1_13_R1.trait;
import org.bukkit.entity.Phantom;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
@TraitName("phantomtrait")
public class PhantomTrait extends Trait {
@Persist
private int size = 1;
public PhantomTrait() {
super("phantomtrait");
}
@Override
public void run() {
if (npc.isSpawned() && npc.getEntity() instanceof Phantom) {
Phantom phantom = (Phantom) npc.getEntity();
phantom.setSize(size);
}
}
public void setSize(int size) {
this.size = size;
}
}

View File

@ -0,0 +1,29 @@
package net.citizensnpcs.nms.v1_13_R1.trait;
import org.bukkit.entity.PufferFish;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
@TraitName("pufferfishtrait")
public class PufferFishTrait extends Trait {
@Persist
private int puffState = 1;
public PufferFishTrait() {
super("pufferfishtrait");
}
@Override
public void run() {
if (npc.isSpawned() && npc.getEntity() instanceof PufferFish) {
PufferFish puffer = (PufferFish) npc.getEntity();
puffer.setPuffState(puffState);
}
}
public void setPuffState(int state) {
this.puffState = state;
}
}

View File

@ -0,0 +1,45 @@
package net.citizensnpcs.nms.v1_13_R1.trait;
import org.bukkit.DyeColor;
import org.bukkit.entity.TropicalFish;
import org.bukkit.entity.TropicalFish.Pattern;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
@TraitName("tropicalfishtrait")
public class TropicalFishTrait extends Trait {
@Persist
private DyeColor bodyColor = DyeColor.BLUE;
@Persist
private Pattern pattern = Pattern.BRINELY;
@Persist
private DyeColor patternColor = DyeColor.BLUE;
public TropicalFishTrait() {
super("tropicalfishtrait");
}
@Override
public void run() {
if (npc.isSpawned() && npc.getEntity() instanceof TropicalFish) {
TropicalFish fish = (TropicalFish) npc.getEntity();
fish.setBodyColor(bodyColor);
fish.setPatternColor(patternColor);
fish.setPattern(pattern);
}
}
public void setBodyColor(DyeColor color) {
this.bodyColor = color;
}
public void setPattern(Pattern pattern) {
this.pattern = pattern;
}
public void setPatternColor(DyeColor color) {
this.patternColor = color;
}
}

View File

@ -166,7 +166,10 @@ import net.citizensnpcs.nms.v1_13_R1.trait.BossBarTrait;
import net.citizensnpcs.nms.v1_13_R1.trait.Commands;
import net.citizensnpcs.nms.v1_13_R1.trait.LlamaTrait;
import net.citizensnpcs.nms.v1_13_R1.trait.ParrotTrait;
import net.citizensnpcs.nms.v1_13_R1.trait.PhantomTrait;
import net.citizensnpcs.nms.v1_13_R1.trait.PufferFishTrait;
import net.citizensnpcs.nms.v1_13_R1.trait.ShulkerTrait;
import net.citizensnpcs.nms.v1_13_R1.trait.TropicalFishTrait;
import net.citizensnpcs.npc.EntityControllers;
import net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator;
import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator;
@ -566,6 +569,9 @@ public class NMSImpl implements NMSBridge {
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(PhantomTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(PufferFishTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(TropicalFishTrait.class));
manager.register(Commands.class);
}