Improves LockettePro integration

Uses Lockette's API for checking whether a given sign is a Lockette sign
Allows the override to work for additional users signs as well
This commit is contained in:
Kristian Knarvik 2023-04-05 19:16:43 +02:00
parent 620334278b
commit d930d82c5b

View File

@ -8,7 +8,8 @@ import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.Engine; import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
import org.bukkit.block.Sign; import me.crafter.mc.lockettepro.LocketteProAPI;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
@ -27,33 +28,22 @@ public class EngineLockette extends Engine {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onLocketteBreak(BlockBreakEvent event) { public void onLocketteBreak(BlockBreakEvent event) {
if (!event.isCancelled() || !(event.getBlock().getState() instanceof Sign)) { Block block = event.getBlock();
return; // Check if we are dealing with a protection sign, and overriding is enabled
} if (!event.isCancelled() || (!LocketteProAPI.isLockSign(block) && !LocketteProAPI.isAdditionalSign(block)) ||
!MConf.get().locketteLeaderRemoveOverride) {
// If disabled, do nothing
if (!MConf.get().locketteLeaderRemoveOverride) {
return;
}
// Check if we are dealing with a protection sign
String firstLine = ((Sign) event.getBlock().getState()).getLine(0);
if (firstLine.contains("#")) {
firstLine = firstLine.split("#", 2)[0];
}
if (!firstLine.equalsIgnoreCase("[Private]")) {
return; return;
} }
// If in wilderness, don't allow any overrides // If in wilderness, don't allow any overrides
PS ps = PS.valueOf(event.getBlock()); PS ps = PS.valueOf(block);
Faction hostFaction = BoardColl.get().getFactionAt(ps); Faction hostFaction = BoardColl.get().getFactionAt(ps);
if (hostFaction.isNone()) { if (hostFaction.isNone()) {
return; return;
} }
MPlayer player = MPlayer.get(event.getPlayer()); MPlayer player = MPlayer.get(event.getPlayer());
MPerm perm = ProtectCase.BUILD.getPerm(event.getBlock()); MPerm perm = ProtectCase.BUILD.getPerm(block);
// Only allow if the player is the leader of the faction the sign is in // Only allow if the player is the leader of the faction the sign is in
if (player.getFaction() != hostFaction || !player.getRank().isLeader()) { if (player.getFaction() != hostFaction || !player.getRank().isLeader()) {