Store location of block in config

Discussion in 'Plugin Development' started by CraterHater, Jun 21, 2015.

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

    CraterHater

    How do I store a location of a emerald block in the config upon right clicking. I want every time some right clicks a emerald block to check if the location of that block is in the config behind the clickers name or if nothing is in there. how do I do that?
     
  2. Offline

    meguy26

  3. Offline

    seanliam2000

    Pretty unhelpful response, for all you know he could be good at java and new to the bukkit API

    I would store the location of the x y and z in a list in your config

    Then you would use the PlayerInteractEvent to check if they right clicked on the block getting the x y and z of the block
     
  4. Offline

    meguy26

    @seanliam2000
    True, my response was utterly unhelpful. However, everything in his question can be answered with 2-3 google searches. Regardless of his java knowledge, this is a lazy question.


    @CraterHater
    1. Save locations to config
    2. Check if they are there on PlayerInteractEvent
    3. If they are do something...

    See the following:
    http://bukkit.org/threads/serializing.368229/
    http://wiki.bukkit.org/Plugin_Tutorial
    http://wiki.bukkit.org/Event_API_Reference
    http://wiki.bukkit.org/Configuration_API_Reference
     
    seanliam2000 likes this.
  5. Offline

    CraterHater

    @meguy26 @seanliam2000 why doesn't this work? Ow and I want it to be an dragon egg except for an emerald block
    Code:
     @EventHandler
                                                            public void onPlayerInteract8(PlayerInteractEvent e){                                                       
                                                                Player p = e.getPlayer();
                                                                if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
                                                                    Block b = e.getClickedBlock();
                                                                    if(b.getType().equals(Material.DRAGON_EGG)){
                                                                         e.setCancelled(true);
                                                                       
                                                                             double x = (double) getConfig().get("EGGX");
                                                                             double z = (double) getConfig().get("EGGY");
                                                                             double y = (double) getConfig().get("EGGZ");
                                                                             World w = (World) getConfig().get("EGGW");
                                                                             Location spawn = new Location(w, x, y, z);
                                                                            if(spawn == b.getLocation())
                                                                                 if (Cooldowns.tryCooldown(p, "x13", 30000)) {
                                                                                      Player p1 = e.getPlayer();
                                                                                      p1.sendMessage(ChatColor.GREEN + "Hatched!");
                                          
                                                                                 }else{
                                                                                     p.sendMessage("§b§6[Egg]:§rYou have " + (Cooldowns.getCooldown(p, "x13") / 1000) + " seconds left!");
                                                                                     p.playSound(p.getLocation(), Sound.NOTE_PLING, 6, 6);
    
                                                                                                     }
    
                                                                         }else{                                                                       
                                                                             Integer EGGX = this.getConfig().getInt("EGGX");
                                                                             Integer EGGY = this.getConfig().getInt("EGGY");
                                                                             Integer EGGZ = this.getConfig().getInt("EGGZ");
                                                                             Integer EGGW = this.getConfig().getInt("EGGW");
                                                                             if(EGGX == null
                                                                                     || EGGY == null
                                                                                     || EGGZ == null
                                                                                      || EGGW == null) {
    
    {
                                                                             b.getLocation().getX();
                                                                             b.getLocation().getY();
                                                                             b.getLocation().getZ();
                                                                             b.getLocation().getWorld();
                                                                             getConfig().set("EGGX" + ".x", b.getLocation().getX());
                                                                             getConfig().set("EGGY" + ".y", b.getLocation().getY());
                                                                             getConfig().set("EGGZ" + ".z", b.getLocation().getZ());
                                                                             getConfig().set("EGGW" + ".world", b.getLocation().getWorld());
                                                                             saveConfig();
                                                                             Player p1 = e.getPlayer();
                                                                             p1.sendMessage(ChatColor.GREEN + "Succesfully set the location");
                                                                             return;
                                                                         }
                                                       
                                                                }
                                                            }
                                                            }
    }
                                                           
    }
     
  6. @CraterHater
    First of all, if(spawn == b.getLocation()) will never return true. Replace with something like spawn.getBlock().equals(b)
    And I think your issue is that it sets the config e.g. EGGX.x to the x, while when loading you get the x by EGGX, when setting remove the .x, .y, .z and .world
     
  7. Offline

    CraterHater

    I changed it a bit but it doesn't work. the console gives error: Could not pass PlayerInteractEvent to ServerPlugin. It just says 1 when I right click the egg.
    here is the code:
    Code:
     @EventHandler
                                                            public void onPlayerInteract8(PlayerInteractEvent e){                                                     
                                                                Player p = e.getPlayer();
                                                                if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
                                                                    Block b = e.getClickedBlock();
                                                                    if(b.getType().equals(Material.DRAGON_EGG)){
                                                                         e.setCancelled(true);
                                                                         p.sendMessage(ChatColor.GREEN + "1");
                                                                     
                                                                             double x = (double) getConfig().get("EGGX");
                                                                             double z = (double) getConfig().get("EGGY");
                                                                             double y = (double) getConfig().get("EGGZ");
                                                                             World w = (World) getConfig().get("EGGW");
                                                                             Location eg = new Location(w, x, y, z);
                                                                            if(eg.getBlock().equals(b))
                                                                                 if (Cooldowns.tryCooldown(p, "x13", 30000)) {
                                                                                      Player p1 = e.getPlayer();
                                                                                      p1.sendMessage(ChatColor.GREEN + "Hatched!");
                                        
                                                                                 }else{
                                                                                     p.sendMessage("§b§6[Egg]:§rYou have " + (Cooldowns.getCooldown(p, "x13") / 1000) + " seconds left!");
                                                                                     p.playSound(p.getLocation(), Sound.NOTE_PLING, 6, 6);
    
                                                                                                     }
    
                                                                         }else{                                                                     
                                                                             Integer EGGX = this.getConfig().getInt("EGGX");
                                                                             Integer EGGY = this.getConfig().getInt("EGGY");
                                                                             Integer EGGZ = this.getConfig().getInt("EGGZ");
                                                                             Integer EGGW = this.getConfig().getInt("EGGW");
                                                                             if(EGGX == null
                                                                                     || EGGY == null
                                                                                     || EGGZ == null
                                                                                      || EGGW == null) {
    
    {
                                                                             b.getLocation().getX();
                                                                             b.getLocation().getY();
                                                                             b.getLocation().getZ();
                                                                             b.getLocation().getWorld();
                                                                             getConfig().set("EGGX" + "x", b.getLocation().getX());
                                                                             getConfig().set("EGGY" + "y", b.getLocation().getY());
                                                                             getConfig().set("EGGZ" + "z", b.getLocation().getZ());
                                                                             getConfig().set("EGGW" + "world", b.getLocation().getWorld());
                                                                             saveConfig();
                                                                             Player p1 = e.getPlayer();
                                                                             p1.sendMessage(ChatColor.GREEN + "Succesfully set the location");
                                                                             return;
                                                                         }
                                                     
                                                                }
                                                            }
                                                            }
    }
                                                         
    }
     
    Last edited: Jun 23, 2015
  8. @CraterHater
    You only send the cause of the stacktrace, not the stacktrace where I can do something with. My guess would be that cast of x y and z to double, use getConfig().getDouble instead
     
  9. Offline

    CraterHater

    @megamichiel I guess I need to change something at this code forget the code above:
    Code:
                                @EventHandler
                                                            public void onPlayerInteract8(PlayerInteractEvent e){                                                    
                                                             Player p = e.getPlayer();
                                                               if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
                                                                    Block b = e.getClickedBlock();
                                                                  if(b.getType().equals(Material.DRAGON_EGG)){
                                                                        e.setCancelled(true);
                                                                        p.sendMessage(ChatColor.GREEN + "1");
                                                                             double x = (double) getConfig().get("EGGX");
                                                                             double z = (double) getConfig().get("EGGY");
                                                                             double y = (double) getConfig().get("EGGZ");
                                                                             World w = (World) getConfig().get("EGGW");
                                                                             Location eg = new Location(w, x, y, z);
                                                                            if(eg.getBlock().equals(b))
                                                                                 if (Cooldowns.tryCooldown(p, "x13", 30000)) {
                                                                                     Player p1 = e.getPlayer();
                                                                                      p1.sendMessage(ChatColor.GREEN + "Hatched!");
    
                                                                                 }else{
                                                                                     p.sendMessage("§b§6[Egg]:§rYou have " + (Cooldowns.getCooldown(p, "x13") / 1000) + " seconds left!");
                                                                                     p.playSound(p.getLocation(), Sound.NOTE_PLING, 6, 6);
                                                                                 }
                                                                         }else{                                                                    
    
    
                                                                            Integer EGGX = this.getConfig().getInt("EGGX");
                                                                             Integer EGGY = this.getConfig().getInt("EGGY");
                                                                             Integer EGGZ = this.getConfig().getInt("EGGZ");
                                                                             Integer EGGW = this.getConfig().getInt("EGGW");
                                                                             if(EGGX == null
                                                                                     || EGGY == null
                                                                                     || EGGZ == null
                                                                                     || EGGW == null) {
    
                                                                             b.getLocation().getX();
                                                                             b.getLocation().getY();
                                                                             b.getLocation().getZ();
                                                                             b.getLocation().getWorld();
                                                                             getConfig().set("EGGX" + "x", b.getLocation().getX());
                                                                             getConfig().set("EGGY" + "y", b.getLocation().getY());
                                                                             getConfig().set("EGGZ" + "z", b.getLocation().getZ());
                                                                             getConfig().set("EGGW" + "world", b.getLocation().getWorld());
                                                                             saveConfig();
                                                                             Player p1 = e.getPlayer();
                                                                             p1.sendMessage(ChatColor.GREEN + "Succesfully set the location");
    
    
                                                                            return;
    
    
                                                                         }
    
    
    
    
                                                                }
    
                                                            }
                                                            }
    }
     
  10. Offline

    Zombie_Striker

    @CraterHater
    • Please stick to JavaNamingConventions
    • Instead of just casting a double, actually #getDouble();
    • When comparing two objects, use ==
    • Why use an Integer, when you can just use an int?
    • WHY ARE YOU PUTTING TWO STRING TOGETHER FOR THE PATH INSTEAD OF MAKING THEM ONE
    • Since p1 only comes up once, you should remove that variable.
    • WAIT, YOU HAVE TWO PLAYER VARIABLES?
    • WHATS THE USE FOR LINES 30-40? THEY DO NOTHING ( @meguy26 was right in his first post)
     
  11. Offline

    CraterHater

    I am really confused, can you please explain more.
     
  12. Offline

    CraterHater

  13. Offline

    Googlelover1234

    @CraterHater
    It actually is, as blunt as it sounds. If you plan on learning the Bukkit API, you must be able to write in Java. That's like not knowing Spanish, and then trying to write for a Spanish magazine. Here is a link to get started:

    Oracle: https://docs.oracle.com/javase/tutorial/getStarted/index.html

    Or, if you get bored of reading text, you can watch YouTube videos (Not recommended, people aren't always going to provide you with good examples of how to program in Java)
     
  14. Offline

    CraterHater

    Alright I'll make it clear, I know how to code in Java a bit I am no beginner anymore. However, I do not know anything of config files and stuff like that. I made a lot of other stuff so I am not completely new with java and the Bukkit API.
     
  15. Offline

    Googlelover1234

    @CraterHater
    The problem that most people have here is not that you are new. Now, obviously, we have no problem with helping people who are making a good attempt at improving, but you learn a great deal more if you solve the problem yourself. @meguy26 gave you all that you needed to finish this project, and @Zombie_Striker even took the time to point out your mistakes in Java. As I said, we all must start somewhere, but in order to get help from other developers here, you have to be able to solve problems yourself, and try your hardest to fix your problem.
     
  16. Offline

    CraterHater

    I actually think I can learn more of examples and study it so I know that stuff when I do it again or use the knowledge I learned from studying on problems I would encounter later on.
     
  17. Offline

    Zombie_Striker

    @CraterHater
    Here are all the lines that you should change:
    ALL THE PLAYERS
    For that ==

    Change this from Integer to int
    These doubles, that you are just casting
    Paths that can be put together
    These varibales that do nothing (showing you do not know what you're doing)

     
Thread Status:
Not open for further replies.

Share This Page