mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-12-24 09:07:34 +01:00
5908eb67fa
- Copied utilities from ChestShop-4 - Made code really, really nicer to read - Made every external plugin's wrapper a listener, so it listens to events instead of being hard-coded.
51 lines
1.7 KiB
Java
51 lines
1.7 KiB
Java
package com.Acrobot.ChestShop.Plugins;
|
|
|
|
import com.Acrobot.ChestShop.Events.Protection.ProtectionCheckEvent;
|
|
import com.sk89q.worldedit.Vector;
|
|
import com.sk89q.worldedit.bukkit.BukkitUtil;
|
|
import com.sk89q.worldguard.LocalPlayer;
|
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
|
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
|
import org.bukkit.block.Block;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.event.Event;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.Listener;
|
|
|
|
/**
|
|
* @author Acrobot
|
|
*/
|
|
public class WorldGuardProtection implements Listener {
|
|
private WorldGuardPlugin worldGuard;
|
|
|
|
public WorldGuardProtection(WorldGuardPlugin worldGuard) {
|
|
this.worldGuard = worldGuard;
|
|
}
|
|
|
|
@EventHandler
|
|
public void onProtectionCheck(ProtectionCheckEvent event) {
|
|
if (event.getResult() == Event.Result.DENY) {
|
|
return;
|
|
}
|
|
|
|
Block block = event.getBlock();
|
|
Player player = event.getPlayer();
|
|
|
|
Vector blockPos = BukkitUtil.toVector(block);
|
|
RegionManager manager = worldGuard.getRegionManager(block.getWorld());
|
|
ApplicableRegionSet set = manager.getApplicableRegions(blockPos);
|
|
|
|
LocalPlayer localPlayer = worldGuard.wrapPlayer(player);
|
|
|
|
if (!canAccess(localPlayer, block, set)) {
|
|
event.setResult(Event.Result.DENY);
|
|
}
|
|
}
|
|
|
|
private boolean canAccess(LocalPlayer player, Block block, ApplicableRegionSet set) {
|
|
return worldGuard.getGlobalRegionManager().hasBypass(player, block.getWorld()) || set.canBuild(player) || set.allows(DefaultFlag.CHEST_ACCESS, player);
|
|
}
|
|
}
|