TurnBasedMinecraftMod.proxy.displayComponent(parentComponent);
break;
}
+ case SERVER_EDIT:
+ {
+ TextComponent parent = new TextComponent("Edit what server value? ");
+ parent.setStyle(parent.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF)).withBold(false));
+
+ TextComponent sub = new TextComponent("leave_battle_cooldown ");
+ sub.setStyle(sub.getStyle().withColor(0xFFFFFF00));
+
+ for (int i = 1; i <= 10; ++i) {
+ TextComponent value = new TextComponent(String.valueOf(i) + ' ');
+ value.setStyle(
+ value.getStyle()
+ .withColor(0xFF00FF00)
+ .withClickEvent(new ClickEvent(
+ ClickEvent.Action.RUN_COMMAND,
+ "/tbm-server-edit leave_battle_cooldown " + i)));
+ sub.append(value);
+ }
+
+ parent.append(sub);
+
+ sub = new TextComponent("aggro_start_battle_max_distance ");
+ sub.setStyle(sub.getStyle().withColor(0xFFFFFF00));
+ parent.append(sub);
+
+ sub = new TextComponent("5 ");
+ sub.setStyle(
+ sub.getStyle()
+ .withColor(0xFF00FF00)
+ .withClickEvent(new ClickEvent(
+ ClickEvent.Action.RUN_COMMAND,
+ "/tbm-server-edit aggro_start_battle_max_distance 5")));
+ parent.append(sub);
+
+ sub = new TextComponent("8 ");
+ sub.setStyle(
+ sub.getStyle()
+ .withColor(0xFF00FF00)
+ .withClickEvent(new ClickEvent(
+ ClickEvent.Action.RUN_COMMAND,
+ "/tbm-server-edit aggro_start_battle_max_distance 8")));
+ parent.append(sub);
+
+ for (int i = 10; i <= 50; i += 5) {
+ sub = new TextComponent(String.valueOf(i) + ' ');
+ sub.setStyle(
+ sub.getStyle()
+ .withColor(0xFF00FF00)
+ .withClickEvent(new ClickEvent(
+ ClickEvent.Action.RUN_COMMAND,
+ "/tbm-server-edit aggro_start_battle_max_distance " + String.valueOf(i))));
+ parent.append(sub);
+ }
+
+ sub = new TextComponent("old_battle_behavior ");
+ sub.setStyle(sub.getStyle()
+ .withColor(0xFFFFFF00)
+ .withHoverEvent(new HoverEvent(
+ HoverEvent.Action.SHOW_TEXT,
+ new TextComponent("If enabled, battles only start on a hit, not including mobs targeting players"))));
+ parent.append(sub);
+
+ sub = new TextComponent("true ");
+ sub.setStyle(
+ sub.getStyle()
+ .withColor(0xFF00FF00)
+ .withClickEvent(new ClickEvent(
+ ClickEvent.Action.RUN_COMMAND,
+ "/tbm-server-edit old_battle_behavior true")));
+ parent.append(sub);
+
+ sub = new TextComponent("false ");
+ sub.setStyle(
+ sub.getStyle()
+ .withColor(0xFF00FF00)
+ .withClickEvent(new ClickEvent(
+ ClickEvent.Action.RUN_COMMAND,
+ "/tbm-server-edit old_battle_behavior false")));
+ parent.append(sub);
+
+ sub = new TextComponent("anyone_can_disable_tbm_for_self ");
+ sub.setStyle(sub.getStyle()
+ .withColor(0xFFFFFF00)
+ .withHoverEvent(new HoverEvent(
+ HoverEvent.Action.SHOW_TEXT,
+ new TextComponent("Allows use for /tbm-disable and /tbm-enable for all"))));
+ parent.append(sub);
+
+ sub = new TextComponent("true ");
+ sub.setStyle(
+ sub.getStyle()
+ .withColor(0xFF00FF00)
+ .withClickEvent(new ClickEvent(
+ ClickEvent.Action.RUN_COMMAND,
+ "/tbm-server-edit anyone_can_disable_tbm_for_self true")));
+ parent.append(sub);
+
+ sub = new TextComponent("false ");
+ sub.setStyle(
+ sub.getStyle()
+ .withColor(0xFF00FF00)
+ .withClickEvent(new ClickEvent(
+ ClickEvent.Action.RUN_COMMAND,
+ "/tbm-server-edit anyone_can_disable_tbm_for_self false")));
+ parent.append(sub);
+
+ sub = new TextComponent("max_in_battle ");
+ sub.setStyle(sub.getStyle().withColor(0xFFFFFF00));
+ parent.append(sub);
+
+ sub = new TextComponent("2 ");
+ sub.setStyle(sub.getStyle()
+ .withColor(0xFF00FF00)
+ .withClickEvent(new ClickEvent(
+ ClickEvent.Action.RUN_COMMAND,
+ "/tbm-server-edit max_in_battle 2")));
+ parent.append(sub);
+
+ for (int i = 5; i < 30; i += 5) {
+ sub = new TextComponent(String.valueOf(i) + ' ');
+ sub.setStyle(sub.getStyle()
+ .withColor(0xFF00FF00)
+ .withClickEvent(new ClickEvent(
+ ClickEvent.Action.RUN_COMMAND,
+ "/tbm-server-edit max_in_battle " + String.valueOf(i))));
+ parent.append(sub);
+ }
+
+ sub = new TextComponent("freeze_battle_combatants ");
+ sub.setStyle(sub.getStyle().withColor(0xFFFFFF00));
+ parent.append(sub);
+
+ sub = new TextComponent("true ");
+ sub.setStyle(sub.getStyle()
+ .withColor(0xFF00FF00)
+ .withClickEvent(new ClickEvent(
+ ClickEvent.Action.RUN_COMMAND,
+ "/tbm-server-edit freeze_battle_combatants true"
+ )));
+ parent.append(sub);
+
+ sub = new TextComponent("false ");
+ sub.setStyle(sub.getStyle()
+ .withColor(0xFF00FF00)
+ .withClickEvent(new ClickEvent(
+ ClickEvent.Action.RUN_COMMAND,
+ "/tbm-server-edit freeze_battle_combatants false"
+ )));
+ parent.append(sub);
+
+ TurnBasedMinecraftMod.proxy.displayComponent(parent);
+ break;
+ }
case EDIT_IGNORE_BATTLE:
{
TextComponent text = new TextComponent("ignoreBattle: ");
private boolean parseConfig(File configFile) throws IOException
{
- CommentedFileConfig conf = CommentedFileConfig
- .builder(configFile)
- .defaultResource(TurnBasedMinecraftMod.DEFAULT_CONFIG_FILE_PATH)
- .build();
- conf.load();
+ CommentedFileConfig conf = getConfigObj(configFile);
// client config
try {
return canOverwrite;
}
+ private CommentedFileConfig getConfigObj(File configFile) {
+ CommentedFileConfig conf = CommentedFileConfig
+ .builder(configFile)
+ .defaultResource(TurnBasedMinecraftMod.DEFAULT_CONFIG_FILE_PATH)
+ .build();
+ conf.load();
+
+ return conf;
+ }
+
+ public boolean updateConfig(String path, Object value) {
+ File configFile = new File(TurnBasedMinecraftMod.CONFIG_FILE_PATH);
+ CommentedFileConfig conf = getConfigObj(configFile);
+
+ conf.set(path, value);
+ conf.save();
+ conf.close();
+
+ return true;
+ }
+
public boolean isIgnoreBattleType(String type)
{
return ignoreBattleTypes.contains(type);
return maxInBattle;
}
+ public void setMaxInBattle(int maxInBattle) {
+ if (maxInBattle < 2) {
+ maxInBattle = 2;
+ } else if (maxInBattle > 30) {
+ maxInBattle = 30;
+ }
+ this.maxInBattle = maxInBattle;
+ }
+
public boolean isBattleMusicType(String type)
{
return musicBattleTypes.contains(type.toLowerCase());
return freezeCombatantsInBattle;
}
+ public void setFreezeCombatantsInBattle(boolean enabled) {
+ freezeCombatantsInBattle = enabled;
+ }
+
public int getSillyMusicThreshold()
{
return sillyMusicThreshold;
return onlyOPsSelfDisableTB;
}
+ public void setIfOnlyOPsCanDisableTurnBasedForSelf(boolean enabled_for_only_ops) {
+ onlyOPsSelfDisableTB = enabled_for_only_ops;
+ }
+
protected void setBattleDisabledForAll(boolean isDisabled)
{
battleDisabledForAll = isDisabled;
return oldBattleBehaviorEnabled;
}
+ public void setOldBattleBehavior(boolean enabled) {
+ oldBattleBehaviorEnabled = enabled;
+ }
+
public int getLeaveBattleCooldownSeconds()
{
return leaveBattleCooldownSeconds;
}
+ public void setLeaveBattleCooldownSeconds(int seconds) {
+ if (seconds < 1) {
+ seconds = 1;
+ } else if (seconds > 10) {
+ seconds = 10;
+ }
+ leaveBattleCooldownSeconds = seconds;
+ }
+
public long getLeaveBattleCooldownNanos()
{
return (long)leaveBattleCooldownSeconds * 1000000000L;
return aggroStartBattleDistance;
}
+ public void setAggroStartBattleDistance(int distance) {
+ if (distance < 5) {
+ distance = 5;
+ } else if (distance > 50) {
+ distance = 50;
+ }
+ aggroStartBattleDistance = distance;
+ }
+
public int getCreeperExplodeTurn() { return creeperExplodeTurn; }
public boolean getCreeperStopExplodeOnLeaveBattle() { return creeperStopExplodeOnLeaveBattle; }
public class TurnBasedMinecraftMod {
public static final String MODID = "com_burnedkirby_turnbasedminecraft";
public static final String NAME = "Turn Based Minecraft Mod";
- public static final String VERSION = "1.18.2";
+ public static final String VERSION = "1.18.3";
public static final String CONFIG_FILENAME = "TBM_Config.toml";
public static final String DEFAULT_CONFIG_FILENAME = "TBM_Config_DEFAULT.toml";
public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/";
)
)
);
+ // tbm-server-edit
+ event.getDispatcher().register(
+ Commands.literal("tbm-server-edit")
+ .requires(c -> c.hasPermission(2))
+ .executes(c -> {
+ ServerPlayer player = c.getSource().getPlayerOrException();
+ getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.SERVER_EDIT));
+ return 1;
+ })
+ .then(Commands.literal("leave_battle_cooldown").executes(c -> {
+ TextComponent response = new TextComponent("leave_battle_cooldown requires an integer argument. ");
+ TextComponent subResponse = new TextComponent("leave_battle_cooldown is currently: ");
+ response.append(subResponse);
+ subResponse = new TextComponent(String.valueOf(TurnBasedMinecraftMod.proxy.getConfig().getLeaveBattleCooldownSeconds()));
+ subResponse.setStyle(subResponse.getStyle().withColor(0xFF00FF00));
+ response.append(subResponse);
+ c.getSource().sendSuccess(response, false);
+ return 1;
+ })
+ .then(Commands.argument("cooldown_seconds", IntegerArgumentType.integer())
+ .executes(c -> {
+ int cooldown = IntegerArgumentType.getInteger(c, "cooldown_seconds");
+ // setting cooldown validates the value. Set it, then fetch it again.
+ TurnBasedMinecraftMod.proxy.getConfig().setLeaveBattleCooldownSeconds(cooldown);
+ cooldown = TurnBasedMinecraftMod.proxy.getConfig().getLeaveBattleCooldownSeconds();
+ if (!TurnBasedMinecraftMod.proxy.getConfig().updateConfig(
+ "server_config.leave_battle_cooldown",
+ cooldown)) {
+ TurnBasedMinecraftMod.logger.warn(
+ "Failed to set \"server_config.leave_battle_cooldown\" in config file!");
+ c.getSource().sendFailure(new TextComponent("" +
+ "Failed to set leave_battle_cooldown to \""
+ + cooldown
+ + "\" in config file!"));
+ } else {
+ TextComponent response = new TextComponent("Successfully set leave_battle_cooldown to: ");
+ TextComponent subResponse = new TextComponent(String.valueOf(cooldown));
+ subResponse.setStyle(subResponse.getStyle().withColor(0xFF00FF00));
+ response.append(subResponse);
+ c.getSource().sendSuccess(response, true);
+ }
+ return 1;
+ })))
+ .then(Commands.literal("aggro_start_battle_max_distance").executes(c -> {
+ TextComponent response = new TextComponent("aggro_start_battle_max_distance requires an integer argument. ");
+ TextComponent subResponse = new TextComponent("aggro_start_battle_max_distance is currently: ");
+ response.append(subResponse);
+ subResponse = new TextComponent(String.valueOf(
+ TurnBasedMinecraftMod.proxy.getConfig().getAggroStartBattleDistance()));
+ subResponse.setStyle(subResponse.getStyle().withColor(0xFF00FF00));
+ response.append(subResponse);
+ c.getSource().sendSuccess(response, false);
+ return 1;
+ })
+ .then(Commands.argument("aggro_distance", IntegerArgumentType.integer())
+ .executes(c -> {
+ int distance = IntegerArgumentType.getInteger(c, "aggro_distance");
+ // setDistance in Config validates the value. Set it, then fetch it again.
+ TurnBasedMinecraftMod.proxy.getConfig().setAggroStartBattleDistance(distance);
+ distance = TurnBasedMinecraftMod.proxy.getConfig().getAggroStartBattleDistance();
+ if (!TurnBasedMinecraftMod.proxy.getConfig().updateConfig(
+ "server_config.aggro_start_battle_max_distance",
+ distance)) {
+ TurnBasedMinecraftMod.logger.warn(
+ "Failed to set \"server_config.aggro_start_battle_max_distance\" in config file!");
+ c.getSource().sendFailure(new TextComponent(
+ "Failed to set aggro_start_battle_max_distance to \""
+ + distance
+ + "\" in config file!"));
+ } else {
+ TextComponent response = new TextComponent("Successfully set aggro_start_battle_max_distance to: ");
+ TextComponent subResponse = new TextComponent(String.valueOf(distance));
+ subResponse.setStyle(subResponse.getStyle().withColor(0xFF00FF00));
+ response.append(subResponse);
+ c.getSource().sendSuccess(response, true);
+ }
+ return 1;
+ })))
+ .then(Commands.literal("old_battle_behavior").executes(c -> {
+ TextComponent response = new TextComponent("old_battle_behavior requires a boolean argument. ");
+ TextComponent subResponse = new TextComponent("old_battle_behavior is currently: ");
+ response.append(subResponse);
+ subResponse = new TextComponent(String.valueOf(
+ TurnBasedMinecraftMod.proxy.getConfig().isOldBattleBehaviorEnabled()));
+ subResponse.setStyle(subResponse.getStyle().withColor(0xFF00FF00));
+ response.append(subResponse);
+ c.getSource().sendSuccess(response, false);
+ return 1;
+ })
+ .then(Commands.argument("old_battle_behavior_enabled", BoolArgumentType.bool())
+ .executes(c -> {
+ boolean enabled = BoolArgumentType.getBool(c, "old_battle_behavior_enabled");
+ TurnBasedMinecraftMod.proxy.getConfig().setOldBattleBehavior(enabled);
+ if (!TurnBasedMinecraftMod.proxy.getConfig().updateConfig(
+ "server_config.old_battle_behavior",
+ enabled)) {
+ TurnBasedMinecraftMod.logger.warn(
+ "Failed to set \"server_config.old_battle_behavior\" in config file!");
+ c.getSource().sendFailure(new TextComponent(
+ "Failed to set old_battle_behavior to \""
+ + enabled
+ + "\" in config file!"));
+ } else {
+ TextComponent response = new TextComponent("Successfully set old_battle_behavior to: ");
+ TextComponent subResponse = new TextComponent(String.valueOf(enabled));
+ subResponse.setStyle(subResponse.getStyle().withColor(0xFF00FF00));
+ response.append(subResponse);
+ c.getSource().sendSuccess(response, true);
+ }
+ return 1;
+ })))
+ .then(Commands.literal("anyone_can_disable_tbm_for_self").executes(c -> {
+ TextComponent response = new TextComponent("anyone_can_disable_tbm_for_self requires a boolean argument. ");
+ TextComponent subResponse = new TextComponent("anyone_can_disable_tbm_for_self is currently: ");
+ response.append(subResponse);
+ subResponse = new TextComponent(String.valueOf(
+ !TurnBasedMinecraftMod.proxy.getConfig().getIfOnlyOPsCanDisableTurnBasedForSelf()));
+ subResponse.setStyle(subResponse.getStyle().withColor(0xFF00FF00));
+ response.append(subResponse);
+ c.getSource().sendSuccess(response, false);
+ return 1;
+ })
+ .then(Commands.argument("enabled_for_all", BoolArgumentType.bool())
+ .executes(c -> {
+ boolean enabled_for_all = BoolArgumentType.getBool(c, "enabled_for_all");
+ TurnBasedMinecraftMod.proxy.getConfig().setIfOnlyOPsCanDisableTurnBasedForSelf(!enabled_for_all);
+ if (!TurnBasedMinecraftMod.proxy.getConfig().updateConfig(
+ "server_config.anyone_can_disable_tbm_for_self",
+ enabled_for_all
+ )) {
+ TurnBasedMinecraftMod.logger.warn(
+ "Failed to set \"server_config.anyone_can_disable_tbm_for_self\" in config file!");
+ c.getSource().sendFailure(new TextComponent(
+ "Failed to set anyone_can_disable_tbm_for_self to \""
+ + enabled_for_all
+ + "\" in config file!"));
+ } else {
+ TextComponent response = new TextComponent("Successfully set anyone_can_disable_tbm_for_self to: ");
+ TextComponent subResponse = new TextComponent(String.valueOf(enabled_for_all));
+ subResponse.setStyle(subResponse.getStyle().withColor(0xFF00FF00));
+ response.append(subResponse);
+ c.getSource().sendSuccess(response, true);
+ }
+ return 1;
+ })))
+ .then(Commands.literal("max_in_battle").executes(c -> {
+ TextComponent response = new TextComponent("max_in_battle requires an integer argument. ");
+ TextComponent subResponse = new TextComponent("max_in_battle is currently: ");
+ response.append(subResponse);
+ subResponse = new TextComponent(String.valueOf(
+ TurnBasedMinecraftMod.proxy.getConfig().getMaxInBattle()));
+ subResponse.setStyle(subResponse.getStyle().withColor(0xFF00FF00));
+ response.append(subResponse);
+ c.getSource().sendSuccess(response, false);
+ return 1;
+ })
+ .then(Commands.argument("max_amount", IntegerArgumentType.integer())
+ .executes(c -> {
+ int max_amount = IntegerArgumentType.getInteger(c, "max_amount");
+ // setMaxInBattle in Config validates the value. Set it, then fetch it again.
+ TurnBasedMinecraftMod.proxy.getConfig().setMaxInBattle(max_amount);
+ max_amount = TurnBasedMinecraftMod.proxy.getConfig().getMaxInBattle();
+ if (!TurnBasedMinecraftMod.proxy.getConfig().updateConfig(
+ "server_config.max_in_battle",
+ max_amount)) {
+ TurnBasedMinecraftMod.logger.warn(
+ "Failed to set \"server_config.max_in_battle\" in config file!");
+ c.getSource().sendFailure(new TextComponent(
+ "Failed to set max_in_battle to \""
+ + max_amount
+ + "\" in config file!"));
+ } else {
+ TextComponent response = new TextComponent("Successfully set max_in_battle to: ");
+ TextComponent subResponse = new TextComponent(String.valueOf(max_amount));
+ subResponse.setStyle(subResponse.getStyle().withColor(0xFF00FF00));
+ response.append(subResponse);
+ c.getSource().sendSuccess(response, true);
+ }
+ return 1;
+ })))
+ .then(Commands.literal("freeze_battle_combatants").executes(c -> {
+ TextComponent response = new TextComponent("freeze_battle_combatants requires a boolean argument. ");
+ TextComponent subResponse = new TextComponent("freeze_battle_combatants is currently: ");
+ response.append(subResponse);
+ subResponse = new TextComponent(String.valueOf(
+ !TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled()));
+ subResponse.setStyle(subResponse.getStyle().withColor(0xFF00FF00));
+ response.append(subResponse);
+ c.getSource().sendSuccess(response, false);
+ return 1;
+ })
+ .then(Commands.argument("freeze_enabled", BoolArgumentType.bool())
+ .executes(c -> {
+ boolean enabled = BoolArgumentType.getBool(c, "freeze_enabled");
+ TurnBasedMinecraftMod.proxy.getConfig().setFreezeCombatantsInBattle(enabled);
+ if (!TurnBasedMinecraftMod.proxy.getConfig().updateConfig("server_config.freeze_battle_combatants", enabled)) {
+ TurnBasedMinecraftMod.logger.warn(
+ "Failed to set \"server_config.freeze_battle_combatants\" in config file!");
+ c.getSource().sendFailure(new TextComponent(
+ "Failed to set freeze_battle_combatants to \""
+ + enabled
+ + "\" in config file!"));
+ } else {
+ TextComponent response = new TextComponent("Successfully set freeze_battle_combatants to: ");
+ TextComponent subResponse = new TextComponent(String.valueOf(enabled));
+ subResponse.setStyle(subResponse.getStyle().withColor(0xFF00FF00));
+ response.append(subResponse);
+ c.getSource().sendSuccess(response, true);
+ }
+ return 1;
+ })))
+ );
}
@SubscribeEvent
- public void serverStopping(ServerStoppingEvent event) {
+ public void serverStopping(ServerStoppingEvent ignoredEvent) {
logger.debug("About to cleanup BattleManager");
if (proxy.cleanupBattleManager()) {
logger.debug("Cleaned up BattleManager");