mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 10:36:10 +01:00
Add /npc llama
This commit is contained in:
parent
af24e5f427
commit
59f67c02b9
@ -295,6 +295,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
|
||||
|
||||
registerCommands();
|
||||
enableSubPlugins();
|
||||
NMS.load(commands);
|
||||
|
||||
// Setup NPCs after all plugins have been enabled (allows for multiworld
|
||||
// support and for NPCs to properly register external settings)
|
||||
|
@ -23,7 +23,6 @@ import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Horse;
|
||||
import org.bukkit.entity.Horse.Color;
|
||||
import org.bukkit.entity.Horse.Style;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
@ -629,11 +628,8 @@ public class NPCCommands {
|
||||
max = 1,
|
||||
flags = "cb",
|
||||
permission = "citizens.npc.horse")
|
||||
@Requirements(selected = true, ownership = true)
|
||||
@Requirements(selected = true, ownership = true, types = EntityType.HORSE)
|
||||
public void horse(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
if (!(npc.getEntity() instanceof Horse)) {
|
||||
throw new CommandException(Messages.INVALID_ENTITY_TYPE);
|
||||
}
|
||||
HorseModifiers horse = npc.getTrait(HorseModifiers.class);
|
||||
String output = "";
|
||||
if (args.hasFlag('c')) {
|
||||
|
@ -162,7 +162,7 @@ public class CitizensNavigator implements Navigator, Runnable {
|
||||
updatePathfindingRange();
|
||||
boolean finished = executing.update();
|
||||
if (localParams.lookAtFunction() != null) {
|
||||
Util.faceLocation(npc.getEntity(), localParams.lookAtFunction().apply(this), true, false);
|
||||
Util.faceLocation(npc.getEntity(), localParams.lookAtFunction().apply(this), true, true);
|
||||
Entity entity = npc.getEntity().getPassenger();
|
||||
Location npcLoc = npc.getEntity().getLocation();
|
||||
while (entity != null) {
|
||||
|
@ -106,6 +106,7 @@ public class Messages {
|
||||
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";
|
||||
public static final String INVALID_LLAMA_COLOR = "citizens.commands.npc.llama.invalid-color";
|
||||
public static final String INVALID_OCELOT_TYPE = "citizens.commands.npc.ocelot.invalid-type";
|
||||
public static final String INVALID_POSE_NAME = "citizens.commands.npc.pose.invalid-name";
|
||||
public static final String INVALID_PROFESSION = "citizens.commands.npc.profession.invalid-profession";
|
||||
@ -128,6 +129,8 @@ public class Messages {
|
||||
public static final String LINEAR_WAYPOINT_EDITOR_REMOVED_WAYPOINT = "citizens.editors.waypoints.linear.removed-waypoint";
|
||||
public static final String LINEAR_WAYPOINT_EDITOR_SHOWING_MARKERS = "citizens.editors.waypoints.linear.showing-markers";
|
||||
public static final String LINEAR_WAYPOINT_EDITOR_WAYPOINTS_CLEARED = "citizens.editors.waypoints.linear.waypoints-cleared";
|
||||
public static final String LLAMA_COLOR_SET = "citizens.commands.npc.llama.color-set";
|
||||
public static final String LLAMA_STRENGTH_SET = "citizens.commands.npc.llama.strength-set";
|
||||
public static final String LOAD_NAME_NOT_FOUND = "citizens.notifications.npc-name-not-found";
|
||||
public static final String LOAD_TASK_NOT_SCHEDULED = "citizens.load-task-error";
|
||||
public static final String LOAD_UNKNOWN_NPC_TYPE = "citizens.notifications.unknown-npc-type";
|
||||
|
@ -22,6 +22,7 @@ import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.GameProfileRepository;
|
||||
|
||||
import net.citizensnpcs.api.ai.NavigatorParameters;
|
||||
import net.citizensnpcs.api.command.CommandManager;
|
||||
import net.citizensnpcs.api.command.exception.CommandException;
|
||||
import net.citizensnpcs.api.npc.BlockBreaker;
|
||||
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
|
||||
@ -143,6 +144,10 @@ public class NMS {
|
||||
return BRIDGE.isOnGround(entity);
|
||||
}
|
||||
|
||||
public static void load(CommandManager commands) {
|
||||
BRIDGE.load(commands);
|
||||
}
|
||||
|
||||
public static void loadBridge(String rev) throws Exception {
|
||||
BRIDGE = (NMSBridge) Class.forName("net.citizensnpcs.nms.v" + rev + ".util.NMSImpl").getConstructor()
|
||||
.newInstance();
|
||||
|
@ -22,6 +22,7 @@ import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.GameProfileRepository;
|
||||
|
||||
import net.citizensnpcs.api.ai.NavigatorParameters;
|
||||
import net.citizensnpcs.api.command.CommandManager;
|
||||
import net.citizensnpcs.api.command.exception.CommandException;
|
||||
import net.citizensnpcs.api.npc.BlockBreaker;
|
||||
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
|
||||
@ -76,6 +77,8 @@ public interface NMSBridge {
|
||||
|
||||
public boolean isOnGround(Entity entity);
|
||||
|
||||
public void load(CommandManager commands);
|
||||
|
||||
public void loadPlugins();
|
||||
|
||||
public void look(Entity from, Entity to);
|
||||
|
@ -62,6 +62,9 @@ citizens.commands.npc.item.item-set=NPC item set to [[{0}]].
|
||||
citizens.commands.npc.item.unknown-material=Unknown material given.
|
||||
citizens.commands.npc.leashable.set=[[{0}]] is now leashable.
|
||||
citizens.commands.npc.leashable.stopped=[[{0}]] is no longer leashable.
|
||||
citizens.commands.npc.llama.strength-set=Llama strength set to [[{0}]].
|
||||
citizens.commands.npc.llama.color-set=Llama color set to [[{0}]].
|
||||
citizens.commands.npc.llama.invalid-color=Invalid llama color given. Valid colors are: [[{0}]].
|
||||
citizens.commands.npc.lookclose.set=[[{0}]] will now rotate when players are nearby.
|
||||
citizens.commands.npc.lookclose.stopped=[[{0}]] will no longer rotate when players are nearby.
|
||||
citizens.commands.npc.minecart.set=[[{0}]] now has item [[{1}]]:[[{2}]] with offset [[{3}]].
|
||||
|
@ -58,6 +58,7 @@ import com.mojang.util.UUIDTypeAdapter;
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.ai.NavigatorParameters;
|
||||
import net.citizensnpcs.api.ai.event.CancelReason;
|
||||
import net.citizensnpcs.api.command.CommandManager;
|
||||
import net.citizensnpcs.api.command.exception.CommandException;
|
||||
import net.citizensnpcs.api.npc.BlockBreaker;
|
||||
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
|
||||
@ -517,6 +518,10 @@ public class NMSImpl implements NMSBridge {
|
||||
return NMSImpl.getHandle(entity).onGround;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CommandManager commands) {
|
||||
}
|
||||
|
||||
private void loadEntityTypes() {
|
||||
EntityControllers.setEntityControllerForType(EntityType.AREA_EFFECT_CLOUD, AreaEffectCloudController.class);
|
||||
EntityControllers.setEntityControllerForType(EntityType.ARROW, TippedArrowController.class);
|
||||
@ -1393,7 +1398,6 @@ public class NMSImpl implements NMSBridge {
|
||||
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.SILVERFISH,
|
||||
EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.MAGMA_CUBE,
|
||||
EntityType.HORSE, EntityType.GHAST);
|
||||
|
||||
private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle");
|
||||
private static final float DEFAULT_SPEED = 1F;
|
||||
private static final Field ENDERDRAGON_BATTLE_BAR_FIELD = NMS.getField(EnderDragonBattle.class, "c");
|
||||
|
@ -0,0 +1,47 @@
|
||||
package net.citizensnpcs.nms.v1_11_R1.trait;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Llama.Color;
|
||||
|
||||
import net.citizensnpcs.api.command.Command;
|
||||
import net.citizensnpcs.api.command.CommandContext;
|
||||
import net.citizensnpcs.api.command.Requirements;
|
||||
import net.citizensnpcs.api.command.exception.CommandException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.util.Messaging;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.Util;
|
||||
|
||||
public class Commands {
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "llama (--color color) (--strength strength)",
|
||||
desc = "Sets llama modifiers",
|
||||
modifiers = { "llama" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "citizens.npc.llama")
|
||||
@Requirements(selected = true, ownership = true, types = EntityType.LLAMA)
|
||||
public void llama(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
LlamaTrait trait = npc.getTrait(LlamaTrait.class);
|
||||
String output = "";
|
||||
if (args.hasValueFlag("color") || args.hasValueFlag("colour")) {
|
||||
String colorRaw = args.getFlag("color", args.getFlag("colour"));
|
||||
Color color = Util.matchEnum(Color.values(), colorRaw);
|
||||
if (color == null) {
|
||||
String valid = Util.listValuesPretty(Color.values());
|
||||
throw new CommandException(Messages.INVALID_LLAMA_COLOR, valid);
|
||||
}
|
||||
trait.setColor(color);
|
||||
output += Messaging.tr(Messages.LLAMA_COLOR_SET, Util.prettyEnum(color));
|
||||
}
|
||||
if (args.hasValueFlag("strength")) {
|
||||
trait.setStrength(Math.max(1, Math.min(5, args.getFlagInteger("strength"))));
|
||||
output += Messaging.tr(Messages.LLAMA_STRENGTH_SET, args.getFlagInteger("strength"));
|
||||
}
|
||||
if (!output.isEmpty()) {
|
||||
Messaging.send(sender, output);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package net.citizensnpcs.nms.v1_11_R1.trait;
|
||||
|
||||
import org.bukkit.entity.Llama;
|
||||
import org.bukkit.entity.Llama.Color;
|
||||
|
||||
import net.citizensnpcs.api.persistence.Persist;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.trait.TraitName;
|
||||
|
||||
@TraitName("llamatrait")
|
||||
public class LlamaTrait extends Trait {
|
||||
@Persist
|
||||
private Color color = Color.BROWN;
|
||||
@Persist
|
||||
private int strength = 3;
|
||||
|
||||
public LlamaTrait() {
|
||||
super("llamatrait");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (npc.isSpawned() && npc.getEntity() instanceof Llama) {
|
||||
Llama llama = (Llama) npc.getEntity();
|
||||
llama.setColor(color);
|
||||
llama.setStrength(strength);
|
||||
}
|
||||
}
|
||||
|
||||
public void setColor(Llama.Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public void setStrength(int strength) {
|
||||
this.strength = strength;
|
||||
}
|
||||
}
|
@ -56,13 +56,16 @@ import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
|
||||
import com.mojang.util.UUIDTypeAdapter;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.ai.NavigatorParameters;
|
||||
import net.citizensnpcs.api.ai.event.CancelReason;
|
||||
import net.citizensnpcs.api.command.CommandManager;
|
||||
import net.citizensnpcs.api.command.exception.CommandException;
|
||||
import net.citizensnpcs.api.npc.BlockBreaker;
|
||||
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.npc.NPCRegistry;
|
||||
import net.citizensnpcs.api.trait.TraitInfo;
|
||||
import net.citizensnpcs.api.util.Messaging;
|
||||
import net.citizensnpcs.nms.v1_11_R1.entity.BatController;
|
||||
import net.citizensnpcs.nms.v1_11_R1.entity.BlazeController;
|
||||
@ -147,6 +150,8 @@ import net.citizensnpcs.nms.v1_11_R1.entity.nonliving.ThrownPotionController;
|
||||
import net.citizensnpcs.nms.v1_11_R1.entity.nonliving.TippedArrowController;
|
||||
import net.citizensnpcs.nms.v1_11_R1.entity.nonliving.WitherSkullController;
|
||||
import net.citizensnpcs.nms.v1_11_R1.network.EmptyChannel;
|
||||
import net.citizensnpcs.nms.v1_11_R1.trait.Commands;
|
||||
import net.citizensnpcs.nms.v1_11_R1.trait.LlamaTrait;
|
||||
import net.citizensnpcs.npc.EntityControllers;
|
||||
import net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator;
|
||||
import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator;
|
||||
@ -535,6 +540,12 @@ public class NMSImpl implements NMSBridge {
|
||||
return NMSImpl.getHandle(entity).onGround;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CommandManager manager) {
|
||||
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(LlamaTrait.class));
|
||||
manager.register(Commands.class);
|
||||
}
|
||||
|
||||
private void loadEntityTypes() {
|
||||
EntityControllers.setEntityControllerForType(EntityType.AREA_EFFECT_CLOUD, AreaEffectCloudController.class);
|
||||
EntityControllers.setEntityControllerForType(EntityType.ARROW, TippedArrowController.class);
|
||||
@ -1453,6 +1464,7 @@ public class NMSImpl implements NMSBridge {
|
||||
private static Field PATHFINDING_RANGE = NMS.getField(NavigationAbstract.class, "f");
|
||||
private static final Field RABBIT_FIELD = NMS.getField(EntityRabbit.class, "bx");
|
||||
private static final Random RANDOM = Util.getFastRandom();
|
||||
|
||||
private static Field SKULL_PROFILE_FIELD;
|
||||
|
||||
private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c");
|
||||
|
Loading…
Reference in New Issue
Block a user