var stringToCode = require('../utils').stringToCode; var parseExtra = require('../parsers/extra'); module.exports = function(jsonMsg) { var buffer = ''; var color = stringToCode(jsonMsg.color); switch (jsonMsg.translate) { case 'chat.type.text': username = jsonMsg.with[0].text; msg = jsonMsg.with[1]; return '§' + color + '<'+username+'> ' + msg; case 'chat.type.announcement': sender = jsonMsg.with[0]; broadcast = parseExtra(jsonMsg.with[1].extra); return '§' + color + '['+sender+'] ' + broadcast; case 'commands.generic.notFound': return '§' + color + 'Unknown command. Try /help for a list of commands'; case 'commands.players.list': connected = jsonMsg.with[0]; max = jsonMsg.with[1]; return '§' + color + 'There are '+connected+'/'+max+' players online:'; case 'commands.help.header': current = jsonMsg.with[0]; pages = jsonMsg.with[1]; return '§' + color + '--- Showing help page '+current+' of '+pages+' (/help ) ---'; case 'commands.generic.usage': return '§' + color + 'Usage: ' + parseCommandUsage(jsonMsg.with[0].translate); case 'multiplayer.player.left': player = jsonMsg.with[0].text; return '§' + color + player + ' left the game'; case 'multiplayer.player.joined': player = jsonMsg.with[0].text; return '§' + color + player + ' joined the game'; case 'chat.type.admin': return '§' + color + '[' + jsonMsg.with[0] + ': ' + parseAdmin(jsonMsg.with[1]) + ']'; case 'death.attack.mob': victim = jsonMsg.with[0].text; killer = jsonMsg.with[1].text; return '§' + color + victim + ' was slain by ' + killer; case 'death.attack.arrow': victim = jsonMsg.with[0].text; killer = jsonMsg.with[1].text; return '§' + color + victim + ' was shot by ' + killer; case 'death.attack.player': victim = jsonMsg.with[0].text; killer = jsonMsg.with[1].text; return '§' + color + victim + ' was slain by ' + killer; case 'death.attack.explosion.player': victim = jsonMsg.with[0].text; killer = jsonMsg.with[1].text; return '§' + color + victim + ' was blown up by ' + killer; case 'chat.type.achievement': player = jsonMsg.with[0].text; achievement = jsonMsg.with[1].extra[0].translate; return '§' + color + player + ' has just earned the achievement ' + '§a['+parseAchievement(achievement)+']' ; } // if message is a command usage if (/^commands\..*usage$/.test(jsonMsg.translate)) { return '§' + color + parseCommandUsage(jsonMsg.translate); } }; function parseAdmin(command) { switch (command.translate) { case 'commands.downfall.success': return 'Toggled downfall'; case 'commands.op.success': return 'Opped ' + command.with[0]; case 'commands.tp.success': return 'Teleported ' + command.with[0] + ' to ' + command.with[1]; case 'commands.kill.successful': return 'Killed ' + command.with[0]; case 'commands.gamemode.success.other': player = command.with[0]; gamemode = command.with[1].translate.split('.')[1]; gamemode = gamemode.charAt(0).toUpperCase() + gamemode.slice(1); return 'Set ' + player + ' game mode to ' + gamemode + ' Mode'; default: return 'Unknown admin message'; } } function parseAchievement(achievementid) { var achievements = { 'achievement.acquireIron': 'Acquire Hardware', 'achievement.bakeCake': 'The Lie', 'achievement.blazeRod': 'Into Fire', 'achievement.bookcase': 'Librarian', 'achievement.breedCow': 'Repopulation', 'achievement.buildBetterPickaxe': 'Getting an Upgrade', 'achievement.buildFurnace': 'Hot Topic', 'achievement.buildHoe': 'Time to Farm!', 'achievement.buildPickaxe': 'Time to Mine!', 'achievement.buildSword': 'Time to Strike!', 'achievement.buildWorkBench': 'Benchmarking', 'achievement.cookFish': 'Delicious Fish', 'achievement.diamonds': 'DIAMONDS!', 'achievement.diamondsToYou': 'Diamonds to you!', 'achievement.enchantments': 'Enchanter', 'achievement.exploreAllBiomes': 'Adventuring Time', 'achievement.flyPig': 'When Pigs Fly', 'achievement.fullBeacon': 'Beaconator', 'achievement.get': 'Achievement get!', 'achievement.ghast': 'Return to Sender', 'achievement.killCow': 'Cow Tipper', 'achievement.killEnemy': 'Monster Hunter', 'achievement.killWither': 'The Beginning.', 'achievement.makeBread': 'Bake Bread', 'achievement.mineWood': 'Getting Wood', 'achievement.onARail': 'On A Rail', 'achievement.openInventory': 'Taking Inventory', 'achievement.overkill': 'Overkill', 'achievement.overpowered': 'Overpowered', 'achievement.portal': 'We Need to Go Deeper', 'achievement.potion': 'Local Brewery', 'achievement.snipeSkeleton': 'Sniper Duel', 'achievement.spawnWither': 'The Beginning?', 'achievement.taken': 'Taken!', 'achievement.theEnd': 'The End?', 'achievement.theEnd2': 'The End.', 'achievement.unknown': '???' }; return achievements[achievementid] || '???'; } function parseCommandUsage(commandId) { var commands = { 'commands.achievement.usage': '/achievement [player]', 'commands.ban.usage': '/ban [reason ...]', 'commands.banip.usage': '/ban-ip [reason ...]', 'commands.banlist.usage': '/banlist [ips|players]', 'commands.blockdata.usage': '/blockdata ', 'commands.chunkinfo.usage': '/chunkinfo [ ]', 'commands.clear.usage': '/clear [player] [item] [data] [maxCount] [dataTag]', 'commands.clone.usage': '/clone [mode]', 'commands.compare.usage': '/testforblocks [mode]', 'commands.defaultgamemode.usage': '/defaultgamemode ', 'commands.deop.usage': '/deop ', 'commands.difficulty.usage': '/difficulty ', 'commands.downfall.usage': '/toggledownfall', 'commands.effect.usage': '/effect [seconds] [amplifier] [hideParticles]', 'commands.enchant.usage': '/enchant [level]', 'commands.entitydata.usage': '/entitydata ', 'commands.execute.usage': '/execute OR /execute detect ', 'commands.fill.usage': '/fill [dataValue] [oldBlockHandling] [dataTag]', 'commands.gamemode.usage': '/gamemode [player]', 'commands.gamerule.usage': '/gamerule [value]', 'commands.give.usage': '/give [amount] [data] [dataTag]', 'commands.help.usage': '/help [page|command name]', 'commands.kick.usage': '/kick [reason ...]', 'commands.kill.usage': '/kill [player|entity]', 'commands.me.usage': '/me ', 'commands.message.usage': '/tell ', 'commands.op.usage': '/op ', 'commands.particle.usage': '/particle [count] [mode]', 'commands.players.usage': '/list', 'commands.playsound.usage': '/playsound [x] [y] [z] [volume] [pitch] [minimumVolume]', 'commands.publish.usage': '/publish', 'commands.replaceitem.block.usage': '/replaceitem block [amount] [data] [dataTag]', 'commands.replaceitem.entity.usage': '/replaceitem entity [amount] [data] [dataTag]', 'commands.replaceitem.usage': '/replaceitem ...', 'commands.save-off.usage': '/save-off', 'commands.save-on.usage': '/save-on', 'commands.save.usage': '/save-all', 'commands.say.usage': '/say ', 'commands.scoreboard.objectives.add.usage': '/scoreboard objectives add [display name ...]', 'commands.scoreboard.objectives.remove.usage': '/scoreboard objectives remove ', 'commands.scoreboard.objectives.setdisplay.usage': '/scoreboard objectives setdisplay [objective]', 'commands.scoreboard.objectives.usage': '/scoreboard objectives ...', 'commands.scoreboard.players.add.usage': '/scoreboard players add [dataTag]', 'commands.scoreboard.players.enable.usage': '/scoreboard players enable ', 'commands.scoreboard.players.list.usage': '/scoreboard players list [name]', 'commands.scoreboard.players.operation.usage': '/scoreboard players operation ', 'commands.scoreboard.players.remove.usage': '/scoreboard players remove [dataTag]', 'commands.scoreboard.players.reset.usage': '/scoreboard players reset [objective]', 'commands.scoreboard.players.set.usage': '/scoreboard players set [dataTag]', 'commands.scoreboard.players.test.usage': '/scoreboard players test ', 'commands.scoreboard.players.usage': '/scoreboard players ...', 'commands.scoreboard.teams.add.usage': '/scoreboard teams add [display name ...]', 'commands.scoreboard.teams.empty.usage': '/scoreboard teams empty ', 'commands.scoreboard.teams.join.usage': '/scoreboard teams join [player]', 'commands.scoreboard.teams.leave.usage': '/scoreboard teams leave [player]', 'commands.scoreboard.teams.list.usage': '/scoreboard teams list [name]', 'commands.scoreboard.teams.option.usage': '/scoreboard teams option ', 'commands.scoreboard.teams.remove.usage': '/scoreboard teams remove ', 'commands.scoreboard.teams.usage': '/scoreboard teams ...', 'commands.scoreboard.usage': '/scoreboard ...', 'commands.seed.usage': '/seed', 'commands.setblock.usage': '/setblock [dataValue] [oldBlockHandling] [dataTag]', 'commands.setidletimeout.usage': '/setidletimeout ', 'commands.setworldspawn.usage': '/setworldspawn [ ]', 'commands.spawnpoint.usage': '/spawnpoint [player] [ ]', 'commands.spreadplayers.usage': '/spreadplayers ', 'commands.stats.block.clear.usage': '/stats block clear ', 'commands.stats.block.set.usage': '/stats block set ', 'commands.stats.block.usage': '/stats block ...', 'commands.stats.entity.clear.usage': '/stats entity clear ', 'commands.stats.entity.set.usage': '/stats entity set ', 'commands.stats.entity.usage': '/stats entity ', 'commands.stats.usage': '/stats ...', 'commands.stop.usage': '/stop', 'commands.summon.usage': '/summon [x] [y] [z] [dataTag]', 'commands.tellraw.usage': '/tellraw ', 'commands.testfor.usage': '/testfor [dataTag]', 'commands.testforblock.usage': '/testforblock [dataValue] [dataTag]', 'commands.time.usage': '/time ', 'commands.title.usage': '/title ...', 'commands.title.usage.clear': '/title clear|reset', 'commands.title.usage.times': '/title times ', 'commands.title.usage.title': '/title title|subtitle ', 'commands.tp.usage': '/tp [target player] OR /tp [target player] [ ]', 'commands.trigger.usage': '/trigger ', 'commands.unban.usage': '/pardon ', 'commands.unbanip.usage': '/pardon-ip
', 'commands.weather.usage': '/weather [duration in seconds]', 'commands.whitelist.add.usage': '/whitelist add ', 'commands.whitelist.remove.usage': '/whitelist remove ', 'commands.whitelist.usage': '/whitelist ', 'commands.worldborder.add.usage': '/worldborder add [timeInSeconds]', 'commands.worldborder.center.usage': '/worldborder centre ', 'commands.worldborder.damage.amount.usage': '/worldborder damage amount ', 'commands.worldborder.damage.buffer.usage': '/worldborder damage buffer ', 'commands.worldborder.damage.usage': '/worldborder damage ', 'commands.worldborder.set.usage': '/worldborder set [timeInSeconds]', 'commands.worldborder.usage': '/worldborder ...', 'commands.worldborder.warning.distance.usage': '/worldborder warning distance ', 'commands.worldborder.warning.time.usage': '/worldborder warning time ', 'commands.worldborder.warning.usage': '/worldborder warning ', 'commands.xp.usage': '/xp [player] OR /xp L [player]' }; return commands[commandId] || 'Unknown command usage'; }