mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-08 08:31:46 +01:00
Added in Vault as the prefered method for checking economy stuff. Will defer to AllPay for item based world costs.
This commit is contained in:
parent
74241e3d9c
commit
57da3df860
18
pom.xml
18
pom.xml
@ -20,10 +20,16 @@
|
||||
<id>Bukkit Official</id>
|
||||
<url>http://repo.bukkit.org/content/repositories/public</url>
|
||||
</repository>
|
||||
<!-- Required for Metrics -->
|
||||
<repository>
|
||||
<id>mcstats</id>
|
||||
<url>http://repo.mcstats.org/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
<!-- Required for Vault -->
|
||||
<repository>
|
||||
<id>herocraft</id>
|
||||
<url>http://ci.herocraftonline.com/plugin/repository/everything/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<pluginRepositories>
|
||||
@ -175,7 +181,6 @@
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>me.main__.util:SerializationConfig</include>
|
||||
<include>com.fernferret.allpay:AllPay</include>
|
||||
<include>com.pneumaticraft.commandhandler:CommandHandler</include>
|
||||
<include>com.dumptruckman.minecraft:buscript</include>
|
||||
<include>org.mcstats:metrics</include>
|
||||
@ -247,7 +252,7 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- End of SerializationConfig Dependency -->
|
||||
<!-- Start of AllPay Dependency -->
|
||||
<!-- Start of Economy Dependency -->
|
||||
<dependency>
|
||||
<groupId>com.fernferret.allpay</groupId>
|
||||
<artifactId>AllPay</artifactId>
|
||||
@ -255,7 +260,14 @@
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- End of AllPay Dependency -->
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>Vault</artifactId>
|
||||
<version>1.2.19-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- End of Economy Dependency -->
|
||||
<!-- Start of CommandHandler Dependency -->
|
||||
<dependency>
|
||||
<groupId>com.pneumaticraft.commandhandler</groupId>
|
||||
|
@ -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<String, MVPlayerSession> 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<Economy> 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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
/**
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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');
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user