added file headers

This commit is contained in:
aPunch 2012-02-08 06:07:17 -06:00
parent 46a2763a98
commit 4a0d340755
5 changed files with 49 additions and 13 deletions

View File

@ -64,6 +64,7 @@ public class Citizens extends JavaPlugin {
private final CommandManager cmdManager = new CommandManager(); private final CommandManager cmdManager = new CommandManager();
private Settings config; private Settings config;
private Storage saves; private Storage saves;
private Storage templates;
private boolean compatible; private boolean compatible;
private boolean handleMistake(CommandSender sender, String command, String modifier) { private boolean handleMistake(CommandSender sender, String command, String modifier) {
@ -174,7 +175,11 @@ public class Citizens extends JavaPlugin {
if (Setting.USE_DATABASE.asBoolean()) if (Setting.USE_DATABASE.asBoolean())
saves = new DatabaseStorage(); saves = new DatabaseStorage();
else else
saves = new YamlStorage(getDataFolder() + File.separator + "saves.yml"); saves = new YamlStorage(getDataFolder() + File.separator + "saves.yml", "Citizens NPC Storage");
// Templates
templates = new YamlStorage(getDataFolder() + File.separator + "templates.yml", "NPC Templates");
templates.load();
// Register API managers // Register API managers
npcManager = new CitizensNPCManager(saves); npcManager = new CitizensNPCManager(saves);
@ -225,6 +230,14 @@ public class Citizens extends JavaPlugin {
return cmdManager; return cmdManager;
} }
public Storage getStorage() {
return saves;
}
public Storage getTemplates() {
return templates;
}
private void registerCommands() { private void registerCommands() {
cmdManager.setInjector(new Injector(this)); cmdManager.setInjector(new Injector(this));

View File

@ -10,7 +10,7 @@ public class Settings {
private final YamlStorage config; private final YamlStorage config;
public Settings(Citizens plugin) { public Settings(Citizens plugin) {
config = new YamlStorage(plugin.getDataFolder() + File.separator + "config.yml"); config = new YamlStorage(plugin.getDataFolder() + File.separator + "config.yml", "Citizens Configuration");
} }
public void load() { public void load() {

View File

@ -0,0 +1,15 @@
package net.citizensnpcs;
import net.citizensnpcs.api.DataKey;
public class Template {
private final DataKey template;
public Template(DataKey template) {
this.template = template;
}
public void apply(DataKey to) {
// TODO
}
}

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.command.command;
import net.citizensnpcs.Citizens; import net.citizensnpcs.Citizens;
import net.citizensnpcs.Settings.Setting; import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.Template;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.trait.Character; import net.citizensnpcs.api.npc.trait.Character;
import net.citizensnpcs.api.npc.trait.DefaultInstanceFactory; import net.citizensnpcs.api.npc.trait.DefaultInstanceFactory;
@ -23,21 +24,23 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
@Requirements(selected = true, ownership = true) @Requirements(selected = true, ownership = true)
public class NPCCommands { public class NPCCommands {
private final Citizens plugin;
private final CitizensNPCManager npcManager; private final CitizensNPCManager npcManager;
private final DefaultInstanceFactory<Character> characterManager; private final DefaultInstanceFactory<Character> characterManager;
public NPCCommands(Citizens plugin) { public NPCCommands(Citizens plugin) {
this.plugin = plugin;
npcManager = plugin.getNPCManager(); npcManager = plugin.getNPCManager();
characterManager = plugin.getCharacterManager(); characterManager = plugin.getCharacterManager();
} }
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "create [name] --type (type) --char (character)", usage = "create [name] --type (type) --char (character) --temp (template)",
desc = "Create a new NPC", desc = "Create a new NPC",
modifiers = { "create" }, modifiers = { "create" },
min = 2, min = 2,
max = 4, max = 5,
permission = "npc.create") permission = "npc.create")
@Requirements @Requirements
public void createNPC(CommandContext args, Player player, NPC npc) { public void createNPC(CommandContext args, Player player, NPC npc) {
@ -68,6 +71,16 @@ public class NPCCommands {
successMsg += " with the character " + StringHelper.wrap(args.getFlag("char")); successMsg += " with the character " + StringHelper.wrap(args.getFlag("char"));
} }
} }
if (args.hasValueFlag("temp")) {
String template = args.getFlag("temp");
if (!plugin.getTemplates().getKey("templates").keyExists(template)) {
Messaging.sendError(player, "The template '" + template
+ "' does not exist. Did you type the name incorrectly?");
return;
}
new Template(plugin.getTemplates().getKey("templates." + template)).apply(plugin.getStorage().getKey(
"npc." + npc.getId()));
}
successMsg += " at your location."; successMsg += " at your location.";
// Set the owner // Set the owner
@ -176,14 +189,8 @@ 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( @Command(aliases = { "npc" }, usage = "lookclose", desc = "Toggle an NPC's look-close state", modifiers = {
aliases = { "npc" }, "lookclose", "look", "rotate" }, min = 1, max = 1, permission = "npc.look-close")
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();

View File

@ -18,11 +18,12 @@ public class YamlStorage implements Storage {
private final FileConfiguration config; private final FileConfiguration config;
private final File file; private final File file;
public YamlStorage(String fileName) { public YamlStorage(String fileName, String header) {
config = new YamlConfiguration(); config = new YamlConfiguration();
file = new File(fileName); file = new File(fileName);
if (!file.exists()) { if (!file.exists()) {
create(); create();
config.options().header(header);
save(); save();
} else } else
load(); load();