Skip to content

Commit 8b758da

Browse files
committed
more aggressive and explicit joinpoint limits and improve messaging (add limit type)
1 parent 8d1a462 commit 8b758da

3 files changed

Lines changed: 25 additions & 12 deletions

File tree

src/main/java/com/fibermc/essentialcommands/commands/joinpoints/JoinpointException.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fibermc.essentialcommands.text.ECText;
44
import com.fibermc.essentialcommands.text.TextFormatType;
5+
import com.fibermc.essentialcommands.types.JoinpointLimit;
56

67
import net.minecraft.text.Text;
78

@@ -210,11 +211,13 @@ public Text message(ECText ecText) {
210211
static final class MaxPointsExceeded extends Set {
211212
private final int max;
212213
private final int current;
214+
private final JoinpointLimit.JoinpointType limitType;
213215

214-
public MaxPointsExceeded(String joinpointName, int max, int current) {
216+
public MaxPointsExceeded(String joinpointName, int max, int current, JoinpointLimit.JoinpointType limitType) {
215217
super(joinpointName);
216218
this.max = max;
217219
this.current = current;
220+
this.limitType = limitType;
218221
}
219222

220223
public int getMax() {
@@ -230,7 +233,9 @@ public Text message(ECText ecText) {
230233
return ecText.getText(
231234
"cmd.joinpoint.set.error.limit",
232235
TextFormatType.Error,
233-
ecText.accent(this.getJoinpointName())
236+
ecText.accent(this.getJoinpointName()),
237+
ecText.accent(String.valueOf(this.getMax())),
238+
ecText.accent(limitType.name().toLowerCase())
234239
);
235240
}
236241
}

src/main/java/com/fibermc/essentialcommands/commands/joinpoints/JoinpointSetCommand.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import net.minecraft.server.network.ServerPlayerEntity;
2828
import net.minecraft.text.Text;
2929

30-
import dev.jpcode.eccore.util.CollectionUtils;
31-
3230
public class JoinpointSetCommand implements Command<ServerCommandSource> {
3331

3432
private final Action action;
@@ -124,24 +122,34 @@ private Void handleSetAsync(
124122
var targetTypePerms = ECPerms.Registry.Group.joinpoint_limit_groups.get(joinpointType);
125123
var anyTypePerms = ECPerms.Registry.Group.joinpoint_limit_groups.get(JoinpointLimit.JoinpointType.ANY);
126124

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
130130

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);
133141
}
134142

135143
// Create new joinpoint
136144
MinecraftLocation location = new MinecraftLocation(senderPlayer);
137145
JoinpointLocation joinpoint = new JoinpointLocation(
138-
location, joinpointName, senderPlayer.getUuid(), isGlobal, Set.of()
146+
location, joinpointName, senderPlayer.getUuid(), targetTypeIsGlobal, Set.of()
139147
);
140148

141149
database.createJoinpointAsync(joinpointName, senderPlayer.getUuid(), joinpoint).join();
142150

143151
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"
145153
: "cmd.joinpoint.set.feedback";
146154

147155
playerData.sendCommandFeedback(messageKey, joinpointNameText);

src/main/resources/assets/essential_commands/lang/en_us.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"cmd.joinpoint.set.feedback": "Joinpoint '${0}' set.",
3131
"cmd.joinpoint.set.feedback.global": "Global joinpoint '${0}' set.",
3232
"cmd.joinpoint.set.feedback.shared": "Shared joinpoint '${0}' set.",
33-
"cmd.joinpoint.set.error.limit": "Joinpoint '${0}' could not be set. Joinpoint limit (${1}) reached.",
33+
"cmd.joinpoint.set.error.limit": "Joinpoint '${0}' could not be set. Joinpoint limit (${1}) for joinpoint type '${2}' reached.",
3434
"cmd.joinpoint.set.error.exists": "Joinpoint '${0}' could not be set. A joinpoint with the specified name already exists.",
3535
"cmd.joinpoint.set.overwrite": "Joinpoint '${0}' already exists.\nWould you like to overwrite the existing joinpoint?",
3636
"cmd.joinpoint.overwrite.feedback": "Joinpoint '${0}' moved to current location.",

0 commit comments

Comments
 (0)