Sorry i am totally clueless on what should be the title feel free to help me shall you are capable of editing it or just give me suggestion on that too, Anyways how would i go with improving something like this $player->hasPermission(something.$args[1]) live example : https://github.com/Muqsit/PlayerVau...5bf5c9/src/PlayerVaults/PlayerVaults.php#L118 it works and is fine but how could i improve it so i can just grant player biggest numerical value which would grant them all of the lower values instead of having to grant them one value after another or any even better alternatives? Also sorry if there's already solved somewhere else i never seen anyone talked about this ps i dont really have experiences work with perms so forgive me if this is just a simple question Previous ideas: creating a abrititurely limit but using that will be bad, because now i got a abrititurely limit and will break/lags if some user thinks that maybe i should set that to some very very large number because they dont want a limit(buyable things etc) which isnt great either ideally i would want to grab all attached permission of ex vaults.open.* and check for the biggest value which i would continue on from there TLDR; How can i grab all of the subnet of a permission node like every child of vaults.open
I didn't look finely into your context, so I'm not very sure what exactly you're looking for. But I understand the need for more flexible values in permissions. What about using the config to map permissions to your arbitrary values? Code: # config.yml height-perms: bedrock: 4 diamond: 15 gold: 31 sealevel: 62 cloud: 128 PHP: // main classprivate $heights;public function onEnable(){ $parent = $this->getServer()->getPluginManager()->getPermission("playervaults.vault.$args[0].height"); foreach($this->heights = $this->getConfig()->get("height-perms") as $name => $height){ $perm = new Permission("playervaults.vault.$args[0].height.$name", "Allows $args[0] at y <= $height"); $parent->getChildren()[$perm->getName()] = true; $this->getServer()->getPluginManager()->addPermission($perm); }}public function hasPermission(Permissible $permbl, int $height) : bool{ foreach($this->heights as $name => $y){ if($y >=$height and $permbl->hasPermission("playervaults.vault.$args[0].height.$name")) return true; } return false;}
it's either i am missing something or you are, example: i have a vault plugin with multiple chest, but i dont want to check for each vaults permissions right now i would need to grant 50 permissions from 1 to 50 if i want my player to have 50 vaults, so i am looking for a easy way to grant them 50 vaults without doing the 1 to 50, yes you could map arbitrary values like starter: 25 veteran: 50 which was kind of better, but if i want an even flexible one that can be incremented at all times(ex player LVed up) yet without resulting to lv1:20 lv2:21 lv3:22... would be nicer i wanted to do something like get all set child nodes of valut.open and just sort through it for the biggest number if that's possible
If I got you right, you want the player to access Vault #1, Vault #2, Vault #3 ...Vault #100 and thus assign a permission that would be equivalent to playervaults.vault.1, playervaults.vault.2 all the way to playervaults.vault.100?
Yes correct, but playervaults.vault.100 should also allow opening of vault 99-1 since it(or this kind of problem) never been properly tackled in this community might as well do it now
SOF3's reply but a "hacker" kind of way to do it would be take a copy of the database (in this case, the permission array) and brute force the password (in this case, iterate through the array to check if the permission exists). But still, this is not the best method. If the number is too big (something like 100,000,000), its gonna take a while. PHP: $myperm = "playervaults.vault.100";/** @var Player $player */$perms = $player->getEffectivePermissions();$perms = array_keys($perms);//Just a tip, you can run the below code asynchronously.$maxnum = (int) str_replace("playervaults.vault.", "", $myperm); //100$found = false;foreach($perms as $perm){ if(strpos($perm, "playervaults.vault") !== false){ if(str_replace("playervaults.vault.", "", $perm) <= $maxnum){ $found = true; break; } }}return $found;
so can i only iterate through perm nodes but no way to get all child nodes? i thought it would been something like: PHP: $val = 0;//example methodforeach ($player->getPerms('playervaults.vault')->getChilds() as $child){if ($child > $val) $val = $child;//remove all nodes keeping only val so no need to reiterate next time OR store it in an cache} i guess PMMP implementation of it denies that? because you would still end up with a cap value which i tries to avoid
Your code doesn't take much time to run. Doesn't need asynchronization. So, as far as I understand, you have many vaults, each with a given ID, and if the player has permission to vault #n, he must also have permission to all vaults #n-N, where N is any natural number. I don't know why your vaults have such permission arrangement. I doubt if you should even use permissions for these -- according to this, it seems that your permissions are only used for level-up, which is not what permissions are designed for. At least, permissions are designed for discrete behaviour, not continuous behaviour. You simply should not use permissions for this, but instead, store the player's vault access somewhere else and create respective administrative commands to authorize them.