created c.s.e.l. check cashing/writing service system
This commit is contained in:
parent
c341e7a9b8
commit
f285ba4749
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.
BIN
build/classes/java/main/CoswayUtil/BankingSystem.class
Normal file
BIN
build/classes/java/main/CoswayUtil/BankingSystem.class
Normal file
Binary file not shown.
BIN
build/classes/java/main/CoswayUtil/CheckCommand.class
Normal file
BIN
build/classes/java/main/CoswayUtil/CheckCommand.class
Normal file
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.
@ -65,3 +65,9 @@ commands:
|
|||||||
coswaygetpdc:
|
coswaygetpdc:
|
||||||
description: get set value of a players persistent data container key
|
description: get set value of a players persistent data container key
|
||||||
usage: /coswaygetpdc <player> <key>
|
usage: /coswaygetpdc <player> <key>
|
||||||
|
writecheck:
|
||||||
|
description: Writes a check to another player.
|
||||||
|
usage: /writecheck <player> <amount>
|
||||||
|
cashcheck:
|
||||||
|
description: Cash a check you are holding.
|
||||||
|
usage: /cashcheck
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
84
src/main/java/CoswayUtil/BankingSystem.java
Normal file
84
src/main/java/CoswayUtil/BankingSystem.java
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
package CoswayUtil;
|
||||||
|
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public class BankingSystem implements Listener {
|
||||||
|
private final CoswayUtil plugin;
|
||||||
|
private final Economy economy;
|
||||||
|
private final NamespacedKey recipientKey;
|
||||||
|
private final NamespacedKey amountKey;
|
||||||
|
|
||||||
|
public BankingSystem(CoswayUtil plugin, Economy economy) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.economy = economy;
|
||||||
|
this.recipientKey = new NamespacedKey(plugin, "check_recipient");
|
||||||
|
this.amountKey = new NamespacedKey(plugin, "check_amount");
|
||||||
|
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeCheck(Player sender, String recipientName, double amount) {
|
||||||
|
Player recipient = Bukkit.getPlayer(recipientName);
|
||||||
|
if (recipient == null) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Player not found!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (amount <= 0) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Invalid check amount!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!economy.has(sender, amount)) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "You do not have enough funds to cover this check.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
economy.withdrawPlayer(sender, amount);
|
||||||
|
ItemStack check = new ItemStack(Material.PAPER);
|
||||||
|
ItemMeta meta = check.getItemMeta();
|
||||||
|
if (meta != null) {
|
||||||
|
meta.setDisplayName(ChatColor.GOLD + "C.S.E.L. Check");
|
||||||
|
meta.getPersistentDataContainer().set(recipientKey, PersistentDataType.STRING, recipientName);
|
||||||
|
meta.getPersistentDataContainer().set(amountKey, PersistentDataType.DOUBLE, amount);
|
||||||
|
check.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
sender.getInventory().addItem(check);
|
||||||
|
sender.sendMessage(ChatColor.GREEN + "You have written a check for " + ChatColor.GOLD + "$" + amount + ChatColor.GREEN + " to " + recipientName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onCheckUse(PlayerInteractEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
ItemStack item = player.getInventory().getItemInMainHand();
|
||||||
|
if (item.getType() != Material.PAPER || !item.hasItemMeta()) return;
|
||||||
|
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
if (meta == null) return;
|
||||||
|
|
||||||
|
PersistentDataContainer pdc = meta.getPersistentDataContainer();
|
||||||
|
if (!pdc.has(recipientKey, PersistentDataType.STRING) || !pdc.has(amountKey, PersistentDataType.DOUBLE)) return;
|
||||||
|
|
||||||
|
String recipientName = pdc.get(recipientKey, PersistentDataType.STRING);
|
||||||
|
double amount = pdc.get(amountKey, PersistentDataType.DOUBLE);
|
||||||
|
|
||||||
|
if (!player.getName().equalsIgnoreCase(recipientName)) {
|
||||||
|
player.sendMessage(ChatColor.RED + "This check is not written to you!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
economy.depositPlayer(player, amount);
|
||||||
|
player.getInventory().getItemInMainHand().setAmount(0);
|
||||||
|
player.sendMessage(ChatColor.GREEN + "You have cashed a check for " + ChatColor.GOLD + "$" + amount);
|
||||||
|
}
|
||||||
|
}
|
121
src/main/java/CoswayUtil/CheckCommand.java
Normal file
121
src/main/java/CoswayUtil/CheckCommand.java
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
package CoswayUtil;
|
||||||
|
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class CheckCommand implements CommandExecutor {
|
||||||
|
private final CoswayUtil plugin;
|
||||||
|
private final Economy econ;
|
||||||
|
private final NamespacedKey recipientKey;
|
||||||
|
private final NamespacedKey amountKey;
|
||||||
|
|
||||||
|
public CheckCommand(CoswayUtil plugin, Economy econ) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.econ = econ;
|
||||||
|
this.recipientKey = new NamespacedKey(plugin, "check_recipient");
|
||||||
|
this.amountKey = new NamespacedKey(plugin, "check_amount");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (!(sender instanceof Player player)) {
|
||||||
|
sender.sendMessage("Only players can use this command.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmd.getName().equalsIgnoreCase("writecheck")) {
|
||||||
|
if (args.length != 2) {
|
||||||
|
player.sendMessage("Usage: /writecheck <player> <amount>");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player recipient = Bukkit.getPlayerExact(args[0]);
|
||||||
|
if (recipient == null) {
|
||||||
|
player.sendMessage("Player not found!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
double amount;
|
||||||
|
try {
|
||||||
|
amount = Double.parseDouble(args[1]);
|
||||||
|
if (amount <= 0) {
|
||||||
|
player.sendMessage("Amount must be positive.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
player.sendMessage("Invalid amount.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!econ.has(player, amount)) {
|
||||||
|
player.sendMessage("Insufficient funds.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
econ.withdrawPlayer(player, amount);
|
||||||
|
player.getInventory().addItem(createCheck(recipient.getName(), amount));
|
||||||
|
player.sendMessage("Check for " + amount + " written to " + recipient.getName() + ".");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmd.getName().equalsIgnoreCase("cashcheck")) {
|
||||||
|
ItemStack check = player.getInventory().getItemInMainHand();
|
||||||
|
if (!isCheck(check)) {
|
||||||
|
player.sendMessage("You must hold a valid check to cash it.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemMeta meta = check.getItemMeta();
|
||||||
|
String recipient = meta.getPersistentDataContainer().get(recipientKey, PersistentDataType.STRING);
|
||||||
|
Double amount = meta.getPersistentDataContainer().get(amountKey, PersistentDataType.DOUBLE);
|
||||||
|
|
||||||
|
if (recipient == null || amount == null) {
|
||||||
|
player.sendMessage("Invalid check.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!player.getName().equalsIgnoreCase(recipient)) {
|
||||||
|
player.sendMessage("This check is not made out to you!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
econ.depositPlayer(player, amount);
|
||||||
|
player.getInventory().setItemInMainHand(null);
|
||||||
|
player.sendMessage("You cashed a check for " + amount + ".");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack createCheck(String recipient, double amount) {
|
||||||
|
ItemStack check = new ItemStack(Material.PAPER);
|
||||||
|
ItemMeta meta = check.getItemMeta();
|
||||||
|
meta.setDisplayName("§6C.S.E.L. Check");
|
||||||
|
meta.setLore(Arrays.asList("§7Recipient: §b" + recipient, "§7Amount: §a" + amount));
|
||||||
|
|
||||||
|
meta.getPersistentDataContainer().set(recipientKey, PersistentDataType.STRING, recipient);
|
||||||
|
meta.getPersistentDataContainer().set(amountKey, PersistentDataType.DOUBLE, amount);
|
||||||
|
|
||||||
|
check.setItemMeta(meta);
|
||||||
|
return check;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isCheck(ItemStack item) {
|
||||||
|
if (item == null || item.getType() != Material.PAPER || !item.hasItemMeta()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return item.getItemMeta().getPersistentDataContainer().has(recipientKey, PersistentDataType.STRING);
|
||||||
|
}
|
||||||
|
}
|
@ -96,6 +96,9 @@ public final class CoswayUtil extends JavaPlugin implements Listener {
|
|||||||
getLogger().severe("Vault not found or no economy provider found.");
|
getLogger().severe("Vault not found or no economy provider found.");
|
||||||
getServer().getPluginManager().disablePlugin(this);
|
getServer().getPluginManager().disablePlugin(this);
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
getCommand("writecheck").setExecutor(new CheckCommand(this, economy));
|
||||||
|
getCommand("cashcheck").setExecutor(new CheckCommand(this, economy));
|
||||||
}
|
}
|
||||||
|
|
||||||
new BlockShop(this, economy).register();
|
new BlockShop(this, economy).register();
|
||||||
@ -129,7 +132,9 @@ public final class CoswayUtil extends JavaPlugin implements Listener {
|
|||||||
registration("Note Studio",1);
|
registration("Note Studio",1);
|
||||||
new TreasureFountain(this);
|
new TreasureFountain(this);
|
||||||
getServer().getPluginManager().registerEvents(new TreasureFountain(this), this);
|
getServer().getPluginManager().registerEvents(new TreasureFountain(this), this);
|
||||||
registration("Treasure Fountain",3);
|
registration("Treasure Fountain (W.I.P.)",3);
|
||||||
|
new BankingSystem(this,economy);
|
||||||
|
registration("Banking System",3);
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -259,12 +264,12 @@ public final class CoswayUtil extends JavaPlugin implements Listener {
|
|||||||
target = getServer().getPlayer(args[0]);
|
target = getServer().getPlayer(args[0]);
|
||||||
}
|
}
|
||||||
assert target != null;
|
assert target != null;
|
||||||
setpdc(target,args[1],args[2]);
|
|
||||||
String msg = getpdc(target,args[1]);
|
String msg = getpdc(target,args[1]);
|
||||||
if(msg == null) {
|
if(msg == null) {
|
||||||
msg = "&cNULL";
|
msg = "&cNULL";
|
||||||
}
|
}
|
||||||
returnMsg(player,"&aSet "+args[1]+" from "+msg+" to "+args[2]+" for "+target.getName());
|
setpdc(target,args[1],args[2]);
|
||||||
|
returnMsg(player,"&aSet &7&l"+args[1]+"&a from &6&l"+msg+"&a to &e&l"+args[2]+"&a for &d&l"+target.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cmd.getName().equalsIgnoreCase("coswaygetpdc") && sender instanceof Player player) {
|
if (cmd.getName().equalsIgnoreCase("coswaygetpdc") && sender instanceof Player player) {
|
||||||
|
@ -30,17 +30,19 @@ public class FireflySimulator {
|
|||||||
public void run() {
|
public void run() {
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
if (player.getWorld().getTime() == 13000) { // Only at night
|
if (player.getWorld().getTime() == 13000) { // Only at night
|
||||||
if(Objects.equals(getpdc(player,"music"), true)) {
|
if(Objects.equals(getpdc(player,"music"), "true")) {
|
||||||
player.stopAllSounds();
|
player.stopAllSounds();
|
||||||
player.playSound(player.getLocation().clone().add(0, 100, 0), Sound.MUSIC_DISC_MALL, 10, 1);
|
player.playSound(player.getLocation().clone().add(0, 100, 0), Sound.MUSIC_DISC_MALL, 10, 1);
|
||||||
}
|
}
|
||||||
|
//statMsg(player,"your music settings are set to "+getpdc(player,"music"));
|
||||||
statMsg(player,"&6time for bed");
|
statMsg(player,"&6time for bed");
|
||||||
}
|
}
|
||||||
if (player.getWorld().getTime() == 1137) { // Only at night
|
if (player.getWorld().getTime() == 1137) { // Only at night
|
||||||
if(Objects.equals(getpdc(player,"music"), true)) {
|
if(Objects.equals(getpdc(player,"music"), "true")) {
|
||||||
player.stopAllSounds();
|
player.stopAllSounds();
|
||||||
player.playSound(player.getLocation().clone().add(0, 100, 0), Sound.MUSIC_DISC_OTHERSIDE, 10, 1);
|
player.playSound(player.getLocation().clone().add(0, 100, 0), Sound.MUSIC_DISC_OTHERSIDE, 10, 1);
|
||||||
}
|
}
|
||||||
|
//statMsg(player,"your music settings are set to "+getpdc(player,"music"));
|
||||||
statMsg(player,"&eRize and Shine!");
|
statMsg(player,"&eRize and Shine!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,3 +65,9 @@ commands:
|
|||||||
coswaygetpdc:
|
coswaygetpdc:
|
||||||
description: get set value of a players persistent data container key
|
description: get set value of a players persistent data container key
|
||||||
usage: /coswaygetpdc <player> <key>
|
usage: /coswaygetpdc <player> <key>
|
||||||
|
writecheck:
|
||||||
|
description: Writes a check to another player.
|
||||||
|
usage: /writecheck <player> <amount>
|
||||||
|
cashcheck:
|
||||||
|
description: Cash a check you are holding.
|
||||||
|
usage: /cashcheck
|
Loading…
Reference in New Issue
Block a user