This commit is contained in:
fullwall 2012-02-27 19:17:10 +08:00
commit ccf0b14547
5 changed files with 52 additions and 21 deletions

View File

@ -138,7 +138,7 @@ public class Citizens extends JavaPlugin {
saveNPCs();
for (NPC npc : npcManager)
npc.despawn();
Bukkit.getScheduler().cancelTasks(this);
getServer().getScheduler().cancelTasks(this);
}
Messaging.log("v" + getDescription().getVersion() + " disabled.");
@ -230,6 +230,16 @@ public class Citizens extends JavaPlugin {
}.start();
}
public void reload() throws NPCLoadException {
getServer().getScheduler().cancelTasks(this);
config.load();
for (NPC npc : npcManager)
npc.despawn();
saves.load();
setupNPCs();
}
public CitizensNPCManager getNPCManager() {
return npcManager;
}

View File

@ -1,12 +1,15 @@
package net.citizensnpcs.command.command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.citizensnpcs.Citizens;
import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.command.Command;
import net.citizensnpcs.command.CommandContext;
import net.citizensnpcs.command.Requirements;
import net.citizensnpcs.command.ServerCommand;
import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.StringHelper;
@ -18,16 +21,33 @@ public class AdminCommands {
this.plugin = plugin;
}
@Command(
aliases = { "citizens" },
desc = "Shows basic plugin information",
max = 0,
permission = "admin")
@Requirements
@Command(aliases = { "citizens" }, desc = "Show basic plugin information", max = 0, permission = "admin")
public void citizens(CommandContext args, Player player, NPC npc) {
Messaging.send(player, " " + StringHelper.wrapHeader("<e>Citizens v" + plugin.getDescription().getVersion()));
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());
}
@Command(
aliases = { "citizens" },
usage = "reload",
desc = "Reload Citizens",
modifiers = { "reload" },
min = 1,
max = 1,
permission = "admin")
@ServerCommand
public void reload(CommandContext args, CommandSender sender, NPC npc) {
// TODO possibly could be made more safe
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();
}
}
}

View File

@ -167,7 +167,7 @@ public class NPCCommands {
@Command(
aliases = { "npc" },
usage = "select [id]",
desc = "Selects an NPC with the given ID",
desc = "Select an NPC with the given ID",
modifiers = { "select" },
min = 2,
max = 2,
@ -190,7 +190,7 @@ public class NPCCommands {
@Command(
aliases = { "npc" },
usage = "character [character]",
desc = "Sets the character of an NPC",
desc = "Set the character of an NPC",
modifiers = { "character" },
min = 2,
max = 2)

View File

@ -32,9 +32,6 @@ public class CitizensNPCManager implements NPCManager {
}
public NPC createNPC(EntityType type, int id, String name, Character character) {
if (npcs.contains(id))
throw new IllegalArgumentException("An NPC already has the ID '" + id + "'.");
CitizensNPC npc = npcBuilder.getByType(type, this, id, name);
npc.setCharacter(character);
npcs.put(npc.getId(), npc);

View File

@ -8,6 +8,7 @@ import net.citizensnpcs.api.trait.trait.Owner;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.google.common.base.Joiner;
@ -28,23 +29,26 @@ public class Messaging {
log(Level.INFO, SPACE.join(msg));
}
public static void send(Player player, Object msg) {
player.sendMessage(StringHelper.parseColors(msg.toString()));
public static void send(CommandSender sender, Object msg) {
sender.sendMessage(StringHelper.parseColors(msg.toString()));
}
public static void sendError(Player player, Object msg) {
send(player, ChatColor.RED.toString() + msg);
public static void sendError(CommandSender sender, Object msg) {
send(sender, ChatColor.RED.toString() + msg);
}
public static void sendWithNPC(Player player, Object msg, NPC npc) {
public static void sendWithNPC(CommandSender sender, Object msg, NPC npc) {
String send = msg.toString();
send = send.replace("<player>", player.getName());
send = send.replace("<world>", player.getWorld().getName());
if (sender instanceof Player) {
Player player = (Player) sender;
send = send.replace("<player>", player.getName());
send = send.replace("<world>", player.getWorld().getName());
}
send = send.replace("<owner>", npc.getTrait(Owner.class).getOwner());
send = send.replace("<npc>", npc.getName());
send = send.replace("<id>", Integer.toString(npc.getId()));
send(player, send);
send(sender, send);
}
}