Moves the EconomyHandler to utility and adds some encapsulation for three of its variables
This commit is contained in:
parent
e665a49f03
commit
e5fef0b16a
@ -17,6 +17,7 @@ import net.knarcraft.stargate.portal.PortalHandler;
|
|||||||
import net.knarcraft.stargate.portal.PortalOption;
|
import net.knarcraft.stargate.portal.PortalOption;
|
||||||
import net.knarcraft.stargate.thread.BlockPopulatorThread;
|
import net.knarcraft.stargate.thread.BlockPopulatorThread;
|
||||||
import net.knarcraft.stargate.thread.StarGateThread;
|
import net.knarcraft.stargate.thread.StarGateThread;
|
||||||
|
import net.knarcraft.stargate.utility.EconomyHandler;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
@ -613,9 +614,9 @@ public class Stargate extends JavaPlugin {
|
|||||||
permDebug = newConfig.getBoolean("permdebug");
|
permDebug = newConfig.getBoolean("permdebug");
|
||||||
// Economy
|
// Economy
|
||||||
EconomyHandler.economyEnabled = newConfig.getBoolean("useeconomy");
|
EconomyHandler.economyEnabled = newConfig.getBoolean("useeconomy");
|
||||||
EconomyHandler.createCost = newConfig.getInt("createcost");
|
EconomyHandler.setCreateCost(newConfig.getInt("createcost"));
|
||||||
EconomyHandler.destroyCost = newConfig.getInt("destroycost");
|
EconomyHandler.setDestroyCost(newConfig.getInt("destroycost"));
|
||||||
EconomyHandler.useCost = newConfig.getInt("usecost");
|
EconomyHandler.setUseCost(newConfig.getInt("usecost"));
|
||||||
EconomyHandler.toOwner = newConfig.getBoolean("toowner");
|
EconomyHandler.toOwner = newConfig.getBoolean("toowner");
|
||||||
EconomyHandler.chargeFreeDestination = newConfig.getBoolean("chargefreedestination");
|
EconomyHandler.chargeFreeDestination = newConfig.getBoolean("chargefreedestination");
|
||||||
EconomyHandler.freeGatesGreen = newConfig.getBoolean("freegatesgreen");
|
EconomyHandler.freeGatesGreen = newConfig.getBoolean("freegatesgreen");
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package net.knarcraft.stargate.listener;
|
package net.knarcraft.stargate.listener;
|
||||||
|
|
||||||
import net.knarcraft.stargate.EconomyHandler;
|
import net.knarcraft.stargate.utility.EconomyHandler;
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package net.knarcraft.stargate.portal;
|
package net.knarcraft.stargate.portal;
|
||||||
|
|
||||||
import net.knarcraft.stargate.EconomyHandler;
|
import net.knarcraft.stargate.utility.EconomyHandler;
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -13,11 +13,15 @@ import java.util.List;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The gate handler keeps track of all gates
|
||||||
|
*/
|
||||||
public class GateHandler {
|
public class GateHandler {
|
||||||
|
|
||||||
private static final Character ANYTHING = ' ';
|
private static final Character ANYTHING = ' ';
|
||||||
private static final Character ENTRANCE = '.';
|
private static final Character ENTRANCE = '.';
|
||||||
private static final Character EXIT = '*';
|
private static final Character EXIT = '*';
|
||||||
|
private static final Character CONTROL_BLOCK = '-';
|
||||||
|
|
||||||
private static Material defaultPortalBlockOpen = Material.NETHER_PORTAL;
|
private static Material defaultPortalBlockOpen = Material.NETHER_PORTAL;
|
||||||
private static Material defaultPortalBlockClosed = Material.AIR;
|
private static Material defaultPortalBlockClosed = Material.AIR;
|
||||||
@ -49,10 +53,25 @@ public class GateHandler {
|
|||||||
return ENTRANCE;
|
return ENTRANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the character used for defining the exit
|
||||||
|
*
|
||||||
|
* @return <p>The character used for defining the exit</p>
|
||||||
|
*/
|
||||||
public static Character getExitCharacter() {
|
public static Character getExitCharacter() {
|
||||||
return EXIT;
|
return EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the character used for defining control blocks
|
||||||
|
*
|
||||||
|
* @return <p>The character used for defining control blocks</p>
|
||||||
|
*/
|
||||||
|
public static Character getControlBlockCharacter() {
|
||||||
|
return CONTROL_BLOCK;
|
||||||
|
}
|
||||||
|
|
||||||
public static void registerGate(Gate gate) {
|
public static void registerGate(Gate gate) {
|
||||||
gates.put(gate.getFilename(), gate);
|
gates.put(gate.getFilename(), gate);
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ public class GateLayout {
|
|||||||
List<RelativeBlockVector> controlList, List<RelativeBlockVector> entranceList,
|
List<RelativeBlockVector> controlList, List<RelativeBlockVector> entranceList,
|
||||||
List<RelativeBlockVector> borderList) {
|
List<RelativeBlockVector> borderList) {
|
||||||
//Add control blocks
|
//Add control blocks
|
||||||
if (key.equals('-')) {
|
if (key.equals(GateHandler.getControlBlockCharacter())) {
|
||||||
controlList.add(new RelativeBlockVector(rowIndex, lineIndex, 0));
|
controlList.add(new RelativeBlockVector(rowIndex, lineIndex, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ package net.knarcraft.stargate.portal;
|
|||||||
|
|
||||||
import net.knarcraft.stargate.BlockLocation;
|
import net.knarcraft.stargate.BlockLocation;
|
||||||
import net.knarcraft.stargate.BloxPopulator;
|
import net.knarcraft.stargate.BloxPopulator;
|
||||||
import net.knarcraft.stargate.EconomyHandler;
|
import net.knarcraft.stargate.utility.EconomyHandler;
|
||||||
import net.knarcraft.stargate.RelativeBlockVector;
|
import net.knarcraft.stargate.RelativeBlockVector;
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.event.StargateActivateEvent;
|
import net.knarcraft.stargate.event.StargateActivateEvent;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.knarcraft.stargate;
|
package net.knarcraft.stargate.utility;
|
||||||
|
|
||||||
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -12,18 +13,79 @@ import java.util.UUID;
|
|||||||
/**
|
/**
|
||||||
* This handler handles economy actions such as payment for using a gate
|
* This handler handles economy actions such as payment for using a gate
|
||||||
*/
|
*/
|
||||||
public class EconomyHandler {
|
public final class EconomyHandler {
|
||||||
|
|
||||||
public static boolean economyEnabled = false;
|
public static boolean economyEnabled = false;
|
||||||
public static Economy economy = null;
|
public static Economy economy = null;
|
||||||
public static Plugin vault = null;
|
public static Plugin vault = null;
|
||||||
|
private static int useCost = 0;
|
||||||
public static int useCost = 0;
|
private static int createCost = 0;
|
||||||
public static int createCost = 0;
|
private static int destroyCost = 0;
|
||||||
public static int destroyCost = 0;
|
|
||||||
public static boolean toOwner = false;
|
public static boolean toOwner = false;
|
||||||
public static boolean chargeFreeDestination = true;
|
public static boolean chargeFreeDestination = true;
|
||||||
public static boolean freeGatesGreen = false;
|
public static boolean freeGatesGreen = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cost of using a gate without a specified cost
|
||||||
|
*
|
||||||
|
* @return <p>The gate use cost</p>
|
||||||
|
*/
|
||||||
|
public static int getUseCost() {
|
||||||
|
return useCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cost of using a gate without a specified cost
|
||||||
|
*
|
||||||
|
* <p>The use cost cannot be negative.</p>
|
||||||
|
*
|
||||||
|
* @param useCost <p>The gate use cost</p>
|
||||||
|
*/
|
||||||
|
public static void setUseCost(int useCost) {
|
||||||
|
if (useCost < 0) {
|
||||||
|
throw new IllegalArgumentException("Using a gate cannot cost a negative amount");
|
||||||
|
}
|
||||||
|
EconomyHandler.useCost = useCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cost of creating a gate without a specified cost
|
||||||
|
*
|
||||||
|
* @return <p>The gate creation cost</p>
|
||||||
|
*/
|
||||||
|
public static int getCreateCost() {
|
||||||
|
return createCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cost of creating a gate without a specified cost
|
||||||
|
*
|
||||||
|
* <p>The gate create cost cannot be negative</p>
|
||||||
|
*
|
||||||
|
* @param createCost <p>The gate creation cost</p>
|
||||||
|
*/
|
||||||
|
public static void setCreateCost(int createCost) {
|
||||||
|
EconomyHandler.createCost = createCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cost of destroying a gate without a specified cost
|
||||||
|
*
|
||||||
|
* @return <p>The gate destruction cost</p>
|
||||||
|
*/
|
||||||
|
public static int getDestroyCost() {
|
||||||
|
return destroyCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cost of destroying a gate without a specified cost
|
||||||
|
*
|
||||||
|
* @param destroyCost <p>The gate destruction cost</p>
|
||||||
|
*/
|
||||||
|
public static void setDestroyCost(int destroyCost) {
|
||||||
|
EconomyHandler.destroyCost = destroyCost;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the balance (money) of the given player
|
* Gets the balance (money) of the given player
|
||||||
*
|
*
|
||||||
@ -51,6 +113,7 @@ public class EconomyHandler {
|
|||||||
if (!economy.has(player, amount)) {
|
if (!economy.has(player, amount)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
//Take money from the user and give to the owner
|
||||||
economy.withdrawPlayer(player, amount);
|
economy.withdrawPlayer(player, amount);
|
||||||
economy.depositPlayer(Bukkit.getOfflinePlayer(target), amount);
|
economy.depositPlayer(Bukkit.getOfflinePlayer(target), amount);
|
||||||
}
|
}
|
@ -1,10 +1,12 @@
|
|||||||
package net.knarcraft.stargate.utility;
|
package net.knarcraft.stargate.utility;
|
||||||
|
|
||||||
import net.knarcraft.stargate.EconomyHandler;
|
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The economy helper class has helper functions for player payment
|
||||||
|
*/
|
||||||
public final class EconomyHelper {
|
public final class EconomyHelper {
|
||||||
|
|
||||||
private EconomyHelper() {
|
private EconomyHelper() {
|
||||||
@ -24,7 +26,8 @@ public final class EconomyHelper {
|
|||||||
|
|
||||||
//Try to charge the player
|
//Try to charge the player
|
||||||
if (entrancePortal.getGate().getToOwner()) {
|
if (entrancePortal.getGate().getToOwner()) {
|
||||||
success = entrancePortal.getOwnerUUID() != null && Stargate.chargePlayer(player, entrancePortal.getOwnerUUID(), cost);
|
success = entrancePortal.getOwnerUUID() != null && Stargate.chargePlayer(player,
|
||||||
|
entrancePortal.getOwnerUUID(), cost);
|
||||||
} else {
|
} else {
|
||||||
success = Stargate.chargePlayer(player, cost);
|
success = Stargate.chargePlayer(player, cost);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user