New general Barrel open perms checker + Towny

This commit is contained in:
Sn0wStorm 2020-11-03 21:28:50 +01:00
parent d77d511dae
commit 4228bbc02c
18 changed files with 176 additions and 6 deletions

View File

@ -89,7 +89,7 @@
<url>http://maven.sk89q.com/repo/</url>
</repository>
<repository>
<!-- GriefPrevention, SlimeFun -->
<!-- GriefPrevention, SlimeFun, Towny -->
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
@ -233,6 +233,12 @@
<version>3.11</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.TownyAdvanced</groupId>
<artifactId>Towny</artifactId>
<version>0.96.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>

View File

@ -426,9 +426,14 @@ recipes:
useWorldGuard: true
useLWC: true
useGriefPrevention: true
useTowny: true
useGMInventories: true
useCitadel: true
# Beim öffnen eine virtuelle Kiste nutzen um Rechte bei alle anderen Plugins abzufragen
# Könnte Anti-Cheat plugins verwirren aber sonst ok zu aktivieren
useVirtualChestPerms: false
# Änderungen an Fassinventaren mit LogBlock aufzeichen [true]
useLogBlock: true

View File

@ -428,9 +428,14 @@ recipes:
useWorldGuard: true
useLWC: true
useGriefPrevention: true
useTowny: true
useGMInventories: true
useCitadel: true
# Use a virtual chest when opening a Barrel to check with all other protection plugins
# This could confuse Anti-Cheat plugins, but is otherwise good to use
useVirtualChestPerms: false
# Enable the Logging of Barrel Inventories to LogBlock [true]
useLogBlock: true

View File

@ -423,9 +423,14 @@ recipes:
useWorldGuard: true
useLWC: true
useGriefPrevention: true
useTowny: true
useGMInventories: true
useCitadel: true
# Use a virtual chest when opening a Barrel to check with all other protection plugins
# This could confuse Anti-Cheat plugins, but is otherwise good to use
useVirtualChestPerms: false
# Activer l'historique du contenu des tonneaux avec LogBlock [true]
useLogBlock: true

View File

@ -415,9 +415,14 @@ recipes:
useWorldGuard: true
useLWC: true
useGriefPrevention: true
useTowny: true
useGMInventories: true
useCitadel: true
# Use a virtual chest when opening a Barrel to check with all other protection plugins
# This could confuse Anti-Cheat plugins, but is otherwise good to use
useVirtualChestPerms: false
# Abilita il logging degli inventari dei barili [true]
useLogBlock: true

View File

@ -786,8 +786,14 @@ recipes:
useWorldGuard: true
useLWC: true
useGriefPrevention: true
useTowny: true
useGMInventories: true
# Beim Fass öffnen eine virtuelle Kiste nutzen um Rechte bei alle anderen Plugins abzufragen
# Könnte Anti-Cheat plugins verwirren aber sonst ok zu aktivieren
useVirtualChestPerms: false
# Änderungen an Fassinventaren mit LogBlock aufzeichen [true]
useLogBlock: true

View File

@ -780,8 +780,13 @@ recipes:
useWorldGuard: true
useLWC: true
useGriefPrevention: true
useTowny: true
useGMInventories: true
# Use a virtual chest when opening a Barrel to check with all other protection plugins
# This could confuse Anti-Cheat plugins, but is otherwise good to use
useVirtualChestPerms: false
# Enable the Logging of Barrel Inventories to LogBlock [true]
useLogBlock: true

View File

@ -780,8 +780,13 @@ recipes:
useWorldGuard: true
useLWC: true
useGriefPrevention: true
useTowny: true
useGMInventories: true
# Use a virtual chest when opening a Barrel to check with all other protection plugins
# This could confuse Anti-Cheat plugins, but is otherwise good to use
useVirtualChestPerms: false
# Enable the Logging of Barrel Inventories to LogBlock [true]
useLogBlock: true

View File

@ -786,8 +786,13 @@ recipes:
useWorldGuard: true
useLWC: true
useGriefPrevention: true
useTowny: true
useGMInventories: true
# Use a virtual chest when opening a Barrel to check with all other protection plugins
# This could confuse Anti-Cheat plugins, but is otherwise good to use
useVirtualChestPerms: false
# Activer l'historique du contenu des tonneaux avec LogBlock [true]
useLogBlock: true

View File

@ -780,8 +780,13 @@ eggnog:
useWorldGuard: true
useLWC: true
useGriefPrevention: true
useTowny: true
useGMInventories: true
# Use a virtual chest when opening a Barrel to check with all other protection plugins
# This could confuse Anti-Cheat plugins, but is otherwise good to use
useVirtualChestPerms: false
# Abilita il logging degli inventari dei barili [true]
useLogBlock: true

View File

@ -784,8 +784,13 @@ recipes:
useWorldGuard: true
useLWC: true
useGriefPrevention: true
useTowny: true
useGMInventories: true
# Use a virtual chest when opening a Barrel to check with all other protection plugins
# This could confuse Anti-Cheat plugins, but is otherwise good to use
useVirtualChestPerms: false
# 对LogBlock启用方块数据录入[true]
useLogBlock: true

View File

@ -1,7 +1,7 @@
name: Brewery
version: 2.1.2
main: com.dre.brewery.P
softdepend: [LWC, LogBlock, WorldGuard, GriefPrevention, Vault, ChestShop]
softdepend: [LWC, LogBlock, WorldGuard, GriefPrevention, Vault, ChestShop, Towny]
authors: [Milan Albrecht, Frank Baumann, ProgrammerDan, Daniel Saukel]
api-version: 1.13
commands:

View File

@ -176,7 +176,9 @@ public class BDistiller {
if (now instanceof BrewingStand) {
BrewingStand stand = (BrewingStand) now;
if (brewTime == -1) { // only check at the beginning (and end) for distillables
prepareForDistillables(stand);
if (!prepareForDistillables(stand)) {
return;
}
}
brewTime--; // count down.
@ -204,7 +206,7 @@ public class BDistiller {
}
}
private void prepareForDistillables(BrewingStand stand) {
private boolean prepareForDistillables(BrewingStand stand) {
BrewerInventory inventory = stand.getInventory();
if (contents == null) {
contents = getDistillContents(inventory);
@ -234,13 +236,14 @@ public class BDistiller {
trackedDistillers.remove(standBlock);
showAlc(inventory, contents);
P.p.debugLog("nothing to distill");
return;
return false;
default:
runTime = getLongestDistillTime(contents);
brewTime = runTime;
P.p.debugLog("using brewtime: " + runTime);
}
return true;
}
}
}

View File

@ -124,7 +124,7 @@ public class Barrel implements InventoryHolder {
}
// Call event
BarrelAccessEvent accessEvent = new BarrelAccessEvent(this, player, event.getClickedBlock());
BarrelAccessEvent accessEvent = new BarrelAccessEvent(this, player, event.getClickedBlock(), event.getBlockFace());
// Listened to by WGBarrel7, WGBarrelNew, WGBarrelOld, GriefPreventionBarrel (IntegrationListener)
P.p.getServer().getPluginManager().callEvent(accessEvent);
if (accessEvent.isCancelled()) {

View File

@ -2,6 +2,7 @@ package com.dre.brewery.api.events.barrel;
import com.dre.brewery.Barrel;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
@ -16,12 +17,18 @@ public class BarrelAccessEvent extends BarrelEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final Player player;
private final Block clickedBlock;
private final BlockFace clickedBlockFace;
private boolean isCancelled;
public BarrelAccessEvent(Barrel barrel, Player player, Block clickedBlock) {
this(barrel, player, clickedBlock, BlockFace.UP);
}
public BarrelAccessEvent(Barrel barrel, Player player, Block clickedBlock, BlockFace clickedBlockFace) {
super(barrel);
this.player = player;
this.clickedBlock = clickedBlock;
this.clickedBlockFace = clickedBlockFace;
}
/**
@ -32,6 +39,13 @@ public class BarrelAccessEvent extends BarrelEvent implements Cancellable {
return clickedBlock;
}
/**
* Get the clicked Block Face when clicking on the Barrel Block
*/
public BlockFace getClickedBlockFace() {
return clickedBlockFace;
}
@Override
public boolean isCancelled() {
return isCancelled;

View File

@ -49,6 +49,7 @@ public class BConfig {
public static boolean useLWC; //LWC
public static boolean useLB; //LogBlock
public static boolean useGP; //GriefPrevention
public static boolean useTowny; //Towny
public static boolean hasVault; // Vault
public static boolean useCitadel; // CivCraft/DevotedMC Citadel
public static boolean useGMInventories; // GamemodeInventories
@ -59,6 +60,7 @@ public class BConfig {
// Barrel
public static boolean openEverywhere;
public static boolean loadDataAsync;
public static boolean virtualChestPerms;
// Cauldron
public static boolean useOffhandForCauldron;
@ -212,10 +214,12 @@ public class BConfig {
}
}
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");
virtualChestPerms = config.getBoolean("useVirtualChestPerms", false);
// The item util has been removed in Vault 1.7+
hasVault = plMan.isPluginEnabled("Vault")
&& Integer.parseInt(plMan.getPlugin("Vault").getDescription().getVersion().split("\\.")[1]) <= 6;

View File

@ -9,6 +9,7 @@ import com.dre.brewery.filedata.BConfig;
import com.dre.brewery.integration.barrel.GriefPreventionBarrel;
import com.dre.brewery.integration.barrel.LWCBarrel;
import com.dre.brewery.integration.barrel.LogBlockBarrel;
import com.dre.brewery.integration.barrel.TownyBarrel;
import com.dre.brewery.integration.item.MMOItemsPluginItem;
import com.dre.brewery.recipe.BCauldronRecipe;
import com.dre.brewery.recipe.RecipeItem;
@ -17,7 +18,9 @@ import net.mmogroup.mmolib.api.item.NBTItem;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -106,6 +109,7 @@ public class IntegrationListener implements Listener {
} else {
P.p.msg(player, "&cError opening Barrel, please report to an Admin!");
}
return;
}
}
}
@ -124,6 +128,7 @@ public class IntegrationListener implements Listener {
if (!LWCBarrel.checkAccess(player, sign, plugin)) {
P.p.msg(event.getPlayer(), P.p.languageReader.get("Error_NoBarrelAccess"));
event.setCancelled(true);
return;
}
} catch (Throwable e) {
event.setCancelled(true);
@ -137,11 +142,75 @@ public class IntegrationListener implements Listener {
} else {
P.p.msg(player, "&cError opening Barrel, please report to an Admin!");
}
return;
}
}
}
}
}
if (BConfig.useTowny) {
if (P.p.getServer().getPluginManager().isPluginEnabled("Towny")) {
try {
if (!TownyBarrel.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 Towny for Barrel Open Permissions!");
P.p.errorLog("Brewery was tested with Towny v0.96.3.0");
P.p.errorLog("Disable the Towny 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, "&cTowny check Error, Brewery was tested with up to v0.96.3.0 of Towny");
P.p.msg(player, "&cSet &7useTowny: 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();
event.getClickedBlock().setType(Material.CHEST, false);
PlayerInteractEvent simulatedEvent = new PlayerInteractEvent(
player,
Action.RIGHT_CLICK_BLOCK,
player.getInventory().getItemInMainHand(),
event.getClickedBlock(),
event.getClickedBlockFace(),
EquipmentSlot.HAND);
try {
P.p.getServer().getPluginManager().callEvent(simulatedEvent);
} catch (Throwable e) {
P.p.errorLog("Failed to simulate a Chest for Barrel Open Permissions!");
P.p.errorLog("Disable useVirtualChestPerms in the config and do /brew reload");
e.printStackTrace();
if (player.hasPermission("brewery.admin") || player.hasPermission("brewery.mod")) {
P.p.msg(player, "&cVirtual Chest Error");
P.p.msg(player, "&cSet &7useVirtualChestPerms: false &cin the config and /brew reload");
} else {
P.p.msg(player, "&cError opening Barrel, please report to an Admin!");
}
} finally {
event.getClickedBlock().setType(Material.AIR, false);
originalBlockState.update(true);
}
if (simulatedEvent.useInteractedBlock() == Event.Result.DENY) {
event.setCancelled(true);
P.p.msg(event.getPlayer(), P.p.languageReader.get("Error_NoBarrelAccess"));
//return;
}
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)

View File

@ -0,0 +1,23 @@
package com.dre.brewery.integration.barrel;
import com.dre.brewery.P;
import com.dre.brewery.api.events.barrel.BarrelAccessEvent;
import com.palmergames.bukkit.towny.TownySettings;
import com.palmergames.bukkit.towny.object.TownyPermission;
import com.palmergames.bukkit.towny.utils.PlayerCacheUtil;
import org.bukkit.Material;
public class TownyBarrel {
public static boolean checkAccess(BarrelAccessEvent event) {
if (!TownySettings.isSwitchMaterial("BREWERY") && !TownySettings.isSwitchMaterial("BARREL")) {
if (P.use1_14) {
return true;
} else if (!TownySettings.isSwitchMaterial("CHEST")) {
return true;
}
}
Material mat = P.use1_14 ? Material.BARREL : Material.CHEST;
return PlayerCacheUtil.getCachePermission(event.getPlayer(), event.getSpigot().getLocation(), mat, TownyPermission.ActionType.SWITCH);
}
}