Added WorldGuard Support

This commit is contained in:
Sn0wStorm 2014-02-16 19:55:54 +01:00
parent 23972e69c6
commit 6d11efb0ad
2 changed files with 23 additions and 0 deletions

View File

@ -86,6 +86,7 @@ public class LanguageReader {
/* Error */
defaults.put("Error_NoPermissions", "&cYou have no permission to do this!");
defaults.put("Error_NoBarrelAccess", "&cYou have no permission to access this barrel!");
defaults.put("Error_UnknownCommand", "Unknown Command");
defaults.put("Error_ShowHelp", "use &6/br help &fto display the help");
defaults.put("Error_PlayerCommand", "&cThis command can only be executed as player");

View File

@ -17,6 +17,7 @@ import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.plugin.Plugin;
import com.dre.brewery.BCauldron;
import com.dre.brewery.BIngredients;
@ -26,6 +27,10 @@ import com.dre.brewery.BPlayer;
import com.dre.brewery.Words;
import com.dre.brewery.Wakeup;
import com.dre.brewery.P;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
public class PlayerListener implements Listener {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
@ -92,6 +97,23 @@ public class PlayerListener implements Listener {
Barrel barrel = Barrel.get(clickedBlock);
if (barrel != null) {
event.setCancelled(true);
Plugin plugin = P.p.getServer().getPluginManager().getPlugin("WorldGuard");
if (plugin != null && plugin instanceof WorldGuardPlugin) {
WorldGuardPlugin wg = (WorldGuardPlugin) plugin;
if (!wg.getGlobalRegionManager().hasBypass(player, player.getWorld())) {
ApplicableRegionSet region = wg.getRegionManager(player.getWorld()).getApplicableRegions(clickedBlock.getLocation());
if (region != null) {
LocalPlayer localPlayer = wg.wrapPlayer(player);
if (!region.allows(DefaultFlag.CHEST_ACCESS, localPlayer)) {
if (!region.canBuild(localPlayer)) {
P.p.msg(player, P.p.languageReader.get("Error_NoBarrelAccess"));
return;
}
}
}
}
}
Block broken = Barrel.getBrokenBlock(clickedBlock);
// barrel is built correctly
if (broken == null) {