Use new metadata and parse components per line in shop trait description

This commit is contained in:
fullwall 2024-12-19 21:48:07 +08:00
parent a675406eae
commit e393764880
4 changed files with 17 additions and 11 deletions

View File

@ -2300,7 +2300,7 @@ public class NPCCommands {
output += " " + Messaging.tr(Messages.PATHFINDING_OPTIONS_USE_NEW_FINDER, npc.getName(), useNewFinder);
}
if (fallingDistance != null) {
npc.data().set(NPC.Metadata.PATHFINDER_FALL_DISTANCE, fallingDistance);
npc.getNavigator().getDefaultParameters().fallDistance(fallingDistance);
output += " "
+ Messaging.tr(Messages.PATHFINDING_OPTIONS_FALLING_DISTANCE_SET, npc.getName(), fallingDistance);
}

View File

@ -60,7 +60,8 @@ public class CitizensNavigator implements Navigator, Runnable {
.stationaryTicks(Setting.DEFAULT_STATIONARY_DURATION.asTicks()).stuckAction(TeleportStuckAction.INSTANCE)
.examiner(new MinecraftBlockExaminer()).useNewPathfinder(Setting.USE_NEW_PATHFINDER.asBoolean())
.straightLineTargetingDistance(Setting.DEFAULT_STRAIGHT_LINE_TARGETING_DISTANCE.asFloat())
.destinationTeleportMargin(Setting.DEFAULT_DESTINATION_TELEPORT_MARGIN.asDouble());
.destinationTeleportMargin(Setting.DEFAULT_DESTINATION_TELEPORT_MARGIN.asDouble())
.fallDistance(Setting.PATHFINDER_FALL_DISTANCE.asInt());
private PathStrategy executing;
private int lastX, lastY, lastZ;
private NavigatorParameters localParams = defaultParams;
@ -174,6 +175,9 @@ public class CitizensNavigator implements Navigator, Runnable {
if (root.keyExists("updatepathrate")) {
defaultParams.updatePathRate(root.getInt("updatepathrate"));
}
if (root.keyExists("falldistance")) {
defaultParams.fallDistance(root.getInt("falldistance"));
}
defaultParams.speedModifier((float) root.getDouble("speedmodifier", 1F));
defaultParams.avoidWater(root.getBoolean("avoidwater"));
if (!root.getBoolean("usedefaultstuckaction") && defaultParams.stuckAction() == TeleportStuckAction.INSTANCE) {
@ -268,6 +272,11 @@ public class CitizensNavigator implements Navigator, Runnable {
} else {
root.removeKey("updatepathrate");
}
if (defaultParams.fallDistance() != Setting.PATHFINDER_FALL_DISTANCE.asTicks()) {
root.setInt("falldistance", defaultParams.fallDistance());
} else {
root.removeKey("falldistance");
}
if (defaultParams.useNewPathfinder() != Setting.USE_NEW_PATHFINDER.asBoolean()) {
root.setBoolean("usenewpathfinder", defaultParams.useNewPathfinder());
} else {
@ -334,8 +343,7 @@ public class CitizensNavigator implements Navigator, Runnable {
stopNavigating(CancelReason.REPLACE);
}
localParams = defaultParams.clone();
int fallDistance = npc.data().get(NPC.Metadata.PATHFINDER_FALL_DISTANCE,
Setting.PATHFINDER_FALL_DISTANCE.asInt());
int fallDistance = localParams.fallDistance();
if (fallDistance != -1) {
localParams.examiner(new FallingExaminer(fallDistance));
}

View File

@ -7,6 +7,7 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -686,8 +687,8 @@ public class ShopTrait extends Trait {
if (description.isEmpty()) {
meta.setLore(Lists.newArrayList());
} else {
meta.setLore(Lists
.newArrayList(Splitter.on('\n').split(Messaging.parseComponents(description))));
meta.setLore(Splitter.on("<br>").splitToStream(description)
.map(s -> Messaging.parseComponents(s)).collect(Collectors.toList()));
}
modified.display.setItemMeta(meta);
});

View File

@ -48,7 +48,6 @@ import com.mojang.authlib.GameProfile;
import com.mojang.authlib.GameProfileRepository;
import com.mojang.authlib.ProfileLookupCallback;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.ai.NavigatorParameters;
import net.citizensnpcs.api.astar.pathfinder.SwimmingExaminer;
@ -256,10 +255,8 @@ public class NMS {
}
public static int getFallDistance(NPC npc, int def) {
return npc == null ? def
: npc.data().get(NPC.Metadata.PATHFINDER_FALL_DISTANCE,
Setting.PATHFINDER_FALL_DISTANCE.asInt() != -1 ? Setting.PATHFINDER_FALL_DISTANCE.asInt()
: def);
return npc == null || npc.getNavigator().getLocalParameters().fallDistance() == -1 ? def
: npc.getNavigator().getLocalParameters().fallDistance();
}
public static Field getField(Class<?> clazz, String field) {