Minor changes

This commit is contained in:
fullwall 2022-11-06 23:19:08 +08:00
parent c03160e73e
commit cda8aceb5d
7 changed files with 79 additions and 68 deletions

View File

@ -2862,7 +2862,7 @@ public class NPCCommands {
permission = "citizens.npc.wander")
public void wander(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
Waypoints trait = npc.getOrAddTrait(Waypoints.class);
trait.setWaypointProvider(trait.getCurrentProviderName().equals("wander") ? "wander" : "linear");
trait.setWaypointProvider(trait.getCurrentProviderName().equals("wander") ? "linear" : "wander");
Messaging.sendTr(sender, Messages.WAYPOINT_PROVIDER_SET, trait.getCurrentProviderName());
}

View File

@ -223,6 +223,17 @@ public class CitizensNPC extends AbstractNPC {
updateFlyableState();
}
@Override
public void setMoveDestination(Location destination) {
if (!isSpawned())
return;
if (destination == null) {
NMS.cancelMoveDestination(getEntity());
} else {
NMS.setDestination(getEntity(), destination.getX(), destination.getY(), destination.getZ(), 1);
}
}
@Override
public void setName(String name) {
super.setName(name);

View File

@ -184,6 +184,7 @@ public class CitizensTraitFactory implements TraitFactory {
@Override
public void registerTrait(TraitInfo info) {
Preconditions.checkNotNull(info, "info cannot be null");
info.checkValid();
if (registered.containsKey(info.getTraitName())) {
throw new IllegalArgumentException("Trait name " + info.getTraitName() + " already registered");
}

View File

@ -48,6 +48,8 @@ public class WanderWaypointProvider
@Persist
public int delay = -1;
private NPC npc;
@Persist
public boolean pathfind = true;
private boolean paused;
@Persist
private final List<Location> regionCentres = Lists.newArrayList();
@ -110,7 +112,7 @@ public class WanderWaypointProvider
@Override
public void begin() {
Messaging.sendTr(sender, Messages.WANDER_WAYPOINTS_BEGIN);
Messaging.sendTr(sender, Messages.WANDER_WAYPOINTS_BEGIN, pathfind ? "<green>" : "<red>");
if (currentGoal != null) {
currentGoal.pause();
}
@ -155,18 +157,12 @@ public class WanderWaypointProvider
recalculateTree();
} catch (Exception ex) {
}
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
Messaging.sendTr(sender, Messages.WANDER_WAYPOINTS_RANGE_SET, xrange, yrange);
}
});
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
() -> Messaging.sendTr(sender, Messages.WANDER_WAYPOINTS_RANGE_SET, xrange, yrange));
} else if (message.startsWith("regions")) {
event.setCancelled(true);
editingRegions = !editingRegions;
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> {
if (editingRegions) {
for (Location regionCentre : regionCentres) {
Entity entity = markers.createMarker(regionCentre, regionCentre);
@ -178,7 +174,6 @@ public class WanderWaypointProvider
markers.destroyMarkers();
Messaging.sendTr(sender, Messages.WANDER_WAYPOINTS_REGION_EDITING_STOP);
}
}
});
} else if (message.startsWith("delay")) {
event.setCancelled(true);
@ -187,25 +182,15 @@ public class WanderWaypointProvider
if (currentGoal != null) {
currentGoal.setDelay(delay);
}
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
Messaging.sendTr(sender, Messages.WANDER_WAYPOINTS_DELAY_SET, delay);
}
});
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
() -> Messaging.sendTr(sender, Messages.WANDER_WAYPOINTS_DELAY_SET, delay));
} catch (Exception e) {
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
Messaging.sendErrorTr(sender, Messages.WANDER_WAYPOINTS_INVALID_DELAY);
}
});
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
() -> Messaging.sendErrorTr(sender, Messages.WANDER_WAYPOINTS_INVALID_DELAY));
}
} else if (message.startsWith("worldguardregion")) {
event.setCancelled(true);
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> {
Object region = null;
String regionId = message.replace("worldguardregion ", "");
try {
@ -224,7 +209,15 @@ public class WanderWaypointProvider
currentGoal.setWorldGuardRegion(region);
}
Messaging.sendErrorTr(sender, Messages.WANDER_WAYPOINTS_WORLDGUARD_REGION_SET, regionId);
});
} else if (message.startsWith("pathfind")) {
event.setCancelled(true);
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> {
pathfind = !pathfind;
if (currentGoal != null) {
currentGoal.setPathfind(pathfind);
}
begin();
});
}
}

View File

@ -95,7 +95,7 @@ public abstract class AbstractBlockBreaker extends BlockBreaker {
.distanceMargin(Math.max(configuration.radius() - 1, 0.75));
setTarget = true;
}
} else if (NMS.getDestination(entity) == null) {
} else {
NMS.setDestination(entity, x, y, z, 1);
setTarget = true;
}

View File

@ -1,13 +1,14 @@
package net.citizensnpcs.util;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.function.Function;
import java.util.stream.StreamSupport;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -27,7 +28,6 @@ import org.bukkit.util.Vector;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import io.netty.util.Version;
import net.citizensnpcs.api.event.NPCCollisionEvent;
@ -331,8 +331,9 @@ public class Util {
}
public static String prettyPrintLocation(Location to) {
return String.format("%s at %d, %d, %d (%d, %d)", to.getWorld().getName(), to.getBlockX(), to.getBlockY(),
to.getBlockZ(), (int) to.getYaw(), (int) to.getPitch());
return String.format("%s at %s, %s, %s (%s, %s)", to.getWorld().getName(), TWO_DIGIT_DECIMAL.format(to.getX()),
TWO_DIGIT_DECIMAL.format(to.getY()), TWO_DIGIT_DECIMAL.format(to.getZ()),
TWO_DIGIT_DECIMAL.format(to.getYaw()), TWO_DIGIT_DECIMAL.format(to.getPitch()));
}
public static boolean requiresNettyChannelMetadata() {
@ -346,7 +347,8 @@ public class Util {
if (version == null)
return REQUIRES_CHANNEL_METADATA = false;
try {
Integer[] parts = StreamSupport.stream(Splitter.on('.').split(version.artifactVersion()).spliterator(), false).map(string -> {
Integer[] parts = StreamSupport
.stream(Splitter.on('.').split(version.artifactVersion()).spliterator(), false).map(string -> {
// Newer versions of netty use suffix (like .Final) that can't be parsed to Integer
try {
return Integer.parseInt(string);
@ -375,4 +377,8 @@ public class Util {
private static final Scoreboard DUMMY_SCOREBOARD = Bukkit.getScoreboardManager().getNewScoreboard();
private static String MINECRAFT_REVISION;
private static Boolean REQUIRES_CHANNEL_METADATA;
private static final DecimalFormat TWO_DIGIT_DECIMAL = new DecimalFormat();
static {
TWO_DIGIT_DECIMAL.setMaximumFractionDigits(2);
}
}

View File

@ -348,7 +348,7 @@ citizens.editors.waypoints.wander.editing-regions-stop=Exited the region editor.
citizens.editors.waypoints.wander.worldguard-region-not-found=WorldGuard region not found.
citizens.editors.waypoints.wander.worldguard-region-set=WorldGuard region set to [[{0}]].
citizens.editors.waypoints.wander.range-set=Wander range set to xrange [[{0}]] and yrange [[{1}]].
citizens.editors.waypoints.wander.begin=<aqua>Entered the wander waypoint editor.<br><click:suggest_command:xrange ><hover:show_text:Set the x range in blocks><yellow>x range</hover></click> | <click:suggest_command:yrange ><hover:show_text:Set the y range in blocks><yellow>y range</hover></click> | <click:suggest_command:delay ><hover:show_text:Ticks to wait in between wanders><yellow>delay</hover></click><br><click:suggest_command:regions><yellow>Enter the region editor</click> | <click:suggest_command:worldguardregion ><hover:show_text:Restrict wandering to WorldGuard regions><yellow>region</hover></click>
citizens.editors.waypoints.wander.begin=<aqua>Entered the wander waypoint editor.<br><click:suggest_command:pathfind><hover:show_text:Pathfind>{0}Pathfind</hover></click> | <click:suggest_command:xrange ><hover:show_text:Set the x range in blocks><yellow>x range</hover></click> | <click:suggest_command:yrange ><hover:show_text:Set the y range in blocks><yellow>y range</hover></click> | <click:suggest_command:delay ><hover:show_text:Ticks to wait in between wanders><yellow>delay</hover></click><br><click:suggest_command:regions><yellow>Enter the region editor</click> | <click:suggest_command:worldguardregion ><hover:show_text:Restrict wandering to WorldGuard regions><yellow>region</hover></click>
citizens.editors.waypoints.wander.end=Exited the wander waypoint editor.
citizens.editors.waypoints.wander.delay-set=Delay between wanders set to [[{0}]] ticks.
citizens.editors.waypoints.wander.invalid-delay=Invalid delay specified.