Skip to content

Commit

Permalink
Fix teleporting sync (#7)
Browse files Browse the repository at this point in the history
* remove usages of bukkit scheduler

* switch to good folia lib

* update to latest official shadow

* fix reflective 1.21.1 errors

* fix reflective 1.20.6 errors

* Fix pose injection

* fix maven publishing

* fix trying to teleport in sync
  • Loading branch information
CJCrafter authored Oct 8, 2024
1 parent 8cc4b5c commit 42bc9f2
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies {

// We shade these
implementation("com.github.cryptomorin:XSeries:11.1.0")
implementation("com.cjcrafter:foliascheduler:0.5.0")
implementation("com.cjcrafter:foliascheduler:0.6.0")
implementation("org.bstats:bstats-bukkit:3.0.1")
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=3.1.0
version=3.1.1
2 changes: 1 addition & 1 deletion src/main/java/com/cjcrafter/vivecraft/VSE.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class VSE extends JavaPlugin implements Listener {
public boolean debug = false;
public boolean vault;
FileConfiguration config = getConfig();
private ServerImplementation scheduler;
public ServerImplementation scheduler;
private TaskImplementation<Void> sendPosDataTask;

public static boolean isVive(Player p) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ public void onProjectileLaunch(ProjectileLaunchEvent event) {
}

Location loc = new Location(proj.getWorld(), pos.getX() + aim.getX() * 0.6f, pos.getY() + aim.getY() * 0.6f, pos.getZ() + aim.getZ() * 0.6f);
final Vector finalAim = aim;
double velo = proj.getVelocity().length();
proj.teleport(loc); //paper sets velocity to 0 on teleport.
proj.setVelocity(new Vector(aim.getX() * velo, aim.getY() * velo, aim.getZ() * velo));
VSE.me.scheduler.teleportAsync(proj, loc).thenAccept((a) -> {
proj.setVelocity(new Vector(finalAim.getX() * velo, finalAim.getY() * velo, finalAim.getZ() * velo));
});
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.cjcrafter.vivecraft.listeners;

import com.cryptomorin.xseries.XEntityType;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -36,8 +37,8 @@ public void onPlayerDropItem(PlayerDropItemEvent event) {
v.setY(Math.sin(pitch * 0.017453292F) * f2 + 0.1F);

Vector aim = vp.getControllerDir(0);
event.getItemDrop().teleport(vp.getControllerPos(0).add(0.2f * aim.getX(), 0.25f * aim.getY() - 0.2f, 0.2f * aim.getZ()));
event.getItemDrop().setVelocity(v);
Location target = vp.getControllerPos(0).add(0.2f * aim.getX(), 0.25f * aim.getY() - 0.2f, 0.2f * aim.getZ());
VSE.me.scheduler.teleportAsync(event.getItemDrop(), target).thenAccept((a) -> event.getItemDrop().setVelocity(v));
}
}
}

0 comments on commit 42bc9f2

Please sign in to comment.