Getting previous group with PermissionsEx

Discussion in 'Spigot Plugin Development' started by Exellanix, May 11, 2016.

  1. I have started making a plugin to be able to train trainee's (beginning of the staff team rank on my server). I am using pex and making sure they are in the "trainee" group. I have a feature that makes it so if a staff stops a players training, then it puts the player that was in training back to their previous rank(this is to ensure they always have their donated or normal rank). I do not know how to do this as the player would have to be a trainee to get trained, so I cant just get their rank when the staff member starts training them, and get it if the training stops.

    I was thinking of using a hashmap to put the players rank before they are put to trainee. Then I would get the rank of the player in the stop argument.

    Code of command:

    Code (Text):
    package me.exellanix.traineetrainer.commands;

    import me.exellanix.traineetrainer.TraineeTrainer;
    import me.exellanix.traineetrainer.tools.ERROR;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import ru.tehkode.permissions.PermissionUser;
    import ru.tehkode.permissions.bukkit.PermissionsEx;

    /**
    * Created by Exellanix on 5/10/2016.
    */
    public class Train_Command implements CommandExecutor {

        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("train")) {
                if(sender instanceof Player) {
                    Player player = (Player) sender;
                    if(player.hasPermission("tt.train")) {
                        if(args.length == 0) {
                            player.sendMessage(ChatColor.RED + "Usage: /train <player>");
                            return true;
                        }else if(args.length == 1) {
                            Player target = Bukkit.getPlayerExact(args[0]);
                            if(target != null) {
                                PermissionUser trainee = PermissionsEx.getUser(target);
                                if(trainee.inGroup("trainee")) {
                                    TraineeTrainer.getSingleton().inTraining.add(target);
                                    target.sendMessage(ChatColor.AQUA + "" + ChatColor.BOLD + "You are now getting trained by " + ChatColor.GREEN + "" + ChatColor.BOLD + player.getName() + ChatColor.AQUA + "" + ChatColor.BOLD + "!");
                                    player.sendMessage(ChatColor.GREEN + "You are now training " + target.getName() + "!");
                                    return true;
                                }else{
                                    player.sendMessage(ChatColor.RED + "That player is not a trainee!");
                                    return true;
                                }
                            }else{
                                ERROR.ThrowError(player, ERROR.OFFLINEPLAYER);
                                return true;
                            }
                        }else if(args.length == 2) {
                            if(args[0].equalsIgnoreCase("stop")) {
                                Player target = Bukkit.getPlayerExact(args[0]);

    //this is where I want to get targets previous rank

                            }else if(args[0].equalsIgnoreCase("end")) {
                                Player target = Bukkit.getPlayerExact(args[0]);
                            }
                        }
                    }else{
                        ERROR.ThrowError(player, ERROR.NOPERMS);
                        return true;
                    }
                }else{
                    sender.sendMessage(ChatColor.RED + "You can not do this!");
                    return true;
                }
            }
            return false;
        }
    }
    Code if main class:

    Code (Text):
    package me.exellanix.traineetrainer;

    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import ru.tehkode.permissions.PermissionGroup;
    import ru.tehkode.permissions.bukkit.PermissionsEx;

    import java.util.ArrayList;
    import java.util.HashMap;

    /**
    * Created by Brendan on 5/10/2016.
    */
    public class TraineeTrainer extends JavaPlugin {

        private static TraineeTrainer singleton;

        public void onEnable() {
            singleton = this;
            registerCommands();
            registerEvents();
            saveDefaultConfig();

            getLogger().info("Enabled!");
        }

        public void onDisable() {
            getLogger().info("Disabled.");
        }

        public void registerCommands() {
        }
        public void registerEvents() {
            PluginManager pm = getServer().getPluginManager();
        }

        public static TraineeTrainer getSingleton() {
            return singleton;
        }

        public ArrayList<Player> inTraining = new ArrayList<Player>();

        public HashMap<Player, PermissionGroup> prevGroup = new HashMap<Player, PermissionGroup>();

    }