Advertisement
Guest User

ProjectManager.java

a guest
Sep 1st, 2014
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.07 KB | None | 0 0
  1. package com.bwfcwalshy.kickstarter;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.UUID;
  6. import net.milkbowl.vault.economy.Economy;
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.configuration.file.FileConfiguration;
  9. import org.bukkit.entity.Player;
  10.  
  11. public class ProjectManager
  12. {
  13.   private Kickstarter plugin;
  14.   private List<Project> projects;
  15.  
  16.   public ProjectManager(Kickstarter instance)
  17.   {
  18.     this.plugin = instance;
  19.    
  20.     this.projects = new ArrayList();
  21.     getProjects();
  22.   }
  23.  
  24.   public void createProject(Player p, String name, double target)
  25.   {
  26.     this.plugin.getConfiguration().set(p.getUniqueId().toString() + ".projectName", name);
  27.     this.plugin.getConfiguration().set(p.getUniqueId().toString() + ".projectTarget", Double.valueOf(target));
  28.     this.plugin.getConfiguration().set(p.getUniqueId().toString() + ".totalCollected", Integer.valueOf(0));
  29.    
  30.     this.plugin.save();
  31.   }
  32.  
  33.   public void endProject(Player p)
  34.   {
  35.     this.plugin.getConfiguration().set(p.getUniqueId().toString(), null);
  36.     this.plugin.save();
  37.   }
  38.  
  39.   public boolean hasProject(Player p)
  40.   {
  41.     return this.plugin.getConfiguration().contains(p.getUniqueId().toString());
  42.   }
  43.  
  44.   public Project getProject(String projectName)
  45.   {
  46.     for (Project project : getProjects()) {
  47.       if (project.getName().equals(projectName)) {
  48.         return project;
  49.       }
  50.     }
  51.     return null;
  52.   }
  53.  
  54.   public List<Project> getProjects()
  55.   {
  56.     if (!this.projects.isEmpty()) {
  57.       return this.projects;
  58.     }
  59.     for (String uuid : this.plugin.getConfiguration().getKeys(false)) {
  60.       this.projects.add(new Project(this.plugin, UUID.fromString(uuid), this.plugin.getConfiguration().getString(uuid + ".projectName"), this.plugin.getConfiguration().getDouble(uuid + ".projectTarget"), this.plugin.getConfiguration().getDouble(uuid + ".totalCollected")));
  61.     }
  62.     return this.projects;
  63.   }
  64.  
  65.   public Project getPlayerProject(Player p)
  66.   {
  67.     for (Project project : getProjects()) {
  68.       if (project.getOwner().equals(p.getUniqueId())) {
  69.         return project;
  70.       }
  71.     }
  72.     return null;
  73.   }
  74.  
  75.   public double getCollected(Project project)
  76.   {
  77.     return project.getCollected();
  78.   }
  79.  
  80.   public void fundProject(Project project, Player funder, double amount)
  81.   {
  82.     this.plugin.economy.depositPlayer(Bukkit.getOfflinePlayer(project.getOwner()), amount);
  83.    
  84.     String uuid = project.getOwner().toString();
  85.    
  86.     this.plugin.getConfiguration().set(uuid + ".totalCollected", Double.valueOf(getCollected(project) + amount));
  87.     project.addToCollected(amount);
  88.     List<String> funders;
  89.     List<String> funders;
  90.     if (!this.plugin.getConfiguration().contains(uuid + ".funders")) {
  91.       funders = new ArrayList();
  92.     } else {
  93.       funders = this.plugin.getConfiguration().getStringList(uuid + ".funders");
  94.     }
  95.     funders.add(funder.getName() + ":" + amount);
  96.     project.addFunder(funder.getName(), amount);
  97.    
  98.     this.plugin.getConfiguration().set(uuid + ".funders", funders);
  99.     this.plugin.save();
  100.   }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement