Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property title could be a ChatMessage for generic containers #63

Open
ulcuber opened this issue May 12, 2022 · 1 comment
Open

Property title could be a ChatMessage for generic containers #63

ulcuber opened this issue May 12, 2022 · 1 comment

Comments

@ulcuber
Copy link

ulcuber commented May 12, 2022

Received raw json in title property and cannot call something line .toAnsi()

@ulcuber
Copy link
Author

ulcuber commented May 12, 2022

Current workaround:

let ChatMessage;

function getWindowTitle(window) {
  let title;
  try {
    title = JSON.parse(window.title);
  } catch {
    title = window.title;
  }

  return new ChatMessage(title);
}

const bot = mineflayer.createBot({
  host: host,
  port: port,
  username: username,
});

bot.once('spawn', async () => {
  ChatMessage = require('prismarine-chat')(bot.version);
});

bot.on('windowOpen', (window) => {
  const title = getWindowTitle(window);
  const msg = `Opened window ${title.toAnsi()} (${window.id}|${window.type})`;
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant