commit 986cd858598a4e3abe0850d417a23f15ec1e134b Author: tianyu <32282861@qq.com> Date: Wed Jul 24 05:55:18 2024 +0800 测试版 diff --git a/src/main/java/me/demon/bank/BankAPI.java b/src/main/java/me/demon/bank/BankAPI.java new file mode 100644 index 0000000..03c79cc --- /dev/null +++ b/src/main/java/me/demon/bank/BankAPI.java @@ -0,0 +1,69 @@ +package me.demon.bank; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; + +public abstract class BankAPI { + + public static void addVault(Player p,int money){ + if(Main.dataMap.get(p) == null){ + Main.dataMap.put(p,new BankData(p)); + } + long currentTime = System.currentTimeMillis(); + Main.lastCommandTime.put(p,currentTime); + BankData bankData = Main.dataMap.get(p); + bankData.addMoney(money); + } + + public static int getMoney(String playName){ + FileConfiguration yml = Main.plugin.getConfig(); + return yml.getInt("BankStats."+playName+".Money"); + } + public static void addMoney(String playName,int amount){ + int money = getMoney(playName); + setMoney(playName,(money+amount)); + } + public static void takeMoney(String playName,int amount){ + int money = getMoney(playName); + setMoney(playName,(money-amount)); + } + public static void setMoney(String playName,int amount){ + FileConfiguration yml = Main.plugin.getConfig(); + yml.set("BankStats."+playName+".Money",amount); + } + + public static int getMoneyUUID(String uuid){ + FileConfiguration yml = Main.plugin.getConfig(); + return yml.getInt("BankStats."+uuid+".Money"); + } + public static void addMoneyUUID(String uuid,int amount){ + int money = getMoneyUUID(uuid); + setMoneyUUID(uuid,(money+amount)); + } + public static void takeMoneyUUID(String uuid,int amount){ + int money = getMoneyUUID(uuid); + setMoneyUUID(uuid,(money-amount)); + } + public static void setMoneyUUID(String uuid,int amount){ + FileConfiguration yml = Main.plugin.getConfig(); + yml.set("BankStats."+uuid+".Money",amount); + } + + public static int getPoints(String playName){ + FileConfiguration yml = Main.plugin.getConfig(); + return yml.getInt("BankStats."+playName+".Points"); + } + public static void addPoints(String playName,int amount){ + int money = getPoints(playName); + setPoints(playName,(money+amount)); + } + public static void takePoints(String playName,int amount){ + int money = getPoints(playName); + setPoints(playName,(money-amount)); + } + public static void setPoints(String playName,int amount){ + FileConfiguration yml = Main.plugin.getConfig(); + yml.set("BankStats."+playName+".Points",amount); + } + +} diff --git a/src/main/java/me/demon/bank/BankData.java b/src/main/java/me/demon/bank/BankData.java new file mode 100644 index 0000000..ff5715c --- /dev/null +++ b/src/main/java/me/demon/bank/BankData.java @@ -0,0 +1,37 @@ +package me.demon.bank; + +import org.bukkit.entity.Player; + +public class BankData { + + private final Player player; + private int money; + private int points; + + public BankData(Player p){ + this.player = p; + this.money = 0; + this.points = 0; + } + + public void SaveData(){ + + } + + public int getMoney() { + return money; + } + + public int getPoints() { + return points; + } + + public void addMoney(int money) { + this.money += money; + } + + public void setPoints(int points) { + this.points = points; + } + +} diff --git a/src/main/java/me/demon/bank/Main.java b/src/main/java/me/demon/bank/Main.java new file mode 100644 index 0000000..3f78fb8 --- /dev/null +++ b/src/main/java/me/demon/bank/Main.java @@ -0,0 +1,51 @@ +package me.demon.bank; + +import me.demon.bank.command.BankCommand; +import me.demon.bank.listener.JoinEvent; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.HashMap; +import java.util.Map; + +public class Main extends JavaPlugin { + + public static String pluginName = "魂式银行"; + public static Main plugin; + public static Map lastCommandTime = new HashMap<>(); + public static HashMap dataMap = new HashMap<>(); + public static String prefix = "§7[§6银行§7] §f"; + + public void onEnable() { + plugin = this; + saveDefaultConfig(); + Bukkit.getServer().getPluginManager().registerEvents(new JoinEvent(), plugin); + Bukkit.getPluginCommand("bank").setExecutor(new BankCommand()); + Bukkit.getConsoleSender().sendMessage("§6["+ Main.pluginName+"] §f插件加載成功!"); + Bukkit.getConsoleSender().sendMessage("§6["+ Main.pluginName+"] §f作者QQ:1763917516"); + new Placeholders(this).register(); + Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){ + @Override + public void run() { + long currentTime = System.currentTimeMillis(); + for (Player player : Main.lastCommandTime.keySet()){ + if((currentTime - Main.lastCommandTime.get(player)) >= (1000 * 10)){ + int money = Main.dataMap.get(player).getMoney(); + //HamsterAPI.giveMoney(player,money); + player.sendMessage("获得金币 +"+money); + Main.dataMap.remove(player); + player.sendMessage("发送缓存金币数据,并清理"); + Main.lastCommandTime.remove(player); + } + } + } + }, 5 * 20L, 5 * 20L); + } + + public void onDisable() { + Main.plugin.saveConfig(); + Bukkit.getConsoleSender().sendMessage("§6["+ Main.pluginName+"] §f玩家數據已保存。"); + Bukkit.getConsoleSender().sendMessage("§6["+ Main.pluginName+"] §f插件已安全卸載!"); + } +} diff --git a/src/main/java/me/demon/bank/Placeholders.java b/src/main/java/me/demon/bank/Placeholders.java new file mode 100644 index 0000000..5cf66c6 --- /dev/null +++ b/src/main/java/me/demon/bank/Placeholders.java @@ -0,0 +1,51 @@ +package me.demon.bank; + +import me.clip.placeholderapi.expansion.PlaceholderExpansion; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +public class Placeholders extends PlaceholderExpansion { + + private Plugin plugin; + public Placeholders(Plugin plugin) { + this.plugin = plugin; + } + @Override + public boolean persist() { + return true; + } + + @Override + public boolean canRegister() { + return true; + } + + @Override + public String getAuthor() { + return plugin.getDescription().getAuthors().toString(); + } + + @Override + public String getIdentifier() { + return "bank"; + } + + @Override + public String getVersion() { + return plugin.getDescription().getVersion(); + } + + public String onPlaceholderRequest(Player p, String indentifier) { + if (p == null) { return ""; } + if (indentifier.equalsIgnoreCase("money")) { + return String.valueOf(BankAPI.getMoney(p.getName())); + } + if (indentifier.equalsIgnoreCase("points")) { + return String.valueOf(BankAPI.getPoints(p.getName())); + } + return ""; + } + + +} diff --git a/src/main/java/me/demon/bank/command/BankCommand.java b/src/main/java/me/demon/bank/command/BankCommand.java new file mode 100644 index 0000000..15b977a --- /dev/null +++ b/src/main/java/me/demon/bank/command/BankCommand.java @@ -0,0 +1,79 @@ +package me.demon.bank.command; + +import me.Demon.DemonPlugin.DemonAPI; +import me.demon.bank.BankAPI; +import me.demon.bank.Main; +import org.bukkit.Sound; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class BankCommand implements CommandExecutor { + + public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) { + if (CommandLabel.equalsIgnoreCase("bank")) { + String prefix = Main.prefix; + if(args.length == 0){ + if(sender instanceof Player) { + Player p = (Player) sender; + JieSuanBank(p); + }else{ + sender.sendMessage(""); + sender.sendMessage("§e------- ======= §6魂式银行 §e======= -------"); + sender.sendMessage("§2/bank reset §e[玩家名] §f- §2清理玩家余额"); + sender.sendMessage("§e------- ======= §6魂式银行 §e======= -------"); + sender.sendMessage("§2作者QQ: §e1763917516"); + } + } + // bank [name] amount + if(args.length == 2 && sender.isOp()){ + Player player = (Player) sender; + int money = Integer.parseInt(args[0]); + BankAPI.addVault(player,money); + sender.sendMessage(Main.prefix+" "+player.getName()+" += "+money); + } + if(args.length == 2 && sender.isOp()){ + if(args[0].equalsIgnoreCase("text")){ + BankAPI.setMoney(sender.getName(), Integer.parseInt(args[1])); + BankAPI.setPoints(sender.getName(), Integer.parseInt(args[1])); + sender.sendMessage(prefix+"成功设置玩家银行数据."); + } + if(args[0].equalsIgnoreCase("reset")){ + String playName = args[1]; + BankAPI.setMoney(playName,0); + BankAPI.setPoints(playName,0); + sender.sendMessage(prefix+"成功重置玩家银行账户数据."); + } + } + } + return true; + } + + public void JieSuanBank(Player p){ + int money = BankAPI.getMoney(p.getName()); + int points = BankAPI.getPoints(p.getName()); + int moneyUUID = BankAPI.getMoneyUUID(String.valueOf(p.getUniqueId())); + if(money == 0 && points == 0 && moneyUUID == 0){ + p.sendMessage(Main.prefix+"暂无任何银行收益,无法进行结算!"); + return; + } + if(money != 0){ + DemonAPI.giveMoney(p,money); + BankAPI.setMoney(p.getName(),0); + p.sendMessage(Main.prefix + "已为你自动结算银行收益: §6" + money + "金币"); + } + if(points != 0){ + DemonAPI.givePoints(p,points); + BankAPI.setPoints(p.getName(),0); + p.sendMessage(Main.prefix + "已为你自动结算银行收益: §d" + points + "点券"); + } + if(moneyUUID >= 1){ + DemonAPI.giveMoney(p,moneyUUID); + BankAPI.setMoneyUUID(String.valueOf(p.getUniqueId()),0); + p.sendMessage(Main.prefix + "已为你自动结算商店收益: §6" + moneyUUID + "金币"); + } + Main.plugin.saveConfig(); + p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP,1,2); + } +} diff --git a/src/main/java/me/demon/bank/listener/JoinEvent.java b/src/main/java/me/demon/bank/listener/JoinEvent.java new file mode 100644 index 0000000..412018b --- /dev/null +++ b/src/main/java/me/demon/bank/listener/JoinEvent.java @@ -0,0 +1,45 @@ +package me.demon.bank.listener; + +import me.Demon.DemonPlugin.DemonAPI; +import me.demon.bank.BankAPI; +import me.demon.bank.Main; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +public class JoinEvent implements Listener { + + @EventHandler + public void onjoin(PlayerJoinEvent e) { + Player p = e.getPlayer(); + Bukkit.getScheduler().runTaskLater(Main.plugin, new Runnable() { + @Override + public void run() { + int money = BankAPI.getMoney(p.getName()); + int points = BankAPI.getPoints(p.getName()); + int moneyUUID = BankAPI.getMoneyUUID(String.valueOf(p.getUniqueId())); + if (money == 0 && points == 0 && moneyUUID == 0) { + return; + } + if (money != 0) { + DemonAPI.giveMoney(p, money); + BankAPI.setMoney(p.getName(), 0); + p.sendMessage(Main.prefix + "已为你自动结算银行收益: §6" + money + "金币"); + } + if (points != 0) { + DemonAPI.givePoints(p, points); + BankAPI.setPoints(p.getName(), 0); + p.sendMessage(Main.prefix + "已为你自动结算银行收益: §d" + points + "点券"); + } + if (moneyUUID != 0) { + DemonAPI.giveMoney(p, moneyUUID); + BankAPI.setMoneyUUID(String.valueOf(p.getUniqueId()), 0); + p.sendMessage(Main.prefix + "已为你自动结算商店收益: §6" + moneyUUID + "金币"); + } + } + }, 40L); + } + +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..fbc455a --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,5 @@ +BankStats: + 虎牙妖魂吖99999999: + Money: 1000 + Points: 1 + Coins: 0 \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..aea889d --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,6 @@ +name: DemonBanK +main: me.demon.bank.Main +version: 1.0.1 +depend: [DemonAPI] +commands: + bank: \ No newline at end of file