Allow setting of text talk delay per-NPC

This commit is contained in:
fullwall 2018-02-15 23:29:11 +08:00
parent 72ac9134b1
commit ffbeedfccd
4 changed files with 28 additions and 8 deletions

View File

@ -41,6 +41,7 @@ import net.citizensnpcs.util.Util;
public class Text extends Trait implements Runnable, Toggleable, Listener, ConversationAbandonedListener { public class Text extends Trait implements Runnable, Toggleable, Listener, ConversationAbandonedListener {
private final Map<UUID, Date> cooldowns = Maps.newHashMap(); private final Map<UUID, Date> cooldowns = Maps.newHashMap();
private int currentIndex; private int currentIndex;
private int delay = -1;
private String itemInHandPattern = "default"; private String itemInHandPattern = "default";
private final Plugin plugin; private final Plugin plugin;
private boolean randomTalker = Setting.DEFAULT_RANDOM_TALKER.asBoolean(); private boolean randomTalker = Setting.DEFAULT_RANDOM_TALKER.asBoolean();
@ -108,6 +109,7 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve
realisticLooker = key.getBoolean("realistic-looking", realisticLooker); realisticLooker = key.getBoolean("realistic-looking", realisticLooker);
randomTalker = key.getBoolean("random-talker", randomTalker); randomTalker = key.getBoolean("random-talker", randomTalker);
range = key.getDouble("range", range); range = key.getDouble("range", range);
delay = key.getInt("delay", delay);
itemInHandPattern = key.getString("talkitem", itemInHandPattern); itemInHandPattern = key.getString("talkitem", itemInHandPattern);
} }
@ -150,7 +152,8 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve
return; return;
// Add a cooldown if the text was successfully sent // Add a cooldown if the text was successfully sent
Date wait = new Date(); Date wait = new Date();
int secondsDelta = RANDOM.nextInt(Setting.TALK_CLOSE_MAXIMUM_COOLDOWN.asInt()) int secondsDelta = delay != -1 ? delay
: RANDOM.nextInt(Setting.TALK_CLOSE_MAXIMUM_COOLDOWN.asInt())
+ Setting.TALK_CLOSE_MINIMUM_COOLDOWN.asInt(); + Setting.TALK_CLOSE_MINIMUM_COOLDOWN.asInt();
if (secondsDelta <= 0) if (secondsDelta <= 0)
return; return;
@ -162,6 +165,7 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve
@Override @Override
public void save(DataKey key) { public void save(DataKey key) {
key.setInt("delay", delay);
key.setBoolean("talk-close", talkClose); key.setBoolean("talk-close", talkClose);
key.setBoolean("random-talker", randomTalker); key.setBoolean("random-talker", randomTalker);
key.setBoolean("realistic-looking", realisticLooker); key.setBoolean("realistic-looking", realisticLooker);
@ -202,6 +206,10 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve
return true; return true;
} }
void setDelay(int delay) {
this.delay = delay;
}
void setItemInHandPattern(String pattern) { void setItemInHandPattern(String pattern) {
itemInHandPattern = pattern; itemInHandPattern = pattern;
} }

View File

@ -1,15 +1,15 @@
package net.citizensnpcs.trait.text; package net.citizensnpcs.trait.text;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.conversations.ConversationContext; import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt; import org.bukkit.conversations.Prompt;
import org.bukkit.conversations.StringPrompt; import org.bukkit.conversations.StringPrompt;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
public class TextStartPrompt extends StringPrompt { public class TextStartPrompt extends StringPrompt {
private final Text text; private final Text text;
@ -28,7 +28,15 @@ public class TextStartPrompt extends StringPrompt {
return new TextEditStartPrompt(text); return new TextEditStartPrompt(text);
else if (input.equalsIgnoreCase("remove")) else if (input.equalsIgnoreCase("remove"))
return new TextRemovePrompt(text); return new TextRemovePrompt(text);
else if (input.equalsIgnoreCase("random")) else if (input.equalsIgnoreCase("delay")) {
try {
int delay = Integer.parseInt(parts[1]);
text.setDelay(delay);
Messaging.sendTr(sender, Messages.TEXT_EDITOR_DELAY_SET, delay);
} catch (NumberFormatException e) {
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_DELAY);
}
} else if (input.equalsIgnoreCase("random"))
Messaging.sendTr(sender, Messages.TEXT_EDITOR_RANDOM_TALKER_SET, text.toggleRandomTalker()); Messaging.sendTr(sender, Messages.TEXT_EDITOR_RANDOM_TALKER_SET, text.toggleRandomTalker());
else if (input.equalsIgnoreCase("realistic looking")) else if (input.equalsIgnoreCase("realistic looking"))
Messaging.sendTr(sender, Messages.TEXT_EDITOR_REALISTIC_LOOKING_SET, text.toggleRealisticLooking()); Messaging.sendTr(sender, Messages.TEXT_EDITOR_REALISTIC_LOOKING_SET, text.toggleRealisticLooking());

View File

@ -239,10 +239,12 @@ public class Messages {
public static final String TEXT_EDITOR_ADDED_ENTRY = "citizens.editors.text.added-entry"; public static final String TEXT_EDITOR_ADDED_ENTRY = "citizens.editors.text.added-entry";
public static final String TEXT_EDITOR_BEGIN = "citizens.editors.text.begin"; public static final String TEXT_EDITOR_BEGIN = "citizens.editors.text.begin";
public static final String TEXT_EDITOR_CLOSE_TALKER_SET = "citizens.editors.text.close-talker-set"; public static final String TEXT_EDITOR_CLOSE_TALKER_SET = "citizens.editors.text.close-talker-set";
public static final String TEXT_EDITOR_DELAY_SET = "citizens.editors.text.delay-set";
public static final String TEXT_EDITOR_EDIT_BEGIN_PROMPT = "citizens.editors.text.edit-begin-prompt"; public static final String TEXT_EDITOR_EDIT_BEGIN_PROMPT = "citizens.editors.text.edit-begin-prompt";
public static final String TEXT_EDITOR_EDIT_PROMPT = "citizens.editors.text.edit-prompt"; public static final String TEXT_EDITOR_EDIT_PROMPT = "citizens.editors.text.edit-prompt";
public static final String TEXT_EDITOR_EDITED_TEXT = "citizens.editors.text.edited-text"; public static final String TEXT_EDITOR_EDITED_TEXT = "citizens.editors.text.edited-text";
public static final String TEXT_EDITOR_END = "citizens.editors.text.end"; public static final String TEXT_EDITOR_END = "citizens.editors.text.end";
public static final String TEXT_EDITOR_INVALID_DELAY = "citizens.editors.text.invalid-delay";
public static final String TEXT_EDITOR_INVALID_EDIT_TYPE = "citizens.editors.text.invalid-edit-type"; public static final String TEXT_EDITOR_INVALID_EDIT_TYPE = "citizens.editors.text.invalid-edit-type";
public static final String TEXT_EDITOR_INVALID_INDEX = "citizens.editors.text.invalid-index"; public static final String TEXT_EDITOR_INVALID_INDEX = "citizens.editors.text.invalid-index";
public static final String TEXT_EDITOR_INVALID_INPUT = "citizens.editors.text.invalid-input"; public static final String TEXT_EDITOR_INVALID_INPUT = "citizens.editors.text.invalid-input";

View File

@ -212,12 +212,14 @@ citizens.editors.text.invalid-index=[[{0}]] is not a valid index!
citizens.editors.text.invalid-input=Invalid input. citizens.editors.text.invalid-input=Invalid input.
citizens.editors.text.invalid-page=Invalid page number. citizens.editors.text.invalid-page=Invalid page number.
citizens.editors.text.invalid-range=Invalid range. citizens.editors.text.invalid-range=Invalid range.
citizens.editors.text.invalid-delay=Invalid delay.
citizens.editors.text.random-talker-set=[[Random talking]] set to [[{0}]]. citizens.editors.text.random-talker-set=[[Random talking]] set to [[{0}]].
citizens.editors.text.range-set=[[Range]] set to [[{0}]]. citizens.editors.text.range-set=[[Range]] set to [[{0}]].
citizens.editors.text.delay-set=[[Delay]] set to [[{0}]] ticks.
citizens.editors.text.realistic-looking-set=[[Realistic looking]] set to [[{0}]]. citizens.editors.text.realistic-looking-set=[[Realistic looking]] set to [[{0}]].
citizens.editors.text.remove-prompt=Enter the index of the entry you wish to remove or [[page]] to view more pages. citizens.editors.text.remove-prompt=Enter the index of the entry you wish to remove or [[page]] to view more pages.
citizens.editors.text.removed-entry=[[Removed]] entry at index [[{0}]]. citizens.editors.text.removed-entry=[[Removed]] entry at index [[{0}]].
citizens.editors.text.start-prompt=Type [[add]] to add an entry, [[edit]] to edit entries, [[remove]] to remove entries, [[close]] to toggle the NPC as a close talker, [[item]] to set the item in hand pattern, [[range]] to set the talking range, and [[random]] to toggle the NPC as a random talker. Type [[help]] to show this again. citizens.editors.text.start-prompt=Type [[add]] to add an entry, [[edit]] to edit entries, [[remove]] to remove entries, [[close]] to toggle the NPC as a close talker, [[item]] to set the item in hand pattern, [[range]] to set the talking range, [[delay]] to set the talking delay in ticks and [[random]] to toggle the NPC as a random talker. Type [[help]] to show this again.
citizens.editors.text.talk-item-set=[[Talk item pattern]] set to [[{0}]]. citizens.editors.text.talk-item-set=[[Talk item pattern]] set to [[{0}]].
citizens.editors.waypoints.wander.range-set=Wander range set to xrange [[{0}]] and yrange [[{1}]]. citizens.editors.waypoints.wander.range-set=Wander range set to xrange [[{0}]] and yrange [[{1}]].
citizens.editors.waypoints.wander.begin=<b>Entered the wander waypoint editor.<br> Type [[xrange <number>]] or [[yrange <number>]] to modify the random wander range. citizens.editors.waypoints.wander.begin=<b>Entered the wander waypoint editor.<br> Type [[xrange <number>]] or [[yrange <number>]] to modify the random wander range.