checking if player has plot.

Discussion in 'Plugin Development' started by shawshark, Jan 30, 2014.

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

    shawshark

    Is there any way to check if player has a plot in the plugin PlotMe. I have used this but it doesn't seem to work.. Seems they don't have much of a published api.
    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    3. if(command.getName().equalsIgnoreCase("test")) {
    4. Player p = (Player)sender;
    5.  
    6. Plot plotid = PlotManager.getPlotById(p);
    7.  
    8. if(plotid !=null) {
    9. getServer().broadcastMessage("[debug] player has a plot.");
    10. } else {
    11. getServer().broadcastMessage("[debug] player doesnt have a plot.");
    12. }
    13. }
    14. return false;
    15. }
     
  2. shawshark Check again their API, or try to create some HashMap that contains player and the plot id (Player, Integer) and compare those onCommand...
     
  3. Offline

    Garris0n

  4. Offline

    ZachBora

    shawshark What you wrote above gets the plot where that player is standing.

    What are you trying to achieve exactly? The closest I can think of is this code :

    Code:java
    1.  
    2. PlotManager.getNbOwnedPlot(Player p, World w); //specific to a world
    3. PlotManager.getNbOwnedPlot(Player p); //any worlds
    4.  

    Note that this is from PlotMe-Core, the syntax may differ on the current released PlotMe version.

    If you're trying to get the actual plots, you can use this :
    Code:java
    1.  
    2. for (Plot plot : plugin.getSqlManager().getOwnedPlots(worldname, playername)) { //here plugin is the instance of PlotMe-Core
    3. }
    4.  

    Note that code will differ in current release.

    PlotMe-Core is the newer version that will be released once I'm done testing it.
     
  5. Offline

    shawshark

    ZachBora
    I'm trying to achieve to see if a player has a created plot or not, anywhere/all worlds.
     
  6. Offline

    shawshark

    ZachBora
    Hey sorry to tag you in a old thread of mine, is there any chance that something like checking if a player has a plot in the new plotme api?
    This would be amazing if you could do it.
     
  7. Offline

    ZachBora

    I can add that. Please create a ticket asking that feature on https://github.com/WorldCretornica/PlotMe-Core/issues
    (I just added issues section, forgot to do it... ._.)
     
  8. Offline

    shawshark

    ZachBora
    Sorry for the late response, I have opened a ticket there.
    Thanks for your time :)
     
  9. Offline

    CraftBang

    ZachBora when is this coming?
    If you add this could you also let it give the plot so (If a player has one plot, I don't know what to do when he has more:p)
    Plot testplot = PlotManager.getPlayerPlot(Player)
    I really need this, thanks anyway the plotme system is amazing!
     
  10. Offline

    ZachBora

    CraftBang Well I haven't touched PlotMe-Core yet, just finished the changes to PlotMe for 1.8. This week I should start convertion of PlotMe-Core to 1.8. Once that's done I'll work on making a better API thingy.

    You can already right now find a player's plots, by looping in them I believe.
     
  11. Offline

    CraftBang

    ZachBora

    How would I go about looping in them

    Code:
    public static void test(Player p ){
    for (Plot ps : SqlManager.getPlots("world")){// 
     
    }
    }
    
    I get this error (in eclipse) Error : Can only iterate over an array or an instance of java.lang.Iterable at SqlManager.getPlots("world")
     
  12. Offline

    ZachBora

  13. Offline

    CraftBang

  14. Offline

    CraftBang

    ZachBora sorry for going a little bit offtopic, but how would I make using your SQL stop freezing my server for +- 0.2 Seconds

    I'm using this code:
    Code:
    public static void giveCoins(Player p, int amount){
    Plot ps = PlotManager.getFirstPlot(p.getUniqueId());
    int bedrag = Integer.parseInt(ps.comments.get(28)[1]) + amount;
     
    String comment[] = {"Coins", String.valueOf(bedrag)};
    ps.comments.set(28, comment);
     
    SqlManager.deletePlotComment(PlotManager.getIdX(ps.id), PlotManager.getIdZ(ps.id), 29, ps.world);
    SqlManager.addPlotComment(comment, 29, PlotManager.getIdX(ps.id), PlotManager.getIdZ(ps.id), ps.world, UUID.fromString("067e6162-3b6f-4ae2-a171-2470b63dff00")); // The UUID is random xD.
    return;
    }
    
    Oh and the code works, no errors :).
    And as you see I'm using your plugin for my data, I thought this would be smart.
    Is there anything I'm doing wrong or something?
    Thanks in advance.
     
  15. Offline

    ZachBora

  16. Offline

    CraftBang

    ZachBora well, the UUID , I found it on internet, Im saving data in ur plugin so I dunno what UUID I need.
    So I just basicly pasted it, im not getting it from a function.

    Btw, so the name is like Coins and the UUID is something else.
    These 2 will NOT match, does that matter?

    I'm going to try the async task. (Tried it work perfectly) my function:
    Code:
    public static void setComment(final String comment[], final Plot ps, final int i){
     Bukkit.getServer().getScheduler().runTaskAsynchronously(Main.plugin, new Runnable() {
               @Override
               public void run() {
               SqlManager.deletePlotComment(PlotManager.getIdX(ps.id), PlotManager.getIdZ(ps.id), i + 1, ps.world);
               SqlManager.addPlotComment(comment, i + 1, PlotManager.getIdX(ps.id), PlotManager.getIdZ(ps.id), ps.world, UUID.fromString("067e6162-3b6f-4ae2-a171-2470b63dff00"));
               }
     });
    }
    
    Should I also put the getFirstPlot(UUID) inside the asynctask ?
    Thanks again :p.
     
  17. Offline

    ZachBora

    CraftBang You should put the poster UUID, if there is one. If there is noone, idk. On comments uuid is only used to update the name when that player changes name. If it's not a player it won't do anything (meaning it can be anything). But if you put a real UUID, it will change "coins" to that player's name if he logs in.

    Yes put the getFirstPlot in the async too, it is probably part of why it's slow.
     
  18. Offline

    CraftBang

    Hey ZachBora it's me again, I've been looking in your plugin.
    I want to do something when a player says /p auto
    So if player says /p auto and he gets hes first plot, than I want to run a method.
    If he DOESNT get hes first plot, than I don't want to run a method.

    I did saw this code
    Code:
    Send(p, C("MsgThisPlotYours") + " " + C("WordUse") + " " + RED + "/plotme " + C("CommandHome") + RESET + " " + C("MsgToGetToIt") + " " + f(-price));
    
    Can I maybe check if the player received that message, and if so run the method?

    Or do I need to download your project, add the line of code and export it?

    Thanks in advance,
    CB
     
  19. Offline

    ZachBora

    CraftBang I'll be working on an API soon to help everyone hook to PlotMe. I don't know what you could do atm aside from checking if he has a plot now in the plot list.
     
  20. Offline

    CraftBang

    ZachBora thanks, but I mean in general with bukkit, is it possible to like Monitor? so if a player says /p auto that I can check with my plugin that the player used that command?
    Than I'll check if the player has a plot (using getFirstPlot) and run my method.
     
  21. Offline

    ZachBora

    CraftBang likes this.
  22. Offline

    CraftBang

    ZachBora Okay looks amazing, I hope you didn't change too many things, that I can keep parts of my plugin :p.
     
  23. Offline

    ZachBora

    :(
    we'll see
     
  24. Offline

    Alshain01

  25. Offline

    ZachBora

    Alshain01 UUID release is already released. PlotMe-Core is an on-going project. I was pretty stable but then someone commited things and now the project is all changed and unstable.

    I want to fix/unchange his stuff and redo the core to have a nice API. More object oriented and easy to understand.
     
  26. Offline

    Alshain01

    Cool, I'll be watching. CraftBang sorry for the hijack you can have your thread back now.
     
  27. Offline

    CraftBang

    Alshain01 it wasn't even my thread xD, no problem though.
     
  28. Offline

    Alshain01

    Oh oops. So a hijack of a hijack lol.
     
    CraftBang likes this.
  29. Offline

    ZachBora

    One of the main things I want the api to do is something like

    PlotMe.getPlots.findWorld(world).findPlayer(player).first().reset()

    Not saying that the above line would be useful but the kind of things I'd like it to be able to do.

    Edit: more like
    PlotMe.getPlots.filterBy(World).filterBy(player).first().reset()
     
  30. Offline

    CraftBang

    ZachBora sorry for asking all those questions but,,

    Code:
    public static void setComment(final String comment[], final Plot ps, final int i){
     Bukkit.getServer().getScheduler().runTaskAsynchronously(Main.plugin, new Runnable() {
               @Override
               public void run() {
               SqlManager.deletePlotComment(PlotManager.getIdX(ps.id), PlotManager.getIdZ(ps.id), i + 1, ps.world);
               SqlManager.addPlotComment(comment, i + 1, PlotManager.getIdX(ps.id), PlotManager.getIdZ(ps.id), ps.world, UUID.fromString("067e6162-3b6f-4ae2-a171-2470b63dff00"));
               }
     });
    }
    
    That's my function to set a comment. but do I even need to delete the comment first? or will the addPlotComment OVERRIDE ur old comment?

    Thanks in advance again, this is like my last question for the next few weeks I hope :).
     
Thread Status:
Not open for further replies.

Share This Page