Skip to content

Commit

Permalink
Update version and fix CoreProtect support on folia
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauriichan committed May 3, 2024
1 parent e2c2caa commit f6f3169
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.syntaxphoenix.spigot</groupId>
<artifactId>smoothtimber-legacy</artifactId>
<version>1.26.0</version>
<version>1.27.0</version>
<name>SmoothTimber</name>
<packaging>jar</packaging>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import net.coreprotect.CoreProtectAPI;

public class CoreCompat_v1_13_x implements CoreCompat {
public class CoreCompat_v1_13_x implements ICoreCompat {

private final CoreProtectAPI api;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import net.coreprotect.CoreProtectAPI;

public class CoreCompat_v1_8_x implements CoreCompat {
public class CoreCompat_v1_8_x implements ICoreCompat {

private final CoreProtectAPI api;
private final VersionChanger changer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class CoreProtect extends CompatibilityAddon {
private LocationResolver resolver;
private Listener chopListener;
private Listener growListener;
private CoreCompat compat;
private ICoreCompat compat;

private ExecutorService service;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@
import org.bukkit.event.Listener;

import com.syntaxphoenix.spigot.smoothtimber.event.AsyncPlayerChoppedTreeEvent;
import com.syntaxphoenix.spigot.smoothtimber.platform.Platform;
import com.syntaxphoenix.spigot.smoothtimber.utilities.locate.Locator;

public class CoreProtectChopListener implements Listener {

private final CoreCompat compat;
private final ICoreCompat compat;

protected CoreProtectChopListener(final CoreCompat compat) {
protected CoreProtectChopListener(final ICoreCompat compat) {
this.compat = compat;
}

@EventHandler
public void onChopEvent(final AsyncPlayerChoppedTreeEvent event) {
Platform platform = Platform.getPlatform();
if (!platform.isRegional()) {
handleChopEvent(event);
return;
}
platform.regionalTask(event.getTreeLocation(), () -> handleChopEvent(event));
}

private void handleChopEvent(final AsyncPlayerChoppedTreeEvent event) {
for (final Location location : event.getBlockLocations()) {
compat.logRemoval(event.getPlayer().getName(), location, Locator.getBlockState(location));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

public class CoreProtectGrowListener implements Listener {

private final CoreCompat compat;
private final ICoreCompat compat;

protected CoreProtectGrowListener(final CoreCompat compat) {
protected CoreProtectGrowListener(final ICoreCompat compat) {
this.compat = compat;
}

Expand All @@ -24,7 +24,7 @@ public void onGrow(final StructureGrowEvent event) {
}
final Player player = event.getPlayer();
final String user = player != null ? "#st_" + player.getName() : "#tree";
Platform.getPlatform().asyncTaskLater(() -> {
Platform.getPlatform().regionalAsyncTaskLater(event.getLocation(), () -> {
for (final BlockState state : event.getBlocks()) {
compat.logRemoval(user, state.getLocation(), state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.bukkit.Location;
import org.bukkit.block.BlockState;

public interface CoreCompat {
public interface ICoreCompat {

void logRemoval(String user, Location location, BlockState block);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ public void regionalSyncTask(final Location location, final Runnable runnable) {
public void regionalSyncTaskLater(final Location location, final Runnable runnable, final long delay) {
region.runDelayed(plugin, location, t -> runnable.run(), delay);
}

@Override
public void regionalAsyncTask(Location location, Runnable runnable) {
region.run(plugin, location, t -> runnable.run());
}

@Override
public void regionalAsyncTaskLater(Location location, Runnable runnable, long delay) {
region.runDelayed(plugin, location, t -> runnable.run(), delay);
}

@Override
public void syncTask(final Runnable runnable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ public void regionalSyncTaskLater(final Location location, final Runnable runnab
syncTaskLater(runnable, delay);
}

public void regionalAsyncTask(final Location location, final Runnable runnable) {
asyncTask(runnable);
}

public void regionalAsyncTaskLater(final Location location, final Runnable runnable, final long delay) {
asyncTaskLater(runnable, delay);
}

public abstract void syncTask(Runnable runnable);

public abstract void syncTaskLater(Runnable runnable, long delay);
Expand Down

0 comments on commit f6f3169

Please sign in to comment.