Skip to content

Commit

Permalink
Add config option for claim list command
Browse files Browse the repository at this point in the history
  • Loading branch information
NotRyken committed Jun 18, 2024
1 parent 26b402b commit ae1155f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,23 @@ public void register(Minecraft mc, CommandDispatcher<S> dispatcher, CommandBuild

private static int showClaimPoints() {
ClaimPoints.waypointManager.showClaimPoints();
sendWithPrefix("Enabled all ClaimPoints");
return Command.SINGLE_SUCCESS;
}

private static int hideClaimPoints() {
ClaimPoints.waypointManager.hideClaimPoints();
sendWithPrefix("Disabled all ClaimPoints");
return Command.SINGLE_SUCCESS;
}

private static int clearClaimPoints() {
int removed = ClaimPoints.waypointManager.clearClaimPoints();
MutableComponent msg = ClaimPoints.PREFIX.copy();
msg.append("Removed all ClaimPoints (" + removed + ").");
if (Minecraft.getInstance().player != null) {
Minecraft.getInstance().player.sendSystemMessage(msg);
}
sendWithPrefix("Removed all ClaimPoints (" + removed + ").");
return Command.SINGLE_SUCCESS;
}

private static int setNameFormat(String nameFormat) {
MutableComponent msg = ClaimPoints.PREFIX.copy();
int indexOfSize = nameFormat.indexOf("%d");
if (indexOfSize != -1) {
ClaimPoints.waypointManager.setClaimPointNameFormat(nameFormat);
Expand All @@ -90,15 +87,12 @@ private static int setNameFormat(String nameFormat) {
"(\\d+)" + Pattern.quote(nameFormat.substring(indexOfSize + 2)) + "$";
Config.get().cpSettings.nameCompiled = Pattern.compile(Config.get().cpSettings.namePattern);
Config.save();
msg.append("Set ClaimPoint name format to '" + nameFormat + "'.");
sendWithPrefix("Set ClaimPoint name format to '" + nameFormat + "'.");
}
else {
msg.append("'" + nameFormat + "' is not a valid name format. Requires %d for claim size.");
sendWithPrefix("'" + nameFormat + "' is not a valid name format. Requires %d for claim size.");
}

if (Minecraft.getInstance().player != null) {
Minecraft.getInstance().player.sendSystemMessage(msg);
}
return Command.SINGLE_SUCCESS;
}

Expand All @@ -107,39 +101,31 @@ private static int setAlias(String alias) {
ClaimPoints.waypointManager.setClaimPointAlias(alias);
Config.get().cpSettings.alias = alias;
Config.save();
MutableComponent msg = ClaimPoints.PREFIX.copy();
msg.append("Set alias of all ClaimPoints to " + alias);

if (Minecraft.getInstance().player != null) {
Minecraft.getInstance().player.sendSystemMessage(msg);
}
sendWithPrefix("Set alias of all ClaimPoints to " + alias);
return Command.SINGLE_SUCCESS;
}

private static int setColor(String color) {
MutableComponent msg = ClaimPoints.PREFIX.copy();
int index = ClaimPoints.waypointColorNames.indexOf(color);
if (index == -1) {
msg.append("'" + color + "' is not a valid color ID.");
sendWithPrefix("'" + color + "' is not a valid color ID.");
}
else {
ClaimPoints.waypointManager.setClaimPointColor(index);
Config.get().cpSettings.color = color;
Config.get().cpSettings.colorIdx = index;
Config.save();
msg.append("Set color of all ClaimPoints to " + color);
sendWithPrefix("Set color of all ClaimPoints to " + color);
}

if (Minecraft.getInstance().player != null) {
Minecraft.getInstance().player.sendSystemMessage(msg);
}
return Command.SINGLE_SUCCESS;
}

private static int getWorlds() {
ClientPacketListener connection = Minecraft.getInstance().getConnection();
if (connection != null) {
connection.sendCommand("claimlist");
connection.sendCommand(Config.get().gpSettings.claimListCommand);
ChatScanner.startWorldScan();
}
return Command.SINGLE_SUCCESS;
Expand Down Expand Up @@ -219,9 +205,19 @@ private static int showHelp() {
msg.append(Component.literal("Sets the color of all ClaimPoints to the specified value.\n")
.withStyle(ChatFormatting.GRAY));
msg.append("===============================================\n");
send(msg);
return Command.SINGLE_SUCCESS;
}

private static void sendWithPrefix(String content) {
MutableComponent message = ClaimPoints.PREFIX.copy();
message.append(content);
send(message);
}

private static void send(Component message) {
if (Minecraft.getInstance().player != null) {
Minecraft.getInstance().player.sendSystemMessage(msg);
Minecraft.getInstance().player.sendSystemMessage(message);
}
return Command.SINGLE_SUCCESS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public static class ClaimPointSettings {
}

public static class GriefPreventionSettings {
public static final String defaultClaimListCommand = "claimlist";
public String claimListCommand = defaultClaimListCommand;

public static final String defaultFirstLinePattern =
"^-?\\d+ blocks from play \\+ -?\\d+ bonus = -?\\d+ total\\.$";
public String firstLinePattern = defaultFirstLinePattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ static Screen getConfigScreen(Screen parent) {

ConfigCategory gp = builder.getOrCreateCategory(Component.literal("GriefPrevention"));

gp.addEntry(eb.startStrField(Component.literal("Claim List Command"), config.gpSettings.claimListCommand)
.setDefaultValue(Config.GriefPreventionSettings.defaultClaimListCommand)
.setSaveConsumer(var -> config.gpSettings.claimListCommand = var)
.build());

gp.addEntry(eb.startStrField(Component.literal("First Line Pattern"), config.gpSettings.firstLinePattern)
.setDefaultValue(Config.GriefPreventionSettings.defaultFirstLinePattern)
.setSaveConsumer(var -> config.gpSettings.firstLinePattern = var)
Expand Down

0 comments on commit ae1155f

Please sign in to comment.