Skip to content

Commit

Permalink
'Copy teleport as command' ciontext menu option
Browse files Browse the repository at this point in the history
  • Loading branch information
Heath123 committed Nov 27, 2020
1 parent a9e7999 commit a64ca06
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
11 changes: 11 additions & 0 deletions html/mainPage/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,17 @@ ipcRenderer.on('copyPacketData', (event, arg) => {
ipcRenderer.send('copyToClipboard', data)
})

ipcRenderer.on('copyTeleportCommand', (event, arg) => {
const ipcMessage = JSON.parse(arg)
let data = allPackets[ipcMessage.id].data
data = '/tp @p ' + ((data.flags & 0x01) ? '~' : '') + data.x
+ ((data.flags & 0x02) ? ' ~' : ' ') + data.y
+ ((data.flags & 0x04) ? ' ~' : ' ') + data.z
+ ((data.flags & 0x08) ? ' ~' : ' ') + data.yaw
+ ((data.flags & 0x10) ? ' ~' : ' ') + data.pitch
ipcRenderer.send('copyToClipboard', data)
})

window.closeDialog = function () { // window. stops standardjs from complaining
// dialogOpen = false
document.getElementById('dialog-overlay').className = 'dialog-overlay'
Expand Down
20 changes: 18 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const osDataFolder = app.getPath('appData')
const dataFolder = setupDataFolder.setup(osDataFolder, resourcesPath)

function makeMenu (direction, text, id) {
return Menu.buildFromTemplate([
let menuData = [
{
icon: resourcesPath + `icons/${direction}.png`,
label: text,
Expand Down Expand Up @@ -55,7 +55,23 @@ function makeMenu (direction, text, id) {
}))
}
}
])
]

if (text.split(' ')[1] === 'position' && direction === 'clientbound') {
menuData.splice(3, 0,
{
label: 'Copy teleport as command',
click: () => {
BrowserWindow.getAllWindows()[0].send('copyTeleportCommand', JSON.stringify({
// Packet ID from link URL
id: id
}))
}
}
)
}

return Menu.buildFromTemplate(menuData)
}

function createWindow () {
Expand Down

0 comments on commit a64ca06

Please sign in to comment.