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

Commit 182022f

Browse files
committed
Check for f perm in building
1 parent 9384b0f commit 182022f

File tree

10 files changed

+88
-62
lines changed

10 files changed

+88
-62
lines changed

licenses/LICENCE.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ run a copy of the Program. Ancillary propagation of a covered work
439439
occurring solely as a consequence of using peer-to-peer transmission
440440
to receive a copy likewise does not require acceptance. However,
441441
nothing other than this License grants you permission to propagate or
442-
modify any covered work. These actions infringe copyright if you do
442+
modify any covered work. These permissableActions infringe copyright if you do
443443
not accept this License. Therefore, by modifying or propagating a
444444
covered work, you indicate your acceptance of this License to do so.
445445

src/main/java/com/massivecraft/factions/Faction.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.massivecraft.factions.struct.Role;
77
import com.massivecraft.factions.util.LazyLocation;
88
import com.massivecraft.factions.zcore.fperms.Access;
9-
import com.massivecraft.factions.zcore.fperms.Action;
9+
import com.massivecraft.factions.zcore.fperms.PermissableAction;
1010
import com.massivecraft.factions.zcore.fperms.Permissable;
1111
import org.bukkit.ChatColor;
1212
import org.bukkit.Location;
@@ -139,11 +139,11 @@ public interface Faction extends EconomyParticipator {
139139

140140
public int getDeaths();
141141

142-
public Access getAccess(Permissable permissable, Action action);
142+
public Access getAccess(Permissable permissable, PermissableAction permissableAction);
143143

144-
public Access getAccess(FPlayer player, Action action);
144+
public Access getAccess(FPlayer player, PermissableAction permissableAction);
145145

146-
public void setPermission(Permissable permissable, Action action, Access access);
146+
public void setPermission(Permissable permissable, PermissableAction permissableAction, Access access);
147147

148148
public void resetPerms();
149149

src/main/java/com/massivecraft/factions/P.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import com.massivecraft.factions.util.*;
1515
import com.massivecraft.factions.zcore.MPlugin;
1616
import com.massivecraft.factions.zcore.fperms.Access;
17-
import com.massivecraft.factions.zcore.fperms.Action;
17+
import com.massivecraft.factions.zcore.fperms.PermissableAction;
1818
import com.massivecraft.factions.zcore.util.TextUtil;
1919
import net.milkbowl.vault.permission.Permission;
2020
import org.bukkit.Bukkit;
@@ -171,7 +171,7 @@ public GsonBuilder getGsonBuilder() {
171171
Type mapFLocToStringSetType = new TypeToken<Map<FLocation, Set<String>>>() {
172172
}.getType();
173173

174-
Type accessTypeAdatper = new TypeToken<Map<Relation, Map<Action, Access>>>() {
174+
Type accessTypeAdatper = new TypeToken<Map<Relation, Map<PermissableAction, Access>>>() {
175175
}.getType();
176176

177177
return new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE).registerTypeAdapter(accessTypeAdatper, new PermissionsMapTypeAdapter()).registerTypeAdapter(LazyLocation.class, new MyLocationTypeAdapter()).registerTypeAdapter(mapFLocToStringSetType, new MapFLocToStringSetTypeAdapter()).registerTypeAdapterFactory(EnumTypeAdapter.ENUM_FACTORY);

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.massivecraft.factions.struct.Permission;
55
import com.massivecraft.factions.struct.Relation;
66
import com.massivecraft.factions.zcore.fperms.Access;
7-
import com.massivecraft.factions.zcore.fperms.Action;
7+
import com.massivecraft.factions.zcore.fperms.PermissableAction;
88
import com.massivecraft.factions.zcore.util.TL;
99

1010
import java.util.Arrays;
@@ -47,7 +47,7 @@ public void perform() {
4747
}
4848

4949
Set<Relation> relations = new HashSet<>();
50-
Set<Action> actions = new HashSet<>();
50+
Set<PermissableAction> permissableActions = new HashSet<>();
5151

5252
boolean allRelations = argAsString(0).equalsIgnoreCase("all");
5353
boolean allActions = argAsString(1).equalsIgnoreCase("all");
@@ -65,15 +65,15 @@ public void perform() {
6565
}
6666

6767
if (allActions) {
68-
actions.addAll(Arrays.asList(Action.values()));
68+
permissableActions.addAll(Arrays.asList(PermissableAction.values()));
6969
} else {
70-
Action action = Action.fromString(argAsString(1));
71-
if (action == null) {
70+
PermissableAction permissableAction = PermissableAction.fromString(argAsString(1));
71+
if (permissableAction == null) {
7272
fme.msg(TL.COMMAND_PERM_INVALID_ACTION);
7373
return;
7474
}
7575

76-
actions.add(action);
76+
permissableActions.add(permissableAction);
7777
}
7878

7979
Access access = Access.fromString(argAsString(2));
@@ -84,8 +84,8 @@ public void perform() {
8484
}
8585

8686
for (Relation relation : relations) {
87-
for (Action action : actions) {
88-
fme.getFaction().setPermission(relation, action, access);
87+
for (PermissableAction permissableAction : permissableActions) {
88+
fme.getFaction().setPermission(relation, permissableAction, access);
8989
}
9090
}
9191

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.massivecraft.factions.struct.Permission;
55
import com.massivecraft.factions.struct.Role;
66
import com.massivecraft.factions.zcore.fperms.Access;
7-
import com.massivecraft.factions.zcore.fperms.Action;
7+
import com.massivecraft.factions.zcore.fperms.PermissableAction;
88
import com.massivecraft.factions.zcore.util.TL;
99

1010
public class FPromoteCommand extends FCommand {
@@ -38,7 +38,7 @@ public void perform() {
3838
return;
3939
}
4040

41-
Access access = myFaction.getAccess(fme.getRole(), Action.PROMOTE);
41+
Access access = myFaction.getAccess(fme.getRole(), PermissableAction.PROMOTE);
4242

4343
// Well this is messy.
4444
if (access == null || access == Access.UNDEFINED) {

src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.massivecraft.factions.struct.Permission;
66
import com.massivecraft.factions.struct.Relation;
77
import com.massivecraft.factions.zcore.fperms.Access;
8-
import com.massivecraft.factions.zcore.fperms.Action;
8+
import com.massivecraft.factions.zcore.fperms.PermissableAction;
99
import org.bukkit.Location;
1010
import org.bukkit.Material;
1111
import org.bukkit.block.Block;
@@ -252,7 +252,7 @@ public static boolean playerCanBuildDestroyBlock(Player player, Location locatio
252252
}
253253
}
254254

255-
Access access = otherFaction.getAccess(me, Action.fromString(action));
255+
Access access = otherFaction.getAccess(me, PermissableAction.fromString(action));
256256
if (access != null && access != Access.UNDEFINED) {
257257
// TODO: Update this once new access values are added other than just allow / deny.
258258
return access == Access.ALLOW;

src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java

+33-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.massivecraft.factions.struct.Role;
1212
import com.massivecraft.factions.util.VisualizeUtil;
1313
import com.massivecraft.factions.zcore.fperms.Access;
14+
import com.massivecraft.factions.zcore.fperms.PermissableAction;
1415
import com.massivecraft.factions.zcore.persist.MemoryFPlayer;
1516
import com.massivecraft.factions.zcore.util.TL;
1617
import com.massivecraft.factions.zcore.util.TextUtil;
@@ -32,10 +33,9 @@
3233
import java.util.UUID;
3334
import java.util.logging.Level;
3435

35-
3636
public class FactionsPlayerListener implements Listener {
3737

38-
public P p;
38+
private P p;
3939

4040
public FactionsPlayerListener(P p) {
4141
this.p = p;
@@ -355,7 +355,7 @@ public static boolean playerCanUseItemHere(Player player, Location location, Mat
355355
Relation rel = myFaction.getRelationTo(otherFaction);
356356

357357

358-
Access access = otherFaction.getAccess(me, com.massivecraft.factions.zcore.fperms.Action.ITEM);
358+
Access access = otherFaction.getAccess(me, PermissableAction.ITEM);
359359
if (access != null && access != Access.UNDEFINED) {
360360
// TODO: Update this once new access values are added other than just allow / deny.
361361
return access == Access.ALLOW;
@@ -422,10 +422,36 @@ public static boolean canPlayerUseBlock(Player player, Block block, boolean just
422422
}
423423
}
424424

425-
Access access = otherFaction.getAccess(me, com.massivecraft.factions.zcore.fperms.Action.BUILD);
426-
if (access != null && access != Access.UNDEFINED) {
427-
// TODO: Update this once new access values are added other than just allow / deny.
428-
return access == Access.ALLOW;
425+
PermissableAction action = null;
426+
427+
switch (block.getType()) {
428+
case LEVER:
429+
action = PermissableAction.LEVER;
430+
break;
431+
case STONE_BUTTON:
432+
case WOOD_BUTTON:
433+
action = PermissableAction.BUTTON;
434+
break;
435+
case DARK_OAK_DOOR:
436+
case ACACIA_DOOR:
437+
case BIRCH_DOOR:
438+
case IRON_DOOR:
439+
case JUNGLE_DOOR:
440+
case SPRUCE_DOOR:
441+
case TRAP_DOOR:
442+
case WOOD_DOOR:
443+
case WOODEN_DOOR:
444+
action = PermissableAction.DOOR;
445+
break;
446+
default:
447+
break;
448+
}
449+
450+
// F PERM check runs through before other checks.
451+
Access access = otherFaction.getAccess(me, action);
452+
if (access == null || access == Access.DENY) {
453+
me.msg(TL.GENERIC_NOPERMISSION, action);
454+
return false;
429455
}
430456

431457
// We only care about some material types.

src/main/java/com/massivecraft/factions/util/PermissionsMapTypeAdapter.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,37 @@
44
import com.massivecraft.factions.P;
55
import com.massivecraft.factions.struct.Relation;
66
import com.massivecraft.factions.zcore.fperms.Access;
7-
import com.massivecraft.factions.zcore.fperms.Action;
7+
import com.massivecraft.factions.zcore.fperms.PermissableAction;
88

99
import java.lang.reflect.Type;
1010
import java.util.HashMap;
1111
import java.util.Map;
1212
import java.util.concurrent.ConcurrentHashMap;
1313
import java.util.logging.Level;
1414

15-
public class PermissionsMapTypeAdapter implements JsonDeserializer<Map<Relation, Map<Action, Access>>> {
15+
public class PermissionsMapTypeAdapter implements JsonDeserializer<Map<Relation, Map<PermissableAction, Access>>> {
1616

1717
@Override
18-
public Map<Relation, Map<Action, Access>> deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
18+
public Map<Relation, Map<PermissableAction, Access>> deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
1919

2020
try {
2121
JsonObject obj = json.getAsJsonObject();
2222
if (obj == null) {
2323
return null;
2424
}
2525

26-
Map<Relation, Map<Action, Access>> permissionsMap = new ConcurrentHashMap<>();
26+
Map<Relation, Map<PermissableAction, Access>> permissionsMap = new ConcurrentHashMap<>();
2727

2828
// Top level is Relation
2929
for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
3030
Relation relation = Relation.fromString(entry.getKey());
3131

3232
// Second level is the map between action -> access
3333
for (Map.Entry<String, JsonElement> entry2 : entry.getValue().getAsJsonObject().entrySet()) {
34-
Map<Action, Access> accessMap = new HashMap<>();
35-
Action action = Action.fromString(entry2.getKey());
34+
Map<PermissableAction, Access> accessMap = new HashMap<>();
35+
PermissableAction permissableAction = PermissableAction.fromString(entry2.getKey());
3636
Access access = Access.fromString(entry2.getValue().getAsString());
37-
accessMap.put(action, access);
37+
accessMap.put(permissableAction, access);
3838

3939
permissionsMap.put(relation, accessMap);
4040
}

src/main/java/com/massivecraft/factions/zcore/fperms/Action.java renamed to src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java

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

3-
public enum Action {
3+
public enum PermissableAction {
44
BUILD("build"),
55
DESTROY("destroy"),
66
FROST_WALK("frostwalk"),
@@ -22,7 +22,7 @@ public enum Action {
2222

2323
private String name;
2424

25-
Action(String name) {
25+
PermissableAction(String name) {
2626
this.name = name;
2727
}
2828

@@ -41,10 +41,10 @@ public String getName() {
4141
* @param check
4242
* @return
4343
*/
44-
public static Action fromString(String check) {
45-
for (Action action : values()) {
46-
if (action.name().equalsIgnoreCase(check)) {
47-
return action;
44+
public static PermissableAction fromString(String check) {
45+
for (PermissableAction permissableAction : values()) {
46+
if (permissableAction.name().equalsIgnoreCase(check)) {
47+
return permissableAction;
4848
}
4949
}
5050

src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java

+23-23
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import com.massivecraft.factions.util.MiscUtil;
1212
import com.massivecraft.factions.util.RelationUtil;
1313
import com.massivecraft.factions.zcore.fperms.Access;
14-
import com.massivecraft.factions.zcore.fperms.Action;
14+
import com.massivecraft.factions.zcore.fperms.PermissableAction;
1515
import com.massivecraft.factions.zcore.fperms.Permissable;
1616
import com.massivecraft.factions.zcore.util.TL;
1717
import org.bukkit.Bukkit;
@@ -49,7 +49,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
4949
private long lastDeath;
5050
protected int maxVaults;
5151
protected Role defaultRole;
52-
protected Map<Permissable, Map<Action, Access>> permissions = new HashMap<>();
52+
protected Map<Permissable, Map<PermissableAction, Access>> permissions = new HashMap<>();
5353

5454
public HashMap<String, List<String>> getAnnouncements() {
5555
return this.announcements;
@@ -325,29 +325,29 @@ public int getDeaths() {
325325
// -------------------------------------------- //
326326

327327

328-
public Access getAccess(Permissable permissable, Action action) {
329-
if (permissable == null || action == null) {
330-
return null;
328+
public Access getAccess(Permissable permissable, PermissableAction permissableAction) {
329+
if (permissable == null || permissableAction == null) {
330+
return Access.UNDEFINED;
331331
}
332332

333-
Map<Action, Access> accessMap = permissions.get(permissable);
334-
if (accessMap != null && accessMap.containsKey(action)) {
335-
return accessMap.get(action);
333+
Map<PermissableAction, Access> accessMap = permissions.get(permissable);
334+
if (accessMap != null && accessMap.containsKey(permissableAction)) {
335+
return accessMap.get(permissableAction);
336336
}
337337

338-
return null;
338+
return Access.UNDEFINED;
339339
}
340340

341341
/**
342342
* Get the Access of a player. Will use player's Role if they are a faction member. Otherwise, uses their Relation.
343343
*
344344
* @param player
345-
* @param action
345+
* @param permissableAction
346346
* @return
347347
*/
348-
public Access getAccess(FPlayer player, Action action) {
349-
if (player == null || action == null) {
350-
return null;
348+
public Access getAccess(FPlayer player, PermissableAction permissableAction) {
349+
if (player == null || permissableAction == null) {
350+
return Access.UNDEFINED;
351351
}
352352

353353
Permissable perm;
@@ -358,21 +358,21 @@ public Access getAccess(FPlayer player, Action action) {
358358
perm = player.getFaction().getRelationTo(this);
359359
}
360360

361-
Map<Action, Access> accessMap = permissions.get(perm);
362-
if (accessMap != null && accessMap.containsKey(action)) {
363-
return accessMap.get(action);
361+
Map<PermissableAction, Access> accessMap = permissions.get(perm);
362+
if (accessMap != null && accessMap.containsKey(permissableAction)) {
363+
return accessMap.get(permissableAction);
364364
}
365365

366-
return null;
366+
return Access.UNDEFINED;
367367
}
368368

369-
public void setPermission(Permissable permissable, Action action, Access access) {
370-
Map<Action, Access> accessMap = permissions.get(permissable);
369+
public void setPermission(Permissable permissable, PermissableAction permissableAction, Access access) {
370+
Map<PermissableAction, Access> accessMap = permissions.get(permissable);
371371
if (accessMap == null) {
372372
accessMap = new HashMap<>();
373373
}
374374

375-
accessMap.put(action, access);
375+
accessMap.put(permissableAction, access);
376376
}
377377

378378
public void resetPerms() {
@@ -381,9 +381,9 @@ public void resetPerms() {
381381
permissions.clear();
382382

383383
// First populate a map with undefined as the permission for each action.
384-
Map<Action, Access> freshMap = new HashMap<>();
385-
for (Action action : Action.values()) {
386-
freshMap.put(action, Access.UNDEFINED);
384+
Map<PermissableAction, Access> freshMap = new HashMap<>();
385+
for (PermissableAction permissableAction : PermissableAction.values()) {
386+
freshMap.put(permissableAction, Access.UNDEFINED);
387387
}
388388

389389
// Put the map in there for each relation.

0 commit comments

Comments
 (0)