const requests = [];
function tpRequest(player, target) {
requests.push({
from: player.name,
to: target,
time: world.getAbsoluteTime(),
});
player.sendMessage(`You requested a teleport to "${target}"`);
const tgt = world.getAllPlayers().find((t) => t.name == target);
tgt.sendMessage(`"${player.name}" has requested to teleport to you. Enter in chat "§a!tpa ${player.name}§r" to accept it.\n§4(exspires in 60s) `);
}
function tpAccept(player, target) {
//player.sendMessage(`Active Requests: ${JSON.stringify(requests)}`);
const req = requests.find((r) => r.from == target && r.to == player.name);
if (!req) player.sendMessage(`There is no tp request to "${player.name}" from "${target}"`);
const currentTime = world.getAbsoluteTime();
const timeDifference = currentTime - req.time;
if (timeDifference >= 1200) {
player.sendMessage(`The tp request from ${req.from} has expired`);
return;
}
const tgt = world.getAllPlayers().find((t) => t.name == req.from);
tgt.teleport(player.location, player.dimension, 0, 0);
requests.splice(requests.indexOf(req), 1);
player.sendMessage(`You have accepted ${target} teleport request!`)
tgt.sendMessage(`${player} Has accepted your teleport request!`)
}```
#-ReferenceError: Native funtion [Entity::teleport] does not have required privleges. at tpAccept
1 messages · Page 1 of 1 (latest)
2 issues, the first is it throws the perms error in the title of this page and also when the command is ran a second time, the request timer doesnt reset.
you can read more about privileges system in https://discord.com/channels/523663022053392405/1116399323580739684
ive been reading up on it as much as i can, i have read every single peace of literature i can find about the topic. My code worked before the update and i had to figure out how to update it. i got every bit of my code to work except this bit i pasted here. 12 of my 13 commands work but for some reason when my command for function tpAccept() runs i get a perms issue on the tgt.teleport() line.
im sure their is a simple and easy way to fix this i just havent found it. im pretty new to JS and dont have a complete conceptual understanding of the code yet. working hard at understanding it, but not their yet and would like some help with this instance in particular
can, you tell my how do you undestant that privileges system?
like when it throws and why
im not to sure on how to give the required permissions to run the command. i found something that works just now but i have no clue why it works or it is a terrible way to fix the issue. ```js
function tpAccept(player, target) {
//player.sendMessage(Active Requests: ${JSON.stringify(requests)});
const req = requests.find((r) => r.from == target && r.to == player.name);
if (!req) player.sendMessage(There is no tp request to "${player.name}" from "${target}");
const currentTime = world.getAbsoluteTime();
const timeDifference = currentTime - req.time;
if (timeDifference >= 1200) {
player.sendMessage(`The tp request from ${req.from} has expired`);
return;
}
const tgt = world.getAllPlayers().find((t) => t.name == req.from);
system.run(() => {
tgt.teleport(player.location, player.dimension);
}),
requests.splice(requests.indexOf(req), 1);
player.sendMessage(`You have accepted ${target} teleport request!`)
tgt.sendMessage(`${player} Has accepted your teleport request!`)
}```
you can see i added system.run(() => { but not sure why it works. just trial and error got it to work
teleport methods has changes as well
its not privilege issue there
the console in minecraft says .teleport doesnt have
required privilages
is that just a false error and shouldn't show like that?
i think that error is not current
you didnt save file or something
or you are using other teleport somewhere
did you do that /reload thing?
but i thing sendMessage require privileges as well
currently my code works fully with that adddion i made. but im talking about before i added system.run the .teleport threw the permissions error. and this line is the only place in my code that uses .teleport
the rest of them are .runCommandAsync
this file is the code working. i do not have a current issue since it has been resolved thorugh brute force trial and error.
when i opened the post the first bit of code i posted i had a problem with it. the second bit of code i sent if my resolutiong to the problem.
I do not understand why my "fix" worked, only that it does work. i am asking why adding sytem.run() fixed the code and if it is the optimal way to fix my issue or if a more refined method exists
so you are asking why system.run fixed your code?
right?
yes, why it fixed it and if their is a better way
code, has all privileges until its not executed via beforeEvent so if you dont need to cancel code use afterEvents they are have all provileges, if you dont want to add system.run everywhere add it in beforeEvent after you are don with canceling
thets the best way
for example
world.beforeEvents.chatSend.subscribe((ev)=>{
const {sender, message} = ev;
if(sender.isOp() && message.startsWith("!")) return ev.cancel = true;
system.run(()=>{
//code with all privileges here
});
});
@warm temple if you do this in all your beforeEvents then you are not forced to changing aour other functions in your code
world.beforeEvents.chatSend.subscribe((data) => {
const player = data.sender;
const message = data.message;
if (!message.startsWith(config.prefix)) return;
data.cancel = true;
system.run(() => {
const args = message.trim().slice(config.prefix.length).split(/\s+/g);
const cmd = args.shift().toLowerCase();
const cmdData = commandBuild.registeredCommands.find(
(c) => c.name === cmd || (c.aliases && c.aliases.includes(cmd))
);
if (!cmdData)
return player.sendMessage(
`§cThe command §f${cmd}§c is invalid. Please check that the command exists.`
);
if (cmdData.permission && !cmdData.permission(player))
return player.sendMessage(
`§cInvalid permission to use the command §f${cmd}§c.`
);
cmdData.callback(player, args);
});
//const args = message.trim().slice(config.prefix.length).split(/\s+/g);
// const cmd = args.shift().toLowerCase();
//const cmdData = commandBuild.registeredCommands.find(
// (c) => c.name === cmd || (c.aliases && c.aliases.includes(cmd))
// );
// if (!cmdData)
// return player.sendMessage(
// `§cThe command §f${cmd}§c is invalid. Please check that the command exists.`
// );
// if (cmdData.permission && !cmdData.permission(player))
// return player.sendMessage(
// `§cInvalid permission to use the command §f${cmd}§c.`
// );
// cmdData.callback(player, args);
});```
you can see the change i made as i turned it into comments
but this is working as far as i can tell
yep this is that scenario
but you can call that cmdData callback in system.run only
but its ok
bc other things does need API privileges
but its OK
now i have a .sendMessage issue where it says it cant read property 'sendMessage' of undefined.
it's shown up elsewhere in my code
function tpDecline(player, target) {
player.sendMessage(`§eYou declined§4 "${target}" §eteleport request`);
const req = requests.find((r) => r.from == target && r.to == player.name);
if (!req) player.sendMessage(`§4There is no tp request from§e ${target}`);
const tgt = world.getAllPlayers().find((t) => t.name == target);
tgt.sendMessage(`§e ${player.name} §4decline the tp`);
requests.splice(requests.indexOf(req), 1);
}```
tgt.sendMessage() is now undefined?
nah tgt is undefined
how so?
idk maybe .find didnt found that player xd
function tpDecline(player, target) {
player.sendMessage(`§eYou declined§4 "${target}" §eteleport request`);
const req = requests.find((r) => r.from == target && r.to == player.name);
if (!req) player.sendMessage(`§4There is no tp request from§e ${target}`);
const tgt = world.getAllPlayers().find((t) => t.name == req.from);
tgt.sendMessage(`§e ${player.name} §4decline the tp`);
requests.splice(requests.indexOf(req), 1);
}``` thisis how i have const tgt before but threw req.from 'from' undefined
¯_(ツ)_/¯
function tpAccept(player, target) {
//player.sendMessage(`Active Requests: ${JSON.stringify(requests)}`);
const req = requests.find((r) => r.from == target && r.to == player.name);
if (!req) player.sendMessage(`§4There is no tp request to §e"${player.name}"§4 from §a"${target}"`);
const currentTime = world.getAbsoluteTime();
const timeDifference = currentTime - req.time;
if (timeDifference >= 1200) {
player.sendMessage(`§4The tp request from§e ${req.from} §4has expired`);
return;
}
const tgt = world.getAllPlayers().find((t) => t.name == req.from);
tgt.teleport(player.location, player.dimension);
requests.splice(requests.indexOf(req), 1);
player.sendMessage(`§eYou have accepted§a ${target} §eteleport request!`)
tgt.sendMessage(`§a ${player} §eHas accepted your teleport request!`)
}``` here in this funtion const tgt is defined the say way and it works so im scratching my head