Hello guys, I'm creating a custom OP-PVP plugin. And when the plugin gets disabled I upload every players kit delay to mysql so if the server enables the plugin again. I get the all the players kit delay and I start the runnable counting down. but this is the problem I have my table structure like this UUID|KITNAME|SECONDS but in the onEnable I'm getting every UUIDs's seconds and kit by getting every player with the WeeklyKit. but when I get that it gives me a Weekly kit player but not every player that used the Weekly kit(I think), if it isn't like that. how can I get every player that is in the MySQL database that is using the Kit Weekly And put it in a HashMap<Player,Integer> the Integer is seconds so I'm getting the seconds from the mysql database
Funergy First, can I just say to not use Runnables for cooldowns? Use HashMaps with the current time in milliseconds, and check it against the time they try to perform the action again.
Funergy use UUID keys for the Map. You can't use Player objects for persistence past a join session (a join session starts when a player joins, and ends when he leaves).
Gnat008 fireblast709 None of you guys are answering my question -.- lets say it again "how can I get every player that is in the MySQL database that is using the Kit Weekly And put it in a HashMap<Player,Integer> the Integer is seconds so I'm getting the seconds from the mysql database" How. and if I use a run task later I never actually get how long it should take to refresh the kit. like I can't say "You can use your kit again in 10 min 5 sec". fireblast709 I delete them from the list when leaving so theres no problem EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Nonono I thought you said you were loading Players onEnable (in which case you won't have Players online unless it was a reload). Anyway, Gnat008 was somewhat answering your question. Instead of the amount of seconds they have to wait / waited, why not save/load a timestamp (whether it is when they last used it, or when they can use it again). I assume you have method to determine what the kit weekly is. If not (ex. when the weekly kits are personal) you could add a column which tracks if the kit is weekly or not.
Unica No you are wrong I mean I get all the UUIDs from a database that are using the kit Weekly. what you did is just getting 1 player when he joins or something. fireblast709 Okay how should I set in my MySQL when he can use it again. and how can I set when he tries to choose the kit again it says how long it would take to refresh I use this for now Code: public static String getTimeWeeklyTimer(String uuid){ String time = ""; String.format("Can only use kit in %d min, %d sec!", TimeUnit.SECONDS.toMinutes(weeks.get(uuid)), weeks.get(uuid) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(weeks.get(uuid)))); return time; } EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Funergy I would personally go with a BIGINT column (or one of the day / time types MySQL provides). The column would just hold System.currentTimeMillis() + <amount of milliseconds till refresh>. In the case you want to know how long that is, take the difference between that value and System.currentTimeMillis (which gives you the amount of ms between 'now' and the next refresh) and convert that to minutes and seconds.
Unica What fireblast709 Is a better answer I just don't know how to use the BIGINT or even what it is I hear the word Int in it from Integer. so its a Bigger integer what does is do. what is a BigInt is it just 0 or is it an array of ints. fireblast709 Oh nvm http://stackoverflow.com/questions/4302380/what-is-biginteger-and-when-would-we-use-that EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Funergy It's a MySQL data type, I wasn't referring to BigInteger . BIGINT is pretty much the MySQL variant of long.
fireblast709 I'm having a little problem with getting the BigInteger Code: public BigInteger getTime(String UUID,String KIT){ try { PreparedStatement statement = connection.prepareStatement("select TIME from OPPVPKitTimers where UUID='" +UUID+ " KIT='"+KIT+"'"); ResultSet result = statement.executeQuery(); if (result.next()) { return result.getbig;//Here, theres no result.getBigInteger("Time") } else { return null; } } catch (Exception e) { e.printStackTrace(); return null; } } fireblast709 Is this how I should check if he can use the kit again? Code: if(gd.getTime(p.getUniqueId().toString(), "NORMAL")<System.currentTimeMillis()){ EDIT by Moderator: merged posts, please use the edit button instead of double posting.
I refer to my previous post (use getLong() to get BIGINT columns) Assuming you store System.currentTimeMillis() + <milliseconds until refresh>, yes.