mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-23 02:55:45 +01:00
changes and fixes to character handling
This commit is contained in:
parent
76d9b2b5c9
commit
3469f017f5
@ -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")
|
||||
|
@ -87,15 +87,21 @@ public class EventListen implements Listener {
|
||||
|
||||
NPC npc = manager.getNPC(event.getEntity());
|
||||
Player player = (Player) event.getTarget();
|
||||
if (!manager.hasSelected(player, npc)) {
|
||||
if (manager.canSelect(player, npc)) {
|
||||
manager.selectNPC(player, npc);
|
||||
Messaging.sendWithNPC(player, Setting.SELECTION_MESSAGE.getString(), npc);
|
||||
} else {
|
||||
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()))
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
28
src/net/citizensnpcs/npc/ai/CitizensNavigator.java
Normal file
28
src/net/citizensnpcs/npc/ai/CitizensNavigator.java
Normal 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) {
|
||||
}
|
||||
}
|
@ -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>();
|
||||
|
@ -3,6 +3,7 @@ package net.citizensnpcs.test;
|
||||
import org.junit.Test;
|
||||
|
||||
public class StorageTest {
|
||||
|
||||
@Test
|
||||
public void testYaml() {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user