|
| 1 | +/*------------------------------------------------------------------------------ |
| 2 | + - Adapt is a Skill/Integration plugin for Minecraft Bukkit Servers |
| 3 | + - Copyright (c) 2022 Arcane Arts (Volmit Software) |
| 4 | + - |
| 5 | + - This program is free software: you can redistribute it and/or modify |
| 6 | + - it under the terms of the GNU General Public License as published by |
| 7 | + - the Free Software Foundation, either version 3 of the License, or |
| 8 | + - (at your option) any later version. |
| 9 | + - |
| 10 | + - This program is distributed in the hope that it will be useful, |
| 11 | + - but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + - GNU General Public License for more details. |
| 14 | + - |
| 15 | + - You should have received a copy of the GNU General Public License |
| 16 | + - along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 17 | + -----------------------------------------------------------------------------*/ |
| 18 | + |
| 19 | +package com.volmit.adapt.content.protector; |
| 20 | + |
| 21 | +import com.volmit.adapt.AdaptConfig; |
| 22 | +import com.volmit.adapt.api.adaptation.Adaptation; |
| 23 | +import com.volmit.adapt.api.protection.Protector; |
| 24 | +import me.ryanhamshire.GriefPrevention.Claim; |
| 25 | +import me.ryanhamshire.GriefPrevention.ClaimPermission; |
| 26 | +import me.ryanhamshire.GriefPrevention.GriefPrevention; |
| 27 | +import me.ryanhamshire.GriefPrevention.PlayerData; |
| 28 | +import org.bukkit.Location; |
| 29 | +import org.bukkit.entity.Player; |
| 30 | + |
| 31 | +import java.util.Objects; |
| 32 | + |
| 33 | +public class GriefPreventionProtector implements Protector { |
| 34 | + |
| 35 | + |
| 36 | + @Override |
| 37 | + public boolean canBlockBreak(Player player, Location location, Adaptation<?> adaptation) { |
| 38 | + return canEditClaim(player, location); |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + public boolean canBlockPlace(Player player, Location location, Adaptation<?> adaptation) { |
| 43 | + return canEditClaim(player, location); |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public String getName() { |
| 48 | + return "GriefPrevention"; |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public boolean isEnabledByDefault() { |
| 53 | + return AdaptConfig.get().getProtectorSupport().isGriefprevention(); |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public void unregister() { |
| 58 | + Protector.super.unregister(); |
| 59 | + } |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + private boolean canEditClaim(Player player, Location location) { |
| 64 | + Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, true, null); |
| 65 | + PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId()); |
| 66 | + |
| 67 | + if (claim == null) { |
| 68 | + return true; |
| 69 | + } |
| 70 | + //If doesn't check is adminclaim getting ownerid return null |
| 71 | + if (!claim.isAdminClaim() && Objects.equals(claim.getOwnerID(), player.getUniqueId())) { |
| 72 | + return true; |
| 73 | + } |
| 74 | + else if (claim.getPermission(player.getUniqueId().toString()) == ClaimPermission.Build) { |
| 75 | + return true; |
| 76 | + } |
| 77 | + |
| 78 | + return playerData.ignoreClaims || claim.isAdminClaim() && player.hasPermission("griefprevention.adminclaims"); |
| 79 | + |
| 80 | + } |
| 81 | + |
| 82 | + |
| 83 | +} |
| 84 | + |
0 commit comments