Skip to content

Commit adbb99c

Browse files
committed
3.0.2
Power display fix (Faction.java, AdminCommand.java) — Added fillBasePower() and /f admin power recalc to reset all factions' stored base power to the current config max, fixing old factions showing stale power values after a config change. Max power display fix — Was missing the max fame value. Special character validation (CreateCommand.java, ModifyCommand.java) — Faction names now reject *, ", \, and § to prevent command parsing failures like "The Boot *Stink Warning*". Suggestion filtering fix (Command.java) — Fixed greedyString() suggestions always showing all results by computing the correct remaining text from parsed context nodes instead of relying on builder.getStart(), which points to the end of input for greedy arguments.
1 parent a459b8a commit adbb99c

File tree

6 files changed

+57
-3
lines changed

6 files changed

+57
-3
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ yarn_mappings=1.20.1+build.10
66
loader_version=0.14.22
77

88
# Mod Properties
9-
mod_version = 3.0.1
9+
mod_version = 3.0.2
1010
maven_group = io.icker
1111
archives_base_name = factions
1212

src/main/java/io/icker/factions/api/persistents/Faction.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,12 @@ public static void save() {
672672
Database.save(Faction.class, STORE.values().stream().toList());
673673
}
674674

675+
public void fillBasePower() {
676+
power = getBasePowerMax();
677+
}
678+
675679
public int calculateMaxPower() {
676-
return getBasePowerMax() + adminPower + FactionsMod.CONFIG.POWER.WEALTH.MAX_VALUE + FactionsMod.CONFIG.POWER.WAR.MAX_VALUE + getVassalPowerBonus();
680+
return getBasePowerMax() + adminPower + FactionsMod.CONFIG.POWER.WEALTH.MAX_VALUE + FactionsMod.CONFIG.POWER.WAR.MAX_VALUE + FactionsMod.CONFIG.POWER.FAME.MAX_VALUE + getVassalPowerBonus();
677681
}
678682

679683
public Collection<User> getRelationships() {

src/main/java/io/icker/factions/command/AdminCommand.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ private int power(CommandContext<ServerCommandSource> context) throws CommandSyn
7272
return 1;
7373
}
7474

75+
private int powerRecalc(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
76+
ServerPlayerEntity player = context.getSource().getPlayerOrThrow();
77+
int count = 0;
78+
for (Faction faction : Faction.all()) {
79+
faction.fillBasePower();
80+
count++;
81+
}
82+
new Message("Recalculated base power for %d factions", count).send(player, false);
83+
return 1;
84+
}
85+
7586
private int spoof(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
7687
ServerCommandSource source = context.getSource();
7788
ServerPlayerEntity player = source.getPlayerOrThrow();
@@ -625,6 +636,8 @@ public LiteralCommandNode<ServerCommandSource> getNode() {
625636
.requires(
626637
Requires.hasPerms("factions.admin.power",
627638
FactionsMod.CONFIG.REQUIRED_BYPASS_LEVEL))
639+
.then(CommandManager.literal("recalc")
640+
.executes(this::powerRecalc))
628641
.then(CommandManager.argument("power", IntegerArgumentType.integer())
629642
.then(CommandManager
630643
.argument("faction", StringArgumentType.greedyString())

src/main/java/io/icker/factions/command/CreateCommand.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.icker.factions.command;
22

33
import java.util.Locale;
4+
import java.util.regex.Pattern;
45
import com.mojang.brigadier.arguments.StringArgumentType;
56
import com.mojang.brigadier.context.CommandContext;
67
import com.mojang.brigadier.exceptions.CommandSyntaxException;
@@ -16,12 +17,20 @@
1617
import net.minecraft.util.Formatting;
1718

1819
public class CreateCommand implements Command {
20+
private static final Pattern ILLEGAL_NAME_CHARS = Pattern.compile("[*\"\\\\§]");
21+
1922
private int run(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
2023
String name = StringArgumentType.getString(context, "name");
2124

2225
ServerCommandSource source = context.getSource();
2326
ServerPlayerEntity player = source.getPlayerOrThrow();
2427

28+
if (ILLEGAL_NAME_CHARS.matcher(name).find()) {
29+
new Message("Faction name cannot contain special characters: * \" \\ §").fail()
30+
.send(player, false);
31+
return 0;
32+
}
33+
2534
if (FactionsMod.CONFIG.DISPLAY.NAME_BLACKLIST.contains(name.toLowerCase(Locale.ROOT))) {
2635
new Message("Cannot create a faction with this name as it is on the blacklist").fail()
2736
.send(player, false);

src/main/java/io/icker/factions/command/ModifyCommand.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.icker.factions.command;
22

33
import java.util.Locale;
4+
import java.util.regex.Pattern;
45
import com.mojang.brigadier.arguments.BoolArgumentType;
56
import com.mojang.brigadier.arguments.StringArgumentType;
67
import com.mojang.brigadier.context.CommandContext;
@@ -17,12 +18,20 @@
1718
import net.minecraft.util.Formatting;
1819

1920
public class ModifyCommand implements Command {
21+
private static final Pattern ILLEGAL_NAME_CHARS = Pattern.compile("[*\"\\\\§]");
22+
2023
private int name(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
2124
String name = StringArgumentType.getString(context, "name");
2225

2326
ServerCommandSource source = context.getSource();
2427
ServerPlayerEntity player = source.getPlayerOrThrow();
2528

29+
if (ILLEGAL_NAME_CHARS.matcher(name).find()) {
30+
new Message("Faction name cannot contain special characters: * \" \\ §").fail()
31+
.send(player, false);
32+
return 0;
33+
}
34+
2635
if (FactionsMod.CONFIG.DISPLAY.NAME_BLACKLIST.contains(name.toLowerCase(Locale.ROOT))) {
2736
new Message("Cannot rename a faction to that name as it is on the blacklist").fail()
2837
.send(player, false);

src/main/java/io/icker/factions/util/Command.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import net.minecraft.util.UserCache;
1717

1818
import java.util.Arrays;
19+
import java.util.Locale;
1920
import java.util.Optional;
2021
import java.util.function.Predicate;
2122

@@ -166,8 +167,26 @@ public static SuggestionProvider<ServerCommandSource> suggest(Suggests sug) {
166167
return (context, builder) -> {
167168
ServerPlayerEntity entity = context.getSource().getPlayerOrThrow();
168169
User user = User.get(entity.getUuid());
170+
171+
// For greedyString arguments, builder.getStart() is positioned at the END of
172+
// the parsed input (because greedyString consumes everything), making
173+
// builder.getRemaining() return "" and causing all suggestions to always show.
174+
// Fix: find the actual start of the last argument from the parsed context nodes.
175+
int argStart = builder.getStart();
176+
for (com.mojang.brigadier.context.ParsedCommandNode<?> node : context.getNodes()) {
177+
if (node.getNode() instanceof com.mojang.brigadier.tree.ArgumentCommandNode) {
178+
argStart = node.getRange().getStart();
179+
}
180+
}
181+
182+
String remaining = builder.getInput()
183+
.substring(Math.min(argStart, builder.getInput().length()))
184+
.toLowerCase(Locale.ROOT);
185+
169186
for (String suggestion : sug.run(user)) {
170-
builder.suggest(suggestion);
187+
if (suggestion.toLowerCase(Locale.ROOT).startsWith(remaining)) {
188+
builder.suggest(suggestion);
189+
}
171190
}
172191
return builder.buildFuture();
173192
};

0 commit comments

Comments
 (0)