-
-
Notifications
You must be signed in to change notification settings - Fork 112
fix look command offthread_repeat math and mounted rotation
#2836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BehrRiley
wants to merge
4
commits into
DenizenScript:dev
Choose a base branch
from
BehrRiley:fix/teleport-and-rotation-mechanics
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
262ef0c
fix look command `offthread_repeat` math and mounted rotation
BehrRiley d0f839e
review revisions
BehrRiley e04da2f
clean up `FQN`s and formatting in `TeleportCommand` as well
BehrRiley 7746cd0
Merge branch 'DenizenScript:dev' into fix/teleport-and-rotation-mecha…
BehrRiley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,10 +125,16 @@ public static void autoExecute(ScriptEntry scriptEntry, | |
| final float pitchRaw = pitch == null ? 0 : pitch.asFloat(); | ||
| for (EntityTag entity : entities) { | ||
| if (entity.isSpawned()) { | ||
| if (loc != null) { | ||
| NMSHandler.entityHelper.faceLocation(entity.getBukkitEntity(), loc); | ||
| org.bukkit.entity.Entity bukkitEntity = entity.getBukkitEntity(); | ||
| org.bukkit.entity.Entity vehicle = bukkitEntity.getVehicle(); | ||
|
|
||
| if (vehicle != null) { | ||
| bukkitEntity.leaveVehicle(); | ||
| } | ||
| else { | ||
|
|
||
| if (loc != null) { | ||
| NMSHandler.entityHelper.faceLocation(bukkitEntity, loc); | ||
| } else { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Newline after each }.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can make this |
||
| if (entity.isPlayer()) { | ||
| Location playerTeleDest = entity.getLocation().clone(); | ||
| float relYaw = (yawRaw - playerTeleDest.getYaw()) % 360; | ||
|
|
@@ -140,40 +146,68 @@ public static void autoExecute(ScriptEntry scriptEntry, | |
| playerTeleDest.setYaw(yawRaw); | ||
| playerTeleDest.setPitch(pitchRaw); | ||
| Player player = entity.getPlayer(); | ||
| if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) { | ||
| NetworkInterceptHelper.enable(); | ||
| NMSHandler.packetHelper.sendRelativeLookPacket(player, actualRelYaw, relPitch); | ||
| } | ||
| else { | ||
|
|
||
| if (vehicle != null) { | ||
| PaperAPITools.instance.teleport(player, playerTeleDest, PlayerTeleportEvent.TeleportCause.PLUGIN, null, Arrays.asList(TeleportCommand.Relative.values())); | ||
| } | ||
| if (offthreadRepeats != null) { | ||
| NetworkInterceptHelper.enable(); | ||
| int times = offthreadRepeats.asInt(); | ||
| int ms = 50 / (times + 1); | ||
| DenizenCore.runAsync(() -> { | ||
| try { | ||
| for (int i = 0; i < times; i++) { | ||
| Thread.sleep(ms); | ||
| NMSHandler.packetHelper.sendRelativeLookPacket(player, actualRelYaw, relPitch); | ||
| } else { | ||
| final int times = offthreadRepeats != null ? offthreadRepeats.asInt() : 0; | ||
| final float stepYaw = times > 0 ? actualRelYaw / (times + 1) : actualRelYaw; | ||
| final float stepPitch = times > 0 ? relPitch / (times + 1) : relPitch; | ||
|
|
||
| if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) { | ||
| NetworkInterceptHelper.enable(); | ||
| NMSHandler.packetHelper.sendRelativeLookPacket(player, stepYaw, stepPitch); | ||
| } else { | ||
| PaperAPITools.instance.teleport(player, playerTeleDest, PlayerTeleportEvent.TeleportCause.PLUGIN, null, Arrays.asList(TeleportCommand.Relative.values())); | ||
| } | ||
|
|
||
| if (offthreadRepeats != null) { | ||
| NetworkInterceptHelper.enable(); | ||
| int ms = 50 / (times + 1); | ||
| DenizenCore.runAsync(() -> { | ||
| try { | ||
| for (int i = 0; i < times; i++) { | ||
| Thread.sleep(ms); | ||
| NMSHandler.packetHelper.sendRelativeLookPacket(player, stepYaw, stepPitch); | ||
| } | ||
| } catch (Throwable ex) { | ||
| Debug.echoError(ex); | ||
| } | ||
| } | ||
| catch (Throwable ex) { | ||
| Debug.echoError(ex); | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
| } else { | ||
| NMSHandler.entityHelper.rotate(bukkitEntity, yawRaw, pitchRaw); | ||
| } | ||
| else { | ||
| NMSHandler.entityHelper.rotate(entity.getBukkitEntity(), yawRaw, pitchRaw); | ||
| } | ||
|
|
||
| if (vehicle != null) { | ||
| Location vLoc = vehicle.getLocation().clone(); | ||
| if (loc != null) { | ||
| org.bukkit.util.Vector dir = loc.toVector().subtract(vLoc.toVector()); | ||
| if (dir.lengthSquared() > 0) { | ||
| vLoc.setDirection(dir); | ||
| } | ||
| } else { | ||
| vLoc.setYaw(yawRaw); | ||
| vLoc.setPitch(pitchRaw); | ||
| } | ||
|
|
||
| vehicle.teleport(vLoc, PlayerTeleportEvent.TeleportCause.PLUGIN); | ||
|
|
||
| org.bukkit.Bukkit.getScheduler().runTask(com.denizenscript.denizen.Denizen.getInstance(), () -> { | ||
| if (vehicle.isValid() && bukkitEntity.isValid()) { | ||
| vehicle.addPassenger(bukkitEntity); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| if (duration != null && duration.getTicks() > 1) { | ||
| for (EntityTag entity : entities) { | ||
| BukkitRunnable task = new BukkitRunnable() { | ||
| long bounces = 0; | ||
|
|
||
| public void run() { | ||
| bounces++; | ||
| if (bounces > duration.getTicks()) { | ||
|
|
@@ -182,11 +216,19 @@ public void run() { | |
| return; | ||
| } | ||
| if (entity.isSpawned()) { | ||
| org.bukkit.entity.Entity target = entity.getBukkitEntity(); | ||
| org.bukkit.entity.Entity vehicle = target.getVehicle(); | ||
|
|
||
| if (loc != null) { | ||
| NMSHandler.entityHelper.faceLocation(entity.getBukkitEntity(), loc); | ||
| } | ||
| else { | ||
| NMSHandler.entityHelper.rotate(entity.getBukkitEntity(), yawRaw, pitchRaw); | ||
| NMSHandler.entityHelper.faceLocation(target, loc); | ||
| if (vehicle != null) { | ||
| NMSHandler.entityHelper.faceLocation(vehicle, loc); | ||
| } | ||
| } else { | ||
| NMSHandler.entityHelper.rotate(target, yawRaw, pitchRaw); | ||
| if (vehicle != null) { | ||
| NMSHandler.entityHelper.rotate(vehicle, yawRaw, pitchRaw); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can clean up FQN for these.