created c.s.e.l. check cashing/writing service system
This commit is contained in:
parent
f285ba4749
commit
3a4e07fee3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -15,6 +15,8 @@ import org.bukkit.persistence.PersistentDataContainer;
|
|||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
|
||||||
public class BankingSystem implements Listener {
|
public class BankingSystem implements Listener {
|
||||||
private final CoswayUtil plugin;
|
private final CoswayUtil plugin;
|
||||||
private final Economy economy;
|
private final Economy economy;
|
||||||
@ -28,7 +30,7 @@ public class BankingSystem implements Listener {
|
|||||||
this.amountKey = new NamespacedKey(plugin, "check_amount");
|
this.amountKey = new NamespacedKey(plugin, "check_amount");
|
||||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||||
}
|
}
|
||||||
|
private final DecimalFormat formatter = new DecimalFormat("#,###.##");
|
||||||
public void writeCheck(Player sender, String recipientName, double amount) {
|
public void writeCheck(Player sender, String recipientName, double amount) {
|
||||||
Player recipient = Bukkit.getPlayer(recipientName);
|
Player recipient = Bukkit.getPlayer(recipientName);
|
||||||
if (recipient == null) {
|
if (recipient == null) {
|
||||||
@ -48,13 +50,17 @@ public class BankingSystem implements Listener {
|
|||||||
ItemStack check = new ItemStack(Material.PAPER);
|
ItemStack check = new ItemStack(Material.PAPER);
|
||||||
ItemMeta meta = check.getItemMeta();
|
ItemMeta meta = check.getItemMeta();
|
||||||
if (meta != null) {
|
if (meta != null) {
|
||||||
|
// Format the amount for better readability
|
||||||
|
String formattedAmount = formatter.format(amount);
|
||||||
meta.setDisplayName(ChatColor.GOLD + "C.S.E.L. Check");
|
meta.setDisplayName(ChatColor.GOLD + "C.S.E.L. Check");
|
||||||
meta.getPersistentDataContainer().set(recipientKey, PersistentDataType.STRING, recipientName);
|
meta.getPersistentDataContainer().set(recipientKey, PersistentDataType.STRING, recipientName);
|
||||||
meta.getPersistentDataContainer().set(amountKey, PersistentDataType.DOUBLE, amount);
|
meta.getPersistentDataContainer().set(amountKey, PersistentDataType.DOUBLE, amount);
|
||||||
check.setItemMeta(meta);
|
check.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
|
// Format the amount for better readability
|
||||||
|
String formattedAmount = formatter.format(amount);
|
||||||
sender.getInventory().addItem(check);
|
sender.getInventory().addItem(check);
|
||||||
sender.sendMessage(ChatColor.GREEN + "You have written a check for " + ChatColor.GOLD + "$" + amount + ChatColor.GREEN + " to " + recipientName);
|
sender.sendMessage(ChatColor.GREEN + "You have written a check for " + ChatColor.GOLD + "$" + formattedAmount + ChatColor.GREEN + " to " + recipientName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -2,6 +2,7 @@ package CoswayUtil;
|
|||||||
|
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@ -12,6 +13,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class CheckCommand implements CommandExecutor {
|
public class CheckCommand implements CommandExecutor {
|
||||||
@ -30,19 +32,19 @@ public class CheckCommand implements CommandExecutor {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
if (!(sender instanceof Player player)) {
|
if (!(sender instanceof Player player)) {
|
||||||
sender.sendMessage("Only players can use this command.");
|
sender.sendMessage(BankName()+ChatColor.RED+"Only players can use this command.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd.getName().equalsIgnoreCase("writecheck")) {
|
if (cmd.getName().equalsIgnoreCase("writecheck")) {
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
player.sendMessage("Usage: /writecheck <player> <amount>");
|
player.sendMessage(BankName()+ChatColor.GOLD+"Usage: /writecheck <player> <amount>");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player recipient = Bukkit.getPlayerExact(args[0]);
|
Player recipient = Bukkit.getPlayerExact(args[0]);
|
||||||
if (recipient == null) {
|
if (recipient == null) {
|
||||||
player.sendMessage("Player not found!");
|
player.sendMessage(BankName()+ChatColor.RED+"Player not found!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,29 +52,30 @@ public class CheckCommand implements CommandExecutor {
|
|||||||
try {
|
try {
|
||||||
amount = Double.parseDouble(args[1]);
|
amount = Double.parseDouble(args[1]);
|
||||||
if (amount <= 0) {
|
if (amount <= 0) {
|
||||||
player.sendMessage("Amount must be positive.");
|
player.sendMessage(BankName()+ChatColor.GOLD+"Amount must be positive.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
player.sendMessage("Invalid amount.");
|
player.sendMessage(BankName()+ChatColor.RED+"Invalid amount.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!econ.has(player, amount)) {
|
if (!econ.has(player, amount)) {
|
||||||
player.sendMessage("Insufficient funds.");
|
player.sendMessage(BankName()+ChatColor.RED+"Insufficient funds.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// Format the amount for better readability
|
||||||
|
String formattedAmount = formatter.format(amount);
|
||||||
econ.withdrawPlayer(player, amount);
|
econ.withdrawPlayer(player, amount);
|
||||||
player.getInventory().addItem(createCheck(recipient.getName(), amount));
|
player.getInventory().addItem(createCheck(recipient.getName(), amount));
|
||||||
player.sendMessage("Check for " + amount + " written to " + recipient.getName() + ".");
|
sender.sendMessage(BankName()+ChatColor.GREEN + "You have written a check for " + ChatColor.GOLD + "$" + formattedAmount + ChatColor.GREEN + " to " + recipient.getName());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd.getName().equalsIgnoreCase("cashcheck")) {
|
if (cmd.getName().equalsIgnoreCase("cashcheck")) {
|
||||||
ItemStack check = player.getInventory().getItemInMainHand();
|
ItemStack check = player.getInventory().getItemInMainHand();
|
||||||
if (!isCheck(check)) {
|
if (!isCheck(check)) {
|
||||||
player.sendMessage("You must hold a valid check to cash it.");
|
player.sendMessage(BankName()+ChatColor.RED+"You must hold a valid check to cash it.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,29 +84,34 @@ public class CheckCommand implements CommandExecutor {
|
|||||||
Double amount = meta.getPersistentDataContainer().get(amountKey, PersistentDataType.DOUBLE);
|
Double amount = meta.getPersistentDataContainer().get(amountKey, PersistentDataType.DOUBLE);
|
||||||
|
|
||||||
if (recipient == null || amount == null) {
|
if (recipient == null || amount == null) {
|
||||||
player.sendMessage("Invalid check.");
|
player.sendMessage(BankName()+ChatColor.RED+"Invalid check.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!player.getName().equalsIgnoreCase(recipient)) {
|
if (!player.getName().equalsIgnoreCase(recipient)) {
|
||||||
player.sendMessage("This check is not made out to you!");
|
player.sendMessage(BankName()+ChatColor.RED + "This check is not written to you!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
econ.depositPlayer(player, amount);
|
econ.depositPlayer(player, amount);
|
||||||
player.getInventory().setItemInMainHand(null);
|
player.getInventory().setItemInMainHand(null);
|
||||||
player.sendMessage("You cashed a check for " + amount + ".");
|
player.sendMessage(BankName()+ChatColor.GREEN + "You have cashed a check for " + ChatColor.GOLD + "$" + amount);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
private final DecimalFormat formatter = new DecimalFormat("#,###.##");
|
||||||
|
public String BankName() {
|
||||||
|
return ChatColor.GRAY+"[ "+ChatColor.AQUA+"C.S.E.L. Bank "+ChatColor.GRAY+"] ";
|
||||||
|
}
|
||||||
private ItemStack createCheck(String recipient, double amount) {
|
private ItemStack createCheck(String recipient, double amount) {
|
||||||
ItemStack check = new ItemStack(Material.PAPER);
|
ItemStack check = new ItemStack(Material.PAPER);
|
||||||
ItemMeta meta = check.getItemMeta();
|
ItemMeta meta = check.getItemMeta();
|
||||||
|
// Format the amount for better readability
|
||||||
|
String formattedAmount = formatter.format(amount);
|
||||||
meta.setDisplayName("§6C.S.E.L. Check");
|
meta.setDisplayName("§6C.S.E.L. Check");
|
||||||
meta.setLore(Arrays.asList("§7Recipient: §b" + recipient, "§7Amount: §a" + amount));
|
meta.setLore(Arrays.asList("§7Recipient: §b" + recipient, "§7Amount: §a$" + formattedAmount));
|
||||||
|
|
||||||
meta.getPersistentDataContainer().set(recipientKey, PersistentDataType.STRING, recipient);
|
meta.getPersistentDataContainer().set(recipientKey, PersistentDataType.STRING, recipient);
|
||||||
meta.getPersistentDataContainer().set(amountKey, PersistentDataType.DOUBLE, amount);
|
meta.getPersistentDataContainer().set(amountKey, PersistentDataType.DOUBLE, amount);
|
||||||
|
Loading…
Reference in New Issue
Block a user