|
| 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.griefdefender.api.GriefDefender; |
| 22 | +import com.griefdefender.api.claim.Claim; |
| 23 | +import com.volmit.adapt.AdaptConfig; |
| 24 | +import com.volmit.adapt.api.adaptation.Adaptation; |
| 25 | +import com.volmit.adapt.api.protection.Protector; |
| 26 | +import org.bukkit.Location; |
| 27 | +import org.bukkit.entity.Player; |
| 28 | + |
| 29 | +import java.util.UUID; |
| 30 | + |
| 31 | +public class GriefDefenderProtector implements Protector { |
| 32 | + /** |
| 33 | + * This api is garbage, and obfuscated. |
| 34 | + * If i can get a jar ill improve it, but for now this is the best i can do. |
| 35 | + * Or if someone wants to make a PR feel free. |
| 36 | + * |
| 37 | + * I as an author do not support this api, and do not recommend it, |
| 38 | + * as they are making ME pay $15(spigot) + $5(patreon) per month to be |
| 39 | + * able to ask questions in their discord, and get unobfuscated jars. |
| 40 | + * |
| 41 | + */ |
| 42 | + |
| 43 | + @Override |
| 44 | + public boolean checkRegion(Player player, Location location, Adaptation<?> adaptation) { |
| 45 | + final Claim claim = GriefDefender.getCore().getClaimAt(location); |
| 46 | + return checkPerm(player, claim, adaptation) || claim.isWilderness(); |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public boolean canPVP(Player player, Location entityLocation, Adaptation<?> adaptation) { |
| 51 | + final Claim claim = GriefDefender.getCore().getClaimAt(entityLocation); |
| 52 | + if (checkPerm(player, claim, adaptation)) { |
| 53 | + return claim.isPvpAllowed(); |
| 54 | + } |
| 55 | + return false; |
| 56 | + } |
| 57 | + |
| 58 | + private boolean checkPerm(Player player, Claim claim, Adaptation<?> adaptation) { |
| 59 | + if (claim == null) { |
| 60 | + return true; |
| 61 | + } |
| 62 | + UUID uuid = player.getUniqueId(); |
| 63 | + return claim.isWilderness() |
| 64 | + || claim.getOwnerUniqueId().equals(uuid) |
| 65 | + || claim.getUserTrusts().contains(uuid); |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public boolean canPVE(Player player, Location entityLocation, Adaptation<?> adaptation) { |
| 70 | + return checkPerm(player, GriefDefender.getCore().getClaimAt(entityLocation), adaptation); |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public boolean canInteract(Player player, Location targetLocation, Adaptation<?> adaptation) { |
| 75 | + return checkPerm(player, GriefDefender.getCore().getClaimAt(targetLocation), adaptation); |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + public boolean canAccessChest(Player player, Location chestLocation, Adaptation<?> adaptation) { |
| 80 | + return checkPerm(player, GriefDefender.getCore().getClaimAt(chestLocation), adaptation); |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public boolean canBlockBreak(Player player, Location blockLocation, Adaptation<?> adaptation) { |
| 85 | + return checkPerm(player, GriefDefender.getCore().getClaimAt(blockLocation), adaptation); |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + public boolean canBlockPlace(Player player, Location blockLocation, Adaptation<?> adaptation) { |
| 90 | + return checkPerm(player, GriefDefender.getCore().getClaimAt(blockLocation), adaptation); |
| 91 | + } |
| 92 | + |
| 93 | + @Override |
| 94 | + public String getName() { |
| 95 | + return "GriefDefender"; |
| 96 | + } |
| 97 | + |
| 98 | + @Override |
| 99 | + public boolean isEnabledByDefault() { |
| 100 | + return AdaptConfig.get().getProtectorSupport().isFactionsClaim(); |
| 101 | + } |
| 102 | +} |
0 commit comments