mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-09-28 07:07:39 +02:00
Allow setting of text talk delay per-NPC
This commit is contained in:
parent
72ac9134b1
commit
ffbeedfccd
@ -41,6 +41,7 @@ import net.citizensnpcs.util.Util;
|
||||
public class Text extends Trait implements Runnable, Toggleable, Listener, ConversationAbandonedListener {
|
||||
private final Map<UUID, Date> cooldowns = Maps.newHashMap();
|
||||
private int currentIndex;
|
||||
private int delay = -1;
|
||||
private String itemInHandPattern = "default";
|
||||
private final Plugin plugin;
|
||||
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);
|
||||
randomTalker = key.getBoolean("random-talker", randomTalker);
|
||||
range = key.getDouble("range", range);
|
||||
delay = key.getInt("delay", delay);
|
||||
itemInHandPattern = key.getString("talkitem", itemInHandPattern);
|
||||
}
|
||||
|
||||
@ -150,8 +152,9 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve
|
||||
return;
|
||||
// Add a cooldown if the text was successfully sent
|
||||
Date wait = new Date();
|
||||
int secondsDelta = RANDOM.nextInt(Setting.TALK_CLOSE_MAXIMUM_COOLDOWN.asInt())
|
||||
+ Setting.TALK_CLOSE_MINIMUM_COOLDOWN.asInt();
|
||||
int secondsDelta = delay != -1 ? delay
|
||||
: RANDOM.nextInt(Setting.TALK_CLOSE_MAXIMUM_COOLDOWN.asInt())
|
||||
+ Setting.TALK_CLOSE_MINIMUM_COOLDOWN.asInt();
|
||||
if (secondsDelta <= 0)
|
||||
return;
|
||||
long millisecondsDelta = TimeUnit.MILLISECONDS.convert(secondsDelta, TimeUnit.SECONDS);
|
||||
@ -162,6 +165,7 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve
|
||||
|
||||
@Override
|
||||
public void save(DataKey key) {
|
||||
key.setInt("delay", delay);
|
||||
key.setBoolean("talk-close", talkClose);
|
||||
key.setBoolean("random-talker", randomTalker);
|
||||
key.setBoolean("realistic-looking", realisticLooker);
|
||||
@ -202,6 +206,10 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve
|
||||
return true;
|
||||
}
|
||||
|
||||
void setDelay(int delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
void setItemInHandPattern(String pattern) {
|
||||
itemInHandPattern = pattern;
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
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.command.CommandSender;
|
||||
import org.bukkit.conversations.ConversationContext;
|
||||
import org.bukkit.conversations.Prompt;
|
||||
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 {
|
||||
private final Text text;
|
||||
|
||||
@ -28,7 +28,15 @@ public class TextStartPrompt extends StringPrompt {
|
||||
return new TextEditStartPrompt(text);
|
||||
else if (input.equalsIgnoreCase("remove"))
|
||||
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());
|
||||
else if (input.equalsIgnoreCase("realistic looking"))
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_REALISTIC_LOOKING_SET, text.toggleRealisticLooking());
|
||||
|
@ -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_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_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_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_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_INDEX = "citizens.editors.text.invalid-index";
|
||||
public static final String TEXT_EDITOR_INVALID_INPUT = "citizens.editors.text.invalid-input";
|
||||
|
@ -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-page=Invalid page number.
|
||||
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.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.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.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.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.
|
||||
|
Loading…
Reference in New Issue
Block a user