diff --git a/src/main/java/com/minecolonies/core/colony/ColonyManager.java b/src/main/java/com/minecolonies/core/colony/ColonyManager.java index 63c91a1685d..d1a455fe0d5 100755 --- a/src/main/java/com/minecolonies/core/colony/ColonyManager.java +++ b/src/main/java/com/minecolonies/core/colony/ColonyManager.java @@ -633,7 +633,14 @@ public void onWorldLoad(@NotNull final Level world) c.onWorldLoad(world); } - MinecraftForge.EVENT_BUS.post(new ColonyManagerLoadedEvent(this)); + try + { + MinecraftForge.EVENT_BUS.post(new ColonyManagerLoadedEvent(this)); + } + catch (final Exception e) + { + Log.getLogger().error("Error during ColonyManagerLoadedEvent", e); + } } } @@ -660,7 +667,14 @@ public void onWorldUnload(@NotNull final Level world) BackUpHelper.backupColonyData(); } - MinecraftForge.EVENT_BUS.post(new ColonyManagerUnloadedEvent(this)); + try + { + MinecraftForge.EVENT_BUS.post(new ColonyManagerUnloadedEvent(this)); + } + catch (final Exception e) + { + Log.getLogger().error("Error during ColonyManagerUnloadedEvent", e); + } } } @@ -689,7 +703,14 @@ public void handleColonyViewMessage( } view.handleColonyViewMessage(colonyData, world, isNewSubscription); - MinecraftForge.EVENT_BUS.post(new ColonyViewUpdatedEvent(view)); + try + { + MinecraftForge.EVENT_BUS.post(new ColonyViewUpdatedEvent(view)); + } + catch (final Exception e) + { + Log.getLogger().error("Error during ColonyViewUpdatedEvent", e); + } } @Override diff --git a/src/main/java/com/minecolonies/core/colony/crafting/CustomRecipeManager.java b/src/main/java/com/minecolonies/core/colony/crafting/CustomRecipeManager.java index 0335da2443a..ae2f1cdddd5 100644 --- a/src/main/java/com/minecolonies/core/colony/crafting/CustomRecipeManager.java +++ b/src/main/java/com/minecolonies/core/colony/crafting/CustomRecipeManager.java @@ -421,6 +421,13 @@ public void handleCustomRecipeManagerMessage(final FriendlyByteBuf buff) lootTables.put(id, drops); } - MinecraftForge.EVENT_BUS.post(new CustomRecipesReloadedEvent()); + try + { + MinecraftForge.EVENT_BUS.post(new CustomRecipesReloadedEvent()); + } + catch (final Exception e) + { + Log.getLogger().error("Error during CustomRecipesReloadedEvent", e); + } } } diff --git a/src/main/java/com/minecolonies/core/colony/interactionhandling/RecruitmentInteraction.java b/src/main/java/com/minecolonies/core/colony/interactionhandling/RecruitmentInteraction.java index 175a8797e52..bf80cd562b6 100644 --- a/src/main/java/com/minecolonies/core/colony/interactionhandling/RecruitmentInteraction.java +++ b/src/main/java/com/minecolonies/core/colony/interactionhandling/RecruitmentInteraction.java @@ -12,6 +12,7 @@ import com.minecolonies.api.colony.interactionhandling.IInteractionResponseHandler; import com.minecolonies.api.colony.interactionhandling.ModInteractionResponseHandlers; import com.minecolonies.api.util.InventoryUtils; +import com.minecolonies.api.util.Log; import com.minecolonies.api.util.MessageUtils; import com.minecolonies.api.util.Tuple; import com.minecolonies.api.util.constant.Constants; @@ -189,7 +190,14 @@ public void onServerResponseTriggered(final int responseId, final Player player, MessageUtils.format(MESSAGE_RECRUITMENT_SUCCESS, data.getName()).sendTo(colony).forAllPlayers(); } - MinecraftForge.EVENT_BUS.post(new CitizenAddedEvent(newCitizen, CitizenAddedEvent.Source.HIRED)); + try + { + MinecraftForge.EVENT_BUS.post(new CitizenAddedEvent(newCitizen, CitizenAddedEvent.Source.HIRED)); + } + catch (final Exception e) + { + Log.getLogger().error("Error during CitizenAddedEvent", e); + } } } else diff --git a/src/main/java/com/minecolonies/core/colony/managers/CitizenManager.java b/src/main/java/com/minecolonies/core/colony/managers/CitizenManager.java index 291bb747d01..b70d89af673 100755 --- a/src/main/java/com/minecolonies/core/colony/managers/CitizenManager.java +++ b/src/main/java/com/minecolonies/core/colony/managers/CitizenManager.java @@ -359,8 +359,14 @@ public ICitizenData resurrectCivilianData(@NotNull final CompoundTag compoundNBT citizens.put(citizenData.getId(), citizenData); spawnOrCreateCitizen(citizenData, world, spawnPos); - MinecraftForge.EVENT_BUS.post(new CitizenAddedEvent(citizenData, CitizenAddedEvent.Source.RESURRECTED)); - + try + { + MinecraftForge.EVENT_BUS.post(new CitizenAddedEvent(citizenData, CitizenAddedEvent.Source.RESURRECTED)); + } + catch (final Exception e) + { + Log.getLogger().error("Error during CitizenAddedEvent", e); + } return citizenData; } @@ -618,8 +624,14 @@ else if (femaleCount < (getCitizens().size() - 1) / 2.0) spawnOrCreateCivilian(newCitizen, colony.getWorld(), null, true); - MinecraftForge.EVENT_BUS.post(new CitizenAddedEvent(newCitizen, CitizenAddedEvent.Source.INITIAL)); - + try + { + MinecraftForge.EVENT_BUS.post(new CitizenAddedEvent(newCitizen, CitizenAddedEvent.Source.INITIAL)); + } + catch (final Exception e) + { + Log.getLogger().error("Error during CitizenAddedEvent", e); + } colony.getEventDescriptionManager().addEventDescription(new CitizenSpawnedEvent(colony.getBuildingManager().getTownHall().getPosition(), newCitizen.getName())); } diff --git a/src/main/java/com/minecolonies/core/commands/citizencommands/CommandCitizenSpawnNew.java b/src/main/java/com/minecolonies/core/commands/citizencommands/CommandCitizenSpawnNew.java index 9b731091cdb..0e8cddcbee6 100755 --- a/src/main/java/com/minecolonies/core/commands/citizencommands/CommandCitizenSpawnNew.java +++ b/src/main/java/com/minecolonies/core/commands/citizencommands/CommandCitizenSpawnNew.java @@ -4,6 +4,7 @@ import com.minecolonies.api.colony.IColony; import com.minecolonies.api.colony.IColonyManager; import com.minecolonies.api.colony.citizens.event.CitizenAddedEvent; +import com.minecolonies.api.util.Log; import com.minecolonies.core.commands.commandTypes.IMCCommand; import com.minecolonies.core.commands.commandTypes.IMCOPCommand; import com.mojang.brigadier.arguments.IntegerArgumentType; @@ -42,8 +43,14 @@ public int onExecute(final CommandContext context) final ICitizenData newCitizen = colony.getCitizenManager().spawnOrCreateCivilian(null, colony.getWorld(), null, true); context.getSource().sendSuccess(() -> Component.translatable(COMMAND_CITIZEN_SPAWN_SUCCESS, newCitizen.getName()), true); - MinecraftForge.EVENT_BUS.post(new CitizenAddedEvent(newCitizen, CitizenAddedEvent.Source.COMMANDS)); - + try + { + MinecraftForge.EVENT_BUS.post(new CitizenAddedEvent(newCitizen, CitizenAddedEvent.Source.COMMANDS)); + } + catch (final Exception e) + { + Log.getLogger().error("Error during CitizenAddedEvent", e); + } return 1; } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIStructureWithWorkOrder.java b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIStructureWithWorkOrder.java index 4c6ee8aade4..dd1881be270 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIStructureWithWorkOrder.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIStructureWithWorkOrder.java @@ -424,7 +424,14 @@ public void executeSpecificCompleteActions() if (wo instanceof WorkOrderBuilding) { final IBuilding building = colony.getBuildingManager().getBuilding(wo.getLocation()); - MinecraftForge.EVENT_BUS.post(new BuildingConstructionEvent(building, BuildingConstructionEvent.EventType.fromWorkOrderType(wo.getWorkOrderType()))); + try + { + MinecraftForge.EVENT_BUS.post(new BuildingConstructionEvent(building, BuildingConstructionEvent.EventType.fromWorkOrderType(wo.getWorkOrderType()))); + } + catch (final Exception e) + { + Log.getLogger().error("Error during BuildingConstructionEvent", e); + } switch (wo.getWorkOrderType()) { case BUILD: diff --git a/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java b/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java index 81355da1828..50f1c9d9d58 100755 --- a/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java +++ b/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java @@ -1642,7 +1642,14 @@ public void die(@NotNull final DamageSource damageSource) Component.literal(damageSource.getLocalizedDeathMessage(this).getString()).getString().replaceFirst(this.getDisplayName().getString(), "Citizen"); citizenColonyHandler.getColony().getEventDescriptionManager().addEventDescription(new CitizenDiedEvent(blockPosition(), citizenData.getName(), deathCause)); - MinecraftForge.EVENT_BUS.post(new CitizenRemovedEvent(citizenData, damageSource)); + try + { + MinecraftForge.EVENT_BUS.post(new CitizenRemovedEvent(citizenData, damageSource)); + } + catch (final Exception e) + { + Log.getLogger().error("Error during CitizenRemovedEvent", e); + } } super.die(damageSource); } diff --git a/src/main/java/com/minecolonies/core/network/messages/server/CreateColonyMessage.java b/src/main/java/com/minecolonies/core/network/messages/server/CreateColonyMessage.java index d3542557cd8..995c8bc45ab 100755 --- a/src/main/java/com/minecolonies/core/network/messages/server/CreateColonyMessage.java +++ b/src/main/java/com/minecolonies/core/network/messages/server/CreateColonyMessage.java @@ -6,6 +6,7 @@ import com.minecolonies.api.colony.buildings.IBuilding; import com.minecolonies.api.colony.event.ColonyCreatedEvent; import com.minecolonies.api.network.IMessage; +import com.minecolonies.api.util.Log; import com.minecolonies.core.Network; import com.minecolonies.core.network.messages.client.colony.OpenBuildingUIMessage; import com.minecolonies.core.tileentities.TileEntityColonyBuilding; @@ -189,10 +190,14 @@ else if (spawnDistance > MineColonies.getConfig().getServer().maxDistanceFromWor Network.getNetwork().sendToPlayer(new OpenBuildingUIMessage(building), sender); - if (isLogicalServer) + try { MinecraftForge.EVENT_BUS.post(new ColonyCreatedEvent(createdColony)); } + catch (final Exception e) + { + Log.getLogger().error("Error during ColonyCreatedEvent", e); + } return; } diff --git a/src/main/java/com/minecolonies/core/network/messages/server/colony/ColonyDeleteOwnMessage.java b/src/main/java/com/minecolonies/core/network/messages/server/colony/ColonyDeleteOwnMessage.java index 7a5f069af87..5adf8b4d2de 100755 --- a/src/main/java/com/minecolonies/core/network/messages/server/colony/ColonyDeleteOwnMessage.java +++ b/src/main/java/com/minecolonies/core/network/messages/server/colony/ColonyDeleteOwnMessage.java @@ -4,6 +4,7 @@ import com.minecolonies.api.colony.IColonyManager; import com.minecolonies.api.colony.event.ColonyDeletedEvent; import com.minecolonies.api.network.IMessage; +import com.minecolonies.api.util.Log; import net.minecraft.server.level.ServerPlayer; import net.minecraftforge.common.MinecraftForge; import net.minecraft.network.FriendlyByteBuf; @@ -55,7 +56,14 @@ public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalS if (isLogicalServer) { - MinecraftForge.EVENT_BUS.post(new ColonyDeletedEvent(colony)); + try + { + MinecraftForge.EVENT_BUS.post(new ColonyDeletedEvent(colony)); + } + catch (final Exception e) + { + Log.getLogger().error("Error during ColonyDeletedEvent", e); + } } } else diff --git a/src/main/java/com/minecolonies/core/network/messages/server/colony/ColonyFlagChangeMessage.java b/src/main/java/com/minecolonies/core/network/messages/server/colony/ColonyFlagChangeMessage.java index 70bd4a8eec9..a127e6613d4 100644 --- a/src/main/java/com/minecolonies/core/network/messages/server/colony/ColonyFlagChangeMessage.java +++ b/src/main/java/com/minecolonies/core/network/messages/server/colony/ColonyFlagChangeMessage.java @@ -2,6 +2,7 @@ import com.minecolonies.api.colony.IColony; import com.minecolonies.api.colony.event.ColonyInformationChangedEvent; +import com.minecolonies.api.util.Log; import com.minecolonies.api.util.constant.Constants; import com.minecolonies.core.network.messages.server.AbstractColonyServerMessage; import net.minecraft.nbt.CompoundTag; @@ -39,11 +40,14 @@ public ColonyFlagChangeMessage (IColony colony, ListTag patternList) protected void onExecute(NetworkEvent.Context ctxIn, boolean isLogicalServer, IColony colony) { colony.setColonyFlag(patterns); - - if (isLogicalServer) + try { MinecraftForge.EVENT_BUS.post(new ColonyInformationChangedEvent(colony, ColonyInformationChangedEvent.Type.FLAG)); } + catch (final Exception e) + { + Log.getLogger().error("Error during ColonyInformationChangedEvent", e); + } } @Override diff --git a/src/main/java/com/minecolonies/core/network/messages/server/colony/TeamColonyColorChangeMessage.java b/src/main/java/com/minecolonies/core/network/messages/server/colony/TeamColonyColorChangeMessage.java index a72bdfb113c..b54453ca333 100755 --- a/src/main/java/com/minecolonies/core/network/messages/server/colony/TeamColonyColorChangeMessage.java +++ b/src/main/java/com/minecolonies/core/network/messages/server/colony/TeamColonyColorChangeMessage.java @@ -3,6 +3,7 @@ import com.minecolonies.api.colony.IColony; import com.minecolonies.api.colony.buildings.views.IBuildingView; import com.minecolonies.api.colony.event.ColonyInformationChangedEvent; +import com.minecolonies.api.util.Log; import com.minecolonies.core.network.messages.server.AbstractColonyServerMessage; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.ChatFormatting; @@ -67,10 +68,13 @@ public void toBytesOverride(@NotNull final FriendlyByteBuf buf) protected void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony) { colony.setColonyColor(ChatFormatting.values()[colorOrdinal]); - - if (isLogicalServer) + try { MinecraftForge.EVENT_BUS.post(new ColonyInformationChangedEvent(colony, ColonyInformationChangedEvent.Type.TEAM_COLOR)); } + catch (final Exception e) + { + Log.getLogger().error("Error during ColonyInformationChangedEvent", e); + } } } diff --git a/src/main/java/com/minecolonies/core/network/messages/server/colony/TownHallRenameMessage.java b/src/main/java/com/minecolonies/core/network/messages/server/colony/TownHallRenameMessage.java index 17b139a5923..d2d94f7c951 100755 --- a/src/main/java/com/minecolonies/core/network/messages/server/colony/TownHallRenameMessage.java +++ b/src/main/java/com/minecolonies/core/network/messages/server/colony/TownHallRenameMessage.java @@ -3,6 +3,7 @@ import com.minecolonies.api.colony.IColony; import com.minecolonies.api.colony.IColonyView; import com.minecolonies.api.colony.event.ColonyInformationChangedEvent; +import com.minecolonies.api.util.Log; import com.minecolonies.core.Network; import com.minecolonies.core.network.messages.server.AbstractColonyServerMessage; import net.minecraft.network.FriendlyByteBuf; @@ -56,15 +57,13 @@ protected void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogic { name = (name.length() <= MAX_NAME_LENGTH) ? name : name.substring(0, SUBSTRING_LENGTH); colony.setName(name); - - if (ctxIn.getSender() != null) + try { - Network.getNetwork().sendToEveryone(this); + MinecraftForge.EVENT_BUS.post(new ColonyInformationChangedEvent(colony, ColonyInformationChangedEvent.Type.NAME)); } - - if (isLogicalServer) + catch (final Exception e) { - MinecraftForge.EVENT_BUS.post(new ColonyInformationChangedEvent(colony, ColonyInformationChangedEvent.Type.NAME)); + Log.getLogger().error("Error during ColonyInformationChangedEvent", e); } } } diff --git a/src/main/java/com/minecolonies/core/placementhandlers/main/SurvivalHandler.java b/src/main/java/com/minecolonies/core/placementhandlers/main/SurvivalHandler.java index b7f05ca0ce5..45864dd6693 100644 --- a/src/main/java/com/minecolonies/core/placementhandlers/main/SurvivalHandler.java +++ b/src/main/java/com/minecolonies/core/placementhandlers/main/SurvivalHandler.java @@ -174,7 +174,14 @@ public void handle( placementSettings.getMirror() != Mirror.NONE, packName, blueprintPath); - MinecraftForge.EVENT_BUS.post(new BlockEvent.EntityPlaceEvent(BlockSnapshot.create(world.dimension(), world, blockPos), world.getBlockState(blockPos.below()), player)); + try + { + MinecraftForge.EVENT_BUS.post(new BlockEvent.EntityPlaceEvent(BlockSnapshot.create(world.dimension(), world, blockPos), world.getBlockState(blockPos.below()), player)); + } + catch (final Exception e) + { + Log.getLogger().error("Error during EntityPlaceEvent", e); + } InventoryUtils.reduceStackInItemHandler(new InvWrapper(player.getInventory()), inventoryStack, 1); if (tempColony == null)