added file headers

This commit is contained in:
aPunch 2012-02-08 06:07:17 -06:00
parent efaa462894
commit 7566a15966
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 Settings config;
private Storage saves;
private Storage templates;
private boolean compatible;
private boolean handleMistake(CommandSender sender, String command, String modifier) {
@ -174,7 +175,11 @@ public class Citizens extends JavaPlugin {
if (Setting.USE_DATABASE.asBoolean())
saves = new DatabaseStorage();
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
npcManager = new CitizensNPCManager(saves);
@ -225,6 +230,14 @@ public class Citizens extends JavaPlugin {
return cmdManager;
}
public Storage getStorage() {
return saves;
}
public Storage getTemplates() {
return templates;
}
private void registerCommands() {
cmdManager.setInjector(new Injector(this));

View File

@ -10,7 +10,7 @@ public class Settings {
private final YamlStorage config;
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() {

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.Settings.Setting;
import net.citizensnpcs.Template;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.trait.Character;
import net.citizensnpcs.api.npc.trait.DefaultInstanceFactory;
@ -23,21 +24,23 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
@Requirements(selected = true, ownership = true)
public class NPCCommands {
private final Citizens plugin;
private final CitizensNPCManager npcManager;
private final DefaultInstanceFactory<Character> characterManager;
public NPCCommands(Citizens plugin) {
this.plugin = plugin;
npcManager = plugin.getNPCManager();
characterManager = plugin.getCharacterManager();
}
@Command(
aliases = { "npc" },
usage = "create [name] --type (type) --char (character)",
usage = "create [name] --type (type) --char (character) --temp (template)",
desc = "Create a new NPC",
modifiers = { "create" },
min = 2,
max = 4,
max = 5,
permission = "npc.create")
@Requirements
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"));
}
}
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.";
// Set the owner
@ -176,14 +189,8 @@ 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();

View File

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