mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-14 20:21:19 +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]
|
authors: [aPunch, fullwall]
|
||||||
version: 2.0
|
version: 2.0
|
||||||
main: net.citizensnpcs.Citizens
|
main: net.citizensnpcs.Citizens
|
||||||
|
website: http://www.citizensnpcs.net
|
||||||
commands:
|
commands:
|
||||||
citizens:
|
citizens:
|
||||||
description: Administration commands
|
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.api.npc.trait.trait.Spawned;
|
||||||
import net.citizensnpcs.command.CommandManager;
|
import net.citizensnpcs.command.CommandManager;
|
||||||
import net.citizensnpcs.command.Injector;
|
import net.citizensnpcs.command.Injector;
|
||||||
|
import net.citizensnpcs.command.command.AdminCommands;
|
||||||
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.CommandUsageException;
|
import net.citizensnpcs.command.exception.CommandUsageException;
|
||||||
@ -239,6 +240,7 @@ public class Citizens extends JavaPlugin {
|
|||||||
cmdManager.setInjector(new Injector(this));
|
cmdManager.setInjector(new Injector(this));
|
||||||
|
|
||||||
// Register command classes
|
// Register command classes
|
||||||
|
cmdManager.register(AdminCommands.class);
|
||||||
cmdManager.register(NPCCommands.class);
|
cmdManager.register(NPCCommands.class);
|
||||||
cmdManager.register(HelpCommands.class);
|
cmdManager.register(HelpCommands.class);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,33 @@
|
|||||||
package net.citizensnpcs.command.command;
|
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 {
|
public class AdminCommands {
|
||||||
|
private final Citizens plugin;
|
||||||
|
|
||||||
public AdminCommands(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(
|
Messaging.send(
|
||||||
player,
|
player,
|
||||||
StringHelper.parseColors("<a>=====[ <e>"
|
StringHelper.wrapHeader("<e>"
|
||||||
+ (baseCommand.equalsIgnoreCase("npc") ? "NPC" : StringHelper.capitalize(baseCommand
|
+ (baseCommand.equalsIgnoreCase("npc") ? "NPC" : StringHelper.capitalize(baseCommand
|
||||||
.toLowerCase())) + " Help <f>" + page + "/" + pages + " <a>]====="));
|
.toLowerCase())) + " Help <f>" + page + "/" + pages));
|
||||||
|
|
||||||
if (lines.size() < endIndex)
|
if (lines.size() < endIndex)
|
||||||
endIndex = lines.size() - 1;
|
endIndex = lines.size() - 1;
|
||||||
@ -85,8 +85,8 @@ public class HelpCommands {
|
|||||||
for (Command cmd : cmdManager.getCommands(baseCommand)) {
|
for (Command cmd : cmdManager.getCommands(baseCommand)) {
|
||||||
if (cmds.contains(cmd) || !player.hasPermission("citizens." + cmd.permission()))
|
if (cmds.contains(cmd) || !player.hasPermission("citizens." + cmd.permission()))
|
||||||
continue;
|
continue;
|
||||||
lines.add(StringHelper.parseColors("<7>/<c>" + cmd.aliases()[0] + " " + cmd.usage() + " <7>- <e>"
|
lines.add(StringHelper.parseColors("<7>/<c>" + cmd.aliases()[0]
|
||||||
+ cmd.desc()));
|
+ (cmd.usage().isEmpty() ? "" : " " + cmd.usage()) + " <7>- <e>" + cmd.desc()));
|
||||||
if (cmd.modifiers().length > 1)
|
if (cmd.modifiers().length > 1)
|
||||||
cmds.add(cmd);
|
cmds.add(cmd);
|
||||||
}
|
}
|
||||||
|
@ -109,6 +109,25 @@ public class NPCCommands {
|
|||||||
Messaging.send(player, ChatColor.GREEN + "You despawned " + StringHelper.wrap(npc.getName()) + ".");
|
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(
|
@Command(
|
||||||
aliases = { "npc" },
|
aliases = { "npc" },
|
||||||
usage = "select [id]",
|
usage = "select [id]",
|
||||||
@ -189,8 +208,14 @@ public class NPCCommands {
|
|||||||
Messaging.send(player, ChatColor.GREEN + "You teleported to " + StringHelper.wrap(npc.getName()) + ".");
|
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 = {
|
@Command(
|
||||||
"lookclose", "look", "rotate" }, min = 1, max = 1, permission = "npc.look-close")
|
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) {
|
public void toggleNPCLookClose(CommandContext args, Player player, NPC npc) {
|
||||||
LookClose trait = npc.getTrait(LookClose.class);
|
LookClose trait = npc.getTrait(LookClose.class);
|
||||||
trait.toggle();
|
trait.toggle();
|
||||||
|
@ -39,7 +39,7 @@ public abstract class CitizensNPC extends AbstractNPC {
|
|||||||
|
|
||||||
Bukkit.getPluginManager().callEvent(new NPCDespawnEvent(this));
|
Bukkit.getPluginManager().callEvent(new NPCDespawnEvent(this));
|
||||||
|
|
||||||
manager.despawn(this);
|
manager.despawn(this, getTrait(Spawned.class).shouldSpawn());
|
||||||
mcEntity = null;
|
mcEntity = null;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -113,4 +113,10 @@ public abstract class CitizensNPC extends AbstractNPC {
|
|||||||
super.update();
|
super.update();
|
||||||
ai.update();
|
ai.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setName(String name) {
|
||||||
|
super.setName(name);
|
||||||
|
inventory.setName(name);
|
||||||
|
}
|
||||||
}
|
}
|
@ -50,8 +50,9 @@ public class CitizensNPCManager implements NPCManager {
|
|||||||
return createNPC(type, generateUniqueId(), name, character);
|
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());
|
npc.getTrait(SpawnLocation.class).setLocation(npc.getBukkitEntity().getLocation());
|
||||||
|
if (deselect)
|
||||||
selected.removeAll(npc.getId());
|
selected.removeAll(npc.getId());
|
||||||
npc.getBukkitEntity().remove();
|
npc.getBukkitEntity().remove();
|
||||||
}
|
}
|
||||||
@ -111,7 +112,7 @@ public class CitizensNPCManager implements NPCManager {
|
|||||||
|
|
||||||
public void remove(NPC npc) {
|
public void remove(NPC npc) {
|
||||||
if (npc.isSpawned())
|
if (npc.isSpawned())
|
||||||
despawn(npc);
|
despawn(npc, true);
|
||||||
npcs.remove(npc.getId());
|
npcs.remove(npc.getId());
|
||||||
saves.getKey("npc").removeKey("" + npc.getId());
|
saves.getKey("npc").removeKey("" + npc.getId());
|
||||||
selected.removeAll(npc.getId());
|
selected.removeAll(npc.getId());
|
||||||
|
@ -15,9 +15,9 @@ import org.bukkit.inventory.Inventory;
|
|||||||
public class NPCInventory implements IInventory {
|
public class NPCInventory implements IInventory {
|
||||||
private final int size = 36;
|
private final int size = 36;
|
||||||
private final NPC npc;
|
private final NPC npc;
|
||||||
private final String name;
|
|
||||||
private final ItemStack[] contents;
|
private final ItemStack[] contents;
|
||||||
private final Inventory inventory = new CraftInventory(this);
|
private final Inventory inventory = new CraftInventory(this);
|
||||||
|
private String name;
|
||||||
|
|
||||||
public NPCInventory(NPC npc) {
|
public NPCInventory(NPC npc) {
|
||||||
this.npc = npc;
|
this.npc = npc;
|
||||||
@ -103,4 +103,8 @@ public class NPCInventory implements IInventory {
|
|||||||
public void show(Player player) {
|
public void show(Player player) {
|
||||||
((CraftPlayer) player).getHandle().a(this);
|
((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;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@SaveId("inventory")
|
@SaveId("inventory")
|
||||||
public class Inventory implements Trait {
|
public class Inventory extends Trait {
|
||||||
private ItemStack[] contents;
|
private ItemStack[] contents;
|
||||||
|
|
||||||
public Inventory() {
|
public Inventory() {
|
||||||
|
@ -12,7 +12,7 @@ import net.citizensnpcs.npc.CitizensNPC;
|
|||||||
import net.minecraft.server.EntityLiving;
|
import net.minecraft.server.EntityLiving;
|
||||||
|
|
||||||
@SaveId("look-close")
|
@SaveId("look-close")
|
||||||
public class LookClose implements Trait, Runnable {
|
public class LookClose extends Trait implements Runnable {
|
||||||
private final NPC npc;
|
private final NPC npc;
|
||||||
private boolean shouldLookClose;
|
private boolean shouldLookClose;
|
||||||
|
|
||||||
|
@ -73,4 +73,8 @@ public class StringHelper {
|
|||||||
return capitalize.replaceFirst(String.valueOf(capitalize.charAt(0)),
|
return capitalize.replaceFirst(String.valueOf(capitalize.charAt(0)),
|
||||||
String.valueOf(Character.toUpperCase(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