Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,10 @@ private boolean dispatchCommand(CommandSender sender, Command cmd, String label,
return true;
}
String s = args[1].replace("_", " ");
if(s.equalsIgnoreCase("<culture>")) {
p.sendMessage("§cEnter a culture name instead of <culture>.");
return true;
}
f.setCulture(s);
p.sendMessage("§aFaction culture changed to "+f.getCulture());
return true;
Expand All @@ -1135,6 +1139,10 @@ private boolean dispatchCommand(CommandSender sender, Command cmd, String label,
return true;
}
String s = args[1].replace("_", " ");
if(s.equalsIgnoreCase("<religion>")) {
p.sendMessage("§cEnter a religion name instead of <religion>.");
return true;
}
f.setReligion(s);
p.sendMessage("§aFaction religion changed to "+f.getReligion());
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ static Faction resolveFaction(String nameOrId) {
Faction byId = FactionManager.getByString(nameOrId);
if (byId != null) return byId;
for (Faction f : FactionManager.factions) {
if (f.getName() != null && f.getName().equalsIgnoreCase(nameOrId)) return f;
if (f.getName() != null && (f.getName().equalsIgnoreCase(nameOrId)
|| org.bukkit.ChatColor.stripColor(f.getName()).equalsIgnoreCase(nameOrId))) return f;
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ private Quarantine(Path file) {

public static Quarantine load(Path file) throws IOException {
Quarantine quarantine = new Quarantine(file);
QuarantineCommands.snapshot(file, List.of());
if (!Files.exists(file)) return quarantine;
try {
List<Record> loaded = GSON.fromJson(Files.readString(file, StandardCharsets.UTF_8),
new TypeToken<List<Record>>() {}.getType());
if (loaded == null) throw new JsonParseException("empty quarantine");
for (Record record : loaded) quarantine.records.put(record.id, record);
QuarantineCommands.snapshot(file, quarantine.records());
return quarantine;
} catch (JsonParseException malformed) {
throw new IOException("Unreadable quarantine " + file, malformed);
Expand All @@ -88,6 +90,7 @@ public static Quarantine load(Path file) throws IOException {

public void save() throws IOException {
MigrationFiles.write(file, GSON.toJson(new ArrayList<>(records.values())));
QuarantineCommands.snapshot(file, records());
}

public Collection<Record> records() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.io.IOException;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;

import org.bukkit.command.CommandSender;
Expand All @@ -14,8 +16,35 @@

/** {@code /f admin quarantine list} and {@code /f admin quarantine assign <recordId> <characterId>}. */
public final class QuarantineCommands {
private record Snapshot(Path file, List<String> unresolved) {}
private static volatile Snapshot snapshot = new Snapshot(null, List.of());

private QuarantineCommands() {}

/** Refreshed by migration and staff reads/writes, never by a tab request. */
static void snapshot(Path file, Collection<Quarantine.Record> records) {
snapshot = new Snapshot(file.toAbsolutePath().normalize(), records.stream()
.filter(record -> !record.applied && record.assigned == null)
.map(record -> record.id).toList());
}

public static List<String> complete(CommandSender sender, String[] args) {
if (!Permissions.isAdmin(sender) || args.length < 2 || !args[0].equalsIgnoreCase("admin")) return List.of();
List<String> candidates = List.of();
if (args.length == 2) candidates = List.of("quarantine");
else if (args[1].equalsIgnoreCase("quarantine")) {
if (args.length == 3) candidates = List.of("list", "assign");
else if (args.length == 4 && args[2].equalsIgnoreCase("assign")) {
SimpleFactions plugin = SimpleFactions.getInstance();
Snapshot current = snapshot;
if (plugin != null && plugin.getDataFolder().toPath().resolve(CharacterMigration.QUARANTINE)
.toAbsolutePath().normalize().equals(current.file())) candidates = current.unresolved();
}
}
String prefix = args[args.length - 1];
return candidates.stream().filter(value -> value.regionMatches(true, 0, prefix, 0, prefix.length())).toList();
}

public static boolean matches(String[] args) {
return args.length >= 2 && args[0].equalsIgnoreCase("admin") && args[1].equalsIgnoreCase("quarantine");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public static List<String> complete(String[] args) {
if (!TitleLoader.getByTier(tier).isEmpty()) completions.add(tier.getId());
}
} else if (sub.equals("where")) {
completions.add("<province>");
return List.of();
} else if (SUBCOMMANDS.contains(sub) || sub.equals("setcolor")) {
for (Title title : TitleLoader.getTitles()) {
if (sub.equals("addprovince") && title.isComposite()) continue;
Expand All @@ -237,13 +237,9 @@ public static List<String> complete(String[] args) {
Title title = TitleLoader.getById(args[2]);
String last = args[args.length - 1];
switch (sub) {
case "rename" -> {
if (args.length == 4) completions.add("<name>");
}
case "setcolour", "setcolor" -> {
if (args.length == 4) completions.add(title != null && title.getRgb() != null ? title.getRgb() : "R,G,B");
if (args.length == 4 && title != null && title.getRgb() != null) completions.add(title.getRgb());
}
case "addprovince" -> completions.add("<province>");
case "removeprovince" -> {
if (title != null) {
for (int province : title.getProvinces()) completions.add(String.valueOf(province));
Expand Down
Loading
Loading