Initial commit
This commit is contained in:
commit
8e9e5d6883
39
.gitignore
vendored
Normal file
39
.gitignore
vendored
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
.kotlin
|
||||||
|
|
||||||
|
### 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
|
||||||
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# 默认忽略的文件
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
7
.idea/encodings.xml
generated
Normal file
7
.idea/encodings.xml
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
14
.idea/misc.xml
generated
Normal file
14
.idea/misc.xml
generated
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_24" default="true" project-jdk-name="24" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
42
pom.xml
Normal file
42
pom.xml
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<project>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.example</groupId>
|
||||||
|
<artifactId>HelloPlugin</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>central</id>
|
||||||
|
<url>https://repo.maven.apache.org/maven2/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>spigot-repo</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>jitpack-io</id>
|
||||||
|
<url>https://jitpack.io/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.21.8-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.MilkBowl</groupId>
|
||||||
|
<artifactId>VaultAPI</artifactId>
|
||||||
|
<version>1.7</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains</groupId>
|
||||||
|
<artifactId>annotations</artifactId>
|
||||||
|
<version>24.1.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
79
src/main/java/org/example/HelloPlugin/CheckinCommand.java
Normal file
79
src/main/java/org/example/HelloPlugin/CheckinCommand.java
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
package org.example.HelloPlugin;
|
||||||
|
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class CheckinCommand implements CommandExecutor {
|
||||||
|
private final HashMap<UUID, LocalDate> lastCheckin = new HashMap<>();
|
||||||
|
private final HelloPlugin plugin;
|
||||||
|
|
||||||
|
public CheckinCommand(HelloPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
|
if (!sender.hasPermission("org.example.checkin")) {
|
||||||
|
sender.sendMessage("§c拒绝访问。");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
UUID uuid = player.getUniqueId();
|
||||||
|
LocalDate today = LocalDate.now();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 查询玩家上次签到时间
|
||||||
|
PreparedStatement ps = plugin.getConnection().prepareStatement("SELECT last_checkin FROM checkin WHERE uuid = ?");
|
||||||
|
ps.setString(1, uuid.toString());
|
||||||
|
ResultSet rs = ps.executeQuery();
|
||||||
|
|
||||||
|
if (rs.next()) {
|
||||||
|
String lastDate = rs.getString("last_checkin");
|
||||||
|
if (today.toString().equals(lastDate)) {
|
||||||
|
player.sendMessage("§e你今天已经签到过了!");
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
|
||||||
|
// 更新或插入签到记录
|
||||||
|
PreparedStatement update = plugin.getConnection().prepareStatement(
|
||||||
|
"INSERT OR REPLACE INTO checkin (uuid, last_checkin) VALUES (?, ?)");
|
||||||
|
update.setString(1, uuid.toString());
|
||||||
|
update.setString(2, today.toString());
|
||||||
|
update.executeUpdate();
|
||||||
|
update.close();
|
||||||
|
|
||||||
|
// 发放经济奖励
|
||||||
|
Economy econ = HelloPlugin.getEconomy();
|
||||||
|
double reward = 100.0;
|
||||||
|
econ.depositPlayer(player, reward);
|
||||||
|
|
||||||
|
player.sendMessage("§a签到成功!你获得了 §6" + reward + " §a金币。");
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
player.sendMessage("§c签到时发生错误,请联系管理员。");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
sender.sendMessage("§6没活可以咬打火机");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
87
src/main/java/org/example/HelloPlugin/HelloPlugin.java
Normal file
87
src/main/java/org/example/HelloPlugin/HelloPlugin.java
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
package org.example.HelloPlugin;
|
||||||
|
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.permissions.PermissionDefault;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.permissions.Permission;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class HelloPlugin extends JavaPlugin {
|
||||||
|
public static final Permission CHECKIN_PERM = new Permission(
|
||||||
|
"org.example.checkin",
|
||||||
|
"签到",
|
||||||
|
PermissionDefault.TRUE
|
||||||
|
);
|
||||||
|
private static Economy econ = null;
|
||||||
|
private static Connection connection;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
if (!setupEconomy()) {
|
||||||
|
getLogger().severe("No compatible economy provider found!");
|
||||||
|
getServer().getPluginManager().disablePlugin(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setupDatabase();
|
||||||
|
getLogger().info("Plugin activated successfully");
|
||||||
|
PluginManager pm = getServer().getPluginManager();
|
||||||
|
pm.addPermission(CHECKIN_PERM);
|
||||||
|
pm.registerEvents(new WelcomeMessageListener(), this);
|
||||||
|
Objects.requireNonNull(getCommand("checkin")).setExecutor(new CheckinCommand(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
getLogger().info("Plugin disabled successfully");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Economy getEconomy() {
|
||||||
|
return econ;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Connection getConnection() {
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean setupEconomy() {
|
||||||
|
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
RegisteredServiceProvider<Economy> rsp = Bukkit.getServicesManager().getRegistration(Economy.class);
|
||||||
|
if (rsp == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
econ = rsp.getProvider();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupDatabase() {
|
||||||
|
try {
|
||||||
|
File dbFile = new File(getDataFolder(), "data.db");
|
||||||
|
if (!getDataFolder().exists()) {
|
||||||
|
getDataFolder().mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
connection = DriverManager.getConnection("jdbc:sqlite:" + dbFile.getAbsolutePath());
|
||||||
|
Statement stmt = connection.createStatement();
|
||||||
|
stmt.executeUpdate("CREATE TABLE IF NOT EXISTS checkin (" +
|
||||||
|
"uuid TEXT PRIMARY KEY," +
|
||||||
|
"last_checkin TEXT" +
|
||||||
|
")");
|
||||||
|
stmt.close();
|
||||||
|
|
||||||
|
getLogger().info("SQLite 数据库初始化成功。");
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
package org.example.HelloPlugin;
|
||||||
|
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
|
public class WelcomeMessageListener implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
event.getPlayer().sendMessage("HI");
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src/main/resources/plugin.yml
Normal file
11
src/main/resources/plugin.yml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
name: HelloPlugin
|
||||||
|
main: org.example.HelloPlugin.HelloPlugin
|
||||||
|
version: 1.0
|
||||||
|
api-version: 1.21
|
||||||
|
author: 杏川铭心
|
||||||
|
description: DOES NOTHING
|
||||||
|
depend: [Vault]
|
||||||
|
commands:
|
||||||
|
checkin:
|
||||||
|
description: 签到(伪)
|
||||||
|
usage: /checkin
|
||||||
Loading…
x
Reference in New Issue
Block a user