Solved This should work, right?

Discussion in 'Plugin Development' started by Mattigins, Jan 16, 2014.

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

    Mattigins

    I have the following code, but when i right click on a block, nothing happens.. (no console errors or anything) I am just wondering if the following code should work or if i'm doing something wrong.

    Code:java
    1. @EventHandler
    2. public void onPlayerInteractEvent(PlayerInteractEvent e){
    3. final Player p = e.getPlayer();
    4. Block b = e.getClickedBlock();
    5. if(p.hasPermission("mattigins.admin")){
    6. if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    7. p.sendMessage(ChatColor.AQUA + (b.getTypeId() + " Hit"));
    8. }
    9. }
    10. }
     
  2. Offline

    NoLiver92

    May be a silly question but have you registered the listener? that is normally the cause of most problems like this. Also does the player have the permission?

    Why is the player a final?
     
  3. Offline

    LanteanKnight

    Is the permission registered in your plugin.yml?

    I'm not sure if it's possible to write == in this case, for objects I always use .equals.
    Code:
    if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
    }
    Are either of these two things the problem?

    EDIT: I assumed that you had registered the listener, but the person above me is right, that may just be it.
     
  4. Offline

    metalhedd


    Permission nodes don't need to be registered in plugin.yml, that's only for assigned defaults. an OP will automatically have all permissions, and a non-op can have any permission node granted whether or not it exists in a plugin.yml file.

    Also == is fine in this case, Enums can be compared that way. The issue is almost definitely an unregistered listener.
     
  5. Offline

    Mattigins

    I am really new to bukkit plugin programming, so can you please let me know how to register the listener? I'm not even really sure what that means
     
  6. Offline

    xTrollxDudex

    Monkey_Swag and NoLiver92 like this.
  7. Offline

    NoLiver92

    If you are new to bukkit, have you looked at some tutorials? mainly this one: this? this will teach you how to do it.

    EDIT: xTrollxDudex Ninjered :/
     
  8. Offline

    Mattigins

    oh so it's this (which i already have in my onEnable)
    Code:java
    1. Bukkit.getPluginManager().registerEvents(this, this);
     
  9. Offline

    NoLiver92


    This would depend if your listener (what you posted first) is in the main class. If it is maksure your class definition contains "extend JavaPlugin implements Listener"
     
  10. Offline

    Mattigins

    Yes and Yes
     
  11. Offline

    NoLiver92


    can you post your whole code as it might shed some light on this.
     
  12. Offline

    Monkey_Swag

    • This is inappropriate behavior
    Exactly. Mattigins please don't attempt to create plugins if you don't know what you're doing. Do you even know java?
     
  13. Offline

    Mattigins

    Code:java
    1. package me.mattigins.mattiginsplugin;
    2.  
    3. //My Imports
    4.  
    5. public class mattigins extends JavaPlugin implements Listener{
    6. public final Logger logger = Logger.getLogger("Minecraft");
    7. public static mattigins plugin;
    8.  
    9. @Override
    10. public void onDisable(){
    11. PluginDescriptionFile pdfFile = this.getDescription();
    12. this.logger.info(pdfFile.getName() + " has been disabled.");
    13. }
    14.  
    15. @Override
    16. public void onEnable(){
    17. Bukkit.getPluginManager().registerEvents(this, this);
    18. PluginDescriptionFile pdfFile = this.getDescription();
    19. this.logger.info(pdfFile.getName() + " v" + pdfFile.getVersion() + " has been enabled.");
    20. this.saveDefaultConfig();
    21. }
    22.  
    23. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    24. Player player = (Player) sender;
    25. PluginDescriptionFile pdfFile = this.getDescription();
    26.  
    27. if(player.hasPermission("canMattigins")){
    28. //Reload
    29. if(cmd.getName().equalsIgnoreCase("mattigins")){
    30. reloadConfig();
    31. player.sendMessage(ChatColor.AQUA + "Plugin Reloaded");
    32. player.sendMessage(ChatColor.AQUA + (pdfFile.getName() + " v" + pdfFile.getVersion()));
    33. }
    34. }
    35. return false;
    36. }
    37.  
    38. @EventHandler
    39. public void onPlayerInteractEvent(PlayerInteractEvent e){
    40. final Player p = e.getPlayer();
    41. Block b = e.getClickedBlock();
    42. if(p.hasPermission("mattigins.admin")){
    43. if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    44. p.sendMessage(ChatColor.AQUA + (b.getTypeId() + " Hit"));
    45. }
    46. }
    47. }
    48. }


    No i do not know Java, but i know php, sql, vb.net, c# and Objective C so i figured i would give this a burl.

    Your statement is also contradictory. How am i supposed to learn how to create a plugin if i can never try because "i don't know what i am doing"..

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  14. Offline

    NoLiver92


    What he means is learn java first as bukkit is founded on java. on this forum you wont normally get code given to you (they edit your attempted code) but they will tell you how to do it in words and if you dont understand java you wont be able to do it. there are tutorials which can teach you but it is highly reccomended that you learn java.

    Look at my signiture for the tutorial which will explain how to do things and why.
     
  15. Offline

    1Rogue

    I think the implication was to learn the language before learning the Bukkit API.

    Try putting debug statements in your event method and onEnable
     
    Monkey_Swag likes this.
  16. Offline

    Mattigins

    Will do, Thanks
     
Thread Status:
Not open for further replies.

Share This Page