mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-22 09:07:56 +01:00
Add /npc pausepathfinding --lockout, fix /npc text speech bubbles duration
This commit is contained in:
parent
158d4d328c
commit
4cf042eb3f
@ -11,7 +11,7 @@
|
||||
<artifactId>citizens-main</artifactId>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<craftbukkit.version>1.21.2-R0.1-SNAPSHOT</craftbukkit.version>
|
||||
<craftbukkit.version>1.21.3-R0.1-SNAPSHOT</craftbukkit.version>
|
||||
<placeholderapi.version>2.11.5</placeholderapi.version>
|
||||
<citizensapi.version>${project.version}</citizensapi.version>
|
||||
<worldguard.version>7.1.0-SNAPSHOT</worldguard.version>
|
||||
@ -57,7 +57,7 @@
|
||||
<dependency>
|
||||
<groupId>it.unimi.dsi</groupId>
|
||||
<artifactId>fastutil</artifactId>
|
||||
<version>8.5.14</version>
|
||||
<version>8.5.15</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -69,13 +69,13 @@
|
||||
<dependency>
|
||||
<groupId>ch.ethz.globis.phtree</groupId>
|
||||
<artifactId>phtree</artifactId>
|
||||
<version>2.8.0</version>
|
||||
<version>2.8.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.joml</groupId>
|
||||
<artifactId>joml</artifactId>
|
||||
<version>1.10.5</version>
|
||||
<version>1.10.8</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -2335,7 +2335,7 @@ public class NPCCommands {
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "pausepathfinding --onrightclick [true|false] --when-player-within [range in blocks] --pauseticks [ticks]",
|
||||
usage = "pausepathfinding --onrightclick [true|false] --when-player-within [range in blocks] --pauseduration [duration] --lockoutduration [duration]",
|
||||
desc = "",
|
||||
modifiers = { "pausepathfinding" },
|
||||
min = 1,
|
||||
@ -2343,23 +2343,28 @@ public class NPCCommands {
|
||||
permission = "citizens.npc.pausepathfinding")
|
||||
public void pausepathfinding(CommandContext args, CommandSender sender, NPC npc,
|
||||
@Flag("onrightclick") Boolean rightclick, @Flag("when-player-within") Double playerRange,
|
||||
@Flag("pauseticks") Integer ticks) throws CommandException {
|
||||
@Flag("pauseduration") Duration pauseDuration, @Flag("lockoutduration") Duration lockoutDuration)
|
||||
throws CommandException {
|
||||
PausePathfindingTrait trait = npc.getOrAddTrait(PausePathfindingTrait.class);
|
||||
if (playerRange != null) {
|
||||
if (playerRange <= 0)
|
||||
throw new CommandException("Invalid range");
|
||||
trait.setPlayerRangeBlocks(playerRange);
|
||||
trait.setPlayerRange(playerRange);
|
||||
Messaging.sendTr(sender, Messages.PAUSEPATHFINDING_RANGE_SET, npc.getName(), playerRange);
|
||||
}
|
||||
if (rightclick != null) {
|
||||
trait.setRightClick(rightclick);
|
||||
trait.setPauseOnRightClick(rightclick);
|
||||
Messaging.sendTr(sender,
|
||||
rightclick ? Messages.PAUSEPATHFINDING_RIGHTCLICK_SET : Messages.PAUSEPATHFINDING_RIGHTCLICK_UNSET,
|
||||
npc.getName());
|
||||
}
|
||||
if (ticks != null) {
|
||||
trait.setPauseTicks(ticks);
|
||||
Messaging.sendTr(sender, Messages.PAUSEPATHFINDING_TICKS_SET, npc.getName(), ticks);
|
||||
if (lockoutDuration != null) {
|
||||
trait.setLockoutDuration(Util.toTicks(lockoutDuration));
|
||||
Messaging.sendTr(sender, Messages.PAUSEPATHFINDING_LOCKOUT_DURATION_SET, npc.getName(), lockoutDuration);
|
||||
}
|
||||
if (pauseDuration != null) {
|
||||
trait.setPauseDuration(Util.toTicks(pauseDuration));
|
||||
Messaging.sendTr(sender, Messages.PAUSEPATHFINDING_TICKS_SET, npc.getName(), pauseDuration);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,21 +12,36 @@ import net.citizensnpcs.util.NMS;
|
||||
|
||||
@TraitName("pausepathfinding")
|
||||
public class PausePathfindingTrait extends Trait {
|
||||
@Persist("lockoutduration")
|
||||
private int lockoutDuration = -1;
|
||||
@Persist("pauseticks")
|
||||
private int pauseTicks;
|
||||
@Persist("playerrange")
|
||||
private double playerRange = -1;
|
||||
@Persist("rightclick")
|
||||
private boolean rightclick;
|
||||
private int t;
|
||||
private int unpauseTaskId = -1;
|
||||
|
||||
public PausePathfindingTrait() {
|
||||
super("pausepathfinding");
|
||||
}
|
||||
|
||||
public int getLockoutDuration() {
|
||||
return lockoutDuration;
|
||||
}
|
||||
|
||||
public int getPauseDuration() {
|
||||
return pauseTicks;
|
||||
}
|
||||
|
||||
public double getPlayerRangeInBlocks() {
|
||||
return playerRange;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onInteract(NPCRightClickEvent event) {
|
||||
if (!rightclick || event.getNPC() != npc)
|
||||
if (lockoutDuration > t || !rightclick || event.getNPC() != npc)
|
||||
return;
|
||||
pause();
|
||||
event.setDelayedCancellation(true);
|
||||
@ -42,27 +57,38 @@ public class PausePathfindingTrait extends Trait {
|
||||
NMS.setPitch(npc.getEntity(), 0);
|
||||
npc.getNavigator().setPaused(false);
|
||||
}, pauseTicks <= 0 ? 20 : pauseTicks);
|
||||
t = 0;
|
||||
}
|
||||
|
||||
public boolean pauseOnRightClick() {
|
||||
return rightclick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (playerRange == -1 || !npc.isSpawned() || unpauseTaskId == -1 && !npc.getNavigator().isNavigating())
|
||||
if (lockoutDuration > t++ || playerRange == -1 || !npc.isSpawned()
|
||||
|| unpauseTaskId == -1 && !npc.getNavigator().isNavigating())
|
||||
return;
|
||||
|
||||
if (CitizensAPI.getLocationLookup()
|
||||
.getNearbyVisiblePlayers(npc.getEntity(), npc.getStoredLocation(), playerRange).iterator().hasNext()) {
|
||||
pause();
|
||||
}
|
||||
}
|
||||
|
||||
public void setPauseTicks(int pauseTicks) {
|
||||
this.pauseTicks = pauseTicks;
|
||||
public void setLockoutDuration(int ticks) {
|
||||
this.lockoutDuration = ticks;
|
||||
}
|
||||
|
||||
public void setPlayerRangeBlocks(double range) {
|
||||
playerRange = range;
|
||||
public void setPauseDuration(int ticks) {
|
||||
this.pauseTicks = ticks;
|
||||
}
|
||||
|
||||
public void setRightClick(boolean rightclick) {
|
||||
public void setPauseOnRightClick(boolean rightclick) {
|
||||
this.rightclick = rightclick;
|
||||
}
|
||||
|
||||
public void setPlayerRange(double blockRange) {
|
||||
playerRange = blockRange;
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package net.citizensnpcs.trait.text;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -253,7 +252,7 @@ public class Text extends Trait implements Runnable, Listener {
|
||||
}
|
||||
|
||||
public void setSpeechBubbleDuration(Duration duration) {
|
||||
this.speechBubbleDuration = (int) (duration.get(ChronoUnit.MILLIS) / 50);
|
||||
this.speechBubbleDuration = Util.toTicks(duration);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.citizensnpcs.trait.text;
|
||||
|
||||
import java.time.DateTimeException;
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -86,7 +87,7 @@ public class TextBasePrompt extends StringPrompt {
|
||||
null);
|
||||
text.setSpeechBubbleDuration(duration);
|
||||
Messaging.sendErrorTr(sender, Messages.SPEECH_BUBBLES_DURATION_SET, duration);
|
||||
} catch (Exception exception) {
|
||||
} catch (DateTimeException ex) {
|
||||
Messaging.sendErrorTr(sender, Messages.INVALID_SPEECH_BUBBLES_DURATION);
|
||||
}
|
||||
} else if (input.equalsIgnoreCase("close") || original.trim().equalsIgnoreCase("talk close")) {
|
||||
|
@ -339,6 +339,7 @@ public class Messages {
|
||||
public static final String PATHFINDING_OPTIONS_STATIONARY_TICKS_SET = "citizens.commands.npc.pathopt.stationary-ticks-set";
|
||||
public static final String PATHFINDING_OPTIONS_USE_NEW_FINDER = "citizens.commands.npc.pathopt.use-new-finder";
|
||||
public static final String PATHFINDING_RANGE_SET = "citizens.commands.npc.pathfindingrange.set";
|
||||
public static final String PAUSEPATHFINDING_LOCKOUT_DURATION_SET = "citizens.commands.npc.pausepathfinding.lockout-duration-set";
|
||||
public static final String PAUSEPATHFINDING_RANGE_SET = "citizens.commands.npc.pausepathfinding.pause-range-set";
|
||||
public static final String PAUSEPATHFINDING_RIGHTCLICK_SET = "citizens.commands.npc.pausepathfinding.rightclick-set";
|
||||
public static final String PAUSEPATHFINDING_RIGHTCLICK_UNSET = "citizens.commands.npc.pausepathfinding.rightclick-unset";
|
||||
|
@ -415,6 +415,7 @@
|
||||
"citizens.commands.npc.pathopt.use-new-finder" : "[[{0}]]''s use new finder set to [[{1}]].",
|
||||
"citizens.commands.npc.pathto.description" : "Starts pathfinding to a certain location",
|
||||
"citizens.commands.npc.pathto.help" : "",
|
||||
"citizens.commands.npc.pausepathfinding.lockout-duration-set" : "[[{0}]] will now wait for [[{1}]] ticks before pausing again.",
|
||||
"citizens.commands.npc.pausepathfinding.description" : "Sets pathfinding pause",
|
||||
"citizens.commands.npc.pausepathfinding.help" : "",
|
||||
"citizens.commands.npc.pausepathfinding.pause-range-set" : "[{0}]] will now pause pathfinding when a player is within [[{1}]] blocks.",
|
||||
|
@ -6,8 +6,9 @@ main: net.citizensnpcs.Citizens
|
||||
website: https://www.citizensnpcs.co
|
||||
api-version: "1.13"
|
||||
libraries:
|
||||
- ch.ethz.globis.phtree:phtree:2.8.0
|
||||
- org.joml:joml:1.10.5
|
||||
- ch.ethz.globis.phtree:phtree:2.8.1
|
||||
- org.joml:joml:1.10.8
|
||||
- it.unimi.dsi:fastutil:8.5.15
|
||||
- net.kyori:adventure-platform-bukkit:4.3.3
|
||||
- net.kyori:adventure-text-minimessage:4.17.0
|
||||
commands:
|
||||
|
Loading…
Reference in New Issue
Block a user