Error: couldn't pass event

Discussion in 'Plugin Development' started by Nixo78, Dec 9, 2015.

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

    Nixo78

    Hi, it's about some day i got this problem, and i don't know when it happends :(.
    It's a part of my plugin for disable infinite water in an arena, so there is no natural water source.
    Actually the plugin remove all water(smoothly by setting the water as not source) not placed by a player.
    The plugin remove some ocean, without any bug, but sometimes, it just crash, and i don't know why...
    Error:
    http://pastebin.com/er2gt2iV
    I disconnected myself, because i finished to test my plugin.
    Here my event class:
    EventClass (open)

    Code:
       
    203.@SuppressWarnings("deprecation")
        public void checkifsource(Block b) { // Check if is player source or not.
            // Remove source if not from player
            boolean check = false;
            if (b.getType() == Material.WATER || b.getType() == Material.STATIONARY_WATER) {
                if (b.getData() == (byte) 0) {
                    for (int i = 0; i < plugin.source.size(); i++) {
    210.
                        if (b.getX() == plugin.source.get(i).getX() && b.getY() == plugin.source.get(i).getY()
                                && b.getZ() == plugin.source.get(i).getZ()) {
    
                            check = true;
    215.             }
                    }
                    if (check == false) {
                        b.setData((byte) 1);
                        // Bukkit.broadcastMessage("Non Source");
    220.
                    }
                }
            }
        }
    
    Code:
        226.@EventHandler
        public void onBlockFromToEvent(BlockFromToEvent e) { // start when water
                                                                // flow. Launch
                                                                // check if source
    
    230.      e.setCancelled(false); // to two blocks.
            Block b = e.getBlock();
            Block bf = e.getToBlock();
            checkifsource(b);
            checkifsource(bf);
    235.    }

    Thanks for the help !
    And, someone can tell me something listing what you should and should not do for avoid lags in a plugin ?
    Thanks :)
     
    Last edited: Dec 9, 2015
  2. Offline

    Zombie_Striker

    Caused by: net.minecraft.server.v1_8_R3.ReportedException: Exception while updating neighbours

    at com.gmail.nvandeginste.EventClass.checkifsource(EventClass.java:218) ~[?:?] at com.gmail.nvandeginste.EventClass.onBlockFromToEvent(EventClass.java:233) ~[?:?]

    What is on line 218? What is on line 233?
     
  3. Offline

    Nixo78

    Oh, you are fast, thank ! I was starting add it, i add lines in the first post in few seconds,
     
  4. Offline

    Zombie_Striker

    @Nixo78
    Can you pinpoint those exact lines? Most likely it is that the server can't handle updating soo many blocks (as shown by the "Did the system time change, or is the server overloaded?")
     
  5. Offline

    Nixo78

    Thanks !
    No one was connected to the server, so the chunk are unloaded :S.
    218. b.setData((byte) 1);
    It's what i use for switch the bloc water source to non source
    233. checkifsource(b);

    The log error you seen is when i was not connected, and i stopped the server quicky, sometime the logfile want on 16 mo of error x)
     
  6. Offline

    Zombie_Striker

    @Nixo78
    Before setting the blocks data/type, make sure that either the chunk the block is in is loaded. It can be as simple as if(block.getChunk().isLoaded())
     
  7. Offline

    Nixo78

    So the server crash because he try to modify blocks data not in loaded chunk ? Didn't thinked to that, thanks !
    Edit: Crash again :s
     
  8. Offline

    Zombie_Striker

    @Nixo78
    Check if that makes a difference. If so, mark thread as solved.
     
  9. Offline

    Nixo78

    Just edit my last post, it crashed again :S.
    The error is on same lines.
     
  10. Offline

    Zombie_Striker

    @Nixo78
    Whats the new crash report? Can you post your full startup log?
     
  11. Offline

    Nixo78

    There: http://pastebin.com/VPqsE5i7
    I added some comment, it's why the number of the line error increased, i'll post my event class in few seconds
    Edit:
    There !
    Code:
    package com.gmail.nvandeginste;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Color;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockFace;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockFromToEvent;
    import org.bukkit.event.entity.EntityShootBowEvent;
    import org.bukkit.event.entity.ProjectileHitEvent;
    import org.bukkit.event.player.PlayerBucketEmptyEvent;
    import org.bukkit.event.player.PlayerBucketFillEvent;
    import org.bukkit.event.player.PlayerDropItemEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.LeatherArmorMeta;
    import org.bukkit.scheduler.BukkitScheduler;
    import org.bukkit.potion.PotionEffectType;
    
    public class EventClass implements Listener {
        public main plugin;
    
        public EventClass(main main) {
            this.plugin = main;
        }
    
        /*************************************
         *
         * Bukkit Runnables
         *
         */
        public class BowReload implements Runnable {
            private Player p;
    
            public BowReload(Player _p) {
                this.p = _p;
            }
    
            public void run() {
                int arrowNb = 0;
                ItemStack[] stacks = p.getInventory().getContents();
                for (ItemStack stack : stacks) {
                    if (stack == null) {
                        continue;
                    }
                    if (stack.getType() == Material.ARROW) {
                        arrowNb = stack.getAmount() + arrowNb;
                    }
                }
                if (arrowNb != 3) {
                    p.getInventory().addItem(new ItemStack(Material.ARROW));
                } else {
                    BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
                    scheduler.scheduleSyncDelayedTask(plugin, new BowReload(p), 5 * 20L);
                }
            }
        }
    
        public class Runnabledelay implements Runnable {
            private Block water;
            private String pString;
    
            public Runnabledelay(Block _water, String _pString) {
                this.water = _water;
                this.pString = _pString;
            }
    
            @SuppressWarnings("deprecation")
            public void run() {
                Player p = Bukkit.getServer().getPlayer(pString);
                if (plugin.pIdSource.contains(p.getUniqueId())) {
                    plugin.pIdSource.remove(p.getUniqueId());
                    water.setData((byte) 1);
                    if (p.getInventory().contains(new ItemStack(Material.WATER_BUCKET)) == false) {
                        // est bien le joueur ciblé ???
                        ItemStack[] stacks = p.getInventory().getContents();
                        for (ItemStack stack : stacks) {
                            if (stack == null) {
                                continue;
                            }
                            if (stack.getType() == Material.BUCKET) {
                                stack.setType(Material.WATER_BUCKET);
    
                            }
                        }
                        plugin.source.remove(water);
                    }
    
                }
            }
        }
    
        public class blocBuff implements Runnable {
            private Player p;
    
            public blocBuff(Player _p) {
                this.p = _p;
            }
    
            public void run() {
                if (p.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.GOLD_BLOCK) {
                    p.addPotionEffect(PotionEffectType.JUMP.createEffect((int) 10L, 3));
                    BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
                    scheduler.scheduleSyncDelayedTask(plugin, new blocBuff(p), 10L);
                }
            }
        }
    
        public class blueJoin implements Runnable {
            private Player p;
            private int count;
    
            public blueJoin(Player _p, int _count) {
                this.p = _p;
                this.count = _count;
            }
    
            public void run() {
                if (p.getLocation().getBlock().getType() == Material.ENDER_PORTAL_FRAME && ! plugin.blueTeam.contains(p)) {
                    p.addPotionEffect(PotionEffectType.SLOW.createEffect((int) 50L, 3));
                    count++;
                    if (count == 10) {
                        if (plugin.redTeam.contains(p)){
                            plugin.redTeam.remove(p);
                        }
                        plugin.blueTeam.add(p);
                        ItemStack bboots = new ItemStack(Material.LEATHER_BOOTS, 1);
                        ItemStack blegs = new ItemStack(Material.LEATHER_BOOTS, 1);
                        ItemStack bthorn = new ItemStack(Material.LEATHER_BOOTS, 1);
                        ItemStack bhead = new ItemStack(Material.LEATHER_BOOTS, 1);
                        LeatherArmorMeta bbootsmeta = (LeatherArmorMeta)bboots.getItemMeta();
                        LeatherArmorMeta blegsmeta = (LeatherArmorMeta)blegs.getItemMeta();
                        LeatherArmorMeta bthornmeta = (LeatherArmorMeta)bthorn.getItemMeta();
                        LeatherArmorMeta bheadmeta = (LeatherArmorMeta)bhead.getItemMeta();
                        bbootsmeta.setColor(Color.fromRGB(0, 0, 255));
                        blegsmeta.setColor(Color.fromRGB(0, 0, 255));
                        bthornmeta.setColor(Color.fromRGB(0, 0, 255));
                        bheadmeta.setColor(Color.fromRGB(0, 0, 255));
                        bboots.setItemMeta(bbootsmeta);
                        blegs.setItemMeta(blegsmeta);
                        bthorn.setItemMeta(bthornmeta);
                        bhead.setItemMeta(bheadmeta);
                        p.getInventory().setBoots(bboots);
                        p.getInventory().setLeggings(blegs);
                        p.getInventory().setChestplate(bthorn);
                        p.getInventory().setHelmet(bhead);
                    } else {
                       
                        BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
                        scheduler.scheduleSyncDelayedTask(plugin, new blueJoin(p, count), 10L);
                    }
                }
            }
        }
    
        public class redJoin implements Runnable {
            private Player p;
            private int count;
    
            public redJoin(Player _p, int _count) {
                this.p = _p;
                this.count = _count;
            }
    
            public void run() {
                if (p.getLocation().getBlock().getType() == Material.ENDER_PORTAL_FRAME && ! plugin.redTeam.contains(p)) {
                    p.addPotionEffect(PotionEffectType.SLOW.createEffect((int) 50L, 3));
                    count++;
                    if (count == 10) {
                        if (plugin.blueTeam.contains(p)){
                            plugin.blueTeam.remove(p);
                        }
                        plugin.redTeam.add(p);
                        ItemStack rboots = new ItemStack(Material.LEATHER_BOOTS, 1);
                        ItemStack rlegs = new ItemStack(Material.LEATHER_BOOTS, 1);
                        ItemStack rthorn = new ItemStack(Material.LEATHER_BOOTS, 1);
                        ItemStack rhead = new ItemStack(Material.LEATHER_BOOTS, 1);
                        LeatherArmorMeta rbootsmeta = (LeatherArmorMeta)rboots.getItemMeta();
                        LeatherArmorMeta rlegsmeta = (LeatherArmorMeta)rlegs.getItemMeta();
                        LeatherArmorMeta rthornmeta = (LeatherArmorMeta)rthorn.getItemMeta();
                        LeatherArmorMeta rheadmeta = (LeatherArmorMeta)rhead.getItemMeta();
                        rbootsmeta.setColor(Color.fromRGB(255, 0, 0));
                        rlegsmeta.setColor(Color.fromRGB(255, 0, 0));
                        rthornmeta.setColor(Color.fromRGB(255, 0, 0));
                        rheadmeta.setColor(Color.fromRGB(255, 0, 0));
                        rboots.setItemMeta(rbootsmeta);
                        rlegs.setItemMeta(rlegsmeta);
                        rthorn.setItemMeta(rthornmeta);
                        rhead.setItemMeta(rheadmeta);
                        p.getInventory().setBoots(rboots);
                        p.getInventory().setLeggings(rlegs);
                        p.getInventory().setChestplate(rthorn);
                        p.getInventory().setHelmet(rhead);
                        if (plugin.blueTeam.size()+plugin.redTeam.size()==6){
    
                        }
                    } else {
                        BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
                        scheduler.scheduleSyncDelayedTask(plugin, new redJoin(p, count), 10L);
                    }
                }
            }
        }
    
        /***********************
         *
         * Event Processing: Bow Processing
         */
        @SuppressWarnings("deprecation")
        public void checkifsource(Block b) { // Check if is player source or not.
            // Remove source if not from player
            boolean check = false;
            if (b.getType() == Material.WATER || b.getType() == Material.STATIONARY_WATER) {
                if (b.getData() == (byte) 0) {
                    for (int i = 0; i < plugin.source.size(); i++) {
    
                        if (b.getX() == plugin.source.get(i).getX() && b.getY() == plugin.source.get(i).getY()
                                && b.getZ() == plugin.source.get(i).getZ()) {
    
                            check = true;
                        }
                    }
                    if (check == false && b.getChunk().isLoaded()) {
                        b.setData((byte) 1);
                        // Bukkit.broadcastMessage("Non Source");
    
                    }
                }
            }
        }
    
        @EventHandler
        public void onBlockFromToEvent(BlockFromToEvent e) { // start when water
                                                                // flow. Launch
                                                                // check if source
            e.setCancelled(false); // to two blocks.
            Block b = e.getBlock();
            Block bf = e.getToBlock();
            checkifsource(b);
            checkifsource(bf);
        }
    
        @EventHandler
        public void onPlayerBucketFillEvent(PlayerBucketFillEvent e) {
            Block b = e.getBlockClicked();
            Player p = e.getPlayer();
            for (int i = 0; i < plugin.source.size(); i++) {
                if (b.getX() == plugin.source.get(i).getX() && b.getY() == plugin.source.get(i).getY()
                        && b.getZ() == plugin.source.get(i).getZ()) {
                    plugin.source.remove(i);
    
                    if (plugin.pIdSource.contains(p.getUniqueId())) {
                        plugin.pIdSource.remove(p.getUniqueId());
                    }
    
                }
                e.setCancelled(false);
            }
        }
    
        @EventHandler
        public void onPlayerBucketEmptyEvent(PlayerBucketEmptyEvent e) {
            Player p = e.getPlayer();
            Block b = e.getBlockClicked();
            BlockFace f = e.getBlockFace();
            Block water = b.getRelative(f);
    
            if (e.getBucket() != null && e.getBucket() == Material.WATER_BUCKET) {
                BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
                scheduler.scheduleSyncDelayedTask(plugin, new Runnabledelay(water, p.getPlayerListName()), 5 * 20L);
                plugin.pIdSource.add(p.getUniqueId());
                plugin.source.add(water);
    
            }
            e.setCancelled(false);
        }
    
        /***********************************************************************
         * Bow processing
         *
         ***********************************************************************/
    
        @SuppressWarnings("deprecation")
        @EventHandler
        public void onEntityShootBowEvent(EntityShootBowEvent e) {
            e.setCancelled(false);
            Player p = Bukkit.getServer().getPlayer(e.getEntity().getName());
            BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
            scheduler.scheduleSyncDelayedTask(plugin, new BowReload(p), 5 * 20L);
        }
    
        @EventHandler
        public void onProjectileHitEvent(ProjectileHitEvent e) {
            e.getEntity().remove();
        }
    
        @EventHandler
        public void onPlayerDropItem(PlayerDropItemEvent e) {
            e.setCancelled(true);
        }
    
        /*******
         * Blocs Buffs processing
         */
        @SuppressWarnings("deprecation")
        @EventHandler
        public void onPlayerMoveEvent(PlayerMoveEvent e) {
            Player p = e.getPlayer();
            if (p.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.GOLD_BLOCK) {
                p.addPotionEffect(PotionEffectType.JUMP.createEffect((int) 10L, 3));
                BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
                scheduler.scheduleSyncDelayedTask(plugin, new blocBuff(p), 10L);
            }
            if (p.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.EMERALD_BLOCK) {
                p.addPotionEffect(PotionEffectType.SPEED.createEffect((int) 60L, 3));
            }
            if (p.getLocation().getBlock().getType() == Material.ENDER_PORTAL_FRAME) {
                int rota = p.getLocation().getBlock().getData();
                if (rota == 0 && !p.hasPotionEffect(PotionEffectType.SLOW) && !plugin.blueTeam.contains(p)) {
                    p.addPotionEffect(PotionEffectType.SLOW.createEffect((int) 100L, 3));
                    BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
                    scheduler.scheduleSyncDelayedTask(plugin, new blueJoin(p, 0), 10L);
                }
                if (rota == 2 && !p.hasPotionEffect(PotionEffectType.SLOW)&& !plugin.redTeam.contains(p)) {
                    p.addPotionEffect(PotionEffectType.SLOW.createEffect((int) 100L, 3));
                    BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
                    scheduler.scheduleSyncDelayedTask(plugin, new redJoin(p, 0), 10L);
                }
            }
        }
    }
    
     
  12. Offline

    Zombie_Striker

    at com.gmail.nvandeginste.EventClass.checkifsource(EventClass.java:227) ~[?:?] at com.gmail.nvandeginste.EventClass.onBlockFromToEvent(EventClass.java:242) ~[?:?]

    Why do you need to set the data? Why not set the type to AIR?
     
  13. Offline

    Nixo78

    I set to data because it's more smoothly.
    Set to air ERASE the water, don't erase it and make water removing smooth.
    I'm thinking if it's a nice idea or not to fix this bug, it's a plugin for a minigame, and ... There is 10 water block at max :S.
     
  14. Offline

    Zombie_Striker

    @Zombie_Striker
    Well, I can't figure out why the .setData() thing is casuing the error. One though is that due to blocks around it that may have different values( e.g. Main block = 1, block next to it may be 5. ) Because minecraft works by "sloping" the values (Block with data 1 will be next to block with data 2, and next to that is 3, ect.), it may cause a problem if 1 is next to a 5 or something like that.

    Try setting the type and see if it fixes it.
     
  15. Offline

    Nixo78

    We won't understand us if we edit post when another write post x). (it mean i edited mine).
    The problem is it work fine on mass water area, but sometime, it's crash, like it corrupted the world.
    EDIT: Crashed again with setType, but i removed the chunk loaded check.
     
    Last edited: Dec 9, 2015
  16. Offline

    rbrick

    Last edited: Dec 9, 2015
  17. Offline

    Nixo78

    Last edited: Dec 9, 2015
  18. Offline

    timtower Administrator Administrator Moderator

    Locked.
    Offline mode is not supported.
     
Thread Status:
Not open for further replies.

Share This Page