Dateien nach "src/main/java/net/viper/money/commands" hochladen
This commit is contained in:
147
src/main/java/net/viper/money/commands/BalanceCmd.java
Normal file
147
src/main/java/net/viper/money/commands/BalanceCmd.java
Normal file
@@ -0,0 +1,147 @@
|
||||
package net.craftersland.money.commands;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.craftersland.money.Money;
|
||||
|
||||
public class BalanceCmd {
|
||||
|
||||
private Money money;
|
||||
|
||||
public BalanceCmd(Money m) {
|
||||
this.money = m;
|
||||
}
|
||||
|
||||
public boolean runUserCmd(CommandSender sender) {
|
||||
if (sender instanceof Player) {
|
||||
final Player p = (Player) sender;
|
||||
if (p.hasPermission("MysqlEconomyBank.cmd.balance")) {
|
||||
if (money.cooldown.contains(p.getUniqueId())) {
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.tooFastInteraction", "0", p, p.getName());
|
||||
money.getSoundHandler().sendPlingSound(p);
|
||||
return true;
|
||||
}
|
||||
money.getMoneyDatabaseInterface().getBalance(p);
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.balance", "0", p, p.getName());
|
||||
money.getSoundHandler().sendClickSound(p);
|
||||
|
||||
|
||||
|
||||
// Cooldown hinzufügen
|
||||
money.cooldown.add(p.getUniqueId());
|
||||
Double delayCalc = 20.00 / 1000.00 * Double.parseDouble(money.getConfigurationHandler().getString("general.timeBetweenTwoInteractions"));
|
||||
int delay = delayCalc.intValue();
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(money, new Runnable() {
|
||||
public void run() {
|
||||
money.cooldown.remove(p.getUniqueId());
|
||||
}
|
||||
}, delay);
|
||||
} else {
|
||||
money.getSoundHandler().sendPlingSound(p);
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.noPermission", "0", p, p.getName());
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("You can't run this command from console!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean runAdminCmd(CommandSender sender, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
if (p.hasPermission("MysqlEconomyBank.admin")) {
|
||||
Player target = Bukkit.getPlayer(args[1]);
|
||||
if (target != null) {
|
||||
if (target.isOnline()) {
|
||||
if (money.getMoneyDatabaseInterface().hasAccount(target) == false) {
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.accountDoesNotExist", "0", target, target.getName());
|
||||
money.getSoundHandler().sendPlingSound(p);
|
||||
return false;
|
||||
}
|
||||
String amount = money.getMoneyDatabaseInterface().getBalance(target).toString();
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.balanceCommand", amount, target, target.getName());
|
||||
money.getSoundHandler().sendClickSound(p);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
UUID targetUUID = UUID.fromString(args[1]);
|
||||
if (money.getMoneyDatabaseInterface().hasAccount(targetUUID) == false) {
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.accountDoesNotExist", "0", null, "null");
|
||||
money.getSoundHandler().sendPlingSound(p);
|
||||
return false;
|
||||
}
|
||||
String amount = money.getMoneyDatabaseInterface().getBalance(targetUUID).toString();
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.balanceCommand", amount, null, "null");
|
||||
money.getSoundHandler().sendClickSound(p);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
OfflinePlayer offp = Bukkit.getOfflinePlayer(args[1]);
|
||||
if (offp != null) {
|
||||
if (money.getMoneyDatabaseInterface().hasAccount(offp.getUniqueId()) == false) {
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.accountDoesNotExist", "0", null, "null");
|
||||
money.getSoundHandler().sendPlingSound(p);
|
||||
return false;
|
||||
}
|
||||
String amount = money.getMoneyDatabaseInterface().getBalance(offp.getUniqueId()).toString();
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.balanceCommand", amount, null, "null");
|
||||
money.getSoundHandler().sendClickSound(p);
|
||||
return true;
|
||||
} else {
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.accountDoesNotExist", "0", null, "null");
|
||||
money.getSoundHandler().sendPlingSound(p);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
money.getSoundHandler().sendPlingSound(p);
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.noPermission", "0", p, p.getName());
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]);
|
||||
if (target != null) {
|
||||
if (target.isOnline()) {
|
||||
if (money.getMoneyDatabaseInterface().hasAccount(target) == false) {
|
||||
sender.sendMessage(ChatColor.RED + ">> " + ChatColor.WHITE + "" + target.getName() + ChatColor.RED + " does not have an account!");
|
||||
return false;
|
||||
}
|
||||
String amount = money.getMoneyDatabaseInterface().getBalance(target).toString();
|
||||
sender.sendMessage(ChatColor.GREEN + ">> " + ChatColor.WHITE + "" + target.getName() + ChatColor.GREEN + " balance: " + ChatColor.WHITE + "" + amount);
|
||||
return true;
|
||||
} else {
|
||||
try {
|
||||
UUID targetUUID = UUID.fromString(args[1]);
|
||||
if (money.getMoneyDatabaseInterface().hasAccount(targetUUID) == false) {
|
||||
sender.sendMessage(ChatColor.RED + ">> " + ChatColor.WHITE + "" + targetUUID + ChatColor.RED + " does not have an account!");
|
||||
return false;
|
||||
}
|
||||
String amount = money.getMoneyDatabaseInterface().getBalance(targetUUID).toString();
|
||||
sender.sendMessage(ChatColor.GREEN + ">> " + ChatColor.WHITE + "" + targetUUID + ChatColor.GREEN + " balance: " + ChatColor.WHITE + "" + amount);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
if (money.getMoneyDatabaseInterface().hasAccount(target) == false) {
|
||||
sender.sendMessage(ChatColor.RED + ">> " + ChatColor.WHITE + "" + target.getName() + ChatColor.RED + " does not have an account!");
|
||||
return false;
|
||||
}
|
||||
String amount = money.getMoneyDatabaseInterface().getBalance(target).toString();
|
||||
sender.sendMessage(ChatColor.GREEN + ">> " + ChatColor.WHITE + "" + target.getName() + ChatColor.GREEN + " balance: " + ChatColor.WHITE + "" + amount);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
sender.sendMessage(ChatColor.RED + ">> " + ChatColor.WHITE + "" + args[1] + ChatColor.RED + " does not have an account!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
138
src/main/java/net/viper/money/commands/DepositCmd.java
Normal file
138
src/main/java/net/viper/money/commands/DepositCmd.java
Normal file
@@ -0,0 +1,138 @@
|
||||
package net.craftersland.money.commands;
|
||||
|
||||
import net.craftersland.money.Money;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class DepositCmd {
|
||||
private Money m;
|
||||
|
||||
public DepositCmd(Money m) {
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
public boolean runUserCmd(CommandSender sender, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
final Player p = (Player) sender;
|
||||
if (p.hasPermission("MysqlEconomyBank.cmd.deposit") || p.hasPermission("MysqlEconomyBank.admin")) {
|
||||
if (m.cooldown.contains(p.getUniqueId())) {
|
||||
m.getConfigurationHandler().printMessage(p, "chatMessages.tooFastInteraction", "0", p, p.getName());
|
||||
m.getSoundHandler().sendPlingSound(p);
|
||||
return true;
|
||||
}
|
||||
Double amount = 0.0;
|
||||
try {
|
||||
amount = Double.parseDouble(args[1]);
|
||||
} catch (Exception e) {
|
||||
p.sendMessage(m.getConfigurationHandler().getStringWithColor("chatMessages.negativeAmount"));
|
||||
m.getSoundHandler().sendPlingSound(p);
|
||||
return true;
|
||||
}
|
||||
if (amount <= 0) {
|
||||
m.getConfigurationHandler().printMessage(p, "chatMessages.negativeAmount", amount + "", p, p.getName());
|
||||
m.getSoundHandler().sendPlingSound(p);
|
||||
return true;
|
||||
}
|
||||
Double localBalance = Money.econ.getBalance(p);
|
||||
if (localBalance >= amount) {
|
||||
Double bankBalance = m.getMoneyDatabaseInterface().getBalance(p);
|
||||
if (bankBalance.doubleValue() + amount > Double.parseDouble(m.getConfigurationHandler().getString("general.maxBankLimitMoney"))) {
|
||||
m.getConfigurationHandler().printMessage(p, "chatMessages.reachedMaximumMoneyInAccount", amount + "", p, p.getName());
|
||||
m.getSoundHandler().sendPlingSound(p);
|
||||
return true;
|
||||
}
|
||||
final double fAmount = amount;
|
||||
Bukkit.getScheduler().runTask(m, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Money.econ.withdrawPlayer(p, fAmount);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
m.getMoneyDatabaseInterface().setBalance(p, bankBalance + amount);
|
||||
m.getConfigurationHandler().printMessage(p, "chatMessages.depositedSuccessfully", amount + "", p, p.getName());
|
||||
m.getSoundHandler().sendClickSound(p);
|
||||
m.cooldown.add(p.getUniqueId());
|
||||
Double delayCalc = Double.valueOf(0.02D * Double.parseDouble(m.getConfigurationHandler().getString("general.timeBetweenTwoInteractions")));
|
||||
int delay = delayCalc.intValue();
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(m, new Runnable() {
|
||||
public void run() {
|
||||
m.cooldown.remove(p.getUniqueId());
|
||||
}
|
||||
}, delay);
|
||||
} else {
|
||||
m.getConfigurationHandler().printMessage(p, "chatMessages.notEnoughMoneyInPoket", amount.toString(), p, p.getName());
|
||||
m.getSoundHandler().sendPlingSound(p);
|
||||
}
|
||||
} else {
|
||||
m.getSoundHandler().sendPlingSound(p);
|
||||
m.getConfigurationHandler().printMessage(p, "chatMessages.noPermission", "0", p, p.getName());
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("You cant run this command from console, it's for players only!");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean runAdminCmd(CommandSender sender, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
if (p.hasPermission("MysqlEconomyBank.admin")) {
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(args[2]);
|
||||
Double amount = 0.0;
|
||||
try {
|
||||
amount = Double.parseDouble(args[1]);
|
||||
} catch (Exception e) {
|
||||
p.sendMessage(m.getConfigurationHandler().getStringWithColor("chatMessages.negativeAmount"));
|
||||
m.getSoundHandler().sendPlingSound(p);
|
||||
return true;
|
||||
}
|
||||
if (amount <= 0) {
|
||||
m.getConfigurationHandler().printMessage(p, "chatMessages.negativeAmount", amount + "", p, p.getName());
|
||||
m.getSoundHandler().sendPlingSound(p);
|
||||
return true;
|
||||
}
|
||||
if (target != null && m.getMoneyDatabaseInterface().hasAccount(target)) {
|
||||
double balance = m.getMoneyDatabaseInterface().getBalance(target).doubleValue();
|
||||
m.getMoneyDatabaseInterface().setBalance(target, Double.valueOf(balance + amount.doubleValue()));
|
||||
m.getSoundHandler().sendLevelUpSound(p);
|
||||
m.getConfigurationHandler().printMessage(p, "chatMessages.depositedSuccessfully", amount + "", p, p.getName());
|
||||
} else {
|
||||
m.getConfigurationHandler().printMessage(p, "chatMessages.accountDoesNotExist", "0", null, args[2]);
|
||||
m.getSoundHandler().sendPlingSound(p);
|
||||
}
|
||||
} else {
|
||||
this.m.getSoundHandler().sendPlingSound(p);
|
||||
this.m.getConfigurationHandler().printMessage(p, "chatMessages.noPermission", "0", p, p.getName());
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(args[2]);
|
||||
Double amount = 0.0;
|
||||
try {
|
||||
amount = Double.parseDouble(args[1]);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(m.getConfigurationHandler().getStringWithColor("chatMessages.negativeAmount"));
|
||||
return true;
|
||||
}
|
||||
if (amount <= 0) {
|
||||
sender.sendMessage(m.getConfigurationHandler().getStringWithColor("chatMessages.negativeAmount"));
|
||||
return true;
|
||||
}
|
||||
if (target != null && m.getMoneyDatabaseInterface().hasAccount(target)) {
|
||||
double balance = m.getMoneyDatabaseInterface().getBalance(target);
|
||||
m.getMoneyDatabaseInterface().setBalance(target, Double.valueOf(balance + amount.doubleValue()));
|
||||
sender.sendMessage(m.getConfigurationHandler().getStringWithColor("chatMessages.depositedSuccessfully").replace("%amount", amount.toString()));
|
||||
} else {
|
||||
sender.sendMessage(m.getConfigurationHandler().getStringWithColor("chatMessages.accountDoesNotExist"));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
52
src/main/java/net/viper/money/commands/InterestCmd.java
Normal file
52
src/main/java/net/viper/money/commands/InterestCmd.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package net.craftersland.money.commands;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.craftersland.money.Money;
|
||||
|
||||
public class InterestCmd {
|
||||
|
||||
private Money money;
|
||||
|
||||
public InterestCmd(Money m) {
|
||||
this.money = m;
|
||||
}
|
||||
|
||||
public void runUserCmd(CommandSender sender) {
|
||||
if (sender instanceof Player) {
|
||||
if (money.getConfigurationHandler().getBoolean("general.interest.enabled") == true) {
|
||||
final Player p = (Player) sender;
|
||||
if (p.hasPermission("MysqlEconomyBank.cmd.interest")) {
|
||||
if (money.cooldown.contains(p.getUniqueId())) {
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.tooFastInteraction", "0", p, p.getName());
|
||||
money.getSoundHandler().sendPlingSound(p);
|
||||
return;
|
||||
}
|
||||
p.sendMessage(money.getConfigurationHandler().getStringWithColor("chatMessages.interestCommand").replace("%time", money.getInterestHandler().getNextInterestTime()));
|
||||
money.getSoundHandler().sendLevelUpSound(p);
|
||||
//add player to cooldown
|
||||
money.cooldown.add(p.getUniqueId());
|
||||
Double delayCalc = 20.00 / 1000.00 * Double.parseDouble(money.getConfigurationHandler().getString("general.timeBetweenTwoInteractions"));
|
||||
int delay = delayCalc.intValue();
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(money, new Runnable() {
|
||||
public void run() {
|
||||
//remove player from cooldown
|
||||
money.cooldown.remove(p.getUniqueId());
|
||||
}
|
||||
}, delay);
|
||||
} else {
|
||||
money.getSoundHandler().sendPlingSound(p);
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.noPermission", "0", p, p.getName());
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(money.getConfigurationHandler().getStringWithColor("chatMessages.interestDisabled").replace("%time", money.getInterestHandler().getNextInterestTime()));
|
||||
money.getSoundHandler().sendPlingSound((Player) sender);
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("You cant run this command from console!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
52
src/main/java/net/viper/money/commands/ReloadCmd.java
Normal file
52
src/main/java/net/viper/money/commands/ReloadCmd.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package net.craftersland.money.commands;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.craftersland.money.Money;
|
||||
|
||||
public class ReloadCmd {
|
||||
|
||||
private Money money;
|
||||
|
||||
public ReloadCmd(Money m) {
|
||||
this.money = m;
|
||||
}
|
||||
|
||||
public boolean runCmd(CommandSender sender) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
if (p.hasPermission("MysqlEconomyBank.admin")) {
|
||||
try {
|
||||
money.getConfig().load(new File("plugins"+System.getProperty("file.separator")+"MysqlEconomyBank"+System.getProperty("file.separator")+"config.yml"));
|
||||
} catch (Exception e) {
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.reloadFail", "0", p, p.getName());
|
||||
money.getSoundHandler().sendPlingSound(p);
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
money.getInterestHandler().resetTask();
|
||||
money.getSoundHandler().sendLevelUpSound(p);
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.reloadComplete", "0", p, p.getName());
|
||||
return true;
|
||||
}
|
||||
money.getSoundHandler().sendPlingSound(p);
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.noPermission", "0", p, p.getName());
|
||||
return false;
|
||||
} else {
|
||||
try {
|
||||
money.getConfig().load(new File("plugins"+System.getProperty("file.separator")+"MysqlEconomyBank"+System.getProperty("file.separator")+"config.yml"));
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD + ">> " + ChatColor.RED + "Could not load config! Check logs!");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "" + ChatColor.BOLD + ">> " + ChatColor.GREEN + "Configuration reloaded!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
178
src/main/java/net/viper/money/commands/SetCmd.java
Normal file
178
src/main/java/net/viper/money/commands/SetCmd.java
Normal file
@@ -0,0 +1,178 @@
|
||||
package net.craftersland.money.commands;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.craftersland.money.Money;
|
||||
|
||||
public class SetCmd {
|
||||
|
||||
private Money money;
|
||||
|
||||
public SetCmd(Money m) {
|
||||
this.money = m;
|
||||
}
|
||||
|
||||
public boolean runCmd(CommandSender sender, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
if (p.hasPermission("MysqlEconomyBank.admin")) {
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]);
|
||||
if (target != null) {
|
||||
if (money.getMoneyDatabaseInterface().hasAccount(target) == false) {
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.accountDoesNotExist", "0", target.getPlayer(), target.getName());
|
||||
money.getSoundHandler().sendPlingSound(p);
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
Double amount = Double.parseDouble(args[2]);
|
||||
if (amount <= 0) {
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.negativeAmount", amount + "", p, p.getName());
|
||||
money.getSoundHandler().sendPlingSound(p);
|
||||
return true;
|
||||
}
|
||||
money.getMoneyDatabaseInterface().setBalance(target, amount);
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.setCommand", amount.toString(), target.getPlayer(), target.getName());
|
||||
money.getSoundHandler().sendClickSound(p);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.setCommandFail", "0", null, null);
|
||||
money.getSoundHandler().sendPlingSound(p);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
UUID targetUUID = UUID.fromString(args[1]);
|
||||
if (money.getMoneyDatabaseInterface().hasAccount(targetUUID) == false) {
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.accountDoesNotExist", "0", null, "null");
|
||||
money.getSoundHandler().sendPlingSound(p);
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
Double amount = Double.parseDouble(args[2]);
|
||||
if (amount <= 0) {
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.negativeAmount", amount + "", p, p.getName());
|
||||
money.getSoundHandler().sendPlingSound(p);
|
||||
return true;
|
||||
}
|
||||
money.getMoneyDatabaseInterface().setBalance(targetUUID, amount);
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.setCommand", amount.toString(), null, "null");
|
||||
if (money.is19Server == true) {
|
||||
p.playSound(p.getLocation(), Sound.UI_BUTTON_CLICK, 1.0F, 1.0F);
|
||||
} else {
|
||||
p.playSound(p.getLocation(), Sound.valueOf("CLICK"), 1.0F, 1.0F);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.setCommandFail", "0", null, null);
|
||||
money.getSoundHandler().sendPlingSound(p);
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
if (money.getMoneyDatabaseInterface().hasAccount(target) == false) {
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.accountDoesNotExist", "0", target.getPlayer(), target.getName());
|
||||
money.getSoundHandler().sendPlingSound(p);
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
Double amount = Double.parseDouble(args[2]);
|
||||
if (amount <= 0) {
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.negativeAmount", amount + "", p, p.getName());
|
||||
money.getSoundHandler().sendPlingSound(p);
|
||||
return true;
|
||||
}
|
||||
money.getMoneyDatabaseInterface().setBalance(target, amount);
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.setCommand", amount.toString(), target.getPlayer(), target.getName());
|
||||
money.getSoundHandler().sendClickSound(p);
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.setCommandFail", "0", null, null);
|
||||
money.getSoundHandler().sendPlingSound(p);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
money.getSoundHandler().sendPlingSound(p);
|
||||
money.getConfigurationHandler().printMessage(p, "chatMessages.noPermission", "0", p, p.getName());
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]);
|
||||
if (target != null) {
|
||||
if (money.getMoneyDatabaseInterface().hasAccount(target) == false) {
|
||||
sender.sendMessage(ChatColor.RED + ">> " + ChatColor.WHITE + "" + target.getName() + ChatColor.RED + " does not have an account!");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
Double amount = Double.parseDouble(args[2]);
|
||||
if (amount <= 0) {
|
||||
sender.sendMessage(money.getConfigurationHandler().getStringWithColor("chatMessages.negativeAmount"));
|
||||
return true;
|
||||
}
|
||||
money.getMoneyDatabaseInterface().setBalance(target, amount);
|
||||
sender.sendMessage(ChatColor.GREEN + ">> " + ChatColor.WHITE + "" + target.getName() + ChatColor.GREEN + " balance set to: " + ChatColor.WHITE + "" + amount);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + ">> The amount must be a number!");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
UUID targetUUID = UUID.fromString(args[1]);
|
||||
if (money.getMoneyDatabaseInterface().hasAccount(targetUUID) == false) {
|
||||
sender.sendMessage(ChatColor.RED + ">> " + ChatColor.WHITE + "" + targetUUID + ChatColor.RED + " does not have an account!");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
Double amount = Double.parseDouble(args[2]);
|
||||
if (amount <= 0) {
|
||||
sender.sendMessage(money.getConfigurationHandler().getStringWithColor("chatMessages.negativeAmount"));
|
||||
return true;
|
||||
}
|
||||
money.getMoneyDatabaseInterface().setBalance(targetUUID, amount);
|
||||
sender.sendMessage(ChatColor.GREEN + ">> " + ChatColor.WHITE + "" + targetUUID + ChatColor.GREEN + " balance set to: " + ChatColor.WHITE + "" + amount);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + ">> The amount must be a number!");
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
if (money.getMoneyDatabaseInterface().hasAccount(target) == false) {
|
||||
sender.sendMessage(ChatColor.RED + ">> " + ChatColor.WHITE + "" + target.getName() + ChatColor.RED + " does not have an account!");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
Double amount = Double.parseDouble(args[2]);
|
||||
if (amount <= 0) {
|
||||
sender.sendMessage(money.getConfigurationHandler().getStringWithColor("chatMessages.negativeAmount"));
|
||||
return true;
|
||||
}
|
||||
money.getMoneyDatabaseInterface().setBalance(target, amount);
|
||||
sender.sendMessage(ChatColor.GREEN + ">> " + ChatColor.WHITE + "" + target.getName() + ChatColor.GREEN + " balance set to: " + ChatColor.WHITE + "" + amount);
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
sender.sendMessage(ChatColor.RED + ">> The amount must be a number!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
150
src/main/java/net/viper/money/commands/WithdrawCmd.java
Normal file
150
src/main/java/net/viper/money/commands/WithdrawCmd.java
Normal file
@@ -0,0 +1,150 @@
|
||||
package net.craftersland.money.commands;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.craftersland.money.Money;
|
||||
|
||||
public class WithdrawCmd {
|
||||
|
||||
private Money m;
|
||||
|
||||
public WithdrawCmd(Money m) {
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
public boolean runUserCmd(CommandSender sender, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
final Player p = (Player) sender;
|
||||
if (p.hasPermission("MysqlEconomyBank.cmd.withdraw")) {
|
||||
//check if player is in cooldown
|
||||
if (m.cooldown.contains(p.getUniqueId())) {
|
||||
m.getConfigurationHandler().printMessage(p, "chatMessages.tooFastInteraction", "0", p, p.getName());
|
||||
m.getSoundHandler().sendPlingSound(p);
|
||||
return true;
|
||||
}
|
||||
Double bankBalance = m.getMoneyDatabaseInterface().getBalance(p);
|
||||
Double amount = 0.0;
|
||||
try {
|
||||
amount = Double.parseDouble(args[1]);
|
||||
} catch (Exception e) {
|
||||
p.sendMessage(m.getConfigurationHandler().getStringWithColor("chatMessages.negativeAmount"));
|
||||
m.getSoundHandler().sendPlingSound(p);
|
||||
return true;
|
||||
}
|
||||
if (amount <= 0) {
|
||||
m.getConfigurationHandler().printMessage(p, "chatMessages.negativeAmount", amount + "", p, p.getName());
|
||||
m.getSoundHandler().sendPlingSound(p);
|
||||
return true;
|
||||
}
|
||||
if (bankBalance >= amount) {
|
||||
if (Money.econ.getBalance(p) + amount > Double.parseDouble(m.getConfigurationHandler().getString("general.maxPocketLimitMoney"))) {
|
||||
m.getConfigurationHandler().printMessage(p, "chatMessages.reachedMaximumMoneyInPocket", amount + "", p, p.getName());
|
||||
m.getSoundHandler().sendPlingSound(p);
|
||||
return true;
|
||||
}
|
||||
m.getMoneyDatabaseInterface().setBalance(p, bankBalance - amount);
|
||||
final double fAmount = amount;
|
||||
Bukkit.getScheduler().runTask(m, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Money.econ.depositPlayer(p, fAmount);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
m.getConfigurationHandler().printMessage(p, "chatMessages.withdrewSuccessfully", amount + "", p, p.getName());
|
||||
m.getSoundHandler().sendClickSound(p);
|
||||
//add player to cooldown
|
||||
m.cooldown.add(p.getUniqueId());
|
||||
Double delayCalc = 20.00 / 1000.00 * Double.parseDouble(m.getConfigurationHandler().getString("general.timeBetweenTwoInteractions"));
|
||||
int delay = delayCalc.intValue();
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(m, new Runnable() {
|
||||
public void run() {
|
||||
//remove player from cooldown
|
||||
m.cooldown.remove(p.getUniqueId());
|
||||
}
|
||||
}, delay);
|
||||
return true;
|
||||
}
|
||||
m.getConfigurationHandler().printMessage(p, "chatMessages.notEnoughMoneyInAccount", bankBalance.toString(), p, p.getName());
|
||||
m.getSoundHandler().sendPlingSound(p);
|
||||
return true;
|
||||
} else {
|
||||
m.getSoundHandler().sendPlingSound(p);
|
||||
m.getConfigurationHandler().printMessage(p, "chatMessages.noPermission", "0", p, p.getName());
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("You cant run this command from console, it's for players only!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean runAdminCmd(CommandSender sender, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
if (p.hasPermission("MysqlEconomyBank.admin")) {
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(args[2]);
|
||||
Double amount = 0.0;
|
||||
try {
|
||||
amount = Double.parseDouble(args[1]);
|
||||
} catch (Exception e) {
|
||||
p.sendMessage(m.getConfigurationHandler().getStringWithColor("chatMessages.negativeAmount"));
|
||||
m.getSoundHandler().sendPlingSound(p);
|
||||
return true;
|
||||
}
|
||||
if (amount <= 0) {
|
||||
m.getConfigurationHandler().printMessage(p, "chatMessages.negativeAmount", amount + "", p, p.getName());
|
||||
m.getSoundHandler().sendPlingSound(p);
|
||||
return true;
|
||||
}
|
||||
if (target != null && m.getMoneyDatabaseInterface().hasAccount(target)) {
|
||||
double balance = m.getMoneyDatabaseInterface().getBalance(target);
|
||||
if (balance >= amount.doubleValue()) {
|
||||
m.getMoneyDatabaseInterface().setBalance(target, balance - amount);
|
||||
m.getSoundHandler().sendLevelUpSound(p);
|
||||
m.getConfigurationHandler().printMessage(p, "chatMessages.withdrewSuccessfully", amount.toString(), p, p.getName());
|
||||
} else {
|
||||
m.getSoundHandler().sendPlingSound(p);
|
||||
m.getConfigurationHandler().printMessage(p, "chatMessages.notEnoughMoneyInAccount", amount.toString(), p, p.getName());
|
||||
}
|
||||
} else {
|
||||
m.getSoundHandler().sendPlingSound(p);
|
||||
m.getConfigurationHandler().printMessage(p, "chatMessages.noPermission", "0", p, p.getName());
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
m.getSoundHandler().sendPlingSound(p);
|
||||
m.getConfigurationHandler().printMessage(p, "chatMessages.noPermission", "0", p, p.getName());
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(args[2]);
|
||||
Double amount = 0.0;
|
||||
try {
|
||||
amount = Double.parseDouble(args[1]);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(m.getConfigurationHandler().getStringWithColor("chatMessages.negativeAmount"));
|
||||
return true;
|
||||
}
|
||||
if (target != null && m.getMoneyDatabaseInterface().hasAccount(target)) {
|
||||
double balance = m.getMoneyDatabaseInterface().getBalance(target);
|
||||
if (balance >= amount) {
|
||||
m.getMoneyDatabaseInterface().setBalance(target, balance - amount);
|
||||
sender.sendMessage(m.getConfigurationHandler().getStringWithColor("chatMessages.withdrewSuccessfully").replace("%amount", amount.toString()));
|
||||
} else {
|
||||
sender.sendMessage(m.getConfigurationHandler().getStringWithColor("chatMessages.notEnoughMoneyInAccount").replace("%amount", amount.toString()));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(m.getConfigurationHandler().getStringWithColor("chatMessages.accountDoesNotExist"));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user