Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.bwfcwalshy.kickstarter;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.UUID;
- import net.milkbowl.vault.economy.Economy;
- import org.bukkit.Bukkit;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.Player;
- public class ProjectManager
- {
- private Kickstarter plugin;
- private List<Project> projects;
- public ProjectManager(Kickstarter instance)
- {
- this.plugin = instance;
- this.projects = new ArrayList();
- getProjects();
- }
- public void createProject(Player p, String name, double target)
- {
- this.plugin.getConfiguration().set(p.getUniqueId().toString() + ".projectName", name);
- this.plugin.getConfiguration().set(p.getUniqueId().toString() + ".projectTarget", Double.valueOf(target));
- this.plugin.getConfiguration().set(p.getUniqueId().toString() + ".totalCollected", Integer.valueOf(0));
- this.plugin.save();
- }
- public void endProject(Player p)
- {
- this.plugin.getConfiguration().set(p.getUniqueId().toString(), null);
- this.plugin.save();
- }
- public boolean hasProject(Player p)
- {
- return this.plugin.getConfiguration().contains(p.getUniqueId().toString());
- }
- public Project getProject(String projectName)
- {
- for (Project project : getProjects()) {
- if (project.getName().equals(projectName)) {
- return project;
- }
- }
- return null;
- }
- public List<Project> getProjects()
- {
- if (!this.projects.isEmpty()) {
- return this.projects;
- }
- for (String uuid : this.plugin.getConfiguration().getKeys(false)) {
- 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")));
- }
- return this.projects;
- }
- public Project getPlayerProject(Player p)
- {
- for (Project project : getProjects()) {
- if (project.getOwner().equals(p.getUniqueId())) {
- return project;
- }
- }
- return null;
- }
- public double getCollected(Project project)
- {
- return project.getCollected();
- }
- public void fundProject(Project project, Player funder, double amount)
- {
- this.plugin.economy.depositPlayer(Bukkit.getOfflinePlayer(project.getOwner()), amount);
- String uuid = project.getOwner().toString();
- this.plugin.getConfiguration().set(uuid + ".totalCollected", Double.valueOf(getCollected(project) + amount));
- project.addToCollected(amount);
- List<String> funders;
- List<String> funders;
- if (!this.plugin.getConfiguration().contains(uuid + ".funders")) {
- funders = new ArrayList();
- } else {
- funders = this.plugin.getConfiguration().getStringList(uuid + ".funders");
- }
- funders.add(funder.getName() + ":" + amount);
- project.addFunder(funder.getName(), amount);
- this.plugin.getConfiguration().set(uuid + ".funders", funders);
- this.plugin.save();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement