forked from Jason123/iConomyListener
-
Notifications
You must be signed in to change notification settings - Fork 1
/
iConomyListener.java
81 lines (63 loc) · 2.34 KB
/
iConomyListener.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.Server;
//import org.bukkit.ChatColor;
//test
import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider;
import com.vexsoftware.votifier.model.Vote;
import com.vexsoftware.votifier.model.VoteListener;
import net.milkbowl.vault.economy.Economy;
public class iConomyListener implements VoteListener {
/** The logger instance. */
private static Logger logger = Logger.getLogger("iConomyListener");
private int amount = 100;
public iConomyListener() {
Properties props = new Properties();
try {
// Create the file if it doesn't exist.
File configFile = new File("./plugins/Votifier/iConomyListener.ini");
if (!configFile.exists()) {
configFile.createNewFile();
// Load the configuration.
props.load(new FileReader(configFile));
// Write the default configuration.
props.setProperty("reward_amount", Integer.toString(amount));
props.store(new FileWriter(configFile), "iConomy Listener Configuration");
} else {
// Load the configuration.
props.load(new FileReader(configFile));
setupEconomy();
}
amount = Integer.parseInt(props.getProperty("reward_amount", "100"));
} catch (Exception ex) {
logger.log(Level.WARNING, "Unable to load iConomyListener.ini, using default reward value of: " + amount);
}
}
public static Economy economy = null;
Server server = Bukkit.getServer();
private Boolean setupEconomy()
{
RegisteredServiceProvider<Economy> economyProvider = server.getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
if (economyProvider != null) {
economy = economyProvider.getProvider();
}
return (economy != null);
}
@Override
public void voteMade(Vote vote) {
String username = vote.getUsername();
Player player = server.getPlayer(username);
if (player != null){
this.server.broadcastMessage("The server was voted for by " + player.getName() + "!");
economy.depositPlayer(player.getName(), amount);
player.sendMessage("Thanks for voting on " + vote.getServiceName() + "!");
player.sendMessage(amount + " has been added to your iConomy balance.");
}
}
}