mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-14 04:02:01 +01:00
Merge branch 'master' of http://www.github.com/aPunch/Citizens2
This commit is contained in:
commit
da147f39f3
Binary file not shown.
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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("<e>Citizens v" + plugin.getDescription().getVersion()));
|
||||
Messaging.send(player, " <7>-- <c>Written by fullwall and aPunch");
|
||||
Messaging.send(player, " <7>-- <c>Source: http://github.com/CitizensDev");
|
||||
Messaging.send(player, " <7>-- <c>Website: " + plugin.getDescription().getWebsite());
|
||||
}
|
||||
}
|
@ -67,9 +67,9 @@ public class HelpCommands {
|
||||
|
||||
Messaging.send(
|
||||
player,
|
||||
StringHelper.parseColors("<a>=====[ <e>"
|
||||
StringHelper.wrapHeader("<e>"
|
||||
+ (baseCommand.equalsIgnoreCase("npc") ? "NPC" : StringHelper.capitalize(baseCommand
|
||||
.toLowerCase())) + " Help <f>" + page + "/" + pages + " <a>]====="));
|
||||
.toLowerCase())) + " Help <f>" + 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>/<c>" + cmd.aliases()[0] + " " + cmd.usage() + " <7>- <e>"
|
||||
+ cmd.desc()));
|
||||
lines.add(StringHelper.parseColors("<7>/<c>" + cmd.aliases()[0]
|
||||
+ (cmd.usage().isEmpty() ? "" : " " + cmd.usage()) + " <7>- <e>" + cmd.desc()));
|
||||
if (cmd.modifiers().length > 1)
|
||||
cmds.add(cmd);
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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());
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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() {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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 + " ]=====";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user