commit 8e9e5d6883c1d26311b3f92fb1343431b12562e3 Author: Kyoukawa Meishin Date: Thu Oct 16 13:16:59 2025 +0800 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..480bdf5 --- /dev/null +++ b/.gitignore @@ -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 \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..359bb53 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..eda147d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..bcae94a --- /dev/null +++ b/pom.xml @@ -0,0 +1,42 @@ + + 4.0.0 + org.example + HelloPlugin + 1.0 + + + + central + https://repo.maven.apache.org/maven2/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + jitpack-io + https://jitpack.io/ + + + + + + org.spigotmc + spigot-api + 1.21.8-R0.1-SNAPSHOT + provided + + + com.github.MilkBowl + VaultAPI + 1.7 + provided + + + org.jetbrains + annotations + 24.1.0 + compile + + + diff --git a/src/main/java/org/example/HelloPlugin/CheckinCommand.java b/src/main/java/org/example/HelloPlugin/CheckinCommand.java new file mode 100644 index 0000000..fa6a105 --- /dev/null +++ b/src/main/java/org/example/HelloPlugin/CheckinCommand.java @@ -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 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; + } +} diff --git a/src/main/java/org/example/HelloPlugin/HelloPlugin.java b/src/main/java/org/example/HelloPlugin/HelloPlugin.java new file mode 100644 index 0000000..9010a4d --- /dev/null +++ b/src/main/java/org/example/HelloPlugin/HelloPlugin.java @@ -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 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(); + } + } +} diff --git a/src/main/java/org/example/HelloPlugin/WelcomeMessageListener.java b/src/main/java/org/example/HelloPlugin/WelcomeMessageListener.java new file mode 100644 index 0000000..565a827 --- /dev/null +++ b/src/main/java/org/example/HelloPlugin/WelcomeMessageListener.java @@ -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"); + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..05620ff --- /dev/null +++ b/src/main/resources/plugin.yml @@ -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 \ No newline at end of file