测试版

This commit is contained in:
tianyu 2024-07-24 19:32:43 +08:00
commit a4ec6935bd
10 changed files with 648 additions and 0 deletions

40
.gitignore vendored Normal file
View File

@ -0,0 +1,40 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
/.idea/
/out/

42
pom.xml Normal file
View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>DemonPay</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>public-rpg</id>
<url>https://repo.aurora-pixels.com/repository/public-rpg/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2</version>
</dependency>
<dependency>
<groupId>me.Demon.DemonPlugin</groupId>
<artifactId>DemonAPI</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>cn.hamster3.cdapi</groupId>
<artifactId>CDTimeAPI</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,151 @@
package me.Demon.DemonPay;
import me.Demon.DemonPay.command.DpayCommand;
import me.Demon.DemonPay.command.MpayCommand;
import me.Demon.DemonPay.util.SqlUtil;
import me.Demon.DemonPay.util.database.SqlManager;
import me.Demon.DemonPlugin.DemonAPI;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap;
public class Main extends JavaPlugin {
public static Main plugin;
public static String prefix = "§7[§6货币贸易§7] §f";
public static HashMap<Player, PLimitData> dataAPI = new HashMap<>();
private SqlUtil sqlUtil;
private SqlManager sqlManager;
public SqlUtil getSqlUtil() {
return sqlUtil;
}
public SqlManager getSqlManager() {
return sqlManager;
}
public void onEnable() {
plugin = this;
getCommand("dpay").setExecutor(new DpayCommand());
getCommand("pay").setExecutor(new MpayCommand());
Bukkit.getConsoleSender().sendMessage("§b[DemonPay] §a插件成功载入Sever");
Bukkit.getConsoleSender().sendMessage("§b[DemonPay] §a作者QQ:1763917516");
// 数据库配置
// sqlManager = new SqlManager(this);
// String SQL_Host = DemonMySql.SQL_Host;
// String SQL_Port = DemonMySql.SQL_Port;
// String SQL_Database = DemonMySql.SQL_Database;
// String SQL_Users = DemonMySql.SQL_Users;
// String SQL_Password = DemonMySql.SQL_Password;
// sqlUtil = new SqlUtil(this, SQL_Host, SQL_Port, SQL_Database, SQL_Users, SQL_Password);
// sqlManager.createTable();
}
public void onDisable() {
Bukkit.getConsoleSender().sendMessage("§b[DemonPay] §c插件成功卸载");
}
public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) {
if ((CommandLabel.equalsIgnoreCase("eco")) && (sender.isOp())) {
if (args.length == 0) {
sender.sendMessage("======== " + prefix + "========");
sender.sendMessage("§7/eco look <name> §6: 查询某玩家的金币");
sender.sendMessage("§7/eco give <name> [money] §6: 给予某玩家金币");
sender.sendMessage("§7/eco giveall [money] §6: 给予在线玩家金币");
sender.sendMessage("§7/eco take <name> [money] §6: 扣除某玩家的金币");
sender.sendMessage("§7/eco set <name> [money] §6: 设置某玩家的金币");
sender.sendMessage("§7/eco reset <name> §c: 重置某玩家的金币为0");
return true;
}
if (args.length == 2) {
if (args[0].equalsIgnoreCase("reset")) {
OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]);
DemonAPI.takeMoney(player, DemonAPI.seeMoney(player));
sender.sendMessage(prefix + "成功清空玩家§a" + player.getName() + "§f的金币.");
}
}
if (args.length == 2) {
if (args[0].equalsIgnoreCase("look")) {
OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]);
sender.sendMessage(prefix + "玩家 §a" + player.getName() + " §f有 §a" + DemonAPI.seeMoney(player) + " §f金币");
}
if (args[0].equalsIgnoreCase("giveall")) {
int money = Integer.parseInt(args[1]);
int amount = 0;
for (Player allp : Bukkit.getOnlinePlayers()) {
allp.sendMessage(prefix + "你从 §c管理员 §f那收到了 §e" + money + " §f金币");
DemonAPI.giveMoney(allp, money);
amount++;
}
sender.sendMessage(prefix + "成功给在线 §a" + amount + " §f名玩家发放金币 总计: §e" + (money * amount) + " §f金币");
}
}
if (args.length == 3) {
if (args[0].equalsIgnoreCase("give")) {
OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]);
int money = Integer.parseInt(args[2]);
if (money >= 1) {
DemonAPI.giveMoney(player, money);
sender.sendMessage(prefix + "玩家 §a" + player.getName() + " §f有 §a" + DemonAPI.seeMoney(player) + " §f金币");
}
}
if (args[0].equalsIgnoreCase("take")) {
OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]);
int money = Integer.parseInt(args[2]);
if (money >= 1) {
if (DemonAPI.hasMoney(player, money)) {
DemonAPI.takeMoney(player, money);
sender.sendMessage(prefix + "玩家 §a" + player.getName() + " §f有 §a" + DemonAPI.seeMoney(player) + " §f金币");
} else {
sender.sendMessage(prefix + "没有足够的金币用于扣除.");
}
}
}
if (args[0].equalsIgnoreCase("set")) {
OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]);
//获取玩家要设置的金额数
int money = Integer.parseInt(args[2]);
//判断玩家余额是否大于Money
if (DemonAPI.seeMoney(player) >= money) {
//获取玩家余额
int Y = (int) DemonAPI.seeMoney(player);
// Y = 50000
// X = 80000
//我想得出 Z = 30000
//也就是 X - Y = Z
int Z = money - Y;
DemonAPI.giveMoney(player, Z);
sender.sendMessage(prefix + "玩家 §a" + player.getName() + " §f有 §a" + DemonAPI.seeMoney(player) + " §f金币");
} else {
//获取玩家余额
int Y = (int) DemonAPI.seeMoney(player);
// Y = 50000
// X = 1000
//我想得出 Z = 49000
//也就是 Y - (Y-X) = Z
int Z = Y - (Y - money);
DemonAPI.takeMoney(player, (Y - Z));
sender.sendMessage(prefix + "玩家 §a" + player.getName() + " §f有 §a" + DemonAPI.seeMoney(player) + " §f金币");
}
}
}
}
return true;
}
public static boolean isInt(String s) {
try {
Integer.parseInt(s);
} catch (NumberFormatException nfe) {
return false;
}
return true;
}
}

View File

@ -0,0 +1,59 @@
package me.Demon.DemonPay;
import me.Demon.DemonPay.util.database.SqlManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.Date;
public class PLimitData {
private final Player p;
private int limit;
private String updata_time;
public PLimitData(Player p){
this.p = p;
SqlManager sqlManager = Main.plugin.getSqlManager();
String playerData = sqlManager.getPlayerData(p.getName());
if(playerData == null){
sqlManager.createPlayerTableData(p);
playerData = sqlManager.getPlayerData(p.getName());
}
// 获取数据库中上次数据刷新时间
String Todaytime = playerData.split("#")[1];
Date date = new Date();
// 获取今天是几月几号 时间是否与数据库数据匹配
String time = date.getMonth()+"."+date.getDate();
if(Todaytime.equalsIgnoreCase(time)) {
this.limit = Integer.parseInt(playerData.split("#")[0]);
this.updata_time = playerData.split("#")[1];
}else{
this.updata_time = time;
this.limit = 200;
if(p.hasPermission("vip1.use")){
this.limit = 800;
}else if(p.hasPermission("yuanzu.use")){
this.limit = 600;
}else if(p.hasPermission("lianjinshi.use")){
this.limit = 400;
}
Bukkit.getConsoleSender().sendMessage("§d[点券限额] §f玩家"+p.getName()+"的每日额度已刷新.");
Main.plugin.getSqlManager().SaverPlayerData(p);
}
}
public int getLimit() {
return limit;
}
public void setLimit(int limit) {
this.limit = limit;
}
public String getUpdata_time() {
return updata_time;
}
}

View File

@ -0,0 +1,74 @@
package me.Demon.DemonPay.command;
import cn.hamster3.cdapi.CDTimeAPI;
import me.Demon.DemonPay.Main;
import me.Demon.DemonPay.PLimitData;
import me.Demon.DemonPlugin.DemonAPI;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class DpayCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
String prefix = Main.prefix;
Player p = (Player) sender;
if(!p.hasPermission("demonpay.points")){
sender.sendMessage(prefix+"你需要成为 §c【领域炼金师】 §f才能使用此命令.");
return true;
}
if (args.length == 2) {
if(!Main.isInt(args[1])){
sender.sendMessage(prefix+"正确用法: §a/dpay [玩家ID] [金额]");
return true;
}
Player otherPlayer = Bukkit.getPlayer(args[0]);
if (otherPlayer == null) {
sender.sendMessage(prefix + "目标玩家不在线");
return true;
}
if (p.getName().equalsIgnoreCase(otherPlayer.getName())){
sender.sendMessage(prefix + "无法向自己发起转账");
return true;
}
if (CDTimeAPI.getCD(p.getUniqueId(), "PayCD") > 0) {
sender.sendMessage(prefix + "支付系统正在冷却...");
return true;
}
int points = Integer.parseInt(args[1]);
if (points < 5) {
sender.sendMessage(prefix + "支付金额必须大于 §d5.0点券");
return true;
}
if (!DemonAPI.hasPoints(p, points)) {
sender.sendMessage(prefix + "没有足够的点券!");
return true;
}
// 若无此权限将会进行额度检测
if(!p.hasPermission("demonpay.pointspro")) {
if (Main.dataAPI.get(p) == null) {
Main.dataAPI.put(p, new PLimitData(p));
}
PLimitData dataAPI = Main.dataAPI.get(p);
int limit = dataAPI.getLimit();
int newLimit = limit - points;
if (newLimit <= -1) {
sender.sendMessage(prefix+"转账失败,您的今日点券额度不足.");
return true;
}
dataAPI.setLimit(newLimit);
}
DemonAPI.takePoints(p, points);
DemonAPI.givePoints(otherPlayer, points);
CDTimeAPI.setPlayerCD(p.getUniqueId(),"PayCD",1000 * 10);
sender.sendMessage(prefix+"你向 §a" + otherPlayer.getName() + " §f支付了 §a" + points + " §f点券");
otherPlayer.sendMessage(prefix+"你从 §a" + sender.getName() + " §f收到了 §a" + points + " §f点券");
} else {
sender.sendMessage(prefix+"正确用法: §a/dpay [玩家ID] [金额]");
}
return false;
}
}

View File

@ -0,0 +1,59 @@
package me.Demon.DemonPay.command;
import cn.hamster3.cdapi.CDTimeAPI;
import me.Demon.DemonPay.Main;
import me.Demon.DemonPlugin.DemonAPI;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class MpayCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
String prefix = Main.prefix;
Player p = (Player) sender;
if (!p.hasPermission("demonpay.money")) {
sender.sendMessage(prefix + "你需要成为 §2【领域农民】 §f才能使用此命令.");
return true;
}
if (args.length == 2) {
if (!Main.isInt(args[1])) {
sender.sendMessage(prefix + "正确用法: §a/pay [玩家ID] [金额]");
return true;
}
Player otherPlayer = Bukkit.getPlayer(args[0]);
if (otherPlayer == null) {
sender.sendMessage(prefix + "目标玩家不在线");
return true;
}
if (p.getName().equalsIgnoreCase(otherPlayer.getName())) {
sender.sendMessage(prefix + "无法向自己发起转账");
return true;
}
if (CDTimeAPI.getCD(p.getUniqueId(), "PayCD") > 0) {
sender.sendMessage(prefix + "支付系统正在冷却...");
return true;
}
int money = Integer.parseInt(args[1]);
if (money < 100) {
sender.sendMessage(prefix + "支付金额必须大于§6 $100.0");
return true;
}
if (DemonAPI.hasMoney(p, money)) {
DemonAPI.takeMoney(p, money);
DemonAPI.giveMoney(otherPlayer, money);
CDTimeAPI.setPlayerCD(p.getUniqueId(), "PayCD", 1000 * 10);
sender.sendMessage(prefix + "你向 §a" + otherPlayer.getName() + " §f支付了 §a" + money + " §f金币");
otherPlayer.sendMessage(prefix + "你从 §a" + sender.getName() + " §f收到了 §a" + money + " §f金币");
} else {
sender.sendMessage(prefix + "没有足够的钱!");
}
} else {
sender.sendMessage(prefix + "正确用法: §a/pay [玩家ID] [金额]");
}
return false;
}
}

View File

@ -0,0 +1,108 @@
package me.Demon.DemonPay.util;
import me.Demon.DemonPay.Main;
import me.Demon.DemonPay.util.database.MegumiSQL;
import org.bukkit.Bukkit;
import java.sql.*;
public class SqlUtil extends MegumiSQL {
private Main plugin;
private final String hostname;
private final String port;
private final String database;
private final String username;
private final String password;
private Connection connection;
public SqlUtil(Main plugin, String hostname, String port, String database, String username, String password) {
this.plugin = plugin;
this.hostname = hostname;
this.port = port;
this.database = database;
this.username = username;
this.password = password;
this.connection = null;
}
@Override
public void openConnection() {
try {
Class.forName("com.mysql.jdbc.Driver");
this.connection = DriverManager.getConnection("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database + "?useSSL=false", this.username, this.password);
} catch (SQLException e) {
Bukkit.getConsoleSender().sendMessage("§6[点券限额] §c数据库连接失败");
this.connection = null;
} catch (ClassNotFoundException e) {
Bukkit.getConsoleSender().sendMessage("§6[点券限额] §c未找到JDBC驱动程序");
this.connection = null;
}
}
@Override
public boolean checkConnection() {
return this.connection != null;
}
@Override
public Connection getConnection() {
return this.connection;
}
@Override
public void closeConnection() {
if (this.connection != null) {
try {
this.connection.close();
this.connection = null;
} catch (SQLException e) {
Bukkit.getConsoleSender().sendMessage("§6[点券限额] §c关闭数据库失败");
e.printStackTrace();
}
}
}
public ResultSet querySQL(String query) {
Connection conn;
if (checkConnection())
conn = getConnection();
else
return null;
Statement stat = null;
try {
stat = conn.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
ResultSet result = null;
try {
if (stat != null)
result = stat.executeQuery(query);
else
return null;
} catch (SQLException e) {
e.printStackTrace();
return null;
}
return result;
}
public boolean updateSQL(String data) {
Connection conn;
if (checkConnection()) {
conn = getConnection();
} else {
return false;
}
Statement stat = null;
try {
stat = conn.createStatement();
stat.executeUpdate(data);
return true;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
}

View File

@ -0,0 +1,15 @@
package me.Demon.DemonPay.util.database;
import java.sql.Connection;
public abstract class MegumiSQL {
public abstract void openConnection();
public abstract boolean checkConnection();
public abstract Connection getConnection();
public abstract void closeConnection();
}

View File

@ -0,0 +1,93 @@
package me.Demon.DemonPay.util.database;
import me.Demon.DemonPay.Main;
import me.Demon.DemonPay.PLimitData;
import me.Demon.DemonPay.util.SqlUtil;
import org.bukkit.entity.Player;
import java.sql.ResultSet;
import java.util.Date;
import java.util.List;
public class SqlManager {
private Main plugin;
public String table = "demonpay_points";
public SqlManager(Main plugin) {
this.plugin = plugin;
}
private SqlUtil getSQL() {
return plugin.getSqlUtil();
}
// 创建数据库表格格式
public void createTable() {
// 数据库结构组成
// 玩家名(VARCHAR)
// UUID(VARCHAR)
// 已转账金额(VARCHAR)
// 刷新时间(VARCHAR)
String s = "CREATE TABLE IF NOT EXISTS " + table + "(" +
" `name` VARCHAR(64) NOT NULL," +
" `uuid` VARCHAR(64) NOT NULL," +
" `limit` VARCHAR(16) NOT NULL," +
" `date` VARCHAR(10) NOT NULL" +
") ENGINE = InnoDB";
getSQL().openConnection();
getSQL().updateSQL(s);
getSQL().closeConnection();
}
// 创建玩家数据表格
public void createPlayerTableData(Player p) {
String set = "INSERT INTO " + table + " (`name`, `uuid`, `limit`, `date`) VALUES ('%name%','%uuid%','%limit%','%date%')";
getSQL().openConnection();
Date date = new Date();
getSQL().updateSQL(set.replace("%name%", p.getName())
.replace("%uuid%", String.valueOf(p.getUniqueId()))
.replace("%limit%", "0")
.replace("%updata%", date.getMonth() + "." + date.getDate()));
getSQL().closeConnection();
}
// 从数据库中获取玩家所有数据
public String getPlayerData(String playName) {
String string = null;
String select = "SELECT * FROM " + table + " WHERE name = '%playerName%'";
try {
getSQL().openConnection();
ResultSet set = getSQL().querySQL(select.replace("%playerName%", playName));
if (set.next()) {
String jieshou = set.getString("limit");
String update = set.getString("date");
string = update + "#" + jieshou;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
getSQL().closeConnection();
}
return string;
}
// 保存玩家在DataAPI中的数据
public void SaverPlayerData(Player player) {
if (Main.dataAPI.get(player) == null) {
return;
}
PLimitData dataAPI = Main.dataAPI.get(player);
String update_time = dataAPI.getUpdata_time();
String limit = String.valueOf(dataAPI.getLimit());
String set = "UPDATE `" + table + "` SET " +
"`limit` = '%limit%'," +
"`date` = '%date%' WHERE `" + table + "`.`name` = '%player%'";
getSQL().openConnection();
getSQL().updateSQL(set.replace("%player%", player.getName()).
replace("%limit%", limit)
.replace("%date%", update_time));
getSQL().closeConnection();
}
}

View File

@ -0,0 +1,7 @@
main: me.Demon.DemonPay.Main
name: DemonPay
version: 1.0.2
commands:
pay:
dpay:
eco: