Add sittable support to /npc sitting, disable array pooling for now

This commit is contained in:
fullwall 2023-06-11 16:51:28 +08:00
parent ddc938a38c
commit 64b200837d
7 changed files with 30 additions and 10 deletions

View File

@ -32,6 +32,7 @@ import com.google.common.io.Files;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import ch.ethz.globis.phtree.PhTreeHelper;
import net.byteflux.libby.BukkitLibraryManager;
import net.byteflux.libby.Library;
import net.byteflux.libby.LibraryManager;
@ -337,6 +338,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
} catch (Throwable t) {
lib.loadLibrary(Library.builder().groupId("org{}joml").artifactId("joml").version("1.10.5").build());
}
PhTreeHelper.enablePooling(false);
}
@Override

View File

@ -2670,7 +2670,7 @@ public class NPCCommands {
at = npc.getStoredLocation();
}
trait.setSitting(at);
Messaging.sendTr(sender, Messages.SITTING_SET, npc.getName(), at);
Messaging.sendTr(sender, Messages.SITTING_SET, npc.getName(), Util.prettyPrintLocation(at));
}
@Command(

View File

@ -174,19 +174,11 @@ public class FlyingAStarNavigationStrategy extends AbstractPathStrategy {
velocity.setX(motX).setY(motY).setZ(motZ).multiply(parameters.speed());
npc.getEntity().setVelocity(velocity);
float targetYaw = (float) (Math.toDegrees(Math.atan2(motZ, motX))) - 90.0F;
float normalisedTargetYaw = (targetYaw - current.getYaw()) % 360;
if (normalisedTargetYaw >= 180.0F) {
normalisedTargetYaw -= 360.0F;
}
if (normalisedTargetYaw < -180.0F) {
normalisedTargetYaw += 360.0F;
}
if (npc.getEntity().getType() != EntityType.ENDER_DRAGON) {
NMS.setVerticalMovement(npc.getEntity(), 0.5);
Util.faceLocation(npc.getEntity(), centeredDest.toLocation(npc.getEntity().getWorld()));
}
plan.run(npc);
return false;
}

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.trait;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Sittable;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import net.citizensnpcs.api.CitizensAPI;
@ -29,6 +30,11 @@ public class SitTrait extends Trait {
@Override
public void onDespawn() {
if (SUPPORT_SITTABLE && npc.getEntity() instanceof Sittable) {
((Sittable) npc.getEntity()).setSitting(false);
return;
}
if (chair != null) {
if (chair.getEntity() != null) {
chair.getEntity().eject();
@ -48,6 +54,13 @@ public class SitTrait extends Trait {
if (!npc.isSpawned() || !isSitting())
return;
if (SUPPORT_SITTABLE && npc.getEntity() instanceof Sittable) {
((Sittable) npc.getEntity()).setSitting(true);
if (npc.getEntity().getLocation().distance(sittingAt) > 0.05) {
npc.teleport(sittingAt, TeleportCause.PLUGIN);
}
}
if (chair == null) {
NPCRegistry registry = CitizensAPI.getNamedNPCRegistry("SitRegistry");
if (registry == null) {
@ -76,4 +89,13 @@ public class SitTrait extends Trait {
onDespawn();
}
}
private static boolean SUPPORT_SITTABLE = true;
static {
try {
Class.forName("org.bukkit.entity.Sittable");
} catch (ClassNotFoundException e) {
SUPPORT_SITTABLE = false;
}
}
}

View File

@ -33,6 +33,8 @@ public class AnimationTriggerPrompt extends StringPrompt implements WaypointTrig
at = CommandContext.parseLocation(
context.getForWhom() instanceof Player ? ((Player) context.getForWhom()).getLocation() : null,
input.replaceFirst("at ", ""));
Messaging.send((CommandSender) context.getForWhom(), Messages.WAYPOINT_TRIGGER_ANIMATION_AT_SET,
Util.prettyPrintLocation(at));
} catch (CommandException e) {
Messaging.send((CommandSender) context.getForWhom(), e.getMessage());
}

View File

@ -457,6 +457,7 @@ public class Messages {
public static final String WAYPOINT_TELEPORTING_ENABLED = "citizens.commands.waypoints.disableteleporting.enabled";
public static final String WAYPOINT_TRIGGER_ADD_PROMPT = "citizens.editors.waypoints.triggers.add.prompt";
public static final String WAYPOINT_TRIGGER_ADDED_SUCCESSFULLY = "citizens.editors.waypoints.triggers.add.added";
public static final String WAYPOINT_TRIGGER_ANIMATION_AT_SET = "citizens.editors.waypoints.triggers.animation.at-set";
public static final String WAYPOINT_TRIGGER_CHAT_INVALID_RADIUS = "citizens.editors.waypoints.triggers.chat.invalid-radius";
public static final String WAYPOINT_TRIGGER_CHAT_NO_RADIUS = "citizens.editors.waypoints.triggers.chat.missing-radius";
public static final String WAYPOINT_TRIGGER_EDITOR_EXIT = "citizens.editors.waypoints.triggers.main.exit";

View File

@ -431,6 +431,7 @@ citizens.editors.waypoints.triggers.add.added=Added waypoint trigger successfull
citizens.editors.waypoints.triggers.add.invalid-trigger=Couldn''t create a trigger by the name [[{0}]].
citizens.editors.waypoints.triggers.add.prompt=Enter in a trigger name to add or type [[back]] to return to the edit prompt. Valid trigger names are {0}.
citizens.editors.waypoints.triggers.animation.added=Animation [[{0}]] added.
citizens.editors.waypoints.triggers.animation.at-set=Animation location set to [[{0}]].
citizens.editors.waypoints.triggers.list=Current triggers are:{0}
citizens.editors.waypoints.triggers.animation.prompt=Enter in animations to perform - valid animations are {0}.<br>[[at (x:y:z:world)]] optionally set a location to perform the animation at.<br>Type in [[finish]] to finish the animation trigger or [[back]] to return to the previous prompt.
citizens.editors.waypoints.triggers.animation.invalid-animation=Invalid animation [[{0}]]. Valid animations are {1}.