PlayerInteractEvent

Discussion in 'Plugin Development' started by badboysteee98, Apr 17, 2014.

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

    badboysteee98

    Hey everyone,

    So I'm making a ParkourPrize plugin and I want it so when they right click a sponge they get say

    In-Game
    In-Items

    How could I make it configurable also what would I do to make it so it's on a timer??

    Any docs would be great thanks :D

    EDIT: Also I mean by paying them is to get the console to run a command that pays them :D
     
  2. Offline

    tackleza

    Maybe you have to create class for timer and make it run every 1 sec and you have to create new Hashmap with <String, Int> to save each player time left <Playername, Timeleft>

    Code:java
    1. public class Timeing implements Runnable{
    2. public static HashMap<String, Integer> parkoutlist = new HashMap<String, Integer>();
    3. @Override
    4. public void run() {
    5. for (String playerName : parkoutlist.keySet()) {
    6. int timeleft = parkoutlist.get(playerName);
    7. timeleft--;
    8. if(timeleft == 0){
    9. //Time up, dosomething
    10. parkoutlist.remove(playerName);//Remove player from countdown list
    11. Player player = Bukkit.getPlayer(playerName);
    12. player.sendMessage("LooL timeup");
    13. }
    14. else{//Save new time
    15. parkoutlist.put(playerName, timeleft);
    16. }
    17. }
    18. }
    19. }
     
  3. Offline

    badboysteee98

    tackleza Where does this state the time 24 hours?
     
  4. Offline

    tackleza

    Err how long do you want to countdown 60s?

    Code:java
    1. public class Timeing implements Runnable{
    2. public static HashMap<String, Integer> parkoutlist = new HashMap<String, Integer>();
    3. @Override
    4. public void run() {
    5. for (String playerName : parkoutlist.keySet()) {
    6. int timeleft = parkoutlist.get(playerName);
    7. Player player = Bukkit.getPlayer(playerName);
    8. timeleft--;
    9. if(timeleft == 0){
    10. //Time up, dosomething
    11. parkoutlist.remove(playerName);//Remove player from countdown list
    12. player.sendMessage("LooL timeup");
    13. }
    14. else{//Save new time
    15. parkoutlist.put(playerName, timeleft);
    16. player.sendMessage("Time left: "+timeleft);
    17. }
    18. }
    19. }
    20. }
    21.  
    22. //----- To add player to countdown
    23.  
    24. public class Onplayerblabal(event e){
    25. Timeing.parkoutlist.put(Playername, 60);//Add player to countdown task for 60 sec
    26. }


    It's will countdown until 0 and it's will remove from countdown list
     
  5. Offline

    badboysteee98

    tackleza Any docs for this as I would need that because I'm abit stuck with this :p
     
  6. Offline

    VictoryShot

    Here is
    Here is my event for 24 hours. When a player does /kit it starts the timer, but when the server restarts the time does too so the player can use it again.
    Code:java
    1. if (cmd.getName().equalsIgnoreCase("kits")) {
    2. if (cooldown.contains(p)) {
    3. p.sendMessage(ChatColor.RED + "You cannot get another kit yet!");
    4. return true;
    5. }
    6. menu.show(p.getPlayer());
    7. cooldown.add(p);
    8. Bukkit.getServer().getScheduler()
    9. .scheduleSyncDelayedTask(this, new Runnable() {
    10. public void run() {
    11. cooldown.remove(p);
    12. }
    13. }, 1728000);
    14. return true;
    15. } else {
    16. p.sendMessage(ChatColor.RED + "You cannot get a kit at this time!");
    17. return true;
    18. }
     
  7. Offline

    tackleza

    ok, so you need to save config into file, if your server not running for 24 hr.

    Maybe to need to used "YamlConfiguration" class (by bukkit)
    save playerlist and load playerlist


    File parkoutfile = new File(plugin.getDataFolder(), "parkourcooldown.yml");
    YamlConfiguration parkoutfileconfig = YamlConfiguration.loadConfiguration(parkoutfile);

    more infomation here: http://wiki.bukkit.org/Configuration_API_Reference

    parkoutfileconfig.addDefault();
    parkoutfileconfig.getInt();//to get time from player name you have to use getInt
    parkoutfileconfig.set();//don't forget to save

    **Note: you should create task to save player process if your server crash or error
    **Note: you should create save function and call it when server stop(onDisable event on your mainclass)

    If you still need help, let me know:)
     
    badboysteee98 likes this.
  8. Offline

    Plo124

    VictoryShot badboysteee98 tackleza
    Store a date in a player config, and then check if the date is more than 24 hours appart.
    This will save lots of CPU because you only need to check it once the player does the command, and it doesnt have to write to the file every second for every player multiple times.
     
  9. Offline

    tackleza

    Store a date in a player config, and then check if the date is more than 24 hours appart.
    This will save lots of CPU because you only need to check it once the player does the command, and it doesnt have to write to the file every second for every player multiple times.[/quote]


    nice idea to use player config

    just create file and put timedate into that file
    that file name like

    Your_Plugin_Folder/cooldown/Tacklezaza.txt
    Your_Plugin_Folder/cooldown/badboysteee98.txt

    you can use txt or whatever u like

    //----- How to get next 24 hour
    Calendar calendar = new GregorianCalendar();
    calendar.add(Calendar.DAY_OF_MONTH, 1);
    String nextday= dateFormat.format(calendar.getTime());
    //nextday --> It's will have something like "2014-04-02 15:14:43"

    And how to compare time
    http://stackoverflow.com/questions/7913264/compare-two-timestamp-in-java

    or you can search by "How to compate timestamp java"

    *Note* If you doing like this there will have a lot of file if you have a lot of player
     
Thread Status:
Not open for further replies.

Share This Page