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

Commit 90ae182

Browse files
committed
Revert "WIP: Access method for commands"
This reverts commit 9c6cc18.
1 parent 9a77370 commit 90ae182

21 files changed

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

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

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

37-
// Simplified for clarity
38-
if (!this.hasAccess(PermissableAction.BAN)) {
39-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage bans");
40-
return;
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+
}
4144
}
4245

46+
4347
// Good on permission checks. Now lets just ban the player.
4448
FPlayer target = argAsFPlayer(0);
4549
if (target == null) {

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

-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
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;
109
import com.massivecraft.factions.zcore.util.TL;
1110

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

3433
@Override
3534
public void perform() {
36-
if (!this.hasAccess(PermissableAction.BAN)) {
37-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage bans");
38-
return;
39-
}
4035
Faction target = myFaction;
4136
if (!args.isEmpty()) {
4237
target = argAsFaction(0);

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ public void perform() {
3232
return;
3333
}
3434
// This permission check is way too explicit but it's clean
35-
if (!this.hasAccess(PermissableAction.CHEST)) {
36-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "access chest");
37-
return;
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+
}
3841
}
3942

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

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ 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 (!this.hasAccess(PermissableAction.TERRITORY)) {
41-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "change faction territory");
42-
return;
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+
}
4346
}
4447

4548

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ public CmdDeinvite() {
3434
@Override
3535
public void perform() {
3636
FPlayer you = this.argAsBestFPlayerMatch(0);
37-
if (!this.hasAccess(PermissableAction.INVITE)) {
38-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage invites");
39-
return;
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+
}
4043
}
4144
if (you == null) {
4245
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,7 +3,6 @@
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;
76
import com.massivecraft.factions.zcore.util.TL;
87

98
public class CmdDelFWarp extends FCommand {
@@ -23,10 +22,6 @@ public CmdDelFWarp() {
2322
@Override
2423
public void perform() {
2524
String warp = argAsString(0);
26-
if (!this.hasAccess(PermissableAction.WARP)){
27-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage warps");
28-
return;
29-
}
3025
if (myFaction.isWarp(warp)) {
3126
if (!transact(fme)) {
3227
return;

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ 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+
}
4855
if (!faction.isNormal()) {
4956
msg(TL.COMMAND_DISBAND_IMMUTABLE.toString());
5057
return;
@@ -53,10 +60,6 @@ public void perform() {
5360
msg(TL.COMMAND_DISBAND_MARKEDPERMANENT.toString());
5461
return;
5562
}
56-
if (!this.hasAccess(PermissableAction.DISBAND)) {
57-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "disband faction");
58-
return;
59-
}
6063

6164

6265
// check for tnt before disbanding.

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ public CmdFWarp() {
3131
@Override
3232
public void perform() {
3333
//TODO: check if in combat.
34-
if (!this.hasAccess(PermissableAction.WARP)) {
35-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "use warps");
36-
return;
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+
}
3740
}
3841

3942

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

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

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

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

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

33
import com.massivecraft.factions.P;
44
import com.massivecraft.factions.struct.Permission;
5-
import com.massivecraft.factions.zcore.fperms.PermissableAction;
65
import com.massivecraft.factions.zcore.util.TL;
76
import org.bukkit.Location;
87
import org.bukkit.Material;
@@ -34,10 +33,7 @@ public void perform() {
3433
Location vaultLocation = fme.getFaction().getVault();
3534
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")));
3635

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

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ public void perform() {
4949
fme.msg(TL.COMMAND_HOME_TELEPORTDISABLED);
5050
return;
5151
}
52-
if (!this.hasAccess(PermissableAction.HOME)) {
53-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "teleport home");
54-
return;
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+
}
5558
}
5659

5760

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

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

2323
@Override
2424
public void perform() {
25-
// Who can inspect?
2625
if (fme.isInspectMode()) {
2726
fme.setInspectMode(false);
2827
msg(TL.COMMAND_INSPECT_DISABLED_MSG);

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

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

51-
if (!this.hasAccess(PermissableAction.INVITE)) {
52-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage invites");
53-
return;
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+
}
5457
}
5558

5659
if (myFaction.isInvited(target)) {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ 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-
if (!this.hasAccess(PermissableAction.KICK, false)) {
82+
Access access = myFaction.getAccess(fme, PermissableAction.KICK);
83+
if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) {
8384
fme.msg(TL.GENERIC_NOPERMISSION, "kick");
8485
return;
8586
}

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

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

33
import com.massivecraft.factions.struct.Permission;
4-
import com.massivecraft.factions.struct.Role;
54
import com.massivecraft.factions.zcore.util.TL;
65

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

2019
@Override
2120
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-
}
2721
boolean monitor = fme.isMonitoringJoins();
2822
fme.msg(TL.COMMAND_LOGINS_TOGGLE, String.valueOf(!monitor));
2923
fme.setMonitorJoins(!monitor);

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ 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 (!this.hasAccess(PermissableAction.SETWARP)) {
41-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "set warps");
42-
return;
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+
}
4346
}
4447

4548

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

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

43-
if (!this.hasAccess(PermissableAction.SETHOME) && !Permission.SETHOME_ANY.has(sender, true)) {
44-
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "set home");
45-
return;
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+
}
4649
}
4750

4851
// 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,7 +4,6 @@
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;
87
import com.massivecraft.factions.zcore.util.TL;
98

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

2726
@Override
2827
public void perform() {
29-
// #suggestion
30-
if (!this.hasAccess(PermissableAction.TERRITORY)) {
31-
fme.msg(TL.GENERIC_NOPERMISSION, "manage territory");
32-
return;
33-
}
3428
sendMessage(TL.COMMAND_SHOWCLAIMS_HEADER.toString().replace("{faction}", fme.getFaction().describeTo(fme)));
3529
ListMultimap<String, String> chunkMap = ArrayListMultimap.create();
3630
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,7 +4,6 @@
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;
87
import com.massivecraft.factions.zcore.util.TL;
98
import mkremins.fanciful.FancyMessage;
109
import org.bukkit.ChatColor;
@@ -22,10 +21,6 @@ public CmdShowInvites() {
2221

2322
@Override
2423
public void perform() {
25-
if (!this.hasAccess(PermissableAction.INVITE)) {
26-
fme.msg(TL.GENERIC_NOPERMISSION, "manage invites");
27-
return;
28-
}
2924
FancyMessage msg = new FancyMessage(TL.COMMAND_SHOWINVITES_PENDING.toString()).color(ChatColor.GOLD);
3025
for (String id : myFaction.getInvites()) {
3126
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,8 +5,6 @@
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;
108
import com.massivecraft.factions.zcore.util.TL;
119
import org.bukkit.command.CommandSender;
1210
import org.bukkit.entity.Player;
@@ -27,7 +25,6 @@ public abstract class FCommand extends MCommand<P> {
2725
public boolean senderMustBeModerator;
2826
public boolean senderMustBeAdmin;
2927
public boolean senderMustBeColeader;
30-
protected PermissableAction actionPermission;
3128

3229
public boolean isMoneyCommand;
3330

@@ -46,47 +43,6 @@ public FCommand() {
4643
senderMustBeAdmin = false;
4744
}
4845

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 isAdmin) {
60-
if (this.actionPermission == null || this.fme == null) return false;
61-
if (!this.fme.isAdminBypassing() && isAdmin) {
62-
Access access = myFaction.getAccess(this.fme, this.actionPermission);
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 isAdmin) {
80-
if (this.permission == null || this.fme == null) return false;
81-
if (!this.fme.isAdminBypassing() && isAdmin) {
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-
9046
@Override
9147
public void execute(CommandSender sender, List<String> args, List<MCommand<?>> commandChain) {
9248
if (sender instanceof Player) {

0 commit comments

Comments
 (0)