diff --git a/lib/CitizensAPI.jar b/lib/CitizensAPI.jar index 95400e3fc..47e75d31d 100644 Binary files a/lib/CitizensAPI.jar and b/lib/CitizensAPI.jar differ diff --git a/plugin.yml b/plugin.yml index 65cbaa9d2..310b62454 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,6 +2,7 @@ name: Citizens authors: [aPunch, fullwall] version: 2.0 main: net.citizensnpcs.Citizens +website: http://www.citizensnpcs.net commands: citizens: description: Administration commands diff --git a/src/net/citizensnpcs/Citizens.java b/src/net/citizensnpcs/Citizens.java index b34b09858..b3b3ea505 100644 --- a/src/net/citizensnpcs/Citizens.java +++ b/src/net/citizensnpcs/Citizens.java @@ -20,6 +20,7 @@ import net.citizensnpcs.api.npc.trait.trait.SpawnLocation; import net.citizensnpcs.api.npc.trait.trait.Spawned; import net.citizensnpcs.command.CommandManager; import net.citizensnpcs.command.Injector; +import net.citizensnpcs.command.command.AdminCommands; import net.citizensnpcs.command.command.HelpCommands; import net.citizensnpcs.command.command.NPCCommands; import net.citizensnpcs.command.exception.CommandUsageException; @@ -239,6 +240,7 @@ public class Citizens extends JavaPlugin { cmdManager.setInjector(new Injector(this)); // Register command classes + cmdManager.register(AdminCommands.class); cmdManager.register(NPCCommands.class); cmdManager.register(HelpCommands.class); } diff --git a/src/net/citizensnpcs/command/command/AdminCommands.java b/src/net/citizensnpcs/command/command/AdminCommands.java index 6c5717cc9..81d0164c8 100644 --- a/src/net/citizensnpcs/command/command/AdminCommands.java +++ b/src/net/citizensnpcs/command/command/AdminCommands.java @@ -1,9 +1,33 @@ package net.citizensnpcs.command.command; -import net.citizensnpcs.Citizens; +import org.bukkit.entity.Player; +import net.citizensnpcs.Citizens; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.command.CommandContext; +import net.citizensnpcs.command.annotation.Command; +import net.citizensnpcs.command.annotation.Requirements; +import net.citizensnpcs.util.Messaging; +import net.citizensnpcs.util.StringHelper; + +@Requirements public class AdminCommands { + private final Citizens plugin; public AdminCommands(Citizens plugin) { + this.plugin = plugin; + } + + @Command( + aliases = { "citizens" }, + desc = "Shows basic plugin information", + max = 0, + permission = "admin") + @Requirements + public void citizens(CommandContext args, Player player, NPC npc) { + Messaging.send(player, " " + StringHelper.wrapHeader("Citizens v" + plugin.getDescription().getVersion())); + Messaging.send(player, " <7>-- Written by fullwall and aPunch"); + Messaging.send(player, " <7>-- Source: http://github.com/CitizensDev"); + Messaging.send(player, " <7>-- Website: " + plugin.getDescription().getWebsite()); } } \ No newline at end of file diff --git a/src/net/citizensnpcs/command/command/HelpCommands.java b/src/net/citizensnpcs/command/command/HelpCommands.java index 27d098abf..6adf9daf0 100644 --- a/src/net/citizensnpcs/command/command/HelpCommands.java +++ b/src/net/citizensnpcs/command/command/HelpCommands.java @@ -67,9 +67,9 @@ public class HelpCommands { Messaging.send( player, - StringHelper.parseColors("=====[ " + StringHelper.wrapHeader("" + (baseCommand.equalsIgnoreCase("npc") ? "NPC" : StringHelper.capitalize(baseCommand - .toLowerCase())) + " Help " + page + "/" + pages + " ]=====")); + .toLowerCase())) + " Help " + page + "/" + pages)); if (lines.size() < endIndex) endIndex = lines.size() - 1; @@ -85,8 +85,8 @@ public class HelpCommands { for (Command cmd : cmdManager.getCommands(baseCommand)) { if (cmds.contains(cmd) || !player.hasPermission("citizens." + cmd.permission())) continue; - lines.add(StringHelper.parseColors("<7>/" + cmd.aliases()[0] + " " + cmd.usage() + " <7>- " - + cmd.desc())); + lines.add(StringHelper.parseColors("<7>/" + cmd.aliases()[0] + + (cmd.usage().isEmpty() ? "" : " " + cmd.usage()) + " <7>- " + cmd.desc())); if (cmd.modifiers().length > 1) cmds.add(cmd); } diff --git a/src/net/citizensnpcs/command/command/NPCCommands.java b/src/net/citizensnpcs/command/command/NPCCommands.java index 359993fe5..9758640aa 100644 --- a/src/net/citizensnpcs/command/command/NPCCommands.java +++ b/src/net/citizensnpcs/command/command/NPCCommands.java @@ -109,6 +109,25 @@ public class NPCCommands { Messaging.send(player, ChatColor.GREEN + "You despawned " + StringHelper.wrap(npc.getName()) + "."); } + @Command( + aliases = { "npc" }, + usage = "rename [name]", + desc = "Rename an NPC", + modifiers = { "rename" }, + min = 2, + max = 2, + permission = "npc.rename") + public void renameNPC(CommandContext args, Player player, NPC npc) { + String oldName = npc.getName(); + npc.setName(args.getString(1)); + // Must reselect NPC after it is despawned + npcManager.selectNPC(player, npc); + Messaging.send( + player, + ChatColor.GREEN + "You renamed " + StringHelper.wrap(oldName) + " to " + + StringHelper.wrap(args.getString(1)) + "."); + } + @Command( aliases = { "npc" }, usage = "select [id]", @@ -189,8 +208,14 @@ public class NPCCommands { Messaging.send(player, ChatColor.GREEN + "You teleported to " + StringHelper.wrap(npc.getName()) + "."); } - @Command(aliases = { "npc" }, usage = "lookclose", desc = "Toggle an NPC's look-close state", modifiers = { - "lookclose", "look", "rotate" }, min = 1, max = 1, permission = "npc.look-close") + @Command( + aliases = { "npc" }, + usage = "lookclose", + desc = "Toggle an NPC's look-close state", + modifiers = { "lookclose", "look", "rotate" }, + min = 1, + max = 1, + permission = "npc.look-close") public void toggleNPCLookClose(CommandContext args, Player player, NPC npc) { LookClose trait = npc.getTrait(LookClose.class); trait.toggle(); diff --git a/src/net/citizensnpcs/npc/CitizensNPC.java b/src/net/citizensnpcs/npc/CitizensNPC.java index 19992e9e8..cbe409634 100644 --- a/src/net/citizensnpcs/npc/CitizensNPC.java +++ b/src/net/citizensnpcs/npc/CitizensNPC.java @@ -39,7 +39,7 @@ public abstract class CitizensNPC extends AbstractNPC { Bukkit.getPluginManager().callEvent(new NPCDespawnEvent(this)); - manager.despawn(this); + manager.despawn(this, getTrait(Spawned.class).shouldSpawn()); mcEntity = null; return true; @@ -113,4 +113,10 @@ public abstract class CitizensNPC extends AbstractNPC { super.update(); ai.update(); } + + @Override + public void setName(String name) { + super.setName(name); + inventory.setName(name); + } } \ No newline at end of file diff --git a/src/net/citizensnpcs/npc/CitizensNPCManager.java b/src/net/citizensnpcs/npc/CitizensNPCManager.java index 48073d7e8..fe9264eb9 100644 --- a/src/net/citizensnpcs/npc/CitizensNPCManager.java +++ b/src/net/citizensnpcs/npc/CitizensNPCManager.java @@ -50,9 +50,10 @@ public class CitizensNPCManager implements NPCManager { return createNPC(type, generateUniqueId(), name, character); } - public void despawn(NPC npc) { + public void despawn(NPC npc, boolean deselect) { npc.getTrait(SpawnLocation.class).setLocation(npc.getBukkitEntity().getLocation()); - selected.removeAll(npc.getId()); + if (deselect) + selected.removeAll(npc.getId()); npc.getBukkitEntity().remove(); } @@ -111,7 +112,7 @@ public class CitizensNPCManager implements NPCManager { public void remove(NPC npc) { if (npc.isSpawned()) - despawn(npc); + despawn(npc, true); npcs.remove(npc.getId()); saves.getKey("npc").removeKey("" + npc.getId()); selected.removeAll(npc.getId()); diff --git a/src/net/citizensnpcs/npc/NPCInventory.java b/src/net/citizensnpcs/npc/NPCInventory.java index 822537a1d..877735ab0 100644 --- a/src/net/citizensnpcs/npc/NPCInventory.java +++ b/src/net/citizensnpcs/npc/NPCInventory.java @@ -15,9 +15,9 @@ import org.bukkit.inventory.Inventory; public class NPCInventory implements IInventory { private final int size = 36; private final NPC npc; - private final String name; private final ItemStack[] contents; private final Inventory inventory = new CraftInventory(this); + private String name; public NPCInventory(NPC npc) { this.npc = npc; @@ -103,4 +103,8 @@ public class NPCInventory implements IInventory { public void show(Player player) { ((CraftPlayer) player).getHandle().a(this); } + + public void setName(String name) { + this.name = StringHelper.parseColors(name); + } } \ No newline at end of file diff --git a/src/net/citizensnpcs/trait/Inventory.java b/src/net/citizensnpcs/trait/Inventory.java index 844b0894f..1f154677c 100644 --- a/src/net/citizensnpcs/trait/Inventory.java +++ b/src/net/citizensnpcs/trait/Inventory.java @@ -13,7 +13,7 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; @SaveId("inventory") -public class Inventory implements Trait { +public class Inventory extends Trait { private ItemStack[] contents; public Inventory() { diff --git a/src/net/citizensnpcs/trait/LookClose.java b/src/net/citizensnpcs/trait/LookClose.java index a2875e3ed..1eaaae964 100644 --- a/src/net/citizensnpcs/trait/LookClose.java +++ b/src/net/citizensnpcs/trait/LookClose.java @@ -12,7 +12,7 @@ import net.citizensnpcs.npc.CitizensNPC; import net.minecraft.server.EntityLiving; @SaveId("look-close") -public class LookClose implements Trait, Runnable { +public class LookClose extends Trait implements Runnable { private final NPC npc; private boolean shouldLookClose; diff --git a/src/net/citizensnpcs/util/StringHelper.java b/src/net/citizensnpcs/util/StringHelper.java index 293989b11..3a6f1d2a8 100644 --- a/src/net/citizensnpcs/util/StringHelper.java +++ b/src/net/citizensnpcs/util/StringHelper.java @@ -73,4 +73,8 @@ public class StringHelper { return capitalize.replaceFirst(String.valueOf(capitalize.charAt(0)), String.valueOf(Character.toUpperCase(capitalize.charAt(0)))); } + + public static String wrapHeader(Object string) { + return ChatColor.GREEN + "=====[ " + string.toString() + ChatColor.GREEN + " ]====="; + } } \ No newline at end of file