Impl in-game server config editing

This commit is contained in:
Stephen Seo 2022-06-10 12:05:19 +09:00
parent bfd584ad69
commit c094f9b690
3 changed files with 230 additions and 56 deletions

View file

@ -961,6 +961,73 @@ public class ClientProxy extends CommonProxy {
parent.append(sub); parent.append(sub);
} }
sub = new TextComponent("creeper_explode_turn ");
sub.setStyle(sub.getStyle()
.withColor(ChatFormatting.YELLOW)
.withBold(true)
.withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
new TextComponent("The number of turns it takes for a creeper to explode")
)));
parent.append(sub);
for (int i = 1; i <= 10; ++i) {
sub = new TextComponent(String.valueOf(i) + ' ');
sub.setStyle(sub.getStyle()
.withColor(ChatFormatting.GREEN)
.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND,
"/tbm-server-edit creeper_explode_turn " + i)));
parent.append(sub);
}
sub = new TextComponent("creeper_stop_explode_on_leave_battle ");
sub.setStyle(sub.getStyle()
.withColor(ChatFormatting.YELLOW)
.withBold(true)
.withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
new TextComponent("Stops creepers from exploding when they leave battle (during leave battle cooldown)")
)));
parent.append(sub);
sub = new TextComponent("true ");
sub.setStyle(sub.getStyle()
.withColor(ChatFormatting.GREEN)
.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND,
"/tbm-server-edit creeper_stop_explode_on_leave_battle true")));
parent.append(sub);
sub = new TextComponent("false ");
sub.setStyle(sub.getStyle()
.withColor(ChatFormatting.GREEN)
.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND,
"/tbm-server-edit creeper_stop_explode_on_leave_battle false")));
parent.append(sub);
sub = new TextComponent("creeper_always_allow_damage ");
sub.setStyle(sub.getStyle()
.withColor(ChatFormatting.YELLOW)
.withBold(true)
.withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
new TextComponent("Allows creepers to damage anyone who just left battle (in cooldown)")
)));
parent.append(sub);
sub = new TextComponent("true ");
sub.setStyle(sub.getStyle()
.withColor(ChatFormatting.GREEN)
.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND,
"/tbm-server-edit creeper_always_allow_damage true")));
parent.append(sub);
sub = new TextComponent("false ");
sub.setStyle(sub.getStyle()
.withColor(ChatFormatting.GREEN)
.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND,
"/tbm-server-edit creeper_always_allow_damage false")));
parent.append(sub);
TurnBasedMinecraftMod.proxy.displayComponent(parent); TurnBasedMinecraftMod.proxy.displayComponent(parent);
break; break;
} }

View file

@ -1410,7 +1410,24 @@ public class Config
public int getCreeperExplodeTurn() { return creeperExplodeTurn; } public int getCreeperExplodeTurn() { return creeperExplodeTurn; }
public void setCreeperExplodeTurn(int turns) {
if (turns < 1) {
turns = 1;
} else if (turns > 10) {
turns = 10;
}
creeperExplodeTurn = turns;
}
public boolean getCreeperStopExplodeOnLeaveBattle() { return creeperStopExplodeOnLeaveBattle; } public boolean getCreeperStopExplodeOnLeaveBattle() { return creeperStopExplodeOnLeaveBattle; }
public void setCreeperStopExplodeOnLeaveBattle(boolean stop_explode_on_leave_battle) {
creeperStopExplodeOnLeaveBattle = stop_explode_on_leave_battle;
}
public boolean getCreeperAlwaysAllowDamage() { return creeperAlwaysAllowDamage; } public boolean getCreeperAlwaysAllowDamage() { return creeperAlwaysAllowDamage; }
public void setCreeperAlwaysAllowDamage(boolean allow_damage) {
creeperAlwaysAllowDamage = allow_damage;
}
} }

View file

@ -1098,14 +1098,14 @@ public class TurnBasedMinecraftMod {
return 1; return 1;
}))) })))
.then(Commands.literal("player_haste_speed").executes(c -> { .then(Commands.literal("player_haste_speed").executes(c -> {
TextComponent parent = new TextComponent("Use "); TextComponent parent = new TextComponent("Use ");
TextComponent sub = new TextComponent("/tbm-server-edit player_haste_speed <0-100>"); TextComponent sub = new TextComponent("/tbm-server-edit player_haste_speed <0-100>");
sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW)); sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW));
parent.append(sub); parent.append(sub);
c.getSource().sendSuccess(parent, false); c.getSource().sendSuccess(parent, false);
return 1; return 1;
}) })
.then(Commands.argument("haste_speed", IntegerArgumentType.integer()).executes(c -> { .then(Commands.argument("haste_speed", IntegerArgumentType.integer()).executes(c -> {
int haste_speed = IntegerArgumentType.getInteger(c, "haste_speed"); int haste_speed = IntegerArgumentType.getInteger(c, "haste_speed");
// setPlayerHasteSpeed() in Config validates the value. Set it, then fetch it again. // setPlayerHasteSpeed() in Config validates the value. Set it, then fetch it again.
@ -1128,14 +1128,14 @@ public class TurnBasedMinecraftMod {
return 1; return 1;
}))) })))
.then(Commands.literal("player_slow_speed").executes(c -> { .then(Commands.literal("player_slow_speed").executes(c -> {
TextComponent parent = new TextComponent("Use "); TextComponent parent = new TextComponent("Use ");
TextComponent sub = new TextComponent("/tbm-server-edit player_slow_speed <0-100>"); TextComponent sub = new TextComponent("/tbm-server-edit player_slow_speed <0-100>");
sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW)); sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW));
parent.append(sub); parent.append(sub);
c.getSource().sendSuccess(parent, false); c.getSource().sendSuccess(parent, false);
return 1; return 1;
}) })
.then(Commands.argument("slow_speed", IntegerArgumentType.integer()).executes(c -> { .then(Commands.argument("slow_speed", IntegerArgumentType.integer()).executes(c -> {
int slow_speed = IntegerArgumentType.getInteger(c, "slow_speed"); int slow_speed = IntegerArgumentType.getInteger(c, "slow_speed");
// setPlayerSlowSpeed() in Config validates the value. Set it, then fetch it again. // setPlayerSlowSpeed() in Config validates the value. Set it, then fetch it again.
@ -1158,14 +1158,14 @@ public class TurnBasedMinecraftMod {
return 1; return 1;
}))) })))
.then(Commands.literal("player_attack_probability").executes(c -> { .then(Commands.literal("player_attack_probability").executes(c -> {
TextComponent parent = new TextComponent("Use "); TextComponent parent = new TextComponent("Use ");
TextComponent sub = new TextComponent("/tbm-server-edit player_attack_probability <1-100>"); TextComponent sub = new TextComponent("/tbm-server-edit player_attack_probability <1-100>");
sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW)); sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW));
parent.append(sub); parent.append(sub);
c.getSource().sendSuccess(parent, false); c.getSource().sendSuccess(parent, false);
return 1; return 1;
}) })
.then(Commands.argument("probability", IntegerArgumentType.integer()).executes(c -> { .then(Commands.argument("probability", IntegerArgumentType.integer()).executes(c -> {
int probability = IntegerArgumentType.getInteger(c, "probability"); int probability = IntegerArgumentType.getInteger(c, "probability");
// setPlayerAttackProbability() in Config validates the value. Set it, then fetch it again. // setPlayerAttackProbability() in Config validates the value. Set it, then fetch it again.
@ -1188,14 +1188,14 @@ public class TurnBasedMinecraftMod {
return 1; return 1;
}))) })))
.then(Commands.literal("player_evasion").executes(c -> { .then(Commands.literal("player_evasion").executes(c -> {
TextComponent parent = new TextComponent("Use "); TextComponent parent = new TextComponent("Use ");
TextComponent sub = new TextComponent("/tbm-server-edit player_evasion <0-100>"); TextComponent sub = new TextComponent("/tbm-server-edit player_evasion <0-100>");
sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW)); sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW));
parent.append(sub); parent.append(sub);
c.getSource().sendSuccess(parent, false); c.getSource().sendSuccess(parent, false);
return 1; return 1;
}) })
.then(Commands.argument("evasion", IntegerArgumentType.integer()).executes(c -> { .then(Commands.argument("evasion", IntegerArgumentType.integer()).executes(c -> {
int evasion = IntegerArgumentType.getInteger(c, "evasion"); int evasion = IntegerArgumentType.getInteger(c, "evasion");
// setPlayerEvasion() in Config validates the value. Set it, then fetch it again. // setPlayerEvasion() in Config validates the value. Set it, then fetch it again.
@ -1218,14 +1218,14 @@ public class TurnBasedMinecraftMod {
return 1; return 1;
}))) })))
.then(Commands.literal("defense_duration").executes(c -> { .then(Commands.literal("defense_duration").executes(c -> {
TextComponent parent = new TextComponent("Use "); TextComponent parent = new TextComponent("Use ");
TextComponent sub = new TextComponent("/tbm-server-edit defense_duration <0-5>"); TextComponent sub = new TextComponent("/tbm-server-edit defense_duration <0-5>");
sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW)); sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW));
parent.append(sub); parent.append(sub);
c.getSource().sendSuccess(parent, false); c.getSource().sendSuccess(parent, false);
return 1; return 1;
}) })
.then(Commands.argument("defends", IntegerArgumentType.integer()).executes(c -> { .then(Commands.argument("defends", IntegerArgumentType.integer()).executes(c -> {
int defends = IntegerArgumentType.getInteger(c, "defends"); int defends = IntegerArgumentType.getInteger(c, "defends");
// setDefenseDuration() in Config validates the value. Set it, then fetch it again. // setDefenseDuration() in Config validates the value. Set it, then fetch it again.
@ -1248,14 +1248,14 @@ public class TurnBasedMinecraftMod {
return 1; return 1;
}))) })))
.then(Commands.literal("flee_good_probability").executes(c -> { .then(Commands.literal("flee_good_probability").executes(c -> {
TextComponent parent = new TextComponent("Use "); TextComponent parent = new TextComponent("Use ");
TextComponent sub = new TextComponent("/tbm-server-edit flee_good_probability <1-100>"); TextComponent sub = new TextComponent("/tbm-server-edit flee_good_probability <1-100>");
sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW)); sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW));
parent.append(sub); parent.append(sub);
c.getSource().sendSuccess(parent, false); c.getSource().sendSuccess(parent, false);
return 1; return 1;
}) })
.then(Commands.argument("probability", IntegerArgumentType.integer()).executes(c -> { .then(Commands.argument("probability", IntegerArgumentType.integer()).executes(c -> {
int probability = IntegerArgumentType.getInteger(c, "probability"); int probability = IntegerArgumentType.getInteger(c, "probability");
// setFleeGoodProbability() in Config validates the value. Set it, then fetch it again. // setFleeGoodProbability() in Config validates the value. Set it, then fetch it again.
@ -1308,14 +1308,14 @@ public class TurnBasedMinecraftMod {
return 1; return 1;
}))) })))
.then(Commands.literal("minimum_hit_percentage").executes(c -> { .then(Commands.literal("minimum_hit_percentage").executes(c -> {
TextComponent parent = new TextComponent("Use "); TextComponent parent = new TextComponent("Use ");
TextComponent sub = new TextComponent("/tbm-server-edit minimum_hit_percentage <1-100>"); TextComponent sub = new TextComponent("/tbm-server-edit minimum_hit_percentage <1-100>");
sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW)); sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW));
parent.append(sub); parent.append(sub);
c.getSource().sendSuccess(parent, false); c.getSource().sendSuccess(parent, false);
return 1; return 1;
}) })
.then(Commands.argument("percentage", IntegerArgumentType.integer()).executes(c -> { .then(Commands.argument("percentage", IntegerArgumentType.integer()).executes(c -> {
int percentage = IntegerArgumentType.getInteger(c, "percentage"); int percentage = IntegerArgumentType.getInteger(c, "percentage");
// setMinimumHitPercentage() in Config validates the value. Set it, then fetch it again. // setMinimumHitPercentage() in Config validates the value. Set it, then fetch it again.
@ -1338,14 +1338,14 @@ public class TurnBasedMinecraftMod {
return 1; return 1;
}))) })))
.then(Commands.literal("battle_turn_time_seconds").executes(c -> { .then(Commands.literal("battle_turn_time_seconds").executes(c -> {
TextComponent parent = new TextComponent("Use "); TextComponent parent = new TextComponent("Use ");
TextComponent sub = new TextComponent("/tbm-server-edit battle_turn_time_seconds <5-60>"); TextComponent sub = new TextComponent("/tbm-server-edit battle_turn_time_seconds <5-60>");
sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW)); sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW));
parent.append(sub); parent.append(sub);
c.getSource().sendSuccess(parent, false); c.getSource().sendSuccess(parent, false);
return 1; return 1;
}) })
.then(Commands.argument("seconds", IntegerArgumentType.integer()).executes(c -> { .then(Commands.argument("seconds", IntegerArgumentType.integer()).executes(c -> {
int seconds = IntegerArgumentType.getInteger(c, "seconds"); int seconds = IntegerArgumentType.getInteger(c, "seconds");
// setDecisionDurationSeconds() in Config validates the value. Set it, then fetch it again. // setDecisionDurationSeconds() in Config validates the value. Set it, then fetch it again.
@ -1367,6 +1367,96 @@ public class TurnBasedMinecraftMod {
} }
return 1; return 1;
}))) })))
.then(Commands.literal("creeper_explode_turn").executes(c -> {
TextComponent parent = new TextComponent("Use ");
TextComponent sub = new TextComponent("/tbm-server-edit creeper_explode_turn <1-10>");
sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW));
parent.append(sub);
c.getSource().sendSuccess(parent, false);
return 1;
})
.then(Commands.argument("turns", IntegerArgumentType.integer()).executes(c -> {
int turns = IntegerArgumentType.getInteger(c, "turns");
// setCreeperExplodeTurn() in Config validates the value. Set it, then fetch it again.
TurnBasedMinecraftMod.proxy.getConfig().setCreeperExplodeTurn(turns);
turns = TurnBasedMinecraftMod.proxy.getConfig().getCreeperExplodeTurn();
if (!TurnBasedMinecraftMod.proxy.getConfig().updateConfig("server_config.creeper_explode_turn", turns)) {
TurnBasedMinecraftMod.logger.warn(
"Failed to set \"server_config.creeper_explode_turn\" in config file!");
c.getSource().sendFailure(new TextComponent(
"Failed to set creeper_explode_turn to \""
+ turns
+ "\" in config file!"));
} else {
TextComponent response = new TextComponent("Successfully set creeper_explode_turn to: ");
TextComponent subResponse = new TextComponent(String.valueOf(turns));
subResponse.setStyle(subResponse.getStyle().withColor(ChatFormatting.GREEN));
response.append(subResponse);
c.getSource().sendSuccess(response, true);
}
return 1;
})))
.then(Commands.literal("creeper_stop_explode_on_leave_battle").executes(c -> {
TextComponent parent = new TextComponent("Use ");
TextComponent sub = new TextComponent("/tbm-server-edit creeper_stop_explode_on_leave_battle <true/false>");
sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW));
parent.append(sub);
c.getSource().sendSuccess(parent, false);
return 1;
})
.then(Commands.argument("stop_explode_on_leave", BoolArgumentType.bool()).executes(c -> {
boolean stop_explode_on_leave = BoolArgumentType.getBool(c, "stop_explode_on_leave");
TurnBasedMinecraftMod.proxy.getConfig().setCreeperStopExplodeOnLeaveBattle(stop_explode_on_leave);
if (!TurnBasedMinecraftMod.proxy.getConfig().updateConfig("server_config.creeper_stop_explode_on_leave_battle", stop_explode_on_leave)) {
TurnBasedMinecraftMod.logger.warn(
"Failed to set \"server_config.creeper_stop_explode_on_leave_battle\" in config file!"
);
c.getSource().sendFailure(new TextComponent(
"Failed to set creeper_stop_explode_on_leave_battle to \""
+ stop_explode_on_leave
+ "\" in config file!"
));
} else {
TextComponent response = new TextComponent("Successfully set creeper_stop_explode_on_leave_battle to: ");
TextComponent subResponse = new TextComponent(String.valueOf(stop_explode_on_leave));
subResponse.setStyle(subResponse.getStyle().withColor(ChatFormatting.GREEN));
response.append(subResponse);
c.getSource().sendSuccess(response, true);
}
return 1;
})))
.then(Commands.literal("creeper_always_allow_damage").executes(c -> {
TextComponent parent = new TextComponent("Use ");
TextComponent sub = new TextComponent("/tbm-server-edit creeper_always_allow_damage <true/false>");
sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW));
parent.append(sub);
c.getSource().sendSuccess(parent, false);
return 1;
})
.then(Commands.argument("allow_damage", BoolArgumentType.bool()).executes(c -> {
boolean allow_damage = BoolArgumentType.getBool(c, "allow_damage");
TurnBasedMinecraftMod.proxy.getConfig().setCreeperAlwaysAllowDamage(allow_damage);
if (!TurnBasedMinecraftMod.proxy.getConfig().updateConfig("server_config.creeper_always_allow_damage", allow_damage)) {
TurnBasedMinecraftMod.logger.warn(
"Failed to set \"server_config.creeper_always_allow_damage\" in config file!"
);
c.getSource().sendFailure(new TextComponent(
"Failed to set creeper_always_allow_damage to \""
+ allow_damage
+ "\" in config file!"
));
} else {
TextComponent response = new TextComponent("Successfully set creeper_always_allow_damage to: ");
TextComponent subResponse = new TextComponent(String.valueOf(allow_damage));
subResponse.setStyle(subResponse.getStyle().withColor(ChatFormatting.GREEN));
response.append(subResponse);
c.getSource().sendSuccess(response, true);
}
return 1;
})))
); );
} }