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); output += " " + Messaging.tr(Messages.PATHFINDING_OPTIONS_USE_NEW_FINDER, npc.getName(), useNewFinder);
} }
if (fallingDistance != null) { if (fallingDistance != null) {
npc.data().set(NPC.Metadata.PATHFINDER_FALL_DISTANCE, fallingDistance); npc.getNavigator().getDefaultParameters().fallDistance(fallingDistance);
output += " " output += " "
+ Messaging.tr(Messages.PATHFINDING_OPTIONS_FALLING_DISTANCE_SET, npc.getName(), fallingDistance); + 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) .stationaryTicks(Setting.DEFAULT_STATIONARY_DURATION.asTicks()).stuckAction(TeleportStuckAction.INSTANCE)
.examiner(new MinecraftBlockExaminer()).useNewPathfinder(Setting.USE_NEW_PATHFINDER.asBoolean()) .examiner(new MinecraftBlockExaminer()).useNewPathfinder(Setting.USE_NEW_PATHFINDER.asBoolean())
.straightLineTargetingDistance(Setting.DEFAULT_STRAIGHT_LINE_TARGETING_DISTANCE.asFloat()) .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 PathStrategy executing;
private int lastX, lastY, lastZ; private int lastX, lastY, lastZ;
private NavigatorParameters localParams = defaultParams; private NavigatorParameters localParams = defaultParams;
@ -174,6 +175,9 @@ public class CitizensNavigator implements Navigator, Runnable {
if (root.keyExists("updatepathrate")) { if (root.keyExists("updatepathrate")) {
defaultParams.updatePathRate(root.getInt("updatepathrate")); defaultParams.updatePathRate(root.getInt("updatepathrate"));
} }
if (root.keyExists("falldistance")) {
defaultParams.fallDistance(root.getInt("falldistance"));
}
defaultParams.speedModifier((float) root.getDouble("speedmodifier", 1F)); defaultParams.speedModifier((float) root.getDouble("speedmodifier", 1F));
defaultParams.avoidWater(root.getBoolean("avoidwater")); defaultParams.avoidWater(root.getBoolean("avoidwater"));
if (!root.getBoolean("usedefaultstuckaction") && defaultParams.stuckAction() == TeleportStuckAction.INSTANCE) { if (!root.getBoolean("usedefaultstuckaction") && defaultParams.stuckAction() == TeleportStuckAction.INSTANCE) {
@ -268,6 +272,11 @@ public class CitizensNavigator implements Navigator, Runnable {
} else { } else {
root.removeKey("updatepathrate"); 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()) { if (defaultParams.useNewPathfinder() != Setting.USE_NEW_PATHFINDER.asBoolean()) {
root.setBoolean("usenewpathfinder", defaultParams.useNewPathfinder()); root.setBoolean("usenewpathfinder", defaultParams.useNewPathfinder());
} else { } else {
@ -334,8 +343,7 @@ public class CitizensNavigator implements Navigator, Runnable {
stopNavigating(CancelReason.REPLACE); stopNavigating(CancelReason.REPLACE);
} }
localParams = defaultParams.clone(); localParams = defaultParams.clone();
int fallDistance = npc.data().get(NPC.Metadata.PATHFINDER_FALL_DISTANCE, int fallDistance = localParams.fallDistance();
Setting.PATHFINDER_FALL_DISTANCE.asInt());
if (fallDistance != -1) { if (fallDistance != -1) {
localParams.examiner(new FallingExaminer(fallDistance)); localParams.examiner(new FallingExaminer(fallDistance));
} }

View File

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

View File

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