Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- @Filename : setGroup.php
- @Description : Changes a user to a specific group, through a web page
- Could be useful for admins working on control panels :)
- @Written by Pr4w for Bukkit.org
- @Usage : setGroup('Pr4w', 'Admin', '/opt/mc/plugins/PermissionsBukkit/config.yml');
- Have fun :)
- */
- // Including the Spyc Yaml Parser, change this to wherever you want to have it
- @require_once('spyc.php');
- function setGroup($user, $group, $file) {
- // Let's load some YAML
- $yaml = Spyc::YAMLLoad(@file_get_contents($file));
- // Check to see if the file was correctly loaded or not
- if (!$yaml) {
- die (" Yaml file doesn't exist/could not be found ! ");
- }
- // Check if group exists, in case
- if (!array_key_exists($group, $yaml['groups'])) {
- die (" Group $group does not exist ! ");
- }
- // Check if user exists, in case
- if (!array_key_exists($user, $yaml['users'])) {
- die (" User $user does not exist ! ");
- }
- // Set group to the new group
- $yaml['users'][$user][0] = $group;
- // Dump it back to YAML format
- $yaml = Spyc::YAMLDump($yaml, 4);
- // Fix some formatting errors that Permissions won't like
- $yaml = str_replace("0:", "-", $yaml);
- // Open the .yml file for writing
- $write = fopen($file, "w");
- // Check if file can be opened
- if (!$write) {
- die (" Could not open file $file ! ");
- }
- // Write to the file, and check if that works
- if (!fwrite($write, $yaml)) {
- die (" Could not write to file ! ");
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement