Skip to content

Commit

Permalink
Replace run command with suggest command for changable value button
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbowdashlabs committed Apr 4, 2024
1 parent 2788928 commit fff643a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import java.util.stream.Collectors;

import static de.eldoria.bloodnight.command.util.CommandUtil.changeButton;
import static de.eldoria.bloodnight.command.util.CommandUtil.changeableValue;
import static de.eldoria.bloodnight.command.util.CommandUtil.changeableValueWithInput;
import static de.eldoria.bloodnight.command.util.CommandUtil.getBooleanField;
import static de.eldoria.bloodnight.command.util.CommandUtil.getToggleField;
import static de.eldoria.eldoutilities.localization.ILocalizer.escape;
Expand Down Expand Up @@ -273,9 +273,9 @@ private void sendMobListPage(World world, CommandSender sender, Map.Entry<String
// Mob name state
entry.getMobName(), getBooleanField(entry.isActive(), cmd + "state {bool}", "", "state.enabled", "state.disabled"),
// Display Name
changeableValue("field.displayName", entry.getDisplayName(), cmd + "displayName " + entry.getDisplayName().replace("§", "&")),
changeableValueWithInput("field.displayName", entry.getDisplayName(), cmd + "displayName " + entry.getDisplayName().replace("§", "&")),
// Drop amount
changeableValue("field.dropAmount", entry.getDropAmount() == 0 ? escape("action.default") : entry.getDropAmount() + "x", cmd + "dropAmount "),
changeableValueWithInput("field.dropAmount", entry.getDropAmount() == 0 ? escape("action.default") : entry.getDropAmount() + "x", cmd + "dropAmount "),
// Drops
escape("field.drops"),
entry.getDrops().size() + " " + escape("field.drops"),
Expand All @@ -286,11 +286,11 @@ private void sendMobListPage(World world, CommandSender sender, Map.Entry<String
getToggleField(entry.getHealthModifier() == MobValueModifier.DEFAULT, cmd + "healthModifier DEFAULT", "action.default"),
getToggleField(entry.getHealthModifier() == MobValueModifier.MULTIPLY, cmd + "healthModifier MULTIPLY", "action.multiply"),
getToggleField(entry.getHealthModifier() == MobValueModifier.VALUE, cmd + "healthModifier VALUE", "action.value"),
escape("field.health"), healthModifier, changeButton(cmd + "health "),
changeableValueWithInput("field.health", healthModifier, cmd + "health "),
getToggleField(entry.getDamageModifier() == MobValueModifier.DEFAULT, cmd + "damageModifier DEFAULT", localizer().getMessage("action.default")),
getToggleField(entry.getDamageModifier() == MobValueModifier.MULTIPLY, cmd + "damageModifier MULTIPLY", "action.multiply"),
getToggleField(entry.getDamageModifier() == MobValueModifier.VALUE, cmd + "damageModifier VALUE", "action.value"),
escape("field.damage"), healthModifier, changeButton(cmd + "damage ")
changeableValueWithInput("field.damage", healthModifier, cmd + "damage ")
);
},
"manageMob.title",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import java.util.stream.Collectors;

import static de.eldoria.bloodnight.command.util.CommandUtil.changeButton;
import static de.eldoria.bloodnight.command.util.CommandUtil.changeableValue;
import static de.eldoria.bloodnight.command.util.CommandUtil.changeableValueWithInput;
import static de.eldoria.bloodnight.command.util.CommandUtil.getBooleanField;
import static de.eldoria.bloodnight.command.util.CommandUtil.getHeader;
import static de.eldoria.bloodnight.command.util.CommandUtil.getToggleField;
Expand Down Expand Up @@ -222,7 +222,7 @@ private void sendInfo(CommandSender sender, WorldSettings worldSettings) {
MobSettings mSet = worldSettings.getMobSettings();
VanillaMobSettings vms = worldSettings.getMobSettings().getVanillaMobSettings();
String cmd = "/bloodnight manageMobs " + ArgumentUtils.escapeWorldName(worldSettings.getWorldName()) + " ";
var notVanilla = changeableValue("field.customDropAmount", vms.getExtraDrops() + "x", cmd + "vanillaDropAmount ");
var notVanilla = changeableValueWithInput("field.customDropAmount", vms.getExtraDrops() + "x", cmd + "vanillaDropAmount ");

var a = """
%s
Expand All @@ -244,15 +244,15 @@ private void sendInfo(CommandSender sender, WorldSettings worldSettings) {
.formatted(
getHeader("manageMobs.title"),
// spawn percentage
changeableValue("field.spawnPercentage", mSet.getSpawnPercentage() + "%", cmd + "spawnPercentage "),
changeableValueWithInput("field.spawnPercentage", mSet.getSpawnPercentage() + "%", cmd + "spawnPercentage "),
// Display mobNamens
getBooleanField(mSet.isDisplayMobNames(), cmd + "displayName {bool}", "field.showMobNames", "state.enabled", "state.disabled"),
// Monster damage
changeableValue("field.monsterDamage", mSet.getDamageMultiplier() + "x", cmd + "monsterDamage "),
changeableValueWithInput("field.monsterDamage", mSet.getDamageMultiplier() + "x", cmd + "monsterDamage "),
// Player damage
changeableValue("field.monsterHealth", mSet.getHealthModifier() + "x", cmd + "monsterHealth "),
changeableValueWithInput("field.monsterHealth", mSet.getHealthModifier() + "x", cmd + "monsterHealth "),
// experience multiply
changeableValue("field.experienceMultiplier", mSet.getExperienceMultiplier() + "x", cmd + "experience "),
changeableValueWithInput("field.experienceMultiplier", mSet.getExperienceMultiplier() + "x", cmd + "experience "),
// force phantoms
getBooleanField(mSet.isForcePhantoms(), cmd + "forcePhantoms {bool}", "field.forcePhantoms", "state.enabled", "state.disabled"),
// natural drops
Expand All @@ -263,15 +263,15 @@ private void sendInfo(CommandSender sender, WorldSettings worldSettings) {
changeButton(cmd + "defaultDrops changeWeight", "action.weight", "weight"),
changeButton(cmd + "defaultDrops clear", "action.clear", "delete"),
// default drop amount
changeableValue("field.dropAmount", mSet.getDropAmount() + "x", cmd + "dropAmount "),
changeableValueWithInput("field.dropAmount", mSet.getDropAmount() + "x", cmd + "dropAmount "),
// Vanilla Mobs submenu
escape("field.vanillaMobs"),
// Monster damage
changeableValue("field.monsterDamage", vms.getDamageMultiplier() + "x", cmd + "vanillaMonsterDamage "),
changeableValueWithInput("field.monsterDamage", vms.getDamageMultiplier() + "x", cmd + "vanillaMonsterDamage "),
// Player damage
changeableValue("field.monsterHealth", vms.getHealthMultiplier() + "x", cmd + "vanillaMonsterHealth "),
changeableValueWithInput("field.monsterHealth", vms.getHealthMultiplier() + "x", cmd + "vanillaMonsterHealth "),
// drops
changeableValue("field.dropsMultiplier", vms.getDropMultiplier() + "x", cmd + "vanillaDropsMulti "),
changeableValueWithInput("field.dropsMultiplier", vms.getDropMultiplier() + "x", cmd + "vanillaDropsMulti "),
// Drop Mode
escape("field.dropMode"),
getToggleField(vms.getVanillaDropMode() == VanillaDropMode.VANILLA, cmd + "vanillaDropMode VANILLA", "state.vanilla"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.Collections;
import java.util.List;

import static de.eldoria.bloodnight.command.util.CommandUtil.changeableValue;
import static de.eldoria.bloodnight.command.util.CommandUtil.changeableValueWithInput;
import static de.eldoria.bloodnight.command.util.CommandUtil.getBooleanField;
import static de.eldoria.bloodnight.command.util.CommandUtil.getHeader;
import static de.eldoria.bloodnight.command.util.CommandUtil.getToggleField;
Expand Down Expand Up @@ -122,14 +122,14 @@ private void sendNightSettings(CommandSender sender, WorldSettings worldSettings
<value>> %s
<value>>""".stripIndent()
.formatted(
changeableValue("field.nightDuration", nightSettings.getNightDuration() + " " + escape("value.seconds"), cmd + "nightDuration ")
changeableValueWithInput("field.nightDuration", nightSettings.getNightDuration() + " " + escape("value.seconds"), cmd + "nightDuration ")
);
case RANGE -> """
<value>> %s
<value>> %s""".stripIndent()
.formatted(
changeableValue("field.minDuration", nightSettings.getNightDuration() + " " + escape("value.seconds"), cmd + "nightDuration "),
changeableValue("field.maxDuration", nightSettings.getMaxNightDuration() + " " + escape("value.seconds"), cmd + "maxNightDuration ")
changeableValueWithInput("field.minDuration", nightSettings.getNightDuration() + " " + escape("value.seconds"), cmd + "nightDuration "),
changeableValueWithInput("field.maxDuration", nightSettings.getMaxNightDuration() + " " + escape("value.seconds"), cmd + "maxNightDuration ")
);
};

Expand All @@ -149,9 +149,9 @@ private void sendNightSettings(CommandSender sender, WorldSettings worldSettings
// skippable
getBooleanField(nightSettings.isSkippable(), cmd + "skippable {bool}", "field.sleep", "state.allow", "state.deny"),
// night begin
changeableValue("field.nightBegin", nightSettings.getNightBegin(), cmd + "nightBegin "),
changeableValueWithInput("field.nightBegin", nightSettings.getNightBegin(), cmd + "nightBegin "),
// night end
changeableValue("field.nightEnd", nightSettings.getNightEnd(), cmd + "nightEnd "),
changeableValueWithInput("field.nightEnd", nightSettings.getNightEnd(), cmd + "nightEnd "),
// Night duration type
getToggleField(durationMode == NightSettings.NightDuration.NORMAL, cmd + "durationMode NORMAL", "state.normal"),
getToggleField(durationMode == NightSettings.NightDuration.EXTENDED, cmd + "durationMode EXTENDED", "state.extended"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import java.util.stream.Collectors;

import static de.eldoria.bloodnight.command.util.CommandUtil.changeButton;
import static de.eldoria.bloodnight.command.util.CommandUtil.changeableValue;
import static de.eldoria.bloodnight.command.util.CommandUtil.changeableValueWithInput;
import static de.eldoria.bloodnight.command.util.CommandUtil.getToggleField;
import static de.eldoria.bloodnight.config.worldsettings.NightSelection.NightSelectionType;
import static de.eldoria.bloodnight.config.worldsettings.NightSelection.NightSelectionType.CURVE;
Expand Down Expand Up @@ -97,6 +97,7 @@ private static String getMoonPhaseSign(int phase) {
default -> throw new IllegalStateException("Unexpected value: " + phase);
};
}

private static String getMoonPhaseSignLegacy(int phase) {
return switch (phase) {
case 0 -> "§f████";
Expand Down Expand Up @@ -226,7 +227,7 @@ private void sendWorldPage(World world, CommandSender sender, int p) {
""".stripIndent()
.formatted(changeableValue("field.probability", ns.getProbability(), cmd + "probability "));
.formatted(changeableValueWithInput("field.probability", ns.getProbability(), cmd + "probability "));
case REAL_MOON_PHASE, MOON_PHASE -> {
var phases = ns.getMoonPhase().entrySet().stream().map(e -> {
var hover = """
Expand Down Expand Up @@ -256,15 +257,15 @@ private void sendWorldPage(World world, CommandSender sender, int p) {
%s
""".stripIndent()
.formatted(
changeableValue("field.interval", ns.getInterval(), cmd + "interval "),
changeableValue("field.intervalProbability", ns.getIntervalProbability(), cmd + "intervalProbability ")
changeableValueWithInput("field.interval", ns.getInterval(), cmd + "interval "),
changeableValueWithInput("field.intervalProbability", ns.getIntervalProbability(), cmd + "intervalProbability ")
);
case PHASE -> """
%s
%s %s
""".stripIndent()
.formatted(
changeableValue("field.amount", ns.getPhaseCustom().size(), cmd + "phaseAmount "),
changeableValueWithInput("field.amount", ns.getPhaseCustom().size(), cmd + "phaseAmount "),
escape("field.amount"),
changeButton(cmd + "phase none ")
);
Expand All @@ -274,9 +275,9 @@ private void sendWorldPage(World world, CommandSender sender, int p) {
%s
""".stripIndent()
.formatted(
changeableValue("field.length", ns.getPeriod(), cmd + "period "),
changeableValue("field.minProb", ns.getMinCurveVal(), cmd + "minCurveVal "),
changeableValue("field.maxProb", ns.getMaxCurveVal(), cmd + "maxCurveVal ")
changeableValueWithInput("field.length", ns.getPeriod(), cmd + "period "),
changeableValueWithInput("field.minProb", ns.getMinCurveVal(), cmd + "minCurveVal "),
changeableValueWithInput("field.maxProb", ns.getMaxCurveVal(), cmd + "maxCurveVal ")
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,19 @@ public static String getBooleanField(boolean currValue, String cmd, String field
public static String changeButton(String command) {
return changeButton(command, "action.change", "change");
}
public static String changeButtonWithInput(String command) {
return changeButtonWithInput(command, "action.change", "change");
}

public static String changeButton(String command, String label, String color) {
return "<click:run_command:'%s'><%s>[%s]</click>".formatted(command, color, escape(label));
}
public static String changeButtonWithInput(String command, String label, String color) {
return "<click:suggest_command:'%s'><%s>[%s]</click>".formatted(command, color, escape(label));
}

public static String changeableValue(String field, Object value, String command) {
return "%s %s".formatted(value(field, value), changeButton(command));
public static String changeableValueWithInput(String field, Object value, String command) {
return "%s %s".formatted(value(field, value), changeButtonWithInput(command));
}

public static String value(String field, Object value) {
Expand Down
2 changes: 1 addition & 1 deletion BloodNight-core/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ state.phase6=First quarter
state.phase7=Waxing gibbous
state.random=Random
state.range=Range
state.realMoonPhase=Moon
state.realMoonPhase=Real Moon
state.vanilla=vanilla
syntax.commandPlayer=Please enter a command. Use {player} as playername placeholder
syntax.field=field
Expand Down

0 comments on commit fff643a

Please sign in to comment.