Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.io.PrintWriter;
- import java.io.Serializable;
- import java.lang.reflect.Field;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.Comparator;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
- import java.util.Map.Entry;
- import java.util.Set;
- import java.util.TreeMap;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class Economy extends Plugin
- implements Serializable
- {
- private static final long serialVersionUID = 0L;
- private static final Logger logger;
- private static final String PLUGIN_NAME = "Minecraft Economy Controller";
- private static final String PLUGIN_VERSION = "1.2";
- private static final String PROPERTIES_NAME = "economy.properties";
- private static final File ECONOMY_FILE;
- private static final File LOCATIONS_FILE;
- private static final HashMap<String, String> COMMANDS;
- private static Map<String, String> PROPERTIES;
- private static int MAX_TRADE_AREA_LENGTH;
- private static int MAX_TRADE_AREA_SIZE;
- private static int MAX_BANK_AREA_LENGTH;
- private static int MAX_BANK_AREA_SIZE;
- private static double TRADE_AREA_COST;
- private static double PERSONAL_AREA_COST;
- private static double BANK_AREA_COST;
- private static double TRANSFER_FEE;
- private static double RENAME_FEE;
- private static double STARTING_MONEY;
- private static String TRADE_AREA_COLOR;
- private static String PERSONAL_AREA_COLOR;
- private static String BANK_AREA_COLOR;
- private static String OFFER_COLOR;
- private static String ONLINE;
- private static String OFFLINE;
- private static String ERROR;
- private static String INFO;
- private static String COMMAND;
- private static String MONEY;
- private static int MAX_OFFERS;
- private static double VERTICAL_COST;
- private static double LOTTERY_INTERVAL;
- private static int PLAYERS_TO_HALF;
- private static int MAX_AREAS;
- private HashMap<String, Double> balances;
- private HashMap<String, Double> paychecks;
- private HashMap<String, ArrayList<Economy.Offer>> sellingOffers;
- private HashMap<String, ArrayList<Block>> pendingTradeAreas;
- private HashMap<String, ArrayList<Block>> pendingBankAreas;
- private HashSet<Economy.Area> tradingAreas;
- private HashMap<String, ArrayList<Block>> pendingPersonalAreas;
- private HashSet<Economy.Area> personalAreas;
- private HashSet<Economy.Area> bankingAreas;
- private HashSet<Economy.Offer> allOffers;
- private double publicFund;
- private long lastLottery = System.currentTimeMillis() -
- ()(LOTTERY_INTERVAL * 60.0D * 1000.0D);
- private HashMap<Integer, HashSet<String>> offerListeners;
- private static HashMap<Integer, Double> ITEM_VALUES;
- private static int offerCount;
- private static int areaCount;
- static
- {
- logger = Logger.getLogger("Minecraft");
- COMMANDS = new HashMap()
- {
- };
- ECONOMY_FILE = new File("economy.dat");
- LOCATIONS_FILE = new File("locations.dat");
- try {
- if (ECONOMY_FILE.createNewFile()) {
- ObjectOutputStream outputStream = new ObjectOutputStream(
- new FileOutputStream(ECONOMY_FILE));
- outputStream.writeObject(new HashMap());
- outputStream.writeObject(new HashMap());
- outputStream
- .writeObject(new HashMap());
- outputStream.writeObject(new HashSet());
- outputStream.writeObject(new Integer(0));
- outputStream.writeObject(new Double(0.0D));
- outputStream
- .writeObject(new HashMap());
- outputStream.flush();
- outputStream.close();
- logger.log(Level.INFO, "Economy file successfully created.");
- }
- } catch (IOException exception) {
- exception.printStackTrace();
- logger.log(Level.SEVERE, "Exception while creating economy file.");
- }
- try {
- if (LOCATIONS_FILE.createNewFile()) {
- ObjectOutputStream outputStream = new ObjectOutputStream(
- new FileOutputStream(LOCATIONS_FILE));
- outputStream.writeObject(new HashSet());
- outputStream.writeObject(new HashSet());
- outputStream.writeObject(new HashSet());
- outputStream
- .writeObject(new HashMap());
- outputStream
- .writeObject(new HashMap());
- outputStream
- .writeObject(new HashMap());
- outputStream.writeObject(new Integer(0));
- outputStream.flush();
- outputStream.close();
- logger.log(Level.INFO, "Locations file successfully created.");
- }
- } catch (IOException exception) {
- exception.printStackTrace();
- logger
- .log(Level.SEVERE,
- "Exception while creating locations file.");
- }
- try {
- if (new File("economy.properties").createNewFile()) {
- PrintWriter output = new PrintWriter(
- new FileOutputStream(new File("economy.properties")));
- output.println("maxTradeAreaLength=15");
- output.println("maxTradeAreaSize=144");
- output.println("maxBankAreaLength=25");
- output.println("maxBankAreaSize=400");
- output.println("tradeAreaCost=1.0");
- output.println("personalAreaCost=3.0");
- output.println("bankAreaCost=5.0");
- output.println("transferFee=0.15");
- output.println("renameFee=0.05");
- output.println("startingMoney=10.0");
- output.println("tradeAreaColor=Yellow");
- output.println("personalAreaColor=LightBlue");
- output.println("bankAreaColor=Green");
- output.println("offerColor=LightGray");
- output.println("errorColor=Red");
- output.println("commandColor=Rose");
- output.println("infoColor=Blue");
- output.println("moneyColor=Green");
- output.println("onlineColor=White");
- output.println("offlineColor=Gray");
- output.println("maxOffers=10");
- output.println("verticalCost=0.02");
- output.println("lotteryInterval=60");
- output.println("playersToHalf=5");
- output.println("maxAreas=20");
- output
- .println("exchange=265:1,42:9,266:10,41:90,264:100,57:900");
- output.flush();
- output.close();
- logger.log(Level.INFO, "Properties file successfully created.");
- }
- PROPERTIES = new PropertiesFile("economy.properties").returnMap();
- } catch (Exception e) {
- e.printStackTrace();
- logger.log(Level.SEVERE,
- "Exception while creating properties file.");
- }
- MAX_TRADE_AREA_LENGTH = 15;
- MAX_TRADE_AREA_SIZE = 144;
- MAX_BANK_AREA_LENGTH = 25;
- MAX_BANK_AREA_SIZE = 400;
- TRADE_AREA_COST = 1.0D;
- PERSONAL_AREA_COST = 3.0D;
- BANK_AREA_COST = 5.0D;
- TRANSFER_FEE = 0.15D;
- RENAME_FEE = 0.05D;
- STARTING_MONEY = 10.0D;
- TRADE_AREA_COLOR = "§e";
- PERSONAL_AREA_COLOR = "§b";
- BANK_AREA_COLOR = "§2";
- OFFER_COLOR = "§7";
- ONLINE = "§f";
- OFFLINE = "§8";
- ERROR = "§4";
- INFO = "§3";
- COMMAND = "§c";
- MONEY = "§2";
- MAX_OFFERS = 10;
- VERTICAL_COST = 0.01D;
- LOTTERY_INTERVAL = 60.0D;
- PLAYERS_TO_HALF = 5;
- MAX_AREAS = 20;
- ITEM_VALUES = new HashMap()
- {
- };
- offerCount = 0;
- }
- public void enable()
- {
- Iterator localIterator = COMMANDS
- .entrySet().iterator();
- while (localIterator.hasNext()) {
- Map.Entry currentCommand = (Map.Entry)localIterator.next();
- etc.getInstance().addCommand((String)currentCommand.getKey(),
- (String)currentCommand.getValue());
- }
- if (!isEnabled()) {
- toggleEnabled();
- logger.info(this + " enabled.");
- }
- }
- public void disable()
- {
- Iterator localIterator = COMMANDS
- .entrySet().iterator();
- while (localIterator.hasNext()) {
- Map.Entry currentCommand = (Map.Entry)localIterator.next();
- etc.getInstance().removeCommand((String)currentCommand.getKey());
- }
- if (isEnabled()) {
- toggleEnabled();
- logger.info(this + " disabled.");
- writeEconomy();
- writeLocations();
- }
- }
- public void initialize()
- {
- readEconomy();
- readLocations();
- try {
- readProperties();
- } catch (FileNotFoundException exception) {
- exception.printStackTrace();
- }
- PluginListener listener = new Economy.EconomyListener(null);
- etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this,
- PluginListener.Priority.MEDIUM);
- etc.getLoader().addListener(PluginLoader.Hook.BLOCK_RIGHTCLICKED,
- listener, this, PluginListener.Priority.MEDIUM);
- etc.getLoader().addListener(PluginLoader.Hook.BLOCK_PLACE, listener,
- this, PluginListener.Priority.MEDIUM);
- etc.getLoader().addListener(PluginLoader.Hook.BLOCK_BROKEN, listener,
- this, PluginListener.Priority.MEDIUM);
- etc.getLoader().addListener(PluginLoader.Hook.MOB_SPAWN, listener,
- this, PluginListener.Priority.MEDIUM);
- etc.getLoader().addListener(PluginLoader.Hook.LOGIN, listener, this,
- PluginListener.Priority.MEDIUM);
- logger.info(this + " initialized.");
- }
- public final String toString()
- {
- return "Minecraft Economy Controller version 1.2";
- }
- private static final boolean online(String playerName) {
- return etc.getServer().getPlayer(playerName) != null;
- }
- private final void readEconomy()
- {
- try
- {
- ObjectInputStream inputStream = new ObjectInputStream(
- new FileInputStream(ECONOMY_FILE));
- this.balances = ((HashMap)inputStream.readObject());
- this.paychecks = ((HashMap)inputStream.readObject());
- this.sellingOffers = ((HashMap)
- inputStream.readObject());
- this.allOffers = ((HashSet)inputStream.readObject());
- offerCount = ((Integer)inputStream.readObject()).intValue();
- this.publicFund = ((Double)inputStream.readObject()).doubleValue();
- this.offerListeners = ((HashMap)
- inputStream.readObject());
- this.lastLottery = ((Long)inputStream.readObject()).longValue();
- inputStream.close();
- logger.log(Level.INFO, "Economy file successfully read.");
- } catch (Exception ioe) {
- ioe.printStackTrace();
- logger.log(Level.SEVERE, "Error while reading economy file.");
- } finally {
- if (this.balances == null) {
- this.balances = new HashMap();
- }
- if (this.paychecks == null) {
- this.paychecks = new HashMap();
- }
- if (this.sellingOffers == null) {
- this.sellingOffers = new HashMap();
- }
- if (this.allOffers == null) {
- this.allOffers = new HashSet();
- }
- if (this.offerListeners == null)
- this.offerListeners = new HashMap();
- }
- }
- private final void readLocations()
- {
- try
- {
- ObjectInputStream inputStream = new ObjectInputStream(
- new FileInputStream(LOCATIONS_FILE));
- this.tradingAreas = ((HashSet)inputStream.readObject());
- this.personalAreas = ((HashSet)inputStream.readObject());
- this.bankingAreas = ((HashSet)inputStream.readObject());
- this.pendingTradeAreas = ((HashMap)
- inputStream.readObject());
- this.pendingPersonalAreas = ((HashMap)
- inputStream.readObject());
- this.pendingBankAreas = ((HashMap)
- inputStream.readObject());
- areaCount = ((Integer)inputStream.readObject()).intValue();
- inputStream.close();
- logger.log(Level.INFO, "Locations file successfully read.");
- } catch (Exception exception) {
- exception.printStackTrace();
- logger.log(Level.SEVERE, "Error while reading locations file.");
- } finally {
- if (this.tradingAreas == null) {
- this.tradingAreas = new HashSet();
- }
- if (this.personalAreas == null) {
- this.personalAreas = new HashSet();
- }
- if (this.bankingAreas == null) {
- this.bankingAreas = new HashSet();
- }
- if (this.pendingTradeAreas == null) {
- this.pendingTradeAreas = new HashMap();
- }
- if (this.pendingPersonalAreas == null) {
- this.pendingPersonalAreas = new HashMap();
- }
- if (this.pendingBankAreas == null)
- this.pendingBankAreas = new HashMap();
- }
- }
- private final void readProperties()
- throws FileNotFoundException
- {
- boolean error = false;
- PrintWriter output = new PrintWriter(
- new FileOutputStream(new File("economy.properties")));
- if (PROPERTIES.containsKey("maxTradeAreaLength"))
- try {
- MAX_TRADE_AREA_LENGTH = Integer.parseInt(
- (String)PROPERTIES
- .get("maxTradeAreaLength"));
- if (MAX_TRADE_AREA_LENGTH >= 1) break label90; MAX_TRADE_AREA_LENGTH = 1;
- }
- catch (Exception e)
- {
- error = true;
- e.printStackTrace();
- }
- else {
- output.println("maxTradeAreaLength=15");
- }
- label90: if (PROPERTIES.containsKey("maxTradeAreaSize"))
- try {
- MAX_TRADE_AREA_SIZE = Integer.parseInt(
- (String)PROPERTIES
- .get("maxTradeAreaSize"));
- if (MAX_TRADE_AREA_SIZE >= 1) break label154; MAX_TRADE_AREA_SIZE = 1;
- }
- catch (Exception e) {
- error = true;
- e.printStackTrace();
- }
- else {
- output.println("maxTradeAreaSize=144");
- }
- label154: if (PROPERTIES.containsKey("maxBankAreaLength"))
- try {
- MAX_BANK_AREA_LENGTH = Integer.parseInt(
- (String)PROPERTIES
- .get("maxBankAreaLength"));
- if (MAX_BANK_AREA_LENGTH >= 1) break label218; MAX_BANK_AREA_LENGTH = 1;
- }
- catch (Exception e) {
- error = true;
- e.printStackTrace();
- }
- else {
- output.println("maxBankAreaLength=25");
- }
- label218: if (PROPERTIES.containsKey("maxBankAreaSize"))
- try {
- MAX_BANK_AREA_SIZE = Integer.parseInt(
- (String)PROPERTIES
- .get("maxBankAreaSize"));
- if (MAX_BANK_AREA_SIZE >= 1) break label282; MAX_BANK_AREA_SIZE = 1;
- }
- catch (Exception e) {
- error = true;
- e.printStackTrace();
- }
- else {
- output.println("maxBankAreaSize=400");
- }
- label282: if (PROPERTIES.containsKey("tradeAreaCost"))
- try {
- TRADE_AREA_COST = Double.parseDouble(
- (String)PROPERTIES
- .get("tradeAreaCost"));
- if (TRADE_AREA_COST >= 0.0D) break label347; TRADE_AREA_COST = 0.0D;
- }
- catch (Exception e) {
- error = true;
- e.printStackTrace();
- }
- else {
- output.println("tradeAreaCost=1.0");
- }
- label347: if (PROPERTIES.containsKey("personalAreaCost"))
- try {
- PERSONAL_AREA_COST = Double.parseDouble(
- (String)PROPERTIES
- .get("personalAreaCost"));
- if (PERSONAL_AREA_COST >= 0.0D) break label412; PERSONAL_AREA_COST = 0.0D;
- }
- catch (Exception e) {
- error = true;
- e.printStackTrace();
- }
- else {
- output.println("personalAreaCost=3.0");
- }
- label412: if (PROPERTIES.containsKey("bankAreaCost"))
- try {
- BANK_AREA_COST = Double.parseDouble(
- (String)PROPERTIES
- .get("bankAreaCost"));
- if (BANK_AREA_COST >= 0.0D) break label477; BANK_AREA_COST = 0.0D;
- }
- catch (Exception e) {
- error = true;
- e.printStackTrace();
- }
- else {
- output.println("bankAreaCost=5.0");
- }
- label477: if (PROPERTIES.containsKey("transferFee"))
- try {
- TRANSFER_FEE =
- Double.parseDouble((String)PROPERTIES.get("transferFee"));
- if (TRANSFER_FEE > 1.0D) {
- TRANSFER_FEE = 1.0D; break label557;
- }if (TRANSFER_FEE >= 0.0D) break label557; TRANSFER_FEE = 0.0D;
- }
- catch (Exception e) {
- error = true;
- e.printStackTrace();
- }
- else {
- output.println("transferFee=0.15");
- }
- label557: if (PROPERTIES.containsKey("renameFee"))
- try {
- RENAME_FEE = Double.parseDouble((String)PROPERTIES.get("renameFee"));
- if (RENAME_FEE > 1.0D) {
- RENAME_FEE = 1.0D; break label637;
- }if (RENAME_FEE >= 0.0D) break label637; RENAME_FEE = 0.0D;
- }
- catch (Exception e) {
- error = true;
- e.printStackTrace();
- }
- else {
- output.println("renameFee=0.05");
- }
- label637: if (PROPERTIES.containsKey("startingMoney"))
- try {
- STARTING_MONEY = Double.parseDouble(
- (String)PROPERTIES
- .get("startingMoney"));
- if (STARTING_MONEY >= 0.0D) break label702; STARTING_MONEY = 0.0D;
- }
- catch (Exception e) {
- error = true;
- e.printStackTrace();
- }
- else {
- output.println("startingMoney=10.0");
- }
- label702: if (PROPERTIES.containsKey("tradeAreaColor"))
- try {
- TRADE_AREA_COLOR = (String)Colors.class.getField(
- (String)PROPERTIES.get("tradeAreaColor")).get(null);
- } catch (Exception exception) {
- error = true;
- exception.printStackTrace();
- }
- else {
- output.println("tradeAreaColor=Yellow");
- }
- if (PROPERTIES.containsKey("personalAreaColor"))
- try {
- PERSONAL_AREA_COLOR = (String)Colors.class.getField(
- (String)PROPERTIES.get("personalAreaColor")).get(null);
- } catch (Exception exception) {
- error = true;
- exception.printStackTrace();
- }
- else {
- output.println("personalAreaColor=LightBlue");
- }
- if (PROPERTIES.containsKey("bankAreaColor"))
- try {
- BANK_AREA_COLOR = (String)Colors.class.getField(
- (String)PROPERTIES.get("bankAreaColor")).get(null);
- } catch (Exception exception) {
- error = true;
- exception.printStackTrace();
- }
- else {
- output.println("bankAreaColor=Green");
- }
- if (PROPERTIES.containsKey("offerColor"))
- try {
- OFFER_COLOR = (String)Colors.class.getField(
- (String)PROPERTIES.get("offerColor")).get(null);
- } catch (Exception exception) {
- error = true;
- exception.printStackTrace();
- }
- else {
- output.println("offerColor=LightGray");
- }
- if (PROPERTIES.containsKey("errorColor"))
- try {
- ERROR = (String)Colors.class.getField(
- (String)PROPERTIES.get("errorColor")).get(null);
- } catch (Exception exception) {
- error = true;
- exception.printStackTrace();
- }
- else {
- output.println("errorColor=Red");
- }
- if (PROPERTIES.containsKey("commandColor"))
- try {
- COMMAND = (String)Colors.class.getField(
- (String)PROPERTIES.get("commandColor")).get(null);
- } catch (Exception exception) {
- error = true;
- exception.printStackTrace();
- }
- else {
- output.println("commandColor=Rose");
- }
- if (PROPERTIES.containsKey("infoColor"))
- try {
- INFO = (String)Colors.class.getField(
- (String)PROPERTIES.get("infoColor")).get(null);
- } catch (Exception exception) {
- error = true;
- exception.printStackTrace();
- }
- else {
- output.println("infoColor=Blue");
- }
- if (PROPERTIES.containsKey("moneyColor"))
- try {
- MONEY = (String)Colors.class.getField(
- (String)PROPERTIES.get("moneyColor")).get(null);
- } catch (Exception exception) {
- error = true;
- exception.printStackTrace();
- }
- else {
- output.println("moneyColor=Green");
- }
- if (PROPERTIES.containsKey("onlineColor"))
- try {
- ONLINE = (String)Colors.class.getField(
- (String)PROPERTIES.get("onlineColor")).get(null);
- } catch (Exception exception) {
- error = true;
- exception.printStackTrace();
- }
- else {
- output.println("onlineColor=White");
- }
- if (PROPERTIES.containsKey("offlineColor"))
- try {
- OFFLINE = (String)Colors.class.getField(
- (String)PROPERTIES.get("offlineColor")).get(null);
- } catch (Exception exception) {
- error = true;
- exception.printStackTrace();
- }
- else {
- output.println("offlineColor=Gray");
- }
- if (PROPERTIES.containsKey("maxOffers"))
- try {
- MAX_OFFERS = Integer.parseInt((String)PROPERTIES.get("maxOffers"));
- if (MAX_OFFERS >= 1) break label1396; MAX_OFFERS = 1;
- }
- catch (Exception e) {
- error = true;
- e.printStackTrace();
- }
- else {
- output.println("maxOffers=10");
- }
- label1396: if (PROPERTIES.containsKey("verticalCost"))
- try {
- VERTICAL_COST = Double.parseDouble(
- (String)PROPERTIES
- .get("verticalCost"));
- if (VERTICAL_COST > 1.0D) {
- VERTICAL_COST = 1.0D; break label1476;
- }if (VERTICAL_COST >= 0.0D) break label1476; VERTICAL_COST = 0.0D;
- }
- catch (Exception e) {
- error = true;
- e.printStackTrace();
- }
- else {
- output.println("verticalCost=0.02");
- }
- label1476: if (PROPERTIES.containsKey("lotteryInterval"))
- try {
- LOTTERY_INTERVAL = Double.parseDouble(
- (String)PROPERTIES
- .get("lotteryInterval"));
- if (LOTTERY_INTERVAL >= 0.0D) break label1541; LOTTERY_INTERVAL = 0.0D;
- }
- catch (Exception e) {
- error = true;
- e.printStackTrace();
- }
- else {
- output.println("lotteryInterval=60");
- }
- label1541: if (PROPERTIES.containsKey("playersToHalf"))
- try {
- PLAYERS_TO_HALF = Integer.parseInt(
- (String)PROPERTIES
- .get("playersToHalf"));
- if (PLAYERS_TO_HALF >= 0) break label1604; PLAYERS_TO_HALF = 0;
- }
- catch (Exception e) {
- error = true;
- e.printStackTrace();
- }
- else {
- output.println("playersToHalf=5");
- }
- label1604: if (PROPERTIES.containsKey("maxAreas"))
- try {
- MAX_AREAS = Integer.parseInt((String)PROPERTIES.get("maxAreas"));
- if (MAX_AREAS >= 1) break label1668; MAX_AREAS = 1;
- }
- catch (Exception e) {
- error = true;
- e.printStackTrace();
- }
- else {
- output.println("maxAreas=20");
- }
- label1668: if (PROPERTIES.containsKey("exchange")) {
- ITEM_VALUES = new HashMap();
- for (String kv : ((String)PROPERTIES.get("exchange")).split(",")) {
- int colon = kv.indexOf(':');
- if (colon == -1)
- continue;
- try
- {
- int id = Integer.parseInt(kv.substring(0, colon));
- double value = Double.parseDouble(kv.substring(colon + 1));
- value = Math.round(value * 100.0D) / 100.0D;
- if (value > 0.0D)
- ITEM_VALUES.put(Integer.valueOf(id), Double.valueOf(value));
- }
- catch (Exception e) {
- error = true;
- e.printStackTrace();
- }
- }
- } else {
- output.println("exchange=265:1,42:9,266:10,41:90,264:100,57:900");
- }
- if (error)
- logger.log(Level.SEVERE, "Error while reading properties file.");
- else {
- logger.log(Level.INFO, "Properties file successfully read.");
- }
- output.flush();
- output.close();
- }
- private final void writeEconomy()
- {
- try
- {
- ObjectOutputStream outputStream = new ObjectOutputStream(
- new FileOutputStream(ECONOMY_FILE));
- outputStream.writeObject(this.balances);
- outputStream.writeObject(this.paychecks);
- outputStream.writeObject(this.sellingOffers);
- outputStream.writeObject(this.allOffers);
- outputStream.writeObject(new Integer(offerCount));
- outputStream.writeObject(new Double(this.publicFund));
- outputStream.writeObject(this.offerListeners);
- outputStream.writeObject(Long.valueOf(this.lastLottery));
- outputStream.flush();
- outputStream.close();
- logger.log(Level.INFO, "Economy file successfully written.");
- } catch (Exception exception) {
- exception.printStackTrace();
- logger.log(Level.SEVERE, "Error while writing economy file.");
- }
- }
- private final void writeLocations()
- {
- try
- {
- ObjectOutputStream outputStream = new ObjectOutputStream(
- new FileOutputStream(LOCATIONS_FILE));
- outputStream.writeObject(this.tradingAreas);
- outputStream.writeObject(this.personalAreas);
- outputStream.writeObject(this.bankingAreas);
- outputStream.writeObject(this.pendingTradeAreas);
- outputStream.writeObject(this.pendingPersonalAreas);
- outputStream.writeObject(this.pendingBankAreas);
- outputStream.writeObject(new Integer(areaCount));
- outputStream.flush();
- outputStream.close();
- logger.log(Level.INFO, "Locations file successfully written.");
- } catch (Exception exception) {
- exception.printStackTrace();
- logger.log(Level.SEVERE, "Error while writing locations file.");
- }
- }
- private Iterator<Economy.Offer> offerIterator()
- {
- return this.allOffers.iterator();
- }
- private final double getBalance(String player)
- {
- Double balance = (Double)this.balances.get(player.toLowerCase());
- if (balance == null) {
- this.balances.put(player.toLowerCase(), Double.valueOf(0.0D));
- balance = Double.valueOf(0.0D);
- }
- return balance.doubleValue();
- }
- private final void setBalance(String player, double balance)
- {
- assert ((balance >= 0.0D) && (
- (this.balances.containsKey(player)) || (
- etc.getServer().getPlayer(player) != null)));
- this.balances.put(player.toLowerCase(), Double.valueOf(balance));
- }
- private final void addToBalance(String player, double amount)
- {
- if (getBalance(player) > 1.7976931348623157E+308D - amount)
- {
- if (amount < 0.0D)
- setBalance(player,
- Math.max(0.0D, getBalance(player) +
- amount));
- else {
- setBalance(player, 1.7976931348623157E+308D);
- }
- }
- else
- setBalance(player,
- Math.max(0.0D, getBalance(player) +
- amount));
- }
- private final void addOffer(String player, Economy.Offer offer)
- {
- ArrayList playerOffers = (ArrayList)this.sellingOffers.get(
- player.toLowerCase());
- if (playerOffers == null) {
- playerOffers = new ArrayList();
- this.sellingOffers.put(player.toLowerCase(), playerOffers);
- }
- playerOffers.add(offer);
- this.allOffers.add(offer);
- }
- private final void removeOffer(Economy.Offer offer)
- {
- ((ArrayList)this.sellingOffers.get(offer.player)).remove(offer);
- this.allOffers.remove(offer);
- }
- private final boolean hasOffers()
- {
- return !this.allOffers.isEmpty();
- }
- private static final String itemName(int id)
- {
- return Item.Type.fromId(id).name().toLowerCase();
- }
- private static final int itemId(String name)
- {
- for (Item.Type type : Item.Type.values()) {
- if (type.name().equalsIgnoreCase(name)) {
- return type.getId();
- }
- }
- return -1;
- }
- private Economy.Area getArea(Player player)
- {
- return getArea(player.getX(), player.getY(), player.getZ());
- }
- private Economy.Area getArea(double x, double y, double z)
- {
- for (Economy.Area area : this.personalAreas) {
- if (area.withinArea(x, y, z)) {
- return area;
- }
- }
- for (Economy.Area area : this.tradingAreas) {
- if (area.withinArea(x, y, z)) {
- return area;
- }
- }
- for (Economy.Area area : this.bankingAreas) {
- if (area.withinArea(x, y, z)) {
- return area;
- }
- }
- return null;
- }
- private ArrayList<Economy.Area> allAreas()
- {
- return new ArrayList(this.tradingAreas.size() +
- this.personalAreas.size() + this.bankingAreas.size())
- {
- };
- }
- private boolean canTrade(Player player)
- {
- Economy.Area area = getArea(player);
- if (area == null) {
- return false;
- }
- return area instanceof Economy.TradeArea;
- }
- private final int givePlayer(Player player, int id, int amount)
- {
- hn[] items = player.getInventory().getArray();
- int remaining = amount;
- for (int index = 0; (index < items.length) && (remaining > 0); index++) {
- if (items[index] == null) {
- continue;
- }
- if (items[index].c != id) {
- continue;
- }
- if (items[index].a == 64) {
- continue;
- }
- int amountToAdd = Math.min(64 - items[index].a, remaining);
- remaining -= amountToAdd;
- items[index].a += amountToAdd;
- }
- for (int index = 0; (index < items.length) && (remaining > 0); index++) {
- if (items[index] != null) {
- continue;
- }
- int amountToAdd = Math.min(remaining, 64);
- remaining -= amountToAdd;
- items[index] = new hn(id, amountToAdd);
- }
- player.getInventory().updateInventory();
- return remaining;
- }
- private final String format(double amount)
- {
- return String.format("%.2f", new Object[] { Double.valueOf(amount) });
- }
- private final String formatTime(double time)
- {
- int hours = (int)(time / 60.0D) % 24;
- int minutes = (int)time % 60;
- int seconds = (int)(60.0D * (time - (int)time) + 0.5D);
- if (hours != 0) {
- return String.format("%02d:%02d:%02d", new Object[] { Integer.valueOf(hours), Integer.valueOf(minutes), Integer.valueOf(seconds) });
- }
- return String.format("%02d:%02d", new Object[] { Integer.valueOf(minutes), Integer.valueOf(seconds) });
- }
- private static final String areaColor(Economy.Area area)
- {
- if ((area instanceof Economy.TradeArea))
- return TRADE_AREA_COLOR;
- if ((area instanceof Economy.PersonalArea))
- return PERSONAL_AREA_COLOR;
- if ((area instanceof Economy.BankArea)) {
- return BANK_AREA_COLOR;
- }
- return "§0";
- }
- private static final void sendMessage(Player player, String message)
- {
- player.sendMessage(message);
- }
- private static final HashMap<String, String> toKV(String[] split)
- {
- HashMap result = new HashMap();
- String[] arrayOfString = split; int j = split.length; for (int i = 0; i < j; i++) { String current = arrayOfString[i];
- int colon = current.indexOf(':');
- if (colon == -1) {
- continue;
- }
- String key = current.substring(0, colon);
- String value = current.substring(colon + 1);
- result.put(key, value);
- }
- return result;
- }
- private final int numberOfAreas(Player player)
- {
- int result = 0;
- for (Economy.Area area : allAreas()) {
- if (player.getName().equalsIgnoreCase(area.owner)) {
- result++;
- }
- }
- return result;
- }
- private abstract class Area
- implements Serializable
- {
- private static final long serialVersionUID = 2L;
- private double minX;
- private double maxX;
- private double minY;
- private double maxY;
- private double minZ;
- private double maxZ;
- private final int areaId;
- private String owner;
- private String areaName;
- public Area(double minX, double maxX, double minY, double maxY, double minZ, double maxZ, String owner)
- {
- this.minX = minX;
- this.maxX = maxX;
- this.minY = minY;
- this.maxY = maxY;
- this.minZ = minZ;
- this.maxZ = maxZ;
- this.areaId = (Economy.areaCount++);
- if (Economy.areaCount < 0) {
- Economy.logger.log(Level.WARNING,
- "Area id count has overflowed.");
- }
- this.owner = owner;
- this.areaName = "";
- }
- public boolean equals(Object other)
- {
- if (!(other instanceof Area)) {
- return false;
- }
- Area otherArea = (Area)other;
- return this.areaId == otherArea.areaId;
- }
- public double distanceTo(Player player)
- {
- double centerX = this.minX + (this.maxX - this.minX) / 2.0D;
- double centerZ = this.minZ + (this.maxZ - this.minZ) / 2.0D;
- double deltaX = player.getX() - centerX;
- double deltaZ = player.getZ() - centerZ;
- return Math.sqrt(deltaX * deltaX + deltaZ * deltaZ);
- }
- public String directionFrom(Player player)
- {
- double centerX = this.minX + (this.maxX - this.minX) / 2.0D;
- double centerZ = this.minZ + (this.maxZ - this.minZ) / 2.0D;
- double deltaX = centerX - player.getX();
- double deltaZ = centerZ - player.getZ();
- double degrees = -(180.0D * Math.atan2(deltaX, deltaZ) / 3.141592653589793D + 90.0D);
- if (degrees < 0.0D)
- degrees += 360.0D;
- else if (degrees > 360.0D) {
- degrees -= 360.0D;
- }
- return etc.getCompassPointForDirection(degrees);
- }
- public double floorSize()
- {
- return (this.maxX - this.minX) * (this.maxZ - this.minZ);
- }
- public double totalSize()
- {
- return floorSize() * (this.maxY - this.minY);
- }
- public double price()
- {
- return floorSize() * (1.0D + Economy.VERTICAL_COST * (this.maxY - this.minY));
- }
- public boolean withinArea(double x, double y, double z)
- {
- return (x >= this.minX) && (x <= this.maxX) && (y >= this.minY) &&
- (y <= this.maxY) && (z >= this.minZ) && (z <= this.maxZ);
- }
- public final void setName(String name)
- {
- this.areaName = name;
- }
- public String toString()
- {
- StringBuilder result = new StringBuilder();
- if (!this.areaName.equals("")) {
- result.append(this.areaName);
- result.append(": ");
- }
- result.append("(");
- result.append((int)this.minX);
- result.append(", ");
- result.append((int)this.minY);
- result.append(", ");
- result.append((int)this.minZ);
- result.append(") to (");
- result.append((int)this.maxX);
- result.append(", ");
- result.append((int)this.maxY);
- result.append(", ");
- result.append((int)this.maxZ);
- result.append(")");
- return result.toString();
- }
- }
- private class BankArea extends Economy.Area
- {
- private static final long serialVersionUID = 1231436205851667615L;
- public BankArea(double minX, double maxX, double minY, double maxY, double minZ, double maxZ, String owner)
- {
- super(minX, maxX, minY, maxY, minZ, maxZ, owner);
- }
- public double price()
- {
- return Economy.BANK_AREA_COST * super.price();
- }
- }
- private class CompoundCondition<T> extends Economy.Condition<T>
- {
- private static final long serialVersionUID = 4L;
- private HashSet<Economy.Condition<T>> subConditions = new HashSet();
- private CompoundCondition()
- {
- super(null);
- }
- boolean isValid(T parameter)
- {
- for (Economy.Condition condition : this.subConditions) {
- if (!condition.isValid(parameter)) {
- return false;
- }
- }
- return true;
- }
- public boolean addSubCondition(Economy.Condition<T> condition) {
- return this.subConditions.add(condition);
- }
- public boolean removeSubCondition(Economy.Condition<T> condition) {
- return this.subConditions.remove(condition);
- }
- }
- private abstract class Condition<T>
- implements Serializable
- {
- private static final long serialVersionUID = 3L;
- private Condition()
- {
- }
- abstract boolean isValid(T paramT);
- }
- private final class EconomyListener extends PluginListener
- {
- private EconomyListener()
- {
- }
- public void onLogin(Player player)
- {
- if ((Economy.this.balances.containsKey(
- player.getName().toLowerCase())) ||
- (!player.canUseCommand("/balance"))) {
- return;
- }
- if ((Economy.STARTING_MONEY > 0.0D) && (Economy.this.publicFund >= Economy.STARTING_MONEY)) {
- Economy.access$5(player, Economy.INFO + "Welcome to the sever.");
- Economy.access$5(player, Economy.INFO + "Here's " + Economy.MONEY +
- Economy.this.format(Economy.STARTING_MONEY) + Economy.INFO +
- " to get you started.");
- Economy.this.publicFund -= Economy.STARTING_MONEY;
- Economy.this.addToBalance(player.getName(), Economy.STARTING_MONEY);
- }
- }
- public boolean onMobSpawn(Mob mob)
- {
- return Economy.this.getArea(mob.getX(), mob.getY(), mob.getZ()) != null;
- }
- public boolean onBlockPlace(Player player, Block block, Block blockClicked, Item itemInHand)
- {
- Economy.Area area = Economy.this.getArea(block.getX(), block.getY(),
- block.getZ());
- if (area == null) {
- return false;
- }
- if (!area.owner.equalsIgnoreCase(player.getName())) {
- Economy.access$5(player, Economy.ERROR +
- "Can't place blocks here. This area belongs to " + (
- Economy.access$12(area.owner) ? Economy.ONLINE : Economy.OFFLINE) + area.owner +
- Economy.ERROR + ".");
- return true;
- }
- return false;
- }
- public boolean onBlockBreak(Player player, Block block)
- {
- Economy.Area area = Economy.this.getArea(block.getX(), block.getY(),
- block.getZ());
- if (area == null) {
- return false;
- }
- if (!(area instanceof Economy.PersonalArea)) {
- return false;
- }
- if (!area.owner.equalsIgnoreCase(player.getName())) {
- Economy.access$5(player, Economy.ERROR +
- "Can't remove blocks here. This area belongs to " + (
- Economy.access$12(area.owner) ? Economy.ONLINE : Economy.OFFLINE) + area.owner +
- Economy.ERROR + ".");
- return true;
- }
- return false;
- }
- public boolean onCommand(Player player, String[] split)
- {
- if (!Economy.this.isEnabled()) {
- return false;
- }
- String command = split[0].toLowerCase();
- if (command.equals("/buy")) {
- buy(player, split);
- return true;
- }if (command.equals("/saveeconomy")) {
- saveEconomy(player, split);
- return true;
- }if (command.equals("/lottery")) {
- lottery(player, split);
- return true;
- }if (command.equals("/area")) {
- if (split.length <= 1) {
- Economy.access$5(
- player,
- Economy.COMMAND +
- "Usage: /area <add | get | give | list | name | remove>");
- }
- String subcommand = split[1].toLowerCase();
- if (subcommand.equals("add"))
- addArea(player, split);
- else if (subcommand.equals("get"))
- getArea(player, split);
- else if (subcommand.equals("give"))
- giveArea(player, split);
- else if (subcommand.equals("list"))
- listAreas(player, split);
- else if (subcommand.equals("name"))
- nameArea(player, split);
- else if (subcommand.equals("remove"))
- removeArea(player, split);
- else {
- player
- .sendMessage(Economy.COMMAND +
- "Usage: /area <add | get | give | list | name | remove>");
- }
- return true;
- }if (command.equals("/offer")) {
- if (split.length <= 1) {
- Economy.access$5(player, Economy.COMMAND +
- "Usage: /offer <add | list | listen | remove>");
- }
- String subcommand = split[1].toLowerCase();
- if (subcommand.equals("add"))
- offer(player, split);
- else if (subcommand.equals("list"))
- listOffers(player, split);
- else if (subcommand.equals("remove"))
- removeOffer(player, split);
- else if (subcommand.equals("listen"))
- listenFor(player, split);
- else {
- player.sendMessage(Economy.COMMAND +
- "Usage: /offer <add | list | remove>");
- }
- return true;
- }if (command.equals("/money")) {
- if (split.length <= 1) {
- Economy.access$5(
- player,
- Economy.COMMAND +
- "Usage: /money <balance | deposit | give | pay | withdraw>");
- }
- String subcommand = split[1].toLowerCase();
- if (subcommand.equals("balance"))
- balance(player, split);
- else if (subcommand.equals("deposit"))
- deposit(player, split);
- else if (subcommand.equals("give"))
- giveMoney(player, split);
- else if (subcommand.equals("pay"))
- pay(player, split);
- else if (subcommand.equals("withdraw"))
- withdraw(player, split);
- else {
- Economy.access$5(
- player,
- Economy.COMMAND +
- "Usage: /money <balance | deposit | give | pay | withdraw>");
- }
- return true;
- }
- return false;
- }
- private final void withdraw(Player player, String[] split) {
- if (!player.canUseCommand("/money")) {
- return;
- }
- if (split.length < 3) {
- Economy.access$5(player, Economy.COMMAND +
- "Usage: /money withdraw <amount | 'all' >");
- return;
- }
- Economy.Area area = Economy.this.getArea(player);
- if ((area == null) || (!(area instanceof Economy.BankArea))) {
- Economy.access$5(
- player,
- Economy.ERROR +
- "Error - you must be in a banking area to withdraw money.");
- if (player.canUseCommand("/area")) {
- Economy.access$5(player, Economy.INFO +
- "Try using the \"/area list\" command.");
- }
- return;
- }
- double withdrawAmount;
- try {
- double withdrawAmount = Double.parseDouble(split[2]);
- withdrawAmount = Math.round(withdrawAmount * 100.0D) / 100.0D;
- } catch (Exception e) {
- if (!split[2].equalsIgnoreCase("all")) {
- Economy.access$5(player, Economy.ERROR +
- "Error - amount must be a valid number.");
- return;
- }
- withdrawAmount = Economy.this.getBalance(player.getName());
- }
- if (withdrawAmount <= 0.0D) {
- Economy.access$5(player, Economy.ERROR +
- "Error - must withdraw a positive amount.");
- return;
- }
- if (Economy.this.getBalance(player.getName()) < withdrawAmount) {
- Economy.access$5(player, Economy.ERROR + "Error - insufficient funds.");
- Economy.access$5(player, Economy.INFO + "Your current balance is " + Economy.MONEY +
- Economy.this.format(Economy.access$17(Economy.this, player.getName())) +
- Economy.INFO + ".");
- return;
- }
- TreeMap VALUE_ITEMS = new TreeMap(
- new Comparator()
- {
- public int compare(Double arg0, Double arg1) {
- if (arg0.doubleValue() < arg1.doubleValue())
- return 1;
- if (arg0 == arg1) {
- return 0;
- }
- return -1;
- }
- })
- {
- };
- boolean removed = false;
- for (Map.Entry entry : VALUE_ITEMS.entrySet()) {
- double itemValue = ((Double)entry.getKey()).doubleValue();
- int itemId = ((Integer)entry.getValue()).intValue();
- int count = (int)(withdrawAmount / itemValue);
- if (count == 0) {
- continue;
- }
- int remaining = Economy.this.givePlayer(player, itemId, count);
- withdrawAmount -= (count - remaining) * itemValue;
- Economy.this.addToBalance(player.getName(), (remaining - count) *
- itemValue);
- if (remaining > 0) {
- Economy.access$5(player, Economy.ERROR + "Error - could not withdraw " +
- Economy.MONEY + Economy.this.format(withdrawAmount) + Economy.ERROR + ".");
- Economy.access$5(player, Economy.ERROR +
- "Please make room in your inventory.");
- if (removed) {
- Economy.access$5(player, Economy.INFO +
- "Your balance has decreased to " +
- Economy.MONEY +
- Economy.this
- .format(Economy.access$17(Economy.this,
- player.getName())) + Economy.INFO + ".");
- }
- return;
- }
- removed = true;
- }
- if (withdrawAmount > 0.0D) {
- Economy.access$5(player, Economy.ERROR + "Warning - could not withdraw " +
- Economy.MONEY + Economy.this.format(withdrawAmount) + Economy.ERROR + ".");
- }
- if (removed)
- Economy.access$5(player, Economy.INFO + "Your balance has decreased to " +
- Economy.MONEY +
- Economy.this.format(Economy.access$17(Economy.this, player.getName())) +
- Economy.INFO + ".");
- }
- private final void lottery(Player player, String[] split)
- {
- if (!player.canUseCommand("/lottery")) {
- return;
- }
- long currentTime = System.currentTimeMillis();
- double lotteryMs = Economy.LOTTERY_INTERVAL * 60.0D * 1000.0D;
- if (currentTime - Economy.this.lastLottery < lotteryMs) {
- player.sendMessage(Economy.ERROR +
- "Error - lottery has been run too recently.");
- player.sendMessage(Economy.ERROR +
- "You must wait another " +
- "§f" +
- Economy.this
- .formatTime(Economy.LOTTERY_INTERVAL -
- (currentTime - Economy.this.lastLottery) /
- 1000.0D / 60.0D) + Economy.ERROR +
- " before trying again.");
- return;
- }
- Economy.this.lastLottery = currentTime;
- List players = etc.getServer().getPlayerList();
- Iterator iterator = players.iterator();
- while (iterator.hasNext()) {
- if (!((Player)iterator.next()).canUseCommand("/money")) {
- iterator.remove();
- }
- }
- if (players.size() <= 1) {
- player
- .sendMessage(Economy.ERROR +
- "Error - there must be more people online to have a lottery.");
- return;
- }
- double maxWinnings = Economy.this.publicFund * (
- 1.0D -
- Math.exp(Math.log(2.0D) / (Economy.PLAYERS_TO_HALF - 1) * (
- 1 - players.size())));
- maxWinnings = Math.round(100.0D * maxWinnings) / 100.0D;
- Player winner = (Player)players.get((int)(Math.random() * players.size()));
- for (Player p : players) {
- Economy.access$5(p, Economy.ONLINE + player.getName() + Economy.INFO +
- " has started the lottery!");
- Economy.access$5(p, Economy.MONEY + Economy.this.format(maxWinnings) + Economy.INFO +
- " is up for stake!");
- Economy.access$5(p, Economy.INFO + "And the winner is... " + Economy.ONLINE +
- winner.getName() + Economy.INFO + "! Congratulations!");
- }
- Economy.this.addToBalance(winner.getName(), maxWinnings);
- Economy.this.publicFund -= maxWinnings;
- Economy.access$5(winner, Economy.INFO + "Your balance has increased to " + Economy.MONEY +
- Economy.this.format(Economy.access$17(Economy.this, winner.getName())) + Economy.INFO +
- ".");
- }
- private final void listenFor(Player player, String[] split) {
- String playerName = player.getName().toLowerCase();
- if (!player.canUseCommand("/offer")) {
- return;
- }
- if (split.length < 3) {
- Economy.access$5(
- player,
- Economy.COMMAND +
- "Usage: /offer listen <itemName1|'none'|?> [itemName2] ... [itemNameN]");
- return;
- }
- Iterator localIterator1;
- if (split[2].equalsIgnoreCase("none")) {
- boolean found = false;
- localIterator1 = Economy.this.offerListeners
- .values().iterator();
- while (localIterator1.hasNext()) {
- HashSet listeners = (HashSet)localIterator1.next();
- if (listeners.contains(playerName)) {
- found = true;
- }
- listeners.remove(playerName);
- }
- if (found)
- Economy.access$5(player, Economy.INFO +
- "You are no longer listening for any items.");
- else {
- Economy.access$5(player, Economy.ERROR +
- "Error - you are not listening for any items.");
- }
- return;
- }if (split[2].equals("?")) {
- HashSet listeningFor = new HashSet();
- localIterator1 = Economy.this.offerListeners
- .entrySet().iterator();
- while (localIterator1.hasNext()) {
- Map.Entry entry = (Map.Entry)localIterator1.next();
- if (!((HashSet)entry.getValue()).contains(
- player.getName().toLowerCase())) continue;
- listeningFor.add((Integer)entry.getKey());
- }
- if (listeningFor.size() == 0) {
- Economy.access$5(player, Economy.INFO +
- "You are not listening for any items.");
- } else {
- StringBuilder message = new StringBuilder();
- message.append(Economy.INFO);
- message.append("You are listening for ");
- int listenerIndex = 0;
- for (Integer id : listeningFor) {
- message.append(Economy.access$26(id.intValue()));
- if (listenerIndex < listeningFor.size() - 1) {
- if (listeningFor.size() > 2) {
- message.append(',');
- }
- message.append(' ');
- }
- if (listenerIndex == listeningFor.size() - 2) {
- message.append("and ");
- }
- listenerIndex++;
- }
- message.append(".");
- Economy.access$5(player, message.toString());
- }
- return;
- }
- for (int itemIndex = 2; itemIndex < split.length; itemIndex++) {
- int itemId = Economy.access$0(split[itemIndex]);
- if (itemId == -1) {
- Economy.access$5(player, Economy.ERROR +
- "Error - could not find item id for " +
- split[itemIndex] + ".");
- }
- else
- {
- HashSet listeners =
- (HashSet)Economy.this.offerListeners
- .get(Integer.valueOf(itemId));
- if (listeners == null) {
- listeners = new HashSet();
- Economy.this.offerListeners.put(Integer.valueOf(itemId), listeners);
- }
- if (listeners.contains(playerName)) {
- Economy.access$5(player, Economy.INFO +
- "You are no longer listening for " +
- split[itemIndex] + ".");
- listeners.remove(playerName);
- return;
- }
- listeners.add(playerName);
- Economy.access$5(player, Economy.INFO + "You are now listening for " +
- split[itemIndex] + ".");
- }
- }
- }
- private final void giveArea(Player player, String[] split)
- {
- if (!player.canUseCommand("/area")) {
- return;
- }
- if (split.length < 4) {
- Economy.access$5(player, Economy.COMMAND +
- "Usage: /area give <areaId> <playerName>");
- return;
- }
- try
- {
- areaId = Integer.parseInt(split[2]);
- }
- catch (Exception e)
- {
- int areaId;
- Economy.access$5(player, Economy.ERROR +
- "Error - area id must be a valid number.");
- return;
- }
- int areaId;
- if (player.getName().equalsIgnoreCase(split[3])) {
- Economy.access$5(player, Economy.ERROR +
- "Error - you can't transfer an area to yourself.");
- return;
- }
- String otherName = split[3].toLowerCase();
- Player otherPlayer = etc.getServer().getPlayer(otherName);
- if ((otherPlayer == null) &&
- (!Economy.this.balances.containsKey(otherName))) {
- Economy.access$5(player, Economy.ERROR + "Error - can't find player " +
- Economy.OFFLINE + otherName + Economy.ERROR + ".");
- return;
- }
- for (Economy.Area area : Economy.this.allAreas()) {
- if (area.areaId != areaId) {
- continue;
- }
- if ((!area.owner.equalsIgnoreCase(player.getName())) &&
- (!player.isAdmin())) {
- Economy.access$5(player, Economy.ERROR +
- "Error - you can't transfer that area.");
- return;
- }
- double transferPrice = Economy.TRANSFER_FEE * area.price();
- String color = Economy.access$29(area);
- if (Economy.this.getBalance(player.getName()) < transferPrice) {
- Economy.access$5(player, Economy.ERROR + "Error - insufficient funds.");
- Economy.access$5(player, Economy.ERROR + "It will cost " + Economy.MONEY +
- Economy.this.format(transferPrice) + Economy.ERROR +
- " to transfer that area.");
- return;
- }
- area.owner = split[3].toLowerCase();
- if (area.areaName.equals("")) {
- Economy.access$5(player, Economy.INFO + "You have transferred area ID " +
- color + area.areaId + Economy.INFO + " to " + (
- Economy.access$12(otherName) ? Economy.ONLINE : Economy.OFFLINE) +
- otherName + Economy.INFO + ".");
- if (otherPlayer != null)
- Economy.access$5(otherPlayer, Economy.INFO + Economy.ONLINE +
- player.getName().toLowerCase() + Economy.INFO +
- " has given you area ID " + color +
- area.areaId + Economy.INFO + ".");
- }
- else {
- Economy.access$5(player, Economy.INFO + "You have transferred " + color +
- area.areaName + Economy.INFO + " to " + (
- Economy.access$12(otherName) ? Economy.ONLINE : Economy.OFFLINE) +
- otherName + Economy.INFO + ".");
- if (otherPlayer != null) {
- Economy.access$5(otherPlayer, Economy.INFO + Economy.ONLINE +
- player.getName().toLowerCase() + Economy.INFO +
- " has given you " + color + area.areaName +
- Economy.INFO + ".");
- }
- }
- Economy.this.addToBalance(player.getName().toLowerCase(),
- -transferPrice);
- Economy.this.publicFund += transferPrice;
- Economy.access$5(player, Economy.INFO + "You spent " + Economy.MONEY +
- Economy.this.format(transferPrice) + Economy.INFO +
- " transferring that area.");
- Economy.access$5(player, Economy.INFO + "Your balance has decreased to " +
- Economy.MONEY +
- Economy.this.format(Economy.access$17(Economy.this, player.getName())) +
- Economy.INFO + ".");
- return;
- }
- }
- private final void getArea(Player player, String[] split)
- {
- if (!player.canUseCommand("/area"))
- return;
- String playerName;
- String playerName;
- if (split.length < 3)
- playerName = player.getName().toLowerCase();
- else {
- playerName = split[2].toLowerCase();
- }
- if (!Economy.access$12(playerName)) {
- Economy.access$5(player, Economy.ERROR + "Error - " + Economy.OFFLINE + playerName +
- Economy.ERROR + " is not online.");
- return;
- }
- Player otherPlayer = etc.getServer().getPlayer(playerName);
- Economy.Area area = Economy.this.getArea(otherPlayer);
- if (area == null) {
- if (playerName.equalsIgnoreCase(player.getName())) {
- Economy.access$5(player, Economy.INFO + "You are not in any areas.");
- if (player.canUseCommand("/area"))
- Economy.access$5(player, Economy.INFO +
- "Try using the \"/area list\" command.");
- }
- else {
- Economy.access$5(player, Economy.ONLINE + playerName + Economy.INFO +
- " is not in any areas.");
- }
- return;
- }
- String owner = area.owner;
- String color = Economy.access$29(area);
- StringBuilder message = new StringBuilder();
- message.append(Economy.INFO);
- if ((area.areaName.equals("")) || ((area instanceof Economy.PersonalArea))) {
- if (player.getName().equalsIgnoreCase(playerName)) {
- message.append("You are in ");
- if (player.getName().equalsIgnoreCase(owner)) {
- if (area.areaName.equals(""))
- message.append("your own area. " + color + "(" +
- area.areaId + ")");
- else
- message.append(color + area.areaName + Economy.INFO + "." +
- color + " (" + area.areaId + ")");
- }
- else {
- message.append((Economy.access$12(owner) ? Economy.ONLINE : Economy.OFFLINE) +
- owner + "'s " + Economy.INFO + "area.");
- if (player.isAdmin())
- message.append(color + " (" + area.areaId + ")");
- }
- }
- else {
- message.append((Economy.access$12(playerName) ? Economy.ONLINE : Economy.OFFLINE) +
- playerName + Economy.INFO + " is in ");
- if (player.getName().equalsIgnoreCase(owner)) {
- if (area.areaName.equals(""))
- message.append("your area. " + color + "(" +
- area.areaId + ")");
- else
- message.append(color + area.areaName + Economy.INFO + "." +
- color + " (" + area.areaId + ")");
- }
- else {
- message.append((Economy.access$12(owner) ? Economy.ONLINE : Economy.OFFLINE) +
- owner + "'s " + Economy.INFO + "area.");
- if (player.isAdmin())
- message.append(color + " (" + area.areaId + ")");
- }
- }
- }
- else {
- if (playerName.equalsIgnoreCase(player.getName()))
- message.append("You are in ");
- else {
- message.append((Economy.access$12(playerName) ? Economy.ONLINE : Economy.OFFLINE) +
- playerName + Economy.INFO + " is in ");
- }
- message.append(color + area.areaName);
- message.append(Economy.INFO + ".");
- if ((player.getName().equalsIgnoreCase(owner)) ||
- (player.isAdmin())) {
- message.append(color);
- message.append(" (");
- message.append(area.areaId);
- message.append(")");
- }
- }
- Economy.access$5(player, message.toString());
- }
- private final void deposit(Player player, String[] split)
- {
- if (!player.canUseCommand("/money")) {
- return;
- }
- Economy.Area area = Economy.this.getArea(player);
- if ((area == null) || (!(area instanceof Economy.BankArea))) {
- Economy.access$5(
- player,
- Economy.ERROR +
- "Error - you must be in a banking area to make a deposit.");
- if (player.canUseCommand("/area")) {
- Economy.access$5(player, Economy.INFO +
- "Try using the \"/area list\" command.");
- }
- return;
- }
- Inventory inventory = player.getInventory();
- hn[] inventoryArray = inventory.getArray();
- double totalDeposit = 0.0D;
- for (int index = 0; index < inventoryArray.length; index++) {
- if (inventoryArray[index] == null) {
- continue;
- }
- int id = inventoryArray[index].c;
- if (!Economy.ITEM_VALUES.containsKey(Integer.valueOf(id))) {
- continue;
- }
- int pileSize = inventoryArray[index].a;
- double depositAmount = pileSize * ((Double)Economy.ITEM_VALUES.get(Integer.valueOf(id))).doubleValue();
- totalDeposit += depositAmount;
- Economy.this.addToBalance(player.getName().toLowerCase(),
- depositAmount);
- inventoryArray[index] = null;
- }
- if (totalDeposit == 0.0D) {
- Economy.access$5(player, Economy.ERROR +
- "Error - you don't have anything to deposit.");
- return;
- }
- player.getInventory().updateInventory();
- Economy.access$5(player, Economy.INFO + "You have deposited " + Economy.MONEY +
- Economy.this.format(totalDeposit) + Economy.INFO + ".");
- Economy.access$5(player, Economy.INFO +
- "Your balance has increased to " +
- Economy.MONEY +
- Economy.this
- .format(Economy.access$17(Economy.this,
- player.getName().toLowerCase())) + Economy.INFO + ".");
- }
- private final void giveMoney(Player player, String[] split)
- {
- if ((!player.canUseCommand("/money")) || (!player.isAdmin())) {
- return;
- }
- if (split.length < 3) {
- Economy.access$5(player, Economy.COMMAND + "Usage: /money give <amount>");
- return;
- }
- try
- {
- double amount = Double.parseDouble(split[2]);
- amount = Math.round(amount * 100.0D) / 100.0D;
- } catch (Exception e) {
- Economy.access$5(player, Economy.ERROR +
- "Error - amount must be a valid number.");
- return;
- }
- double amount;
- if (amount == 0.0D) {
- Economy.access$5(player, Economy.ERROR + "Error - amount cannot equal 0.");
- return;
- }
- Economy.this.addToBalance(player.getName(), amount);
- if (amount > 0.0D)
- Economy.access$5(player, Economy.INFO + "Your balance has increased to " +
- Economy.MONEY +
- Economy.this.format(Economy.access$17(Economy.this, player.getName())) +
- Economy.INFO + ".");
- else
- Economy.access$5(player, Economy.INFO + "Your balance has decreased to " +
- Economy.MONEY +
- Economy.this.format(Economy.access$17(Economy.this, player.getName())) +
- Economy.INFO + ".");
- }
- private final void saveEconomy(Player player, String[] split)
- {
- if (!player.canUseCommand("/saveEconomy")) {
- return;
- }
- Economy.this.writeEconomy();
- Economy.this.writeLocations();
- Economy.access$5(player, Economy.INFO + "Economy files saved.");
- }
- public void onBlockRightClicked(Player player, Block block, Item item)
- {
- String currentPlayer = player.getName().toLowerCase();
- if (item.getItemId() != -1)
- return;
- String areaType;
- if (Economy.this.pendingTradeAreas.containsKey(currentPlayer)) {
- ArrayList blocks = (ArrayList)Economy.this.pendingTradeAreas.get(currentPlayer);
- areaType = "trade";
- }
- else
- {
- String areaType;
- if (Economy.this.pendingPersonalAreas
- .containsKey(currentPlayer)) {
- ArrayList blocks = (ArrayList)Economy.this.pendingPersonalAreas.get(currentPlayer);
- areaType = "personal";
- }
- else
- {
- String areaType;
- if (Economy.this.pendingBankAreas.containsKey(currentPlayer)) {
- ArrayList blocks = (ArrayList)Economy.this.pendingBankAreas.get(currentPlayer);
- areaType = "bank";
- } else {
- return;
- }
- }
- }
- String areaType;
- ArrayList blocks;
- for (Economy.Area area : Economy.this.allAreas()) {
- if ((!area.withinArea(block.getX(), block.getY(), block.getZ())) || (
- ((area instanceof Economy.PersonalArea)) &&
- (area.owner.equalsIgnoreCase(currentPlayer)) && (
- (areaType.equals("trade")) ||
- (areaType.equals("bank"))))) {
- continue;
- }
- String color = Economy.access$29(area);
- if (player.getName().equalsIgnoreCase(area.owner)) {
- if (area.areaName.equals(""))
- Economy.access$5(
- player,
- Economy.ERROR +
- "Error - that block is already part of area ID " +
- color + area.areaId + Economy.ERROR + ".");
- else
- Economy.access$5(player, Economy.ERROR +
- "Error - that block is already part of " +
- color + area.areaName + Economy.INFO + "." +
- color + " (" + area.areaId + ")");
- }
- else {
- StringBuilder message = new StringBuilder();
- if ((area.areaName.equals("")) ||
- ((area instanceof Economy.PersonalArea))) {
- message.append(Economy.ERROR +
- "Error - that block is already part of " + (
- Economy.access$12(area.owner) ? Economy.ONLINE : Economy.OFFLINE) +
- "'s" + Economy.ERROR + " area.");
- if (player.isAdmin())
- message
- .append(color + " (" + area.areaId +
- ")");
- }
- else {
- message.append(Economy.ERROR +
- "Error - that block is already part of " +
- color + area.areaName + Economy.ERROR + ".");
- if (player.isAdmin()) {
- message
- .append(color + " (" + area.areaId +
- ")");
- }
- }
- Economy.access$5(player, message.toString());
- }
- return;
- }
- if (blocks.size() == 3) {
- Block block0 = (Block)blocks.get(0);
- Block block1 = (Block)blocks.get(1);
- Block block2 = (Block)blocks.get(2);
- double xmin = Math.min(block1.getX(), block0.getX());
- double xmax = Math.max(block1.getX(), block0.getX()) + 1;
- double zmin = Math.min(block1.getZ(), block0.getZ());
- double zmax = Math.max(block1.getZ(), block0.getZ()) + 1;
- double ymin = Math.min(block2.getY(), block.getY());
- double ymax = Math.max(block2.getY(), block.getY()) + 1;
- double deltaX = xmax - xmin;
- double deltaY = ymax - ymin;
- double deltaZ = zmax - zmin;
- double floorSize = deltaX * deltaZ;
- if (deltaY <= 1.0D) {
- ymax = ymin + 2.0D;
- deltaY = ymax - ymin;
- }
- if ((areaType.equals("trade")) &&
- ((deltaX > Economy.MAX_TRADE_AREA_LENGTH) || (deltaZ > Economy.MAX_TRADE_AREA_LENGTH)) &&
- (!player.isAdmin())) {
- Economy.access$5(
- player,
- Economy.ERROR +
- "Error - area too long. Trade area side lengths must be less than " +
- Economy.MAX_TRADE_AREA_LENGTH);
- Economy.this.pendingTradeAreas.remove(currentPlayer);
- return;
- }
- if ((areaType.equals("trade")) && (floorSize > Economy.MAX_TRADE_AREA_SIZE) &&
- (!player.isAdmin())) {
- Economy.access$5(
- player,
- Economy.ERROR +
- "Error - area too large. Maximum trade area size is " +
- Economy.MAX_TRADE_AREA_SIZE + "blocks^2");
- Economy.this.pendingTradeAreas.remove(currentPlayer);
- return;
- }
- if ((areaType.equals("bank")) &&
- ((deltaX > Economy.MAX_BANK_AREA_LENGTH) || (deltaZ > Economy.MAX_BANK_AREA_LENGTH)) &&
- (!player.isAdmin())) {
- Economy.access$5(
- player,
- Economy.ERROR +
- "Error - area too long. Bank area side lengths must be less than " +
- Economy.MAX_BANK_AREA_LENGTH + ".");
- Economy.this.pendingBankAreas.remove(currentPlayer);
- return;
- }
- if ((areaType.equals("bank")) && (floorSize > Economy.MAX_BANK_AREA_SIZE) &&
- (!player.isAdmin())) {
- Economy.access$5(
- player,
- Economy.ERROR +
- "Error - area too large. Maximum bank area size is " +
- Economy.MAX_BANK_AREA_SIZE + "blocks^2");
- Economy.this.pendingBankAreas.remove(currentPlayer);
- return;
- }
- double areaCost = 0.0D;
- if (areaType.equals("trade"))
- {
- areaCost = areaCost + floorSize * Economy.TRADE_AREA_COST * (
- 1.0D + Economy.VERTICAL_COST * deltaY);
- if (areaCost > Economy.this.getBalance(currentPlayer)) {
- Economy.access$5(player, Economy.ERROR +
- "Error - insufficient funds.");
- Economy.access$5(player, Economy.ERROR +
- "A trading area of that size will cost " +
- Economy.MONEY + Economy.this.format(areaCost) + Economy.ERROR + ".");
- Economy.this.pendingTradeAreas.remove(currentPlayer);
- Economy.access$5(player, Economy.INFO +
- "You are no longer defining trading areas.");
- return;
- }
- Economy.this.addToBalance(currentPlayer, -areaCost);
- Economy.this.publicFund += areaCost;
- } else if (areaType.equals("personal"))
- {
- areaCost = areaCost + floorSize * Economy.PERSONAL_AREA_COST * (
- 1.0D + Economy.VERTICAL_COST * deltaY);
- if (areaCost > Economy.this.getBalance(currentPlayer)) {
- Economy.access$5(player, Economy.ERROR +
- "Error - insufficient funds.");
- Economy.access$5(player, Economy.ERROR +
- "A personal area of that size will cost " +
- Economy.MONEY + Economy.this.format(areaCost) + Economy.ERROR + ".");
- Economy.this.pendingPersonalAreas.remove(currentPlayer);
- Economy.access$5(player, Economy.INFO +
- "You are no longer defining personl areas.");
- return;
- }
- Economy.this.addToBalance(currentPlayer, -areaCost);
- Economy.this.publicFund += areaCost;
- } else if (areaType.equals("bank"))
- {
- areaCost = areaCost + floorSize * Economy.BANK_AREA_COST * (
- 1.0D + Economy.VERTICAL_COST * deltaY);
- if (areaCost > Economy.this.getBalance(currentPlayer)) {
- Economy.access$5(player, Economy.ERROR +
- "Error - insufficient funds.");
- Economy.access$5(player, Economy.ERROR +
- "A banking area of that size will cost " +
- Economy.MONEY + Economy.this.format(areaCost) + Economy.ERROR + ".");
- Economy.this.pendingBankAreas.remove(currentPlayer);
- Economy.access$5(player, Economy.INFO +
- "You are no longer defining banking areas.");
- return;
- }
- Economy.this.addToBalance(currentPlayer, -areaCost);
- Economy.this.publicFund += areaCost;
- }
- if (areaType.equals("trade")) {
- Economy.Area newArea = new Economy.TradeArea(Economy.this, xmin, xmax, ymin, ymax, zmin, zmax,
- currentPlayer);
- Economy.this.tradingAreas.add(newArea);
- Economy.this.pendingTradeAreas.remove(currentPlayer);
- Economy.access$5(player, Economy.INFO +
- "You have defined a trading area. (Area id " +
- Economy.TRADE_AREA_COLOR + newArea.areaId + Economy.INFO + ")");
- } else if (areaType.equals("personal")) {
- Economy.Area newArea = new Economy.PersonalArea(Economy.this, xmin, xmax, ymin, ymax, zmin,
- zmax, currentPlayer);
- Economy.this.personalAreas.add(newArea);
- Economy.this.pendingPersonalAreas.remove(currentPlayer);
- Economy.access$5(player, Economy.INFO +
- "You have defined a personal area. (Area id " +
- Economy.PERSONAL_AREA_COLOR + newArea.areaId + Economy.INFO + ")");
- } else if (areaType.equals("bank")) {
- Economy.Area newArea = new Economy.BankArea(Economy.this, xmin, xmax, ymin, ymax, zmin, zmax,
- currentPlayer);
- Economy.this.bankingAreas.add(newArea);
- Economy.this.pendingBankAreas.remove(currentPlayer);
- Economy.access$5(player, Economy.INFO +
- "You have defined a banking area. (Area id " +
- Economy.BANK_AREA_COLOR + newArea.areaId + Economy.INFO + ")");
- }
- Economy.access$5(player, Economy.INFO + "You have bought the area for " +
- Economy.MONEY + Economy.this.format(areaCost) + Economy.INFO + ".");
- Economy.access$5(player, Economy.INFO + "Your balance has decreased to " +
- Economy.MONEY +
- Economy.this.format(Economy.access$17(Economy.this, currentPlayer)) + Economy.INFO +
- ".");
- if (player.canUseCommand("/nameArea")) {
- Economy.access$5(player, Economy.INFO +
- "You can now name this area with /nameArea.");
- }
- return;
- }
- blocks.add(block);
- if (blocks.size() == 1)
- Economy.access$5(player, Economy.INFO + "Now right click the other corner.");
- else if (blocks.size() == 2)
- Economy.access$5(player, Economy.INFO +
- "Next, right click the floor of your area.");
- else if (blocks.size() == 3)
- Economy.access$5(player, Economy.INFO +
- "Finally, right click the ceiling of your area.");
- }
- private final void removeArea(Player player, String[] split)
- {
- if (!player.canUseCommand("/area")) {
- return;
- }
- if (split.length < 3) {
- Economy.access$5(player, Economy.COMMAND +
- "Usage: /area remove <areaId|'all'>");
- return;
- }
- if ((Economy.this.tradingAreas.isEmpty()) &&
- (Economy.this.personalAreas.isEmpty()) &&
- (Economy.this.bankingAreas.isEmpty())) {
- Economy.access$5(player, Economy.ERROR + "Error - no areas to remove.");
- return;
- }
- int areaId;
- try {
- areaId = Integer.parseInt(split[2]);
- }
- catch (Exception e)
- {
- int areaId;
- if (!split[2].equalsIgnoreCase("all")) {
- Economy.access$5(player, Economy.ERROR +
- "Error - area id must be a valid number.");
- return;
- }
- areaId = -1;
- }
- boolean removed = false;
- Iterator tradingAreaIterator = Economy.this.tradingAreas
- .iterator();
- while (tradingAreaIterator.hasNext()) {
- Economy.Area area = (Economy.Area)tradingAreaIterator.next();
- if ((area.areaId == areaId) || (areaId == -1)) {
- if (!player.getName().equalsIgnoreCase(area.owner)) {
- if (areaId == -1) {
- continue;
- }
- if (!player.isAdmin()) {
- Economy.access$5(player, Economy.ERROR +
- "Error - you cannot remove that area.");
- return;
- }
- }
- removed = true;
- tradingAreaIterator.remove();
- if (areaId != -1) {
- Economy.access$5(player, Economy.INFO + "Area successfully removed.");
- return;
- }
- }
- }
- Iterator personalAreaIterator = Economy.this.personalAreas
- .iterator();
- while (personalAreaIterator.hasNext()) {
- Economy.Area area = (Economy.Area)personalAreaIterator.next();
- if ((area.areaId == areaId) || (areaId == -1)) {
- if (!player.getName().equalsIgnoreCase(area.owner)) {
- if (areaId == -1) {
- continue;
- }
- if (!player.isAdmin()) {
- Economy.access$5(player, Economy.ERROR +
- "Error - you cannot remove that area.");
- return;
- }
- }
- removed = true;
- personalAreaIterator.remove();
- if (areaId != -1) {
- Economy.access$5(player, Economy.INFO + "Area successfully removed.");
- return;
- }
- }
- }
- Iterator bankAreaIterator = Economy.this.bankingAreas
- .iterator();
- while (bankAreaIterator.hasNext()) {
- Economy.Area area = (Economy.Area)bankAreaIterator.next();
- if ((area.areaId == areaId) || (areaId == -1)) {
- if (!player.getName().equalsIgnoreCase(area.owner)) {
- if (areaId == -1) {
- continue;
- }
- if (!player.isAdmin()) {
- Economy.access$5(player, Economy.ERROR +
- "Error - you cannot remove that area.");
- return;
- }
- }
- removed = true;
- bankAreaIterator.remove();
- if (areaId != -1) {
- Economy.access$5(player, Economy.INFO + "Area successfully removed.");
- return;
- }
- }
- }
- if (areaId == -1) {
- if (removed)
- Economy.access$5(player, Economy.INFO + "All areas removed.");
- else {
- Economy.access$5(player, Economy.ERROR +
- "Error - you can't remove any areas.");
- }
- return;
- }
- Economy.access$5(player, Economy.ERROR + "Error - could not find area id " +
- areaId + ".");
- }
- private final void nameArea(Player player, String[] split)
- {
- if (!player.canUseCommand("/area")) {
- return;
- }
- if (split.length < 4) {
- Economy.access$5(player, Economy.COMMAND +
- "Usage: /area name <areaId> <newName>");
- return;
- }
- try
- {
- areaId = Integer.parseInt(split[2]);
- }
- catch (Exception e)
- {
- int areaId;
- Economy.access$5(player, Economy.ERROR +
- "Error - area id must be a valid number.");
- return;
- }
- int areaId;
- StringBuilder newName = new StringBuilder();
- for (int index = 3; index < split.length; index++) {
- newName.append(split[index]);
- if (index < split.length - 1) {
- newName.append(' ');
- }
- }
- for (Economy.Area area : Economy.this.allAreas()) {
- if (area.areaId == areaId) {
- if ((!player.getName().equalsIgnoreCase(area.owner)) &&
- (!player.isAdmin())) {
- Economy.access$5(player, Economy.ERROR +
- "Error - you cannot rename that area.");
- return;
- }
- double renameFee = area.floorSize() * Economy.RENAME_FEE;
- String color;
- if ((area instanceof Economy.TradeArea)) {
- String color = Economy.TRADE_AREA_COLOR;
- renameFee *= Economy.TRADE_AREA_COST;
- } else if ((area instanceof Economy.PersonalArea)) {
- String color = Economy.PERSONAL_AREA_COLOR;
- renameFee *= Economy.PERSONAL_AREA_COST;
- } else if ((area instanceof Economy.BankArea)) {
- String color = Economy.BANK_AREA_COLOR;
- renameFee *= Economy.BANK_AREA_COST;
- } else {
- color = "§0";
- }
- if ((!area.areaName.equals("")) &&
- (Economy.this.getBalance(player.getName()) < renameFee)) {
- Economy.access$5(player, Economy.ERROR +
- "Error - insufficient funds.");
- Economy.access$5(player, Economy.ERROR + "It will cost " + Economy.MONEY +
- Economy.this.format(renameFee) + Economy.ERROR +
- " to rename that area.");
- Economy.access$5(player, Economy.INFO +
- "Your current balance is " +
- Economy.this
- .format(Economy.access$17(Economy.this,
- player.getName())) + Economy.INFO + ".");
- return;
- }
- Economy.access$5(player, Economy.INFO +
- "Area name successfully changed to " + color +
- newName.toString() + Economy.INFO + ".");
- if (!area.areaName.equals("")) {
- Economy.this.addToBalance(player.getName(), -renameFee);
- Economy.this.publicFund += renameFee;
- Economy.access$5(player, Economy.INFO +
- "Your balance has decreased to " +
- Economy.MONEY +
- Economy.this
- .format(Economy.access$17(Economy.this,
- player.getName())) + Economy.INFO + ".");
- } else if (renameFee > 0.0D) {
- Economy.access$5(player, Economy.INFO + "You will be charged " +
- Economy.MONEY + Economy.this.format(renameFee) + Economy.INFO +
- " the next time you rename this area.");
- }
- area.areaName = newName.toString();
- return;
- }
- }
- Economy.access$5(player, Economy.ERROR + "Error - could not find area id " +
- areaId + ".");
- }
- private final void listAreas(Player player, String[] split)
- {
- if (!player.canUseCommand("/area"))
- return;
- Economy.Condition displayCondition;
- Economy.Condition displayCondition;
- if (split.length > 2) {
- if (split[2].equals("?")) {
- Economy.access$5(player, Economy.COMMAND +
- "Usage: /area list [playerName] [page]");
- return;
- }
- displayCondition = new Economy.Condition(Economy.this, split, player)
- {
- boolean isValid(Economy.Area area) {
- if (!area.owner.equalsIgnoreCase(this.val$split[2])) {
- return false;
- }
- return (!(area instanceof Economy.PersonalArea)) ||
- (this.val$player.isAdmin()) ||
- (this.val$player.getName().equalsIgnoreCase(
- area.owner));
- }
- };
- }
- else
- {
- displayCondition = new Economy.Condition(Economy.this, player)
- {
- boolean isValid(Economy.Area area) {
- if ((area instanceof Economy.PersonalArea)) {
- return area.owner
- .equalsIgnoreCase(this.val$player.getName());
- }
- return true;
- }
- };
- }
- if ((Economy.this.tradingAreas.isEmpty()) &&
- (Economy.this.personalAreas.isEmpty()) &&
- (Economy.this.bankingAreas.isEmpty())) {
- Economy.access$5(player, Economy.INFO + "No areas defined.");
- return;
- }
- ArrayList validAreas = new ArrayList();
- for (Economy.Area area : Economy.this.allAreas()) {
- if (displayCondition.isValid(area)) {
- validAreas.add(area);
- }
- }
- if (validAreas.size() == 0) {
- if (player.getName().equalsIgnoreCase(split[2]))
- Economy.access$5(player, Economy.INFO +
- "You don't currently own any areas.");
- else {
- Economy.access$5(player, (Economy.access$12(split[2]) ? Economy.ONLINE : Economy.OFFLINE) +
- split[2].toLowerCase() + Economy.INFO +
- " doesn't currently own any areas.");
- }
- return;
- }
- if (split.length > 2) {
- Economy.access$5(player, (Economy.access$12(split[2]) ? Economy.ONLINE : Economy.OFFLINE) +
- split[2].toLowerCase() + "'s" + Economy.INFO + " areas:");
- }
- for (Economy.Area area : validAreas) {
- StringBuilder message = new StringBuilder();
- String areaColor = Economy.access$29(area);
- message.append(areaColor);
- message.append(area.areaName);
- message.append(" [");
- message.append(Economy.this.format(area.distanceTo(player)));
- message.append(' ');
- message.append(area.directionFrom(player));
- message.append("]");
- if ((area.owner.equalsIgnoreCase(player.getName())) ||
- (player.isAdmin())) {
- message.append(" (");
- message.append(area.areaId);
- message.append(", ");
- message.append(Economy.MONEY);
- message.append(Economy.this.format(area.price()));
- message.append(areaColor);
- message.append(")");
- }
- Economy.access$5(player, message.toString());
- }
- }
- private final void addArea(Player player, String[] split)
- {
- String name = player.getName().toLowerCase();
- if (!player.canUseCommand("/area")) {
- return;
- }
- if (split.length < 3) {
- Economy.access$5(player, Economy.COMMAND +
- "Usage: /area add ['trade'|'personal'|'bank']");
- return;
- }
- if (Economy.this.numberOfAreas(player) >= Economy.MAX_AREAS) {
- Economy.access$5(player, Economy.ERROR + "Error - you cannot own more than " +
- Economy.MAX_AREAS + " areas.");
- return;
- }
- if ((!split[2].equalsIgnoreCase("trade")) &&
- (!split[2].equalsIgnoreCase("personal")) &&
- (!split[2].equalsIgnoreCase("bank"))) {
- Economy.access$5(player, Economy.COMMAND +
- "Usage: /area add ['trade'|'personal'|'bank']");
- return;
- }
- if (Economy.this.pendingTradeAreas.containsKey(name)) {
- Economy.this.pendingTradeAreas.remove(name);
- if (split[2].equalsIgnoreCase("trade")) {
- Economy.access$5(player, Economy.INFO +
- "No longer defining trading areas.");
- return;
- }if (split[2].equalsIgnoreCase("personal")) {
- Economy.access$5(player, Economy.INFO + "Now defining personal areas.");
- Economy.this.pendingPersonalAreas.put(name,
- new ArrayList());
- } else if (split[2].equalsIgnoreCase("bank")) {
- Economy.access$5(player, Economy.INFO + "Now defining banking areas.");
- Economy.this.pendingBankAreas.put(name,
- new ArrayList());
- }
- } else if (Economy.this.pendingPersonalAreas.containsKey(name)) {
- Economy.this.pendingPersonalAreas.remove(name);
- if (split[2].equalsIgnoreCase("trade")) {
- Economy.access$5(player, Economy.INFO + "Now defining trading areas.");
- Economy.this.pendingTradeAreas.put(name,
- new ArrayList()); } else {
- if (split[2].equalsIgnoreCase("personal")) {
- Economy.access$5(player, Economy.INFO +
- "No longer defining personal areas.");
- return;
- }if (split[2].equalsIgnoreCase("bank")) {
- Economy.access$5(player, Economy.INFO + "Now defining banking areas.");
- Economy.this.pendingBankAreas.put(name,
- new ArrayList());
- }
- }
- } else if (Economy.this.pendingBankAreas.containsKey(name)) {
- Economy.this.pendingBankAreas.remove(name);
- if (split[2].equalsIgnoreCase("trade")) {
- Economy.access$5(player, Economy.INFO + "Now defining trading areas.");
- Economy.this.pendingTradeAreas.put(name,
- new ArrayList());
- } else if (split[2].equalsIgnoreCase("personal")) {
- Economy.access$5(player, Economy.INFO + "Now defining personal areas.");
- Economy.this.pendingPersonalAreas.put(name,
- new ArrayList());
- } else if (split[2].equalsIgnoreCase("bank")) {
- Economy.access$5(player, Economy.INFO +
- "No longer defining banking areas.");
- return;
- }
- }
- else if (split[2].equalsIgnoreCase("trade")) {
- Economy.this.pendingTradeAreas.put(name,
- new ArrayList());
- Economy.access$5(player, Economy.INFO + "Now defining trading areas.");
- } else if (split[2].equalsIgnoreCase("personal")) {
- Economy.this.pendingPersonalAreas.put(name,
- new ArrayList());
- Economy.access$5(player, Economy.INFO + "Now defining personal areas.");
- } else if (split[2].equalsIgnoreCase("bank")) {
- Economy.this.pendingBankAreas.put(name,
- new ArrayList());
- Economy.access$5(player, Economy.INFO + "Now defining banking areas.");
- }
- Economy.access$5(
- player,
- Economy.INFO +
- "Right click one corner of the area with nothing in your hands.");
- }
- private void balance(Player player, String[] split)
- {
- if (!player.canUseCommand("/money")) {
- return;
- }
- if ((split.length > 2) && (player.isAdmin())) {
- String other = split[2].toLowerCase();
- if (other.equals("public"))
- Economy.access$5(player, Economy.INFO + "The public fund is at " + Economy.MONEY +
- Economy.this.format(Economy.this.publicFund) + Economy.INFO + ".");
- else if (!Economy.this.balances.containsKey(other))
- Economy.access$5(player, Economy.ERROR + "Error - could not find " +
- other + ".");
- else {
- Economy.access$5(player, (Economy.access$12(other) ? Economy.ONLINE : Economy.OFFLINE) +
- other + "'s" + Economy.INFO + " current balance is " +
- Economy.MONEY + Economy.this.format(Economy.access$17(Economy.this, other)) +
- Economy.INFO + ".");
- }
- return;
- }
- Economy.access$5(player, Economy.INFO + "Your current balance is " + Economy.MONEY +
- Economy.this.format(Economy.access$17(Economy.this, player.getName())) + Economy.INFO +
- ".");
- }
- private void pay(Player player, String[] split)
- {
- if (!player.canUseCommand("/money")) {
- return;
- }
- if (split.length < 4) {
- Economy.access$5(player, Economy.COMMAND +
- "Usage: /money pay <player> <amount> [message]");
- return;
- }
- String payTo = split[2].toLowerCase();
- if ((!Economy.access$12(payTo)) && (!Economy.this.balances.containsKey(payTo))) {
- Economy.access$5(player, Economy.INFO + "Could not find " + payTo + ".");
- return;
- }
- try
- {
- double paymentAmount = Double.parseDouble(split[3]);
- paymentAmount = Math.round(paymentAmount * 100.0D) / 100.0D;
- } catch (Exception e) {
- Economy.access$5(player, Economy.ERROR +
- "Error - must specify a valid number.");
- return;
- }
- double paymentAmount;
- if (paymentAmount <= 0.0D) {
- Economy.access$5(player, Economy.ERROR +
- "Error - payment amount must positive.");
- return;
- }
- double balance = Economy.this.getBalance(player.getName());
- if (paymentAmount > balance) {
- Economy.access$5(player, Economy.ERROR + "Error - insufficient funds.");
- Economy.access$5(player, Economy.INFO + "Your current balance is " + Economy.MONEY +
- Economy.this.format(balance) + Economy.INFO + ".");
- return;
- }
- StringBuilder message = null;
- if (split.length > 4) {
- message = new StringBuilder();
- for (int index = 4; index < split.length; index++) {
- message.append(split[index]);
- if (index < split.length - 1) {
- message.append(' ');
- }
- }
- }
- Economy.this.addToBalance(player.getName(), -paymentAmount);
- Economy.this.addToBalance(payTo, paymentAmount);
- Economy.access$5(player, Economy.INFO + "Payment sent.");
- Player otherPlayer = etc.getServer().getPlayer(payTo);
- if (otherPlayer != null) {
- Economy.access$5(otherPlayer, Economy.ONLINE + player.getName() + Economy.INFO +
- " has sent you " + Economy.MONEY + Economy.this.format(paymentAmount) +
- Economy.INFO + ".");
- Economy.access$5(otherPlayer, Economy.INFO +
- "Your balance has increased to " + Economy.MONEY +
- Economy.this.format(Economy.access$17(Economy.this, payTo)) + Economy.INFO + ".");
- if (message != null)
- Economy.access$5(otherPlayer, Economy.ONLINE + player.getName() + Economy.INFO +
- " says " + message.toString());
- }
- }
- private void offer(Player player, String[] split)
- {
- if (!player.canUseCommand("/offer")) {
- return;
- }
- if (split.length < 5) {
- Economy.access$5(
- player,
- Economy.COMMAND +
- "Usage: /offer add <itemName> <amount|'all'> <unitPrice>");
- return;
- }
- if (!Economy.this.canTrade(player)) {
- Economy.access$5(
- player,
- Economy.ERROR +
- "Error - cannot trade here. Please locate a trading area.");
- if (player.canUseCommand("/area")) {
- Economy.access$5(player, Economy.INFO +
- "Try using the \"/area list\" command.");
- }
- return;
- }
- if (((ArrayList)Economy.this.sellingOffers.get(player.getName().toLowerCase()))
- .size() >= Economy.MAX_OFFERS) {
- Economy.access$5(player, Economy.ERROR + "Error - you can't have more than " +
- Economy.INFO + Economy.MAX_OFFERS + Economy.ERROR + " offers at once.");
- return;
- }
- int id = Economy.access$0(split[2]);
- if (id == -1) {
- Economy.access$5(player, Economy.ERROR + "Error - could not find id for " +
- split[2] + ".");
- return;
- }
- boolean offerAll = false;
- int amount = 0;
- try {
- amount = Integer.parseInt(split[3]);
- } catch (Exception e) {
- if (!split[3].equalsIgnoreCase("all")) {
- Economy.access$5(player, Economy.ERROR +
- "Error - amount must be a valid number.");
- return;
- }
- offerAll = true;
- }
- Inventory inventory = player.getInventory();
- hn[] inventoryArray = inventory.getArray();
- int totalAmount = 0;
- for (int index = 0; index < inventoryArray.length; index++) {
- if (inventoryArray[index] == null) {
- continue;
- }
- if (inventoryArray[index].c == id) {
- totalAmount += inventoryArray[index].a;
- }
- }
- if (offerAll) {
- amount = totalAmount;
- }
- if (amount <= 0) {
- if (offerAll) {
- Economy.access$5(player, Economy.ERROR + "Error - you do not have any " +
- split[2].toLowerCase() + ".");
- return;
- }
- Economy.access$5(player, Economy.ERROR + "Error - amount must be positive.");
- return;
- }
- if (totalAmount < amount) {
- Economy.access$5(player, Economy.ERROR + "Error - you do not have enough " +
- split[2].toLowerCase() + ".");
- return;
- }
- try
- {
- double unitPrice = Double.parseDouble(split[4]);
- unitPrice = Math.round(unitPrice * 100.0D) / 100.0D;
- } catch (Exception e) {
- Economy.access$5(player, Economy.ERROR +
- "Error - unit price must be a valid number.");
- return;
- }
- double unitPrice;
- if (unitPrice <= 0.0D) {
- Economy.access$5(player, Economy.ERROR +
- "Error - unit price must be positive.");
- return;
- }
- int tempAmount = amount;
- for (int index = 0; (index < inventoryArray.length) && (tempAmount > 0); index++) {
- if (inventoryArray[index] == null) {
- continue;
- }
- if (inventoryArray[index].c != id) {
- continue;
- }
- if (inventoryArray[index].a == 64) {
- continue;
- }
- int amountToRemove = Math.min(inventoryArray[index].a,
- tempAmount);
- tempAmount -= amountToRemove;
- inventoryArray[index].a -= amountToRemove;
- if (inventoryArray[index].a <= 0) {
- inventoryArray[index] = null;
- }
- }
- for (int index = 0; (index < inventoryArray.length) && (tempAmount > 0); index++) {
- if (inventoryArray[index] == null) {
- continue;
- }
- if (inventoryArray[index].c != id) {
- continue;
- }
- int amountToRemove = Math.min(inventoryArray[index].a,
- tempAmount);
- tempAmount -= amountToRemove;
- inventoryArray[index].a -= amountToRemove;
- if (inventoryArray[index].a <= 0) {
- inventoryArray[index] = null;
- }
- }
- player.getInventory().updateInventory();
- ArrayList currentOffers =
- (ArrayList)Economy.this.sellingOffers
- .get(player.getName().toLowerCase());
- if (currentOffers != null) {
- for (Economy.Offer offer : currentOffers) {
- if ((Economy.Offer.access$0(offer) == id) && (Economy.Offer.access$1(offer) == unitPrice))
- {
- Economy.Offer tmp903_901 = offer; Economy.Offer.access$3(tmp903_901, Economy.Offer.access$2(tmp903_901) + amount);
- Economy.access$5(player, Economy.INFO +
- "Your offer has been combined with offer id " +
- Economy.Offer.access$4(offer) + ".");
- return;
- }
- }
- }
- Economy.Offer offer = new Economy.Offer(Economy.this, player.getName().toLowerCase(), id, amount,
- unitPrice);
- Economy.this.addOffer(player.getName().toLowerCase(), offer);
- Economy.access$5(player, Economy.INFO +
- "Your offer has been placed. Your offer id is " +
- Economy.Offer.access$4(offer) + ".");
- HashSet listeners = (HashSet)Economy.this.offerListeners.get(Integer.valueOf(id));
- if (listeners == null) {
- return;
- }
- for (String playerName : listeners) {
- if (playerName.equalsIgnoreCase(player.getName())) {
- continue;
- }
- Player listener = etc.getServer().getPlayer(playerName);
- if (listener == null) {
- continue;
- }
- Economy.access$5(listener, Economy.INFO + player.getName() +
- " has put up an offer for " + amount + " " +
- Economy.access$26(id) + ".");
- }
- }
- private void buy(Player player, String[] split)
- {
- if (!player.canUseCommand("/buy")) {
- return;
- }
- if (split.length < 4) {
- Economy.access$5(player, Economy.COMMAND +
- "Usage: /buy <itemName> <amount> <unitPrice>");
- return;
- }
- if (!Economy.this.canTrade(player)) {
- Economy.access$5(
- player,
- Economy.ERROR +
- "Error - cannot trade here. Please locate a trading area.");
- if (player.canUseCommand("/area")) {
- Economy.access$5(player, Economy.INFO +
- "Try using the \"/area list\" command.");
- }
- return;
- }
- int id = Economy.access$0(split[1]);
- if (id == -1) {
- Economy.access$5(player, Economy.ERROR + "Error - could not find id for " +
- split[1] + ".");
- return;
- }
- try
- {
- buyingAmount = Integer.parseInt(split[2]);
- }
- catch (Exception e)
- {
- int buyingAmount;
- Economy.access$5(player, Economy.ERROR +
- "Error - amount must be a valid number.");
- return;
- }
- int buyingAmount;
- if (buyingAmount <= 0) {
- Economy.access$5(player, Economy.ERROR +
- "Error - amount must be a positive number.");
- return;
- }
- Inventory inventory = player.getInventory();
- hn[] array = inventory.getArray();
- int canHold = 0;
- for (int index = 0; index < array.length; index++) {
- if (array[index] == null) {
- canHold += 64;
- }
- else {
- if (array[index].c != id) {
- continue;
- }
- canHold += 64 - array[index].a;
- }
- }
- if (buyingAmount > canHold) {
- if (canHold == 0) {
- Economy.access$5(player, Economy.ERROR + "Error - you can't hold any " +
- split[1].toLowerCase() + ".");
- } else {
- Economy.access$5(player, Economy.ERROR + "Error - you can't hold " +
- buyingAmount + " " + split[1].toLowerCase() + ".");
- Economy.access$5(player, Economy.ERROR + "You can only hold " + canHold +
- " " + split[1].toLowerCase() + ".");
- }
- return;
- }
- try
- {
- double unitPrice = Double.parseDouble(split[3]);
- unitPrice = Math.round(unitPrice * 100.0D) / 100.0D;
- } catch (Exception e) {
- Economy.access$5(player, Economy.ERROR +
- "Error - unit price must be a valid number.");
- return;
- }
- double unitPrice;
- if (unitPrice <= 0.0D) {
- Economy.access$5(player, Economy.ERROR +
- "Error - unit price must be a positive number.");
- return;
- }
- double totalMoney = buyingAmount * unitPrice;
- if (Economy.this.getBalance(player.getName()) < unitPrice) {
- Economy.access$5(player, Economy.ERROR + "Error - insufficient funds.");
- Economy.access$5(player, Economy.INFO + "Your current balance is " + Economy.MONEY +
- Economy.this.format(Economy.access$17(Economy.this, player.getName())) +
- Economy.INFO + ".");
- return;
- }
- if (Economy.this.getBalance(player.getName()) < totalMoney) {
- Economy.access$5(player, Economy.ERROR + "Warning - can't buy " +
- buyingAmount + " " + split[1].toLowerCase() + ".");
- buyingAmount = (int)(Economy.this.getBalance(player.getName()) / unitPrice);
- Economy.access$5(player, Economy.ERROR + "You will only buy up to " +
- buyingAmount + " " + split[1].toLowerCase() + ".");
- }
- while (buyingAmount > 0) {
- Economy.Offer bestOffer = null;
- int mostItems = -1;
- double bestPrice = 1.7976931348623157E+308D;
- Iterator iterator = Economy.this.offerIterator();
- while (iterator.hasNext()) {
- Economy.Offer offer = (Economy.Offer)iterator.next();
- if ((Economy.Offer.access$0(offer) != id) ||
- (Economy.Offer.access$5(offer).equalsIgnoreCase(player.getName())) ||
- (Economy.Offer.access$1(offer) > unitPrice))
- {
- continue;
- }
- int canBuy = Math.min(
- (int)(totalMoney / Economy.Offer.access$1(offer)),
- buyingAmount);
- if (canBuy <= 0) {
- continue;
- }
- double price = canBuy * Economy.Offer.access$1(offer);
- if (canBuy > mostItems) {
- mostItems = canBuy;
- bestOffer = offer;
- bestPrice = price;
- } else if ((canBuy == mostItems) && (price < bestPrice)) {
- bestOffer = offer;
- bestPrice = price;
- }
- }
- if (bestOffer == null) {
- Economy.access$5(player, Economy.INFO +
- "Could not find a player selling " + Economy.access$26(id) +
- ".");
- Economy.access$5(player, Economy.INFO + "Could not buy " + buyingAmount +
- " " + Economy.access$26(id) + ".");
- return;
- }
- int sellingAmount = Math.min(mostItems, Economy.Offer.access$2(bestOffer));
- double sellingPrice = sellingAmount * Economy.Offer.access$1(bestOffer);
- Economy.this.addToBalance(player.getName(), -sellingPrice);
- totalMoney -= sellingPrice;
- Economy.this.addToBalance(Economy.Offer.access$5(bestOffer), sellingPrice);
- player.getInventory().giveItem(id, sellingAmount);
- player.getInventory().updateInventory();
- Economy.access$5(player, Economy.INFO + "You bought " + sellingAmount + " " +
- Economy.access$26(id) + " from " + (
- Economy.access$12(Economy.Offer.access$5(bestOffer)) ? Economy.ONLINE : Economy.OFFLINE) +
- Economy.Offer.access$5(bestOffer) + Economy.INFO + " for " + Economy.MONEY +
- Economy.this.format(sellingPrice) + Economy.INFO + ".");
- Player seller = etc.getServer().getPlayer(Economy.Offer.access$5(bestOffer));
- if (seller != null) {
- Economy.access$5(seller, Economy.ONLINE + player.getName() + Economy.INFO +
- " bought " + sellingAmount + " " + Economy.access$26(id) +
- " for " + Economy.MONEY + Economy.this.format(sellingPrice) + ".");
- Economy.access$5(seller, Economy.INFO + "Your balance has increased to " +
- Economy.MONEY +
- Economy.this.format(Economy.access$17(Economy.this, Economy.Offer.access$5(bestOffer))) +
- Economy.INFO + ".");
- }
- buyingAmount -= sellingAmount;
- Economy.Offer tmp1449_1447 = bestOffer; Economy.Offer.access$3(tmp1449_1447, Economy.Offer.access$2(tmp1449_1447) - sellingAmount);
- if (Economy.Offer.access$2(bestOffer) <= 0) {
- Economy.this.removeOffer(bestOffer);
- }
- HashSet listeners =
- (HashSet)Economy.this.offerListeners
- .get(Integer.valueOf(Economy.Offer.access$0(bestOffer)));
- if (listeners == null) {
- continue;
- }
- for (String playerName : listeners) {
- if ((playerName.equalsIgnoreCase(player.getName())) ||
- (playerName.equalsIgnoreCase(Economy.Offer.access$5(bestOffer)))) {
- continue;
- }
- Player listener = etc.getServer().getPlayer(playerName);
- if (listener == null) {
- continue;
- }
- if (Economy.Offer.access$2(bestOffer) <= 0)
- Economy.access$5(listener,
- (Economy.access$12(Economy.Offer.access$5(bestOffer)) ? Economy.ONLINE : Economy.OFFLINE) +
- Economy.Offer.access$5(bestOffer) + "'s" + Economy.INFO +
- " offer for " + sellingAmount + " " +
- Economy.access$26(Economy.Offer.access$0(bestOffer)) +
- " has been bought.");
- else {
- Economy.access$5(listener,
- (Economy.access$12(Economy.Offer.access$5(bestOffer)) ? Economy.ONLINE : Economy.OFFLINE) +
- Economy.Offer.access$5(bestOffer) + "'s" + Economy.INFO +
- " offer for " + (
- sellingAmount + Economy.Offer.access$2(bestOffer)) +
- " " + Economy.access$26(Economy.Offer.access$0(bestOffer)) +
- " has " + Economy.Offer.access$2(bestOffer) +
- " remaining.");
- }
- }
- }
- Economy.access$5(player, Economy.INFO + "Your balance has decreased to " + Economy.MONEY +
- Economy.this.format(Economy.access$17(Economy.this, player.getName())) + Economy.INFO +
- ".");
- }
- private void listOffers(Player player, String[] split)
- {
- if (!player.canUseCommand("/offer")) {
- return;
- }
- if (!Economy.this.hasOffers()) {
- Economy.access$5(player, Economy.INFO + "No current offers.");
- if (player.canUseCommand("/offer")) {
- Economy.access$5(
- player,
- Economy.INFO +
- "Try selling things with the \"/offer add\" command.");
- }
- return;
- }
- Economy.Condition displayCondition;
- Economy.Condition displayCondition;
- if (split.length > 2) {
- if (split[2].equals("?")) {
- Economy.access$5(player, Economy.COMMAND +
- "Usage: /offer list [playerName]");
- return;
- }
- ArrayList offers =
- (ArrayList)Economy.this.sellingOffers
- .get(split[2].toLowerCase());
- if ((offers == null) || (offers.size() == 0)) {
- Economy.access$5(player, (Economy.access$12(split[2]) ? Economy.ONLINE : Economy.OFFLINE) +
- split[2].toLowerCase() + Economy.INFO +
- " currently has no offers.");
- return;
- }
- displayCondition = new Economy.Condition(Economy.this, split)
- {
- boolean isValid(Economy.Offer offer) {
- return Economy.Offer.access$5(offer).equalsIgnoreCase(this.val$split[2]);
- } } ;
- } else {
- displayCondition = new Economy.Condition(Economy.this)
- {
- boolean isValid(Economy.Offer offer) {
- return true;
- }
- };
- }
- Economy.access$5(player, Economy.INFO + "Current offers: ");
- Iterator playerOfferIterator = Economy.this.sellingOffers
- .entrySet().iterator();
- while (playerOfferIterator.hasNext()) {
- Map.Entry currentPlayerOffers =
- (Map.Entry)playerOfferIterator
- .next();
- String sellerName = (String)currentPlayerOffers.getKey();
- ArrayList offers = (ArrayList)currentPlayerOffers.getValue();
- if (offers.size() == 0)
- {
- continue;
- }
- StringBuilder condensedOffers = new StringBuilder();
- condensedOffers.append(Economy.OFFER_COLOR);
- Iterator offerIterator = offers.iterator();
- boolean hasOffers = false;
- while (offerIterator.hasNext()) {
- Economy.Offer offer = (Economy.Offer)offerIterator.next();
- if (!displayCondition.isValid(offer)) {
- continue;
- }
- hasOffers = true;
- condensedOffers.append(offer.toString());
- if ((player.getName().equalsIgnoreCase(Economy.Offer.access$5(offer))) ||
- (player.isAdmin())) {
- condensedOffers.append("[");
- condensedOffers.append(Economy.Offer.access$4(offer));
- condensedOffers.append("]");
- }
- if (offerIterator.hasNext()) {
- condensedOffers.append(" ");
- }
- }
- if (hasOffers) {
- StringBuilder playerName = new StringBuilder();
- playerName.append(Economy.access$12(sellerName) ? Economy.ONLINE : Economy.OFFLINE);
- playerName.append(sellerName);
- Player seller = etc.getServer().getPlayer(sellerName);
- if (seller != null) {
- Economy.Area sellerArea = Economy.this.getArea(seller);
- if ((sellerArea != null) &&
- ((sellerArea instanceof Economy.TradeArea)) &&
- (!sellerArea.areaName.equals(""))) {
- playerName.append(Economy.TRADE_AREA_COLOR);
- playerName.append(" (");
- playerName.append(sellerArea.areaName);
- playerName.append(")");
- }
- }
- playerName.append(Economy.OFFER_COLOR);
- playerName.append(": ");
- Economy.access$5(player, playerName.toString() +
- condensedOffers.toString());
- }
- }
- }
- private void removeOffer(Player player, String[] split)
- {
- if (!player.canUseCommand("/offer")) {
- return;
- }
- if (split.length < 3) {
- Economy.access$5(player, Economy.COMMAND +
- "Usage: /offer remove [offerId|'all']");
- return;
- }
- int offerId = -1;
- boolean removeAll = false;
- try {
- offerId = Integer.parseInt(split[2]);
- } catch (Exception e) {
- if (!split[2].equalsIgnoreCase("all")) {
- Economy.access$5(player, Economy.ERROR +
- "Error - offer id must be a valid number.");
- return;
- }
- removeAll = true;
- }
- ArrayList currentOffers =
- (ArrayList)Economy.this.sellingOffers
- .get(player.getName().toLowerCase());
- if ((currentOffers == null) || (currentOffers.size() == 0)) {
- Economy.access$5(player, Economy.ERROR +
- "Error - you currently have no offers.");
- return;
- }
- Iterator offerIterator = currentOffers.iterator();
- while (offerIterator.hasNext()) {
- Economy.Offer offer = (Economy.Offer)offerIterator.next();
- if ((Economy.Offer.access$4(offer) == offerId) || (removeAll)) {
- int remaining = Economy.this.givePlayer(player,
- Economy.Offer.access$0(offer), Economy.Offer.access$2(offer));
- if (remaining != 0) {
- Economy.access$5(player, Economy.ERROR +
- "Error - please make room in your inventory.");
- Economy.access$5(player, Economy.ERROR +
- "Could not remove all of offer id " +
- Economy.Offer.access$4(offer));
- notifyOfRemove(offer, remaining);
- Economy.Offer.access$3(offer, remaining);
- return;
- }
- offerIterator.remove();
- Economy.this.allOffers.remove(offer);
- if (!removeAll) {
- Economy.access$5(player, Economy.INFO +
- "Offer successfully removed.");
- return;
- }
- notifyOfRemove(offer, 0);
- }
- }
- if (removeAll) {
- Economy.access$5(player, Economy.INFO + "All offers removed.");
- return;
- }
- Economy.access$5(player, Economy.ERROR + "Error - could not find offer id " +
- offerId);
- }
- private final void notifyOfRemove(Economy.Offer offer, int remaining)
- {
- HashSet listeners =
- (HashSet)Economy.this.offerListeners
- .get(Integer.valueOf(Economy.Offer.access$0(offer)));
- if (listeners == null) {
- return;
- }
- for (String playerName : listeners) {
- if (playerName.equalsIgnoreCase(Economy.Offer.access$5(offer))) {
- continue;
- }
- Player listener = etc.getServer().getPlayer(playerName);
- if (listener == null) {
- continue;
- }
- if (remaining <= 0)
- Economy.access$5(listener, (Economy.access$12(Economy.Offer.access$5(offer)) ? Economy.ONLINE :
- Economy.OFFLINE) +
- Economy.Offer.access$5(offer) +
- "'s" +
- Economy.INFO +
- " offer for " +
- Economy.Offer.access$2(offer) +
- " " +
- Economy.access$26(Economy.Offer.access$0(offer)) +
- " has been removed.");
- else
- Economy.access$5(listener, (Economy.access$12(Economy.Offer.access$5(offer)) ? Economy.ONLINE :
- Economy.OFFLINE) +
- Economy.Offer.access$5(offer) +
- "'s" +
- Economy.INFO +
- " offer for " +
- Economy.Offer.access$2(offer) +
- " " +
- Economy.access$26(Economy.Offer.access$0(offer)) +
- " has " + remaining + " remaining.");
- }
- }
- }
- private final class Offer
- implements Serializable
- {
- private static final long serialVersionUID = 1L;
- private String player;
- private final int itemId;
- private final double unitPrice;
- private int amount;
- private final int offerId;
- public Offer(String player, int id, int amount, double unitPrice)
- {
- this.player = player;
- this.itemId = id;
- this.amount = amount;
- this.unitPrice = unitPrice;
- this.offerId = (Economy.offerCount++);
- if (Economy.offerCount < 0)
- Economy.logger.log(Level.WARNING,
- "Offer id count has overflowed.");
- }
- public boolean equals(Object other)
- {
- if (!(other instanceof Offer)) {
- return false;
- }
- Offer otherOffer = (Offer)other;
- return this.offerId == otherOffer.offerId;
- }
- public String toString()
- {
- StringBuilder result = new StringBuilder();
- result.append("(");
- result.append(this.amount);
- result.append(Economy.access$26(this.itemId));
- result.append(",");
- result.append(Economy.MONEY);
- result.append(Economy.this.format(this.unitPrice));
- result.append(Economy.OFFER_COLOR);
- result.append(")");
- return result.toString();
- }
- }
- private class PersonalArea extends Economy.Area
- {
- private static final long serialVersionUID = 1175775527803459405L;
- public PersonalArea(double minX, double maxX, double minY, double maxY, double minZ, double maxZ, String owner)
- {
- super(minX, maxX, minY, maxY, minZ, maxZ, owner);
- }
- public double price()
- {
- return Economy.PERSONAL_AREA_COST * super.price();
- }
- }
- private class TradeArea extends Economy.Area
- {
- private static final long serialVersionUID = 7906766924747483195L;
- public TradeArea(double minX, double maxX, double minY, double maxY, double minZ, double maxZ, String owner)
- {
- super(minX, maxX, minY, maxY, minZ, maxZ, owner);
- }
- public double price()
- {
- return Economy.TRADE_AREA_COST * super.price();
- }
- }
- }
- /* Location: C:\Users\Juntalis\Downloads\Economy.jar
- * Qualified Name: Economy
- * JD-Core Version: 0.6.0
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement