1 parent
1666d815b2
commit
a3b5999de3
4 files changed
+5
-92
No files matched your search
@@ -3,7 +3,6 @@ package me.caseload.knockbacksync;
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder;
|
||||
import lombok.Getter;
|
||||
import me.caseload.knockbacksync.event.events.ConfigReloadEvent;
|
||||
import me.caseload.knockbacksync.event.KBSyncEventHandler;
|
||||
import me.caseload.knockbacksync.listener.bukkit.*;
|
||||
@@ -40,13 +39,14 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class BukkitBase extends Base {
|
||||
|
||||
@Getter private final JavaPlugin plugin;
|
||||
private final JavaPlugin plugin;
|
||||
private final BukkitSenderFactory bukkitSenderFactory = new BukkitSenderFactory(this);
|
||||
private final PluginPermissionChecker permissionChecker = new PluginPermissionChecker();
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ package me.caseload.knockbacksync.stats.custom;
|
||||
* Violations will result in a ban of your plugin and account from bStats.
|
||||
*/
|
||||
|
||||
import me.caseload.knockbacksync.BukkitLoaderPlugin;
|
||||
import me.caseload.knockbacksync.Base;
|
||||
import me.caseload.knockbacksync.stats.CustomChart;
|
||||
import me.caseload.knockbacksync.stats.JsonObjectBuilder;
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
package me.caseload.knockbacksync.world;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.world.states.WrappedBlockState;
|
||||
import com.github.retrooper.packetevents.util.Vector3d;
|
||||
import com.github.retrooper.packetevents.util.Vector3i;
|
||||
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
|
||||
import io.github.retrooper.packetevents.util.folia.FoliaScheduler;
|
||||
import io.github.retrooper.packetevents.util.folia.RegionScheduler;
|
||||
import me.caseload.knockbacksync.Base;
|
||||
import me.caseload.knockbacksync.BukkitBase;
|
||||
import me.caseload.knockbacksync.listener.bukkit.BukkitPlayerKnockbackListener;
|
||||
import me.caseload.knockbacksync.world.raytrace.FluidHandling;
|
||||
import me.caseload.knockbacksync.world.raytrace.RayTraceResult;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.FluidCollisionMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class FoliaWorld extends SpigotWorld {
|
||||
|
||||
private final RegionScheduler scheduler;
|
||||
private final JavaPlugin plugin = ((BukkitBase) Base.INSTANCE).getPlugin();
|
||||
|
||||
public FoliaWorld(World world) {
|
||||
super(world);
|
||||
this.scheduler = FoliaScheduler.getRegionScheduler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WrappedBlockState getBlockStateAt(int x, int y, int z) {
|
||||
Location location = new Location(super.world, x, y, z);
|
||||
CompletableFuture<WrappedBlockState> future = new CompletableFuture<>();
|
||||
|
||||
scheduler.execute(plugin, location, () -> {
|
||||
Block block = location.getBlock();
|
||||
future.complete(SpigotConversionUtil.fromBukkitBlockData(block.getBlockData()));
|
||||
});
|
||||
|
||||
try {
|
||||
return future.get(); // Wait for the result
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null; // Handle error appropriately
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RayTraceResult rayTraceBlocks(Vector3d start, Vector3d direction, double maxDistance, FluidHandling fluidHandling, boolean ignorePassableBlocks) {
|
||||
Location location = new Location(super.world, start.getX(), start.getY(), start.getZ());
|
||||
CompletableFuture<RayTraceResult> future = new CompletableFuture<>();
|
||||
|
||||
scheduler.execute(plugin, location, () -> {
|
||||
// Existing 1.13+ code using world.rayTraceBlocks
|
||||
Vector startVec = new Vector(start.getX(), start.getY(), start.getZ());
|
||||
Vector directionVec = new Vector(direction.getX(), direction.getY(), direction.getZ());
|
||||
|
||||
FluidCollisionMode fluidMode = (fluidHandling == FluidHandling.NONE) ? FluidCollisionMode.NEVER :
|
||||
(fluidHandling == FluidHandling.SOURCE_ONLY) ? FluidCollisionMode.SOURCE_ONLY :
|
||||
FluidCollisionMode.ALWAYS;
|
||||
|
||||
org.bukkit.util.RayTraceResult result = super.world.rayTraceBlocks(startVec.toLocation(super.world), directionVec, maxDistance, fluidMode, ignorePassableBlocks);
|
||||
|
||||
if (result == null) {
|
||||
future.complete(null);
|
||||
return;
|
||||
}
|
||||
|
||||
future.complete(new RayTraceResult(
|
||||
new Vector3d(result.getHitPosition().getX(), result.getHitPosition().getY(), result.getHitPosition().getZ()),
|
||||
getBlockFaceFrom(result.getHitBlockFace()),
|
||||
new Vector3i(result.getHitBlock().getX(), result.getHitBlock().getY(), result.getHitBlock().getY()),
|
||||
result.getHitBlock() != null ? SpigotConversionUtil.fromBukkitBlockData(result.getHitBlock().getBlockData()) : null
|
||||
));
|
||||
});
|
||||
|
||||
try {
|
||||
return future.get(); // Wait for the result
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null; // Handle error appropriately
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ import org.bukkit.util.Vector;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class SpigotWorld implements PlatformWorld {
|
||||
protected final World world;
|
||||
private final World world;
|
||||
|
||||
// Reflection variables
|
||||
private static Class<?> craftWorldClass;
|
||||
@@ -58,7 +58,7 @@ public class SpigotWorld implements PlatformWorld {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
protected static BlockFace getBlockFaceFrom(org.bukkit.block.BlockFace direction) {
|
||||
private static BlockFace getBlockFaceFrom(org.bukkit.block.BlockFace direction) {
|
||||
switch (direction) {
|
||||
case NORTH:
|
||||
return BlockFace.NORTH;
|
||||
|
||||
Reference in new issue
Block a user