From 28279fd890c2ed3da8dce0c987d353df46a7ca6e Mon Sep 17 00:00:00 2001 From: deirn Date: Thu, 3 Jun 2021 21:57:46 +0700 Subject: [PATCH] make it configurable --- .../megane/config/MeganeConfig.java | 9 ++ .../config/screen/MeganeConfigScreen.java | 1 + .../megane/runtime/data/block/BlockData.java | 4 + .../runtime/data/entity/EntityData.java | 4 + .../resources/assets/megane/lang/en_us.json | 94 ++++++++++--------- 5 files changed, 66 insertions(+), 46 deletions(-) diff --git a/src/base/java/badasintended/megane/config/MeganeConfig.java b/src/base/java/badasintended/megane/config/MeganeConfig.java index eb4913e..8a4963f 100644 --- a/src/base/java/badasintended/megane/config/MeganeConfig.java +++ b/src/base/java/badasintended/megane/config/MeganeConfig.java @@ -24,9 +24,14 @@ public class MeganeConfig { public final PetOwner petOwner = new PetOwner(); public final Effect effect = new Effect(); + private boolean catchServerErrors = true; private boolean spawnEgg = true; private boolean playerHead = true; + public boolean getCatchServerErrors() { + return catchServerErrors; + } + public boolean getSpawnEgg() { return spawnEgg; } @@ -35,6 +40,10 @@ public boolean getPlayerHead() { return playerHead; } + public void setCatchServerErrors(boolean catchServerErrors) { + this.catchServerErrors = catchServerErrors; + } + public void setSpawnEgg(boolean spawnEgg) { this.spawnEgg = spawnEgg; } diff --git a/src/runtime/java/badasintended/megane/runtime/config/screen/MeganeConfigScreen.java b/src/runtime/java/badasintended/megane/runtime/config/screen/MeganeConfigScreen.java index a447e11..1089a79 100644 --- a/src/runtime/java/badasintended/megane/runtime/config/screen/MeganeConfigScreen.java +++ b/src/runtime/java/badasintended/megane/runtime/config/screen/MeganeConfigScreen.java @@ -178,6 +178,7 @@ public OptionsListWidget getOptions() { } }))); + options.add(sided(SERVER, bool("catchServerErrors", config().getCatchServerErrors(), config()::setCatchServerErrors))); options.add(sided(CLIENT, bool("spawnEgg", config().getSpawnEgg(), config()::setSpawnEgg))); options.add(sided(CLIENT, bool("playerHead", config().getPlayerHead(), config()::setPlayerHead))); diff --git a/src/runtime/java/badasintended/megane/runtime/data/block/BlockData.java b/src/runtime/java/badasintended/megane/runtime/data/block/BlockData.java index 9f4162a..6bead16 100644 --- a/src/runtime/java/badasintended/megane/runtime/data/block/BlockData.java +++ b/src/runtime/java/badasintended/megane/runtime/data/block/BlockData.java @@ -19,6 +19,7 @@ import static badasintended.megane.util.MeganeUtils.ISSUE_URL; import static badasintended.megane.util.MeganeUtils.LOGGER; +import static badasintended.megane.util.MeganeUtils.config; import static net.minecraft.util.registry.Registry.BLOCK; public abstract class BlockData implements IServerDataProvider { @@ -54,6 +55,9 @@ public final void appendServerData(CompoundTag data, ServerPlayerEntity player, BlockPos pos = blockEntity.getPos(); player.sendSystemMessage(ERROR_TEXT, Util.NIL_UUID); LOGGER.error("Something went wrong when retrieving data for {} at ({}, {}, {})", blockEntity.getClass().getName(), pos.getX(), pos.getY(), pos.getZ()); + if (!config().getCatchServerErrors()) { + throw t; + } LOGGER.error("Stacktrace:", t); if (registry != null) { diff --git a/src/runtime/java/badasintended/megane/runtime/data/entity/EntityData.java b/src/runtime/java/badasintended/megane/runtime/data/entity/EntityData.java index 2d81cbd..a017175 100644 --- a/src/runtime/java/badasintended/megane/runtime/data/entity/EntityData.java +++ b/src/runtime/java/badasintended/megane/runtime/data/entity/EntityData.java @@ -19,6 +19,7 @@ import static badasintended.megane.util.MeganeUtils.ISSUE_URL; import static badasintended.megane.util.MeganeUtils.LOGGER; +import static badasintended.megane.util.MeganeUtils.config; import static net.minecraft.util.registry.Registry.ENTITY_TYPE; public abstract class EntityData implements IServerDataProvider { @@ -54,6 +55,9 @@ public final void appendServerData(CompoundTag data, ServerPlayerEntity player, Vec3d pos = entity.getPos(); player.sendSystemMessage(ERROR_TEXT, Util.NIL_UUID); LOGGER.error("Something went wrong when retrieving data for {} at ({}, {}, {})", entity.getClass().getName(), pos.getX(), pos.getY(), pos.getZ()); + if (!config().getCatchServerErrors()) { + throw t; + } LOGGER.error("Stacktrace:", t); if (registry != null) { diff --git a/src/runtime/resources/assets/megane/lang/en_us.json b/src/runtime/resources/assets/megane/lang/en_us.json index 2f1d534..cd4400c 100644 --- a/src/runtime/resources/assets/megane/lang/en_us.json +++ b/src/runtime/resources/assets/megane/lang/en_us.json @@ -1,48 +1,50 @@ { - "config.waila.megane" : "Megane", - "config.megane.side.server" : "§7This option will get overloaded by the server", - "config.megane.side.and" : "§7Both client and server needs to have the same value", - "config.megane.side.plus" : "§7Server values will be added to the list", - "config.megane.side.client" : "§7This option is client side only", - "config.megane.enabled" : "Enabled", - "config.megane.expand" : "Expand when Sneaking", - "config.megane.add" : "Add New", - "config.megane.blacklist" : "Blacklist", - "config.megane.inventory" : "Block Inventory", - "config.megane.entityInventory" : "Entity Inventory", - "config.megane.inventory.itemCount" : "Show Item Count", - "config.megane.inventory.nbt" : "NBT Data", - "config.megane.inventory.nbt_desc" : "§7While this makes two stack with same item but different NBT not merged in the tooltip, this makes the packet sent to client significantly bigger, so it's not recommended for dedicated server", - "config.megane.inventory.maxWidth" : "Max Width", - "config.megane.inventory.maxHeight" : "Max Height", - "config.megane.inventory.blacklist" : "Inventory Blacklist", - "config.megane.energy" : "Energy", - "config.megane.energy.color" : "Bar Colors", - "config.megane.energy.color_desc" : "RRGGBB", - "config.megane.energy.unit" : "Units", - "config.megane.energy.blacklist" : "Energy Blacklist", - "config.megane.fluid" : "Fluid", - "config.megane.fluid.color" : "Bar Colors", - "config.megane.fluid.color_desc" : "RRGGBB", - "config.megane.fluid.blacklist" : "Fluid Blacklist", - "config.megane.progress" : "Progress", - "config.megane.progress.showWhenZero": "Show when 0%", - "config.megane.progress.blacklist" : "Progress Blacklist", - "config.megane.owner" : "Pet Owner", - "config.megane.owner.offline" : "Show Offline Owner", - "config.megane.owner.offline_desc" : "§7If enabled it will try to get offline owner name by sending a request to §5https://sessionserver.mojang.com §7and cache the result for later use. Otherwise just show \"???\" instead", - "config.megane.owner.blacklist" : "Pet Owner Blacklist", - "config.megane.effect" : "Status Effect", - "config.megane.effect.level" : "Show Level", - "config.megane.effect.hidden" : "Show Hidden Effect", - "config.megane.effect.roman" : "Use Roman Numeral", - "config.megane.effect.blacklist" : "Status Effect Blacklist", - "config.megane.playerHead" : "Player Head Icon", - "config.megane.spawnEgg" : "Spawn Egg Icon", - "megane.energy" : "Energy", - "megane.level" : "Level", - "megane.owner" : "Owner", - "megane.fluid.unknown" : "Unknown Fluid", - "megane.configToast.title" : "Megane Config Reset", - "megane.configToast.desc" : "Found version %d, not %d" + "config.waila.megane" : "Megane", + "config.megane.side.server" : "§7This option will get overloaded by the server", + "config.megane.side.and" : "§7Both client and server needs to have the same value", + "config.megane.side.plus" : "§7Server values will be added to the list", + "config.megane.side.client" : "§7This option is client side only", + "config.megane.enabled" : "Enabled", + "config.megane.expand" : "Expand when Sneaking", + "config.megane.add" : "Add New", + "config.megane.blacklist" : "Blacklist", + "config.megane.inventory" : "Block Inventory", + "config.megane.entityInventory" : "Entity Inventory", + "config.megane.inventory.itemCount" : "Show Item Count", + "config.megane.inventory.nbt" : "NBT Data", + "config.megane.inventory.nbt_desc" : "§7While this makes two stack with same item but different NBT not merged in the tooltip, this makes the packet sent to client significantly bigger, so it's not recommended for dedicated server", + "config.megane.inventory.maxWidth" : "Max Width", + "config.megane.inventory.maxHeight" : "Max Height", + "config.megane.inventory.blacklist" : "Inventory Blacklist", + "config.megane.energy" : "Energy", + "config.megane.energy.color" : "Bar Colors", + "config.megane.energy.color_desc" : "RRGGBB", + "config.megane.energy.unit" : "Units", + "config.megane.energy.blacklist" : "Energy Blacklist", + "config.megane.fluid" : "Fluid", + "config.megane.fluid.color" : "Bar Colors", + "config.megane.fluid.color_desc" : "RRGGBB", + "config.megane.fluid.blacklist" : "Fluid Blacklist", + "config.megane.progress" : "Progress", + "config.megane.progress.showWhenZero" : "Show when 0%", + "config.megane.progress.blacklist" : "Progress Blacklist", + "config.megane.owner" : "Pet Owner", + "config.megane.owner.offline" : "Show Offline Owner", + "config.megane.owner.offline_desc" : "§7If enabled it will try to get offline owner name by sending a request to §5https://sessionserver.mojang.com §7and cache the result for later use. Otherwise just show \"???\" instead", + "config.megane.owner.blacklist" : "Pet Owner Blacklist", + "config.megane.effect" : "Status Effect", + "config.megane.effect.level" : "Show Level", + "config.megane.effect.hidden" : "Show Hidden Effect", + "config.megane.effect.roman" : "Use Roman Numeral", + "config.megane.effect.blacklist" : "Status Effect Blacklist", + "config.megane.playerHead" : "Player Head Icon", + "config.megane.spawnEgg" : "Spawn Egg Icon", + "config.megane.catchServerErrors" : "Catch Server Errors", + "config.megane.catchServerErrors_desc": "§7Make errors on block/entity data provider not crashing the server but instead, just simply disable the data for that specific block/entity", + "megane.energy" : "Energy", + "megane.level" : "Level", + "megane.owner" : "Owner", + "megane.fluid.unknown" : "Unknown Fluid", + "megane.configToast.title" : "Megane Config Reset", + "megane.configToast.desc" : "Found version %d, not %d" }