[Solved] GetPlayer Undefined [BlockEnderChest]

Discussion in 'Plugin Development' started by Laloth, Aug 2, 2012.

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

    Laloth

    Hello,

    So today i started coding BlockEnderChest and i got the placment of it working but now i want to do when they craft it now i know how to prevent them from crafting it in a config but i jsut want to block the crafting of the EnderChest (Code 130) and i gotten p0retty close well i think i have but right now i am kindof at a brick wall at link 38 of te PlayerListner class getplayer is red int he line Player player = event.getPlayer(); and it is saying that The method getPlayer() is undefined for the type CraftItemEventPlayerListener.java and im not sure how to fix this so if you coudl help em that would be awsome and here is the source code:

    MAIN:http://pastebin.com/gx3xm1XJ
    1. package me.Laloth.Main;
    2. import org.bukkit.plugin.PluginManager;
    3. import org.bukkit.plugin.java.JavaPlugin;
    4. public class Main extends JavaPlugin {
    5. private PlayerListener PlayerListener = new PlayerListener(this);
    6. public static Main plugin;
    7. public void onEnable() {
    8. System.out.println("BlockEnderChest Has Been Enabled");
    9. PluginManager pm = getServer().getPluginManager();
    10. pm.registerEvents(this.PlayerListener, this);
    11. getConfig().options().copyDefaults(true);
    12. saveConfig();
    13. }
    14. public void onDisable() {
    15. System.out.println("BlockEnderChest Has Been Disabled");
    16. }
    17. }
    PLAYERLISTNER:http://pastebin.com/jnccFhht
    1. package me.Laloth.Main;
    2. import java.util.List;
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.block.Block;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.block.BlockPlaceEvent;
    9. import org.bukkit.event.inventory.CraftItemEvent;
    10. import org.bukkit.inventory.ItemStack;
    11. import org.bukkit.permissions.Permissible;
    12. public class PlayerListener implements Listener {
    13. public Main plugin;
    14. public PlayerListener(Main instance) {
    15. plugin = instance;
    16. }
    17. @EventHandler
    18. public static void onPlayerPlaceBlock(BlockPlaceEvent event) {
    19. Player player = event.getPlayer();
    20. Block block = event.getBlockPlaced();
    21. int id = block.getTypeId();
    22. if (((id == 130) || (id == 0)) &&
    23. (!player.hasPermission("BlockEnderChest.PlaceEnderChest")))
    24. {
    25. player.sendMessage(ChatColor.RED + "You cannot place EnderChest!");
    26. event.setCancelled(true);
    27. }
    28. }
    29. @EventHandler
    30. public void onPlayerCraft(CraftItemEvent event) {
    31. ItemStack itm = event.getRecipe().getResult();
    32. Player p = (Player)event.getView().getPlayer();
    33. Player player = event.getPlayer();
    34. int id = itm.getTypeId();
    35. if (((id == 130) || (id == 0)) &&
    36. (!player.hasPermission("BlockEnderChest.CreateenderChest")))
    37. {
    38. player.sendMessage(ChatColor.RED + "You cannot Create EnderChest!");
    39. event.setCancelled(true);
    40. }
    41. }
    42. }
    Plugin.yml- http://pastebin.com/g8bTcpNv

    1. name: BlockEnderChest
    2. version: 1.1
    3. main: me.Laloth.Main.Main
    4. author: Laloth
    5. description: Block's the placing and crafting of EnderChest
    6. permissions:
    7. BlockEnderChest.*:
    8. description: Gives access to all commands
    9. children:
    10. BlockEnderChest.PlaceEnderChest: true
    11. BlockEnderChest.PlaceEnderChest:
    12. description: Allows the placeing of EnderChest!
    13. default: op
    Config.yml- http://pastebin.com/hJ6CEup3

    1. # ###############INFO############
    2. # Welcome to the BlockEnderChest config
    3. # Made by: Laloth
    4. # ##############CONFIG INFO######
    5. # Their isn't that much of a config.
    6. # BlockItems:
    7. # - id1
    8. # - id2
    9. # - id3
    10. # ect:
    11. # ######BEGIN EDITING HERE#########
    12. BlockedItems:
    13. world:
    14. - 130
    15. - 46

    Thank youin advance for helping me!
     
  2. Offline

    Laloth

    Still unsolved
     
  3. Offline

    Megolas

    Although line 33 isnt needed, thats where the bug is. You can delete it and replace p with Player in line 32
    line 33:
    Player player = event.getWhoClicked();
     
  4. Offline

    Laloth

    thanks i got it working!
     
Thread Status:
Not open for further replies.

Share This Page