diff --git a/pom.xml b/pom.xml index 98341920..5d664e62 100644 --- a/pom.xml +++ b/pom.xml @@ -20,10 +20,16 @@ Bukkit Official http://repo.bukkit.org/content/repositories/public + mcstats http://repo.mcstats.org/content/repositories/snapshots + + + herocraft + http://ci.herocraftonline.com/plugin/repository/everything/ + @@ -175,7 +181,6 @@ me.main__.util:SerializationConfig - com.fernferret.allpay:AllPay com.pneumaticraft.commandhandler:CommandHandler com.dumptruckman.minecraft:buscript org.mcstats:metrics @@ -247,7 +252,7 @@ compile - + com.fernferret.allpay AllPay @@ -255,7 +260,14 @@ jar compile - + + net.milkbowl.vault + Vault + 1.2.19-SNAPSHOT + jar + compile + + com.pneumaticraft.commandhandler diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 2bc9de59..99d8fe18 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -79,6 +79,8 @@ import com.onarandombox.MultiverseCore.utils.SimpleSafeTTeleporter; import com.onarandombox.MultiverseCore.utils.WorldManager; import com.pneumaticraft.commandhandler.CommandHandler; import me.main__.util.SerializationConfig.SerializationConfig; +import net.milkbowl.vault.economy.Economy; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.World.Environment; @@ -89,7 +91,12 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.server.PluginDisableEvent; +import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; import org.mcstats.Metrics; @@ -109,7 +116,7 @@ import java.util.logging.Level; /** * The implementation of the Multiverse-{@link Core}. */ -public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { +public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listener { private static final int PROTOCOL = 18; // TODO: Investigate if this one is really needed to be static. // Doubt it. -- FernFerret @@ -199,6 +206,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { // HashMap to contain information relating to the Players. private HashMap playerSessions; + private Economy vaultEco = null; private GenericBank bank = null; private AllPay banker; private Buscript buscript; @@ -245,10 +253,19 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { * {@inheritDoc} */ @Override + @Deprecated public GenericBank getBank() { return this.bank; } + /** + * {@inheritDoc} + */ + @Override + public Economy getVaultEconomy() { + return vaultEco; + } + /** * {@inheritDoc} */ @@ -324,6 +341,43 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { this.initializeBuscript(); this.setupMetrics(); + // Listen out for vault. + getServer().getPluginManager().registerEvents(this, this); + this.setupVaultEconomy(); + } + + private boolean setupVaultEconomy() { + if (Bukkit.getPluginManager().getPlugin("Vault") != null) { + final RegisteredServiceProvider economyProvider + = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); + if (economyProvider != null) { + Logging.fine("Vault economy enabled."); + vaultEco = economyProvider.getProvider(); + } else { + Logging.finer("Vault economy not detected."); + vaultEco = null; + } + } else { + Logging.finer("Vault was not found."); + vaultEco = null; + } + + return (vaultEco != null); + } + + @EventHandler + private void vaultEnabled(PluginEnableEvent event) { + if (event.getPlugin() != null && event.getPlugin().getName().equals("Vault")) { + setupVaultEconomy(); + } + } + + @EventHandler + private void vaultDisabled(PluginDisableEvent event) { + if (event.getPlugin() != null && event.getPlugin().getName().equals("Vault")) { + Logging.fine("Vault economy disabled"); + setupVaultEconomy(); + } } /** @@ -993,6 +1047,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { * {@inheritDoc} */ @Override + @Deprecated public AllPay getBanker() { return this.banker; } @@ -1001,6 +1056,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { * {@inheritDoc} */ @Override + @Deprecated public void setBank(GenericBank bank) { this.bank = bank; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/Core.java b/src/main/java/com/onarandombox/MultiverseCore/api/Core.java index 0fc7f377..f8c59283 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/Core.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/Core.java @@ -11,8 +11,15 @@ import buscript.Buscript; import com.fernferret.allpay.AllPay; import com.fernferret.allpay.GenericBank; import com.onarandombox.MultiverseCore.destination.DestinationFactory; -import com.onarandombox.MultiverseCore.utils.*; +import com.onarandombox.MultiverseCore.utils.AnchorManager; +import com.onarandombox.MultiverseCore.utils.MVPermissions; +import com.onarandombox.MultiverseCore.utils.MVPlayerSession; +import com.onarandombox.MultiverseCore.utils.SimpleBlockSafety; +import com.onarandombox.MultiverseCore.utils.SimpleLocationManipulation; +import com.onarandombox.MultiverseCore.utils.SimpleSafeTTeleporter; +import com.onarandombox.MultiverseCore.utils.WorldManager; import com.pneumaticraft.commandhandler.CommandHandler; +import net.milkbowl.vault.economy.Economy; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; @@ -36,9 +43,18 @@ public interface Core { * Gets the Banking system that Multiverse-Core has hooked into. * * @return A {@link GenericBank} that can be used for payments. + * @deprecated Now using vault, see {@link #getVaultEconomy} */ + @Deprecated GenericBank getBank(); + /** + * Returns the Vault economy system if Vault is present and has an economy system enabled. + * + * @return The vault economy system or null if not configured. + */ + Economy getVaultEconomy(); + /** * Reloads the Multiverse Configuration files: * worlds.yml and config.yml. @@ -139,14 +155,18 @@ public interface Core { * Sets the {@link GenericBank}-Bank AllPay is using. * * @param bank The new {@link GenericBank} + * @deprecated Now using vault, see {@link #getVaultEconomy} */ + @Deprecated void setBank(GenericBank bank); /** * Gets this plugin's {@link AllPay}-Banker. * * @return An {@link AllPay}-Banker + * @deprecated Now using vault, see {@link #getVaultEconomy} */ + @Deprecated AllPay getBanker(); /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java index f9b5380d..67463f0a 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java @@ -124,8 +124,13 @@ public class InfoCommand extends MultiverseCommand { message.add(new FancyMessage("Spawn Location: ", plugin.getLocationManipulation().strCoords(spawn), colors)); message.add(new FancyMessage("World Scale: ", world.getScaling() + "", colors)); if (world.getPrice() > 0) { - message.add(new FancyMessage("Price to enter this world: ", - this.plugin.getBank().getFormattedAmount(p, world.getPrice(), world.getCurrency()), colors)); + final String formattedAmount; + if (world.getCurrency() <= 0 && plugin.getVaultEconomy() != null) { + formattedAmount = plugin.getVaultEconomy().format(world.getPrice()); + } else { + formattedAmount = this.plugin.getBank().getFormattedAmount(p, world.getPrice(), world.getCurrency()); + } + message.add(new FancyMessage("Price to enter this world: ", formattedAmount, colors)); } else { message.add(new FancyMessage("Price to enter this world: ", ChatColor.GREEN + "FREE!", colors)); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java index b6364148..9d967d34 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java @@ -53,7 +53,13 @@ public class VersionCommand extends MultiverseCommand { buffer.append("[Multiverse-Core] Bukkit Version: ").append(this.plugin.getServer().getVersion()).append('\n'); buffer.append("[Multiverse-Core] Loaded Worlds: ").append(this.plugin.getMVWorldManager().getMVWorlds()).append('\n'); buffer.append("[Multiverse-Core] Multiverse Plugins Loaded: ").append(this.plugin.getPluginCount()).append('\n'); - buffer.append("[Multiverse-Core] Economy being used: ").append(this.plugin.getBank().getEconUsed()).append('\n'); + final boolean usingVault = this.plugin.getVaultEconomy() != null; + buffer.append("[Multiverse-Core] Using Vault: ").append(usingVault).append('\n'); + if (usingVault) { + buffer.append("[Multiverse-Core] Economy being used: ").append(this.plugin.getVaultEconomy().getName()).append('\n'); + } else { + buffer.append("[Multiverse-Core] Economy being used: ").append(this.plugin.getBank().getEconUsed()).append('\n'); + } buffer.append("[Multiverse-Core] Permissions Plugin: ").append(this.plugin.getMVPerms().getType()).append('\n'); buffer.append("[Multiverse-Core] Dumping Config Values: (version ") .append(this.plugin.getMVConfig().getVersion()).append(")").append('\n'); diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPluginListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPluginListener.java index 3d255703..aa271cf5 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPluginListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPluginListener.java @@ -34,6 +34,10 @@ public class MVPluginListener implements Listener { */ @EventHandler(priority = EventPriority.MONITOR) public void pluginEnable(PluginEnableEvent event) { + if (plugin.getVaultEconomy() != null) { + // Don't hook 2 economy plugins. + return; + } // Let AllPay handle all econ plugin loadings, only go for econ plugins we support if (Arrays.asList(AllPay.getValidEconPlugins()).contains(event.getPlugin().getDescription().getName())) { this.plugin.setBank(this.plugin.getBanker().loadEconPlugin()); diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java b/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java index 780f0a89..9e5a5d99 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java @@ -143,17 +143,32 @@ public class PermissionTools { if (this.plugin.getMVPerms().hasPermission(teleporter, toWorld.getExemptPermission().getName(), true)) { return true; } - GenericBank bank = plugin.getBank(); - String errString = "You need " + bank.getFormattedAmount(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency()) - + " to send " + teleportee + " to " + toWorld.getColoredWorldString(); - if (teleportee.equals(teleporter)) { - errString = "You need " + bank.getFormattedAmount(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency()) - + " to enter " + toWorld.getColoredWorldString(); + final boolean usingVault; + final String formattedAmount; + if (toWorld.getCurrency() <= 0 && plugin.getVaultEconomy() != null) { + usingVault = true; + formattedAmount = plugin.getVaultEconomy().format(toWorld.getPrice()); + } else { + usingVault = false; + formattedAmount = this.plugin.getBank().getFormattedAmount(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency()); } - if (!bank.hasEnough(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency(), errString)) { - return false; - } else if (pay) { - bank.give(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency()); + String errString = "You need " + formattedAmount + " to send " + teleportee + " to " + toWorld.getColoredWorldString(); + if (teleportee.equals(teleporter)) { + errString = "You need " + formattedAmount + " to enter " + toWorld.getColoredWorldString(); + } + if (usingVault) { + if (!plugin.getVaultEconomy().has(teleporterPlayer.getName(), toWorld.getPrice())) { + return false; + } else if (pay) { + plugin.getVaultEconomy().withdrawPlayer(teleporterPlayer.getName(), toWorld.getPrice()); + } + } else { + GenericBank bank = plugin.getBank(); + if (!bank.hasEnough(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency(), errString)) { + return false; + } else if (pay) { + bank.give(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency()); + } } } return true;