Add an interface for the Jail Pay Manager.

Further API work.
This commit is contained in:
graywolf336 2015-05-21 14:30:49 -05:00
parent cf50e37910
commit 307a096acc
4 changed files with 76 additions and 42 deletions

View File

@ -13,6 +13,7 @@ import com.graywolf336.jail.command.CommandHandler;
import com.graywolf336.jail.command.JailHandler;
import com.graywolf336.jail.enums.Lang;
import com.graywolf336.jail.enums.Settings;
import com.graywolf336.jail.interfaces.IJailPayManager;
import com.graywolf336.jail.interfaces.IJailStickManager;
import com.graywolf336.jail.legacy.LegacyManager;
import com.graywolf336.jail.listeners.CacheListener;
@ -38,7 +39,7 @@ public class JailMain extends JavaPlugin {
private JailHandler jh;
private JailIO io;
private JailManager jm;
private JailPayManager jpm;
private IJailPayManager jpm;
private IJailStickManager jsm;
private JailTimer jt;
private JailVoteManager jvm;
@ -296,8 +297,8 @@ public class JailMain extends JavaPlugin {
return this.jm;
}
/** Gets the {@link JailPayManager} instance. */
public JailPayManager getJailPayManager() {
/** Gets an instance of the {@link IJailPayManager}. */
public IJailPayManager getJailPayManager() {
return this.jpm;
}
@ -306,7 +307,7 @@ public class JailMain extends JavaPlugin {
return this.pm;
}
/** Gets the {@link JailStickManager} instance. */
/** Gets an instance of the {@link JailStickManager}. */
public IJailStickManager getJailStickManager() {
return this.jsm;
}

View File

@ -9,8 +9,9 @@ import org.bukkit.plugin.RegisteredServiceProvider;
import com.graywolf336.jail.beans.Prisoner;
import com.graywolf336.jail.enums.Settings;
import com.graywolf336.jail.interfaces.IJailPayManager;
public class JailPayManager {
public class JailPayManager implements IJailPayManager {
private Economy economy = null;
private double minteCost, infiniteCost;
private Material item;
@ -32,72 +33,42 @@ public class JailPayManager {
this.infinite = plugin.getConfig().getDouble(Settings.JAILPAYPRICEINFINITE.getPath()) != 0;
}
/** Checks if paying for infinite is enabled. */
public boolean isInfiniteEnabled() {
return this.infinite;
}
/** Checks if paying for timed is enabled. */
public boolean isTimedEnabled() {
return this.timed;
}
/** Gets how much it cost per minute in string format. */
public String getCostPerMinute() {
return String.valueOf(this.minteCost);
}
/**
* Calculates how much players have to pay to get completely free.
*
* @param prisoner data of who we're calculating
* @return The economy cost the prisoner will need to pay to get completely free.
*/
public double calculateBill(Prisoner prisoner) {
return prisoner.getRemainingTime() >= 0 ? prisoner.getRemainingTimeInMinutes() * this.minteCost : infiniteCost;
}
/** Gets how many minutes someone is paying for (rounds to the lowest number). */
public long getMinutesPayingFor(double amount) {
return (long) Math.floor(amount / this.minteCost);
}
/** Returns if we are using items for payment instead of economy. */
public boolean usingItemsForPayment() {
return this.item != Material.AIR;
}
/**
* Gets the {@link Material} it costs for jail pay, will be air if using economy.
*
* @return The item type it costs, air if using virtual economy.
*/
public Material getItemItCost() {
return this.item;
}
/**
* Checks if the player has enough money/items to pay what they have said they want to.
*
* @param p The player who is doing the paying.
* @param amt The amount to check they if they have.
* @return true if they have enough, false if not.
*/
public boolean hasEnoughToPay(Player p, double amt) {
if(this.usingItemsForPayment()) {
return p.getInventory().contains(this.item, (int) Math.ceil(amt));
}else {
return this.economy.has(p.getName(), amt);
return this.economy.has(p, amt);
}
}
/**
* Pays the required fees from the given player, removing items or money from economy.
*
* @param p The player who is paying.
* @param amt The amount of items or money to withdraw from the player.
*/
public void pay(Player p, double amt) {
if(this.usingItemsForPayment()) {
int amtNeeded = (int) Math.ceil(amt);
@ -123,12 +94,11 @@ public class JailPayManager {
if (amtNeeded == 0) break;
}
}else {
this.economy.withdrawPlayer(p.getName(), amt);
this.economy.withdrawPlayer(p, amt);
}
}
/** Gets the name of the item in nice capitals. */
public String getCurrencyName(){
public String getCurrencyName() {
if(this.usingItemsForPayment()) {
String name = item.toString().replaceAll("_", " ");
@ -154,7 +124,6 @@ public class JailPayManager {
}
}
/** Returns the economy provider to do transaction with. */
public Economy getEconomy() {
return this.economy;
}

View File

@ -7,12 +7,12 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.JailPayManager;
import com.graywolf336.jail.beans.Prisoner;
import com.graywolf336.jail.command.Command;
import com.graywolf336.jail.command.CommandInfo;
import com.graywolf336.jail.enums.Lang;
import com.graywolf336.jail.enums.Settings;
import com.graywolf336.jail.interfaces.IJailPayManager;
@CommandInfo(
maxArgs = 2,
@ -25,7 +25,7 @@ import com.graywolf336.jail.enums.Settings;
public class JailPayCommand implements Command {
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
if(jm.getPlugin().getConfig().getBoolean(Settings.JAILPAYENABLED.getPath())) {
JailPayManager pm = jm.getPlugin().getJailPayManager();
IJailPayManager pm = jm.getPlugin().getJailPayManager();
switch(args.length) {
case 1:

View File

@ -0,0 +1,64 @@
package com.graywolf336.jail.interfaces;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import com.graywolf336.jail.beans.Prisoner;
public interface IJailPayManager {
/** Checks if paying for infinite is enabled. */
public boolean isInfiniteEnabled();
/** Checks if paying for timed is enabled. */
public boolean isTimedEnabled();
/** Gets how much it cost per minute in string format. */
public String getCostPerMinute();
/**
* Calculates how much players have to pay to get completely free.
*
* @param prisoner data of who we're calculating
* @return The economy cost the prisoner will need to pay to get completely free.
*/
public double calculateBill(Prisoner prisoner);
/** Gets how many minutes someone is paying for (rounds to the lowest number). */
public long getMinutesPayingFor(double amount);
/** Returns if we are using items for payment instead of economy. */
public boolean usingItemsForPayment();
/**
* Gets the {@link Material} it costs for jail pay, will be air if using economy.
*
* @return The item type it costs, air if using virtual economy.
*/
public Material getItemItCost();
/**
* Checks if the player has enough money/items to pay what they have said they want to.
*
* @param player The player who is doing the paying.
* @param amount The amount to check they if they have.
* @return true if they have enough, false if not.
*/
public boolean hasEnoughToPay(Player player, double amount);
/**
* Pays the required fees from the given player, removing items or money from economy.
*
* @param player The player who is paying.
* @param amount The amount of items or money to withdraw from the player.
*/
public void pay(Player player, double amount);
/** Gets the name of the item in nice capitals. */
public String getCurrencyName();
/** Returns the economy provider to do transaction with. */
public Economy getEconomy();
}