How to give players permissions

Discussion in 'Spigot Plugin Development' started by ZevoGaems, Apr 13, 2017.

  1. Hello. I am making a ban plugin and I thought of a way so it kicks but doesn't set them to banned. I want to make it so, on join the plugin checks for something that the player has and if they have it kicks the player. How would I be able to mark a player this way? Thank you for looking and helping me out!
    Code (Text):
    package pw.LoopTurn.Punishment;

    import java.awt.print.Paper;

    import org.bukkit.Bukkit;
    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 punish extends JavaPlugin {
        public void onEnable() {
            getLogger().info("Punishments have been enabled");
        }
        public void onDisble() {
            getLogger().info("Punishments have been disabled");
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("ban")) {
                if(sender instanceof Player)
                    if(args.length < 1)
                        sender.sendMessage(ChatColor.RED + "Punish, " + ChatColor.GRAY + "usage: /ban (player) (reason)");
                   
                } else {
                if(!sender.hasPermission("minegrid.punish")) {
                    sender.sendMessage(ChatColor.RED + "Punish, " + ChatColor.GRAY + "you do not have the required permissions!");
                } else {
                    String reason = " ";
                    for (int i = 0; i < args.length; i++) {
                    reason = reason + args[i] + " ";
                }
                    Player other = Bukkit.getPlayer(args[0]);
                    other.kickPlayer(ChatColor.DARK_RED + "You have been banned from MineGird by " + sender.getName());
                    other.()
                   
            }
            return false;
        }
    }
     
     
  2. Save their UUIDs in a file.
     
  3. Give the player a permission like "<plugin_name>.banned" and when a player joins with that permission you can kick them. You can also keep a list of banned players UUIDS in a .yml file and load it every time the server starts. The last option is often preferred above the first option, but takes more code.
     
  4. I was thinking that to but I just remembered ops get all permissions that mean all ops would be banned on join
     
  5. How would I create a file, I forgot how to. Also how would I retrieve information from it?
     
  6. Googled "java file io": https://www.tutorialspoint.com/java/java_files_io.htm
    You can also look into serialization, I personally prefer that, since I can serialize almost any Object with just one method. Google "ObjectOutputStream" and "ObjectInputStream". If you want, I can send you my methods, but you don't learn much from copy-pasting and googling skills are very useful :)
     
  7. Only if you set default to op, if I am correct?
     
  8. Yes, you can set the default to false and ops won't get the permission.
     
  9. How would I set default permission?
     
  10. Look at the bukkit wiki documentation for plugin.yml files: http://bukkit.gamepedia.com/Plugin_YAML
    At the bottom it shows an example with permissions registered. That's where you set the default: false for your permissions. If you don't specify a default in the yml, it'll default to ops.