Solved Help With Ranks Detections

Discussion in 'Plugin Development' started by LightDarkness, Apr 20, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    LightDarkness

    So I have looked quite a while for something like this that can help. So far I have no been able to find anything, but that may just be due to my horrible searching skills. Right now I have the command /hell in the code. Eventually there will be the command /heaven as well, but before I do that, I am in need of help figuring out how to make it search if they are in the Default, or Human rank. If they are not in the Human rank, then they can't use the commands Heaven, or Hell. I have been using Java for a good while now, just stuck on the Bucket/Spigot API. Thank you all in advance for your help. Feel free to judge me on my code, this is only my 3rd plugin, and I am trying to go a bit bigger. If you see something that is to lengthy, or just plain wrong, please tell me.


    Code:
    package me.multigen.prison;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class War extends JavaPlugin {
       
        public void onEnable() {
            getServer().getLogger().info("Multigen Prison");
            getServer().getLogger().info("Heaven or Hell Activated");
        }
       
        public void onDisable() {
            getServer().getLogger().info("Multigen Prison");
            getServer().getLogger().info("Heaven or Hell Deactivated");
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player player = (Player) sender;
            String name = player.getName();
           
            if (commandLabel.equalsIgnoreCase("hell")){
    
                getServer().dispatchCommand(getServer().getConsoleSender(), "pex group Human user remove " + name);
                getServer().dispatchCommand(getServer().getConsoleSender(), "pex group Demon user add " + name);
                getServer().dispatchCommand(getServer().getConsoleSender(), "spawn " + name);
                player.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_RED + "Prison" + ChatColor.DARK_GRAY + "]" + ChatColor.GRAY + " You are now on the side of " + ChatColor.DARK_RED + "Hell" + ChatColor.GRAY + "!");
                player.sendMessage(ChatColor.DARK_GRAY + "Do " + ChatColor.WHITE + "/kit Demon" + ChatColor.DARK_GRAY + " for your starting kit.");
            }
           
            return false;
        }
    }
     
  2. Offline

    MCMastery

    What plugin are you using to manage permissions? Usually you can use Vault, an API for economy / permissions, to find out what group / rank someone's in.

    Nitpicks:
    - You should add an @Override right before onCommand, onEnable and onDisable. These are methods you are overriding from the JavaPlugin class. It's a good habit to get into - it makes sure the onEnable is actually a method in the superclass (so you know you didn't spell anything wrong, it will throw an error).
    - Do you really need to see in the console when your plugin is enabled / disabled - twice? I don't know, I feel like this just kind of clogs up the console. Bukkit automatically says in the console when plugins are enabled / disabled.
     
  3. Offline

    yPedx

    @LightDarkness
    Do not blindly cast sender to player, what if the sender is command block or console?
    as @MCMastery said;
    You do not need to log your own plugin, Bukkit does this automaticly. (unless you want it to say something special)
     
  4. Offline

    MarinD99

    Wouldn't it just be easier to persist those three ranks (human, angel, and presumably demon) in a database, and just chek?
     
  5. Offline

    thechrisanator

    You could just give those ranks a permission node, and check in the plugin if they have that permission. And if they don't, then dont let them use the commands.
     
  6. Offline

    LightDarkness

    Alright thanks for those nitpicks. I took out the console spam, and I am making sure to use the @Override.

    Thank you. I ended up doing this, and it is working wonderfully.

    So how would I go about adding some type of /promote or /rankup command which checks if they have the correct amount of money, if they do it takes the money, and promotes them in pex, and if they don't then it tells them so? I don't want to just use Pex, I want it imported into my plugin so it is an all in one plugin.
     
    MCMastery likes this.
  7. Offline

    thechrisanator

    If you have vault installed, then you can implement their methods from their API.
    Which is found here:
    http://milkbowl.github.io/VaultAPI/
    Then if a player reaches the money requirements, you can give the sender a permission node.
     
  8. Offline

    LightDarkness

    NvM. Creating a new post for new problem.
     
    Last edited: Apr 20, 2017
Thread Status:
Not open for further replies.

Share This Page