From 43bbb24dd52ed67dbe8ec8cd366c2a7d0a48c73c Mon Sep 17 00:00:00 2001 From: cmastudios Date: Wed, 26 Feb 2014 17:07:44 -0600 Subject: [PATCH 1/2] Initial Vault support for economy I personally dislike forcing our users to use a separate plugin just to abstract different economy plugins, but sadly we live in a hell world where there are 20 competing economy plugins and counting so I don't want to deal with that. --- war/pom.xml | 9 +++++++++ war/src/main/java/com/tommytony/war/War.java | 19 +++++++++++++++++-- war/src/main/resources/plugin.yml | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/war/pom.xml b/war/pom.xml index 20d20d9..81f9e1e 100644 --- a/war/pom.xml +++ b/war/pom.xml @@ -35,6 +35,10 @@ mcstats.releases http://repo.mcstats.org/content/repositories/releases/ + + vault-repo + http://nexus.theyeticave.net/content/repositories/pub_releases + Github issues @@ -140,5 +144,10 @@ R7 compile + + net.milkbowl.vault + Vault + 1.2.32 + diff --git a/war/src/main/java/com/tommytony/war/War.java b/war/src/main/java/com/tommytony/war/War.java index 7cc80b6..151ff0e 100644 --- a/war/src/main/java/com/tommytony/war/War.java +++ b/war/src/main/java/com/tommytony/war/War.java @@ -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(); @@ -292,6 +296,13 @@ public class War extends JavaPlugin { this.getServer().getPluginManager().disablePlugin(this); } } + if (this.getServer().getPluginManager().isPluginEnabled("Vault")) { + RegisteredServiceProvider rsp = this.getServer().getServicesManager() + .getRegistration(Economy.class); + if (rsp != null) { + this.econ = rsp.getProvider(); + } + } War.reloadLanguage(); @@ -1341,4 +1352,8 @@ public class War extends JavaPlugin { return null; } } + + public Economy getEconomy() { + return econ; + } } diff --git a/war/src/main/resources/plugin.yml b/war/src/main/resources/plugin.yml index d516993..b6229d3 100644 --- a/war/src/main/resources/plugin.yml +++ b/war/src/main/resources/plugin.yml @@ -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. From f00ed85c4b3cd5c9d967266800b77367fd2c1b2c Mon Sep 17 00:00:00 2001 From: cmastudios Date: Wed, 26 Feb 2014 18:51:39 -0600 Subject: [PATCH 2/2] Add economy reward for winning team --- war/src/main/java/com/tommytony/war/War.java | 1 + .../main/java/com/tommytony/war/Warzone.java | 17 ++++++++++++ .../com/tommytony/war/config/TeamConfig.java | 3 ++- .../tommytony/war/config/TeamConfigBag.java | 27 ++++++++++++++++++- 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/war/src/main/java/com/tommytony/war/War.java b/war/src/main/java/com/tommytony/war/War.java index 151ff0e..c1dd1a7 100644 --- a/war/src/main/java/com/tommytony/war/War.java +++ b/war/src/main/java/com/tommytony/war/War.java @@ -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 defaultLoadout = new HashMap(); diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index 5287c6b..13747a0 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -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 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(); diff --git a/war/src/main/java/com/tommytony/war/config/TeamConfig.java b/war/src/main/java/com/tommytony/war/config/TeamConfig.java index 807e2de..314acc1 100644 --- a/war/src/main/java/com/tommytony/war/config/TeamConfig.java +++ b/war/src/main/java/com/tommytony/war/config/TeamConfig.java @@ -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; diff --git a/war/src/main/java/com/tommytony/war/config/TeamConfigBag.java b/war/src/main/java/com/tommytony/war/config/TeamConfigBag.java index cadbed5..ddd7712 100644 --- a/war/src/main/java/com/tommytony/war/config/TeamConfigBag.java +++ b/war/src/main/java/com/tommytony/war/config/TeamConfigBag.java @@ -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"));