Merge branch 'master' into snapshot

# Conflicts:
#	gradle.properties
#	src/main/java/one/oth3r/sit/ModMenu.java
#	src/main/java/one/oth3r/sit/Sit.java
#	src/main/java/one/oth3r/sit/SitClient.java
This commit is contained in:
Oth3r 2024-04-10 12:12:42 -05:00
commit c6fb594d1f
8 changed files with 184 additions and 112 deletions

View file

@ -7,17 +7,23 @@
Sit on **stairs**, **slabs**, **carpets** by default, and sit on everything else using the config! Sit on **stairs**, **slabs**, **carpets** by default, and sit on everything else using the config!
You can also customize hand restrictions to stop accidentally sitting down! You can also customize hand restrictions to stop accidentally sitting down!
The mod also has full Geyser support! Enjoy sitting with everyone, weather they are on Bedrock or Java! The mod also has full Geyser support! Enjoy sitting with everyone, weather they are on Bedrock or Java!
### Where to install? ### Where to install?
**Sit!** works on the server (singleplayer included), with support for clients that join in to use their own settings to sit. **Sit!** works on the server (singleplayer included), also with support for clients that join in to use their own settings to sit.
## Help localize Sit! on [Crowdin](https://crowdin.com/project/oth3r-sit)! ## Help localize Sit! on [Crowdin](https://crowdin.com/project/oth3r-sit)!
![overview](https://github.com/Oth3r/Sit/blob/master/media/overview.gif?raw=true) ![overview](https://github.com/Oth3r/Sit/blob/master/media/overview.gif?raw=true)
## Check out my other Projects! ## Check out my other Projects!
[![Caligo badge](https://github.com/Oth3r/Caligo/blob/master/media/promo_badge.png?raw=true)](https://modrinth.com/mod/caligo)
[![DirectionHUD badge](https://github.com/Oth3r/DirectionHUD/blob/master/media/mod-badge.png?raw=true)](https://modrinth.com/mod/directionhud) [![DirectionHUD badge](https://github.com/Oth3r/DirectionHUD/blob/master/media/mod-badge.png?raw=true)](https://modrinth.com/mod/directionhud)
[![DirectionHUD Spigot badge](https://github.com/Oth3r/DirectionHUD/blob/master/media/plugin-badge.png?raw=true)](https://modrinth.com/plugin/directionhud-plugin) [![DirectionHUD Spigot badge](https://github.com/Oth3r/DirectionHUD/blob/master/media/plugin-badge.png?raw=true)](https://modrinth.com/plugin/directionhud-plugin)
# Features # Features
### Hand Restrictions ### Hand Restrictions
Don't want to accidentally sit down? Set custom restrictions for each hand in the config! Don't want to accidentally sit down? Set custom restrictions for each hand in the config!
* Per player hand restrictions when connecting to a `Sit!` server on a `Sit!` Client! * Per player hand restrictions when connecting to a `Sit!` server on a `Sit!` Client!
![hand restrictions](https://github.com/Oth3r/Sit/blob/master/media/hand-restrictions.gif?raw=true) ![hand restrictions](https://github.com/Oth3r/Sit/blob/master/media/hand-restrictions.gif?raw=true)
@ -26,6 +32,7 @@ Don't want to accidentally sit down? Set custom restrictions for each hand in th
Want to sit on _**EVERY**_ block? With the config you can add more options to sit on! Custom block states are also supported. Want to sit on _**EVERY**_ block? With the config you can add more options to sit on! Custom block states are also supported.
![custom blocks](https://github.com/Oth3r/Sit/blob/master/media/custom-blocks.gif?raw=true) ![custom blocks](https://github.com/Oth3r/Sit/blob/master/media/custom-blocks.gif?raw=true)
### Customizable Config ### Customizable Config
Configure to your hearts desire with the in-game config with **[ModMenu](https://modrinth.com/mod/modmenu)** & **[YetAnotherConfigLib](https://modrinth.com/mod/yacl)**, or use the provided config file for servers! Configure to your hearts desire with the in-game config with **[ModMenu](https://modrinth.com/mod/modmenu)** & **[YetAnotherConfigLib](https://modrinth.com/mod/yacl)**, or use the provided config file for servers!
@ -35,3 +42,5 @@ Configure to your hearts desire with the in-game config with **[ModMenu](https:/
## Future Goals ## Future Goals
* Forge Port (probably NeoForge 1.21) * Forge Port (probably NeoForge 1.21)
* Custom dismounting logic * Custom dismounting logic
* better config (coming soon!)
* keybindings (next update)

View file

@ -9,7 +9,7 @@ yarn_mappings=24w03b+build.6
loader_version=0.15.6 loader_version=0.15.6
# Mod Properties # Mod Properties
mod_version=s1.1.3+24w03b mod_version=s1.1.4+24w03b
maven_group=one.oth3r maven_group=one.oth3r
archives_base_name=sit! archives_base_name=sit!

View file

@ -23,7 +23,8 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box; import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
import one.oth3r.sit.Utl.HandType; import one.oth3r.sit.Utl.HandSettings.HandType;
import one.oth3r.sit.file.Config;
import java.util.*; import java.util.*;
@ -38,25 +39,25 @@ public class Events {
ArrayList<UseAction> notUsable = new ArrayList<>(food); ArrayList<UseAction> notUsable = new ArrayList<>(food);
notUsable.add(UseAction.NONE); notUsable.add(UseAction.NONE);
HashMap<HandType, ItemStack> itemMap = new HashMap<>(); HashMap<HandType, ItemStack> itemMap = new HashMap<>();
itemMap.put(HandType.main,player.getMainHandStack()); itemMap.put(Utl.HandSettings.HandType.main,player.getMainHandStack());
itemMap.put(HandType.off,player.getOffHandStack()); itemMap.put(Utl.HandSettings.HandType.off,player.getOffHandStack());
// if sneaking cant sit // if sneaking cant sit
if (player.isSneaking()) return false; if (player.isSneaking()) return false;
// for both hands // for both hands
for (HandType type:HandType.values()) { for (HandType type: Utl.HandSettings.HandType.values()) {
ItemStack targetStack = itemMap.get(type); ItemStack targetStack = itemMap.get(type);
// if req is empty and the item isn't empty, false // if req is empty and the item isn't empty, false
if (Utl.getReq(player,type).equals(config.HandRequirement.empty) && !targetStack.isEmpty()) return false; if (Utl.HandSettings.getReq(player,type).equals(Config.HandRequirement.empty) && !targetStack.isEmpty()) return false;
// if req is restrictive // if req is restrictive
if (Utl.getReq(player,type).equals(config.HandRequirement.restrictive)) { if (Utl.HandSettings.getReq(player,type).equals(Config.HandRequirement.restrictive)) {
// if item is in blacklist, false // if item is in blacklist, false
if (checkList(Utl.getList(player,type,"blacklist"),targetStack)) return false; if (checkList(Utl.HandSettings.getList(player,type,"blacklist"),targetStack)) return false;
// if item is NOT in whitelist // if item is NOT in whitelist
if (!checkList(Utl.getList(player,type,"whitelist"),targetStack)) { if (!checkList(Utl.HandSettings.getList(player,type,"whitelist"),targetStack)) {
// if block is restricted and items is block, false, ect // if block is restricted and items is block, false, ect
if (Utl.getBool(player,type,"block") && (targetStack.getItem() instanceof BlockItem)) return false; if (Utl.HandSettings.getBool(player,type,"block") && (targetStack.getItem() instanceof BlockItem)) return false;
if (Utl.getBool(player,type,"food") && food.contains(targetStack.getUseAction())) return false; if (Utl.HandSettings.getBool(player,type,"food") && food.contains(targetStack.getUseAction())) return false;
if (Utl.getBool(player,type,"usable") && !notUsable.contains(targetStack.getUseAction())) return false; if (Utl.HandSettings.getBool(player,type,"usable") && !notUsable.contains(targetStack.getUseAction())) return false;
} }
} }
} }
@ -72,7 +73,7 @@ public class Events {
// get a hashmap of custom blocks // get a hashmap of custom blocks
HashMap<String,HashMap<String,Object>> map = new HashMap<>(); HashMap<String,HashMap<String,Object>> map = new HashMap<>();
int i = 1; int i = 1;
for (String s:config.customBlocks) { for (String s: Config.customBlocks) {
String[] split = s.split("\\|"); String[] split = s.split("\\|");
HashMap<String,Object> data = new HashMap<>(); HashMap<String,Object> data = new HashMap<>();
data.put("block",split[0]); data.put("block",split[0]);
@ -100,12 +101,12 @@ public class Events {
for (Entity entity:entities.values()) if (entity.getBlockPos().equals(pos) || entity.getBlockPos().add(0,1,0).equals(pos)) return false; for (Entity entity:entities.values()) if (entity.getBlockPos().equals(pos) || entity.getBlockPos().add(0,1,0).equals(pos)) return false;
// return for the 4 default types // return for the 4 default types
if (block instanceof StairsBlock && config.stairsOn) return blockState.get(StairsBlock.HALF) == BlockHalf.BOTTOM; if (block instanceof StairsBlock && Config.stairsOn) return blockState.get(StairsBlock.HALF) == BlockHalf.BOTTOM;
if (block instanceof SlabBlock && config.slabsOn) return blockState.get(SlabBlock.TYPE) == SlabType.BOTTOM; if (block instanceof SlabBlock && Config.slabsOn) return blockState.get(SlabBlock.TYPE) == SlabType.BOTTOM;
if (block instanceof CarpetBlock && config.carpetsOn) return true; if (block instanceof CarpetBlock && Config.carpetsOn) return true;
if (blockState.isFullCube(world,pos.add(0,1,0)) && config.fullBlocksOn) return true; if (blockState.isFullCube(world,pos.add(0,1,0)) && Config.fullBlocksOn) return true;
// custom checker // custom checker
if (config.customOn && config.customBlocks.size() != 0) { if (Config.customOn && Config.customBlocks.size() != 0) {
for (HashMap<String,Object> map:getCustomBlocks().values()) { for (HashMap<String,Object> map:getCustomBlocks().values()) {
String blockID = Registries.BLOCK.getId(block).toString(); String blockID = Registries.BLOCK.getId(block).toString();
if (map.get("block").equals(blockID)) { if (map.get("block").equals(blockID)) {
@ -149,7 +150,7 @@ public class Events {
entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+.78, pos.getZ() + 0.5, 0, 0); entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+.78, pos.getZ() + 0.5, 0, 0);
hitBoxY = 2; hitBoxY = 2;
} }
if (config.customOn && config.customBlocks.size() != 0) { if (Config.customOn && !Config.customBlocks.isEmpty()) {
for (HashMap<String,Object> map:getCustomBlocks().values()) { for (HashMap<String,Object> map:getCustomBlocks().values()) {
String blockID = Registries.BLOCK.getId(block).toString(); String blockID = Registries.BLOCK.getId(block).toString();
if (map.get("block").equals(blockID)) { if (map.get("block").equals(blockID)) {
@ -167,6 +168,24 @@ public class Events {
if (entity.getY() <= pos.getY()+.35+oneTwentyTwo) entity.setPitch(90); // below if (entity.getY() <= pos.getY()+.35+oneTwentyTwo) entity.setPitch(90); // below
else entity.setPitch(-90); // above else entity.setPitch(-90); // above
} }
public static boolean sit(ServerPlayerEntity player, BlockPos pos) {
// todo interactions entity to make the sitting hitbox?
World world = player.getWorld();
DisplayEntity.TextDisplayEntity entity = new DisplayEntity.TextDisplayEntity(EntityType.TEXT_DISPLAY,player.getServerWorld());
setEntity(pos,world,entity);
if (checkBlocks(pos,world,isAboveBlockheight(entity))) {
if (entities.containsKey(player)) {
if (!Config.sitWhileSeated) return false;
entities.get(player).setRemoved(Entity.RemovalReason.DISCARDED);
entities.remove(player);
}
player.getServerWorld().spawnEntity(entity);
player.startRiding(entity);
entities.put(player,entity);
return true;
}
return false;
}
public static void register() { public static void register() {
ServerTickEvents.END_SERVER_TICK.register(minecraftServer -> minecraftServer.execute(Events::cleanUp)); ServerTickEvents.END_SERVER_TICK.register(minecraftServer -> minecraftServer.execute(Events::cleanUp));
// PLAYER JOIN // PLAYER JOIN
@ -174,12 +193,12 @@ public class Events {
ServerPlayerEntity player = handler.player; ServerPlayerEntity player = handler.player;
checkPlayers.put(player,2); checkPlayers.put(player,2);
// put server settings in the player settings // put server settings in the player settings
Sit.playerSettings.put(player,Utl.getHandSettings()); Sit.playerSettings.put(player, Utl.HandSettings.getHandSettings());
}); });
ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> { ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> {
ServerPlayerEntity player = handler.player; ServerPlayerEntity player = handler.player;
if (entities.containsKey(player)) { if (entities.containsKey(player)) {
if (!config.keepActive) { if (!Config.keepActive) {
player.dismountVehicle(); player.dismountVehicle();
entities.get(player).setRemoved(Entity.RemovalReason.DISCARDED); entities.get(player).setRemoved(Entity.RemovalReason.DISCARDED);
} }
@ -196,22 +215,12 @@ public class Events {
if (player == null) return ActionResult.PASS; if (player == null) return ActionResult.PASS;
if (hand == net.minecraft.util.Hand.MAIN_HAND && hitResult.getType() == HitResult.Type.BLOCK) { if (hand == net.minecraft.util.Hand.MAIN_HAND && hitResult.getType() == HitResult.Type.BLOCK) {
BlockPos pos = hitResult.getBlockPos(); BlockPos pos = hitResult.getBlockPos();
// check the players hands
if (!checkLogic(player)) return ActionResult.PASS; if (!checkLogic(player)) return ActionResult.PASS;
// todo interactions entity to make the hitbox? // make the player sit
// make the entity first before checking to make sure the blocks around are fine boolean status = sit(player,pos);
DisplayEntity.TextDisplayEntity entity = new DisplayEntity.TextDisplayEntity(EntityType.TEXT_DISPLAY,player.getServerWorld()); // if sat, cancel / FAIL the use block event
setEntity(pos,world,entity); if (status) return ActionResult.FAIL;
if (checkBlocks(pos,world,isAboveBlockheight(entity))) {
if (entities.containsKey(player)) {
if (!config.sitWhileSeated) return ActionResult.PASS;
entities.get(player).setRemoved(Entity.RemovalReason.DISCARDED);
entities.remove(player);
}
player.getServerWorld().spawnEntity(entity);
player.startRiding(entity);
entities.put(player,entity);
return ActionResult.FAIL;
}
} }
return ActionResult.PASS; return ActionResult.PASS;
}); });

View file

@ -4,6 +4,7 @@ import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import net.minecraft.text.MutableText; import net.minecraft.text.MutableText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import one.oth3r.sit.file.Config;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -77,10 +78,10 @@ public class LangReader {
public static void loadLanguageFile() { public static void loadLanguageFile() {
try { try {
ClassLoader classLoader = Sit.class.getClassLoader(); ClassLoader classLoader = Sit.class.getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream("assets/sit/lang/"+ config.lang+".json"); InputStream inputStream = classLoader.getResourceAsStream("assets/sit/lang/"+ Config.lang+".json");
if (inputStream == null) { if (inputStream == null) {
inputStream = classLoader.getResourceAsStream("assets/sit/lang/"+config.defaults.lang+".json"); inputStream = classLoader.getResourceAsStream("assets/sit/lang/"+ Config.defaults.lang+".json");
config.lang = config.defaults.lang; Config.lang = Config.defaults.lang;
} }
if (inputStream == null) throw new IllegalArgumentException("CANT LOAD THE LANGUAGE FILE. DIRECTIONHUD WILL BREAK."); if (inputStream == null) throw new IllegalArgumentException("CANT LOAD THE LANGUAGE FILE. DIRECTIONHUD WILL BREAK.");
Type type = new TypeToken<Map<String, String>>(){}.getType(); Type type = new TypeToken<Map<String, String>>(){}.getType();

View file

@ -16,7 +16,7 @@ import net.minecraft.server.command.CommandManager;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.MutableText; import net.minecraft.text.MutableText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Identifier; import one.oth3r.sit.file.Config;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -37,7 +37,7 @@ public class Sit implements ModInitializer {
//todo future: //todo future:
// make it so it updates the sitting height and pos based on the block so if it changed while offline it still works (or if stair changes shape) // make it so it updates the sitting height and pos based on the block so if it changed while offline it still works (or if stair changes shape)
// inner stair offset & custom support for that ig // inner stair offset & custom support for that ig
config.load(); Config.load();
Events.register(); Events.register();
//PACKETS //PACKETS
PayloadTypeRegistry.playC2S().register(SettingsPayload.ID, SettingsPayload.CODEC); PayloadTypeRegistry.playC2S().register(SettingsPayload.ID, SettingsPayload.CODEC);

View file

@ -7,15 +7,13 @@ import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder; import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.decoration.DisplayEntity;
import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.TextColor; import net.minecraft.text.TextColor;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import one.oth3r.sit.file.Config;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -48,31 +46,24 @@ public class SitCommand {
// if console // if console
if (player == null) { if (player == null) {
if (args[0].equalsIgnoreCase("reload")) { if (args[0].equalsIgnoreCase("reload")) {
config.load(); Config.load();
Sit.LOGGER.info(Sit.lang("key.sit.command.reloaded").getString()); Sit.LOGGER.info(Sit.lang("key.sit.command.reloaded").getString());
} }
return 1; return 1;
} }
if (args[0].equalsIgnoreCase("sit")) { if (args[0].equalsIgnoreCase("sit")) {
BlockPos pos = player.getBlockPos(); BlockPos pos = player.getBlockPos();
if (!(player.getY() -((int) player.getY()) > 0.00)) { // get the block under the player if player on top of a solid
if (!(player.getY() - ((int) player.getY()) > 0.00)) {
pos = pos.add(0,-1,0); pos = pos.add(0,-1,0);
} }
World world = player.getWorld();
// if already sitting, ignore // if already sitting, ignore
if (Events.entities.containsKey(player)) return 1; if (Events.entities.containsKey(player)) return 1;
// make entity first to check the blocks // sit
DisplayEntity.TextDisplayEntity entity = new DisplayEntity.TextDisplayEntity(EntityType.TEXT_DISPLAY,player.getServerWorld()); Events.sit(player,pos);
Events.setEntity(pos,world,entity);
if (Events.checkBlocks(pos,world,Events.isAboveBlockheight(entity))) {
player.getServerWorld().spawnEntity(entity);
player.startRiding(entity);
Events.entities.put(player,entity);
return 1;
}
} }
if (args[0].equalsIgnoreCase("reload")) { if (args[0].equalsIgnoreCase("reload")) {
config.load(); Config.load();
player.sendMessage(Sit.lang("key.sit.command.reloaded").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GREEN)))); player.sendMessage(Sit.lang("key.sit.command.reloaded").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GREEN))));
} }
if (args[0].equalsIgnoreCase("purgeChairEntities")) { if (args[0].equalsIgnoreCase("purgeChairEntities")) {

View file

@ -4,6 +4,7 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import one.oth3r.sit.file.Config;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
@ -11,35 +12,59 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
public class Utl { public class Utl {
enum HandType { public static class HandSettings {
main, public static HashMap<String,String> getHandSettings() {
off Gson gson = new GsonBuilder().disableHtmlEscaping().create();
HashMap<String,String> settings = new HashMap<>();
settings.put("hand.main.requirement",String.valueOf(Config.mainReq));
settings.put("hand.main.block",String.valueOf(Config.mainBlock));
settings.put("hand.main.food",String.valueOf(Config.mainFood));
settings.put("hand.main.usable",String.valueOf(Config.mainUsable));
settings.put("hand.main.whitelist",gson.toJson(Config.mainWhitelist));
settings.put("hand.main.blacklist",gson.toJson(Config.mainBlacklist));
settings.put("hand.off.requirement",String.valueOf(Config.offReq));
settings.put("hand.off.block",String.valueOf(Config.offBlock));
settings.put("hand.off.food",String.valueOf(Config.offFood));
settings.put("hand.off.usable",String.valueOf(Config.offUsable));
settings.put("hand.off.whitelist",gson.toJson(Config.offWhitelist));
settings.put("hand.off.blacklist",gson.toJson(Config.offBlacklist));
return settings;
}
public static Config.HandRequirement getReq(ServerPlayerEntity player, HandType type) {
return Config.HandRequirement.get(Sit.playerSettings.get(player).get("hand."+type+".requirement"));
}
public static List<String> getList(ServerPlayerEntity player, HandType type, String setting) {
Type listType = new TypeToken<ArrayList<String>>() {}.getType();
return new Gson().fromJson(Sit.playerSettings.get(player).get("hand."+type+"."+setting),listType);
}
public static boolean getBool(ServerPlayerEntity player, HandType type, String setting) {
return Boolean.parseBoolean(Sit.playerSettings.get(player).get("hand."+type+"."+setting));
}
public enum HandType {
main,
off
}
} }
public static HashMap<String,String> getHandSettings() { public static class Num {
Gson gson = new GsonBuilder().disableHtmlEscaping().create(); public static boolean isInt(String string) {
HashMap<String,String> settings = new HashMap<>(); try {
settings.put("hand.main.requirement",String.valueOf(config.mainReq)); Integer.parseInt(string);
settings.put("hand.main.block",String.valueOf(config.mainBlock)); } catch (NumberFormatException nfe) {
settings.put("hand.main.food",String.valueOf(config.mainFood)); return false;
settings.put("hand.main.usable",String.valueOf(config.mainUsable)); }
settings.put("hand.main.whitelist",gson.toJson(config.mainWhitelist)); return true;
settings.put("hand.main.blacklist",gson.toJson(config.mainBlacklist)); }
settings.put("hand.off.requirement",String.valueOf(config.offReq)); public static boolean isFloat(String string) {
settings.put("hand.off.block",String.valueOf(config.offBlock)); try {
settings.put("hand.off.food",String.valueOf(config.offFood)); Float.parseFloat(string);
settings.put("hand.off.usable",String.valueOf(config.offUsable)); } catch (NumberFormatException nfe) {
settings.put("hand.off.whitelist",gson.toJson(config.offWhitelist)); return false;
settings.put("hand.off.blacklist",gson.toJson(config.offBlacklist)); }
return settings; return true;
} }
public static config.HandRequirement getReq(ServerPlayerEntity player, HandType type) {
return config.HandRequirement.get(Sit.playerSettings.get(player).get("hand."+type+".requirement"));
}
public static List<String> getList(ServerPlayerEntity player, HandType type, String setting) {
Type listType = new TypeToken<ArrayList<String>>() {}.getType();
return new Gson().fromJson(Sit.playerSettings.get(player).get("hand."+type+"."+setting),listType);
}
public static boolean getBool(ServerPlayerEntity player, HandType type, String setting) {
return Boolean.parseBoolean(Sit.playerSettings.get(player).get("hand."+type+"."+setting));
} }
} }

View file

@ -1,9 +1,14 @@
package one.oth3r.sit; package one.oth3r.sit.file;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import one.oth3r.sit.LangReader;
import one.oth3r.sit.Sit;
import one.oth3r.sit.SitClient;
import one.oth3r.sit.Utl.*;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -14,7 +19,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
public class config { public class Config {
public static String lang = defaults.lang; public static String lang = defaults.lang;
public static boolean keepActive = defaults.keepActive; public static boolean keepActive = defaults.keepActive;
public static boolean sitWhileSeated = defaults.sitWhileSeated; public static boolean sitWhileSeated = defaults.sitWhileSeated;
@ -24,7 +29,7 @@ public class config {
public static boolean fullBlocksOn = defaults.fullBlocksOn; public static boolean fullBlocksOn = defaults.fullBlocksOn;
public static boolean customOn = defaults.customOn; public static boolean customOn = defaults.customOn;
public static List<String> customBlocks = defaults.customBlocks; public static List<String> customBlocks = defaults.customBlocks;
enum HandRequirement { public enum HandRequirement {
empty, empty,
restrictive, restrictive,
none; none;
@ -62,17 +67,35 @@ public class config {
Properties properties = new Properties(); Properties properties = new Properties();
properties.load(fileStream); properties.load(fileStream);
String ver = (String) properties.computeIfAbsent("version", a -> String.valueOf(defaults.version)); String ver = (String) properties.computeIfAbsent("version", a -> String.valueOf(defaults.version));
// if the old version system (v1.0) remove "v:
// if the old version system (v1.0) remove "v"
if (ver.contains("v")) ver = ver.substring(1); if (ver.contains("v")) ver = ver.substring(1);
loadVersion(properties,Double.parseDouble(ver)); loadVersion(properties,Double.parseDouble(ver));
LangReader.loadLanguageFile(); LangReader.loadLanguageFile();
save(); save();
} catch (Exception f) { } catch (Exception e) {
//read fail //read fail
f.printStackTrace(); e.printStackTrace();
save(); save();
} }
} }
public static ArrayList<String> validateCustomBlocks(ArrayList<String> fix) {
ArrayList<String> out = new ArrayList<>();
for (String entry : fix) {
String[] split = entry.split("\\|");
// skip if not the right size
if (split.length < 3 || split.length > 4) continue;
// keep going if that block exists
// if (Registries.BLOCK.stream().anyMatch(match -> Registries.BLOCK.getId(match).toString().equals(split[0]))) {}
// if the other entries aren't correct, skip
if (!Num.isFloat(split[1]) || !Num.isInt(split[2])) continue;
// add if everything is a okay
out.add(entry);
}
return out;
}
public static void loadVersion(Properties properties, double version) { public static void loadVersion(Properties properties, double version) {
try { try {
Gson gson = new GsonBuilder().disableHtmlEscaping().create(); Gson gson = new GsonBuilder().disableHtmlEscaping().create();
@ -86,17 +109,23 @@ public class config {
carpetsOn = Boolean.parseBoolean((String) properties.computeIfAbsent("carpets", a -> String.valueOf(defaults.carpetsOn))); carpetsOn = Boolean.parseBoolean((String) properties.computeIfAbsent("carpets", a -> String.valueOf(defaults.carpetsOn)));
fullBlocksOn = Boolean.parseBoolean((String) properties.computeIfAbsent("full-blocks", a -> String.valueOf(defaults.fullBlocksOn))); fullBlocksOn = Boolean.parseBoolean((String) properties.computeIfAbsent("full-blocks", a -> String.valueOf(defaults.fullBlocksOn)));
customOn = Boolean.parseBoolean((String) properties.computeIfAbsent("custom", a -> String.valueOf(defaults.customOn))); customOn = Boolean.parseBoolean((String) properties.computeIfAbsent("custom", a -> String.valueOf(defaults.customOn)));
customBlocks = new Gson().fromJson((String) try {
properties.computeIfAbsent("custom-blocks", a -> gson.toJson(defaults.customBlocks)), listType); customBlocks = validateCustomBlocks(new Gson().fromJson((String)
mainReq = HandRequirement.valueOf((String) properties.computeIfAbsent("hand.main.requirement", a -> String.valueOf(defaults.mainReq))); properties.computeIfAbsent("custom-blocks", a -> gson.toJson(defaults.customBlocks)), listType));
} catch (JsonSyntaxException ignore) {}
mainReq = HandRequirement.get((String) properties.computeIfAbsent("hand.main.requirement", a -> String.valueOf(defaults.mainReq)));
mainBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.main.block", a -> String.valueOf(defaults.mainBlock))); mainBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.main.block", a -> String.valueOf(defaults.mainBlock)));
mainFood = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.main.food", a -> String.valueOf(defaults.mainFood))); mainFood = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.main.food", a -> String.valueOf(defaults.mainFood)));
mainUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.main.usable", a -> String.valueOf(defaults.mainUsable))); mainUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.main.usable", a -> String.valueOf(defaults.mainUsable)));
mainWhitelist = new Gson().fromJson((String) try {
properties.computeIfAbsent("hand.main.whitelist", a -> gson.toJson(defaults.mainWhitelist)), listType); mainWhitelist = new Gson().fromJson((String)
mainBlacklist = new Gson().fromJson((String) properties.computeIfAbsent("hand.main.whitelist", a -> gson.toJson(defaults.mainWhitelist)), listType);
properties.computeIfAbsent("hand.main.blacklist", a -> gson.toJson(defaults.mainBlacklist)), listType); } catch (JsonSyntaxException ignore) {}
offReq = HandRequirement.valueOf((String) properties.computeIfAbsent("hand.off.requirement", a -> String.valueOf(defaults.offReq))); try {
mainBlacklist = new Gson().fromJson((String)
properties.computeIfAbsent("hand.main.blacklist", a -> gson.toJson(defaults.mainBlacklist)), listType);
} catch (JsonSyntaxException ignore) {}
offReq = HandRequirement.get((String) properties.computeIfAbsent("hand.off.requirement", a -> String.valueOf(defaults.offReq)));
offBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.off.block", a -> String.valueOf(defaults.offBlock))); offBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.off.block", a -> String.valueOf(defaults.offBlock)));
offFood = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.off.food", a -> String.valueOf(defaults.offFood))); offFood = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.off.food", a -> String.valueOf(defaults.offFood)));
offUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.off.usable", a -> String.valueOf(defaults.offUsable))); offUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.off.usable", a -> String.valueOf(defaults.offUsable)));
@ -105,22 +134,30 @@ public class config {
offBlacklist = new Gson().fromJson((String) offBlacklist = new Gson().fromJson((String)
properties.computeIfAbsent("hand.off.blacklist", a -> gson.toJson(defaults.offBlacklist)), listType); properties.computeIfAbsent("hand.off.blacklist", a -> gson.toJson(defaults.offBlacklist)), listType);
if (version == 1.0) { if (version == 1.0) {
mainReq = HandRequirement.valueOf((String) properties.computeIfAbsent("main-hand-requirement", a -> String.valueOf(defaults.mainReq))); mainReq = HandRequirement.get((String) properties.computeIfAbsent("main-hand-requirement", a -> String.valueOf(defaults.mainReq)));
mainBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-block", a -> String.valueOf(defaults.mainBlock))); mainBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-block", a -> String.valueOf(defaults.mainBlock)));
mainFood = Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-food", a -> String.valueOf(defaults.mainFood))); mainFood = Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-food", a -> String.valueOf(defaults.mainFood)));
mainUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-usable", a -> String.valueOf(defaults.mainUsable))); mainUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-usable", a -> String.valueOf(defaults.mainUsable)));
mainWhitelist = new Gson().fromJson((String) try {
properties.computeIfAbsent("main-hand-whitelist", a -> gson.toJson(defaults.mainWhitelist)), listType); mainWhitelist = new Gson().fromJson((String)
mainBlacklist = new Gson().fromJson((String) properties.computeIfAbsent("main-hand-whitelist", a -> gson.toJson(defaults.mainWhitelist)), listType);
properties.computeIfAbsent("main-hand-blacklist", a -> gson.toJson(defaults.mainBlacklist)), listType); } catch (JsonSyntaxException ignore) {}
offReq = HandRequirement.valueOf((String) properties.computeIfAbsent("off-hand-requirement", a -> String.valueOf(defaults.offReq))); try {
mainBlacklist = new Gson().fromJson((String)
properties.computeIfAbsent("main-hand-blacklist", a -> gson.toJson(defaults.mainBlacklist)), listType);
} catch (JsonSyntaxException ignore) {}
offReq = HandRequirement.get((String) properties.computeIfAbsent("off-hand-requirement", a -> String.valueOf(defaults.offReq)));
offBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-block", a -> String.valueOf(defaults.offBlock))); offBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-block", a -> String.valueOf(defaults.offBlock)));
offFood = Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-food", a -> String.valueOf(defaults.offFood))); offFood = Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-food", a -> String.valueOf(defaults.offFood)));
offUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-usable", a -> String.valueOf(defaults.offUsable))); offUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-usable", a -> String.valueOf(defaults.offUsable)));
offWhitelist = new Gson().fromJson((String) try {
properties.computeIfAbsent("off-hand-whitelist", a -> gson.toJson(defaults.offWhitelist)), listType); offWhitelist = new Gson().fromJson((String)
offBlacklist = new Gson().fromJson((String) properties.computeIfAbsent("off-hand-whitelist", a -> gson.toJson(defaults.offWhitelist)), listType);
properties.computeIfAbsent("off-hand-blacklist", a -> gson.toJson(defaults.offBlacklist)), listType); } catch (JsonSyntaxException ignore) {}
try {
offBlacklist = new Gson().fromJson((String)
properties.computeIfAbsent("off-hand-blacklist", a -> gson.toJson(defaults.offBlacklist)), listType);
} catch (JsonSyntaxException ignore) {}
} }
} catch (Exception e) { } catch (Exception e) {
Sit.LOGGER.info("ERROR LOADING CONFIG - PLEASE REPORT WITH THE ERROR LOG"); Sit.LOGGER.info("ERROR LOADING CONFIG - PLEASE REPORT WITH THE ERROR LOG");
@ -191,7 +228,7 @@ public class config {
public static boolean carpetsOn = true; public static boolean carpetsOn = true;
public static boolean fullBlocksOn = false; public static boolean fullBlocksOn = false;
public static boolean customOn = false; public static boolean customOn = false;
public static List<String> customBlocks = List.of("minecraft:campfire|.46|1|lit=false","minecraft:soul_campfire|.46|1|lit=false"); public static List<String> customBlocks = List.of("minecraft:campfire|.46|1|lit=false","minecraft:soul_campfire|.46|1|lit=false,waterlogged=false");
public static HandRequirement mainReq = HandRequirement.empty; public static HandRequirement mainReq = HandRequirement.empty;
public static boolean mainBlock = false; public static boolean mainBlock = false;
public static boolean mainFood = false; public static boolean mainFood = false;