changes and fixes to character handling

This commit is contained in:
aPunch 2012-01-25 04:09:02 -06:00
parent 76d9b2b5c9
commit 3469f017f5
8 changed files with 57 additions and 15 deletions

View File

@ -42,6 +42,8 @@ public class Citizens extends JavaPlugin {
public boolean onCommand(CommandSender sender, Command cmd, String cmdName, String[] args) {
if (args[0].equals("spawn")) {
NPC npc = npcManager.createNPC(ChatColor.GREEN + "aPunch");
// TODO remove
npc.setCharacter(characterManager.getInstance("test"));
npc.spawn(((Player) sender).getLocation());
((CitizensNPC) npc).save(saves);
} else if (args[0].equals("despawn")) {
@ -120,7 +122,7 @@ public class Citizens extends JavaPlugin {
// Load the character if it exists, otherwise remove the character
if (character != null)
character.load(key.getRelative(character.getName()));
character.load(key.getRelative("characters." + character.getName()));
else {
if (key.keyExists("character")) {
Messaging.debug("Character '" + key.getString("character")

View File

@ -87,15 +87,21 @@ public class EventListen implements Listener {
NPC npc = manager.getNPC(event.getEntity());
Player player = (Player) event.getTarget();
if (manager.canSelect(player, npc)) {
manager.selectNPC(player, npc);
Messaging.sendWithNPC(player, Setting.SELECTION_MESSAGE.getString(), npc);
} else {
if (npc.getCharacter() != null)
npc.getCharacter().onRightClick(npc, player);
if (!manager.hasSelected(player, npc)) {
if (manager.canSelect(player, npc)) {
manager.selectNPC(player, npc);
Messaging.sendWithNPC(player, Setting.SELECTION_MESSAGE.getString(), npc);
if (!Setting.QUICK_SELECT.getBoolean())
return;
}
}
if (npc.getCharacter() != null)
npc.getCharacter().onRightClick(npc, player);
}
/*
* Player events
*/
@EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (!manager.isNPC(event.getRightClicked()))

View File

@ -33,7 +33,8 @@ public class Settings {
DEBUG_MODE("general.debug-mode", false),
USE_DATABASE("use-database", false),
SELECTION_ITEM("npc.selection.item", 280),
SELECTION_MESSAGE("npc.selection.message", "<b>You selected <a><npc><b>!");
SELECTION_MESSAGE("npc.selection.message", "<b>You selected <a><npc><b>!"),
QUICK_SELECT("npc.selection.quick-select", false);
private String path;
private Object value;

View File

@ -7,6 +7,7 @@ import net.citizensnpcs.api.npc.AbstractNPC;
import net.citizensnpcs.api.npc.ai.Navigator;
import net.citizensnpcs.api.npc.trait.Trait;
import net.citizensnpcs.api.npc.trait.trait.SpawnLocation;
import net.citizensnpcs.npc.ai.CitizensNavigator;
import net.citizensnpcs.resources.lib.CraftNPC;
import net.citizensnpcs.storage.Storage;
import net.citizensnpcs.util.Messaging;
@ -51,8 +52,7 @@ public class CitizensNPC extends AbstractNPC {
@Override
public Navigator getNavigator() {
// TODO add default navigator
return null;
return new CitizensNavigator(this);
}
@Override
@ -101,7 +101,7 @@ public class CitizensNPC extends AbstractNPC {
// Save the character if it exists
if (getCharacter() != null) {
key.setString("character", getCharacter().getName());
getCharacter().save(key.getRelative(getCharacter().getName()));
getCharacter().save(key.getRelative("characters." + getCharacter().getName()));
}
// Save all existing traits

View File

@ -143,12 +143,15 @@ public class CitizensNPCManager implements NPCManager {
selected.put(player.getName(), npc.getId());
}
public boolean hasSelected(Player player, NPC npc) {
if (!selected.containsKey(player.getName()))
return false;
return selected.get(player.getName()) == npc.getId();
}
public boolean canSelect(Player player, NPC npc) {
if (player.hasPermission("citizens.npc.select")) {
if (!selected.containsKey(player.getName()))
return true;
return selected.get(player.getName()) != npc.getId()
&& player.getItemInHand().getTypeId() == Setting.SELECTION_ITEM.getInt();
return player.getItemInHand().getTypeId() == Setting.SELECTION_ITEM.getInt();
}
return false;
}

View File

@ -0,0 +1,28 @@
package net.citizensnpcs.npc.ai;
import net.citizensnpcs.api.npc.ai.Navigator;
import net.citizensnpcs.api.npc.ai.NavigatorCallback;
import net.citizensnpcs.npc.CitizensNPC;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
public class CitizensNavigator implements Navigator {
private CitizensNPC npc;
public CitizensNavigator(CitizensNPC npc) {
this.npc = npc;
}
@Override
public void setDestination(Location destination) {
}
@Override
public void registerCallback(NavigatorCallback callback) {
}
@Override
public void setTarget(Entity target, boolean aggressive) {
}
}

View File

@ -7,6 +7,7 @@ import net.citizensnpcs.util.ByIdArray;
import org.junit.Test;
public class ByIdArrayTest {
@Test
public void testInsert() {
ByIdArray<String> test = new ByIdArray<String>();

View File

@ -3,6 +3,7 @@ package net.citizensnpcs.test;
import org.junit.Test;
public class StorageTest {
@Test
public void testYaml() {
}