Implement new trait methods

This commit is contained in:
fullwall 2012-09-16 12:29:08 +08:00
parent d3ae5bcd61
commit 1394ec9c9a
9 changed files with 17 additions and 13 deletions

View File

@ -6,13 +6,13 @@
<groupId>net.citizensnpcs</groupId>
<artifactId>citizens</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
<name>Citizens</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<craftbukkit.version>LATEST</craftbukkit.version>
<citizensapi.version>LATEST</citizensapi.version>
<citizensapi.version>2.0.2</citizensapi.version>
<vault.version>1.2.18-SNAPSHOT</vault.version>
<build.number>Unknown</build.number>
</properties>

View File

@ -17,6 +17,7 @@ import com.google.common.collect.Maps;
public abstract class CitizensMobNPC extends CitizensNPC {
private final Constructor<? extends EntityLiving> constructor;
protected CitizensMobNPC(int id, String name, Class<? extends EntityLiving> clazz) {
super(id, name);
this.constructor = getConstructor(clazz);

View File

@ -45,6 +45,8 @@ public abstract class CitizensNPC extends AbstractNPC {
boolean keepSelected = getTrait(Spawned.class).shouldSpawn();
if (!keepSelected)
data().remove("selectors");
for (Trait trait : traits.values())
trait.onDespawn();
getBukkitEntity().remove();
mcEntity = null;

View File

@ -1,6 +1,5 @@
package net.citizensnpcs.trait;
public interface Toggleable {
public boolean toggle();
}

View File

@ -101,6 +101,12 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve
range = key.getDouble("range", range);
}
@Override
public void onAttach() {
if (text.isEmpty())
populateDefaultText();
}
@EventHandler
public void onRightClick(NPCRightClickEvent event) {
if (!event.getNPC().equals(npc))
@ -109,12 +115,6 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve
sendText(event.getClicker());
}
@Override
public void onSpawn() {
if (text.isEmpty())
populateDefaultText();
}
private void populateDefaultText() {
text.addAll(Setting.DEFAULT_TEXT.asList());
}

View File

@ -19,8 +19,8 @@ public class TextEditPrompt extends StringPrompt {
public Prompt acceptInput(ConversationContext context, String input) {
int index = (Integer) context.getSessionData("index");
text.edit(index, input);
Messaging.send((Player) context.getForWhom(), "<a>Changed entry at index <e>" + index + " <a>to <e>" + input
+ "<a>.");
Messaging.send((Player) context.getForWhom(), "<a>Changed entry at index <e>" + index + " <a>to <e>"
+ input + "<a>.");
return new StartPrompt(text);
}

View File

@ -49,6 +49,7 @@ public class WanderingWaypointProvider implements WaypointProvider {
xrange = key.getInt("xrange", DEFAULT_XRANGE);
yrange = key.getInt("yrange", DEFAULT_YRANGE);
}
@Override
public void onSpawn(NPC npc) {
this.npc = npc;

View File

@ -20,7 +20,8 @@ public class Paginator {
}
public boolean sendPage(CommandSender sender, int page) {
int pages = (int) ((lines.size() / LINES_PER_PAGE == 0) ? 1 : Math.ceil((double) lines.size() / LINES_PER_PAGE));
int pages = (int) ((lines.size() / LINES_PER_PAGE == 0) ? 1 : Math.ceil((double) lines.size()
/ LINES_PER_PAGE));
if (page < 0 || page > pages)
return false;

View File

@ -1,7 +1,7 @@
name: Citizens
authors: [aPunch, fullwall]
softdepend: [Vault]
version: 2.0.1
version: 2.0.2
main: net.citizensnpcs.Citizens
website: http://www.citizensnpcs.net
commands: