mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-28 20:17:50 +01:00
change to commands
This commit is contained in:
parent
4273c8fcfa
commit
b8b240700d
@ -30,9 +30,8 @@ import net.citizensnpcs.command.command.AdminCommands;
|
||||
import net.citizensnpcs.command.command.EditorCommands;
|
||||
import net.citizensnpcs.command.command.HelpCommands;
|
||||
import net.citizensnpcs.command.command.NPCCommands;
|
||||
import net.citizensnpcs.command.exception.CommandException;
|
||||
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.UnhandledCommandException;
|
||||
import net.citizensnpcs.command.exception.WrappedCommandException;
|
||||
@ -110,25 +109,23 @@ public class Citizens extends JavaPlugin {
|
||||
try {
|
||||
commands.execute(split, player, player == null ? sender : player, npc);
|
||||
} catch (ServerCommandException ex) {
|
||||
sender.sendMessage("You must be in-game to execute that command.");
|
||||
} catch (NoPermissionsException ex) {
|
||||
Messaging.sendError(player, "You don't have permission to execute that command.");
|
||||
Messaging.send(sender, "You must be in-game to execute that command.");
|
||||
} catch (CommandUsageException ex) {
|
||||
Messaging.sendError(player, ex.getMessage());
|
||||
Messaging.sendError(player, ex.getUsage());
|
||||
} catch (RequirementMissingException ex) {
|
||||
Messaging.sendError(player, ex.getMessage());
|
||||
} catch (WrappedCommandException e) {
|
||||
throw e.getCause();
|
||||
} catch (UnhandledCommandException e) {
|
||||
} catch (WrappedCommandException ex) {
|
||||
throw ex.getCause();
|
||||
} catch (UnhandledCommandException ex) {
|
||||
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.");
|
||||
} catch (Throwable excp) {
|
||||
excp.printStackTrace();
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
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;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import net.citizensnpcs.command.Command;
|
||||
import net.citizensnpcs.command.CommandContext;
|
||||
import net.citizensnpcs.command.Requirements;
|
||||
import net.citizensnpcs.command.ServerCommand;
|
||||
import net.citizensnpcs.command.exception.CommandException;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
|
||||
@ -39,14 +40,13 @@ public class AdminCommands {
|
||||
max = 1,
|
||||
permission = "admin")
|
||||
@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...");
|
||||
try {
|
||||
plugin.reload();
|
||||
Messaging.send(sender, "<e>Citizens reloaded.");
|
||||
} catch (NPCLoadException e) {
|
||||
Messaging.sendError(sender, "Error occured while reloading, see console.");
|
||||
e.printStackTrace();
|
||||
} catch (NPCLoadException ex) {
|
||||
throw new CommandException("Error occured while reloading, see console.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ import net.citizensnpcs.command.Command;
|
||||
import net.citizensnpcs.command.CommandContext;
|
||||
import net.citizensnpcs.command.CommandManager;
|
||||
import net.citizensnpcs.command.Requirements;
|
||||
import net.citizensnpcs.command.exception.CommandException;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
|
||||
@ -35,10 +36,10 @@ public class HelpCommands {
|
||||
max = 2,
|
||||
permission = "help")
|
||||
@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;
|
||||
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(
|
||||
@ -50,10 +51,10 @@ public class HelpCommands {
|
||||
max = 2,
|
||||
permission = "npc.help")
|
||||
@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;
|
||||
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) {
|
||||
|
@ -12,6 +12,8 @@ import net.citizensnpcs.api.trait.trait.Spawned;
|
||||
import net.citizensnpcs.command.Command;
|
||||
import net.citizensnpcs.command.CommandContext;
|
||||
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.trait.LookClose;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
@ -114,32 +116,22 @@ public class NPCCommands {
|
||||
min = 1,
|
||||
max = 2)
|
||||
@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.getString(1).equals("all")) {
|
||||
Messaging.sendError(player, "Incorrect syntax. /npc remove (all)");
|
||||
return;
|
||||
}
|
||||
if (!player.hasPermission("citizens.npc.remove.all") && !player.hasPermission("citizens.admin")) {
|
||||
Messaging.sendError(player, "You don't have permission to execute that command.");
|
||||
return;
|
||||
}
|
||||
if (!args.getString(1).equals("all"))
|
||||
throw new CommandException("Incorrect syntax. /npc remove (all)");
|
||||
if (!player.hasPermission("citizens.npc.remove.all") && !player.hasPermission("citizens.admin"))
|
||||
throw new NoPermissionsException();
|
||||
npcManager.removeAll();
|
||||
Messaging.send(player, "<a>You permanently removed all NPCs.");
|
||||
return;
|
||||
}
|
||||
if (npc == null) {
|
||||
Messaging.sendError(player, "You must have an NPC selected to execute that command.");
|
||||
return;
|
||||
}
|
||||
if (!npc.getTrait(Owner.class).getOwner().equals(player.getName()) && !player.hasPermission("citizens.admin")) {
|
||||
Messaging.sendError(player, "You must be the owner of this NPC to execute that command.");
|
||||
return;
|
||||
}
|
||||
if (!player.hasPermission("citizens.npc.remove") && !player.hasPermission("citizens.admin")) {
|
||||
Messaging.sendError(player, "You don't have permission to execute that command.");
|
||||
return;
|
||||
}
|
||||
if (npc == null)
|
||||
throw new CommandException("You must have an NPC selected to execute that command.");
|
||||
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 (!player.hasPermission("citizens.npc.remove") && !player.hasPermission("citizens.admin"))
|
||||
throw new NoPermissionsException();
|
||||
npc.remove();
|
||||
Messaging.send(player, "<a>You permanently removed " + StringHelper.wrap(npc.getName()) + ".");
|
||||
}
|
||||
@ -173,16 +165,12 @@ public class NPCCommands {
|
||||
max = 2,
|
||||
permission = "npc.select")
|
||||
@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));
|
||||
if (toSelect == null || !toSelect.getTrait(Spawned.class).shouldSpawn()) {
|
||||
Messaging.sendError(player, "No NPC with the ID '" + args.getInteger(1) + "' is spawned.");
|
||||
return;
|
||||
}
|
||||
if (npc != null && toSelect.getId() == npc.getId()) {
|
||||
Messaging.sendError(player, "You already have that NPC selected.");
|
||||
return;
|
||||
}
|
||||
if (toSelect == null || !toSelect.getTrait(Spawned.class).shouldSpawn())
|
||||
throw new CommandException("No NPC with the ID '" + args.getInteger(1) + "' is spawned.");
|
||||
if (npc != null && toSelect.getId() == npc.getId())
|
||||
throw new CommandException("You already have that NPC selected.");
|
||||
npcManager.selectNPC(player, toSelect);
|
||||
Messaging.sendWithNPC(player, Setting.SELECTION_MESSAGE.asString(), toSelect);
|
||||
}
|
||||
@ -194,22 +182,16 @@ public class NPCCommands {
|
||||
modifiers = { "character" },
|
||||
min = 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();
|
||||
Character character = characterManager.getInstance(name, npc);
|
||||
if (character == null) {
|
||||
Messaging.sendError(player, "The character '" + args.getString(1) + "' does not exist.");
|
||||
return;
|
||||
}
|
||||
if (npc.getCharacter() != null && npc.getCharacter().getName().equalsIgnoreCase(character.getName())) {
|
||||
Messaging.sendError(player, "The NPC already has the character '" + name + "'.");
|
||||
return;
|
||||
}
|
||||
if (character == null)
|
||||
throw new CommandException("The character '" + args.getString(1) + "' does not exist.");
|
||||
if (npc.getCharacter() != null && npc.getCharacter().getName().equalsIgnoreCase(character.getName()))
|
||||
throw new CommandException("The NPC already has the character '" + name + "'.");
|
||||
if (!player.hasPermission("citizens.npc.character." + character.getName())
|
||||
&& !player.hasPermission("citizens.npc.character.*") && !player.hasPermission("citizens.admin")) {
|
||||
Messaging.sendError(player, "You don't have permission to execute that command.");
|
||||
return;
|
||||
}
|
||||
&& !player.hasPermission("citizens.npc.character.*") && !player.hasPermission("citizens.admin"))
|
||||
throw new NoPermissionsException();
|
||||
Messaging.send(player, StringHelper.wrap(npc.getName() + "'s") + " character is now '"
|
||||
+ StringHelper.wrap(name) + "'.");
|
||||
npc.setCharacter(character);
|
||||
@ -223,12 +205,10 @@ public class NPCCommands {
|
||||
min = 2,
|
||||
max = 2,
|
||||
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);
|
||||
if (npc.getTrait(Owner.class).getOwner().equals(name)) {
|
||||
Messaging.sendError(player, "'" + name + "' is already the owner of " + npc.getName() + ".");
|
||||
return;
|
||||
}
|
||||
if (npc.getTrait(Owner.class).getOwner().equals(name))
|
||||
throw new CommandException("'" + name + "' is already the owner of " + npc.getName() + ".");
|
||||
npc.getTrait(Owner.class).setOwner(name);
|
||||
Messaging.send(player, StringHelper.wrap(name) + " is now the owner of " + StringHelper.wrap(npc.getName())
|
||||
+ ".");
|
||||
@ -243,26 +223,21 @@ public class NPCCommands {
|
||||
max = 2,
|
||||
permission = "npc.spawn")
|
||||
@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));
|
||||
if (respawn == null) {
|
||||
Messaging.sendError(player, "No NPC with the ID '" + args.getInteger(1) + "' exists.");
|
||||
return;
|
||||
}
|
||||
if (respawn == null)
|
||||
throw new CommandException("No NPC with the ID '" + args.getInteger(1) + "' exists.");
|
||||
|
||||
if (!respawn.getTrait(Owner.class).getOwner().equals(player.getName())) {
|
||||
Messaging.sendError(player, "You must be the owner of this NPC to execute that command.");
|
||||
return;
|
||||
}
|
||||
if (!respawn.getTrait(Owner.class).getOwner().equals(player.getName()))
|
||||
throw new CommandException("You must be the owner of this NPC to execute that command.");
|
||||
|
||||
if (respawn.spawn(player.getLocation())) {
|
||||
npcManager.selectNPC(player, respawn);
|
||||
Messaging.send(player, ChatColor.GREEN + "You respawned " + StringHelper.wrap(respawn.getName())
|
||||
+ " at your location.");
|
||||
} else {
|
||||
Messaging.sendError(player, respawn.getName() + " is already spawned at another location."
|
||||
} else
|
||||
throw new CommandException(respawn.getName() + " is already spawned at another location."
|
||||
+ " Use '/npc tphere' to teleport the NPC to your location.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
|
@ -2,4 +2,8 @@ package net.citizensnpcs.command.exception;
|
||||
|
||||
public class NoPermissionsException extends CommandException {
|
||||
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
|
||||
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>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.");
|
||||
|
Loading…
Reference in New Issue
Block a user