测试版

This commit is contained in:
tianyu 2024-07-24 05:55:18 +08:00
commit 986cd85859
8 changed files with 343 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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<Player, Long> lastCommandTime = new HashMap<>();
public static HashMap<Player,BankData> 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插件已安全卸載");
}
}

View File

@ -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 "";
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -0,0 +1,5 @@
BankStats:
虎牙妖魂吖99999999:
Money: 1000
Points: 1
Coins: 0

View File

@ -0,0 +1,6 @@
name: DemonBanK
main: me.demon.bank.Main
version: 1.0.1
depend: [DemonAPI]
commands:
bank: