Economy support!

Supports any economy supported by Vault. Requires Vault plugin
installed on server.

Closes #98, ping #132, #294, #12
This commit is contained in:
cmastudios 2014-02-26 20:00:29 -06:00
commit 0a80198084
6 changed files with 73 additions and 5 deletions

View File

@ -35,6 +35,10 @@
<id>mcstats.releases</id>
<url>http://repo.mcstats.org/content/repositories/releases/</url>
</repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.theyeticave.net/content/repositories/pub_releases</url>
</repository>
</repositories>
<issueManagement>
<system>Github issues</system>
@ -140,5 +144,10 @@
<version>R7</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>Vault</artifactId>
<version>1.2.32</version>
</dependency>
</dependencies>
</project>

View File

@ -8,6 +8,8 @@ import java.util.logging.FileHandler;
import java.util.logging.Formatter;
import java.util.logging.Level;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
@ -20,7 +22,10 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import com.tommytony.war.command.WarCommandHandler;
import com.tommytony.war.config.FlagReturn;
@ -57,8 +62,6 @@ import com.tommytony.war.utility.PlayerState;
import com.tommytony.war.utility.SizeCounter;
import com.tommytony.war.utility.WarLogFormatter;
import com.tommytony.war.volume.Volume;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
/**
* Main class of War
@ -99,6 +102,7 @@ public class War extends JavaPlugin {
private final InventoryBag defaultInventories = new InventoryBag();
private KillstreakReward killstreakReward;
private MySQLConfig mysqlConfig;
private Economy econ = null;
private final WarConfigBag warConfig = new WarConfigBag();
private final WarzoneConfigBag warzoneDefaultConfig = new WarzoneConfigBag();
@ -229,6 +233,7 @@ public class War extends JavaPlugin {
teamDefaultConfig.put(TeamConfig.BLOCKWHITELIST, "all");
teamDefaultConfig.put(TeamConfig.PLACEBLOCK, true);
teamDefaultConfig.put(TeamConfig.APPLYPOTION, "");
teamDefaultConfig.put(TeamConfig.ECOREWARD, 0.0);
this.getDefaultInventories().clearLoadouts();
HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>();
@ -292,6 +297,13 @@ public class War extends JavaPlugin {
this.getServer().getPluginManager().disablePlugin(this);
}
}
if (this.getServer().getPluginManager().isPluginEnabled("Vault")) {
RegisteredServiceProvider<Economy> rsp = this.getServer().getServicesManager()
.getRegistration(Economy.class);
if (rsp != null) {
this.econ = rsp.getProvider();
}
}
War.reloadLanguage();
@ -1341,4 +1353,8 @@ public class War extends JavaPlugin {
return null;
}
}
public Economy getEconomy() {
return econ;
}
}

View File

@ -14,6 +14,8 @@ import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import net.milkbowl.vault.economy.EconomyResponse;
import com.tommytony.war.mapper.VolumeMapper;
import com.tommytony.war.mapper.ZoneVolumeMapper;
import org.apache.commons.lang.StringUtils;
@ -1367,6 +1369,8 @@ public class Warzone {
String winnersStrAndExtra = "Score cap reached. Game is over! Winning team(s): " + winnersStr;
winnersStrAndExtra += ". Resetting warzone and your inventory...";
t.teamcast(winnersStrAndExtra);
double ecoReward = t.getTeamConfig().resolveDouble(TeamConfig.ECOREWARD);
boolean doEcoReward = ecoReward != 0 && War.war.getEconomy() != null;
for (Iterator<Player> it = t.getPlayers().iterator(); it.hasNext();) {
Player tp = it.next();
it.remove(); // Remove player from team first to prevent anti-tp
@ -1375,6 +1379,19 @@ public class Warzone {
if (winnersStr.contains(t.getName())) {
// give reward
rewardPlayer(tp, t.getInventories().resolveReward());
if (doEcoReward) {
EconomyResponse r;
if (ecoReward > 0) {
r = War.war.getEconomy().depositPlayer(tp.getName(), ecoReward);
} else {
r = War.war.getEconomy().withdrawPlayer(tp.getName(), ecoReward);
}
if (!r.transactionSuccess()) {
War.war.getLogger().log(Level.WARNING,
"Failed to reward player {0} ${1}. Error: {2}",
new Object[] {tp.getName(), ecoReward, r.errorMessage});
}
}
}
}
t.resetPoints();

View File

@ -18,7 +18,8 @@ public enum TeamConfig {
KILLSTREAK (Boolean.class),
BLOCKWHITELIST (String.class),
PLACEBLOCK (Boolean.class),
APPLYPOTION(String.class);
APPLYPOTION(String.class),
ECOREWARD(Double.class);
private final Class<?> configType;

View File

@ -54,6 +54,25 @@ public class TeamConfigBag {
}
}
public Double getDouble(TeamConfig config) {
if (this.contains(config)) {
return (Double)this.bag.get(config);
}
return null;
}
public Double resolveDouble(TeamConfig config) {
if (this.contains(config)) {
return (Double)this.bag.get(config);
} else if (this.warzone != null && this.warzone.getTeamDefaultConfig().contains(config)){
// use Warzone default config
return this.warzone.getTeamDefaultConfig().resolveDouble(config);
} else {
// use War default config
return War.war.getTeamDefaultConfig().resolveDouble(config);
}
}
public Integer getInt(TeamConfig config) {
if (this.contains(config)) {
return (Integer)this.bag.get(config);
@ -157,6 +176,8 @@ public class TeamConfigBag {
this.put(config, teamConfigSection.getBoolean(config.toString()));
} else if (config.getConfigType().equals(String.class)) {
this.put(config, teamConfigSection.getString(config.toString()));
} else if (config.getConfigType().equals(Double.class)) {
this.put(config, teamConfigSection.getDouble(config.toString()));
} else if (config.getConfigType().equals(FlagReturn.class)) {
String flagReturnStr = teamConfigSection.getString(config.toString());
FlagReturn returnMode = FlagReturn.getFromString(flagReturnStr);
@ -178,7 +199,8 @@ public class TeamConfigBag {
for (TeamConfig config : TeamConfig.values()) {
if (this.contains(config)) {
if (config.getConfigType().equals(Integer.class)
|| config.getConfigType().equals(Boolean.class)) {
|| config.getConfigType().equals(Boolean.class)
|| config.getConfigType().equals(Double.class)) {
teamConfigSection.set(config.toString(), this.bag.get(config));
} else {
teamConfigSection.set(config.toString(), this.bag.get(config).toString());
@ -195,6 +217,9 @@ public class TeamConfigBag {
if (teamConfig.getConfigType().equals(Integer.class)) {
int intValue = Integer.parseInt(namedParams.get(namedParam));
this.bag.put(teamConfig, intValue);
} else if (teamConfig.getConfigType().equals(Double.class)) {
double doubleValue = Double.parseDouble(namedParams.get(namedParam));
this.bag.put(teamConfig, doubleValue);
} else if (teamConfig.getConfigType().equals(Boolean.class)) {
String onOff = namedParams.get(namedParam);
this.bag.put(teamConfig, onOff.equals("on") || onOff.equals("true"));

View File

@ -4,7 +4,7 @@ description: ${project.description}
author: tommytony
website: ${project.url}
main: com.tommytony.war.War
softdepend: [Spout, TagAPI, WorldEdit]
softdepend: [Spout, TagAPI, WorldEdit, Vault]
permissions:
war.*:
description: Full War permissions. Create and destroy warzones. Change War configuration.