Solved Code does weird things

Discussion in 'Plugin Development' started by ArthurHoeke, Jun 2, 2014.

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

    ArthurHoeke

    Hello

    Im working on a robbery plugin, And i got some problems.
    Like it says massages 2 times but i only have 1 message code line and it checks the hashmap wrong etc

    Code:
        @EventHandler
        public void blockBreak(BlockBreakEvent e) throws Exception {
            Player p = e.getPlayer();
                Location Open = new Location(Bukkit.getWorld("world"), 120.48852, 150, -547.70000);
     
                Block block = Open.getBlock();
     
                if (e.getBlock().getLocation().equals(block.getLocation()))
                    if (Robbery.size() >= 1){
                        p.sendMessage(ChatColor.RED + "Someone is already robbering the bank!");
                    }else
                    Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.GOLD + "Alarm" + ChatColor.RED + "]" + ChatColor.GRAY + " The bank is getting robbert! Cops go to it!");
                    e.setCancelled(true);
                    Robbery.put(p, null);
                    Bukkit.getScheduler().runTaskLater(Main.this, new Runnable() {
                        public void run() {
                            Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.GOLD + "Alarm" + ChatColor.RED + "]" + ChatColor.GRAY + " The vault is open in 1 minute!");
                        }
                            }, 20);
                    Bukkit.getScheduler().runTaskLater(Main.this, new Runnable() {
                        public void run() {
                            Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.GOLD + "Alarm" + ChatColor.RED + "]" + ChatColor.GRAY + " The vault is open in 40 seconds!");
                        }
                            }, 400);
                    Bukkit.getScheduler().runTaskLater(Main.this, new Runnable() {
                        public void run() {
                            Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.GOLD + "Alarm" + ChatColor.RED + "]" + ChatColor.GRAY + " The vault is open in 20 seconds!");
                        }
                            }, 800);
                    Bukkit.getScheduler().runTaskLater(Main.this, new Runnable() {
                        public void run() {
                            Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.GOLD + "Alarm" + ChatColor.RED + "]" + ChatColor.GRAY + " The vault is open in 10 seconds!");
                        }
                            }, 1000);
                    Bukkit.getScheduler().runTaskLater(Main.this, new Runnable() {
                        public void run() {
                            Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.GOLD + "Alarm" + ChatColor.RED + "]" + ChatColor.GRAY + " The vault is open in 5 seconds!");
                        }
                            }, 1100);
                    Bukkit.getScheduler().runTaskLater(Main.this, new Runnable() {
                        public void run() {
                            Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.GOLD + "Alarm" + ChatColor.RED + "]" + ChatColor.GRAY + " The vault is open! Common cops! Get them!");
                        }
                            }, 1200);
        }
    }
     
  2. Offline

    Necrodoom

    You don't have a hashmap in this paste.
    Paste full code.
     
  3. Offline

    ArthurHoeke

    Necrodoom Thats too long. And the hashmap code is here:

    if (e.getBlock().getLocation().equals(block.getLocation()))
    if (Robbery.size() >= 1){
    p.sendMessage(ChatColor.RED + "Someone is already robbering the bank!");
    }else
    Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.GOLD + "Alarm" + ChatColor.RED + "]" + ChatColor.GRAY + " The bank is getting robbert! Cops go to it!");
    e.setCancelled(true);
    Robbery.put(p, null);
    Bukkit.getScheduler().runTaskLater(Main.this, new Runnable() {
    public void run() {
    Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.GOLD + "Alarm" + ChatColor.RED + "]" + ChatColor.GRAY + " The vault is open in 1 minute!");
    }
    }, 20);
     
  4. Offline

    Necrodoom

  5. Offline

    ArthurHoeke

    Necrodoom I cant its a private project sorry :( But in the code i show you can see whats wrong...
     
  6. Offline

    BlueMustache

    ArthurHoeke

    I once had a weird glitch like that.
    A random guy asked me to make a plugin that used Disguise craft, and allowed you to shoot the projectile of whatever creature you were.
    It worked great on my old windows xp server.
    When I gave it to him to use. It worked fine.
    But, it duplicated everything that was happening. (Projectiles fired, messages sent, commands sent, etc.)
    Are you hosting your own server for testing, or using a hosting company? (MCProHost?)
    It is probably a code problem, but it is just an idea.
    - Blue
     
  7. Offline

    Necrodoom

    No, I can't see. You pasted a piece of code, and the problem is caused by something outside of it. But if you don't want to paste your code in fear of people copying your code, despite that there are hundreds of open source plugins doing this already, then I cannot help you.
     
    AdamQpzm likes this.
  8. Offline

    ArthurHoeke

    BlueMustache We are on a hosting.

    Updated code but still dont work
    Code:
    @EventHandler
        public void blockBreak(BlockBreakEvent e) throws Exception {
            Player p = e.getPlayer();
                Location Open = new Location(Bukkit.getWorld("world"), 120.48852, 150, -547.70000);
     
                Block block = Open.getBlock();
     
                if (e.getBlock().getLocation().equals(block.getLocation()))
                    if (Robbery.size() >= 1){
                        p.sendMessage(ChatColor.RED + "Someone is already robbering the bank!");
                    }else
                    Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.GOLD + "Alarm" + ChatColor.RED + "]" + ChatColor.GRAY + " The bank is getting robbert! Cops go to it!");
                    e.setCancelled(true);
                    Robbery.put(p, null);
                    Bukkit.getScheduler().runTaskLater(Main.this, new Runnable() {
                        public void run() {
                            Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.GOLD + "Alarm" + ChatColor.RED + "]" + ChatColor.GRAY + " The vault is open in 1 minute!");
                        }
                            }, 20);
                    Bukkit.getScheduler().runTaskLater(Main.this, new Runnable() {
                        public void run() {
                            Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.GOLD + "Alarm" + ChatColor.RED + "]" + ChatColor.GRAY + " The vault is open in 40 seconds!");
                        }
                            }, 400);
                    Bukkit.getScheduler().runTaskLater(Main.this, new Runnable() {
                        public void run() {
                            Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.GOLD + "Alarm" + ChatColor.RED + "]" + ChatColor.GRAY + " The vault is open in 20 seconds!");
                        }
                            }, 800);
                    Bukkit.getScheduler().runTaskLater(Main.this, new Runnable() {
                        public void run() {
                            Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.GOLD + "Alarm" + ChatColor.RED + "]" + ChatColor.GRAY + " The vault is open in 10 seconds!");
                        }
                            }, 1000);
                    Bukkit.getScheduler().runTaskLater(Main.this, new Runnable() {
                        public void run() {
                            Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.GOLD + "Alarm" + ChatColor.RED + "]" + ChatColor.GRAY + " The vault is open in 5 seconds!");
                        }
                            }, 1100);
                    Bukkit.getScheduler().runTaskLater(Main.this, new Runnable() {
                        public void run() {
                            Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.GOLD + "Alarm" + ChatColor.RED + "]" + ChatColor.GRAY + " The vault is open! Common cops! Get them!");
                        }
                            }, 1200);
        }
    bumb

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 30, 2016
  9. Offline

    PreFiXAUT

    1. What's with the Location for Open? Isn't a block always on Coordinates without comma?
    2. Sure you didn't forgot the Brackets?
    Show Spoiler

    Code:java
    1. }else
    2. Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.GOLD + "Alarm" + ChatColor.RED + "]" + ChatColor.GRAY + " The bank is getting robbert! Cops go to it!");
    3. e.setCancelled(true);


    3. Do you get any Errors in the Console maybe?
     
  10. Offline

    ArthurHoeke

    PreFiXAUT
    1. The cordinates are the block that the player breaks
    2. Im sure i dont forget the brackets.
    3. No
     
  11. Offline

    Deleted user

    ArthurHoeke
    So, this is a private project. Therefore you can't paste code.

    I think it'd be fine if you pasted it considering the bad quality that it's in. Example: Creating 10 BukkitRunnables instead of one with a decrementing timer.

    Also, are you totally sure you didn't forget the bracket? I'm assuming you copy/pasted the code here, so unless you randomly deleted stuff from it...

    Finally, why are your variable names uppercase? And if not, that might also be why.

    And you are doing an extremely ineffective method to do so.
    You hardcode a non-exact location, find a block in that location, get the location of said block to get the exact location, and only then compare it with the actual mined location.
    You could skip this and compare directly with open by creating the location without decimals.
    Also, we still cannot see what causes your problem, because:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 9, 2022
  12. Offline

    Konkz

    "Message sends twice".
    *Looks at code*
    Sees like 10 different messages.

    What is wrong? Did you even bother adding debug mode to see what's going wrong, also from what I can tell nobody would copy this code as it is easily re creatable, especially if you have an API that setsup the arena and such already ready for you and you just fill in the gabs.

    Also this makes me laugh, ngl
    PHP:
    ukkit.broadcastMessage(ChatColor.RED "[" ChatColor.GOLD "Alarm" ChatColor.RED "]" ChatColor.GRAY " The bank is getting robbert! Cops go to it!");
    Bank is getting robbert! - I died when I read that.

    EDIT Also just noticed, wtf is "throws exception" doing there?
    PHP:
    public void blockBreak(BlockBreakEvent ethrows Exception {
     
  13. Offline

    ArthurHoeke

    Konkz If you only want to say something about my english, You dont have to react on this. I know i dont have the best english, Cause im dutch.
     
  14. Offline

    Konkz

    Don't take it in an offensive way, I just never saw someone do that. :p

    Yet, my questions remain unanswered:
     
  15. Offline

    ArthurHoeke

    Konkz Already fixed it...
     
  16. Offline

    Konkz

    Should of told us ;-;
    Anyways, good to hear! :)
     
Thread Status:
Not open for further replies.

Share This Page