mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-03 05:51:42 +01:00
Adjust /npc text to consider delay in right click as well
This commit is contained in:
parent
5a5bc1349d
commit
dee442e935
@ -143,6 +143,7 @@ public class Text extends Trait implements Runnable, Listener, ConversationAband
|
||||
for (DataKey sub : key.getRelative("text").getIntegerSubKeys()) {
|
||||
text.add(sub.getString(""));
|
||||
}
|
||||
|
||||
if (text.isEmpty()) {
|
||||
populateDefaultText();
|
||||
}
|
||||
@ -162,7 +163,7 @@ public class Text extends Trait implements Runnable, Listener, ConversationAband
|
||||
return;
|
||||
String localPattern = itemInHandPattern.equals("default") ? Setting.TALK_ITEM.asString() : itemInHandPattern;
|
||||
if (Util.matchesItemInHand(event.getClicker(), localPattern) && !shouldTalkClose()) {
|
||||
sendText(event.getClicker());
|
||||
sendCooldownMessage(event.getClicker());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@ -190,25 +191,7 @@ public class Text extends Trait implements Runnable, Listener, ConversationAband
|
||||
for (Entity search : nearby) {
|
||||
if (!(search instanceof Player) || ((Player) search).getGameMode() == GameMode.SPECTATOR)
|
||||
continue;
|
||||
Player player = (Player) search;
|
||||
|
||||
Long cooldown = cooldowns.get(player.getUniqueId());
|
||||
if (cooldown != null) {
|
||||
if (System.currentTimeMillis() < cooldown) {
|
||||
return;
|
||||
}
|
||||
cooldowns.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
sendText(player);
|
||||
|
||||
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);
|
||||
cooldowns.put(player.getUniqueId(), System.currentTimeMillis() + millisecondsDelta);
|
||||
sendCooldownMessage((Player) search);
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,6 +210,26 @@ public class Text extends Trait implements Runnable, Listener, ConversationAband
|
||||
}
|
||||
}
|
||||
|
||||
private void sendCooldownMessage(Player player) {
|
||||
Long cooldown = cooldowns.get(player.getUniqueId());
|
||||
if (cooldown != null) {
|
||||
if (System.currentTimeMillis() < cooldown)
|
||||
return;
|
||||
|
||||
cooldowns.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
sendText(player);
|
||||
|
||||
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);
|
||||
cooldowns.put(player.getUniqueId(), System.currentTimeMillis() + millisecondsDelta);
|
||||
}
|
||||
|
||||
boolean sendPage(CommandSender player, int page) {
|
||||
Paginator paginator = new Paginator().header("Current Texts").enablePageSwitcher();
|
||||
for (int i = 0; i < text.size(); i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user