Started api and events

This commit is contained in:
Sn0wStorm
2019-10-11 20:44:43 +02:00
parent 49fb0e3d82
commit 519c4821d9
32 changed files with 1400 additions and 264 deletions
@@ -1,18 +1,19 @@
package com.dre.brewery.integration;
import com.dre.brewery.P;
import com.dre.brewery.api.events.barrel.BarrelAccessEvent;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import me.ryanhamshire.GriefPrevention.PlayerData;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
public class GriefPreventionBarrel {
static P brewery = P.p;
static GriefPrevention griefPrevention = GriefPrevention.instance;
private static P brewery = P.p;
public static boolean checkAccess(Player player, Block sign) {
public static boolean checkAccess(BarrelAccessEvent event) {
GriefPrevention griefPrevention = GriefPrevention.instance;
Player player = event.getPlayer();
PlayerData playerData = griefPrevention.dataStore.getPlayerData(player.getUniqueId());
if (!griefPrevention.claimsEnabledForWorld(player.getWorld()) || playerData.ignoreClaims || !griefPrevention.config_claims_preventTheft) {
@@ -21,12 +22,11 @@ public class GriefPreventionBarrel {
// block container use during pvp combat
if (playerData.inPvpCombat()) {
brewery.msg(player, brewery.languageReader.get("Error_NoBarrelAccess"));
return false;
}
// check permissions for the claim the Barrel is in
Claim claim = griefPrevention.dataStore.getClaimAt(sign.getLocation(), false, playerData.lastClaim);
Claim claim = griefPrevention.dataStore.getClaimAt(event.getSpigot().getLocation(), false, playerData.lastClaim);
if (claim != null) {
playerData.lastClaim = claim;
String noContainersReason = claim.allowContainers(player);
@@ -0,0 +1,122 @@
package com.dre.brewery.integration;
import com.dre.brewery.Barrel;
import com.dre.brewery.P;
import com.dre.brewery.api.events.barrel.BarrelAccessEvent;
import com.dre.brewery.api.events.barrel.BarrelDestroyEvent;
import com.dre.brewery.api.events.barrel.BarrelRemoveEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.plugin.Plugin;
public class IntegrationListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBarrelAccessLowest(BarrelAccessEvent event) {
if (P.p.useWG) {
Plugin plugin = P.p.getServer().getPluginManager().getPlugin("WorldGuard");
if (plugin != null) {
try {
if (!P.p.wg.checkAccess(event.getPlayer(), event.getSpigot(), plugin)) {
event.setCancelled(true);
}
} catch (Throwable e) {
event.setCancelled(true);
P.p.errorLog("Failed to Check WorldGuard for Barrel Open Permissions!");
P.p.errorLog("Brewery was tested with version 5.8 to 6.1 of WorldGuard!");
P.p.errorLog("Disable the WorldGuard support in the config and do /brew reload");
e.printStackTrace();
P.p.msg(event.getPlayer(), "&cError opening Barrel, please report to an Admin!");
}
}
}
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBarrelAccess(BarrelAccessEvent event) {
if (P.p.useGP) {
if (P.p.getServer().getPluginManager().isPluginEnabled("GriefPrevention")) {
try {
if (!GriefPreventionBarrel.checkAccess(event)) {
event.setCancelled(true);
}
} catch (Throwable e) {
event.setCancelled(true);
P.p.errorLog("Failed to Check GriefPrevention for Barrel Open Permissions!");
P.p.errorLog("Brewery was tested with GriefPrevention 14.5.4");
P.p.errorLog("Disable the GriefPrevention support in the config and do /brew reload");
e.printStackTrace();
P.p.msg(event.getPlayer(), "&cError opening Barrel, please report to an Admin!");
}
}
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
public void onBarrelDestroy(BarrelDestroyEvent event) {
if (!P.p.useLWC) return;
if (event.hasPlayer()) {
try {
if (LWCBarrel.denyDestroy(event.getPlayerOptional(), event.getBarrel())) {
event.setCancelled(true);
}
} catch (Throwable e) {
event.setCancelled(true);
P.p.errorLog("Failed to Check LWC for Barrel Break Permissions!");
P.p.errorLog("Brewery was tested with version 4.5.0 of LWC!");
P.p.errorLog("Disable the LWC support in the config and do /brew reload");
e.printStackTrace();
P.p.msg(event.getPlayerOptional(), "&cError breaking Barrel, please report to an Admin!");
}
} else {
try {
if (event.getReason() == BarrelDestroyEvent.Reason.EXPLODED) {
if (LWCBarrel.denyExplosion(event.getBarrel())) {
event.setCancelled(true);
}
} else {
if (LWCBarrel.denyDestroyOther(event.getBarrel())) {
event.setCancelled(true);
}
}
} catch (Throwable e) {
event.setCancelled(true);
P.p.errorLog("Failed to Check LWC on Barrel Destruction!");
P.p.errorLog("Brewery was tested with version 4.5.0 of LWC!");
P.p.errorLog("Disable the LWC support in the config and do /brew reload");
e.printStackTrace();
}
}
}
@EventHandler
public void onBarrelRemove(BarrelRemoveEvent event) {
if (!P.p.useLWC) return;
try {
LWCBarrel.remove(event.getBarrel());
} catch (Throwable e) {
P.p.errorLog("Failed to Remove LWC Lock from Barrel!");
P.p.errorLog("Brewery was tested with version 4.5.0 of LWC!");
e.printStackTrace();
}
}
@EventHandler
public void onInventoryClose(InventoryCloseEvent event) {
if (P.p.useLB) {
if (event.getInventory().getHolder() instanceof Barrel) {
try {
LogBlockBarrel.closeBarrel(event.getPlayer(), event.getInventory());
} catch (Exception e) {
P.p.errorLog("Failed to Log Barrel to LogBlock!");
P.p.errorLog("Brewery was tested with version 1.94 of LogBlock!");
e.printStackTrace();
}
}
}
}
}
+17 -23
View File
@@ -1,13 +1,5 @@
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;
@@ -15,11 +7,18 @@ import com.griefcraft.lwc.LWC;
import com.griefcraft.model.Flag;
import com.griefcraft.model.Protection;
import com.griefcraft.scripting.event.LWCProtectionDestroyEvent;
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;
public class LWCBarrel {
public static boolean checkDestroy(Player player, Barrel barrel) {
public static boolean denyDestroy(Player player, Barrel barrel) {
LWC lwc = LWC.getInstance();
Block sign = barrel.getSignOfSpigot();
//if (!Boolean.parseBoolean(lwc.resolveProtectionConfiguration(sign, "ignoreBlockDestruction"))) {
@@ -33,18 +32,18 @@ public class LWCBarrel {
lwc.getModuleLoader().dispatchEvent(evt);
if (evt.isCancelled()) {
return false;
return true;
}
} catch (Exception e) {
lwc.sendLocale(player, "protection.internalerror", "id", "BLOCK_BREAK");
P.p.errorLog("Failed to dispatch LWCProtectionDestroyEvent");
e.printStackTrace();
return false;
return true;
}
}
//}
return true;
return false;
}
public static boolean checkAccess(Player player, Block sign, PlayerInteractEvent event, Plugin plugin) {
@@ -86,19 +85,14 @@ public class LWCBarrel {
}
// Returns true if the block that exploded should not be removed
public static boolean blockExplosion(Barrel barrel, Block block) {
public static boolean denyExplosion(Barrel barrel) {
Protection protection = LWC.getInstance().findProtection(barrel.getSignOfSpigot());
if (protection == null) {
barrel.remove(block, null);
return false;
}
return protection != null && !protection.hasFlag(Flag.Type.ALLOWEXPLOSIONS);
}
if (protection.hasFlag(Flag.Type.ALLOWEXPLOSIONS)) {
protection.remove();
barrel.remove(block, null);
return false;
}
return true;
// Returns true if the block that was destroyed should not be removed
public static boolean denyDestroyOther(Barrel barrel) {
return LWC.getInstance().findProtection(barrel.getSignOfSpigot()) != null;
}
}
@@ -1,15 +1,13 @@
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.bukkit.RegionQuery;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.permission.RegionPermissionModel;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class WGBarrelNew implements WGBarrel {
@@ -21,12 +19,8 @@ public class WGBarrelNew implements WGBarrel {
RegionQuery query = wg.getRegionContainer().createQuery();
if (!query.testBuild(spigot.getLocation(), player, DefaultFlag.USE, DefaultFlag.CHEST_ACCESS)) {
P.p.msg(player, P.p.languageReader.get("Error_NoBarrelAccess"));
return false;
}
return query.testBuild(spigot.getLocation(), player, DefaultFlag.USE, DefaultFlag.CHEST_ACCESS);
return true;
}
}
@@ -48,7 +48,6 @@ public class WGBarrelOld implements WGBarrel {
if (!(Boolean) allows.invoke(region, DefaultFlag.CHEST_ACCESS, localPlayer)) {
if (!(Boolean) canBuild.invoke(region, localPlayer)) {
P.p.msg(player, P.p.languageReader.get("Error_NoBarrelAccess"));
return false;
}
}