Item Spawned on right clicking ground :(

Discussion in 'Plugin Development' started by XxZHALO13Xx, Jul 26, 2014.

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

    XxZHALO13Xx

    So when i click to place a block a ink sack spawns... -_- im like nope that cant happen lol. so how do i fix it? heres the class

    Code:java
    1. public class Blooper implements Listener {
    2.  
    3. //Blooper object
    4.  
    5.  
    6. @EventHandler
    7. public void onPlayerPickupItem(PlayerPickupItemEvent e){
    8. Player p = e.getPlayer();
    9. //Doesn't let the player pick up the blooper
    10. if(e.getItem().getType().equals(Material.INK_SACK)){
    11. e.setCancelled(true);
    12. }
    13. }
    14.  
    15. @EventHandler
    16. public void onPlayerInteract(PlayerInteractEvent e){
    17. Player p = e.getPlayer();
    18. Action a = e.getAction();
    19. //Sets the blooper object(above) to an ink sack
    20. //Checks if the player right clicks it
    21. if(a.equals(Action.RIGHT_CLICK_AIR)){
    22. //Checks to see if the item is a blooper
    23. if(p.getItemInHand().getType().equals(Material.INK_SACK)){
    24. p.sendMessage("§9§lBLOOP!");
    25. //Removes a blooper, takes away 1 if the player has more than 1
    26. p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
    27. if(p.getItemInHand().getAmount() == 1){
    28. p.getItemInHand().setAmount(0);
    29. }
    30.  
    31.  
    32. if (p.getItemInHand().getAmount() == 1){
    33. p.setItemInHand(new ItemStack(Material.AIR));
    34.  
    35.  
    36. }
    37.  
    38. }
    39. //Spawns the blooper
    40. p.getLocation().getWorld().dropItem(p.getLocation(), new ItemStack(Material.INK_SACK));
    41. //Gets players in a 2.5 radius from the player
    42. for(Entity en : p.getNearbyEntities(2.5, 2.5, 2.5)){
    43. if(en instanceof Player){
    44. Player pl = (Player)en;
    45. //Gives the blooper effect
    46. pl.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 5 * 20, 3));
    47. pl.sendMessage("§9§lYou've been blooped by " + p.getName() + "!");
    48. //Add a scheduler here if you want
    49. //Removes the blooper
    50. World world = p.getWorld();
    51. List<Entity> entList = world.getEntities();
    52. for(Entity current : entList){
    53. if (current instanceof Item){
    54. current.remove();
    55. }
    56. }
    57. }
    58. }
    59. }
    60. }
    61. }
    62.  
     
  2. Offline

    Niknea

    XxZHALO13Xx Your short description of the problem didn't help, mind explaing it better? Also, your signature code is incorrect, variables "turqmelon" and "turquoise" aren't defined, and there's a space between ChatColor. and "turquoise". On top of that, there's no main method, fix your signature. : 3
     
  3. Offline

    XxZHALO13Xx

    Niknea for one. its a signature, it can be what i want. for two. when i try to place a block it places but a ink sack spawns with the block causing glitches for a survival games match.
     
  4. Offline

    Niknea

    XxZHALO13Xx That's because you spawned an ink sac in your code. Line 40.
    PHP:
     p.getLocation().getWorld().dropItem(p.getLocation(), new ItemStack(Material.INK_SACK));
     
Thread Status:
Not open for further replies.

Share This Page