Why my plugin override all protection plugins!!!???

Discussion in 'Plugin Development' started by EnchantedMiners, Oct 18, 2014.

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

    EnchantedMiners

    Please someone help this is my block break event!
    Code:java
    1. @EventHandler(priority = EventPriority.NORMAL)
    2. public void blockbreak(BlockBreakEvent e){
    3. Player p = e.getPlayer();
    4. SoundsUtility sounds = new SoundsUtility();
    5.  
    6. if(!(p.getInventory().firstEmpty() == -1)){
    7. if(!p.getGameMode().equals(GameMode.CREATIVE)){
    8. for(ItemStack items : e.getBlock().getDrops()){
    9. if (p.getItemInHand().getEnchantments() != null) {
    10. ItemStack item = p.getItemInHand();
    11.  
    12. Map<Enchantment, Integer> enchantments = item.getEnchantments();
    13. if (enchantments.containsKey(Enchantment.LOOT_BONUS_BLOCKS)) {
    14. int level = enchantments.get(Enchantment.LOOT_BONUS_BLOCKS);
    15. for(int i = 0; i <= level; i++){
    16. p.getInventory().addItem(items);
    17. p.updateInventory();
    18. }
    19. } else {
    20. p.getInventory().addItem(items);
    21. }
    22. }
    23. }
    24. e.getBlock().setType(Material.AIR);
    25. e.setCancelled(true);
    26. }
    27. } else {
    28. for(ItemStack items : e.getBlock().getDrops()){
    29. if (p.getItemInHand().getEnchantments() != null) {
    30. ItemStack item = p.getItemInHand();
    31.  
    32. Map<Enchantment, Integer> enchantments = item.getEnchantments();
    33. if (enchantments.containsKey(Enchantment.LOOT_BONUS_BLOCKS)) {
    34. int level = enchantments.get(Enchantment.LOOT_BONUS_BLOCKS);
    35. for(int i = 0; i <= level; i++){
    36. sounds.playSound(p, p.getLocation(), "note.hat", 1, 1);
    37. e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), items);
    38.  
    39. e.getBlock().setType(Material.AIR);
    40. e.setCancelled(true);
    41. }
    42. }
    43. }
    44. }
    45. }
    46. }
     
  2. Offline

    Panjab

    You should add that at the beginning of your event:

    Code:java
    1.  
    2. if (event.isCancelled())
    3. return;
     
  3. Offline

    EnchantedMiners

    Panjab Still does override protection plugins D:
     
  4. Offline

    Watto

    That means the event hasn't been cancelled by your protection plugin, my suggestion would be to move down to the next priority until you noticed a difference.
     
  5. Offline

    EnchantedMiners

    Watto my protection plugin is world guard and i think they cancel the event don't they .... and i tried LOWEST priority and still nothing ...
    Edit: I also look on this code https://github.com/OzairP/AutoInven...m/ozairpatel/autoinventory/EventListener.java and it looks soooooo simple there but in my plugin it just overrides ...
    Maybe my Main class will help a bit:
    Code:java
    1. package net.killacraft;
    2.  
    3. import net.killacraft.events.BreakBlockEvent;
    4.  
    5. import org.bukkit.plugin.PluginManager;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8. public class AutoInventory extends JavaPlugin{
    9. public void onEnable(){
    10. registerEvents();
    11. }
    12. public void registerEvents(){
    13. PluginManager pm = getServer().getPluginManager();
    14.  
    15. pm.registerEvents(new BreakBlockEvent(this), this);
    16. }
    17. }
    18.  
     
  6. Offline

    blablubbabc

    You have to set the priority to at least to HIGHER in order for WorldGuard to be able to cancle it before it reaches your plugin. Then ignore the event if it already is cancelled.
    Also why do you even need to have those lines in there?
    e.getBlock().setType(Material.AIR);
    e.setCancelled(true);

    You are tring to recreate how the server would handle the event? Why not just not cancle it and let the server actually handle it itself?
     
  7. Offline

    fireblast709

    Ever heard of the EventHandler's value 'ignoreCancelled'? Try setting that to true.

    EnchantedMiners HIGHEST is the one that is fired last (not including MONITOR because it is not meant to influence the event, it should just be used for logging and such)
     
  8. Offline

    EnchantedMiners

    Watto Panjab thanks for the help but i just looked up WorldGuard API and find out that there was something called canBuild() xD so easier thanks any ways :D
     
  9. EnchantedMiners Using that might make a needless WorldGuard dependency, depending on how you do it, and will still override other protection plugins. Use a higher priority, and include ignoreCancelled as well :)
     
  10. Offline

    EnchantedMiners

    AdamQpzm thanks! but this plugin is a private plugin for my server so i only use WorldGuard to protect land so, but thanks for the comment! :)
     
Thread Status:
Not open for further replies.

Share This Page