Skip to content
This repository was archived by the owner on Jul 7, 2023. It is now read-only.

Commit 1531efc

Browse files
committed
Merge remote-tracking branch 'origin/1.6.x' into 1.6.x
2 parents 36efd8a + 9c6cc18 commit 1531efc

21 files changed

+111
-66
lines changed
1.1 MB
Binary file not shown.

src/main/java/com/massivecraft/factions/cmd/CmdBan.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,12 @@ public CmdBan() {
3434
@Override
3535
public void perform() {
3636

37-
// Adds bypass to admins and clean permission check
38-
if (!fme.isAdminBypassing()) {
39-
Access access = myFaction.getAccess(fme, PermissableAction.BAN);
40-
if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) {
41-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "ban");
42-
return;
43-
}
37+
// Simplified for clarity
38+
if (!this.hasAccess(PermissableAction.BAN)) {
39+
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage bans");
40+
return;
4441
}
4542

46-
4743
// Good on permission checks. Now lets just ban the player.
4844
FPlayer target = argAsFPlayer(0);
4945
if (target == null) {

src/main/java/com/massivecraft/factions/cmd/CmdBanlist.java

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.massivecraft.factions.Factions;
77
import com.massivecraft.factions.struct.BanInfo;
88
import com.massivecraft.factions.struct.Permission;
9+
import com.massivecraft.factions.zcore.fperms.PermissableAction;
910
import com.massivecraft.factions.zcore.util.TL;
1011

1112
import java.util.ArrayList;
@@ -32,6 +33,10 @@ public CmdBanlist() {
3233

3334
@Override
3435
public void perform() {
36+
if (!this.hasAccess(PermissableAction.BAN)) {
37+
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage bans");
38+
return;
39+
}
3540
Faction target = myFaction;
3641
if (!args.isEmpty()) {
3742
target = argAsFaction(0);

src/main/java/com/massivecraft/factions/cmd/CmdChest.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ public void perform() {
3232
return;
3333
}
3434
// This permission check is way too explicit but it's clean
35-
if (!fme.isAdminBypassing()) {
36-
Access access = myFaction.getAccess(fme, PermissableAction.CHEST);
37-
if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) {
38-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "access chest");
39-
return;
40-
}
35+
if (!this.hasAccess(PermissableAction.CHEST)) {
36+
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "access chest");
37+
return;
4138
}
4239

4340
me.openInventory(fme.getFaction().getChest());

src/main/java/com/massivecraft/factions/cmd/CmdClaim.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,9 @@ public void perform() {
3737
int radius = this.argAsInt(0, 1); // Default to 1
3838
final Faction forFaction = this.argAsFaction(1, myFaction); // Default to own
3939

40-
if (!fme.isAdminBypassing()) {
41-
Access access = myFaction.getAccess(fme, PermissableAction.TERRITORY);
42-
if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) {
43-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "change faction territory");
44-
return;
45-
}
40+
if (!this.hasAccess(PermissableAction.TERRITORY)) {
41+
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "change faction territory");
42+
return;
4643
}
4744

4845

src/main/java/com/massivecraft/factions/cmd/CmdDeinvite.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@ public CmdDeinvite() {
3434
@Override
3535
public void perform() {
3636
FPlayer you = this.argAsBestFPlayerMatch(0);
37-
if (!fme.isAdminBypassing()) {
38-
Access access = myFaction.getAccess(fme, PermissableAction.INVITE);
39-
if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) {
40-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage invites");
41-
return;
42-
}
37+
if (!this.hasAccess(PermissableAction.INVITE)) {
38+
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage invites");
39+
return;
4340
}
4441
if (you == null) {
4542
FancyMessage msg = new FancyMessage(TL.COMMAND_DEINVITE_CANDEINVITE.toString()).color(ChatColor.GOLD);

src/main/java/com/massivecraft/factions/cmd/CmdDelFWarp.java

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.massivecraft.factions.FPlayer;
44
import com.massivecraft.factions.P;
55
import com.massivecraft.factions.struct.Permission;
6+
import com.massivecraft.factions.zcore.fperms.PermissableAction;
67
import com.massivecraft.factions.zcore.util.TL;
78

89
public class CmdDelFWarp extends FCommand {
@@ -22,6 +23,10 @@ public CmdDelFWarp() {
2223
@Override
2324
public void perform() {
2425
String warp = argAsString(0);
26+
if (!this.hasAccess(PermissableAction.WARP)){
27+
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage warps");
28+
return;
29+
}
2530
if (myFaction.isWarp(warp)) {
2631
if (!transact(fme)) {
2732
return;

src/main/java/com/massivecraft/factions/cmd/CmdDisband.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ public void perform() {
4545

4646
boolean isMyFaction = fme != null && faction == myFaction;
4747

48-
if (!fme.isAdminBypassing()) {
49-
Access access = myFaction.getAccess(fme, PermissableAction.DISBAND);
50-
if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) {
51-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "disband faction");
52-
return;
53-
}
54-
}
5548
if (!faction.isNormal()) {
5649
msg(TL.COMMAND_DISBAND_IMMUTABLE.toString());
5750
return;
@@ -60,6 +53,10 @@ public void perform() {
6053
msg(TL.COMMAND_DISBAND_MARKEDPERMANENT.toString());
6154
return;
6255
}
56+
if (!this.hasAccess(PermissableAction.DISBAND)) {
57+
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "disband faction");
58+
return;
59+
}
6360

6461

6562
// check for tnt before disbanding.

src/main/java/com/massivecraft/factions/cmd/CmdFWarp.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,9 @@ public CmdFWarp() {
3131
@Override
3232
public void perform() {
3333
//TODO: check if in combat.
34-
if (!fme.isAdminBypassing()) {
35-
Access access = myFaction.getAccess(fme, PermissableAction.WARP);
36-
if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) {
37-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "use warps");
38-
return;
39-
}
34+
if (!this.hasAccess(PermissableAction.WARP)) {
35+
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "use warps");
36+
return;
4037
}
4138

4239

src/main/java/com/massivecraft/factions/cmd/CmdFly.java

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public CmdFly() {
3636
this.senderMustBeMember = true;
3737
this.senderMustBeModerator = false;
3838
}
39+
/// I'll optimize this later today or tomorrow
3940

4041
public static void startParticles() {
4142
id = Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, new Runnable() {

src/main/java/com/massivecraft/factions/cmd/CmdGetVault.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.massivecraft.factions.P;
44
import com.massivecraft.factions.struct.Permission;
5+
import com.massivecraft.factions.zcore.fperms.PermissableAction;
56
import com.massivecraft.factions.zcore.util.TL;
67
import org.bukkit.Location;
78
import org.bukkit.Material;
@@ -33,7 +34,10 @@ public void perform() {
3334
Location vaultLocation = fme.getFaction().getVault();
3435
ItemStack vault = P.p.createItem(Material.CHEST, 1, (short) 0, P.p.color(P.p.getConfig().getString("fvault.Item.Name")), P.p.colorList(P.p.getConfig().getStringList("fvault.Item.Lore")));
3536

36-
37+
if (!this.hasAccess(PermissableAction.VAULT)) {
38+
fme.msg(TL.GENERIC_NOPERMISSION, "use vault");
39+
return;
40+
}
3741
//check if vault is set
3842
if (vaultLocation != null) {
3943
fme.msg(TL.COMMAND_GETVAULT_ALREADYSET);

src/main/java/com/massivecraft/factions/cmd/CmdHome.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,9 @@ public void perform() {
4949
fme.msg(TL.COMMAND_HOME_TELEPORTDISABLED);
5050
return;
5151
}
52-
if (!fme.isAdminBypassing()) {
53-
Access access = myFaction.getAccess(fme, PermissableAction.HOME);
54-
if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) {
55-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "teleport home");
56-
return;
57-
}
52+
if (!this.hasAccess(PermissableAction.HOME)) {
53+
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "teleport home");
54+
return;
5855
}
5956

6057

src/main/java/com/massivecraft/factions/cmd/CmdInspect.java

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public CmdInspect() {
2222

2323
@Override
2424
public void perform() {
25+
// Who can inspect?
2526
if (fme.isInspectMode()) {
2627
fme.setInspectMode(false);
2728
msg(TL.COMMAND_INSPECT_DISABLED_MSG);

src/main/java/com/massivecraft/factions/cmd/CmdInvite.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,9 @@ public void perform() {
4848
return;
4949
}
5050

51-
if (!fme.isAdminBypassing()) {
52-
Access access = myFaction.getAccess(fme, PermissableAction.INVITE);
53-
if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) {
54-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage invites");
55-
return;
56-
}
51+
if (!this.hasAccess(PermissableAction.INVITE)) {
52+
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage invites");
53+
return;
5754
}
5855

5956
if (myFaction.isInvited(target)) {

src/main/java/com/massivecraft/factions/cmd/CmdKick.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ public void perform() {
7979
// - Make sure the player is in the faction.
8080
// - Make sure the kicked player has lower rank than the kicker.
8181
if (!fme.isAdminBypassing()) {
82-
Access access = myFaction.getAccess(fme, PermissableAction.KICK);
83-
if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) {
82+
if (!this.hasAccess(PermissableAction.KICK, false)) {
8483
fme.msg(TL.GENERIC_NOPERMISSION, "kick");
8584
return;
8685
}

src/main/java/com/massivecraft/factions/cmd/CmdLogins.java

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.massivecraft.factions.cmd;
22

33
import com.massivecraft.factions.struct.Permission;
4+
import com.massivecraft.factions.struct.Role;
45
import com.massivecraft.factions.zcore.util.TL;
56

67
public class CmdLogins extends FCommand {
@@ -18,6 +19,11 @@ public CmdLogins() {
1819

1920
@Override
2021
public void perform() {
22+
/// Perhaps add a PermissableAction later?
23+
if (!fme.getRole().isAtLeast(Role.MODERATOR)) {
24+
fme.msg(TL.GENERIC_NOPERMISSION, "monitor joins");
25+
return;
26+
}
2127
boolean monitor = fme.isMonitoringJoins();
2228
fme.msg(TL.COMMAND_LOGINS_TOGGLE, String.valueOf(!monitor));
2329
fme.setMonitorJoins(!monitor);

src/main/java/com/massivecraft/factions/cmd/CmdSetFWarp.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,9 @@ public void perform() {
3737

3838
// This statement allows us to check if they've specifically denied it, or default to
3939
// the old setting of allowing moderators to set warps.
40-
if (!fme.isAdminBypassing()) {
41-
Access access = myFaction.getAccess(fme, PermissableAction.SETWARP);
42-
if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) {
43-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "set warps");
44-
return;
45-
}
40+
if (!this.hasAccess(PermissableAction.SETWARP)) {
41+
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "set warps");
42+
return;
4643
}
4744

4845

src/main/java/com/massivecraft/factions/cmd/CmdSethome.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,9 @@ public void perform() {
4040
return;
4141
}
4242

43-
if (!fme.isAdminBypassing()) {
44-
Access access = myFaction.getAccess(fme, PermissableAction.SETHOME);
45-
if (access != Access.ALLOW && fme.getRole() != Role.ADMIN && !Permission.SETHOME_ANY.has(sender, true)) {
46-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "set home");
47-
return;
48-
}
43+
if (!this.hasAccess(PermissableAction.SETHOME) && !Permission.SETHOME_ANY.has(sender, true)) {
44+
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "set home");
45+
return;
4946
}
5047

5148
// Can the player set the faction home HERE?

src/main/java/com/massivecraft/factions/cmd/CmdShowClaims.java

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.google.common.collect.ListMultimap;
55
import com.massivecraft.factions.FLocation;
66
import com.massivecraft.factions.struct.Permission;
7+
import com.massivecraft.factions.zcore.fperms.PermissableAction;
78
import com.massivecraft.factions.zcore.util.TL;
89

910
public class CmdShowClaims extends FCommand {
@@ -25,6 +26,11 @@ public CmdShowClaims() {
2526

2627
@Override
2728
public void perform() {
29+
// #suggestion
30+
if (!this.hasAccess(PermissableAction.TERRITORY)) {
31+
fme.msg(TL.GENERIC_NOPERMISSION, "manage territory");
32+
return;
33+
}
2834
sendMessage(TL.COMMAND_SHOWCLAIMS_HEADER.toString().replace("{faction}", fme.getFaction().describeTo(fme)));
2935
ListMultimap<String, String> chunkMap = ArrayListMultimap.create();
3036
String format = TL.COMMAND_SHOWCLAIMS_CHUNKSFORMAT.toString();

src/main/java/com/massivecraft/factions/cmd/CmdShowInvites.java

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.massivecraft.factions.FPlayer;
55
import com.massivecraft.factions.FPlayers;
66
import com.massivecraft.factions.struct.Permission;
7+
import com.massivecraft.factions.zcore.fperms.PermissableAction;
78
import com.massivecraft.factions.zcore.util.TL;
89
import mkremins.fanciful.FancyMessage;
910
import org.bukkit.ChatColor;
@@ -21,6 +22,10 @@ public CmdShowInvites() {
2122

2223
@Override
2324
public void perform() {
25+
if (!this.hasAccess(PermissableAction.INVITE)) {
26+
fme.msg(TL.GENERIC_NOPERMISSION, "manage invites");
27+
return;
28+
}
2429
FancyMessage msg = new FancyMessage(TL.COMMAND_SHOWINVITES_PENDING.toString()).color(ChatColor.GOLD);
2530
for (String id : myFaction.getInvites()) {
2631
FPlayer fp = FPlayers.getInstance().getById(id);

src/main/java/com/massivecraft/factions/cmd/FCommand.java

+44
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.massivecraft.factions.struct.Role;
66
import com.massivecraft.factions.util.WarmUpUtil;
77
import com.massivecraft.factions.zcore.MCommand;
8+
import com.massivecraft.factions.zcore.fperms.Access;
9+
import com.massivecraft.factions.zcore.fperms.PermissableAction;
810
import com.massivecraft.factions.zcore.util.TL;
911
import org.bukkit.command.CommandSender;
1012
import org.bukkit.entity.Player;
@@ -25,6 +27,7 @@ public abstract class FCommand extends MCommand<P> {
2527
public boolean senderMustBeModerator;
2628
public boolean senderMustBeAdmin;
2729
public boolean senderMustBeColeader;
30+
protected PermissableAction actionPermission;
2831

2932
public boolean isMoneyCommand;
3033

@@ -43,6 +46,47 @@ public FCommand() {
4346
senderMustBeAdmin = false;
4447
}
4548

49+
public boolean hasAccess() {
50+
if (this.permission == null || this.fme == null) return false;
51+
if (!this.fme.isAdminBypassing()) {
52+
Access access = myFaction.getAccess(this.fme, permission);
53+
if (access != Access.ALLOW && this.fme.getRole() != Role.ADMIN) {
54+
return false;
55+
}
56+
}
57+
return true;
58+
}
59+
public boolean hasAccess(boolean checkifAdmin) {
60+
if (this.permission == null || this.fme == null) return false;
61+
if (!this.fme.isAdminBypassing() && checkifAdmin) {
62+
Access access = myFaction.getAccess(this.fme, permission);
63+
if (access != Access.ALLOW && this.fme.getRole() != Role.ADMIN) {
64+
return false;
65+
}
66+
}
67+
return true;
68+
}
69+
public boolean hasAccess(PermissableAction perm) {
70+
if (this.permission == null || this.fme == null) return false;
71+
if (!this.fme.isAdminBypassing()) {
72+
Access access = myFaction.getAccess(this.fme, perm);
73+
if (access != Access.ALLOW && this.fme.getRole() != Role.ADMIN) {
74+
return false;
75+
}
76+
}
77+
return true;
78+
}
79+
public boolean hasAccess(PermissableAction perm, boolean checkifAdmin) {
80+
if (this.permission == null || this.fme == null) return false;
81+
if (!this.fme.isAdminBypassing() && checkifAdmin) {
82+
Access access = myFaction.getAccess(this.fme, perm);
83+
if (access != Access.ALLOW && this.fme.getRole() != Role.ADMIN) {
84+
return false;
85+
}
86+
}
87+
return true;
88+
}
89+
4690
@Override
4791
public void execute(CommandSender sender, List<String> args, List<MCommand<?>> commandChain) {
4892
if (sender instanceof Player) {

0 commit comments

Comments
 (0)