From acbecb8c56429cbc46b4a41fa66d4a05cd059ba7 Mon Sep 17 00:00:00 2001 From: aPunch Date: Thu, 19 Jan 2012 05:43:21 -0600 Subject: [PATCH] use spaces --- build.xml | 5 +- src/net/citizensnpcs/Citizens.java | 120 +++--- src/net/citizensnpcs/EventListen.java | 102 ++--- src/net/citizensnpcs/npc/CitizensNPC.java | 279 ++++++------ .../citizensnpcs/npc/CitizensNPCManager.java | 146 +++---- .../npc/trait/CitizensCharacterManager.java | 54 +-- .../citizensnpcs/resources/lib/CraftNPC.java | 36 +- .../resources/lib/NPCNetHandler.java | 108 ++--- .../resources/lib/NPCNetworkManager.java | 64 +-- .../citizensnpcs/resources/lib/NPCSocket.java | 16 +- src/net/citizensnpcs/storage/Storage.java | 6 +- .../storage/database/DatabaseStorage.java | 204 ++++----- .../storage/flatfile/YamlStorage.java | 408 +++++++++--------- src/net/citizensnpcs/util/Messaging.java | 20 +- 14 files changed, 782 insertions(+), 786 deletions(-) diff --git a/build.xml b/build.xml index 654be6ca5..2c6af3fc7 100644 --- a/build.xml +++ b/build.xml @@ -1,6 +1,6 @@ - Citizens build file + Citizens build file @@ -13,7 +13,8 @@ - + diff --git a/src/net/citizensnpcs/Citizens.java b/src/net/citizensnpcs/Citizens.java index df7e08f7e..108623741 100644 --- a/src/net/citizensnpcs/Citizens.java +++ b/src/net/citizensnpcs/Citizens.java @@ -22,72 +22,72 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; public class Citizens extends JavaPlugin { - private CitizensNPCManager npcManager; - private CitizensCharacterManager characterManager; - private Storage saves; + private CitizensNPCManager npcManager; + private CitizensCharacterManager characterManager; + private Storage saves; - @Override - public void onDisable() { - Messaging.log("v" + getDescription().getVersion() + " disabled."); - } + @Override + public void onDisable() { + Messaging.log("v" + getDescription().getVersion() + " disabled."); + } - @Override - public void onEnable() { - npcManager = new CitizensNPCManager(); - characterManager = new CitizensCharacterManager(); - CitizensAPI.setNPCManager(npcManager); - CitizensAPI.setCharacterManager(characterManager); + @Override + public void onEnable() { + npcManager = new CitizensNPCManager(); + characterManager = new CitizensCharacterManager(); + CitizensAPI.setNPCManager(npcManager); + CitizensAPI.setCharacterManager(characterManager); - // TODO database support - saves = new YamlStorage(getDataFolder() + File.separator + "saves.yml"); + // TODO database support + saves = new YamlStorage(getDataFolder() + File.separator + "saves.yml"); - // Register events - new EventListen(this); + // Register events + new EventListen(this); - Messaging.log("v" + getDescription().getVersion() + " enabled."); + Messaging.log("v" + getDescription().getVersion() + " enabled."); - // Setup NPCs after all plugins have been enabled (allows for multiworld - // support and for NPCs to properly register external settings) - if (Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { - @Override - public void run() { - try { - setupNPCs(); - } catch (NPCLoadException ex) { - ex.printStackTrace(); - } - } - }, /* TODO how long should delay be? */100) == -1) { - Messaging.log("Issue enabling plugin. Disabling."); - getServer().getPluginManager().disablePlugin(this); - } - } + // Setup NPCs after all plugins have been enabled (allows for multiworld + // support and for NPCs to properly register external settings) + if (Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { + @Override + public void run() { + try { + setupNPCs(); + } catch (NPCLoadException ex) { + ex.printStackTrace(); + } + } + }, /* TODO how long should delay be? */100) == -1) { + Messaging.log("Issue enabling plugin. Disabling."); + getServer().getPluginManager().disablePlugin(this); + } + } - @Override - public boolean onCommand(CommandSender sender, Command cmd, String cmdName, String[] args) { - if (args[0].equals("test")) { - NPC npc = npcManager.createNPC("aPunch"); - npc.spawn(((Player) sender).getLocation()); - } - return true; - } + @Override + public boolean onCommand(CommandSender sender, Command cmd, String cmdName, String[] args) { + if (args[0].equals("test")) { + NPC npc = npcManager.createNPC("aPunch"); + npc.spawn(((Player) sender).getLocation()); + } + return true; + } - private void setupNPCs() throws NPCLoadException { - // TODO needs fixing - for (DataKey key : saves.getKey("npc").getIntegerSubKeys()) { - int id = Integer.parseInt(key.name()); - if (!key.keyExists("name")) - throw new NPCLoadException("Could not find a name for the NPC with ID '" + id + "'."); - Character character = characterManager.getCharacter(key.getString("character")); - NPC npc = npcManager.createNPC(key.getString("name"), character); - if (character != null) { - character.load(key); - } - for (Trait t : npc.getTraits()) { - t.load(key); - } - npc.spawn(npc.getTrait(LocationTrait.class).getLocation()); - } - Messaging.log("Loaded " + npcManager.getNPCs().size() + " NPCs."); - } + private void setupNPCs() throws NPCLoadException { + // TODO needs fixing + for (DataKey key : saves.getKey("npc").getIntegerSubKeys()) { + int id = Integer.parseInt(key.name()); + if (!key.keyExists("name")) + throw new NPCLoadException("Could not find a name for the NPC with ID '" + id + "'."); + Character character = characterManager.getCharacter(key.getString("character")); + NPC npc = npcManager.createNPC(key.getString("name"), character); + if (character != null) { + character.load(key); + } + for (Trait t : npc.getTraits()) { + t.load(key); + } + npc.spawn(npc.getTrait(LocationTrait.class).getLocation()); + } + Messaging.log("Loaded " + npcManager.getNPCs().size() + " NPCs."); + } } \ No newline at end of file diff --git a/src/net/citizensnpcs/EventListen.java b/src/net/citizensnpcs/EventListen.java index 5f846f955..2a007ac5e 100644 --- a/src/net/citizensnpcs/EventListen.java +++ b/src/net/citizensnpcs/EventListen.java @@ -18,63 +18,63 @@ import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.ChunkUnloadEvent; public class EventListen implements Listener { - private Set toRespawn = new HashSet(); + private Set toRespawn = new HashSet(); - public EventListen(Citizens plugin) { - plugin.getServer().getPluginManager().registerEvents(this, plugin); - } + public EventListen(Citizens plugin) { + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } - /* - * Entity events - */ - @EventHandler() - public void onEntityDamage(EntityDamageEvent event) { - if (event.isCancelled() || !CitizensAPI.getNPCManager().isNPC(event.getEntity())) - return; + /* + * Entity events + */ + @EventHandler + public void onEntityDamage(EntityDamageEvent event) { + if (event.isCancelled() || !CitizensAPI.getNPCManager().isNPC(event.getEntity())) + return; - if (event instanceof EntityDamageByEntityEvent) { - EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event; - if (e.getDamager() instanceof Player) { - NPC npc = CitizensAPI.getNPCManager().getNPC(event.getEntity()); - npc.getCharacter().onLeftClick(npc, (Player) e.getDamager()); - } - } - } + if (event instanceof EntityDamageByEntityEvent) { + EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event; + if (e.getDamager() instanceof Player) { + NPC npc = CitizensAPI.getNPCManager().getNPC(event.getEntity()); + npc.getCharacter().onLeftClick(npc, (Player) e.getDamager()); + } + } + } - @EventHandler() - public void onEntityTarget(EntityTargetEvent event) { - if (event.isCancelled() || !CitizensAPI.getNPCManager().isNPC(event.getEntity()) - || !(event.getTarget() instanceof Player)) - return; + @EventHandler + public void onEntityTarget(EntityTargetEvent event) { + if (event.isCancelled() || !CitizensAPI.getNPCManager().isNPC(event.getEntity()) + || !(event.getTarget() instanceof Player)) + return; - NPC npc = CitizensAPI.getNPCManager().getNPC(event.getEntity()); - npc.getCharacter().onRightClick(npc, (Player) event.getTarget()); - } + NPC npc = CitizensAPI.getNPCManager().getNPC(event.getEntity()); + npc.getCharacter().onRightClick(npc, (Player) event.getTarget()); + } - /* - * World events - */ - @EventHandler() - public void onChunkLoad(ChunkLoadEvent event) { - for (int id : toRespawn) { - NPC npc = CitizensAPI.getNPCManager().getNPC(id); - npc.spawn(npc.getTrait(LocationTrait.class).getLocation()); - toRespawn.remove(id); - } - } + /* + * World events + */ + @EventHandler + public void onChunkLoad(ChunkLoadEvent event) { + for (int id : toRespawn) { + NPC npc = CitizensAPI.getNPCManager().getNPC(id); + npc.spawn(npc.getTrait(LocationTrait.class).getLocation()); + toRespawn.remove(id); + } + } - @EventHandler() - public void onChunkUnload(ChunkUnloadEvent event) { - if (event.isCancelled()) - return; + @EventHandler + public void onChunkUnload(ChunkUnloadEvent event) { + if (event.isCancelled()) + return; - for (NPC npc : CitizensAPI.getNPCManager().getNPCs()) { - Location loc = npc.getTrait(LocationTrait.class).getLocation(); - if (event.getWorld().equals(loc.getWorld()) && event.getChunk().getX() == loc.getChunk().getX() - && event.getChunk().getZ() == loc.getChunk().getZ()) { - toRespawn.add(npc.getId()); - npc.despawn(); - } - } - } + for (NPC npc : CitizensAPI.getNPCManager().getNPCs()) { + Location loc = npc.getTrait(LocationTrait.class).getLocation(); + if (event.getWorld().equals(loc.getWorld()) && event.getChunk().getX() == loc.getChunk().getX() + && event.getChunk().getZ() == loc.getChunk().getZ()) { + toRespawn.add(npc.getId()); + npc.despawn(); + } + } + } } \ No newline at end of file diff --git a/src/net/citizensnpcs/npc/CitizensNPC.java b/src/net/citizensnpcs/npc/CitizensNPC.java index eefc7040a..edb5f2cf7 100644 --- a/src/net/citizensnpcs/npc/CitizensNPC.java +++ b/src/net/citizensnpcs/npc/CitizensNPC.java @@ -19,172 +19,167 @@ import org.bukkit.ChatColor; import org.bukkit.Location; public class CitizensNPC implements NPC { - private final int id; - private Character character = null; - private final Map, Trait> traits = new HashMap, Trait>(); - private String name; - private CraftNPC mcEntity; - private boolean spawned; - private final CitizensNPCManager manager; - private final Factory factory = new Factory(); + private final int id; + private Character character = null; + private final Map, Trait> traits = new HashMap, Trait>(); + private String name; + private CraftNPC mcEntity; + private boolean spawned; + private final CitizensNPCManager manager; + private final Factory factory = new Factory(); - public CitizensNPC(String name, Character character) { - this.name = name; - this.character = character; - manager = (CitizensNPCManager) CitizensAPI.getNPCManager(); - id = manager.getUniqueID(); - } + public CitizensNPC(String name, Character character) { + this.name = name; + this.character = character; + manager = (CitizensNPCManager) CitizensAPI.getNPCManager(); + id = manager.getUniqueID(); + } - public CitizensNPC(int id, String name, Character character) { - this.name = name; - this.character = character; - manager = (CitizensNPCManager) CitizensAPI.getNPCManager(); - this.id = id; - } + public CitizensNPC(int id, String name, Character character) { + this.name = name; + this.character = character; + manager = (CitizensNPCManager) CitizensAPI.getNPCManager(); + this.id = id; + } - @Override - public String getFullName() { - return name; - } + @Override + public String getFullName() { + return name; + } - @Override - public String getName() { - return ChatColor.stripColor(name); - } + @Override + public String getName() { + return ChatColor.stripColor(name); + } - @Override - public void setName(String name) { - this.name = name; - } + @Override + public void setName(String name) { + this.name = name; + } - @Override - public void addTrait(Class trait) { - if (!hasTrait(trait)) - traits.put(trait, factory.create(trait)); - else - Messaging.debug("The NPC already has the trait '" + trait.getName() + "'."); - } + @Override + public void addTrait(Class trait) { + if (!hasTrait(trait)) + traits.put(trait, factory.create(trait)); + else + Messaging.debug("The NPC already has the trait '" + trait.getName() + "'."); + } - @Override - public Character getCharacter() { - return character; - } + @Override + public Character getCharacter() { + return character; + } - @Override - public int getId() { - return id; - } + @Override + public int getId() { + return id; + } - @Override - public Navigator getNavigator() { - // TODO add default navigator - return null; - } + @Override + public Navigator getNavigator() { + // TODO add default navigator + return null; + } - @Override - public T getTrait(Class trait) { - Trait t = traits.get(trait); - if (t != null) { - return trait.cast(t); - } + @Override + public T getTrait(Class trait) { + Trait t = traits.get(trait); + if (t != null) { + return trait.cast(t); + } - T create = factory.create(trait); - addTrait(trait); - return create; - } + T create = factory.create(trait); + addTrait(trait); + return create; + } - @Override - public Iterable getTraits() { - return traits.values(); - } + @Override + public Iterable getTraits() { + return traits.values(); + } - @Override - public boolean hasTrait(Class trait) { - return traits.containsKey(trait); - } + @Override + public boolean hasTrait(Class trait) { + return traits.containsKey(trait); + } - @Override - public void removeTrait(Class trait) { - if (!hasTrait(trait)) { - Messaging.debug("The NPC does not have a trait with the name of '" + trait.getName() + "."); - return; - } - traits.remove(trait); - } + @Override + public void removeTrait(Class trait) { + if (!hasTrait(trait)) { + Messaging.debug("The NPC does not have a trait with the name of '" + trait.getName() + "."); + return; + } + traits.remove(trait); + } - @Override - public void setCharacter(Character character) { - if (this.character.equals(character)) { - Messaging.debug("The NPC already has the character '" + character.getName() + "'."); - return; - } - this.character = character; - } + @Override + public void setCharacter(Character character) { + if (this.character.equals(character)) { + Messaging.debug("The NPC already has the character '" + character.getName() + "'."); + return; + } + this.character = character; + } - @Override - public boolean isSpawned() { - return spawned; - } + @Override + public boolean isSpawned() { + return spawned; + } - @Override - public void spawn(Location loc) { - if (isSpawned()) { - System.out.println("The NPC is already spawned."); - return; - } + @Override + public void spawn(Location loc) { + if (isSpawned()) { + Messaging.debug("The NPC is already spawned."); + return; + } - NPCSpawnEvent spawnEvent = new NPCSpawnEvent(this, loc); - Bukkit.getPluginManager().callEvent(spawnEvent); - if (spawnEvent.isCancelled()) { - return; - } + NPCSpawnEvent spawnEvent = new NPCSpawnEvent(this, loc); + Bukkit.getPluginManager().callEvent(spawnEvent); + if (spawnEvent.isCancelled()) { + return; + } - spawned = true; - getTrait(LocationTrait.class).setLocation(loc); - mcEntity = manager.spawn(this, loc); - } + spawned = true; + getTrait(LocationTrait.class).setLocation(loc); + mcEntity = manager.spawn(this, loc); + } - @Override - public void despawn() { - if (!isSpawned()) { - System.out.println("The NPC is already despawned."); - return; - } + @Override + public void despawn() { + if (!isSpawned()) { + Messaging.debug("The NPC is already despawned."); + return; + } - Bukkit.getPluginManager().callEvent(new NPCDespawnEvent(this)); + Bukkit.getPluginManager().callEvent(new NPCDespawnEvent(this)); - spawned = false; - mcEntity.die(); - manager.despawn(this); - } + spawned = false; + mcEntity.die(); + manager.despawn(this); + } - @Override - public void remove() { - if (isSpawned()) { - despawn(); - } - manager.remove(this); - } + @Override + public void remove() { + if (isSpawned()) { + despawn(); + } + manager.remove(this); + } - public CraftNPC getHandle() { - return mcEntity; - } + public CraftNPC getHandle() { + return mcEntity; + } - private class Factory { - private final Map, Trait> created = new HashMap, Trait>(); + private class Factory { - public T create(Class clazz) { - if (created.containsKey(clazz)) { - return clazz.cast(created.get(clazz)); - } - try { - Trait trait = clazz.newInstance(); - created.put(clazz, trait); - return clazz.cast(trait); - } catch (Exception ex) { - ex.printStackTrace(); - return null; - } - } - } + public T create(Class clazz) { + try { + Trait trait = clazz.newInstance(); + return clazz.cast(trait); + } catch (Exception ex) { + ex.printStackTrace(); + return null; + } + } + } } \ No newline at end of file diff --git a/src/net/citizensnpcs/npc/CitizensNPCManager.java b/src/net/citizensnpcs/npc/CitizensNPCManager.java index af804b80b..5a1e6b346 100644 --- a/src/net/citizensnpcs/npc/CitizensNPCManager.java +++ b/src/net/citizensnpcs/npc/CitizensNPCManager.java @@ -25,91 +25,91 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.server.WorldServer; public class CitizensNPCManager implements NPCManager { - private Map spawned = new HashMap(); - private Map byID = new HashMap(); + private Map spawned = new HashMap(); + private Map byID = new HashMap(); - @Override - public NPC createNPC(String name) { - return createNPC(name, null); - } + @Override + public NPC createNPC(String name) { + return createNPC(name, null); + } - @Override - public NPC createNPC(String name, Character character) { - CitizensNPC npc = new CitizensNPC(name, character); - byID.put(npc.getId(), npc); - return npc; - } + @Override + public NPC createNPC(String name, Character character) { + CitizensNPC npc = new CitizensNPC(name, character); + byID.put(npc.getId(), npc); + return npc; + } - @Override - public NPC getNPC(int id) { - return byID.get(id); - } + @Override + public NPC getNPC(int id) { + return byID.get(id); + } - @Override - public NPC getNPC(Entity entity) { - return spawned.get(entity); - } + @Override + public NPC getNPC(Entity entity) { + return spawned.get(entity); + } - @Override - public Collection getNPCs() { - return spawned.values(); - } + @Override + public Collection getNPCs() { + return spawned.values(); + } - @Override - public Collection getNPCs(Class trait) { - Set npcs = new HashSet(); - for (NPC npc : spawned.values()) { - if (npc.hasTrait(trait)) - npcs.add(npc); - } - return npcs; - } + @Override + public Collection getNPCs(Class trait) { + Set npcs = new HashSet(); + for (NPC npc : spawned.values()) { + if (npc.hasTrait(trait)) + npcs.add(npc); + } + return npcs; + } - @Override - public boolean isNPC(Entity entity) { - return spawned.containsKey(entity); - } + @Override + public boolean isNPC(Entity entity) { + return spawned.containsKey(entity); + } - public int getUniqueID() { - int count = 0; - while (true) { - if (getNPC(count) == null) - break; - count++; - } - return count; - } + public int getUniqueID() { + int count = 0; + while (true) { + if (getNPC(count) == null) + break; + count++; + } + return count; + } - public CraftNPC spawn(NPC npc, Location loc) { - WorldServer ws = getWorldServer(loc.getWorld()); - CraftNPC mcEntity = new CraftNPC(getMinecraftServer(ws.getServer()), ws, npc.getFullName(), - new ItemInWorldManager(ws)); - mcEntity.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); - ws.addEntity(mcEntity); - ws.players.remove(mcEntity); + public CraftNPC spawn(NPC npc, Location loc) { + WorldServer ws = getWorldServer(loc.getWorld()); + CraftNPC mcEntity = new CraftNPC(getMinecraftServer(ws.getServer()), ws, npc.getFullName(), + new ItemInWorldManager(ws)); + mcEntity.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); + ws.addEntity(mcEntity); + ws.players.remove(mcEntity); - spawned.put(mcEntity.getPlayer(), npc); - return mcEntity; - } + spawned.put(mcEntity.getPlayer(), npc); + return mcEntity; + } - public void despawn(NPC npc) { - CraftNPC mcEntity = ((CitizensNPC) npc).getHandle(); - // TODO send Packet29DestroyEntity - getWorldServer(npc.getTrait(LocationTrait.class).getLocation().getWorld()).removeEntity(mcEntity); - spawned.remove(mcEntity.getPlayer()); - } + public void despawn(NPC npc) { + CraftNPC mcEntity = ((CitizensNPC) npc).getHandle(); + // TODO send Packet29DestroyEntity + getWorldServer(npc.getTrait(LocationTrait.class).getLocation().getWorld()).removeEntity(mcEntity); + spawned.remove(mcEntity.getPlayer()); + } - public void remove(NPC npc) { - if (spawned.containsKey(((CitizensNPC) npc).getHandle())) - despawn(npc); - byID.remove(npc.getId()); - } + public void remove(NPC npc) { + if (spawned.containsKey(((CitizensNPC) npc).getHandle())) + despawn(npc); + byID.remove(npc.getId()); + } - private WorldServer getWorldServer(World world) { - return ((CraftWorld) world).getHandle(); - } + private WorldServer getWorldServer(World world) { + return ((CraftWorld) world).getHandle(); + } - private MinecraftServer getMinecraftServer(Server server) { - return ((CraftServer) server).getServer(); - } + private MinecraftServer getMinecraftServer(Server server) { + return ((CraftServer) server).getServer(); + } } \ No newline at end of file diff --git a/src/net/citizensnpcs/npc/trait/CitizensCharacterManager.java b/src/net/citizensnpcs/npc/trait/CitizensCharacterManager.java index 30fa440d6..7cabea042 100644 --- a/src/net/citizensnpcs/npc/trait/CitizensCharacterManager.java +++ b/src/net/citizensnpcs/npc/trait/CitizensCharacterManager.java @@ -9,33 +9,33 @@ import net.citizensnpcs.api.npc.trait.Character; import net.citizensnpcs.api.npc.trait.CharacterManager; public class CitizensCharacterManager implements CharacterManager { - private final Map> registered = new HashMap>(); - private final Set characters = new HashSet(); + private final Map> registered = new HashMap>(); + private final Set characters = new HashSet(); - @Override - public Character getCharacter(String name) { - if (registered.get(name) == null) { - return null; - } - for (Character character : characters) { - if (character.getName().equals(name)) { - return character; - } - } - return null; - } + @Override + public Character getCharacter(String name) { + if (registered.get(name) == null) { + return null; + } + for (Character character : characters) { + if (character.getName().equals(name)) { + return character; + } + } + return null; + } - @Override - public void registerCharacter(Class character) { - if (registered.containsValue(character)) { - return; - } - try { - Character register = character.newInstance(); - registered.put(register.getName(), character); - characters.add(register); - } catch (Exception ex) { - ex.printStackTrace(); - } - } + @Override + public void registerCharacter(Class character) { + if (registered.containsValue(character)) { + return; + } + try { + Character register = character.newInstance(); + registered.put(register.getName(), character); + characters.add(register); + } catch (Exception ex) { + ex.printStackTrace(); + } + } } \ No newline at end of file diff --git a/src/net/citizensnpcs/resources/lib/CraftNPC.java b/src/net/citizensnpcs/resources/lib/CraftNPC.java index 9a325c834..539dd91fe 100644 --- a/src/net/citizensnpcs/resources/lib/CraftNPC.java +++ b/src/net/citizensnpcs/resources/lib/CraftNPC.java @@ -11,25 +11,25 @@ import net.minecraft.server.World; public class CraftNPC extends EntityPlayer { - public CraftNPC(MinecraftServer minecraftServer, World world, String string, ItemInWorldManager itemInWorldManager) { - super(minecraftServer, world, string, itemInWorldManager); - itemInWorldManager.setGameMode(0); + public CraftNPC(MinecraftServer minecraftServer, World world, String string, ItemInWorldManager itemInWorldManager) { + super(minecraftServer, world, string, itemInWorldManager); + itemInWorldManager.setGameMode(0); - NPCSocket socket = new NPCSocket(); + NPCSocket socket = new NPCSocket(); - NetworkManager netMgr = new NPCNetworkManager(socket, "npc mgr", new NetHandler() { - @Override - public boolean c() { - return false; - } - }); - netServerHandler = new NPCNetHandler(minecraftServer, netMgr, this); - netMgr.a(netServerHandler); + NetworkManager netMgr = new NPCNetworkManager(socket, "npc mgr", new NetHandler() { + @Override + public boolean c() { + return false; + } + }); + netServerHandler = new NPCNetHandler(minecraftServer, netMgr, this); + netMgr.a(netServerHandler); - try { - socket.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } + try { + socket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } } \ No newline at end of file diff --git a/src/net/citizensnpcs/resources/lib/NPCNetHandler.java b/src/net/citizensnpcs/resources/lib/NPCNetHandler.java index 8b18df425..4ac02e089 100644 --- a/src/net/citizensnpcs/resources/lib/NPCNetHandler.java +++ b/src/net/citizensnpcs/resources/lib/NPCNetHandler.java @@ -20,75 +20,75 @@ import net.minecraft.server.Packet51MapChunk; public class NPCNetHandler extends NetServerHandler { - public NPCNetHandler(MinecraftServer minecraftServer, NetworkManager networkManager, EntityPlayer entityPlayer) { - super(minecraftServer, networkManager, entityPlayer); - } + public NPCNetHandler(MinecraftServer minecraftServer, NetworkManager networkManager, EntityPlayer entityPlayer) { + super(minecraftServer, networkManager, entityPlayer); + } - @Override - public void a() { - } + @Override + public void a() { + } - @Override - public void sendMessage(String string) { - } + @Override + public void sendMessage(String string) { + } - @Override - public void a(String string, Object[] objects) { - } + @Override + public void a(String string, Object[] objects) { + } - @Override - public void a(Packet packet) { - } + @Override + public void a(Packet packet) { + } - @Override - public void sendPacket(Packet packet) { - } + @Override + public void sendPacket(Packet packet) { + } - @Override - public void a(Packet3Chat packet) { - } + @Override + public void a(Packet3Chat packet) { + } - @Override - public void a(Packet10Flying packet) { - } + @Override + public void a(Packet10Flying packet) { + } - @Override - public void a(Packet14BlockDig packet) { - } + @Override + public void a(Packet14BlockDig packet) { + } - @Override - public void a(Packet15Place packet) { - } + @Override + public void a(Packet15Place packet) { + } - @Override - public void a(Packet16BlockItemSwitch packet) { - } + @Override + public void a(Packet16BlockItemSwitch packet) { + } - @Override - public void a(Packet28EntityVelocity packet) { - } + @Override + public void a(Packet28EntityVelocity packet) { + } - @Override - public void a(Packet51MapChunk packet) { - } + @Override + public void a(Packet51MapChunk packet) { + } - @Override - public void a(Packet101CloseWindow packet) { - } + @Override + public void a(Packet101CloseWindow packet) { + } - @Override - public void a(Packet102WindowClick packet) { - } + @Override + public void a(Packet102WindowClick packet) { + } - @Override - public void a(Packet106Transaction packet) { - } + @Override + public void a(Packet106Transaction packet) { + } - @Override - public void a(Packet255KickDisconnect packet) { - } + @Override + public void a(Packet255KickDisconnect packet) { + } - @Override - public void a(Packet130UpdateSign packet) { - } + @Override + public void a(Packet130UpdateSign packet) { + } } \ No newline at end of file diff --git a/src/net/citizensnpcs/resources/lib/NPCNetworkManager.java b/src/net/citizensnpcs/resources/lib/NPCNetworkManager.java index fd256313a..1521ba6c9 100644 --- a/src/net/citizensnpcs/resources/lib/NPCNetworkManager.java +++ b/src/net/citizensnpcs/resources/lib/NPCNetworkManager.java @@ -9,44 +9,44 @@ import net.minecraft.server.Packet; public class NPCNetworkManager extends NetworkManager { - public NPCNetworkManager(Socket socket, String string, NetHandler netHandler) { - super(socket, string, netHandler); + public NPCNetworkManager(Socket socket, String string, NetHandler netHandler) { + super(socket, string, netHandler); - try { - // the field above the 3 synchronized lists. - Field f = NetworkManager.class.getDeclaredField("l"); - f.setAccessible(true); - f.set(this, false); - } catch (Exception e) { - } - } + try { + // the field above the 3 synchronized lists + Field f = NetworkManager.class.getDeclaredField("l"); + f.setAccessible(true); + f.set(this, false); + } catch (Exception e) { + } + } - @Override - public void a(NetHandler netHandler) { - } + @Override + public void a(NetHandler netHandler) { + } - @Override - public void queue(Packet packet) { - } + @Override + public void queue(Packet packet) { + } - @Override - public void a(String s, Object... objects) { - } + @Override + public void a(String s, Object... objects) { + } - @Override - public void a() { - } + @Override + public void a() { + } - @Override - public void b() { - } + @Override + public void b() { + } - @Override - public void d() { - } + @Override + public void d() { + } - @Override - public int e() { - return 0; - } + @Override + public int e() { + return 0; + } } \ No newline at end of file diff --git a/src/net/citizensnpcs/resources/lib/NPCSocket.java b/src/net/citizensnpcs/resources/lib/NPCSocket.java index cc007d7dd..cc78eed86 100644 --- a/src/net/citizensnpcs/resources/lib/NPCSocket.java +++ b/src/net/citizensnpcs/resources/lib/NPCSocket.java @@ -8,13 +8,13 @@ import java.net.Socket; public class NPCSocket extends Socket { - @Override - public InputStream getInputStream() { - return new ByteArrayInputStream(new byte[10]); - } + @Override + public InputStream getInputStream() { + return new ByteArrayInputStream(new byte[10]); + } - @Override - public OutputStream getOutputStream() { - return new ByteArrayOutputStream(); - } + @Override + public OutputStream getOutputStream() { + return new ByteArrayOutputStream(); + } } \ No newline at end of file diff --git a/src/net/citizensnpcs/storage/Storage.java b/src/net/citizensnpcs/storage/Storage.java index 018f3f080..c2db6d550 100644 --- a/src/net/citizensnpcs/storage/Storage.java +++ b/src/net/citizensnpcs/storage/Storage.java @@ -4,9 +4,9 @@ import net.citizensnpcs.api.DataKey; public interface Storage { - public void load(); + public void load(); - public void save(); + public void save(); - public DataKey getKey(String root); + public DataKey getKey(String root); } \ No newline at end of file diff --git a/src/net/citizensnpcs/storage/database/DatabaseStorage.java b/src/net/citizensnpcs/storage/database/DatabaseStorage.java index 0b5fd7cfc..3bf4a9efc 100644 --- a/src/net/citizensnpcs/storage/database/DatabaseStorage.java +++ b/src/net/citizensnpcs/storage/database/DatabaseStorage.java @@ -7,138 +7,138 @@ import net.citizensnpcs.storage.Storage; public class DatabaseStorage implements Storage { - @Override - public void load() { - // TODO Auto-generated method stub + @Override + public void load() { + // TODO Auto-generated method stub - } + } - @Override - public void save() { - // TODO Auto-generated method stub + @Override + public void save() { + // TODO Auto-generated method stub - } + } - @Override - public DataKey getKey(String root) { - // TODO Auto-generated method stub - return null; - } + @Override + public DataKey getKey(String root) { + // TODO Auto-generated method stub + return null; + } - public class DatabaseKey extends DataKey { + public class DatabaseKey extends DataKey { - @Override - public void copy(String to) { - // TODO Auto-generated method stub + @Override + public void copy(String to) { + // TODO Auto-generated method stub - } + } - @Override - public boolean getBoolean(String key) { - // TODO Auto-generated method stub - return false; - } + @Override + public boolean getBoolean(String key) { + // TODO Auto-generated method stub + return false; + } - @Override - public double getDouble(String key) { - // TODO Auto-generated method stub - return 0; - } + @Override + public double getDouble(String key) { + // TODO Auto-generated method stub + return 0; + } - @Override - public int getInt(String key) { - // TODO Auto-generated method stub - return 0; - } + @Override + public int getInt(String key) { + // TODO Auto-generated method stub + return 0; + } - @Override - public List getIntegerSubKeys() { - // TODO Auto-generated method stub - return null; - } + @Override + public List getIntegerSubKeys() { + // TODO Auto-generated method stub + return null; + } - @Override - public long getLong(String key) { - // TODO Auto-generated method stub - return 0; - } + @Override + public long getLong(String key) { + // TODO Auto-generated method stub + return 0; + } - @Override - public DataKey getRelative(String relative) { - // TODO Auto-generated method stub - return null; - } + @Override + public DataKey getRelative(String relative) { + // TODO Auto-generated method stub + return null; + } - @Override - public String getString(String key) { - // TODO Auto-generated method stub - return null; - } + @Override + public String getString(String key) { + // TODO Auto-generated method stub + return null; + } - @Override - public Iterable getSubKeys() { - // TODO Auto-generated method stub - return null; - } + @Override + public Iterable getSubKeys() { + // TODO Auto-generated method stub + return null; + } - @Override - public boolean keyExists(String key) { - // TODO Auto-generated method stub - return false; - } + @Override + public boolean keyExists(String key) { + // TODO Auto-generated method stub + return false; + } - @Override - public String name() { - // TODO Auto-generated method stub - return null; - } + @Override + public String name() { + // TODO Auto-generated method stub + return null; + } - @Override - public void removeKey(String key) { - // TODO Auto-generated method stub + @Override + public void removeKey(String key) { + // TODO Auto-generated method stub - } + } - @Override - public void setBoolean(String key, boolean value) { - // TODO Auto-generated method stub + @Override + public void setBoolean(String key, boolean value) { + // TODO Auto-generated method stub - } + } - @Override - public void setDouble(String key, double value) { - // TODO Auto-generated method stub + @Override + public void setDouble(String key, double value) { + // TODO Auto-generated method stub - } + } - @Override - public void setInt(String key, int value) { - // TODO Auto-generated method stub + @Override + public void setInt(String key, int value) { + // TODO Auto-generated method stub - } + } - @Override - public void setLong(String key, long value) { - // TODO Auto-generated method stub + @Override + public void setLong(String key, long value) { + // TODO Auto-generated method stub - } + } - @Override - public void setString(String key, String value) { - // TODO Auto-generated method stub + @Override + public void setString(String key, String value) { + // TODO Auto-generated method stub - } + } - @Override - public Object getRaw(String key) { - // TODO Auto-generated method stub - return null; - } + @Override + public Object getRaw(String key) { + // TODO Auto-generated method stub + return null; + } - @Override - public void setRaw(String path, Object value) { - // TODO Auto-generated method stub + @Override + public void setRaw(String path, Object value) { + // TODO Auto-generated method stub - } - } + } + } } \ No newline at end of file diff --git a/src/net/citizensnpcs/storage/flatfile/YamlStorage.java b/src/net/citizensnpcs/storage/flatfile/YamlStorage.java index 5403db3ca..2a8ba9127 100644 --- a/src/net/citizensnpcs/storage/flatfile/YamlStorage.java +++ b/src/net/citizensnpcs/storage/flatfile/YamlStorage.java @@ -16,239 +16,239 @@ import net.citizensnpcs.storage.Storage; import net.citizensnpcs.util.Messaging; public class YamlStorage implements Storage { - private final FileConfiguration config; - private final File file; + private final FileConfiguration config; + private final File file; - public YamlStorage(String fileName) { - config = new YamlConfiguration(); - file = new File(fileName); - if (!file.exists()) { - create(); - save(); - } else - load(); - } + public YamlStorage(String fileName) { + config = new YamlConfiguration(); + file = new File(fileName); + if (!file.exists()) { + create(); + save(); + } else + load(); + } - @Override - public void load() { - try { - config.load(file); - } catch (Exception ex) { - ex.printStackTrace(); - } - } + @Override + public void load() { + try { + config.load(file); + } catch (Exception ex) { + ex.printStackTrace(); + } + } - @Override - public void save() { - try { - config.save(file); - } catch (Exception ex) { - ex.printStackTrace(); - } - } + @Override + public void save() { + try { + config.save(file); + } catch (Exception ex) { + ex.printStackTrace(); + } + } - @Override - public DataKey getKey(String root) { - return new YamlKey(root); - } + @Override + public DataKey getKey(String root) { + return new YamlKey(root); + } - private void create() { - try { - Messaging.log("Creating file: " + file.getName()); - file.getParentFile().mkdirs(); - file.createNewFile(); - } catch (IOException ex) { - Messaging.log(Level.SEVERE, "Could not create file: " + file.getName()); - } - } + private void create() { + try { + Messaging.log("Creating file: " + file.getName()); + file.getParentFile().mkdirs(); + file.createNewFile(); + } catch (IOException ex) { + Messaging.log(Level.SEVERE, "Could not create file: " + file.getName()); + } + } - public class YamlKey extends DataKey { - private final String current; + public class YamlKey extends DataKey { + private final String current; - public YamlKey(String root) { - current = root; - } + public YamlKey(String root) { + current = root; + } - @Override - public void copy(String to) { - ConfigurationSection root = config.getConfigurationSection(current); - if (root == null) - return; - config.createSection(to, root.getValues(true)); - } + @Override + public void copy(String to) { + ConfigurationSection root = config.getConfigurationSection(current); + if (root == null) + return; + config.createSection(to, root.getValues(true)); + } - @Override - public boolean getBoolean(String key) { - String path = getKeyExt(key); - if (keyExists(path)) { - if (config.getString(path) == null) - return config.getBoolean(path); - return Boolean.parseBoolean(config.getString(path)); - } - return false; - } + @Override + public boolean getBoolean(String key) { + String path = getKeyExt(key); + if (keyExists(path)) { + if (config.getString(path) == null) + return config.getBoolean(path); + return Boolean.parseBoolean(config.getString(path)); + } + return false; + } - @Override - public boolean getBoolean(String keyExt, boolean def) { - return config.getBoolean(getKeyExt(keyExt), def); - } + @Override + public boolean getBoolean(String keyExt, boolean def) { + return config.getBoolean(getKeyExt(keyExt), def); + } - @Override - public double getDouble(String key) { - String path = getKeyExt(key); - if (keyExists(path)) { - if (config.getString(path) == null) { - if (config.get(path) instanceof Integer) - return config.getInt(path); - return config.getDouble(path); - } - return Double.parseDouble(config.getString(path)); - } - return 0; - } + @Override + public double getDouble(String key) { + String path = getKeyExt(key); + if (keyExists(path)) { + if (config.getString(path) == null) { + if (config.get(path) instanceof Integer) + return config.getInt(path); + return config.getDouble(path); + } + return Double.parseDouble(config.getString(path)); + } + return 0; + } - @Override - public double getDouble(String keyExt, double def) { - return config.getDouble(getKeyExt(keyExt), def); - } + @Override + public double getDouble(String keyExt, double def) { + return config.getDouble(getKeyExt(keyExt), def); + } - @Override - public int getInt(String key) { - String path = getKeyExt(key); - if (keyExists(path)) { - if (config.getString(path) == null) - return config.getInt(path); - return Integer.parseInt(config.getString(path)); - } - return 0; - } + @Override + public int getInt(String key) { + String path = getKeyExt(key); + if (keyExists(path)) { + if (config.getString(path) == null) + return config.getInt(path); + return Integer.parseInt(config.getString(path)); + } + return 0; + } - @Override - public int getInt(String path, int value) { - return config.getInt(getKeyExt(path), value); - } + @Override + public int getInt(String path, int value) { + return config.getInt(getKeyExt(path), value); + } - @Override - public List getIntegerSubKeys() { - List res = new ArrayList(); - ConfigurationSection section = config.getConfigurationSection(current); - if (section == null) - return res; - List keys = new ArrayList(); - for (String key : section.getKeys(false)) { - try { - keys.add(Integer.parseInt(key)); - } catch (NumberFormatException ex) { - } - } - Collections.sort(keys); - for (int key : keys) - res.add(getRelative(Integer.toString(key))); - return res; - } + @Override + public List getIntegerSubKeys() { + List res = new ArrayList(); + ConfigurationSection section = config.getConfigurationSection(current); + if (section == null) + return res; + List keys = new ArrayList(); + for (String key : section.getKeys(false)) { + try { + keys.add(Integer.parseInt(key)); + } catch (NumberFormatException ex) { + } + } + Collections.sort(keys); + for (int key : keys) + res.add(getRelative(Integer.toString(key))); + return res; + } - @Override - public long getLong(String key) { - String path = getKeyExt(key); - if (keyExists(path)) { - if (config.getString(path) == null) { - if (config.get(path) instanceof Integer) - return config.getInt(path); - return config.getLong(path); - } - return Long.parseLong(config.getString(path)); - } - return 0; - } + @Override + public long getLong(String key) { + String path = getKeyExt(key); + if (keyExists(path)) { + if (config.getString(path) == null) { + if (config.get(path) instanceof Integer) + return config.getInt(path); + return config.getLong(path); + } + return Long.parseLong(config.getString(path)); + } + return 0; + } - @Override - public long getLong(String keyExt, long def) { - return config.getLong(getKeyExt(keyExt), def); - } + @Override + public long getLong(String keyExt, long def) { + return config.getLong(getKeyExt(keyExt), def); + } - @Override - public DataKey getRelative(String relative) { - return new YamlKey(getKeyExt(relative)); - } + @Override + public DataKey getRelative(String relative) { + return new YamlKey(getKeyExt(relative)); + } - @Override - public String getString(String key) { - String path = getKeyExt(key); - if (keyExists(path)) { - return config.get(path).toString(); - } - return ""; - } + @Override + public String getString(String key) { + String path = getKeyExt(key); + if (keyExists(path)) { + return config.get(path).toString(); + } + return ""; + } - @Override - public Iterable getSubKeys() { - List res = new ArrayList(); - ConfigurationSection section = config.getConfigurationSection(current); - if (section == null) - return res; - for (String key : section.getKeys(false)) { - res.add(getRelative(key)); - } - return res; - } + @Override + public Iterable getSubKeys() { + List res = new ArrayList(); + ConfigurationSection section = config.getConfigurationSection(current); + if (section == null) + return res; + for (String key : section.getKeys(false)) { + res.add(getRelative(key)); + } + return res; + } - @Override - public boolean keyExists(String key) { - return config.get(getKeyExt(key)) != null; - } + @Override + public boolean keyExists(String key) { + return config.get(getKeyExt(key)) != null; + } - @Override - public String name() { - int last = current.lastIndexOf('.'); - return current.substring(last == 0 ? 0 : last + 1); - } + @Override + public String name() { + int last = current.lastIndexOf('.'); + return current.substring(last == 0 ? 0 : last + 1); + } - @Override - public void removeKey(String key) { - config.set(getKeyExt(key), null); - } + @Override + public void removeKey(String key) { + config.set(getKeyExt(key), null); + } - @Override - public void setBoolean(String key, boolean value) { - config.set(getKeyExt(key), value); - } + @Override + public void setBoolean(String key, boolean value) { + config.set(getKeyExt(key), value); + } - @Override - public void setDouble(String key, double value) { - config.set(getKeyExt(key), String.valueOf(value)); - } + @Override + public void setDouble(String key, double value) { + config.set(getKeyExt(key), String.valueOf(value)); + } - @Override - public void setInt(String key, int value) { - config.set(getKeyExt(key), value); - } + @Override + public void setInt(String key, int value) { + config.set(getKeyExt(key), value); + } - @Override - public void setLong(String key, long value) { - config.set(getKeyExt(key), value); - } + @Override + public void setLong(String key, long value) { + config.set(getKeyExt(key), value); + } - @Override - public void setString(String key, String value) { - config.set(getKeyExt(key), value); - } + @Override + public void setString(String key, String value) { + config.set(getKeyExt(key), value); + } - @Override - public Object getRaw(String key) { - return config.get(getKeyExt(key)); - } + @Override + public Object getRaw(String key) { + return config.get(getKeyExt(key)); + } - @Override - public void setRaw(String key, Object value) { - config.set(getKeyExt(key), value); - } + @Override + public void setRaw(String key, Object value) { + config.set(getKeyExt(key), value); + } - private String getKeyExt(String from) { - if (from.isEmpty()) - return current; - if (from.charAt(0) == '.') - return current.isEmpty() ? from.substring(1, from.length()) : current + from; - return current.isEmpty() ? from : current + "." + from; - } - } + private String getKeyExt(String from) { + if (from.isEmpty()) + return current; + if (from.charAt(0) == '.') + return current.isEmpty() ? from.substring(1, from.length()) : current + from; + return current.isEmpty() ? from : current + "." + from; + } + } } \ No newline at end of file diff --git a/src/net/citizensnpcs/util/Messaging.java b/src/net/citizensnpcs/util/Messaging.java index 20030e8ec..bec8c173a 100644 --- a/src/net/citizensnpcs/util/Messaging.java +++ b/src/net/citizensnpcs/util/Messaging.java @@ -6,16 +6,16 @@ import org.bukkit.Bukkit; public class Messaging { - public static void log(Level level, Object msg) { - Bukkit.getLogger().log(level, "[Citizens] " + msg); - } + public static void log(Level level, Object msg) { + Bukkit.getLogger().log(level, "[Citizens] " + msg); + } - public static void log(Object msg) { - log(Level.INFO, msg); - } + public static void log(Object msg) { + log(Level.INFO, msg); + } - public static void debug(Object msg) { - // TODO add debug setting - log(msg); - } + public static void debug(Object msg) { + // TODO add debug setting + log(msg); + } } \ No newline at end of file