Add economy reward for winning team

This commit is contained in:
cmastudios 2014-02-26 18:51:39 -06:00
parent 43bbb24dd5
commit f00ed85c4b
4 changed files with 46 additions and 2 deletions

View File

@ -233,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>();

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;
@ -1362,6 +1364,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
@ -1370,6 +1374,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"));