Enabling a plugin on certain dates

Discussion in 'Plugin Development' started by Vidsify, Oct 24, 2014.

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

    Vidsify

    Hi

    I've managed to get my plugin to work only on certain days that the player specifies in the config but I am struggling to get it to work on certain dates eg DD/MM/YY 26/10/14.

    Here's my code for the days part

    Code:java
    1. @EventHandler
    2. public void onExpChange(PlayerExpChangeEvent e) {
    3. Calendar mydate = Calendar.getInstance();
    4. int dow = mydate.get(7);
    5. Boolean alreadyDone = Boolean.valueOf(false);
    6. List<String> EnabledDays = this.config.getStringList("DaysToEnable");
    7. this.config.getInt("CheckRadius");
    8. for (String Day : EnabledDays) {
    9. int currentDay = 0;
    10. if (Day.toLowerCase().contains("mon")) {
    11. currentDay = 2;
    12. } else if (Day.toLowerCase().contains("tue")) {
    13. currentDay = 3;
    14. } else if (Day.toLowerCase().contains("wed")) {
    15. currentDay = 4;
    16. } else if (Day.toLowerCase().contains("thu")) {
    17. currentDay = 5;
    18. } else if (Day.toLowerCase().contains("fri")) {
    19. currentDay = 6;
    20. } else if (Day.toLowerCase().contains("sat")) {
    21. currentDay = 7;
    22. } else if (Day.toLowerCase().contains("sun")) {
    23. currentDay = 1;
    24. }
    25. if ((dow == currentDay) && (!alreadyDone.booleanValue()))
    26. ;
     
  2. Offline

    Tecno_Wizard

    Create a new Date object and it is immedietly initiated with the system's date. Then just only call the command and listener registers when you want them based on the date. Vidsify
     
  3. Offline

    Vidsify

    Tecno_Wizard Hang on I'm confused as I had help doing this the first time from stevesmithjr but he's unsure on how to do the dates part
     
  4. Offline

    _Filip

  5. Offline

    fireblast709

    Vidsify you have a Calendar instance use that. Most methods in Date are deprecated. Moreover, instead of Boolean use boolean. Lastly, the getInt("CheckRadius") isn't used, so either use it or remove it.
     
  6. Offline

    Vidsify

    fireblast709 ah ok and the check radius is used further down my code
     
  7. Offline

    TheMintyMate

    Vidsify
    I suggest you use Filip 's Date.java, as he has neatly put together a class designed to determine the day.
    Please can I also suggest that you apply this to a new class(@Filip 's class), remove the unnecessary code for your plugin and then refer to it like this:
    Code:
    private CheckDate cd; //CheckDate is the class
    @EventHandler
    public void onExpChange(PlayerExpChangeEvent e) {
    cd = new CheckDate(); //initialisation. This could also be done on the loading of the plugin
    if (cd.isValid()){ //isValid() method inside CheckDate class
    //do stuff
    }
    }
    
    This will make your plugin look cleaner, and allow you to easily check whether it is
    a correct date, without constantly checking as an if statement as you are showing above.

    Hope this marginally helped,
    - Minty
     
  8. Offline

    es359

  9. Offline

    _Filip

    es359 Wouldn't have posted it if I didn't want you using it :)
     
    es359 likes this.
Thread Status:
Not open for further replies.

Share This Page