|
27 | 27 | import net.minecraft.server.network.ServerPlayerEntity; |
28 | 28 | import net.minecraft.text.Text; |
29 | 29 |
|
30 | | -import dev.jpcode.eccore.util.CollectionUtils; |
31 | | - |
32 | 30 | public class JoinpointSetCommand implements Command<ServerCommandSource> { |
33 | 31 |
|
34 | 32 | private final Action action; |
@@ -124,24 +122,34 @@ private Void handleSetAsync( |
124 | 122 | var targetTypePerms = ECPerms.Registry.Group.joinpoint_limit_groups.get(joinpointType); |
125 | 123 | var anyTypePerms = ECPerms.Registry.Group.joinpoint_limit_groups.get(JoinpointLimit.JoinpointType.ANY); |
126 | 124 |
|
127 | | - int playerMaxJoinpoints = ECPerms.getHighestNumericPermission( |
128 | | - senderPlayer.getCommandSource(), |
129 | | - CollectionUtils.concat(targetTypePerms, anyTypePerms)); |
| 125 | + int playerAllowedOfAnyType = anyTypePerms.length == 0 ? -1 : ECPerms.getHighestNumericPermission(senderPlayer.getCommandSource(), anyTypePerms); |
| 126 | + int playerAllowedCountOfTargetType = targetTypePerms.length == 0 ? -1 : ECPerms.getHighestNumericPermission(senderPlayer.getCommandSource(), targetTypePerms); |
| 127 | + |
| 128 | + // any(5) -> up to 5 shared or global, any combindation |
| 129 | + // any(5),shared(3) -> no more then 3 shared. Could have 5 global:0 shared to 2 global:3 shared |
130 | 130 |
|
131 | | - if (joinpoints.size() >= playerMaxJoinpoints) { |
132 | | - throw new JoinpointException.Set.MaxPointsExceeded(joinpointName, playerMaxJoinpoints, joinpoints.size()); |
| 131 | + boolean targetTypeIsGlobal = joinpointType == JoinpointLimit.JoinpointType.GLOBAL; |
| 132 | + int joinpointsOfTargetType = (int)joinpoints.stream().filter(p -> p.isGlobal() == targetTypeIsGlobal).count(); |
| 133 | + |
| 134 | + if (playerAllowedCountOfTargetType != -1) { |
| 135 | + // if we have an explicit permission for the target type, that overrides all others |
| 136 | + if (joinpointsOfTargetType >= playerAllowedCountOfTargetType) { |
| 137 | + throw new JoinpointException.Set.MaxPointsExceeded(joinpointName, playerAllowedCountOfTargetType, joinpointsOfTargetType, joinpointType); |
| 138 | + } |
| 139 | + } else if (playerAllowedOfAnyType != -1 && joinpoints.size() >= playerAllowedOfAnyType) { |
| 140 | + throw new JoinpointException.Set.MaxPointsExceeded(joinpointName, playerAllowedOfAnyType, joinpoints.size(), JoinpointLimit.JoinpointType.ANY); |
133 | 141 | } |
134 | 142 |
|
135 | 143 | // Create new joinpoint |
136 | 144 | MinecraftLocation location = new MinecraftLocation(senderPlayer); |
137 | 145 | JoinpointLocation joinpoint = new JoinpointLocation( |
138 | | - location, joinpointName, senderPlayer.getUuid(), isGlobal, Set.of() |
| 146 | + location, joinpointName, senderPlayer.getUuid(), targetTypeIsGlobal, Set.of() |
139 | 147 | ); |
140 | 148 |
|
141 | 149 | database.createJoinpointAsync(joinpointName, senderPlayer.getUuid(), joinpoint).join(); |
142 | 150 |
|
143 | 151 | Text joinpointNameText = ECText.access(senderPlayer).accent(joinpointName); |
144 | | - String messageKey = isGlobal ? "cmd.joinpoint.set.feedback.global" |
| 152 | + String messageKey = targetTypeIsGlobal ? "cmd.joinpoint.set.feedback.global" |
145 | 153 | : "cmd.joinpoint.set.feedback"; |
146 | 154 |
|
147 | 155 | playerData.sendCommandFeedback(messageKey, joinpointNameText); |
|
0 commit comments