Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
josemmo committed Jan 9, 2023
2 parents 8061c4b + 1fd4319 commit 1ce3e60
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/main/java/io/josemmo/bukkit/plugin/utils/Permissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.internal.platform.WorldGuardPlatform;
import io.josemmo.bukkit.plugin.YamipaPlugin;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.concurrent.Callable;
import java.util.logging.Level;

public class Permissions {
@Nullable private static WorldGuard worldGuard = null;
Expand Down Expand Up @@ -48,8 +52,20 @@ public static boolean canEditBlock(@NotNull Player player, @NotNull Location loc
}

// Check GriefPrevention permissions
if (griefPrevention != null && griefPrevention.allowBuild(player, location) != null) {
return false;
if (griefPrevention != null) {
YamipaPlugin plugin = YamipaPlugin.getInstance();
Callable<Boolean> canEditCallable = () -> griefPrevention.allowBuild(player, location) == null;
try {
Boolean canEdit = Bukkit.isPrimaryThread() ?
canEditCallable.call() :
Bukkit.getScheduler().callSyncMethod(plugin, canEditCallable).get();
if (!canEdit) {
return false;
}
} catch (Exception e) {
plugin.log(Level.SEVERE, "Failed to get player permissions from GriefPrevention", e);
return false;
}
}

// Passed all checks, player can edit this block
Expand Down

0 comments on commit 1ce3e60

Please sign in to comment.