mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 08:59:01 +00:00
Listener for Barrel breaking -> LWC Support
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
package com.dre.brewery.integration;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventException;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredListener;
|
||||
|
||||
import com.dre.brewery.Barrel;
|
||||
import com.dre.brewery.P;
|
||||
import com.griefcraft.listeners.LWCPlayerListener;
|
||||
import com.griefcraft.lwc.LWC;
|
||||
import com.griefcraft.model.Flag;
|
||||
import com.griefcraft.model.Protection;
|
||||
import com.griefcraft.scripting.event.LWCProtectionDestroyEvent;
|
||||
|
||||
public class LWCBarrel {
|
||||
|
||||
|
||||
public static boolean checkDestroy(Player player, Barrel barrel) {
|
||||
LWC lwc = LWC.getInstance();
|
||||
Block sign = barrel.getSignOfSpigot();
|
||||
//if (!Boolean.parseBoolean(lwc.resolveProtectionConfiguration(sign, "ignoreBlockDestruction"))) {
|
||||
Protection protection = lwc.findProtection(sign);
|
||||
if (protection != null) {
|
||||
boolean canAccess = lwc.canAccessProtection(player, protection);
|
||||
boolean canAdmin = lwc.canAdminProtection(player, protection);
|
||||
|
||||
try {
|
||||
LWCProtectionDestroyEvent evt = new LWCProtectionDestroyEvent(player, protection, LWCProtectionDestroyEvent.Method.BLOCK_DESTRUCTION, canAccess, canAdmin);
|
||||
lwc.getModuleLoader().dispatchEvent(evt);
|
||||
|
||||
if (evt.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
lwc.sendLocale(player, "protection.internalerror", "id", "BLOCK_BREAK");
|
||||
P.p.errorLog("Failed to dispatch LWCProtectionDestroyEvent");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean checkAccess(Player player, Block sign, PlayerInteractEvent event, Plugin plugin) {
|
||||
LWC lwc = LWC.getInstance();
|
||||
|
||||
// Disallow Chest Access with these permissions
|
||||
if (!lwc.hasPermission(player, "lwc.protect") && lwc.hasPermission(player, "lwc.deny") && !lwc.isAdmin(player) && !lwc.isMod(player)) {
|
||||
lwc.sendLocale(player, "protection.interact.error.blocked");
|
||||
return false;
|
||||
}
|
||||
|
||||
// We just fake a BlockInteractEvent on the Sign for LWC, it handles it nicely. Otherwise we could copy LWCs listener in here...
|
||||
PlayerInteractEvent lwcEvent = new PlayerInteractEvent(player, event.getAction(), event.getItem(), sign, event.getBlockFace());
|
||||
for (RegisteredListener listener : HandlerList.getRegisteredListeners(plugin)) {
|
||||
if (listener.getListener() instanceof LWCPlayerListener) {
|
||||
try {
|
||||
listener.callEvent(lwcEvent);
|
||||
if (lwcEvent.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
} catch (EventException e) {
|
||||
lwc.sendLocale(player, "protection.internalerror", "id", "PLAYER_INTERACT");
|
||||
P.p.errorLog("Block Interact could not be passed to LWC");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Returns true if the block that exploded should not be removed
|
||||
public static boolean blockExplosion(Barrel barrel, Block block) {
|
||||
Protection protection = LWC.getInstance().findProtection(barrel.getSignOfSpigot());
|
||||
|
||||
if (protection == null) {
|
||||
barrel.remove(block);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (protection.hasFlag(Flag.Type.ALLOWEXPLOSIONS)) {
|
||||
protection.remove();
|
||||
barrel.remove(block);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.dre.brewery.integration;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
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 WGBarrel {
|
||||
|
||||
public static boolean checkAccess(Player player, Block spigot, Plugin plugin) {
|
||||
WorldGuardPlugin wg = (WorldGuardPlugin) plugin;
|
||||
if (!wg.getGlobalRegionManager().hasBypass(player, player.getWorld())) {
|
||||
ApplicableRegionSet region = wg.getRegionManager(player.getWorld()).getApplicableRegions(spigot.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 false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user