friendlyhj/ZenUtils

`reward.quest.title` not working on server

Closed this issue · 5 comments

I want to make global notification when player finishing important quest.

My ZS code sending global message in chat, so everyone on server knows progress of other players.

There is my code: https://github.com/Krutoy242/Enigmatica2Expert-Extended/blob/5307a7e9483b9191ea83b196b9c3615745e16536/scripts/mods/ftbquests_custom_rewards.zs#L48

Im using events.onCustomReward and getting e.reward.quest.title for quest title.

Seems like (but not sure) since i have lang entries instead of actual titles {q.gates.conflux_i.name}, ftbquests try to translate it but unable to and print this error into crafttweaker.log:

[SERVER_STARTED][SERVER][ERROR] net/minecraft/client/resources/I18n
java.lang.NoClassDefFoundError: net/minecraft/client/resources/I18n
	at com.feed_the_beast.ftbquests.quest.QuestObjectBase.getTitle(QuestObjectBase.java:378)
	at youyihj.zenutils.api.ftbq.CTQuestObjectBase.getTitle(CTQuestObjectBase.java:39)
	at CrafttweakerReloadablemods\Ftbquests_custom_rewards186.handle(mods/ftbquests_custom_rewards.zs:48)
	at CrafttweakerReloadablemods\Ftbquests_custom_rewards186.handle(mods/ftbquests_custom_rewards.zs)
	at crafttweaker.util.EventList.publish(EventList.java:51)
	at youyihj.zenutils.api.ftbq.FTBQEventManager$Handler.onCustomReward(FTBQEventManager.java:104)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_1374_Handler_onCustomReward_CustomRewardEvent.invoke(.dynamic)

How i can fix this error? Is this means i cant notify players with lang entries, since lang can only being translated on clients?

Probably it would make sense to have special getter to get raw lang data of text fields, like e.reward.quest.titleRaw.

Maybe im using it wrong, but i still see untranslated entries.

There is my code:

  /**
  * Endorse player with message to whole server as its finished chapter
  */
  if (e.reward.tags has 'chapcomplete') {
    server.commandManager.executeCommandSilent(server,
      '/say §l' ~ e.player.name
      ~ '§r has fully completed the §n' ~ e.reward.quest.chapter.titleText.formattedText
      ~ '§r chapter after §l' ~ formatPlayTime(e.player) ~ '§r of play!§r ```Congrats!```'
    );
  }

Im using command /say because I need my Discord Bot to show in discord chat that player finished chapter.

But server on .titleText.formattedText returning lang entry instead of real chapter name.
Also, players see in chat lang entry instead of translated name too.

image

Do not use formattedText getter on server side. Pass the text component in ICommandSender#sendRichTextMessage

In your use case, in lang files e2ee.congratulation=%s has fully completed the %s chapter after %s of play! Congrats!

in script

player.sendRichTextMessage(ITextComponent.fromTranslation("e2ee.congratulation", [player.name, e.reward.quest.chapter.titleText, formatPlayTime(e.player)])

For the sake of history, for someone who will find this issue on similar task, there is a code that send message to all players, translating it even on server side, making nice messages in discord.

The key is server.broadcastMessage function.
titleCode is something like e.reward.quest.chapter.titleText.formattedText.

function notifyEveryone(player as IPlayer, langCode as string, titleCode as string) as string {
  server.broadcastMessage(crafttweaker.text.ITextComponent.fromData([{
    translate: langCode,
    with     : [
      player.name,
      { translate: titleCode },
      formatPlayTime(player)
  ]}]));
}

image