Solved adding Permissions to my plugin problem!

Discussion in 'Plugin Development' started by Schaakmatth, Apr 20, 2014.

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

    Schaakmatth

    Hello i'm making my first plugin,
    i have maked a plugin that gives a wand when you typ /vip
    but now i'm at the last step:
    adding permissions.
    i have add permissions,
    and it works but the users are getting still the item
    i dont know how to disable this for people that have none permission to do this
    this is my code:
    Code:java
    1. package me.Matthijs.vip;
    2.  
    3. import java.util.logging.Logger;
    4. import org.bukkit.Material;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandExecutor;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.block.Action;
    12. import org.bukkit.event.player.PlayerInteractEvent;
    13. import org.bukkit.inventory.ItemStack;
    14. import org.bukkit.inventory.meta.ItemMeta;
    15. import org.bukkit.plugin.PluginDescriptionFile;
    16. import org.bukkit.plugin.PluginManager;
    17. import org.bukkit.plugin.java.JavaPlugin;
    18.  
    19. public class Vip extends JavaPlugin implements Listener, CommandExecutor{
    20. public final Logger logger = Logger.getLogger("Minecraft");
    21. public static Vip plugin;
    22.  
    23.  
    24.  
    25.  
    26.  
    27. @Override
    28. public void onDisable() {
    29. PluginDescriptionFile pdfFile = this.getDescription();
    30. this.logger.info(pdfFile.getName() + " [Vip] Uit!");
    31. getServer().getPluginManager().removePermission(new Permissions().vip);
    32.  
    33.  
    34.  
    35. }
    36.  
    37. @Override
    38. public void onEnable() {
    39. PluginDescriptionFile pdfFile = this.getDescription();
    40. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " [Vip] Aan!");
    41. getServer().getPluginManager().registerEvents(this,this);
    42. PluginManager pm = this.getServer().getPluginManager();
    43. pm.addPermission(new Permissions().vip);
    44.  
    45. }
    46.  
    47. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    48.  
    49.  
    50. if (label.equalsIgnoreCase("vip")) {
    51. if(sender.hasPermission(new Permissions().vip)){
    52. sender.sendMessage("Hier is je explosieve wand!");
    53. } else{
    54. sender.sendMessage("Koop vip om dit te kunnen doen");
    55. }
    56.  
    57. ItemStack explosief = new ItemStack(Material.STICK);
    58.  
    59. ItemMeta im = explosief.getItemMeta();
    60.  
    61. im.setDisplayName("Explosief");
    62.  
    63. explosief.setItemMeta(im);
    64.  
    65. Player player = (Player) sender;
    66.  
    67. player.getInventory().addItem(explosief);
    68. return true;
    69. }
    70.  
    71.  
    72. return false;
    73.  
    74. }
    75.  
    76. @SuppressWarnings("deprecation")
    77. @EventHandler
    78. public void onPlayerInteract(PlayerInteractEvent e) {
    79. Player player = e.getPlayer();
    80. if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    81. if (player.getInventory().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("Explosief")) {
    82. player.getWorld().createExplosion(player.getTargetBlock(null, 5).getLocation(), 1);
    83.  
    84. }
    85. }
    86. }
    87. }
    88.  
     
  2. Offline

    TheMcScavenger

    I can see you're new to Bukkit, or Java for that matter... There's tons of errors. About the permissions, just use:

    Code:
    if(player.hasPermission("my permission"){
        // code
    }
    else{
        // error message
    }
     
  3. Offline

    Badeye

    Schaakmatth do not implement the CommandExecutor, bukkit checks for onCommand automaticly. Ads long as you do not use the Executor (what you didn't) do not implement it. Also, you check in your onCommand if a player has the permission you are trying to create right there o.o That part is weird
     
  4. Offline

    Schaakmatth

    Hello i have repared iT by myself and iT World fine i have the basics and van nie make plugins
     
Thread Status:
Not open for further replies.

Share This Page