|
1 | | -package com.volmit.adapt.content.protector; |
2 | | - |
3 | | -import com.bekvon.bukkit.residence.Residence; |
4 | | -import com.bekvon.bukkit.residence.containers.Flags; |
5 | | -import com.bekvon.bukkit.residence.protection.ClaimedResidence; |
6 | | -import com.bekvon.bukkit.residence.protection.FlagPermissions; |
7 | | -import com.volmit.adapt.Adapt; |
8 | | -import com.volmit.adapt.AdaptConfig; |
9 | | -import com.volmit.adapt.api.adaptation.Adaptation; |
10 | | -import com.volmit.adapt.api.protection.Protector; |
11 | | -import org.bukkit.Location; |
12 | | -import org.bukkit.entity.Player; |
13 | | - |
14 | | -public class ResidenceProtector implements Protector { |
15 | | - |
16 | | - public ResidenceProtector() { |
17 | | - FlagPermissions.addFlag("use-adaptations"); |
18 | | - } |
19 | | - |
20 | | - @Override |
21 | | - public boolean checkRegion(Player player, Location location, Adaptation<?> adaptation) { |
22 | | - return checkPerm(player, location, "use-adaptations"); |
23 | | - } |
24 | | - |
25 | | - @Override |
26 | | - public boolean canBlockBreak(Player player, Location blockLocation, Adaptation<?> adaptation) { |
27 | | - return checkRegion(player, blockLocation, adaptation) && checkPerm(player, blockLocation, Flags.destroy); |
28 | | - } |
29 | | - |
30 | | - @Override |
31 | | - public boolean canBlockPlace(Player player, Location blockLocation, Adaptation<?> adaptation) { |
32 | | - return checkRegion(player, blockLocation, adaptation) && checkPerm(player, blockLocation, Flags.place); |
33 | | - } |
34 | | - |
35 | | - @Override |
36 | | - public boolean canPVP(Player player, Location entityLocation, Adaptation<?> adaptation) { |
37 | | - return checkRegion(player, entityLocation, adaptation) && checkPerm(player, entityLocation, Flags.pvp); |
38 | | - } |
39 | | - |
40 | | - @Override |
41 | | - public boolean canPVE(Player player, Location entityLocation, Adaptation<?> adaptation) { |
42 | | - return checkRegion(player, entityLocation, adaptation) && checkPerm(player, entityLocation, Flags.damage); |
43 | | - } |
44 | | - |
45 | | - @Override |
46 | | - public boolean canInteract(Player player, Location targetLocation, Adaptation<?> adaptation) { |
47 | | - return checkRegion(player, targetLocation, adaptation) && checkPerm(player, targetLocation, Flags.use); |
48 | | - } |
49 | | - |
50 | | - @Override |
51 | | - public boolean canAccessChest(Player player, Location chestLocation, Adaptation<?> adaptation) { |
52 | | - return checkRegion(player, chestLocation, adaptation) && checkPerm(player, chestLocation, Flags.container); |
53 | | - } |
54 | | - |
55 | | - private boolean checkPerm(Player player, Location location, Flags flag) { |
56 | | - if (!Residence.getInstance().isDisabledWorld(location.getWorld())) { |
57 | | - ClaimedResidence res = Residence.getInstance().getResidenceManager().getByLoc(location); |
58 | | - if (res != null) { |
59 | | - return res.getPermissions().playerHas(player.getName(), flag, true); |
60 | | - } |
61 | | - } |
62 | | - return true; |
63 | | - } |
64 | | - |
65 | | - private boolean checkPerm(Player player, Location location, String flag) { |
66 | | - if (!Residence.getInstance().isDisabledWorld(location.getWorld())) { |
67 | | - ClaimedResidence res = Residence.getInstance().getResidenceManager().getByLoc(location); |
68 | | - if (res != null) { |
69 | | - return res.getPermissions().playerHas(player.getName(), flag, true); |
70 | | - } |
71 | | - } |
72 | | - return true; |
73 | | - } |
74 | | - |
75 | | - @Override |
76 | | - public String getName() { |
77 | | - return "Residence"; |
78 | | - } |
79 | | - |
80 | | - @Override |
81 | | - public boolean isEnabledByDefault() { |
82 | | - return AdaptConfig.get().getProtectorSupport().isResidence(); |
83 | | - } |
84 | | - |
85 | | -} |
| 1 | +package com.volmit.adapt.content.protector; |
| 2 | + |
| 3 | +import com.bekvon.bukkit.residence.Residence; |
| 4 | +import com.bekvon.bukkit.residence.containers.Flags; |
| 5 | +import com.bekvon.bukkit.residence.protection.ClaimedResidence; |
| 6 | +import com.bekvon.bukkit.residence.protection.FlagPermissions; |
| 7 | +import com.volmit.adapt.AdaptConfig; |
| 8 | +import com.volmit.adapt.api.adaptation.Adaptation; |
| 9 | +import com.volmit.adapt.api.protection.Protector; |
| 10 | +import com.volmit.adapt.util.J; |
| 11 | +import org.bukkit.Location; |
| 12 | +import org.bukkit.entity.Player; |
| 13 | + |
| 14 | +import java.util.concurrent.atomic.AtomicBoolean; |
| 15 | + |
| 16 | +public class ResidenceProtector implements Protector { |
| 17 | + |
| 18 | + public ResidenceProtector() { |
| 19 | + FlagPermissions.addFlag("use-adaptations"); |
| 20 | + } |
| 21 | + |
| 22 | + @Override |
| 23 | + public boolean checkRegion(Player player, Location location, Adaptation<?> adaptation) { |
| 24 | + return checkPerm(player, location, "use-adaptations"); |
| 25 | + } |
| 26 | + |
| 27 | + @Override |
| 28 | + public boolean canBlockBreak(Player player, Location blockLocation, Adaptation<?> adaptation) { |
| 29 | + return checkRegion(player, blockLocation, adaptation) && checkPerm(player, blockLocation, Flags.destroy); |
| 30 | + } |
| 31 | + |
| 32 | + @Override |
| 33 | + public boolean canBlockPlace(Player player, Location blockLocation, Adaptation<?> adaptation) { |
| 34 | + return checkRegion(player, blockLocation, adaptation) && checkPerm(player, blockLocation, Flags.place); |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + public boolean canPVP(Player player, Location entityLocation, Adaptation<?> adaptation) { |
| 39 | + return checkRegion(player, entityLocation, adaptation) && checkPerm(player, entityLocation, Flags.pvp); |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + public boolean canPVE(Player player, Location entityLocation, Adaptation<?> adaptation) { |
| 44 | + return checkRegion(player, entityLocation, adaptation) && checkPerm(player, entityLocation, Flags.damage); |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public boolean canInteract(Player player, Location targetLocation, Adaptation<?> adaptation) { |
| 49 | + return checkRegion(player, targetLocation, adaptation) && checkPerm(player, targetLocation, Flags.use); |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public boolean canAccessChest(Player player, Location chestLocation, Adaptation<?> adaptation) { |
| 54 | + return checkRegion(player, chestLocation, adaptation) && checkPerm(player, chestLocation, Flags.container); |
| 55 | + } |
| 56 | + |
| 57 | + private boolean checkPerm(Player player, Location location, Flags flag) { |
| 58 | + AtomicBoolean perm = new AtomicBoolean(false); |
| 59 | + J.s(() -> { |
| 60 | + if (!Residence.getInstance().isDisabledWorld(location.getWorld())) { |
| 61 | + ClaimedResidence res = Residence.getInstance().getResidenceManager().getByLoc(location); |
| 62 | + if (res != null) { |
| 63 | + perm.set(res.getPermissions().playerHas(player.getName(), flag, true)); |
| 64 | + } |
| 65 | + } |
| 66 | + }); |
| 67 | + return perm.get(); |
| 68 | + } |
| 69 | + |
| 70 | + private boolean checkPerm(Player player, Location location, String flag) { |
| 71 | + AtomicBoolean perm = new AtomicBoolean(false); |
| 72 | + J.s(() -> { |
| 73 | + if (!Residence.getInstance().isDisabledWorld(location.getWorld())) { |
| 74 | + ClaimedResidence res = Residence.getInstance().getResidenceManager().getByLoc(location); |
| 75 | + if (res != null) { |
| 76 | + perm.set(res.getPermissions().playerHas(player.getName(), flag, true)); |
| 77 | + } |
| 78 | + } |
| 79 | + }); |
| 80 | + return true; |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public String getName() { |
| 85 | + return "Residence"; |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + public boolean isEnabledByDefault() { |
| 90 | + return AdaptConfig.get().getProtectorSupport().isResidence(); |
| 91 | + } |
| 92 | + |
| 93 | +} |
0 commit comments