diff --git a/package.json b/package.json index b9b8d8f..fdc0fca 100644 --- a/package.json +++ b/package.json @@ -57,8 +57,8 @@ "devDependencies": { "jest": "^22.1.4", "longjohn": "^0.2.12", - "mineflayer": "^2.6.1", + "mineflayer": "^2.7.3", "require-self": "^0.2.1", - "standard": "^11.0.1" + "standard": "^12.0.1" } } diff --git a/src/lib/experience.js b/src/lib/experience.js index a293c09..c6209e7 100644 --- a/src/lib/experience.js +++ b/src/lib/experience.js @@ -1,4 +1,4 @@ -module.exports = {distanceToXpLevel, getXpLevel, getXpRequired, getBaseXpFromLevel} +module.exports = { distanceToXpLevel, getXpLevel, getXpRequired, getBaseXpFromLevel } function distanceToXpLevel (xp, toLevel) { const level = getXpLevel(xp) diff --git a/src/lib/plugins/animations.js b/src/lib/plugins/animations.js index 7d8364d..89cb92e 100644 --- a/src/lib/plugins/animations.js +++ b/src/lib/plugins/animations.js @@ -8,16 +8,16 @@ module.exports.player = function (player) { }) ) - player._client.on('entity_action', ({actionId} = {}) => { + player._client.on('entity_action', ({ actionId } = {}) => { if (actionId === 3) { - player.setAndUpdateMetadata([{'key': 0, 'type': 0, 'value': 0x08}]) + player.setAndUpdateMetadata([{ 'key': 0, 'type': 0, 'value': 0x08 }]) } else if (actionId === 4) { - player.setAndUpdateMetadata([{'key': 0, 'type': 0, 'value': 0x00}]) + player.setAndUpdateMetadata([{ 'key': 0, 'type': 0, 'value': 0x00 }]) } else if (actionId === 0) { - player.setAndUpdateMetadata([{'key': 0, 'type': 0, 'value': 0x02}]) + player.setAndUpdateMetadata([{ 'key': 0, 'type': 0, 'value': 0x02 }]) player.crouching = true } else if (actionId === 1) { - player.setAndUpdateMetadata([{'key': 0, 'type': 0, 'value': 0x00}]) + player.setAndUpdateMetadata([{ 'key': 0, 'type': 0, 'value': 0x00 }]) player.crouching = false } }) diff --git a/src/lib/plugins/blocks.js b/src/lib/plugins/blocks.js index 3220650..2fed172 100644 --- a/src/lib/plugins/blocks.js +++ b/src/lib/plugins/blocks.js @@ -15,7 +15,7 @@ module.exports.player = function (player, serv) { position: position, blockType: blockType, blockData: blockData - }, ({position, blockType, blockData}) => { + }, ({ position, blockType, blockData }) => { player._client.write('block_change', { location: position, type: blockType << 4 | blockData diff --git a/src/lib/plugins/chat.js b/src/lib/plugins/chat.js index 991ace9..22bda30 100644 --- a/src/lib/plugins/chat.js +++ b/src/lib/plugins/chat.js @@ -1,5 +1,5 @@ module.exports.server = function (serv) { - serv.broadcast = (message, {whitelist = serv.players, blacklist = [], system = false} = {}) => { + serv.broadcast = (message, { whitelist = serv.players, blacklist = [], system = false } = {}) => { if (whitelist.type === 'player') whitelist = [whitelist] if (typeof message === 'string') message = serv.parseClassic(message) @@ -120,9 +120,9 @@ module.exports.server = function (serv) { } module.exports.player = function (player, serv) { - player._client.on('chat', ({message} = {}) => { + player._client.on('chat', ({ message } = {}) => { if (message[0] === '/') { - player.behavior('command', {command: message.slice(1)}, ({command}) => player.handleCommand(command)) + player.behavior('command', { command: message.slice(1) }, ({ command }) => player.handleCommand(command)) } else { player.behavior('chat', { message: message, @@ -130,7 +130,7 @@ module.exports.player = function (player, serv) { text: message, whitelist: serv.players, blacklist: [] - }, ({prefix, text, whitelist, blacklist}) => { + }, ({ prefix, text, whitelist, blacklist }) => { const obj = serv.parseClassic(prefix) if (!obj.extra) obj.extra = [] obj.extra.push(serv.parseClassic(text)) diff --git a/src/lib/plugins/commands.js b/src/lib/plugins/commands.js index 4cccfa5..1e32cf4 100644 --- a/src/lib/plugins/commands.js +++ b/src/lib/plugins/commands.js @@ -1,6 +1,6 @@ const UserError = require('flying-squid').UserError -module.exports.player = function (player, serv, {version}) { +module.exports.player = function (player, serv, { version }) { player.commands.add({ base: 'help', info: 'to show all commands', @@ -14,7 +14,7 @@ module.exports.player = function (player, serv, {version}) { const search = params.join(' ') return { search: search, page: (page && page - 1) || 0 } }, - action ({search, page}) { + action ({ search, page }) { if (page < 0) return 'Page # must be >= 1' const hash = player.commands.uniqueHash @@ -247,7 +247,7 @@ module.exports.server = function (serv) { opt.forEach(o => { const match = o.match(/^([^=]+)=([^=]+)$/) if (match === null) err = new UserError('Invalid selector option format: "' + o + '"') - else optPair.push({key: match[1], val: match[2]}) + else optPair.push({ key: match[1], val: match[2] }) }) if (err) throw err @@ -275,7 +275,7 @@ module.exports.server = function (serv) { minScores: [] } - optPair.forEach(({key, val}) => { + optPair.forEach(({ key, val }) => { if (['x', 'y', 'z'].indexOf(key) !== -1) pos[key] = val else if (!optConversion[key]) { data[key] = val diff --git a/src/lib/plugins/communication.js b/src/lib/plugins/communication.js index 00d6380..6c90184 100644 --- a/src/lib/plugins/communication.js +++ b/src/lib/plugins/communication.js @@ -8,12 +8,12 @@ module.exports.server = function (serv) { serv._writeNearby = (packetName, packetFields, loc) => serv._writeArray(packetName, packetFields, serv.getNearby(loc)) - serv.getNearby = ({world, position, radius = 8 * 16}) => serv.players.filter(player => + serv.getNearby = ({ world, position, radius = 8 * 16 }) => serv.players.filter(player => player.world === world && player.position.distanceTo(position) <= radius ) - serv.getNearbyEntities = ({world, position, radius = 8 * 16}) => Object.keys(serv.entities) + serv.getNearbyEntities = ({ world, position, radius = 8 * 16 }) => Object.keys(serv.entities) .map(eId => serv.entities[eId]) .filter(entity => entity.world === world && diff --git a/src/lib/plugins/daycycle.js b/src/lib/plugins/daycycle.js index 67e56c8..2a17926 100644 --- a/src/lib/plugins/daycycle.js +++ b/src/lib/plugins/daycycle.js @@ -17,7 +17,7 @@ module.exports.server = function (serv) { serv.behavior('changeTime', { old: serv.time, newTime: serv.time + 20 - }, ({newTime}) => { + }, ({ newTime }) => { serv.setTime(newTime % 24000) // Vanilla only does it every second }) } @@ -48,7 +48,7 @@ module.exports.player = function (player, serv) { value: data[2] === 'day' ? 1000 : (data[2] === 'night' ? 13000 : parseInt(data[2])) } }, - action ({action, value}) { + action ({ action, value }) { if (action === 'query') { player.chat('It is ' + serv.time) } else { diff --git a/src/lib/plugins/digging.js b/src/lib/plugins/digging.js index a2e3e3b..71f54bf 100644 --- a/src/lib/plugins/digging.js +++ b/src/lib/plugins/digging.js @@ -1,11 +1,11 @@ const Vec3 = require('vec3').Vec3 module.exports.player = function (player, serv) { - function cancelDig ({position, block}) { + function cancelDig ({ position, block }) { player.sendBlock(position, block.type, block.metadata) } - player._client.on('block_dig', async ({location, status, face}) => { + player._client.on('block_dig', async ({ location, status, face }) => { let pos = new Vec3(location.x, location.y, location.z) const directionVector = directionToVector[face] @@ -25,14 +25,14 @@ module.exports.player = function (player, serv) { player.behavior('dig', { // Start dig survival position: pos, block: block - }, ({position}) => { + }, ({ position }) => { return startDigging(position) }, cancelDig) } else if (status === 2) { completeDigging(pos) } else if (status === 1) { player.behavior('cancelDig', { // Cancel dig survival position: pos, block: block - }, ({position}) => { + }, ({ position }) => { return cancelDigging(position) }) } else if (status === 0 && player.gameMode === 1) { return creativeDigging(pos) } @@ -71,7 +71,7 @@ module.exports.player = function (player, serv) { start: startDigging, timePassed: currentDiggingTime, position: location - }, ({state}) => { + }, ({ state }) => { lastDestroyState = state player._writeOthersNearby('block_break_animation', { 'entityId': currentAnimationId, @@ -127,7 +127,7 @@ module.exports.player = function (player, serv) { } } - function dropBlock ({blockDropPosition, blockDropWorld, blockDropVelocity, blockDropId, blockDropDamage, blockDropPickup, blockDropDeath}) { + function dropBlock ({ blockDropPosition, blockDropWorld, blockDropVelocity, blockDropId, blockDropDamage, blockDropPickup, blockDropDeath }) { serv.spawnObject(2, blockDropWorld, blockDropPosition, { velocity: blockDropVelocity, itemId: blockDropId, diff --git a/src/lib/plugins/effects.js b/src/lib/plugins/effects.js index 29f8e39..d182afe 100644 --- a/src/lib/plugins/effects.js +++ b/src/lib/plugins/effects.js @@ -5,7 +5,7 @@ module.exports.entity = function (entity, serv) { entity.effects[i] = null // Just so we know it's a real potion and not undefined/not existant } - entity.sendEffect = (effectId, {amplifier = 0, duration = 30 * 20, particles = true, whitelist, blacklist = []} = {}) => { + entity.sendEffect = (effectId, { amplifier = 0, duration = 30 * 20, particles = true, whitelist, blacklist = [] } = {}) => { if (!whitelist) whitelist = serv.getNearby(entity) if (entity.type === 'player' && [1].indexOf(effectId) !== -1) entity.sendAbilities() const sendTo = whitelist.filter(p => blacklist.indexOf(p) === -1) @@ -19,7 +19,7 @@ module.exports.entity = function (entity, serv) { serv._writeArray('entity_effect', data, sendTo) } - entity.sendRemoveEffect = (effectId, {whitelist, blacklist = []} = {}) => { + entity.sendRemoveEffect = (effectId, { whitelist, blacklist = [] } = {}) => { if (!whitelist) whitelist = serv.getNearby(entity) const sendTo = whitelist.filter(p => blacklist.indexOf(p) === -1) serv._writeArray('remove_entity_effect', { diff --git a/src/lib/plugins/experience.js b/src/lib/plugins/experience.js index 84b3ed7..6247964 100644 --- a/src/lib/plugins/experience.js +++ b/src/lib/plugins/experience.js @@ -1,4 +1,4 @@ -const {distanceToXpLevel, getXpLevel, getBaseXpFromLevel} = require('flying-squid').experience +const { distanceToXpLevel, getXpLevel, getBaseXpFromLevel } = require('flying-squid').experience module.exports.player = function (player, serv) { player.xp = 0 diff --git a/src/lib/plugins/inventory.js b/src/lib/plugins/inventory.js index baea57a..2e98d77 100644 --- a/src/lib/plugins/inventory.js +++ b/src/lib/plugins/inventory.js @@ -1,6 +1,6 @@ const Vec3 = require('vec3') -module.exports.player = function (player, serv, {version}) { +module.exports.player = function (player, serv, { version }) { const Item = require('prismarine-item')(version) const windows = require('prismarine-windows')(version).windows @@ -8,7 +8,7 @@ module.exports.player = function (player, serv, {version}) { player.heldItem = new Item(256, 1) player.inventory = new windows.InventoryWindow(0, 'Inventory', 44) - player._client.on('held_item_slot', ({slotId} = {}) => { + player._client.on('held_item_slot', ({ slotId } = {}) => { player.heldItemSlot = slotId player.setEquipment(0, player.inventory.slots[36 + player.heldItemSlot]) @@ -143,7 +143,7 @@ module.exports.player = function (player, serv, {version}) { } }) - player._client.on('set_creative_slot', ({slot, item} = {}) => { + player._client.on('set_creative_slot', ({ slot, item } = {}) => { if (item.blockId === -1) { player.inventory.updateSlot(slot, undefined) return diff --git a/src/lib/plugins/log.js b/src/lib/plugins/log.js index 46940f6..f91ddf7 100644 --- a/src/lib/plugins/log.js +++ b/src/lib/plugins/log.js @@ -49,7 +49,7 @@ module.exports.player = function (player, serv) { player.on('disconnected', () => serv.log('[INFO]: ' + player.username + ' disconnected')) - player.on('chat', ({message}) => serv.log('[INFO] ' + '<' + player.username + '>' + ' ' + message)) + player.on('chat', ({ message }) => serv.log('[INFO] ' + '<' + player.username + '>' + ' ' + message)) player.on('kicked', (kicker, reason) => serv.log(kicker.username + ' kicked ' + player.username + (reason ? ' (' + reason + ')' : ''))) diff --git a/src/lib/plugins/moderation.js b/src/lib/plugins/moderation.js index 46cb785..d997977 100644 --- a/src/lib/plugins/moderation.js +++ b/src/lib/plugins/moderation.js @@ -89,7 +89,7 @@ module.exports.player = function (player, serv) { reason: parts.join(' ') } }, - action ({username, reason}) { + action ({ username, reason }) { const kickPlayer = serv.getPlayer(username) if (!kickPlayer) { player.chat(username + ' is not on this server!') @@ -113,7 +113,7 @@ module.exports.player = function (player, serv) { reason: parts.join(' ') } }, - action ({username, reason}) { + action ({ username, reason }) { const banPlayer = serv.getPlayer(username) if (!banPlayer) { @@ -148,7 +148,7 @@ module.exports.player = function (player, serv) { reason: argv.shift() } }, - action ({IP, reason}) { + action ({ IP, reason }) { serv.banIP(IP, reason) player.chat('' + IP + ' was IP banned') } diff --git a/src/lib/plugins/particle.js b/src/lib/plugins/particle.js index bcbc1db..51ae678 100644 --- a/src/lib/plugins/particle.js +++ b/src/lib/plugins/particle.js @@ -1,7 +1,7 @@ const Vec3 = require('vec3').Vec3 module.exports.server = function (serv) { - serv.emitParticle = (particle, world, position, {whitelist, blacklist = [], radius = 32, longDistance = true, size = new Vec3(1, 1, 1), count = 1} = {}) => { + serv.emitParticle = (particle, world, position, { whitelist, blacklist = [], radius = 32, longDistance = true, size = new Vec3(1, 1, 1), count = 1 } = {}) => { const players = (typeof whitelist !== 'undefined' ? (whitelist instanceof Array ? whitelist : [whitelist]) : serv.getNearby({ world: world, position: position, @@ -39,13 +39,13 @@ module.exports.player = function (player, serv) { size: results[5] ? new Vec3(parseInt(results[3]), parseInt(results[4]), parseInt(results[5])) : new Vec3(1, 1, 1) } }, - action ({particle, amount, size}) { + action ({ particle, amount, size }) { if (amount >= 100000) { player.chat('You cannot emit more than 100,000 particles!') return } player.chat('Emitting "' + particle + '" (count: ' + amount + ', size: ' + size.toString() + ')') - serv.emitParticle(particle, player.world, player.position, {count: amount, size: size}) + serv.emitParticle(particle, player.world, player.position, { count: amount, size: size }) } }) } diff --git a/src/lib/plugins/physics.js b/src/lib/plugins/physics.js index d19e2e8..a1b1f96 100644 --- a/src/lib/plugins/physics.js +++ b/src/lib/plugins/physics.js @@ -1,6 +1,6 @@ const Vec3 = require('vec3').Vec3 -module.exports.entity = function (entity, serv, {version}) { +module.exports.entity = function (entity, serv, { version }) { const blocks = require('minecraft-data')(version).blocks entity.calculatePhysics = async (delta) => { diff --git a/src/lib/plugins/placeBlock.js b/src/lib/plugins/placeBlock.js index 3436b30..691bc85 100644 --- a/src/lib/plugins/placeBlock.js +++ b/src/lib/plugins/placeBlock.js @@ -10,10 +10,10 @@ const materialToSound = { 'wood': 'wood' } -module.exports.player = function (player, serv, {version}) { +module.exports.player = function (player, serv, { version }) { const blocks = require('minecraft-data')(version).blocks - player._client.on('block_place', ({direction, location} = {}) => { + player._client.on('block_place', ({ direction, location } = {}) => { const heldItem = player.inventory.slots[36 + player.heldItemSlot] if (direction === -1 || heldItem.type === -1 || !blocks[heldItem.type]) return const referencePosition = new Vec3(location.x, location.y, location.z) @@ -28,7 +28,7 @@ module.exports.player = function (player, serv, {version}) { reference: referencePosition, playSound: true, sound: 'dig.' + (materialToSound[blocks[heldItem.type].material] || 'stone') - }, ({direction, heldItem, position, playSound, sound, id, damage}) => { + }, ({ direction, heldItem, position, playSound, sound, id, damage }) => { if (playSound) { serv.playSound(sound, player.world, placedPosition.clone().add(new Vec3(0.5, 0.5, 0.5)), { pitch: 0.8 diff --git a/src/lib/plugins/players.js b/src/lib/plugins/players.js index 6104628..d1b2513 100644 --- a/src/lib/plugins/players.js +++ b/src/lib/plugins/players.js @@ -38,7 +38,7 @@ module.exports.player = function (player, serv) { return parseInt(str) }, action (diff) { - serv._writeAll('difficulty', {difficulty: diff}) + serv._writeAll('difficulty', { difficulty: diff }) serv.difficulty = diff } }) diff --git a/src/lib/plugins/portal.js b/src/lib/plugins/portal.js index 902a9c2..6db7d78 100644 --- a/src/lib/plugins/portal.js +++ b/src/lib/plugins/portal.js @@ -1,8 +1,8 @@ const Vec3 = require('vec3').Vec3 const UserError = require('flying-squid').UserError -module.exports.player = function (player, serv, {version}) { - const {detectFrame, generatePortal, addPortalToWorld} = require('flying-squid').portal_detector(version) +module.exports.player = function (player, serv, { version }) { + const { detectFrame, generatePortal, addPortalToWorld } = require('flying-squid').portal_detector(version) player.use_flint_and_steel = async (referencePosition, direction, position) => { let block = await player.world.getBlock(referencePosition) @@ -18,7 +18,7 @@ module.exports.player = function (player, serv, {version}) { player.changeBlock(position, 51, 0) } - player.on('dug', ({position, block}) => { + player.on('dug', ({ position, block }) => { function destroyPortal (portal, positionAlreadyDone = null) { player.world.portals = player.world.portals.splice(player.world.portals.indexOf(portal), 1) portal @@ -28,14 +28,14 @@ module.exports.player = function (player, serv, {version}) { } if (block.name === 'obsidian') { - const p = player.world.portals.filter(({bottom, top, left, right}) => + const p = player.world.portals.filter(({ bottom, top, left, right }) => [].concat([], [bottom, left, right, top]) .reduce((acc, pos) => acc || pos.equals(position), false)) p.forEach(portal => destroyPortal(portal, position)) } if (block.name === 'portal') { - const p = player.world.portals.filter(({air}) => air.reduce((acc, pos) => acc || pos.equals(position), false)) + const p = player.world.portals.filter(({ air }) => air.reduce((acc, pos) => acc || pos.equals(position), false)) p.forEach(portal => destroyPortal(portal, position)) } }) @@ -53,9 +53,9 @@ module.exports.player = function (player, serv, {version}) { const bottomLeft = new Vec3(x, y, z) if (direction !== 'x' && direction !== 'z') { throw new UserError('Wrong Direction') } direction = direction === 'x' ? new Vec3(1, 0, 0) : new Vec3(0, 0, 1) - return {bottomLeft, direction, width, height} + return { bottomLeft, direction, width, height } }, - async action ({bottomLeft, direction, width, height}) { + async action ({ bottomLeft, direction, width, height }) { if (width > 21 || height > 21) { throw new UserError('Portals can only be 21x21!') } const portal = generatePortal(bottomLeft, direction, width, height) await addPortalToWorld(player.world, portal, [], [], async (pos, type) => { diff --git a/src/lib/plugins/pvp.js b/src/lib/plugins/pvp.js index 2f690d4..a938f23 100644 --- a/src/lib/plugins/pvp.js +++ b/src/lib/plugins/pvp.js @@ -21,7 +21,7 @@ module.exports.player = function (player, serv) { }, (o) => o.attackedEntity.takeDamage(o)) } - player._client.on('use_entity', ({mouse, target} = {}) => { + player._client.on('use_entity', ({ mouse, target } = {}) => { if (!serv.entities[target]) { let dragon for (dragon = target - 1; dragon >= target - 7 && !serv.entities[dragon]; dragon--) {} @@ -42,13 +42,13 @@ module.exports.player = function (player, serv) { let arr = player.selectorString(sel) if (arr.length === 0) throw new UserError('Could not find player') - arr.map(entity => entity.takeDamage({damage: 20})) + arr.map(entity => entity.takeDamage({ damage: 20 })) } }) } module.exports.entity = function (entity, serv) { - entity.takeDamage = ({sound = 'game.player.hurt', damage = 1, velocity = new Vec3(0, 0, 0), maxVelocity = new Vec3(4, 4, 4), animation = true}) => { + entity.takeDamage = ({ sound = 'game.player.hurt', damage = 1, velocity = new Vec3(0, 0, 0), maxVelocity = new Vec3(4, 4, 4), animation = true }) => { entity.updateHealth(entity.health - damage) serv.playSound(sound, entity.world, entity.position) diff --git a/src/lib/plugins/settings.js b/src/lib/plugins/settings.js index 84be543..b044d1f 100644 --- a/src/lib/plugins/settings.js +++ b/src/lib/plugins/settings.js @@ -31,7 +31,7 @@ module.exports.player = async function (player, serv) { player.findSpawnPoint = async () => { player.spawnPoint = await serv.getSpawnPoint(player.world) } - player._client.on('settings', ({viewDistance}) => { + player._client.on('settings', ({ viewDistance }) => { player.view = viewDistance }) } diff --git a/src/lib/plugins/sound.js b/src/lib/plugins/sound.js index bc8a907..b0c0673 100644 --- a/src/lib/plugins/sound.js +++ b/src/lib/plugins/sound.js @@ -1,7 +1,7 @@ const Vec3 = require('vec3').Vec3 module.exports.server = function (serv) { - serv.playSound = (sound, world, position, {whitelist, blacklist = [], radius = 32, volume = 1.0, pitch = 1.0, soundCategory = 0} = {}) => { + serv.playSound = (sound, world, position, { whitelist, blacklist = [], radius = 32, volume = 1.0, pitch = 1.0, soundCategory = 0 } = {}) => { const players = (typeof whitelist !== 'undefined' ? (typeof whitelist instanceof Array ? whitelist : [whitelist]) : serv.getNearby({ world: world, position: position, @@ -24,7 +24,7 @@ module.exports.server = function (serv) { }) } - serv.playNoteBlock = (pitch, world, position, {instrument = 'harp', particle = true} = {}) => { + serv.playNoteBlock = (pitch, world, position, { instrument = 'harp', particle = true } = {}) => { if (particle) { serv.emitParticle(23, world, position.clone().add(new Vec3(0.5, 1.5, 0.5)), { count: 1, @@ -43,7 +43,7 @@ module.exports.player = function (player, serv) { serv.playSound(sound, player.world, null, opt) } - player.on('placeBlock_cancel', async ({reference}, cancel) => { + player.on('placeBlock_cancel', async ({ reference }, cancel) => { if (player.crouching) return const id = await player.world.getBlockType(reference) if (id !== 25) return @@ -56,7 +56,7 @@ module.exports.player = function (player, serv) { serv.playNoteBlock(data.note, player.world, reference) }) - player.on('dig_cancel', async ({position}, cancel) => { + player.on('dig_cancel', async ({ position }, cancel) => { const id = await player.world.getBlockType(position) if (id !== 25) return cancel(false) @@ -82,7 +82,7 @@ module.exports.player = function (player, serv) { }, action (action) { player.chat('Playing "' + action.sound_name + '" (volume: ' + action.volume + ', pitch: ' + action.pitch + ')') - player.playSound(action.sound_name, {volume: action.volume, pitch: action.pitch}) + player.playSound(action.sound_name, { volume: action.volume, pitch: action.pitch }) } }) @@ -102,7 +102,7 @@ module.exports.player = function (player, serv) { }, action (action) { player.chat('Playing "' + action.sound_name + '" (volume: ' + action.volume + ', pitch: ' + action.pitch + ')') - serv.playSound(action.sound_name, player.world, player.position, {volume: action.volume, pitch: action.pitch}) + serv.playSound(action.sound_name, player.world, player.position, { volume: action.volume, pitch: action.pitch }) } }) } diff --git a/src/lib/plugins/spawn.js b/src/lib/plugins/spawn.js index 1f2131c..943f861 100644 --- a/src/lib/plugins/spawn.js +++ b/src/lib/plugins/spawn.js @@ -28,7 +28,7 @@ module.exports.server = function (serv, options) { return entity } - serv.spawnObject = (type, world, position, {pitch = 0, yaw = 0, velocity = new Vec3(0, 0, 0), data = 1, itemId, itemDamage = 0, pickupTime = undefined, deathTime = undefined}) => { + serv.spawnObject = (type, world, position, { pitch = 0, yaw = 0, velocity = new Vec3(0, 0, 0), data = 1, itemId, itemDamage = 0, pickupTime = undefined, deathTime = undefined }) => { const object = serv.initEntity('object', type, world, position) object.uuid = UUID.v4() object.name = objectsById[type].name @@ -48,7 +48,7 @@ module.exports.server = function (serv, options) { object.updateAndSpawn() } - serv.spawnMob = (type, world, position, {pitch = 0, yaw = 0, headPitch = 0, velocity = new Vec3(0, 0, 0), metadata = []} = {}) => { + serv.spawnMob = (type, world, position, { pitch = 0, yaw = 0, headPitch = 0, velocity = new Vec3(0, 0, 0), metadata = [] } = {}) => { const mob = serv.initEntity('mob', type, world, position) mob.uuid = UUID.v4() mob.name = mobsById[type].name @@ -112,9 +112,9 @@ module.exports.player = function (player, serv, options) { parse (str) { const args = str.split(' ') if (args.length !== 2) { return false } - return {number: args[0], name: args[1]} + return { number: args[0], name: args[1] } }, - action ({number, name}) { + action ({ number, name }) { if (Object.keys(serv.entities).length > options['max-entities'] - number) { throw new UserError('Too many mobs !') } const entity = entitiesByName[name] if (!entity) { @@ -182,9 +182,9 @@ module.exports.player = function (player, serv, options) { let attached = player.selectorString(args[1]) if (attached.length === 0) throw new UserError('one attached') - return {carrier: carrier[0], attached: attached[0]} + return { carrier: carrier[0], attached: attached[0] } }, - action ({carrier, attached}) { + action ({ carrier, attached }) { carrier.attach(attached) } }) diff --git a/src/lib/plugins/stats.js b/src/lib/plugins/stats.js index e10fdfe..6099ae5 100644 --- a/src/lib/plugins/stats.js +++ b/src/lib/plugins/stats.js @@ -1,5 +1,5 @@ module.exports.player = function (player) { - player._client.on('client_command', ({payload} = {}) => { + player._client.on('client_command', ({ payload } = {}) => { if (payload === 1) { // WIP: dummy player.system('WIP, press ESC') diff --git a/src/lib/plugins/updatePositions.js b/src/lib/plugins/updatePositions.js index 43665a0..7947d46 100644 --- a/src/lib/plugins/updatePositions.js +++ b/src/lib/plugins/updatePositions.js @@ -1,7 +1,7 @@ const Vec3 = require('vec3').Vec3 module.exports.player = function (player) { - player._client.on('look', ({yaw, pitch, onGround} = {}) => sendLook(yaw, pitch, onGround)) + player._client.on('look', ({ yaw, pitch, onGround } = {}) => sendLook(yaw, pitch, onGround)) // float (degrees) --> byte (1/256 "degrees") function conv (f) { @@ -37,11 +37,11 @@ module.exports.player = function (player) { }) } - player._client.on('position', ({x, y, z, onGround} = {}) => { + player._client.on('position', ({ x, y, z, onGround } = {}) => { player.sendPosition((new Vec3(x, y, z)), onGround) }) - player._client.on('position_look', ({x, y, z, onGround, yaw, pitch} = {}) => { + player._client.on('position_look', ({ x, y, z, onGround, yaw, pitch } = {}) => { player.sendPosition((new Vec3(x, y, z)), onGround) sendLook(yaw, pitch, onGround) }) @@ -89,7 +89,7 @@ module.exports.entity = function (entity, serv) { position: position, onGround: onGround, teleport: teleport - }, ({position, onGround}) => { + }, ({ position, onGround }) => { // known position is very important because the diff (/delta) send to players is floored hence is not precise enough // storing the known position allows to compensate next time a diff is sent // without the known position, the error accumulate fast and player position is incorrect from the point of view diff --git a/src/lib/plugins/useItem.js b/src/lib/plugins/useItem.js index de276a2..d327674 100644 --- a/src/lib/plugins/useItem.js +++ b/src/lib/plugins/useItem.js @@ -1,9 +1,9 @@ const Vec3 = require('vec3').Vec3 -module.exports.player = function (player, serv, {version}) { +module.exports.player = function (player, serv, { version }) { const items = require('minecraft-data')(version).items - player._client.on('block_place', ({direction, location} = {}) => { + player._client.on('block_place', ({ direction, location } = {}) => { const heldItem = player.inventory.slots[36 + player.heldItemSlot] if (direction === -1 || heldItem.type === -1 || !items[heldItem.type]) return const item = heldItem diff --git a/src/lib/plugins/weather.js b/src/lib/plugins/weather.js index ecde4ee..c672b4d 100644 --- a/src/lib/plugins/weather.js +++ b/src/lib/plugins/weather.js @@ -11,13 +11,13 @@ module.exports.player = function (player, serv) { let condition = args[0] if (['clear', 'rain'].indexOf(condition) === -1) { return false } - return {condition: condition} + return { condition: condition } }, - action ({condition}) { + action ({ condition }) { if (condition === 'rain') { - serv._writeAll('game_state_change', {reason: 2, gameMode: 0}) + serv._writeAll('game_state_change', { reason: 2, gameMode: 0 }) } else if (condition === 'clear') { - serv._writeAll('game_state_change', {reason: 1, gameMode: 0}) + serv._writeAll('game_state_change', { reason: 1, gameMode: 0 }) } } }) diff --git a/src/lib/plugins/world.js b/src/lib/plugins/world.js index cec3606..2e18074 100644 --- a/src/lib/plugins/world.js +++ b/src/lib/plugins/world.js @@ -8,7 +8,7 @@ const { level } = require('prismarine-provider-anvil') const fsStat = promisify(fs.stat) const fsMkdir = promisify(fs.mkdir) -module.exports.server = async function (serv, {version, worldFolder, generation = {'name': 'diamond_square', 'options': {'worldHeight': 80}}} = {}) { +module.exports.server = async function (serv, { version, worldFolder, generation = { 'name': 'diamond_square', 'options': { 'worldHeight': 80 } } } = {}) { const World = require('prismarine-world')(version) const newSeed = generation.options.seed || Math.floor(Math.random() * Math.pow(2, 31)) @@ -27,7 +27,7 @@ module.exports.server = async function (serv, {version, worldFolder, generation seed = levelData['RandomSeed'][0] } catch (err) { seed = newSeed - await level.writeLevel(worldFolder + '/level.dat', {'RandomSeed': [seed, 0]}) + await level.writeLevel(worldFolder + '/level.dat', { 'RandomSeed': [seed, 0] }) } } else { seed = newSeed } generation.options.seed = seed @@ -69,8 +69,8 @@ module.exports.server = async function (serv, {version, worldFolder, generation .filter(player => player.world === world) .forEach(oPlayer => { chunks - .filter(({chunkX, chunkZ}) => oPlayer.loadedChunks[chunkX + ',' + chunkZ] !== undefined) - .forEach(({chunkX, chunkZ}) => oPlayer.unloadChunk(chunkX, chunkZ)) + .filter(({ chunkX, chunkZ }) => oPlayer.loadedChunks[chunkX + ',' + chunkZ] !== undefined) + .forEach(({ chunkX, chunkZ }) => oPlayer.unloadChunk(chunkX, chunkZ)) oPlayer.sendRestMap() }) } @@ -104,7 +104,7 @@ module.exports.player = function (player, serv, settings) { x: chunkX, z: chunkZ, chunk: column - }, ({x, z, chunk}) => { + }, ({ x, z, chunk }) => { player._client.write('map_chunk', { x: x, z: z, @@ -140,19 +140,19 @@ module.exports.player = function (player, serv, settings) { chunkX: playerChunkX + t[0] - view, chunkZ: playerChunkZ + t[1] - view })) - .filter(({chunkX, chunkZ}) => { + .filter(({ chunkX, chunkZ }) => { const key = chunkX + ',' + chunkZ const loaded = player.loadedChunks[key] if (!loaded) player.loadedChunks[key] = 1 return !loaded }) - .reduce((acc, {chunkX, chunkZ}) => { + .reduce((acc, { chunkX, chunkZ }) => { const p = acc .then(() => player.world.getColumn(chunkX, chunkZ)) .then((column) => player.sendChunk(chunkX, chunkZ, column)) return group ? p.then(() => sleep(5)) : p } - , Promise.resolve()) + , Promise.resolve()) } function sleep (ms = 0) { @@ -209,8 +209,8 @@ module.exports.player = function (player, serv, settings) { usage: '/changeworld overworld|nether', op: true, action (world) { - if (world === 'nether') player.changeWorld(serv.netherworld, {dimension: -1}) - if (world === 'overworld') player.changeWorld(serv.overworld, {dimension: 0}) + if (world === 'nether') player.changeWorld(serv.netherworld, { dimension: -1 }) + if (world === 'overworld') player.changeWorld(serv.overworld, { dimension: 0 }) } }) } diff --git a/src/lib/portal_detector.js b/src/lib/portal_detector.js index c3c0ede..47d1f57 100644 --- a/src/lib/portal_detector.js +++ b/src/lib/portal_detector.js @@ -22,7 +22,7 @@ async function findPotentialLines (world, startingPoint, directionV) { const firstLineDirection = directionV.y !== 0 ? [new Vec3(1, 0, 0), new Vec3(0, 0, 1)] : [new Vec3(0, 1, 0)] return (await Promise.all(firstLineDirection - .map(async d => ({direction: d, line: (await findLine(world, startingPoint, 'obsidian', d, directionV))})))) + .map(async d => ({ direction: d, line: (await findLine(world, startingPoint, 'obsidian', d, directionV)) })))) .filter(line => (line.line.length >= 3 && line.direction.y !== 0) || (line.line.length >= 2 && line.direction.y === 0)) } @@ -32,7 +32,7 @@ function positiveOrder (line, direction) { return line } -async function findBorder (world, {line, direction}, directionV) { +async function findBorder (world, { line, direction }, directionV) { let bottom = line if (bottom.length === 0) { return [] } let left = await findLineInDirection(world, bottom[0].plus(direction.scaled(-1).plus(directionV)), 'obsidian', directionV, direction) @@ -57,7 +57,7 @@ async function findBorder (world, {line, direction}, directionV) { if (bottom.length < 2 || top.length < 2 || left.length < 3 || right.length < 3) { return null } - return {bottom, left, right, top} + return { bottom, left, right, top } } async function detectFrame (world, startingPoint, directionV) { @@ -66,8 +66,8 @@ async function detectFrame (world, startingPoint, directionV) { return asyncFilter((await Promise.all(potentialLines .map(line => findBorder(world, line, directionV)))) .filter(border => border !== null) - .map(({bottom, left, right, top}) => ({bottom, left, right, top, air: getAir({bottom, left, right, top})})), - async ({air}) => isAllAir(world, air)) + .map(({ bottom, left, right, top }) => ({ bottom, left, right, top, air: getAir({ bottom, left, right, top }) })), + async ({ air }) => isAllAir(world, air)) } async function asyncEvery (array, pred) { @@ -85,7 +85,7 @@ async function isAllAir (world, blocks) { } function getAir (border) { - const {bottom, top} = border + const { bottom, top } = border return flatMap(bottom, pos => range(1, top[0].y - bottom[0].y).map(i => pos.offset(0, i, 0))) } @@ -110,7 +110,7 @@ function generatePortal (bottomLeft, direction, width, height) { function addPortalToWorld (world, portal, additionalAir, additionalObsidian, setBlockType = null) { if (setBlockType === null) { setBlockType = world.setBlockType.bind(world) } - const {bottom, left, right, top, air} = portal + const { bottom, left, right, top, air } = portal const p = flatMap([bottom, left, right, top], border => border.map(pos => setBlockType(pos, 49))) p.push(air.map(pos => setBlockType(pos, 0))) @@ -131,7 +131,7 @@ async function makeWorldWithPortal (portal, additionalAir, additionalObsidian) { function loader (version) { World = require('prismarine-world')(version) Chunk = require('prismarine-chunk')(version) - return {detectFrame, findPotentialLines, findBorder, getAir, generateLine, generatePortal, addPortalToWorld, makeWorldWithPortal} + return { detectFrame, findPotentialLines, findBorder, getAir, generateLine, generatePortal, addPortalToWorld, makeWorldWithPortal } } module.exports = loader diff --git a/src/lib/supportFeature.js b/src/lib/supportFeature.js index e09121f..42e921a 100644 --- a/src/lib/supportFeature.js +++ b/src/lib/supportFeature.js @@ -1,4 +1,4 @@ const features = require('./features') module.exports = (feature, version) => - features.some(({name, versions}) => name === feature && versions.includes(version)) + features.some(({ name, versions }) => name === feature && versions.includes(version)) diff --git a/src/lib/worldGenerations/all_the_blocks.js b/src/lib/worldGenerations/all_the_blocks.js index ffb6e44..ae84a3a 100644 --- a/src/lib/worldGenerations/all_the_blocks.js +++ b/src/lib/worldGenerations/all_the_blocks.js @@ -1,6 +1,6 @@ const Vec3 = require('vec3').Vec3 -function generation ({version}) { +function generation ({ version }) { const Chunk = require('prismarine-chunk')(version) const blocks = require('minecraft-data')(version).blocks diff --git a/src/lib/worldGenerations/grass_field.js b/src/lib/worldGenerations/grass_field.js index 0e086f9..fff297d 100644 --- a/src/lib/worldGenerations/grass_field.js +++ b/src/lib/worldGenerations/grass_field.js @@ -1,6 +1,6 @@ const Vec3 = require('vec3').Vec3 -function generation ({version}) { +function generation ({ version }) { const Chunk = require('prismarine-chunk')(version) function generateSimpleChunk () { diff --git a/src/lib/worldGenerations/nether.js b/src/lib/worldGenerations/nether.js index f156fbe..21c74dc 100644 --- a/src/lib/worldGenerations/nether.js +++ b/src/lib/worldGenerations/nether.js @@ -1,7 +1,7 @@ const Vec3 = require('vec3').Vec3 const rand = require('random-seed') -function generation ({version, seed, level = 50} = {}) { +function generation ({ version, seed, level = 50 } = {}) { const Chunk = require('prismarine-chunk')(version) function generateChunk (chunkX, chunkZ) { diff --git a/src/lib/worldGenerations/superflat.js b/src/lib/worldGenerations/superflat.js index 6e06207..1a57a63 100644 --- a/src/lib/worldGenerations/superflat.js +++ b/src/lib/worldGenerations/superflat.js @@ -1,6 +1,6 @@ const Vec3 = require('vec3').Vec3 -function generation ({version, opt = 'default', bottomId = 7, middleId = 1, topId = 2, middleThickness = 3, debug = false} = {}) { +function generation ({ version, opt = 'default', bottomId = 7, middleId = 1, topId = 2, middleThickness = 3, debug = false } = {}) { const Chunk = require('prismarine-chunk')(version) function generateChunk () { diff --git a/test/mineflayer.test.js b/test/mineflayer.test.js index b41926e..5342ca9 100644 --- a/test/mineflayer.test.js +++ b/test/mineflayer.test.js @@ -134,7 +134,7 @@ squid.supportedVersions.forEach((supportedVersion, i) => { const pos = bot.entity.position.offset(0, -1, 0).floored() bot.dig(bot.blockAt(pos)) - let [, newBlock] = await once(bot2, 'blockUpdate', {array: true}) + let [, newBlock] = await once(bot2, 'blockUpdate', { array: true }) assertPosEqual(newBlock.position, pos) expect(newBlock.type).toEqual(0) }) @@ -145,7 +145,7 @@ squid.supportedVersions.forEach((supportedVersion, i) => { const pos = bot.entity.position.offset(0, -2, 0).floored() bot.dig(bot.blockAt(pos)) - let [, newBlock] = await once(bot2, 'blockUpdate', {array: true}) + let [, newBlock] = await once(bot2, 'blockUpdate', { array: true }) assertPosEqual(newBlock.position, pos) expect(newBlock.type).toEqual(0) @@ -158,7 +158,7 @@ squid.supportedVersions.forEach((supportedVersion, i) => { bot.placeBlock(bot.blockAt(pos.offset(0, -1, 0)), new Vec3(0, 1, 0)); - [, newBlock] = await once(bot2, 'blockUpdate', {array: true}) + [, newBlock] = await once(bot2, 'blockUpdate', { array: true }) assertPosEqual(newBlock.position, pos) expect(newBlock.type).toEqual(1) }) @@ -246,7 +246,7 @@ squid.supportedVersions.forEach((supportedVersion, i) => { test('can use /setblock', async () => { await Promise.all([waitSpawnZone(bot, 2), onGround(bot)]) bot.chat('/setblock 1 2 3 95 0') - let [, newBlock] = await once(bot, 'blockUpdate:' + new Vec3(1, 2, 3), {array: true}) + let [, newBlock] = await once(bot, 'blockUpdate:' + new Vec3(1, 2, 3), { array: true }) expect(newBlock.type).toEqual(95) }) test('can use /xp', async () => { diff --git a/test/portal.test.js b/test/portal.test.js index c5db7f1..c6f4ee3 100644 --- a/test/portal.test.js +++ b/test/portal.test.js @@ -81,7 +81,7 @@ squid.supportedVersions.forEach((supportedVersion, i) => { additionalObsidian: [new Vec3(2, 1, 1), new Vec3(5, 1, 1), new Vec3(2, 6, 1), new Vec3(5, 6, 1)] }) - const {bottom, left, right, top, air} = generatePortal(new Vec3(2, 1, 2), new Vec3(1, 0, 0), 4, 5) + const { bottom, left, right, top, air } = generatePortal(new Vec3(2, 1, 2), new Vec3(1, 0, 0), 4, 5) portalData.push({ name: '2 portals', @@ -103,11 +103,11 @@ squid.supportedVersions.forEach((supportedVersion, i) => { additionalObsidian: [] }) - portalData.forEach(({name, bottomLeft, direction, width, height, additionalAir, additionalObsidian}) => { + portalData.forEach(({ name, bottomLeft, direction, width, height, additionalAir, additionalObsidian }) => { const portal = generatePortal(bottomLeft, direction, width, height) - const {bottom, left, right, top, air} = portal + const { bottom, left, right, top, air } = portal describe('Detect ' + name, () => { - const expectedBorder = {bottom, left, right, top} + const expectedBorder = { bottom, left, right, top } let world beforeAll(async function () { @@ -233,9 +233,9 @@ squid.supportedVersions.forEach((supportedVersion, i) => { additionalObsidian: [new Vec3(4, 3, 1)] }) - portalData.forEach(({name, bottomLeft, direction, width, height, additionalAir, additionalObsidian}) => { + portalData.forEach(({ name, bottomLeft, direction, width, height, additionalAir, additionalObsidian }) => { const portal = generatePortal(bottomLeft, direction, width, height) - const {bottom, right, top} = portal + const { bottom, right, top } = portal describe("doesn't detect detect " + name, () => { let world beforeAll(async function () {