Double Check Votifier

Discussion in 'Plugin Development' started by Blah1, Dec 30, 2013.

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

    Blah1

    Hey guys. So since you only get 5-6 chances with votifier, I just want to make sure I didn't make any mistakes in my code. So if anyone who has worked with votifer could look over this real quick, that would be awesome :)

    Code:java
    1. @EventHandler(priority = EventPriority.NORMAL)
    2. public void onVote(com.vexsoftware.votifier.model.VotifierEvent event) {
    3. Vote vote = event.getVote();
    4. String s = vote.getUsername().toLowerCase();
    5. FileConfiguration fc = plugin.playerFile(s);
    6. if (fc.getString(s + ".votes") == null) {
    7. fc.set(s + ".votes", 1);
    8. } else {
    9. fc.set(s + ".votes", fc.getInt(s + ".votes") + 1);
    10. }
    11. try {
    12. fc.save(plugin.playerData(s));
    13. } catch (IOException exception) {
    14. exception.printStackTrace();
    15. }
    16. Player player = Bukkit.getServer().getPlayer(vote.getUsername());
    17. for (String ss : plugin.getConfig().getConfigurationSection("votes.").getKeys(false)) {
    18. int i = fc.getInt(s + ".votes");
    19. if (Integer.parseInt(ss) == i) {
    20. if (player != null) {
    21. for (String command : plugin.getConfig().getStringList("votes." + ss + ".commands")) {
    22. Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command.replace("/", ""));
    23. }
    24. } else {
    25. List<String> strings = plugin.getConfig().getStringList("votes." + ss + ".commands");
    26. for (String command : plugin.getConfig().getStringList("votes." + ss + ".commands")) {
    27. strings.add(command);
    28. }
    29. fc.set(s + ".pending-commands", null);
    30. fc.set(s + ".pending", true);
    31. fc.set(s + ".pending-commands", strings);
    32. try {
    33. fc.save(plugin.playerData(s));
    34. } catch (IOException e) {
    35. e.printStackTrace();
    36. }
    37. }
    38. }
    39. }
    40. }


    Resetting every month:

    Code:java
    1. public int getDayOfMonth(Date aDate) {
    2. Calendar cal = Calendar.getInstance();
    3. cal.setTime(aDate);
    4. return cal.get(Calendar.DAY_OF_MONTH);
    5. }
    6.  
    7. public void clearVotes() {
    8. Date date = new Date();
    9. if (getDayOfMonth(date) == 2){
    10. getConfig().set("set-next-vote", true);
    11. saveConfig();
    12. }
    13. if (getDayOfMonth(date) == 1 && getConfig().getBoolean("set-next-vote")) {
    14. String path = getDataFolder().getAbsolutePath();
    15. String plugins = path.substring(0, path.lastIndexOf(File.separator));
    16. File users = new File(plugins + File.separator + "LOLPlugin", "userdata");
    17. getConfig().set("set-next-vote", false);
    18. if (users.exists()) {
    19. for (File file : users.listFiles()) {
    20. String s = file.getName().toLowerCase();
    21. YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
    22. try {
    23. config.set(s + ".votes", 0);
    24. config.set(s + ".votes", false);
    25. config.set(s + ".pending-commands", null);
    26. config.save(file);
    27. } catch (IOException ex) {
    28. ex.printStackTrace();
    29. }
    30. }
    31. }
    32. }
    33. }
     
  2. Offline

    xize

    Blah1
    it seems to look fine although not fully checked.
    just one question why do you use a static reference in your event?:p

    this I mean:p:
    Code:
     public void onVote(com.vexsoftware.votifier.model.VotifierEvent event) {
    
     
  3. Offline

    Blah1

    xize The name of my class is VotifierEvent and they were conflicting. So if run this right now it *should* work?
     
  4. Offline

    rangersmash

    I think there is a /fakevote command that votifier gives you? Or that might be a external plugin.
     
Thread Status:
Not open for further replies.

Share This Page