Skip to content

Commit

Permalink
fix(integrations): GP and WG load order issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker committed Oct 5, 2023
1 parent dead00f commit 389f853
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
*/
package me.machinemaker.papertweaks.integrations.griefprevention;

import com.google.common.base.Suppliers;
import java.util.Objects;
import java.util.function.Supplier;
import me.machinemaker.papertweaks.integrations.Interactions;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.DataStore;
Expand All @@ -32,14 +34,14 @@

public class GPInteractionHandler implements Interactions.Handler {

private static final GriefPrevention PLUGIN = Objects.requireNonNull(GriefPrevention.instance, "Could not find the instance of the GriefPrevention plugin");
private static final DataStore DATA_STORE = Objects.requireNonNull(PLUGIN.dataStore, "Could not find the GriefPrevention dataStore");
private static final Supplier<GriefPrevention> PLUGIN = Suppliers.memoize(() -> GriefPrevention.instance);
private static final Supplier<DataStore> DATA_STORE = Suppliers.memoize(() -> PLUGIN.get().dataStore);

@SuppressWarnings("deprecation") // GP api uses ChatColor
@Override
public boolean checkBlock(final @NotNull Player player, final @NotNull Block clickedBlock) {
final PlayerData playerData = DATA_STORE.getPlayerData(player.getUniqueId());
final Claim claim = DATA_STORE.getClaimAt(clickedBlock.getLocation(), false, playerData.lastClaim);
final PlayerData playerData = DATA_STORE.get().getPlayerData(player.getUniqueId());
final Claim claim = DATA_STORE.get().getClaimAt(clickedBlock.getLocation(), false, playerData.lastClaim);
if (claim != null) {
playerData.lastClaim = claim;
final String noAccessReason = claim.allowAccess(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
*/
package me.machinemaker.papertweaks.integrations.worldguard;

import com.google.common.base.Suppliers;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import java.util.Objects;
import java.util.function.Supplier;
import me.machinemaker.papertweaks.integrations.Interactions;
import org.bukkit.Effect;
import org.bukkit.block.Block;
Expand All @@ -33,21 +34,21 @@

public class WGInteractionHandler implements Interactions.Handler {

private static final WorldGuardPlugin WORLD_GUARD_PLUGIN = Objects.requireNonNull(WorldGuardPlugin.inst(), "Could not find the instance of WorldGuard");
private static final WorldGuard WORLD_GUARD = WorldGuard.getInstance();
private static final Supplier<WorldGuardPlugin> WORLD_GUARD_PLUGIN = Suppliers.memoize(WorldGuardPlugin::inst);
private static final Supplier<WorldGuard> WORLD_GUARD = Suppliers.memoize(WorldGuard::getInstance);

@Override
@SuppressWarnings("deprecation")
public boolean checkBlock(final Player player, final Block clickedBlock) {
final LocalPlayer localPlayer = WORLD_GUARD_PLUGIN.wrapPlayer(player);
if (WORLD_GUARD.getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld())) {
final LocalPlayer localPlayer = WORLD_GUARD_PLUGIN.get().wrapPlayer(player);
if (WORLD_GUARD.get().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld())) {
return true;
}
final RegionQuery query = WORLD_GUARD.getPlatform().getRegionContainer().createQuery();
final RegionQuery query = WORLD_GUARD.get().getPlatform().getRegionContainer().createQuery();
final boolean result = query.testBuild(localPlayer.getLocation(), localPlayer);
if (!result) {
localPlayer.printRaw(query.queryValue(localPlayer.getLocation(), localPlayer, Flags.DENY_MESSAGE).replace("%what%", "use that"));
if (WORLD_GUARD_PLUGIN.getConfigManager().particleEffects) {
if (WORLD_GUARD_PLUGIN.get().getConfigManager().particleEffects) {
player.playEffect(clickedBlock.getLocation().add(0, 1, 0), Effect.SMOKE, BlockFace.UP);
}
return false;
Expand Down

0 comments on commit 389f853

Please sign in to comment.