Solved This should work, right?

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

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


    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.

    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


    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


    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.
    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


    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


    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


    Monkey_Swag and NoLiver92 like this.
  7. Offline


    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


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


    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


    Yes and Yes
  11. Offline


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


    • 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


    1. package me.mattigins.mattiginsplugin;
    3. //My Imports
    5. public class mattigins extends JavaPlugin implements Listener{
    6. public final Logger logger = Logger.getLogger("Minecraft");
    7. public static mattigins plugin;
    9. @Override
    10. public void onDisable(){
    11. PluginDescriptionFile pdfFile = this.getDescription();
    12. + " has been disabled.");
    13. }
    15. @Override
    16. public void onEnable(){
    17. Bukkit.getPluginManager().registerEvents(this, this);
    18. PluginDescriptionFile pdfFile = this.getDescription();
    19. + " v" + pdfFile.getVersion() + " has been enabled.");
    20. this.saveDefaultConfig();
    21. }
    23. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    24. Player player = (Player) sender;
    25. PluginDescriptionFile pdfFile = this.getDescription();
    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. }
    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,, 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


    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


    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


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

Share This Page