mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-29 14:15:50 +01:00
change to commands
This commit is contained in:
parent
416b803216
commit
700a7752ca
@ -30,9 +30,8 @@ import net.citizensnpcs.command.command.AdminCommands;
|
|||||||
import net.citizensnpcs.command.command.EditorCommands;
|
import net.citizensnpcs.command.command.EditorCommands;
|
||||||
import net.citizensnpcs.command.command.HelpCommands;
|
import net.citizensnpcs.command.command.HelpCommands;
|
||||||
import net.citizensnpcs.command.command.NPCCommands;
|
import net.citizensnpcs.command.command.NPCCommands;
|
||||||
|
import net.citizensnpcs.command.exception.CommandException;
|
||||||
import net.citizensnpcs.command.exception.CommandUsageException;
|
import net.citizensnpcs.command.exception.CommandUsageException;
|
||||||
import net.citizensnpcs.command.exception.NoPermissionsException;
|
|
||||||
import net.citizensnpcs.command.exception.RequirementMissingException;
|
|
||||||
import net.citizensnpcs.command.exception.ServerCommandException;
|
import net.citizensnpcs.command.exception.ServerCommandException;
|
||||||
import net.citizensnpcs.command.exception.UnhandledCommandException;
|
import net.citizensnpcs.command.exception.UnhandledCommandException;
|
||||||
import net.citizensnpcs.command.exception.WrappedCommandException;
|
import net.citizensnpcs.command.exception.WrappedCommandException;
|
||||||
@ -110,25 +109,23 @@ public class Citizens extends JavaPlugin {
|
|||||||
try {
|
try {
|
||||||
commands.execute(split, player, player == null ? sender : player, npc);
|
commands.execute(split, player, player == null ? sender : player, npc);
|
||||||
} catch (ServerCommandException ex) {
|
} catch (ServerCommandException ex) {
|
||||||
sender.sendMessage("You must be in-game to execute that command.");
|
Messaging.send(sender, "You must be in-game to execute that command.");
|
||||||
} catch (NoPermissionsException ex) {
|
|
||||||
Messaging.sendError(player, "You don't have permission to execute that command.");
|
|
||||||
} catch (CommandUsageException ex) {
|
} catch (CommandUsageException ex) {
|
||||||
Messaging.sendError(player, ex.getMessage());
|
Messaging.sendError(player, ex.getMessage());
|
||||||
Messaging.sendError(player, ex.getUsage());
|
Messaging.sendError(player, ex.getUsage());
|
||||||
} catch (RequirementMissingException ex) {
|
} catch (WrappedCommandException ex) {
|
||||||
Messaging.sendError(player, ex.getMessage());
|
throw ex.getCause();
|
||||||
} catch (WrappedCommandException e) {
|
} catch (UnhandledCommandException ex) {
|
||||||
throw e.getCause();
|
|
||||||
} catch (UnhandledCommandException e) {
|
|
||||||
return false;
|
return false;
|
||||||
|
} catch (CommandException ex) {
|
||||||
|
Messaging.sendError(player, ex.getMessage());
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException ex) {
|
||||||
Messaging.sendError(player, "That is not a valid number.");
|
Messaging.sendError(player, "That is not a valid number.");
|
||||||
} catch (Throwable excp) {
|
} catch (Throwable ex) {
|
||||||
excp.printStackTrace();
|
ex.printStackTrace();
|
||||||
Messaging.sendError(player, "Please report this error: [See console]");
|
Messaging.sendError(player, "Please report this error: [See console]");
|
||||||
Messaging.sendError(player, excp.getClass().getName() + ": " + excp.getMessage());
|
Messaging.sendError(player, ex.getClass().getName() + ": " + ex.getMessage());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import net.citizensnpcs.command.Command;
|
|||||||
import net.citizensnpcs.command.CommandContext;
|
import net.citizensnpcs.command.CommandContext;
|
||||||
import net.citizensnpcs.command.Requirements;
|
import net.citizensnpcs.command.Requirements;
|
||||||
import net.citizensnpcs.command.ServerCommand;
|
import net.citizensnpcs.command.ServerCommand;
|
||||||
|
import net.citizensnpcs.command.exception.CommandException;
|
||||||
import net.citizensnpcs.util.Messaging;
|
import net.citizensnpcs.util.Messaging;
|
||||||
import net.citizensnpcs.util.StringHelper;
|
import net.citizensnpcs.util.StringHelper;
|
||||||
|
|
||||||
@ -39,14 +40,13 @@ public class AdminCommands {
|
|||||||
max = 1,
|
max = 1,
|
||||||
permission = "admin")
|
permission = "admin")
|
||||||
@ServerCommand
|
@ServerCommand
|
||||||
public void reload(CommandContext args, CommandSender sender, NPC npc) {
|
public void reload(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||||
Messaging.send(sender, "<e>Reloading Citizens...");
|
Messaging.send(sender, "<e>Reloading Citizens...");
|
||||||
try {
|
try {
|
||||||
plugin.reload();
|
plugin.reload();
|
||||||
Messaging.send(sender, "<e>Citizens reloaded.");
|
Messaging.send(sender, "<e>Citizens reloaded.");
|
||||||
} catch (NPCLoadException e) {
|
} catch (NPCLoadException ex) {
|
||||||
Messaging.sendError(sender, "Error occured while reloading, see console.");
|
throw new CommandException("Error occured while reloading, see console.");
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import net.citizensnpcs.command.Command;
|
|||||||
import net.citizensnpcs.command.CommandContext;
|
import net.citizensnpcs.command.CommandContext;
|
||||||
import net.citizensnpcs.command.CommandManager;
|
import net.citizensnpcs.command.CommandManager;
|
||||||
import net.citizensnpcs.command.Requirements;
|
import net.citizensnpcs.command.Requirements;
|
||||||
|
import net.citizensnpcs.command.exception.CommandException;
|
||||||
import net.citizensnpcs.util.Messaging;
|
import net.citizensnpcs.util.Messaging;
|
||||||
import net.citizensnpcs.util.StringHelper;
|
import net.citizensnpcs.util.StringHelper;
|
||||||
|
|
||||||
@ -35,10 +36,10 @@ public class HelpCommands {
|
|||||||
max = 2,
|
max = 2,
|
||||||
permission = "help")
|
permission = "help")
|
||||||
@Requirements
|
@Requirements
|
||||||
public void citizensHelp(CommandContext args, Player player, NPC npc) {
|
public void citizensHelp(CommandContext args, Player player, NPC npc) throws CommandException {
|
||||||
int page = args.argsLength() == 2 ? args.getInteger(1) : 1;
|
int page = args.argsLength() == 2 ? args.getInteger(1) : 1;
|
||||||
if (!sendPage(player, args.getCommand(), page))
|
if (!sendPage(player, args.getCommand(), page))
|
||||||
Messaging.sendError(player, "The page '" + page + "' does not exist.");
|
throw new CommandException("The page '" + page + "' does not exist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
@ -50,10 +51,10 @@ public class HelpCommands {
|
|||||||
max = 2,
|
max = 2,
|
||||||
permission = "npc.help")
|
permission = "npc.help")
|
||||||
@Requirements
|
@Requirements
|
||||||
public void npcHelp(CommandContext args, Player player, NPC npc) {
|
public void npcHelp(CommandContext args, Player player, NPC npc) throws CommandException {
|
||||||
int page = args.argsLength() == 2 ? args.getInteger(1) : 1;
|
int page = args.argsLength() == 2 ? args.getInteger(1) : 1;
|
||||||
if (!sendPage(player, args.getCommand(), page))
|
if (!sendPage(player, args.getCommand(), page))
|
||||||
Messaging.sendError(player, "The page '" + page + "' does not exist.");
|
throw new CommandException("The page '" + page + "' does not exist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean sendPage(Player player, String baseCommand, int page) {
|
private boolean sendPage(Player player, String baseCommand, int page) {
|
||||||
|
@ -12,6 +12,8 @@ import net.citizensnpcs.api.trait.trait.Spawned;
|
|||||||
import net.citizensnpcs.command.Command;
|
import net.citizensnpcs.command.Command;
|
||||||
import net.citizensnpcs.command.CommandContext;
|
import net.citizensnpcs.command.CommandContext;
|
||||||
import net.citizensnpcs.command.Requirements;
|
import net.citizensnpcs.command.Requirements;
|
||||||
|
import net.citizensnpcs.command.exception.CommandException;
|
||||||
|
import net.citizensnpcs.command.exception.NoPermissionsException;
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.trait.LookClose;
|
import net.citizensnpcs.trait.LookClose;
|
||||||
import net.citizensnpcs.util.Messaging;
|
import net.citizensnpcs.util.Messaging;
|
||||||
@ -114,32 +116,22 @@ public class NPCCommands {
|
|||||||
min = 1,
|
min = 1,
|
||||||
max = 2)
|
max = 2)
|
||||||
@Requirements
|
@Requirements
|
||||||
public void remove(CommandContext args, Player player, NPC npc) {
|
public void remove(CommandContext args, Player player, NPC npc) throws CommandException {
|
||||||
if (args.argsLength() == 2) {
|
if (args.argsLength() == 2) {
|
||||||
if (!args.getString(1).equals("all")) {
|
if (!args.getString(1).equals("all"))
|
||||||
Messaging.sendError(player, "Incorrect syntax. /npc remove (all)");
|
throw new CommandException("Incorrect syntax. /npc remove (all)");
|
||||||
return;
|
if (!player.hasPermission("citizens.npc.remove.all") && !player.hasPermission("citizens.admin"))
|
||||||
}
|
throw new NoPermissionsException();
|
||||||
if (!player.hasPermission("citizens.npc.remove.all") && !player.hasPermission("citizens.admin")) {
|
|
||||||
Messaging.sendError(player, "You don't have permission to execute that command.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
npcManager.removeAll();
|
npcManager.removeAll();
|
||||||
Messaging.send(player, "<a>You permanently removed all NPCs.");
|
Messaging.send(player, "<a>You permanently removed all NPCs.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (npc == null) {
|
if (npc == null)
|
||||||
Messaging.sendError(player, "You must have an NPC selected to execute that command.");
|
throw new CommandException("You must have an NPC selected to execute that command.");
|
||||||
return;
|
if (!npc.getTrait(Owner.class).getOwner().equals(player.getName()) && !player.hasPermission("citizens.admin"))
|
||||||
}
|
throw new CommandException("You must be the owner of this NPC to execute that command.");
|
||||||
if (!npc.getTrait(Owner.class).getOwner().equals(player.getName()) && !player.hasPermission("citizens.admin")) {
|
if (!player.hasPermission("citizens.npc.remove") && !player.hasPermission("citizens.admin"))
|
||||||
Messaging.sendError(player, "You must be the owner of this NPC to execute that command.");
|
throw new NoPermissionsException();
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!player.hasPermission("citizens.npc.remove") && !player.hasPermission("citizens.admin")) {
|
|
||||||
Messaging.sendError(player, "You don't have permission to execute that command.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
npc.remove();
|
npc.remove();
|
||||||
Messaging.send(player, "<a>You permanently removed " + StringHelper.wrap(npc.getName()) + ".");
|
Messaging.send(player, "<a>You permanently removed " + StringHelper.wrap(npc.getName()) + ".");
|
||||||
}
|
}
|
||||||
@ -173,16 +165,12 @@ public class NPCCommands {
|
|||||||
max = 2,
|
max = 2,
|
||||||
permission = "npc.select")
|
permission = "npc.select")
|
||||||
@Requirements(ownership = true)
|
@Requirements(ownership = true)
|
||||||
public void select(CommandContext args, Player player, NPC npc) {
|
public void select(CommandContext args, Player player, NPC npc) throws CommandException {
|
||||||
NPC toSelect = npcManager.getNPC(args.getInteger(1));
|
NPC toSelect = npcManager.getNPC(args.getInteger(1));
|
||||||
if (toSelect == null || !toSelect.getTrait(Spawned.class).shouldSpawn()) {
|
if (toSelect == null || !toSelect.getTrait(Spawned.class).shouldSpawn())
|
||||||
Messaging.sendError(player, "No NPC with the ID '" + args.getInteger(1) + "' is spawned.");
|
throw new CommandException("No NPC with the ID '" + args.getInteger(1) + "' is spawned.");
|
||||||
return;
|
if (npc != null && toSelect.getId() == npc.getId())
|
||||||
}
|
throw new CommandException("You already have that NPC selected.");
|
||||||
if (npc != null && toSelect.getId() == npc.getId()) {
|
|
||||||
Messaging.sendError(player, "You already have that NPC selected.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
npcManager.selectNPC(player, toSelect);
|
npcManager.selectNPC(player, toSelect);
|
||||||
Messaging.sendWithNPC(player, Setting.SELECTION_MESSAGE.asString(), toSelect);
|
Messaging.sendWithNPC(player, Setting.SELECTION_MESSAGE.asString(), toSelect);
|
||||||
}
|
}
|
||||||
@ -194,22 +182,16 @@ public class NPCCommands {
|
|||||||
modifiers = { "character" },
|
modifiers = { "character" },
|
||||||
min = 2,
|
min = 2,
|
||||||
max = 2)
|
max = 2)
|
||||||
public void character(CommandContext args, Player player, NPC npc) {
|
public void character(CommandContext args, Player player, NPC npc) throws CommandException {
|
||||||
String name = args.getString(1).toLowerCase();
|
String name = args.getString(1).toLowerCase();
|
||||||
Character character = characterManager.getInstance(name, npc);
|
Character character = characterManager.getInstance(name, npc);
|
||||||
if (character == null) {
|
if (character == null)
|
||||||
Messaging.sendError(player, "The character '" + args.getString(1) + "' does not exist.");
|
throw new CommandException("The character '" + args.getString(1) + "' does not exist.");
|
||||||
return;
|
if (npc.getCharacter() != null && npc.getCharacter().getName().equalsIgnoreCase(character.getName()))
|
||||||
}
|
throw new CommandException("The NPC already has the character '" + name + "'.");
|
||||||
if (npc.getCharacter() != null && npc.getCharacter().getName().equalsIgnoreCase(character.getName())) {
|
|
||||||
Messaging.sendError(player, "The NPC already has the character '" + name + "'.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!player.hasPermission("citizens.npc.character." + character.getName())
|
if (!player.hasPermission("citizens.npc.character." + character.getName())
|
||||||
&& !player.hasPermission("citizens.npc.character.*") && !player.hasPermission("citizens.admin")) {
|
&& !player.hasPermission("citizens.npc.character.*") && !player.hasPermission("citizens.admin"))
|
||||||
Messaging.sendError(player, "You don't have permission to execute that command.");
|
throw new NoPermissionsException();
|
||||||
return;
|
|
||||||
}
|
|
||||||
Messaging.send(player, StringHelper.wrap(npc.getName() + "'s") + " character is now '"
|
Messaging.send(player, StringHelper.wrap(npc.getName() + "'s") + " character is now '"
|
||||||
+ StringHelper.wrap(name) + "'.");
|
+ StringHelper.wrap(name) + "'.");
|
||||||
npc.setCharacter(character);
|
npc.setCharacter(character);
|
||||||
@ -223,12 +205,10 @@ public class NPCCommands {
|
|||||||
min = 2,
|
min = 2,
|
||||||
max = 2,
|
max = 2,
|
||||||
permission = "npc.owner")
|
permission = "npc.owner")
|
||||||
public void owner(CommandContext args, Player player, NPC npc) {
|
public void owner(CommandContext args, Player player, NPC npc) throws CommandException {
|
||||||
String name = args.getString(1);
|
String name = args.getString(1);
|
||||||
if (npc.getTrait(Owner.class).getOwner().equals(name)) {
|
if (npc.getTrait(Owner.class).getOwner().equals(name))
|
||||||
Messaging.sendError(player, "'" + name + "' is already the owner of " + npc.getName() + ".");
|
throw new CommandException("'" + name + "' is already the owner of " + npc.getName() + ".");
|
||||||
return;
|
|
||||||
}
|
|
||||||
npc.getTrait(Owner.class).setOwner(name);
|
npc.getTrait(Owner.class).setOwner(name);
|
||||||
Messaging.send(player, StringHelper.wrap(name) + " is now the owner of " + StringHelper.wrap(npc.getName())
|
Messaging.send(player, StringHelper.wrap(name) + " is now the owner of " + StringHelper.wrap(npc.getName())
|
||||||
+ ".");
|
+ ".");
|
||||||
@ -243,27 +223,22 @@ public class NPCCommands {
|
|||||||
max = 2,
|
max = 2,
|
||||||
permission = "npc.spawn")
|
permission = "npc.spawn")
|
||||||
@Requirements
|
@Requirements
|
||||||
public void spawn(CommandContext args, Player player, NPC npc) {
|
public void spawn(CommandContext args, Player player, NPC npc) throws CommandException {
|
||||||
NPC respawn = npcManager.getNPC(args.getInteger(1));
|
NPC respawn = npcManager.getNPC(args.getInteger(1));
|
||||||
if (respawn == null) {
|
if (respawn == null)
|
||||||
Messaging.sendError(player, "No NPC with the ID '" + args.getInteger(1) + "' exists.");
|
throw new CommandException("No NPC with the ID '" + args.getInteger(1) + "' exists.");
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!respawn.getTrait(Owner.class).getOwner().equals(player.getName())) {
|
if (!respawn.getTrait(Owner.class).getOwner().equals(player.getName()))
|
||||||
Messaging.sendError(player, "You must be the owner of this NPC to execute that command.");
|
throw new CommandException("You must be the owner of this NPC to execute that command.");
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (respawn.spawn(player.getLocation())) {
|
if (respawn.spawn(player.getLocation())) {
|
||||||
npcManager.selectNPC(player, respawn);
|
npcManager.selectNPC(player, respawn);
|
||||||
Messaging.send(player, ChatColor.GREEN + "You respawned " + StringHelper.wrap(respawn.getName())
|
Messaging.send(player, ChatColor.GREEN + "You respawned " + StringHelper.wrap(respawn.getName())
|
||||||
+ " at your location.");
|
+ " at your location.");
|
||||||
} else {
|
} else
|
||||||
Messaging.sendError(player, respawn.getName() + " is already spawned at another location."
|
throw new CommandException(respawn.getName() + " is already spawned at another location."
|
||||||
+ " Use '/npc tphere' to teleport the NPC to your location.");
|
+ " Use '/npc tphere' to teleport the NPC to your location.");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "npc" },
|
aliases = { "npc" },
|
||||||
|
@ -2,4 +2,8 @@ package net.citizensnpcs.command.exception;
|
|||||||
|
|
||||||
public class NoPermissionsException extends CommandException {
|
public class NoPermissionsException extends CommandException {
|
||||||
private static final long serialVersionUID = -602374621030168291L;
|
private static final long serialVersionUID = -602374621030168291L;
|
||||||
|
|
||||||
|
public NoPermissionsException() {
|
||||||
|
super("You don't have permission to execute that command.");
|
||||||
|
}
|
||||||
}
|
}
|
@ -27,7 +27,7 @@ public class EquipmentEditor extends Editor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void begin() {
|
public void begin() {
|
||||||
Messaging.send(player, "<2>Entered the equipment editor!");
|
Messaging.send(player, "<b>Entered the equipment editor!");
|
||||||
Messaging.send(player, "<e>Right click <a>to equip armor and items.");
|
Messaging.send(player, "<e>Right click <a>to equip armor and items.");
|
||||||
Messaging.send(player, "<e>Right click <a>while <e>crouching <a>to equip armor in the NPC's hand.");
|
Messaging.send(player, "<e>Right click <a>while <e>crouching <a>to equip armor in the NPC's hand.");
|
||||||
Messaging.send(player, "<e>Right click <a>with an <e>empty hand <a>to remove all armor and items.");
|
Messaging.send(player, "<e>Right click <a>with an <e>empty hand <a>to remove all armor and items.");
|
||||||
|
Loading…
Reference in New Issue
Block a user