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>
|
<id>Bukkit Official</id>
|
||||||
<url>http://repo.bukkit.org/content/repositories/public</url>
|
<url>http://repo.bukkit.org/content/repositories/public</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<!-- Required for Metrics -->
|
||||||
<repository>
|
<repository>
|
||||||
<id>mcstats</id>
|
<id>mcstats</id>
|
||||||
<url>http://repo.mcstats.org/content/repositories/snapshots</url>
|
<url>http://repo.mcstats.org/content/repositories/snapshots</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<!-- Required for Vault -->
|
||||||
|
<repository>
|
||||||
|
<id>herocraft</id>
|
||||||
|
<url>http://ci.herocraftonline.com/plugin/repository/everything/</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<pluginRepositories>
|
<pluginRepositories>
|
||||||
|
@ -175,7 +181,6 @@
|
||||||
<artifactSet>
|
<artifactSet>
|
||||||
<includes>
|
<includes>
|
||||||
<include>me.main__.util:SerializationConfig</include>
|
<include>me.main__.util:SerializationConfig</include>
|
||||||
<include>com.fernferret.allpay:AllPay</include>
|
|
||||||
<include>com.pneumaticraft.commandhandler:CommandHandler</include>
|
<include>com.pneumaticraft.commandhandler:CommandHandler</include>
|
||||||
<include>com.dumptruckman.minecraft:buscript</include>
|
<include>com.dumptruckman.minecraft:buscript</include>
|
||||||
<include>org.mcstats:metrics</include>
|
<include>org.mcstats:metrics</include>
|
||||||
|
@ -247,7 +252,7 @@
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- End of SerializationConfig Dependency -->
|
<!-- End of SerializationConfig Dependency -->
|
||||||
<!-- Start of AllPay Dependency -->
|
<!-- Start of Economy Dependency -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fernferret.allpay</groupId>
|
<groupId>com.fernferret.allpay</groupId>
|
||||||
<artifactId>AllPay</artifactId>
|
<artifactId>AllPay</artifactId>
|
||||||
|
@ -255,7 +260,14 @@
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</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 -->
|
<!-- Start of CommandHandler Dependency -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.pneumaticraft.commandhandler</groupId>
|
<groupId>com.pneumaticraft.commandhandler</groupId>
|
||||||
|
|
|
@ -79,6 +79,8 @@ import com.onarandombox.MultiverseCore.utils.SimpleSafeTTeleporter;
|
||||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World.Environment;
|
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.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
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.PluginManager;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.mcstats.Metrics;
|
import org.mcstats.Metrics;
|
||||||
|
|
||||||
|
@ -109,7 +116,7 @@ import java.util.logging.Level;
|
||||||
/**
|
/**
|
||||||
* The implementation of the Multiverse-{@link Core}.
|
* 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;
|
private static final int PROTOCOL = 18;
|
||||||
// TODO: Investigate if this one is really needed to be static.
|
// TODO: Investigate if this one is really needed to be static.
|
||||||
// Doubt it. -- FernFerret
|
// Doubt it. -- FernFerret
|
||||||
|
@ -199,6 +206,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||||
|
|
||||||
// HashMap to contain information relating to the Players.
|
// HashMap to contain information relating to the Players.
|
||||||
private HashMap<String, MVPlayerSession> playerSessions;
|
private HashMap<String, MVPlayerSession> playerSessions;
|
||||||
|
private Economy vaultEco = null;
|
||||||
private GenericBank bank = null;
|
private GenericBank bank = null;
|
||||||
private AllPay banker;
|
private AllPay banker;
|
||||||
private Buscript buscript;
|
private Buscript buscript;
|
||||||
|
@ -245,10 +253,19 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public GenericBank getBank() {
|
public GenericBank getBank() {
|
||||||
return this.bank;
|
return this.bank;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Economy getVaultEconomy() {
|
||||||
|
return vaultEco;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -324,6 +341,43 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||||
|
|
||||||
this.initializeBuscript();
|
this.initializeBuscript();
|
||||||
this.setupMetrics();
|
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}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public AllPay getBanker() {
|
public AllPay getBanker() {
|
||||||
return this.banker;
|
return this.banker;
|
||||||
}
|
}
|
||||||
|
@ -1001,6 +1056,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public void setBank(GenericBank bank) {
|
public void setBank(GenericBank bank) {
|
||||||
this.bank = bank;
|
this.bank = bank;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,15 @@ import buscript.Buscript;
|
||||||
import com.fernferret.allpay.AllPay;
|
import com.fernferret.allpay.AllPay;
|
||||||
import com.fernferret.allpay.GenericBank;
|
import com.fernferret.allpay.GenericBank;
|
||||||
import com.onarandombox.MultiverseCore.destination.DestinationFactory;
|
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 com.pneumaticraft.commandhandler.CommandHandler;
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@ -36,9 +43,18 @@ public interface Core {
|
||||||
* Gets the Banking system that Multiverse-Core has hooked into.
|
* Gets the Banking system that Multiverse-Core has hooked into.
|
||||||
*
|
*
|
||||||
* @return A {@link GenericBank} that can be used for payments.
|
* @return A {@link GenericBank} that can be used for payments.
|
||||||
|
* @deprecated Now using vault, see {@link #getVaultEconomy}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
GenericBank getBank();
|
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:
|
* Reloads the Multiverse Configuration files:
|
||||||
* worlds.yml and config.yml.
|
* worlds.yml and config.yml.
|
||||||
|
@ -139,14 +155,18 @@ public interface Core {
|
||||||
* Sets the {@link GenericBank}-Bank AllPay is using.
|
* Sets the {@link GenericBank}-Bank AllPay is using.
|
||||||
*
|
*
|
||||||
* @param bank The new {@link GenericBank}
|
* @param bank The new {@link GenericBank}
|
||||||
|
* @deprecated Now using vault, see {@link #getVaultEconomy}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
void setBank(GenericBank bank);
|
void setBank(GenericBank bank);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets this plugin's {@link AllPay}-Banker.
|
* Gets this plugin's {@link AllPay}-Banker.
|
||||||
*
|
*
|
||||||
* @return An {@link AllPay}-Banker
|
* @return An {@link AllPay}-Banker
|
||||||
|
* @deprecated Now using vault, see {@link #getVaultEconomy}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
AllPay getBanker();
|
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("Spawn Location: ", plugin.getLocationManipulation().strCoords(spawn), colors));
|
||||||
message.add(new FancyMessage("World Scale: ", world.getScaling() + "", colors));
|
message.add(new FancyMessage("World Scale: ", world.getScaling() + "", colors));
|
||||||
if (world.getPrice() > 0) {
|
if (world.getPrice() > 0) {
|
||||||
message.add(new FancyMessage("Price to enter this world: ",
|
final String formattedAmount;
|
||||||
this.plugin.getBank().getFormattedAmount(p, world.getPrice(), world.getCurrency()), colors));
|
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 {
|
} else {
|
||||||
message.add(new FancyMessage("Price to enter this world: ", ChatColor.GREEN + "FREE!", colors));
|
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] 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] 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] 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] Permissions Plugin: ").append(this.plugin.getMVPerms().getType()).append('\n');
|
||||||
buffer.append("[Multiverse-Core] Dumping Config Values: (version ")
|
buffer.append("[Multiverse-Core] Dumping Config Values: (version ")
|
||||||
.append(this.plugin.getMVConfig().getVersion()).append(")").append('\n');
|
.append(this.plugin.getMVConfig().getVersion()).append(")").append('\n');
|
||||||
|
|
|
@ -34,6 +34,10 @@ public class MVPluginListener implements Listener {
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void pluginEnable(PluginEnableEvent event) {
|
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
|
// Let AllPay handle all econ plugin loadings, only go for econ plugins we support
|
||||||
if (Arrays.asList(AllPay.getValidEconPlugins()).contains(event.getPlugin().getDescription().getName())) {
|
if (Arrays.asList(AllPay.getValidEconPlugins()).contains(event.getPlugin().getDescription().getName())) {
|
||||||
this.plugin.setBank(this.plugin.getBanker().loadEconPlugin());
|
this.plugin.setBank(this.plugin.getBanker().loadEconPlugin());
|
||||||
|
|
|
@ -143,17 +143,32 @@ public class PermissionTools {
|
||||||
if (this.plugin.getMVPerms().hasPermission(teleporter, toWorld.getExemptPermission().getName(), true)) {
|
if (this.plugin.getMVPerms().hasPermission(teleporter, toWorld.getExemptPermission().getName(), true)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
GenericBank bank = plugin.getBank();
|
final boolean usingVault;
|
||||||
String errString = "You need " + bank.getFormattedAmount(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency())
|
final String formattedAmount;
|
||||||
+ " to send " + teleportee + " to " + toWorld.getColoredWorldString();
|
if (toWorld.getCurrency() <= 0 && plugin.getVaultEconomy() != null) {
|
||||||
if (teleportee.equals(teleporter)) {
|
usingVault = true;
|
||||||
errString = "You need " + bank.getFormattedAmount(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency())
|
formattedAmount = plugin.getVaultEconomy().format(toWorld.getPrice());
|
||||||
+ " to enter " + toWorld.getColoredWorldString();
|
} else {
|
||||||
|
usingVault = false;
|
||||||
|
formattedAmount = this.plugin.getBank().getFormattedAmount(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency());
|
||||||
}
|
}
|
||||||
if (!bank.hasEnough(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency(), errString)) {
|
String errString = "You need " + formattedAmount + " to send " + teleportee + " to " + toWorld.getColoredWorldString();
|
||||||
return false;
|
if (teleportee.equals(teleporter)) {
|
||||||
} else if (pay) {
|
errString = "You need " + formattedAmount + " to enter " + toWorld.getColoredWorldString();
|
||||||
bank.give(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency());
|
}
|
||||||
|
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;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue