mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2025-01-24 21:31:22 +01:00
Added BlockLocker plugin support
This commit is contained in:
parent
8758e0c603
commit
0b9b364f28
5
pom.xml
5
pom.xml
@ -251,6 +251,11 @@
|
||||
<version>2.12.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.rutgerkok</groupId>
|
||||
<artifactId>BlockLocker</artifactId>
|
||||
<version>eb78e99e72</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
|
@ -1,7 +1,7 @@
|
||||
name: Brewery
|
||||
version: 2.1.2
|
||||
main: com.dre.brewery.P
|
||||
softdepend: [LWC, LogBlock, WorldGuard, GriefPrevention, Vault, ChestShop, Shopkeepers, Towny]
|
||||
softdepend: [LWC, LogBlock, WorldGuard, GriefPrevention, Vault, ChestShop, Shopkeepers, Towny, BlockLocker]
|
||||
authors: [Milan Albrecht, Frank Baumann, ProgrammerDan, Daniel Saukel]
|
||||
api-version: 1.13
|
||||
commands:
|
||||
|
@ -8,6 +8,7 @@ import com.dre.brewery.filedata.UpdateChecker;
|
||||
import com.dre.brewery.integration.ChestShopListener;
|
||||
import com.dre.brewery.integration.IntegrationListener;
|
||||
import com.dre.brewery.integration.ShopKeepersListener;
|
||||
import com.dre.brewery.integration.barrel.BlocklockerBarrel;
|
||||
import com.dre.brewery.integration.barrel.LogBlockBarrel;
|
||||
import com.dre.brewery.listeners.*;
|
||||
import com.dre.brewery.recipe.*;
|
||||
@ -507,6 +508,7 @@ public class P extends JavaPlugin {
|
||||
Barrel.onUpdate();// runs every min to check and update ageing time
|
||||
long t3 = System.nanoTime();
|
||||
if (use1_14) MCBarrel.onUpdate();
|
||||
if (BConfig.useBlocklocker) BlocklockerBarrel.clearBarrelSign();
|
||||
long t4 = System.nanoTime();
|
||||
BPlayer.onUpdate();// updates players drunkeness
|
||||
|
||||
|
@ -6,6 +6,7 @@ import com.dre.brewery.DistortChat;
|
||||
import com.dre.brewery.MCBarrel;
|
||||
import com.dre.brewery.P;
|
||||
import com.dre.brewery.api.events.ConfigLoadEvent;
|
||||
import com.dre.brewery.integration.barrel.BlocklockerBarrel;
|
||||
import com.dre.brewery.integration.barrel.WGBarrel;
|
||||
import com.dre.brewery.integration.barrel.WGBarrel5;
|
||||
import com.dre.brewery.integration.barrel.WGBarrel6;
|
||||
@ -50,6 +51,7 @@ public class BConfig {
|
||||
public static boolean useLB; //LogBlock
|
||||
public static boolean useGP; //GriefPrevention
|
||||
public static boolean useTowny; //Towny
|
||||
public static boolean useBlocklocker; //LockBlocker
|
||||
public static boolean hasVault; // Vault
|
||||
public static boolean useCitadel; // CivCraft/DevotedMC Citadel
|
||||
public static boolean useGMInventories; // GamemodeInventories
|
||||
@ -199,31 +201,13 @@ public class BConfig {
|
||||
|
||||
// Third-Party
|
||||
useWG = config.getBoolean("useWorldGuard", true) && plMan.isPluginEnabled("WorldGuard");
|
||||
|
||||
if (useWG) {
|
||||
Plugin plugin = Bukkit.getPluginManager().getPlugin("WorldEdit");
|
||||
if (plugin != null) {
|
||||
String wgv = plugin.getDescription().getVersion();
|
||||
if (wgv.startsWith("6.")) {
|
||||
wg = new WGBarrel6();
|
||||
} else if (wgv.startsWith("5.")) {
|
||||
wg = new WGBarrel5();
|
||||
} else {
|
||||
wg = new WGBarrel7();
|
||||
}
|
||||
}
|
||||
if (wg == null) {
|
||||
P.p.errorLog("Failed loading WorldGuard Integration! Opening Barrels will NOT work!");
|
||||
P.p.errorLog("Brewery was tested with version 5.8, 6.1 and 7.0 of WorldGuard!");
|
||||
P.p.errorLog("Disable the WorldGuard support in the config and do /brew reload");
|
||||
}
|
||||
}
|
||||
useLWC = config.getBoolean("useLWC", true) && plMan.isPluginEnabled("LWC");
|
||||
useTowny = config.getBoolean("useTowny", true) && plMan.isPluginEnabled("Towny");
|
||||
useGP = config.getBoolean("useGriefPrevention", true) && plMan.isPluginEnabled("GriefPrevention");
|
||||
useLB = config.getBoolean("useLogBlock", false) && plMan.isPluginEnabled("LogBlock");
|
||||
useGMInventories = config.getBoolean("useGMInventories", false);
|
||||
useCitadel = config.getBoolean("useCitadel", false) && plMan.isPluginEnabled("Citadel");
|
||||
useBlocklocker = config.getBoolean("useBlockLocker", false) && plMan.isPluginEnabled("BlockLocker");
|
||||
virtualChestPerms = config.getBoolean("useVirtualChestPerms", false);
|
||||
// The item util has been removed in Vault 1.7+
|
||||
hasVault = plMan.isPluginEnabled("Vault")
|
||||
@ -376,6 +360,33 @@ public class BConfig {
|
||||
}
|
||||
}
|
||||
|
||||
if (useWG) {
|
||||
Plugin plugin = Bukkit.getPluginManager().getPlugin("WorldEdit");
|
||||
if (plugin != null) {
|
||||
String wgv = plugin.getDescription().getVersion();
|
||||
if (wgv.startsWith("6.")) {
|
||||
wg = new WGBarrel6();
|
||||
} else if (wgv.startsWith("5.")) {
|
||||
wg = new WGBarrel5();
|
||||
} else {
|
||||
wg = new WGBarrel7();
|
||||
}
|
||||
}
|
||||
if (wg == null) {
|
||||
P.p.errorLog("Failed loading WorldGuard Integration! Opening Barrels will NOT work!");
|
||||
P.p.errorLog("Brewery was tested with version 5.8, 6.1 and 7.0 of WorldGuard!");
|
||||
P.p.errorLog("Disable the WorldGuard support in the config and do /brew reload");
|
||||
}
|
||||
}
|
||||
if (useBlocklocker) {
|
||||
try {
|
||||
Class.forName("nl.rutgerkok.blocklocker.BlockLockerAPIv2");
|
||||
BlocklockerBarrel.registerBarrelAsProtectable();
|
||||
} catch (ClassNotFoundException e) {
|
||||
useBlocklocker = false;
|
||||
}
|
||||
}
|
||||
|
||||
// init SQL
|
||||
if (sqlSync != null) {
|
||||
try {
|
||||
|
@ -6,6 +6,7 @@ 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 com.dre.brewery.filedata.BConfig;
|
||||
import com.dre.brewery.integration.barrel.BlocklockerBarrel;
|
||||
import com.dre.brewery.integration.barrel.GriefPreventionBarrel;
|
||||
import com.dre.brewery.integration.barrel.LWCBarrel;
|
||||
import com.dre.brewery.integration.barrel.LogBlockBarrel;
|
||||
@ -175,6 +176,32 @@ public class IntegrationListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
if (BConfig.useBlocklocker) {
|
||||
if (P.p.getServer().getPluginManager().isPluginEnabled("BlockLocker")) {
|
||||
try {
|
||||
if (!BlocklockerBarrel.checkAccess(event)) {
|
||||
P.p.msg(event.getPlayer(), P.p.languageReader.get("Error_NoBarrelAccess"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
event.setCancelled(true);
|
||||
P.p.errorLog("Failed to Check BlockLocker for Barrel Open Permissions!");
|
||||
P.p.errorLog("Brewery was tested with BlockLocker v1.8.2");
|
||||
P.p.errorLog("Disable the BlockLocker support in the config and do /brew reload");
|
||||
e.printStackTrace();
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPermission("brewery.admin") || player.hasPermission("brewery.mod")) {
|
||||
P.p.msg(player, "&cBlockLocker check Error, Brewery was tested with v1.8.2 of BlockLocker");
|
||||
P.p.msg(player, "&cSet &7useBlockLocker: false &cin the config and /brew reload");
|
||||
} else {
|
||||
P.p.msg(player, "&cError opening Barrel, please report to an Admin!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (BConfig.virtualChestPerms) {
|
||||
Player player = event.getPlayer();
|
||||
BlockState originalBlockState = event.getClickedBlock().getState();
|
||||
@ -218,8 +245,10 @@ public class IntegrationListener implements Listener {
|
||||
if (!BConfig.useLWC) return;
|
||||
|
||||
if (event.hasPlayer()) {
|
||||
Player player = event.getPlayerOptional();
|
||||
assert player != null;
|
||||
try {
|
||||
if (LWCBarrel.denyDestroy(event.getPlayerOptional(), event.getBarrel())) {
|
||||
if (LWCBarrel.denyDestroy(player, event.getBarrel())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
@ -228,7 +257,6 @@ public class IntegrationListener implements Listener {
|
||||
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();
|
||||
Player player = event.getPlayerOptional();
|
||||
if (player.hasPermission("brewery.admin") || player.hasPermission("brewery.mod")) {
|
||||
P.p.msg(player, "&cLWC check Error, Brewery was tested with up to v4.5.0 of LWC");
|
||||
P.p.msg(player, "&cSet &7useLWC: false &cin the config and /brew reload");
|
||||
|
@ -0,0 +1,91 @@
|
||||
package com.dre.brewery.integration.barrel;
|
||||
|
||||
import com.dre.brewery.Barrel;
|
||||
import com.dre.brewery.BarrelBody;
|
||||
import com.dre.brewery.P;
|
||||
import com.dre.brewery.api.events.barrel.BarrelAccessEvent;
|
||||
import com.dre.brewery.filedata.BConfig;
|
||||
import com.dre.brewery.utility.LegacyUtil;
|
||||
import nl.rutgerkok.blocklocker.BlockLockerAPIv2;
|
||||
import nl.rutgerkok.blocklocker.ProtectableBlocksSettings;
|
||||
import nl.rutgerkok.blocklocker.ProtectionType;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BlocklockerBarrel implements ProtectableBlocksSettings {
|
||||
private static Block lastBarrelSign;
|
||||
|
||||
@Override
|
||||
public boolean canProtect(Block block) {
|
||||
return isOrWillCreateBarrel(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProtect(ProtectionType protectionType, Block block) {
|
||||
if (protectionType != ProtectionType.CONTAINER) return false;
|
||||
|
||||
return isOrWillCreateBarrel(block);
|
||||
}
|
||||
|
||||
public boolean isOrWillCreateBarrel(Block block) {
|
||||
if (!P.p.isEnabled() || !BConfig.useBlocklocker) {
|
||||
return false;
|
||||
}
|
||||
if (!LegacyUtil.isWoodPlanks(block.getType()) && !LegacyUtil.isWoodStairs(block.getType())) {
|
||||
// Can only be a barrel if it's a planks block
|
||||
return false;
|
||||
}
|
||||
if (Barrel.getByWood(block) != null) {
|
||||
// Barrel already exists
|
||||
return true;
|
||||
}
|
||||
if (lastBarrelSign == null) {
|
||||
// No player wants to create a Barrel
|
||||
return false;
|
||||
}
|
||||
for (BlockFace face : new BlockFace[] {BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST}) {
|
||||
Block sign = block.getRelative(face);
|
||||
if (lastBarrelSign.equals(sign)) {
|
||||
Block spigot = BarrelBody.getSpigotOfSign(sign);
|
||||
byte signoffset = 0;
|
||||
if (!spigot.equals(sign)) {
|
||||
signoffset = (byte) (sign.getY() - spigot.getY());
|
||||
}
|
||||
Barrel barrel = new Barrel(spigot, signoffset);
|
||||
|
||||
return barrel.getBody().getBrokenBlock(true) == null;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean checkAccess(BarrelAccessEvent event) {
|
||||
Block sign = event.getBarrel().getBody().getSignOfSpigot();
|
||||
if (!LegacyUtil.isSign(sign.getType())) {
|
||||
return true;
|
||||
}
|
||||
return BlockLockerAPIv2.isAllowed(event.getPlayer(), sign, true);
|
||||
}
|
||||
|
||||
public static void createdBarrelSign(Block sign) {
|
||||
// The Player created a sign with "Barrel" on it, he want's to create a barrel
|
||||
lastBarrelSign = sign;
|
||||
}
|
||||
|
||||
public static void clearBarrelSign() {
|
||||
lastBarrelSign = null;
|
||||
}
|
||||
|
||||
public static void registerBarrelAsProtectable() {
|
||||
try {
|
||||
List<ProtectableBlocksSettings> extraProtectables = BlockLockerAPIv2.getPlugin().getChestSettings().getExtraProtectables();
|
||||
if (extraProtectables.stream().noneMatch(blockSettings -> blockSettings instanceof BlocklockerBarrel)) {
|
||||
extraProtectables.add(new BlocklockerBarrel());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,9 @@ import com.dre.brewery.Barrel;
|
||||
import com.dre.brewery.DistortChat;
|
||||
import com.dre.brewery.P;
|
||||
import com.dre.brewery.api.events.barrel.BarrelDestroyEvent;
|
||||
import com.dre.brewery.filedata.BConfig;
|
||||
import com.dre.brewery.filedata.BData;
|
||||
import com.dre.brewery.integration.barrel.BlocklockerBarrel;
|
||||
import com.dre.brewery.utility.BUtil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -22,7 +24,7 @@ public class BlockListener implements Listener {
|
||||
public void onSignChange(SignChangeEvent event) {
|
||||
String[] lines = event.getLines();
|
||||
|
||||
if (lines[0].equalsIgnoreCase("Barrel") || lines[0].equalsIgnoreCase(P.p.languageReader.get("Etc_Barrel"))) {
|
||||
if (hasBarrelLine(lines)) {
|
||||
Player player = event.getPlayer();
|
||||
if (!player.hasPermission("brewery.createbarrel.small") && !player.hasPermission("brewery.createbarrel.big")) {
|
||||
P.p.msg(player, P.p.languageReader.get("Perms_NoBarrelCreate"));
|
||||
@ -38,6 +40,15 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasBarrelLine(String[] lines) {
|
||||
for (String line : lines) {
|
||||
if (line.equalsIgnoreCase("Barrel") || line.equalsIgnoreCase(P.p.languageReader.get("Etc_Barrel"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onSignChangeLow(SignChangeEvent event) {
|
||||
if (DistortChat.doSigns) {
|
||||
@ -45,6 +56,12 @@ public class BlockListener implements Listener {
|
||||
DistortChat.signWrite(event);
|
||||
}
|
||||
}
|
||||
if (BConfig.useBlocklocker) {
|
||||
String[] lines = event.getLines();
|
||||
if (hasBarrelLine(lines)) {
|
||||
BlocklockerBarrel.createdBarrelSign(event.getBlock());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
|
Loading…
Reference in New Issue
Block a user