mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-29 19:41:50 +01:00
Add /npc copier command
This commit is contained in:
parent
54eb4e31da
commit
9b8bef597d
@ -4,6 +4,7 @@ import net.citizensnpcs.api.command.Command;
|
||||
import net.citizensnpcs.api.command.CommandContext;
|
||||
import net.citizensnpcs.api.command.Requirements;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.editor.CopierEditor;
|
||||
import net.citizensnpcs.editor.Editor;
|
||||
import net.citizensnpcs.editor.EquipmentEditor;
|
||||
import net.citizensnpcs.trait.text.Text;
|
||||
@ -14,6 +15,17 @@ import org.bukkit.entity.Player;
|
||||
|
||||
@Requirements(selected = true, ownership = true)
|
||||
public class EditorCommands {
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "copier",
|
||||
desc = "Toggle the NPC copier",
|
||||
modifiers = { "copier" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "citizens.npc.edit.copier")
|
||||
public void copier(CommandContext args, Player player, NPC npc) {
|
||||
Editor.enterOrLeave(player, new CopierEditor(player, npc));
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
@ -23,7 +35,6 @@ public class EditorCommands {
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "citizens.npc.edit.equip")
|
||||
@Requirements(selected = true, ownership = true)
|
||||
public void equip(CommandContext args, Player player, NPC npc) {
|
||||
Editor.enterOrLeave(player, new EquipmentEditor(player, npc));
|
||||
}
|
||||
|
@ -90,7 +90,6 @@ public class NPCCommands {
|
||||
min = 1,
|
||||
max = 2,
|
||||
permission = "citizens.npc.age")
|
||||
@Requirements(selected = true, ownership = true)
|
||||
public void age(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
if (!npc.isSpawned() || !(npc.getBukkitEntity() instanceof Ageable))
|
||||
throw new CommandException(Messages.MOBTYPE_CANNOT_BE_AGED);
|
||||
@ -108,8 +107,9 @@ public class NPCCommands {
|
||||
int age = 0;
|
||||
try {
|
||||
age = args.getInteger(1);
|
||||
if (age < -24000 || age > 0)
|
||||
if (age < -24000 || age > 0) {
|
||||
throw new CommandException(Messages.INVALID_AGE);
|
||||
}
|
||||
Messaging.sendTr(sender, Messages.AGE_SET_NORMAL, npc.getName(), age);
|
||||
} catch (NumberFormatException ex) {
|
||||
if (args.getString(1).equalsIgnoreCase("baby")) {
|
||||
@ -134,7 +134,6 @@ public class NPCCommands {
|
||||
min = 1,
|
||||
max = 3,
|
||||
permission = "citizens.npc.anchor")
|
||||
@Requirements(selected = true, ownership = true)
|
||||
public void anchor(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
Anchors trait = npc.getTrait(Anchors.class);
|
||||
if (args.hasValueFlag("save")) {
|
||||
|
53
src/main/java/net/citizensnpcs/editor/CopierEditor.java
Normal file
53
src/main/java/net/citizensnpcs/editor/CopierEditor.java
Normal file
@ -0,0 +1,53 @@
|
||||
package net.citizensnpcs.editor;
|
||||
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.util.Messaging;
|
||||
import net.citizensnpcs.trait.CurrentLocation;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
public class CopierEditor extends Editor {
|
||||
private final String name;
|
||||
private final NPC npc;
|
||||
private final Player player;
|
||||
|
||||
public CopierEditor(Player player, NPC npc) {
|
||||
this.player = player;
|
||||
this.npc = npc;
|
||||
this.name = npc.getFullName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin() {
|
||||
Messaging.sendTr(player, Messages.COPIER_EDITOR_BEGIN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end() {
|
||||
Messaging.sendTr(player, Messages.COPIER_EDITOR_END);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockClick(PlayerInteractEvent event) {
|
||||
if (event.getClickedBlock() == null) {
|
||||
return;
|
||||
}
|
||||
NPC copy = npc.clone();
|
||||
if (!copy.getFullName().equals(name)) {
|
||||
copy.setName(name);
|
||||
}
|
||||
|
||||
if (copy.isSpawned() && player.isOnline()) {
|
||||
Location location = player.getLocation();
|
||||
location.getChunk().load();
|
||||
copy.getBukkitEntity().teleport(location);
|
||||
copy.getTrait(CurrentLocation.class).setLocation(location);
|
||||
}
|
||||
|
||||
Messaging.sendTr(player, Messages.NPC_COPIED, npc.getName());
|
||||
}
|
||||
}
|
@ -40,14 +40,16 @@ public class Age extends Trait implements Toggleable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!locked && isAgeable())
|
||||
if (!locked && isAgeable()) {
|
||||
age = ageable.getAge();
|
||||
}
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
if (isAgeable())
|
||||
if (isAgeable()) {
|
||||
ageable.setAge(age);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,6 +45,8 @@ public class Messages {
|
||||
public static final String COMMAND_TOO_MANY_ARGUMENTS = "citizens.commands.requirements.too-many-arguments";
|
||||
public static final String CONTROLLABLE_REMOVED = "citizens.commands.npc.controllable.removed";
|
||||
public static final String CONTROLLABLE_SET = "citizens.commands.npc.controllable.set";
|
||||
public static final String COPIER_EDITOR_BEGIN = "citizens.editors.copier.begin";
|
||||
public static final String COPIER_EDITOR_END = "citizens.editors.copier.end";
|
||||
public static final String CURRENT_WAYPOINT_PROVIDER = "citizens.waypoints.current-provider";
|
||||
public static final String DATABASE_CONNECTION_FAILED = "citizens.notifications.database-connection-failed";
|
||||
public static final String DELAY_TRIGGER_PROMPT = "citizens.editors.waypoints.triggers.delay.prompt";
|
||||
|
@ -122,6 +122,8 @@ citizens.economy.error-loading=Unable to use economy handling. Has Vault been en
|
||||
citizens.economy.minimum-cost-required=Need at least {0}.
|
||||
citizens.economy.money-withdrawn=Withdrew [[{0}]] for your NPC.
|
||||
citizens.editors.already-in-editor=You''re already in an editor!
|
||||
citizens.editors.copier.begin=<b>Entered the NPC copier!<br>Click anywhere to copy the currently selected NPC.
|
||||
citizens.editors.copier.end=Exited the NPC copier.
|
||||
citizens.editors.equipment.all-items-removed=[[{0}]] had all of its items removed.
|
||||
citizens.editors.equipment.begin=<b>Entered the equipment editor!<br>[[Right click]] to equip the NPC!
|
||||
citizens.editors.equipment.end=Exited the equipment editor.
|
||||
|
Loading…
Reference in New Issue
Block a user