diff --git a/src/main/java/one/oth3r/sit/utl/Events.java b/src/main/java/one/oth3r/sit/utl/Events.java index 42c6362..4617fb3 100644 --- a/src/main/java/one/oth3r/sit/utl/Events.java +++ b/src/main/java/one/oth3r/sit/utl/Events.java @@ -45,33 +45,7 @@ public class Events { private static void loopLogic(ClientPlayerEntity player) { while (toggle_key.wasPressed()) { if (Data.isInGame()) { - // todo move to logic.java - if (Data.isSupportedServer()) { - // get the sitting config - SittingConfig config = FileData.getSittingConfig(); - // toggle the setting - config.setEnabled(!config.getEnabled()); - - // set the sitting config to the new value - FileData.setSittingConfig(config); - // save the changes to the file - config.save(); - // send the changes to the server - Utl.sendSettingsPackets(); - - - // get the message settings - String messageKey = "msg.sit_toggle."+(config.getEnabled()?"on":"off"); - Formatting messageColor = config.getEnabled()?Formatting.GREEN:Formatting.RED; - - // send the player the actionbar message - player.sendMessage(Utl.lang("msg.sit_toggle", - Utl.lang(messageKey).formatted(messageColor)), true); - } else { - // unsupported server message if not in a Sit! server - player.sendMessage(Utl.lang("msg.unsupported") - .formatted(Formatting.RED), true); - } + player.sendMessage(Logic.toggleSiting(), true); } } diff --git a/src/main/java/one/oth3r/sit/utl/Logic.java b/src/main/java/one/oth3r/sit/utl/Logic.java index 25f48ec..bf7a36f 100644 --- a/src/main/java/one/oth3r/sit/utl/Logic.java +++ b/src/main/java/one/oth3r/sit/utl/Logic.java @@ -4,6 +4,8 @@ import net.minecraft.block.*; import net.minecraft.entity.decoration.DisplayEntity; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; +import net.minecraft.text.MutableText; +import net.minecraft.util.Formatting; import net.minecraft.util.Hand; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; @@ -142,4 +144,37 @@ public class Logic { FileData.loadFiles(); } + /** + * toggles the sit ablity config option + * @return returns a message, that can be sent to the player + */ + public static MutableText toggleSiting() { + if (Data.isSupportedServer()) { + // get the sitting config + SittingConfig config = FileData.getSittingConfig(); + // toggle the setting + config.setEnabled(!config.getEnabled()); + + // set the sitting config to the new value + FileData.setSittingConfig(config); + // save the changes to the file + config.save(); + // send the changes to the server + Utl.sendSettingsPackets(); + + + // get the message settings + String messageKey = "msg.sit_toggle."+(config.getEnabled()?"on":"off"); + Formatting messageColor = config.getEnabled()?Formatting.GREEN:Formatting.RED; + + // send the player the actionbar message + return Utl.lang("msg.sit_toggle", + Utl.lang(messageKey).formatted(messageColor)); + } else { + // unsupported server message if not in a Sit! server + return Utl.lang("msg.unsupported") + .formatted(Formatting.RED); + } + } + }