Solved Keeping Location through reloads

Discussion in 'Plugin Development' started by CarPet, Nov 3, 2012.

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

    CarPet

    I am working on a plugin but have run into a huge problem, in order for it to work I need the player be able to click on a sign if the text on the line is right and something will be executed. For example if Test was on the first line it would say test but when you reload the server it does nothing. Anyway to save the location through reloads? Please post your code if you find an answer!
     
  2. Offline

    bobacadodl

    You could store the location in a custom configuration file and in your plugin's onEnable, load it.

    EDIT: or you could save the list of locations to disk.
     
  3. Offline

    ZeusAllMighty11

    I used something like this before:

    This isn't full code and i'm trying to remember:

    Code:
     
    Block block = e.getClickedBlock(); // clicked block from interact event
    // do checks for sign
     
    Location 1xblock.getLocation().getX();
    Location 1y block.getLocation().getY();
    Location 1z block.getLocation().getZ();
    Location 1 = new Location(Bukkit.getWorld("World"), 1x, 1, 1z);
     
    getConfig().set("SignLocation.1", 1);
     
  4. Offline

    CarPet

    Alright, guys, could you please post your code on how to check if a player clicks a button at certain coords? Thanks a ton!
     
  5. Offline

    ZeusAllMighty11

    Simple. Like the code above:


    if(e.getClickedLocation() == 1){
    // do stuff
    }


    1 is the location, e.getClickedLocation() is where they clicked
     
  6. Offline

    CarPet

    Gosh!! I understand other problems I have run into but cannot seem to overcome this one! Please go in depth I am noobing it up :/
     
  7. Offline

    fireblast709

    Code:java
    1. @EventHandler
    2. public void onClick(PlayerInteractEvent event)
    3. {
    4. if(event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getMaterial() == Material.STONE_BUTTON)
    5. {
    6. Player p = event.getPlayer();
    7. Block button = p.getTargetBlock(null, 10);
    8. Location l = button.getLocation();
    9. }
    10. }

    Then use that Location l to check if it matches your coordinates
     
  8. Offline

    CarPet

    Okay I cannot get it to work...

    Please go into full explain mode, I am failing tonight for some reason...
    What I am looking for is if it is at 1, 75, 1 then it will say good and if it is at 2,75,2 then it will say bad. Please post the code for that, I do not know why I can't understand this...

    Thanks
     
  9. Offline

    fireblast709

    Do you know how to work with events? For the rest, just do something like this:
    Code:java
    1. // These are defined somewhere in your code, or in the if statement self
    2. int x = 1;
    3. int y = 75;
    4. int z = 1;
    5. // l is the Location object
    6. if(l.getX() == x && l.getY() == y && l.getZ() == z)
    7. {
    8. // as we use the 'good' coordinates, send message "good"
    9. }


    This would do for "bad" as well.
     
    CarPet likes this.
  10. Offline

    CarPet

    Thank you! I do not know why I couldn't figure it out XD So simple! +1
     
  11. Offline

    fireblast709

    CarPet no problem, Ill help anytime I am awake and on Bukkit :3
     
  12. Offline

    CarPet

    It is super buggy D: WOrks some times and others it doesnt
     
  13. Offline

    CevinWa

    U could save it in an arraylist with serializeablelocation. :D
     
  14. Offline

    CarPet

    I just created a flat file... Thanks for all the help though
     
Thread Status:
Not open for further replies.

Share This Page