Skip to content

Commit

Permalink
Add PVP permission
Browse files Browse the repository at this point in the history
  • Loading branch information
cjburkey01 committed May 26, 2024
1 parent 4183563 commit 46fa18c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static final class Masks {
public static int INTERACT_ENTITY = 1 << 5;
public static int INTERACT_BLOCK = 1 << 6;
public static int CONTAINERS = 1 << 7;
public static int PVP = 1 << 8;
}

/**
Expand Down Expand Up @@ -107,6 +108,14 @@ public void allowUseContainers(final boolean allow) {
setAllow(Masks.CONTAINERS, allow);
}

public boolean canAttackPlayer() {
return checkMask(Masks.PVP);
}

public void allowAttackPlayer(final boolean allow) {
setAllow(Masks.PVP, allow);
}

public Map<String, Boolean> toPermissionsMap() {
HashMap<String, Boolean> permissionsMap = new HashMap<>();

Expand All @@ -118,6 +127,7 @@ public Map<String, Boolean> toPermissionsMap() {
permissionsMap.put("interactEntities", this.canInteractEntities());
permissionsMap.put("interactBlocks", this.canInteractBlocks());
permissionsMap.put("useContainers", this.canUseContainers());
permissionsMap.put("pvp", this.canAttackPlayer());

return permissionsMap;
}
Expand All @@ -137,6 +147,7 @@ public Map<String, Boolean> toPermissionsMap() {
case "interactEntities" -> chunkPlayerPermissions.allowInteractEntities(permVal);
case "interactBlocks" -> chunkPlayerPermissions.allowInteractBlocks(permVal);
case "useContainers" -> chunkPlayerPermissions.allowUseContainers(permVal);
case "pvp" -> chunkPlayerPermissions.allowAttackPlayer(permVal);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ private void onEntityEvent(
final String permissionNeeded =
entityClass != null && entityClass.equalsIgnoreCase("VEHICLES")
? "interactVehicles"
: "interactEntities";
: (entity instanceof Player ? "pvp" : "interactEntities");

final boolean isOwner = (chunkOwner != null && chunkOwner.equals(ply));
final boolean isOwnerOrAccess =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,9 @@ public final class V2JsonMessages {
public String argInteractEntities = "interactEntities";
public String argInteractBlocks = "interactBlocks";
public String argUseContainers = "useContainers";
public String argPvp = "pvp";
public String argAllChunks = "allChunks";
public String[] permissionArgs =
public transient String[] permissionArgs =
new String[] {
argBreak,
argPlace,
Expand All @@ -245,6 +246,7 @@ public final class V2JsonMessages {
argInteractEntities,
argInteractBlocks,
argUseContainers,
argPvp,
argAllChunks
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class AccessCmd extends CCSubCommand {
"interactEntities",
"interactBlocks",
"useContainers",
"pvp",
"allChunks"
};

Expand All @@ -55,6 +56,7 @@ public CCArg[] getPermittedArguments() {
new CCArg(claimChunk.getMessages().argInteractEntities, CCAutoComplete.PERMISSION),
new CCArg(claimChunk.getMessages().argInteractBlocks, CCAutoComplete.PERMISSION),
new CCArg(claimChunk.getMessages().argUseContainers, CCAutoComplete.PERMISSION),
new CCArg(claimChunk.getMessages().argPvp, CCAutoComplete.PERMISSION),
new CCArg(claimChunk.getMessages().argAllChunks, CCAutoComplete.PERMISSION)
};
}
Expand Down

0 comments on commit 46fa18c

Please sign in to comment.