mirror of https://github.com/MilkBowl/Vault.git
86 lines
2.4 KiB
Java
86 lines
2.4 KiB
Java
/**
|
|
* Copyright (C) 2011 Morgan Humes <morgan@lanaddict.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*
|
|
*/
|
|
|
|
package net.milkbowl.vault.economy;
|
|
|
|
public class EconomyResponse {
|
|
|
|
/**
|
|
* Enum for types of Responses indicating the status of a method call.
|
|
*/
|
|
public static enum ResponseType {
|
|
SUCCESS(1),
|
|
FAILURE(2),
|
|
NOT_IMPLEMENTED(3);
|
|
|
|
private int id;
|
|
ResponseType(int id) {
|
|
this.id = id;
|
|
}
|
|
|
|
int getId() {
|
|
return id;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Amount modified by calling method
|
|
*/
|
|
public final double amount;
|
|
/**
|
|
* New balance of account
|
|
*/
|
|
public final double balance;
|
|
/**
|
|
* Success or failure of call.
|
|
* Using Enum of ResponseType to determine valid outcomes
|
|
*/
|
|
public final ResponseType type;
|
|
/**
|
|
* Error message if the variable 'type' is ResponseType.FAILURE
|
|
*/
|
|
public final String errorMessage;
|
|
|
|
/**
|
|
* Constructor for EconomyResponse
|
|
* @param amount Amount modified during operation
|
|
* @param balance New balance of account
|
|
* @param type Success or failure type of the operation
|
|
* @param errorMessage Error message if necessary (commonly null)
|
|
*/
|
|
public EconomyResponse(double amount, double balance, ResponseType type, String errorMessage) {
|
|
this.amount = amount;
|
|
this.balance = balance;
|
|
this.type = type;
|
|
this.errorMessage = errorMessage;
|
|
}
|
|
|
|
/**
|
|
* Checks if an operation was successful
|
|
* @return Value
|
|
*/
|
|
public boolean transactionSuccess() {
|
|
switch (type) {
|
|
case SUCCESS:
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
} |