-
-
Notifications
You must be signed in to change notification settings - Fork 7
GH-188 Add support for folia-based servers. #275
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
base: master
Are you sure you want to change the base?
Changes from all commits
952551b
6a07b94
ec8208a
e252c7f
d349352
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.eternalcode.combat; | ||
|
||
import com.eternalcode.commons.bukkit.scheduler.BukkitSchedulerImpl; | ||
import com.eternalcode.commons.bukkit.scheduler.MinecraftScheduler; | ||
import com.eternalcode.commons.folia.scheduler.FoliaSchedulerImpl; | ||
import java.util.logging.Logger; | ||
import org.bukkit.plugin.Plugin; | ||
|
||
public final class CombatSchedulerAdapter { | ||
|
||
private static final String FOLIA_CLASS = "io.papermc.paper.threadedregions.RegionizedServer"; | ||
|
||
private CombatSchedulerAdapter() { | ||
throw new IllegalStateException("You can't instantiate this class"); | ||
} | ||
|
||
public static MinecraftScheduler getAdaptiveScheduler(Plugin plugin) { | ||
vLuckyyy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Logger logger = plugin.getLogger(); | ||
|
||
try { | ||
Class.forName(FOLIA_CLASS); | ||
logger.info("» Detected Folia environment. Using FoliaScheduler."); | ||
return new FoliaSchedulerImpl(plugin); | ||
} | ||
catch (ClassNotFoundException exception) { | ||
logger.info("» Detected Bukkit/Paper environment. Using BukkitScheduler."); | ||
return new BukkitSchedulerImpl(plugin); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import com.eternalcode.combat.region.Point; | ||
import com.eternalcode.combat.region.Region; | ||
import com.eternalcode.combat.region.RegionProvider; | ||
import com.eternalcode.commons.bukkit.scheduler.MinecraftScheduler; | ||
import com.eternalcode.commons.scheduler.Scheduler; | ||
import java.time.Duration; | ||
import java.util.HashMap; | ||
|
@@ -18,12 +19,12 @@ | |
public final class KnockbackService { | ||
|
||
private final PluginConfig config; | ||
private final Scheduler scheduler; | ||
private final MinecraftScheduler scheduler; | ||
private final RegionProvider regionProvider; | ||
|
||
private final Map<UUID, Region> insideRegion = new HashMap<>(); | ||
|
||
public KnockbackService(PluginConfig config, Scheduler scheduler, RegionProvider regionProvider) { | ||
public KnockbackService(PluginConfig config, MinecraftScheduler scheduler, RegionProvider regionProvider) { | ||
this.config = config; | ||
this.scheduler = scheduler; | ||
this.regionProvider = regionProvider; | ||
|
@@ -39,7 +40,8 @@ public void forceKnockbackLater(Player player, Region region) { | |
} | ||
|
||
insideRegion.put(player.getUniqueId(), region); | ||
scheduler.runLater(() -> { | ||
|
||
scheduler.runLater(player.getLocation(), () -> { | ||
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. if this player.getLocation() is here, can it be removed in the next line? |
||
insideRegion.remove(player.getUniqueId()); | ||
Location playerLocation = player.getLocation(); | ||
if (!region.contains(playerLocation) && !regionProvider.isInRegion(playerLocation)) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ record Point2D(int x, int z) { | |
|
||
Location toLocation(Location location) { | ||
World world = location.getWorld(); | ||
int y = world.getHighestBlockYAt(x, z) + 1; | ||
double y = location.getY(); | ||
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. By preserving the player's Y-coordinate, you risk teleporting them inside blocks or terrain if the new X/Z coordinates are inside a wall or mountain. The previous implementation using 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. will do research on this |
||
|
||
return new Location(world, x, y, z, location.getYaw(), location.getPitch()); | ||
} | ||
|
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.
nitpick, but it's a standard in our utility classes