forked from virt-mirrors/Sit
moved toggle sit keybind logic to Logic.java
This commit is contained in:
parent
0738608811
commit
9fd0ee1d6a
2 changed files with 36 additions and 27 deletions
|
@ -45,33 +45,7 @@ public class Events {
|
||||||
private static void loopLogic(ClientPlayerEntity player) {
|
private static void loopLogic(ClientPlayerEntity player) {
|
||||||
while (toggle_key.wasPressed()) {
|
while (toggle_key.wasPressed()) {
|
||||||
if (Data.isInGame()) {
|
if (Data.isInGame()) {
|
||||||
// todo move to logic.java
|
player.sendMessage(Logic.toggleSiting(), true);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ import net.minecraft.block.*;
|
||||||
import net.minecraft.entity.decoration.DisplayEntity;
|
import net.minecraft.entity.decoration.DisplayEntity;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
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.Hand;
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
@ -142,4 +144,37 @@ public class Logic {
|
||||||
FileData.loadFiles();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue