Fixed Indents on all files using the reformat option and optimized imports
This commit is contained in:
@@ -23,418 +23,418 @@ import java.util.logging.Level;
|
||||
|
||||
public class Econ {
|
||||
|
||||
private static final DecimalFormat format = new DecimalFormat(TL.ECON_FORMAT.toString());
|
||||
private static Economy econ = null;
|
||||
private static final DecimalFormat format = new DecimalFormat(TL.ECON_FORMAT.toString());
|
||||
private static Economy econ = null;
|
||||
|
||||
public static void setup() {
|
||||
if (isSetup()) {
|
||||
return;
|
||||
}
|
||||
public static void setup() {
|
||||
if (isSetup()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String integrationFail = "Economy integration is " + (Conf.econEnabled ? "enabled, but" : "disabled, and") + " the plugin \"Vault\" ";
|
||||
String integrationFail = "Economy integration is " + (Conf.econEnabled ? "enabled, but" : "disabled, and") + " the plugin \"Vault\" ";
|
||||
|
||||
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
SavageFactions.plugin.log(integrationFail + "is not installed.");
|
||||
return;
|
||||
}
|
||||
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
SavageFactions.plugin.log(integrationFail + "is not installed.");
|
||||
return;
|
||||
}
|
||||
|
||||
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) {
|
||||
SavageFactions.plugin.log(integrationFail + "is not hooked into an economy plugin.");
|
||||
return;
|
||||
}
|
||||
econ = rsp.getProvider();
|
||||
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) {
|
||||
SavageFactions.plugin.log(integrationFail + "is not hooked into an economy plugin.");
|
||||
return;
|
||||
}
|
||||
econ = rsp.getProvider();
|
||||
|
||||
SavageFactions.plugin.log("Economy integration through Vault plugin successful.");
|
||||
SavageFactions.plugin.log("Economy integration through Vault plugin successful.");
|
||||
|
||||
if (!Conf.econEnabled) {
|
||||
SavageFactions.plugin.log("NOTE: Economy is disabled. You can enable it with the command: f config econEnabled true");
|
||||
}
|
||||
if (!Conf.econEnabled) {
|
||||
SavageFactions.plugin.log("NOTE: Economy is disabled. You can enable it with the command: f config econEnabled true");
|
||||
}
|
||||
|
||||
SavageFactions.plugin.cmdBase.cmdHelp.updateHelp();
|
||||
}
|
||||
SavageFactions.plugin.cmdBase.cmdHelp.updateHelp();
|
||||
}
|
||||
|
||||
public static boolean shouldBeUsed() {
|
||||
return Conf.econEnabled && econ != null && econ.isEnabled();
|
||||
}
|
||||
public static boolean shouldBeUsed() {
|
||||
return Conf.econEnabled && econ != null && econ.isEnabled();
|
||||
}
|
||||
|
||||
public static boolean isSetup() {
|
||||
return econ != null;
|
||||
}
|
||||
public static boolean isSetup() {
|
||||
return econ != null;
|
||||
}
|
||||
|
||||
public static void modifyUniverseMoney(double delta) {
|
||||
if (!shouldBeUsed()) {
|
||||
return;
|
||||
}
|
||||
public static void modifyUniverseMoney(double delta) {
|
||||
if (!shouldBeUsed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Conf.econUniverseAccount == null) {
|
||||
return;
|
||||
}
|
||||
if (Conf.econUniverseAccount.length() == 0) {
|
||||
return;
|
||||
}
|
||||
if (!econ.hasAccount(Conf.econUniverseAccount)) {
|
||||
return;
|
||||
}
|
||||
if (Conf.econUniverseAccount == null) {
|
||||
return;
|
||||
}
|
||||
if (Conf.econUniverseAccount.length() == 0) {
|
||||
return;
|
||||
}
|
||||
if (!econ.hasAccount(Conf.econUniverseAccount)) {
|
||||
return;
|
||||
}
|
||||
|
||||
modifyBalance(Conf.econUniverseAccount, delta);
|
||||
}
|
||||
modifyBalance(Conf.econUniverseAccount, delta);
|
||||
}
|
||||
|
||||
public static void sendBalanceInfo(FPlayer to, EconomyParticipator about) {
|
||||
if (!shouldBeUsed()) {
|
||||
SavageFactions.plugin.log(Level.WARNING, "Vault does not appear to be hooked into an economy plugin.");
|
||||
return;
|
||||
}
|
||||
to.msg("<a>%s's<i> balance is <h>%s<i>.", about.describeTo(to, true), Econ.moneyString(econ.getBalance(about.getAccountId())));
|
||||
}
|
||||
public static void sendBalanceInfo(FPlayer to, EconomyParticipator about) {
|
||||
if (!shouldBeUsed()) {
|
||||
SavageFactions.plugin.log(Level.WARNING, "Vault does not appear to be hooked into an economy plugin.");
|
||||
return;
|
||||
}
|
||||
to.msg("<a>%s's<i> balance is <h>%s<i>.", about.describeTo(to, true), Econ.moneyString(econ.getBalance(about.getAccountId())));
|
||||
}
|
||||
|
||||
public static boolean canIControllYou(EconomyParticipator i, EconomyParticipator you) {
|
||||
Faction fI = RelationUtil.getFaction(i);
|
||||
Faction fYou = RelationUtil.getFaction(you);
|
||||
public static boolean canIControllYou(EconomyParticipator i, EconomyParticipator you) {
|
||||
Faction fI = RelationUtil.getFaction(i);
|
||||
Faction fYou = RelationUtil.getFaction(you);
|
||||
|
||||
// This is a system invoker. Accept it.
|
||||
if (fI == null) {
|
||||
return true;
|
||||
}
|
||||
// This is a system invoker. Accept it.
|
||||
if (fI == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Bypassing players can do any kind of transaction
|
||||
if (i instanceof FPlayer && ((FPlayer) i).isAdminBypassing()) {
|
||||
return true;
|
||||
}
|
||||
// Bypassing players can do any kind of transaction
|
||||
if (i instanceof FPlayer && ((FPlayer) i).isAdminBypassing()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Players with the any withdraw can do.
|
||||
if (i instanceof FPlayer && Permission.MONEY_WITHDRAW_ANY.has(((FPlayer) i).getPlayer())) {
|
||||
return true;
|
||||
}
|
||||
// Players with the any withdraw can do.
|
||||
if (i instanceof FPlayer && Permission.MONEY_WITHDRAW_ANY.has(((FPlayer) i).getPlayer())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// You can deposit to anywhere you feel like. It's your loss if you can't withdraw it again.
|
||||
if (i == you) {
|
||||
return true;
|
||||
}
|
||||
// You can deposit to anywhere you feel like. It's your loss if you can't withdraw it again.
|
||||
if (i == you) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// A faction can always transfer away the money of it's members and its own money...
|
||||
// This will however probably never happen as a faction does not have free will.
|
||||
// Ohh by the way... Yes it could. For daily rent to the faction.
|
||||
if (i == fI && fI == fYou) {
|
||||
return true;
|
||||
}
|
||||
// A faction can always transfer away the money of it's members and its own money...
|
||||
// This will however probably never happen as a faction does not have free will.
|
||||
// Ohh by the way... Yes it could. For daily rent to the faction.
|
||||
if (i == fI && fI == fYou) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Factions can be controlled by members that are moderators... or any member if any member can withdraw.
|
||||
if (you instanceof Faction && fI == fYou && (Conf.bankMembersCanWithdraw || ((FPlayer) i).getRole().value >= Role.MODERATOR.value)) {
|
||||
return true;
|
||||
}
|
||||
// Factions can be controlled by members that are moderators... or any member if any member can withdraw.
|
||||
if (you instanceof Faction && fI == fYou && (Conf.bankMembersCanWithdraw || ((FPlayer) i).getRole().value >= Role.MODERATOR.value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Otherwise you may not!;,,;
|
||||
i.msg("<h>%s<i> lacks permission to control <h>%s's<i> money.", i.describeTo(i, true), you.describeTo(i));
|
||||
return false;
|
||||
}
|
||||
// Otherwise you may not!;,,;
|
||||
i.msg("<h>%s<i> lacks permission to control <h>%s's<i> money.", i.describeTo(i, true), you.describeTo(i));
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean transferMoney(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount) {
|
||||
return transferMoney(invoker, from, to, amount, true);
|
||||
}
|
||||
public static boolean transferMoney(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount) {
|
||||
return transferMoney(invoker, from, to, amount, true);
|
||||
}
|
||||
|
||||
public static boolean transferMoney(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount, boolean notify) {
|
||||
if (!shouldBeUsed()) {
|
||||
return false;
|
||||
}
|
||||
public static boolean transferMoney(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount, boolean notify) {
|
||||
if (!shouldBeUsed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The amount must be positive.
|
||||
// If the amount is negative we must flip and multiply amount with -1.
|
||||
if (amount < 0) {
|
||||
amount *= -1;
|
||||
EconomyParticipator temp = from;
|
||||
from = to;
|
||||
to = temp;
|
||||
}
|
||||
// The amount must be positive.
|
||||
// If the amount is negative we must flip and multiply amount with -1.
|
||||
if (amount < 0) {
|
||||
amount *= -1;
|
||||
EconomyParticipator temp = from;
|
||||
from = to;
|
||||
to = temp;
|
||||
}
|
||||
|
||||
// Check the rights
|
||||
if (!canIControllYou(invoker, from)) {
|
||||
return false;
|
||||
}
|
||||
// Check the rights
|
||||
if (!canIControllYou(invoker, from)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
OfflinePlayer fromAcc;
|
||||
OfflinePlayer toAcc;
|
||||
OfflinePlayer fromAcc;
|
||||
OfflinePlayer toAcc;
|
||||
|
||||
if (isUUID(from.getAccountId())) {
|
||||
fromAcc = Bukkit.getOfflinePlayer(UUID.fromString(from.getAccountId()));
|
||||
if (fromAcc.getName() == null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
fromAcc = Bukkit.getOfflinePlayer(from.getAccountId());
|
||||
}
|
||||
if (isUUID(from.getAccountId())) {
|
||||
fromAcc = Bukkit.getOfflinePlayer(UUID.fromString(from.getAccountId()));
|
||||
if (fromAcc.getName() == null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
fromAcc = Bukkit.getOfflinePlayer(from.getAccountId());
|
||||
}
|
||||
|
||||
if (isUUID(to.getAccountId())) {
|
||||
toAcc = Bukkit.getOfflinePlayer(UUID.fromString(to.getAccountId()));
|
||||
if (toAcc.getName() == null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
toAcc = Bukkit.getOfflinePlayer(to.getAccountId());
|
||||
}
|
||||
if (isUUID(to.getAccountId())) {
|
||||
toAcc = Bukkit.getOfflinePlayer(UUID.fromString(to.getAccountId()));
|
||||
if (toAcc.getName() == null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
toAcc = Bukkit.getOfflinePlayer(to.getAccountId());
|
||||
}
|
||||
|
||||
// Is there enough money for the transaction to happen?
|
||||
if (!econ.has(fromAcc, amount)) {
|
||||
// There was not enough money to pay
|
||||
if (invoker != null && notify) {
|
||||
invoker.msg("<h>%s<b> can't afford to transfer <h>%s<b> to %s<b>.", from.describeTo(invoker, true), moneyString(amount), to.describeTo(invoker));
|
||||
}
|
||||
// Is there enough money for the transaction to happen?
|
||||
if (!econ.has(fromAcc, amount)) {
|
||||
// There was not enough money to pay
|
||||
if (invoker != null && notify) {
|
||||
invoker.msg("<h>%s<b> can't afford to transfer <h>%s<b> to %s<b>.", from.describeTo(invoker, true), moneyString(amount), to.describeTo(invoker));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Transfer money
|
||||
EconomyResponse erw = econ.withdrawPlayer(fromAcc, amount);
|
||||
// Transfer money
|
||||
EconomyResponse erw = econ.withdrawPlayer(fromAcc, amount);
|
||||
|
||||
if (erw.transactionSuccess()) {
|
||||
EconomyResponse erd = econ.depositPlayer(toAcc, amount);
|
||||
if (erd.transactionSuccess()) {
|
||||
if (notify) {
|
||||
sendTransferInfo(invoker, from, to, amount);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// transaction failed, refund account
|
||||
econ.depositPlayer(fromAcc, amount);
|
||||
}
|
||||
}
|
||||
if (erw.transactionSuccess()) {
|
||||
EconomyResponse erd = econ.depositPlayer(toAcc, amount);
|
||||
if (erd.transactionSuccess()) {
|
||||
if (notify) {
|
||||
sendTransferInfo(invoker, from, to, amount);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// transaction failed, refund account
|
||||
econ.depositPlayer(fromAcc, amount);
|
||||
}
|
||||
}
|
||||
|
||||
// if we get here something with the transaction failed
|
||||
if (notify) {
|
||||
invoker.msg("Unable to transfer %s<b> to <h>%s<b> from <h>%s<b>.", moneyString(amount), to.describeTo(invoker), from.describeTo(invoker, true));
|
||||
}
|
||||
// if we get here something with the transaction failed
|
||||
if (notify) {
|
||||
invoker.msg("Unable to transfer %s<b> to <h>%s<b> from <h>%s<b>.", moneyString(amount), to.describeTo(invoker), from.describeTo(invoker, true));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Set<FPlayer> getFplayers(EconomyParticipator ep) {
|
||||
Set<FPlayer> fplayers = new HashSet<>();
|
||||
public static Set<FPlayer> getFplayers(EconomyParticipator ep) {
|
||||
Set<FPlayer> fplayers = new HashSet<>();
|
||||
|
||||
if (ep != null) {
|
||||
if (ep instanceof FPlayer) {
|
||||
fplayers.add((FPlayer) ep);
|
||||
} else if (ep instanceof Faction) {
|
||||
fplayers.addAll(((Faction) ep).getFPlayers());
|
||||
}
|
||||
}
|
||||
if (ep != null) {
|
||||
if (ep instanceof FPlayer) {
|
||||
fplayers.add((FPlayer) ep);
|
||||
} else if (ep instanceof Faction) {
|
||||
fplayers.addAll(((Faction) ep).getFPlayers());
|
||||
}
|
||||
}
|
||||
|
||||
return fplayers;
|
||||
}
|
||||
return fplayers;
|
||||
}
|
||||
|
||||
public static void sendTransferInfo(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount) {
|
||||
Set<FPlayer> recipients = new HashSet<>();
|
||||
recipients.addAll(getFplayers(invoker));
|
||||
recipients.addAll(getFplayers(from));
|
||||
recipients.addAll(getFplayers(to));
|
||||
public static void sendTransferInfo(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount) {
|
||||
Set<FPlayer> recipients = new HashSet<>();
|
||||
recipients.addAll(getFplayers(invoker));
|
||||
recipients.addAll(getFplayers(from));
|
||||
recipients.addAll(getFplayers(to));
|
||||
|
||||
if (invoker == null) {
|
||||
for (FPlayer recipient : recipients) {
|
||||
recipient.msg("<h>%s<i> was transferred from <h>%s<i> to <h>%s<i>.", moneyString(amount), from.describeTo(recipient), to.describeTo(recipient));
|
||||
}
|
||||
} else if (invoker == from) {
|
||||
for (FPlayer recipient : recipients) {
|
||||
recipient.msg("<h>%s<i> <h>gave %s<i> to <h>%s<i>.", from.describeTo(recipient, true), moneyString(amount), to.describeTo(recipient));
|
||||
}
|
||||
} else if (invoker == to) {
|
||||
for (FPlayer recipient : recipients) {
|
||||
recipient.msg("<h>%s<i> <h>took %s<i> from <h>%s<i>.", to.describeTo(recipient, true), moneyString(amount), from.describeTo(recipient));
|
||||
}
|
||||
} else {
|
||||
for (FPlayer recipient : recipients) {
|
||||
recipient.msg("<h>%s<i> transferred <h>%s<i> from <h>%s<i> to <h>%s<i>.", invoker.describeTo(recipient, true), moneyString(amount), from.describeTo(recipient), to.describeTo(recipient));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (invoker == null) {
|
||||
for (FPlayer recipient : recipients) {
|
||||
recipient.msg("<h>%s<i> was transferred from <h>%s<i> to <h>%s<i>.", moneyString(amount), from.describeTo(recipient), to.describeTo(recipient));
|
||||
}
|
||||
} else if (invoker == from) {
|
||||
for (FPlayer recipient : recipients) {
|
||||
recipient.msg("<h>%s<i> <h>gave %s<i> to <h>%s<i>.", from.describeTo(recipient, true), moneyString(amount), to.describeTo(recipient));
|
||||
}
|
||||
} else if (invoker == to) {
|
||||
for (FPlayer recipient : recipients) {
|
||||
recipient.msg("<h>%s<i> <h>took %s<i> from <h>%s<i>.", to.describeTo(recipient, true), moneyString(amount), from.describeTo(recipient));
|
||||
}
|
||||
} else {
|
||||
for (FPlayer recipient : recipients) {
|
||||
recipient.msg("<h>%s<i> transferred <h>%s<i> from <h>%s<i> to <h>%s<i>.", invoker.describeTo(recipient, true), moneyString(amount), from.describeTo(recipient), to.describeTo(recipient));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasAtLeast(EconomyParticipator ep, double delta, String toDoThis) {
|
||||
if (!shouldBeUsed()) {
|
||||
return true;
|
||||
}
|
||||
public static boolean hasAtLeast(EconomyParticipator ep, double delta, String toDoThis) {
|
||||
if (!shouldBeUsed()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// going the hard way round as econ.has refuses to work.
|
||||
boolean affordable = false;
|
||||
double currentBalance;
|
||||
// going the hard way round as econ.has refuses to work.
|
||||
boolean affordable = false;
|
||||
double currentBalance;
|
||||
|
||||
if (isUUID(ep.getAccountId())) {
|
||||
OfflinePlayer offline = Bukkit.getOfflinePlayer(UUID.fromString(ep.getAccountId()));
|
||||
if (offline.getName() != null) {
|
||||
currentBalance = econ.getBalance(Bukkit.getOfflinePlayer(UUID.fromString(ep.getAccountId())));
|
||||
} else {
|
||||
currentBalance = 0;
|
||||
}
|
||||
} else {
|
||||
currentBalance = econ.getBalance(ep.getAccountId());
|
||||
}
|
||||
if (isUUID(ep.getAccountId())) {
|
||||
OfflinePlayer offline = Bukkit.getOfflinePlayer(UUID.fromString(ep.getAccountId()));
|
||||
if (offline.getName() != null) {
|
||||
currentBalance = econ.getBalance(Bukkit.getOfflinePlayer(UUID.fromString(ep.getAccountId())));
|
||||
} else {
|
||||
currentBalance = 0;
|
||||
}
|
||||
} else {
|
||||
currentBalance = econ.getBalance(ep.getAccountId());
|
||||
}
|
||||
|
||||
if (currentBalance >= delta) {
|
||||
affordable = true;
|
||||
}
|
||||
if (currentBalance >= delta) {
|
||||
affordable = true;
|
||||
}
|
||||
|
||||
if (!affordable) {
|
||||
if (toDoThis != null && !toDoThis.isEmpty()) {
|
||||
ep.msg("<h>%s<i> can't afford <h>%s<i> %s.", ep.describeTo(ep, true), moneyString(delta), toDoThis);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (!affordable) {
|
||||
if (toDoThis != null && !toDoThis.isEmpty()) {
|
||||
ep.msg("<h>%s<i> can't afford <h>%s<i> %s.", ep.describeTo(ep, true), moneyString(delta), toDoThis);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean modifyMoney(EconomyParticipator ep, double delta, String toDoThis, String forDoingThis) {
|
||||
if (!shouldBeUsed()) {
|
||||
return false;
|
||||
}
|
||||
public static boolean modifyMoney(EconomyParticipator ep, double delta, String toDoThis, String forDoingThis) {
|
||||
if (!shouldBeUsed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
OfflinePlayer acc;
|
||||
OfflinePlayer acc;
|
||||
|
||||
if (isUUID(ep.getAccountId())) {
|
||||
acc = Bukkit.getOfflinePlayer(UUID.fromString(ep.getAccountId()));
|
||||
if (acc.getName() == null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
acc = Bukkit.getOfflinePlayer(ep.getAccountId());
|
||||
}
|
||||
if (isUUID(ep.getAccountId())) {
|
||||
acc = Bukkit.getOfflinePlayer(UUID.fromString(ep.getAccountId()));
|
||||
if (acc.getName() == null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
acc = Bukkit.getOfflinePlayer(ep.getAccountId());
|
||||
}
|
||||
|
||||
String You = ep.describeTo(ep, true);
|
||||
String You = ep.describeTo(ep, true);
|
||||
|
||||
if (delta == 0) {
|
||||
// no money actually transferred?
|
||||
if (delta == 0) {
|
||||
// no money actually transferred?
|
||||
// ep.msg("<h>%s<i> didn't have to pay anything %s.", You, forDoingThis); // might be for gains, might be for losses
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (delta > 0) {
|
||||
// The player should gain money
|
||||
// The account might not have enough space
|
||||
EconomyResponse er = econ.depositPlayer(acc, delta);
|
||||
if (er.transactionSuccess()) {
|
||||
modifyUniverseMoney(-delta);
|
||||
if (forDoingThis != null && !forDoingThis.isEmpty()) {
|
||||
ep.msg("<h>%s<i> gained <h>%s<i> %s.", You, moneyString(delta), forDoingThis);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// transfer to account failed
|
||||
if (forDoingThis != null && !forDoingThis.isEmpty()) {
|
||||
ep.msg("<h>%s<i> would have gained <h>%s<i> %s, but the deposit failed.", You, moneyString(delta), forDoingThis);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// The player should loose money
|
||||
// The player might not have enough.
|
||||
if (delta > 0) {
|
||||
// The player should gain money
|
||||
// The account might not have enough space
|
||||
EconomyResponse er = econ.depositPlayer(acc, delta);
|
||||
if (er.transactionSuccess()) {
|
||||
modifyUniverseMoney(-delta);
|
||||
if (forDoingThis != null && !forDoingThis.isEmpty()) {
|
||||
ep.msg("<h>%s<i> gained <h>%s<i> %s.", You, moneyString(delta), forDoingThis);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// transfer to account failed
|
||||
if (forDoingThis != null && !forDoingThis.isEmpty()) {
|
||||
ep.msg("<h>%s<i> would have gained <h>%s<i> %s, but the deposit failed.", You, moneyString(delta), forDoingThis);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// The player should loose money
|
||||
// The player might not have enough.
|
||||
|
||||
if (econ.has(acc, -delta) && econ.withdrawPlayer(acc, -delta).transactionSuccess()) {
|
||||
// There is enough money to pay
|
||||
modifyUniverseMoney(-delta);
|
||||
if (forDoingThis != null && !forDoingThis.isEmpty()) {
|
||||
ep.msg("<h>%s<i> lost <h>%s<i> %s.", You, moneyString(-delta), forDoingThis);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// There was not enough money to pay
|
||||
if (toDoThis != null && !toDoThis.isEmpty()) {
|
||||
ep.msg("<h>%s<i> can't afford <h>%s<i> %s.", You, moneyString(-delta), toDoThis);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (econ.has(acc, -delta) && econ.withdrawPlayer(acc, -delta).transactionSuccess()) {
|
||||
// There is enough money to pay
|
||||
modifyUniverseMoney(-delta);
|
||||
if (forDoingThis != null && !forDoingThis.isEmpty()) {
|
||||
ep.msg("<h>%s<i> lost <h>%s<i> %s.", You, moneyString(-delta), forDoingThis);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// There was not enough money to pay
|
||||
if (toDoThis != null && !toDoThis.isEmpty()) {
|
||||
ep.msg("<h>%s<i> can't afford <h>%s<i> %s.", You, moneyString(-delta), toDoThis);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String moneyString(double amount) {
|
||||
return format.format(amount);
|
||||
}
|
||||
public static String moneyString(double amount) {
|
||||
return format.format(amount);
|
||||
}
|
||||
|
||||
// calculate the cost for claiming land
|
||||
public static double calculateClaimCost(int ownedLand, boolean takingFromAnotherFaction) {
|
||||
if (!shouldBeUsed()) {
|
||||
return 0d;
|
||||
}
|
||||
// calculate the cost for claiming land
|
||||
public static double calculateClaimCost(int ownedLand, boolean takingFromAnotherFaction) {
|
||||
if (!shouldBeUsed()) {
|
||||
return 0d;
|
||||
}
|
||||
|
||||
// basic claim cost, plus land inflation cost, minus the potential bonus given for claiming from another faction
|
||||
return Conf.econCostClaimWilderness + (Conf.econCostClaimWilderness * Conf.econClaimAdditionalMultiplier * ownedLand) - (takingFromAnotherFaction ? Conf.econCostClaimFromFactionBonus : 0);
|
||||
}
|
||||
// basic claim cost, plus land inflation cost, minus the potential bonus given for claiming from another faction
|
||||
return Conf.econCostClaimWilderness + (Conf.econCostClaimWilderness * Conf.econClaimAdditionalMultiplier * ownedLand) - (takingFromAnotherFaction ? Conf.econCostClaimFromFactionBonus : 0);
|
||||
}
|
||||
|
||||
// calculate refund amount for unclaiming land
|
||||
public static double calculateClaimRefund(int ownedLand) {
|
||||
return calculateClaimCost(ownedLand - 1, false) * Conf.econClaimRefundMultiplier;
|
||||
}
|
||||
// calculate refund amount for unclaiming land
|
||||
public static double calculateClaimRefund(int ownedLand) {
|
||||
return calculateClaimCost(ownedLand - 1, false) * Conf.econClaimRefundMultiplier;
|
||||
}
|
||||
|
||||
// calculate value of all owned land
|
||||
public static double calculateTotalLandValue(int ownedLand) {
|
||||
double amount = 0;
|
||||
for (int x = 0; x < ownedLand; x++) {
|
||||
amount += calculateClaimCost(x, false);
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
// calculate value of all owned land
|
||||
public static double calculateTotalLandValue(int ownedLand) {
|
||||
double amount = 0;
|
||||
for (int x = 0; x < ownedLand; x++) {
|
||||
amount += calculateClaimCost(x, false);
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------- //
|
||||
// Standard account management methods
|
||||
// -------------------------------------------- //
|
||||
// -------------------------------------------- //
|
||||
// Standard account management methods
|
||||
// -------------------------------------------- //
|
||||
|
||||
// calculate refund amount for all owned land
|
||||
public static double calculateTotalLandRefund(int ownedLand) {
|
||||
return calculateTotalLandValue(ownedLand) * Conf.econClaimRefundMultiplier;
|
||||
}
|
||||
// calculate refund amount for all owned land
|
||||
public static double calculateTotalLandRefund(int ownedLand) {
|
||||
return calculateTotalLandValue(ownedLand) * Conf.econClaimRefundMultiplier;
|
||||
}
|
||||
|
||||
public static boolean hasAccount(String name) {
|
||||
return econ.hasAccount(name);
|
||||
}
|
||||
public static boolean hasAccount(String name) {
|
||||
return econ.hasAccount(name);
|
||||
}
|
||||
|
||||
public static double getBalance(String account) {
|
||||
return econ.getBalance(account);
|
||||
}
|
||||
public static double getBalance(String account) {
|
||||
return econ.getBalance(account);
|
||||
}
|
||||
|
||||
public static String getFriendlyBalance(UUID uuid) {
|
||||
OfflinePlayer offline = Bukkit.getOfflinePlayer(uuid);
|
||||
if (offline.getName() == null) {
|
||||
return "0";
|
||||
}
|
||||
return format.format(econ.getBalance(offline));
|
||||
}
|
||||
public static String getFriendlyBalance(UUID uuid) {
|
||||
OfflinePlayer offline = Bukkit.getOfflinePlayer(uuid);
|
||||
if (offline.getName() == null) {
|
||||
return "0";
|
||||
}
|
||||
return format.format(econ.getBalance(offline));
|
||||
}
|
||||
|
||||
public static String getFriendlyBalance(FPlayer player) {
|
||||
return getFriendlyBalance(UUID.fromString(player.getId()));
|
||||
}
|
||||
public static String getFriendlyBalance(FPlayer player) {
|
||||
return getFriendlyBalance(UUID.fromString(player.getId()));
|
||||
}
|
||||
|
||||
public static boolean setBalance(String account, double amount) {
|
||||
double current = econ.getBalance(account);
|
||||
if (current > amount) {
|
||||
return econ.withdrawPlayer(account, current - amount).transactionSuccess();
|
||||
} else {
|
||||
return econ.depositPlayer(account, amount - current).transactionSuccess();
|
||||
}
|
||||
}
|
||||
public static boolean setBalance(String account, double amount) {
|
||||
double current = econ.getBalance(account);
|
||||
if (current > amount) {
|
||||
return econ.withdrawPlayer(account, current - amount).transactionSuccess();
|
||||
} else {
|
||||
return econ.depositPlayer(account, amount - current).transactionSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean modifyBalance(String account, double amount) {
|
||||
if (amount < 0) {
|
||||
return econ.withdrawPlayer(account, -amount).transactionSuccess();
|
||||
} else {
|
||||
return econ.depositPlayer(account, amount).transactionSuccess();
|
||||
}
|
||||
}
|
||||
public static boolean modifyBalance(String account, double amount) {
|
||||
if (amount < 0) {
|
||||
return econ.withdrawPlayer(account, -amount).transactionSuccess();
|
||||
} else {
|
||||
return econ.depositPlayer(account, amount).transactionSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean deposit(String account, double amount) {
|
||||
return econ.depositPlayer(account, amount).transactionSuccess();
|
||||
}
|
||||
public static boolean deposit(String account, double amount) {
|
||||
return econ.depositPlayer(account, amount).transactionSuccess();
|
||||
}
|
||||
|
||||
public static boolean withdraw(String account, double amount) {
|
||||
return econ.withdrawPlayer(account, amount).transactionSuccess();
|
||||
}
|
||||
public static boolean withdraw(String account, double amount) {
|
||||
return econ.withdrawPlayer(account, amount).transactionSuccess();
|
||||
}
|
||||
|
||||
// ---------------------------------------
|
||||
// Helpful Utilities
|
||||
// ---------------------------------------
|
||||
// ---------------------------------------
|
||||
// Helpful Utilities
|
||||
// ---------------------------------------
|
||||
|
||||
public static boolean isUUID(String uuid) {
|
||||
try {
|
||||
UUID.fromString(uuid);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
return false;
|
||||
}
|
||||
public static boolean isUUID(String uuid) {
|
||||
try {
|
||||
UUID.fromString(uuid);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,32 +15,32 @@ import java.math.BigDecimal;
|
||||
|
||||
public class Essentials {
|
||||
|
||||
private static IEssentials essentials;
|
||||
private static IEssentials essentials;
|
||||
|
||||
public static void setup() {
|
||||
Plugin ess = Bukkit.getPluginManager().getPlugin("Essentials");
|
||||
if (ess != null) {
|
||||
essentials = (IEssentials) ess;
|
||||
}
|
||||
}
|
||||
public static void setup() {
|
||||
Plugin ess = Bukkit.getPluginManager().getPlugin("Essentials");
|
||||
if (ess != null) {
|
||||
essentials = (IEssentials) ess;
|
||||
}
|
||||
}
|
||||
|
||||
// return false if feature is disabled or Essentials isn't available
|
||||
public static boolean handleTeleport(Player player, Location loc) {
|
||||
if (!Conf.homesTeleportCommandEssentialsIntegration || essentials == null) {
|
||||
return false;
|
||||
}
|
||||
// return false if feature is disabled or Essentials isn't available
|
||||
public static boolean handleTeleport(Player player, Location loc) {
|
||||
if (!Conf.homesTeleportCommandEssentialsIntegration || essentials == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Teleport teleport = essentials.getUser(player).getTeleport();
|
||||
Trade trade = new Trade(new BigDecimal(Conf.econCostHome), essentials);
|
||||
try {
|
||||
teleport.teleport(loc, trade, TeleportCause.PLUGIN);
|
||||
} catch (Exception e) {
|
||||
player.sendMessage(ChatColor.RED.toString() + e.getMessage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Teleport teleport = essentials.getUser(player).getTeleport();
|
||||
Trade trade = new Trade(new BigDecimal(Conf.econCostHome), essentials);
|
||||
try {
|
||||
teleport.teleport(loc, trade, TeleportCause.PLUGIN);
|
||||
} catch (Exception e) {
|
||||
player.sendMessage(ChatColor.RED.toString() + e.getMessage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isVanished(Player player) {
|
||||
return essentials != null && essentials.getUser(player).isVanished();
|
||||
}
|
||||
public static boolean isVanished(Player player) {
|
||||
return essentials != null && essentials.getUser(player).isVanished();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,110 +30,110 @@ import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
||||
|
||||
public class Worldguard {
|
||||
|
||||
private static WorldGuardPlugin wg;
|
||||
private static boolean enabled = false;
|
||||
private static WorldGuardPlugin wg;
|
||||
private static boolean enabled = false;
|
||||
|
||||
public static void init(Plugin plugin) {
|
||||
Plugin wgplug = plugin.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
if (wgplug == null || !(wgplug instanceof WorldGuardPlugin)) {
|
||||
enabled = false;
|
||||
wg = null;
|
||||
SavageFactions.plugin.log("Could not hook to WorldGuard. WorldGuard checks are disabled.");
|
||||
} else {
|
||||
wg = (WorldGuardPlugin) wgplug;
|
||||
enabled = true;
|
||||
SavageFactions.plugin.log("Successfully hooked to WorldGuard.");
|
||||
}
|
||||
}
|
||||
public static void init(Plugin plugin) {
|
||||
Plugin wgplug = plugin.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
if (wgplug == null || !(wgplug instanceof WorldGuardPlugin)) {
|
||||
enabled = false;
|
||||
wg = null;
|
||||
SavageFactions.plugin.log("Could not hook to WorldGuard. WorldGuard checks are disabled.");
|
||||
} else {
|
||||
wg = (WorldGuardPlugin) wgplug;
|
||||
enabled = true;
|
||||
SavageFactions.plugin.log("Successfully hooked to WorldGuard.");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
public static boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
// PVP Flag check
|
||||
// Returns:
|
||||
// True: PVP is allowed
|
||||
// False: PVP is disallowed
|
||||
@SuppressWarnings("deprecation")
|
||||
public static boolean isPVP(Player player) {
|
||||
if (!enabled) {
|
||||
// No WG hooks so we'll always bypass this check.
|
||||
return true;
|
||||
}
|
||||
// PVP Flag check
|
||||
// Returns:
|
||||
// True: PVP is allowed
|
||||
// False: PVP is disallowed
|
||||
@SuppressWarnings("deprecation")
|
||||
public static boolean isPVP(Player player) {
|
||||
if (!enabled) {
|
||||
// No WG hooks so we'll always bypass this check.
|
||||
return true;
|
||||
}
|
||||
|
||||
Location loc = player.getLocation();
|
||||
World world = loc.getWorld();
|
||||
Vector pt = toVector(loc);
|
||||
Location loc = player.getLocation();
|
||||
World world = loc.getWorld();
|
||||
Vector pt = toVector(loc);
|
||||
|
||||
RegionManager regionManager = wg.getRegionManager(world);
|
||||
ApplicableRegionSet set = regionManager.getApplicableRegions(pt);
|
||||
return set.allows(DefaultFlag.PVP);
|
||||
}
|
||||
RegionManager regionManager = wg.getRegionManager(world);
|
||||
ApplicableRegionSet set = regionManager.getApplicableRegions(pt);
|
||||
return set.allows(DefaultFlag.PVP);
|
||||
}
|
||||
|
||||
// Check if player can build at location by worldguards rules.
|
||||
// Returns:
|
||||
// True: Player can build in the region.
|
||||
// False: Player can not build in the region.
|
||||
public static boolean playerCanBuild(Player player, Location loc) {
|
||||
if (!enabled) {
|
||||
// No WG hooks so we'll always bypass this check.
|
||||
return false;
|
||||
}
|
||||
// Check if player can build at location by worldguards rules.
|
||||
// Returns:
|
||||
// True: Player can build in the region.
|
||||
// False: Player can not build in the region.
|
||||
public static boolean playerCanBuild(Player player, Location loc) {
|
||||
if (!enabled) {
|
||||
// No WG hooks so we'll always bypass this check.
|
||||
return false;
|
||||
}
|
||||
|
||||
World world = loc.getWorld();
|
||||
Vector pt = toVector(loc);
|
||||
World world = loc.getWorld();
|
||||
Vector pt = toVector(loc);
|
||||
|
||||
return wg.getRegionManager(world).getApplicableRegions(pt).size() > 0 && wg.canBuild(player, loc);
|
||||
}
|
||||
return wg.getRegionManager(world).getApplicableRegions(pt).size() > 0 && wg.canBuild(player, loc);
|
||||
}
|
||||
|
||||
// Check for Regions in chunk the chunk
|
||||
// Returns:
|
||||
// True: Regions found within chunk
|
||||
// False: No regions found within chunk
|
||||
// Check for Regions in chunk the chunk
|
||||
// Returns:
|
||||
// True: Regions found within chunk
|
||||
// False: No regions found within chunk
|
||||
|
||||
public static boolean checkForRegionsInChunk(FLocation floc) {
|
||||
Chunk chunk = floc.getWorld().getChunkAt((int) floc.getX(), (int) floc.getZ());
|
||||
public static boolean checkForRegionsInChunk(FLocation floc) {
|
||||
Chunk chunk = floc.getWorld().getChunkAt((int) floc.getX(), (int) floc.getZ());
|
||||
|
||||
return checkForRegionsInChunk(chunk);
|
||||
}
|
||||
return checkForRegionsInChunk(chunk);
|
||||
}
|
||||
|
||||
public static boolean checkForRegionsInChunk(Location loc) {
|
||||
Chunk chunk = loc.getWorld().getChunkAt(loc);
|
||||
public static boolean checkForRegionsInChunk(Location loc) {
|
||||
Chunk chunk = loc.getWorld().getChunkAt(loc);
|
||||
|
||||
return checkForRegionsInChunk(chunk);
|
||||
}
|
||||
return checkForRegionsInChunk(chunk);
|
||||
}
|
||||
|
||||
public static boolean checkForRegionsInChunk(Chunk chunk) {
|
||||
if (!enabled) {
|
||||
// No WG hooks so we'll always bypass this check.
|
||||
return false;
|
||||
}
|
||||
public static boolean checkForRegionsInChunk(Chunk chunk) {
|
||||
if (!enabled) {
|
||||
// No WG hooks so we'll always bypass this check.
|
||||
return false;
|
||||
}
|
||||
|
||||
World world = chunk.getWorld();
|
||||
int minChunkX = chunk.getX() << 4;
|
||||
int minChunkZ = chunk.getZ() << 4;
|
||||
int maxChunkX = minChunkX + 15;
|
||||
int maxChunkZ = minChunkZ + 15;
|
||||
World world = chunk.getWorld();
|
||||
int minChunkX = chunk.getX() << 4;
|
||||
int minChunkZ = chunk.getZ() << 4;
|
||||
int maxChunkX = minChunkX + 15;
|
||||
int maxChunkZ = minChunkZ + 15;
|
||||
|
||||
int worldHeight = world.getMaxHeight(); // Allow for heights other than default
|
||||
int worldHeight = world.getMaxHeight(); // Allow for heights other than default
|
||||
|
||||
BlockVector minChunk = new BlockVector(minChunkX, 0, minChunkZ);
|
||||
BlockVector maxChunk = new BlockVector(maxChunkX, worldHeight, maxChunkZ);
|
||||
BlockVector minChunk = new BlockVector(minChunkX, 0, minChunkZ);
|
||||
BlockVector maxChunk = new BlockVector(maxChunkX, worldHeight, maxChunkZ);
|
||||
|
||||
RegionManager regionManager = wg.getRegionManager(world);
|
||||
ProtectedCuboidRegion region = new ProtectedCuboidRegion("wgfactionoverlapcheck", minChunk, maxChunk);
|
||||
Map<String, ProtectedRegion> allregions = regionManager.getRegions();
|
||||
Collection<ProtectedRegion> allregionslist = new ArrayList<>(allregions.values());
|
||||
List<ProtectedRegion> overlaps;
|
||||
boolean foundregions = false;
|
||||
RegionManager regionManager = wg.getRegionManager(world);
|
||||
ProtectedCuboidRegion region = new ProtectedCuboidRegion("wgfactionoverlapcheck", minChunk, maxChunk);
|
||||
Map<String, ProtectedRegion> allregions = regionManager.getRegions();
|
||||
Collection<ProtectedRegion> allregionslist = new ArrayList<>(allregions.values());
|
||||
List<ProtectedRegion> overlaps;
|
||||
boolean foundregions = false;
|
||||
|
||||
try {
|
||||
overlaps = region.getIntersectingRegions(allregionslist);
|
||||
foundregions = overlaps != null && !overlaps.isEmpty();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
overlaps = region.getIntersectingRegions(allregionslist);
|
||||
foundregions = overlaps != null && !overlaps.isEmpty();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return foundregions;
|
||||
}
|
||||
return foundregions;
|
||||
}
|
||||
}
|
||||
@@ -3,105 +3,105 @@ package com.massivecraft.factions.integration.dynmap;
|
||||
import com.massivecraft.factions.Conf;
|
||||
|
||||
public class DynmapStyle {
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String lineColor = null;
|
||||
public Double lineOpacity = null;
|
||||
public Integer lineWeight = null;
|
||||
public String fillColor = null;
|
||||
public Double fillOpacity = null;
|
||||
// NOTE: We just return the string here. We do not return the resolved Dynmap MarkerIcon object.
|
||||
// The reason is we use this class in the MConf. For serialization to work Dynmap would have to be loaded and we can't require that.
|
||||
// Using dynmap is optional.
|
||||
public String homeMarker = null;
|
||||
public Boolean boost = null;
|
||||
public String lineColor = null;
|
||||
public Double lineOpacity = null;
|
||||
public Integer lineWeight = null;
|
||||
public String fillColor = null;
|
||||
public Double fillOpacity = null;
|
||||
// NOTE: We just return the string here. We do not return the resolved Dynmap MarkerIcon object.
|
||||
// The reason is we use this class in the MConf. For serialization to work Dynmap would have to be loaded and we can't require that.
|
||||
// Using dynmap is optional.
|
||||
public String homeMarker = null;
|
||||
public Boolean boost = null;
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> T coalesce(T... items) {
|
||||
for (T item : items) {
|
||||
if (item != null) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@SafeVarargs
|
||||
public static <T> T coalesce(T... items) {
|
||||
for (T item : items) {
|
||||
if (item != null) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getColor(String string) {
|
||||
int ret = 0x00FF00;
|
||||
try {
|
||||
ret = Integer.parseInt(string.substring(1), 16);
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
public static int getColor(String string) {
|
||||
int ret = 0x00FF00;
|
||||
try {
|
||||
ret = Integer.parseInt(string.substring(1), 16);
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int getLineColor() {
|
||||
return getColor(coalesce(this.lineColor, Conf.dynmapDefaultStyle.lineColor, Conf.DYNMAP_STYLE_LINE_COLOR));
|
||||
}
|
||||
public int getLineColor() {
|
||||
return getColor(coalesce(this.lineColor, Conf.dynmapDefaultStyle.lineColor, Conf.DYNMAP_STYLE_LINE_COLOR));
|
||||
}
|
||||
|
||||
public DynmapStyle setStrokeColor(String strokeColor) {
|
||||
this.lineColor = strokeColor;
|
||||
return this;
|
||||
}
|
||||
public DynmapStyle setStrokeColor(String strokeColor) {
|
||||
this.lineColor = strokeColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
public double getLineOpacity() {
|
||||
return coalesce(this.lineOpacity, Conf.dynmapDefaultStyle.lineOpacity, Conf.DYNMAP_STYLE_LINE_OPACITY);
|
||||
}
|
||||
public double getLineOpacity() {
|
||||
return coalesce(this.lineOpacity, Conf.dynmapDefaultStyle.lineOpacity, Conf.DYNMAP_STYLE_LINE_OPACITY);
|
||||
}
|
||||
|
||||
public DynmapStyle setLineOpacity(Double strokeOpacity) {
|
||||
this.lineOpacity = strokeOpacity;
|
||||
return this;
|
||||
}
|
||||
public DynmapStyle setLineOpacity(Double strokeOpacity) {
|
||||
this.lineOpacity = strokeOpacity;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getLineWeight() {
|
||||
return coalesce(this.lineWeight, Conf.dynmapDefaultStyle.lineWeight, Conf.DYNMAP_STYLE_LINE_WEIGHT);
|
||||
}
|
||||
public int getLineWeight() {
|
||||
return coalesce(this.lineWeight, Conf.dynmapDefaultStyle.lineWeight, Conf.DYNMAP_STYLE_LINE_WEIGHT);
|
||||
}
|
||||
|
||||
public DynmapStyle setLineWeight(Integer strokeWeight) {
|
||||
this.lineWeight = strokeWeight;
|
||||
return this;
|
||||
}
|
||||
public DynmapStyle setLineWeight(Integer strokeWeight) {
|
||||
this.lineWeight = strokeWeight;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getFillColor() {
|
||||
return getColor(coalesce(this.fillColor, Conf.dynmapDefaultStyle.fillColor, Conf.DYNMAP_STYLE_FILL_COLOR));
|
||||
}
|
||||
public int getFillColor() {
|
||||
return getColor(coalesce(this.fillColor, Conf.dynmapDefaultStyle.fillColor, Conf.DYNMAP_STYLE_FILL_COLOR));
|
||||
}
|
||||
|
||||
public DynmapStyle setFillColor(String fillColor) {
|
||||
this.fillColor = fillColor;
|
||||
return this;
|
||||
}
|
||||
public DynmapStyle setFillColor(String fillColor) {
|
||||
this.fillColor = fillColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
public double getFillOpacity() {
|
||||
return coalesce(this.fillOpacity, Conf.dynmapDefaultStyle.fillOpacity, Conf.DYNMAP_STYLE_FILL_OPACITY);
|
||||
}
|
||||
public double getFillOpacity() {
|
||||
return coalesce(this.fillOpacity, Conf.dynmapDefaultStyle.fillOpacity, Conf.DYNMAP_STYLE_FILL_OPACITY);
|
||||
}
|
||||
|
||||
public DynmapStyle setFillOpacity(Double fillOpacity) {
|
||||
this.fillOpacity = fillOpacity;
|
||||
return this;
|
||||
}
|
||||
public DynmapStyle setFillOpacity(Double fillOpacity) {
|
||||
this.fillOpacity = fillOpacity;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getHomeMarker() {
|
||||
return coalesce(this.homeMarker, Conf.dynmapDefaultStyle.homeMarker, Conf.DYNMAP_STYLE_HOME_MARKER);
|
||||
}
|
||||
public String getHomeMarker() {
|
||||
return coalesce(this.homeMarker, Conf.dynmapDefaultStyle.homeMarker, Conf.DYNMAP_STYLE_HOME_MARKER);
|
||||
}
|
||||
|
||||
public DynmapStyle setHomeMarker(String homeMarker) {
|
||||
this.homeMarker = homeMarker;
|
||||
return this;
|
||||
}
|
||||
public DynmapStyle setHomeMarker(String homeMarker) {
|
||||
this.homeMarker = homeMarker;
|
||||
return this;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean getBoost() {
|
||||
return coalesce(this.boost, Conf.dynmapDefaultStyle.boost, Conf.DYNMAP_STYLE_BOOST);
|
||||
}
|
||||
public boolean getBoost() {
|
||||
return coalesce(this.boost, Conf.dynmapDefaultStyle.boost, Conf.DYNMAP_STYLE_BOOST);
|
||||
}
|
||||
|
||||
public DynmapStyle setBoost(Boolean boost) {
|
||||
this.boost = boost;
|
||||
return this;
|
||||
}
|
||||
public DynmapStyle setBoost(Boolean boost) {
|
||||
this.boost = boost;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,113 +4,113 @@ import org.dynmap.markers.AreaMarker;
|
||||
import org.dynmap.markers.MarkerSet;
|
||||
|
||||
public class TempAreaMarker {
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String label;
|
||||
public String world;
|
||||
public double[] x;
|
||||
public double[] z;
|
||||
public String description;
|
||||
public String label;
|
||||
public String world;
|
||||
public double[] x;
|
||||
public double[] z;
|
||||
public String description;
|
||||
|
||||
public int lineColor;
|
||||
public double lineOpacity;
|
||||
public int lineWeight;
|
||||
public int lineColor;
|
||||
public double lineOpacity;
|
||||
public int lineWeight;
|
||||
|
||||
public int fillColor;
|
||||
public double fillOpacity;
|
||||
public int fillColor;
|
||||
public double fillOpacity;
|
||||
|
||||
public boolean boost;
|
||||
public boolean boost;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static boolean equals(AreaMarker marker, double[] x, double[] z) {
|
||||
int length = marker.getCornerCount();
|
||||
public static boolean equals(AreaMarker marker, double[] x, double[] z) {
|
||||
int length = marker.getCornerCount();
|
||||
|
||||
if (x.length != length) {
|
||||
return false;
|
||||
}
|
||||
if (z.length != length) {
|
||||
return false;
|
||||
}
|
||||
if (x.length != length) {
|
||||
return false;
|
||||
}
|
||||
if (z.length != length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (marker.getCornerX(i) != x[i]) {
|
||||
return false;
|
||||
}
|
||||
if (marker.getCornerZ(i) != z[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (marker.getCornerX(i) != x[i]) {
|
||||
return false;
|
||||
}
|
||||
if (marker.getCornerZ(i) != z[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UPDATE
|
||||
// -------------------------------------------- //
|
||||
// -------------------------------------------- //
|
||||
// UPDATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public AreaMarker create(MarkerSet markerset, String markerId) {
|
||||
AreaMarker ret = markerset.createAreaMarker(markerId, this.label, false, this.world, this.x, this.z, false // not persistent
|
||||
);
|
||||
public AreaMarker create(MarkerSet markerset, String markerId) {
|
||||
AreaMarker ret = markerset.createAreaMarker(markerId, this.label, false, this.world, this.x, this.z, false // not persistent
|
||||
);
|
||||
|
||||
if (ret == null) {
|
||||
return null;
|
||||
}
|
||||
if (ret == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Description
|
||||
ret.setDescription(this.description);
|
||||
// Description
|
||||
ret.setDescription(this.description);
|
||||
|
||||
// Line Style
|
||||
ret.setLineStyle(this.lineWeight, this.lineOpacity, this.lineColor);
|
||||
// Line Style
|
||||
ret.setLineStyle(this.lineWeight, this.lineOpacity, this.lineColor);
|
||||
|
||||
// Fill Style
|
||||
ret.setFillStyle(this.fillOpacity, this.fillColor);
|
||||
// Fill Style
|
||||
ret.setFillStyle(this.fillOpacity, this.fillColor);
|
||||
|
||||
// Boost Flag
|
||||
ret.setBoostFlag(this.boost);
|
||||
// Boost Flag
|
||||
ret.setBoostFlag(this.boost);
|
||||
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void update(AreaMarker marker) {
|
||||
// Corner Locations
|
||||
if (!equals(marker, this.x, this.z)) {
|
||||
marker.setCornerLocations(this.x, this.z);
|
||||
}
|
||||
public void update(AreaMarker marker) {
|
||||
// Corner Locations
|
||||
if (!equals(marker, this.x, this.z)) {
|
||||
marker.setCornerLocations(this.x, this.z);
|
||||
}
|
||||
|
||||
// Label
|
||||
if (!marker.getLabel().equals(this.label)) {
|
||||
marker.setLabel(this.label);
|
||||
}
|
||||
// Label
|
||||
if (!marker.getLabel().equals(this.label)) {
|
||||
marker.setLabel(this.label);
|
||||
}
|
||||
|
||||
// Description
|
||||
if (!marker.getDescription().equals(this.description)) {
|
||||
marker.setDescription(this.description);
|
||||
}
|
||||
// Description
|
||||
if (!marker.getDescription().equals(this.description)) {
|
||||
marker.setDescription(this.description);
|
||||
}
|
||||
|
||||
// Line Style
|
||||
if (marker.getLineWeight() != this.lineWeight ||
|
||||
marker.getLineOpacity() != this.lineOpacity ||
|
||||
marker.getLineColor() != this.lineColor) {
|
||||
marker.setLineStyle(this.lineWeight, this.lineOpacity, this.lineColor);
|
||||
}
|
||||
// Line Style
|
||||
if (marker.getLineWeight() != this.lineWeight ||
|
||||
marker.getLineOpacity() != this.lineOpacity ||
|
||||
marker.getLineColor() != this.lineColor) {
|
||||
marker.setLineStyle(this.lineWeight, this.lineOpacity, this.lineColor);
|
||||
}
|
||||
|
||||
// Fill Style
|
||||
if ((marker.getFillOpacity() != this.fillOpacity) || (marker.getFillColor() != this.fillColor)) {
|
||||
marker.setFillStyle(this.fillOpacity, this.fillColor);
|
||||
}
|
||||
// Boost Flag
|
||||
if (marker.getBoostFlag() != this.boost) {
|
||||
marker.setBoostFlag(this.boost);
|
||||
}
|
||||
}
|
||||
// Fill Style
|
||||
if ((marker.getFillOpacity() != this.fillOpacity) || (marker.getFillColor() != this.fillColor)) {
|
||||
marker.setFillStyle(this.fillOpacity, this.fillColor);
|
||||
}
|
||||
// Boost Flag
|
||||
if (marker.getBoostFlag() != this.boost) {
|
||||
marker.setBoostFlag(this.boost);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,68 +7,68 @@ import org.dynmap.markers.MarkerIcon;
|
||||
import org.dynmap.markers.MarkerSet;
|
||||
|
||||
public class TempMarker {
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String label;
|
||||
public String world;
|
||||
public double x;
|
||||
public double y;
|
||||
public double z;
|
||||
public String iconName;
|
||||
public String description;
|
||||
public String label;
|
||||
public String world;
|
||||
public double x;
|
||||
public double y;
|
||||
public double z;
|
||||
public String iconName;
|
||||
public String description;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static MarkerIcon getMarkerIcon(MarkerAPI markerApi, String name) {
|
||||
MarkerIcon ret = markerApi.getMarkerIcon(name);
|
||||
if (ret == null) {
|
||||
ret = markerApi.getMarkerIcon(Conf.DYNMAP_STYLE_HOME_MARKER);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
public static MarkerIcon getMarkerIcon(MarkerAPI markerApi, String name) {
|
||||
MarkerIcon ret = markerApi.getMarkerIcon(name);
|
||||
if (ret == null) {
|
||||
ret = markerApi.getMarkerIcon(Conf.DYNMAP_STYLE_HOME_MARKER);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UPDATE
|
||||
// -------------------------------------------- //
|
||||
// -------------------------------------------- //
|
||||
// UPDATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Marker create(MarkerAPI markerApi, MarkerSet markerset, String markerId) {
|
||||
Marker ret = markerset.createMarker(markerId, this.label, this.world, this.x, this.y, this.z, getMarkerIcon(markerApi, this.iconName), false // not persistent
|
||||
);
|
||||
public Marker create(MarkerAPI markerApi, MarkerSet markerset, String markerId) {
|
||||
Marker ret = markerset.createMarker(markerId, this.label, this.world, this.x, this.y, this.z, getMarkerIcon(markerApi, this.iconName), false // not persistent
|
||||
);
|
||||
|
||||
if (ret == null) {
|
||||
return null;
|
||||
}
|
||||
if (ret == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ret.setDescription(this.description);
|
||||
ret.setDescription(this.description);
|
||||
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void update(MarkerAPI markerApi, Marker marker) {
|
||||
if (!this.world.equals(marker.getWorld()) || this.x != marker.getX() || this.y != marker.getY() || this.z != marker.getZ()) {
|
||||
marker.setLocation(this.world, this.x, this.y, this.z);
|
||||
}
|
||||
public void update(MarkerAPI markerApi, Marker marker) {
|
||||
if (!this.world.equals(marker.getWorld()) || this.x != marker.getX() || this.y != marker.getY() || this.z != marker.getZ()) {
|
||||
marker.setLocation(this.world, this.x, this.y, this.z);
|
||||
}
|
||||
|
||||
if (!marker.getLabel().equals(this.label)) {
|
||||
marker.setLabel(this.label);
|
||||
}
|
||||
if (!marker.getLabel().equals(this.label)) {
|
||||
marker.setLabel(this.label);
|
||||
}
|
||||
|
||||
MarkerIcon icon = getMarkerIcon(markerApi, this.iconName);
|
||||
if (marker.getMarkerIcon() == null || marker.getMarkerIcon().equals(icon)) {
|
||||
marker.setMarkerIcon(icon);
|
||||
}
|
||||
MarkerIcon icon = getMarkerIcon(markerApi, this.iconName);
|
||||
if (marker.getMarkerIcon() == null || marker.getMarkerIcon().equals(icon)) {
|
||||
marker.setMarkerIcon(icon);
|
||||
}
|
||||
|
||||
if (!marker.getDescription().equals(this.description)) {
|
||||
marker.setDescription(this.description);
|
||||
}
|
||||
}
|
||||
if (!marker.getDescription().equals(this.description)) {
|
||||
marker.setDescription(this.description);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,51 +5,51 @@ import org.dynmap.markers.MarkerSet;
|
||||
|
||||
public class TempMarkerSet {
|
||||
|
||||
public String label;
|
||||
public int minimumZoom;
|
||||
public int priority;
|
||||
public boolean hideByDefault;
|
||||
public String label;
|
||||
public int minimumZoom;
|
||||
public int priority;
|
||||
public boolean hideByDefault;
|
||||
|
||||
public MarkerSet create(MarkerAPI markerApi, String id) {
|
||||
MarkerSet ret = markerApi.createMarkerSet(id, this.label, null, false); // ("null, false" at the end means "all icons allowed, not perisistent")
|
||||
public MarkerSet create(MarkerAPI markerApi, String id) {
|
||||
MarkerSet ret = markerApi.createMarkerSet(id, this.label, null, false); // ("null, false" at the end means "all icons allowed, not perisistent")
|
||||
|
||||
if (ret == null) {
|
||||
return null;
|
||||
}
|
||||
if (ret == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Minimum Zoom
|
||||
if (this.minimumZoom > 0) {
|
||||
ret.setMinZoom(this.minimumZoom);
|
||||
}
|
||||
// Minimum Zoom
|
||||
if (this.minimumZoom > 0) {
|
||||
ret.setMinZoom(this.minimumZoom);
|
||||
}
|
||||
|
||||
// Priority
|
||||
ret.setLayerPriority(this.priority);
|
||||
// Priority
|
||||
ret.setLayerPriority(this.priority);
|
||||
|
||||
// Hide by Default
|
||||
ret.setHideByDefault(this.hideByDefault);
|
||||
// Hide by Default
|
||||
ret.setHideByDefault(this.hideByDefault);
|
||||
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void update(MarkerSet markerset) {
|
||||
// Name
|
||||
if (!markerset.getMarkerSetLabel().equals(this.label)) {
|
||||
markerset.setMarkerSetLabel(this.label);
|
||||
}
|
||||
public void update(MarkerSet markerset) {
|
||||
// Name
|
||||
if (!markerset.getMarkerSetLabel().equals(this.label)) {
|
||||
markerset.setMarkerSetLabel(this.label);
|
||||
}
|
||||
|
||||
if (this.minimumZoom > 0) {
|
||||
if (markerset.getMinZoom() != this.minimumZoom) {
|
||||
markerset.setMinZoom(this.minimumZoom);
|
||||
}
|
||||
}
|
||||
if (this.minimumZoom > 0) {
|
||||
if (markerset.getMinZoom() != this.minimumZoom) {
|
||||
markerset.setMinZoom(this.minimumZoom);
|
||||
}
|
||||
}
|
||||
|
||||
if (markerset.getLayerPriority() != this.priority) {
|
||||
markerset.setLayerPriority(this.priority);
|
||||
}
|
||||
if (markerset.getLayerPriority() != this.priority) {
|
||||
markerset.setLayerPriority(this.priority);
|
||||
}
|
||||
|
||||
if (markerset.getHideByDefault() != this.hideByDefault) {
|
||||
markerset.setHideByDefault(this.hideByDefault);
|
||||
}
|
||||
}
|
||||
if (markerset.getHideByDefault() != this.hideByDefault) {
|
||||
markerset.setHideByDefault(this.hideByDefault);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user