Coordinates Help

Discussion in 'Plugin Development' started by Anerdson, Feb 19, 2014.

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

    Anerdson

    Hey Guys!

    I am currently developing a plugin, that will mimic money printers from GMod using signs.

    Code:java
    1. @EventHandler
    2. public Object onSignChange(SignChangeEvent event){
    3. if(event.getLine(0).equalsIgnoreCase("[bprinter]")){ //Checks the top line of sign for "[bprinter]"
    4. Double playerBalance = plugin.econ.getBalance(event.getPlayer().getName()); //Gets the balance of the player
    5. if(playerBalance <= 250){ //checks if their balance is high enough
    6. event.setLine(0, ChatColor.GOLD + "[Printer"); //sets the sign up
    7. event.setLine(1, ChatColor.GOLD + "Bronze");
    8. event.setLine(2, ChatColor.GOLD + "Owned by %OWNER%");
    9. event.setLine(3, ChatColor.GOLD + "Storage: %STORED%");
    10. plugin.econ.withdrawPlayer(event.getPlayer().getName(), 250); //takes money from players account
    11. event.getPlayer().sendMessage(ChatColor.GOLD + "[MP]" + ChatColor.WHITE + "You have created a Bronze Printer!"); //Sends them a message
    12.  
    13. return event.getBlock.getX().getY().getZ();
    14. }
    15. else{
    16. event.getPlayer().sendMessage(ChatColor.RED + "[MP]You do not have enough money to create that printer!"); //Sends them an error message
    17. }
    18. }
    19. }


    This shows the method i use to update the signs to my liking, and i what i need to do now is to get the X,Y,Z, of the sign, and then log that permenantly.

    How would i do this?

    Thanks,
    Anerdson.
     
  2. Offline

    Alshain01

    Log it permanently... or store it so you can read it back and turn it into a Location again?
     
  3. Offline

    Anerdson

    Alshain sorry im new to coding, how would i do this?
     
  4. Offline

    minecraft124_

    Do you want the locations of the signs in a text file, like a list? or do you want to be able to get the locations of the signs again and use them in your plugin?
     
  5. Offline

    Anerdson

    minecraft124_
    i want to be able to get them again easily so i can use them
     
  6. Offline

    minecraft124_

    You could use a config and store the signs, then get their coordinates and whatever other information you want to store with it.
     
  7. Offline

    Anerdson

    minecraft124_
    Okay, what would i use to get the coords, then push them into a config?
     
  8. Offline

    minecraft124_

  9. Offline

    Alshain01

    You should store the world name too. Might as well start with multiworld compatibility, your going to want it eventually.

    EDIT: Or better still, store the World UUID.
     
  10. Offline

    Anerdson

  11. Offline

    Alshain01

  12. Offline

    Anerdson

    Soo,

    Code:java
    1. int x = event.getBlock().getX();
    2. int y = event.getBlock().getY();
    3. int z = event.getBlock().getZ();
    4. UUID world = event.getBlock().getLocation().getWorld().getUID();
    5.  
    6. p.getConfig().set("Sign.Location" + x + y + z + world);


    u mean like this?
     
  13. Offline

    Alshain01

    Yes, but you need some kind of separator or you will never be able to extract it later.

    Code:java
    1. p.getConfig().set("Sign.Location", x + "," + y + "," + z + "," + world);


    Later

    Code:java
    1. String[] location = p.getConfig().getString("Sign.Location").split(",");
     
Thread Status:
Not open for further replies.

Share This Page