Initial version
This commit is contained in:
commit
d9c6d84ad3
7 changed files with 399 additions and 0 deletions
113
.gitignore
vendored
Normal file
113
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
# User-specific stuff
|
||||
.idea/
|
||||
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
Thumbs.db:encryptable
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
target/
|
||||
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
.flattened-pom.xml
|
||||
|
||||
# Common working directory
|
||||
run/
|
||||
84
pom.xml
Normal file
84
pom.xml
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<?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>me.firephoenix</groupId>
|
||||
<artifactId>deathcounter</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>deathcounter</name>
|
||||
|
||||
<properties>
|
||||
<java.version>21</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.5.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>papermc-repo</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>placeholderapi</id>
|
||||
<url>https://repo.extendedclip.com/releases/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.21.10-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc -->
|
||||
<dependency>
|
||||
<groupId>org.xerial</groupId>
|
||||
<artifactId>sqlite-jdbc</artifactId>
|
||||
<version>3.51.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.11.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
89
src/main/java/me/firephoenix/deathcounter/DeathCounter.java
Normal file
89
src/main/java/me/firephoenix/deathcounter/DeathCounter.java
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
package me.firephoenix.deathcounter;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.firephoenix.deathcounter.listener.DeathListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public final class DeathCounter extends JavaPlugin {
|
||||
public String dataBaseURL;
|
||||
public HashMap<UUID, Integer> playerDeaths = new HashMap<>();
|
||||
|
||||
public HashMap<UUID, Integer> getPlayerDeaths() {
|
||||
return playerDeaths;
|
||||
}
|
||||
|
||||
public String getDataBaseURL() {
|
||||
return dataBaseURL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
this.saveDefaultConfig();
|
||||
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new DeathListener(this), this);
|
||||
|
||||
dataBaseURL = "jdbc:sqlite:" + this.getDataPath() + "/deaths.db";
|
||||
|
||||
createSqLiteDatabase();
|
||||
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) { //
|
||||
new DeathPlaceholderExpansion(this).register(); //
|
||||
}
|
||||
}
|
||||
|
||||
private void createSqLiteDatabase() {
|
||||
try (var conn = DriverManager.getConnection(dataBaseURL)) {
|
||||
if (conn != null) {
|
||||
String sql = "CREATE TABLE IF NOT EXISTS deaths_counts ("
|
||||
+ " id BIGINT auto_increment,"
|
||||
+ " uuid VARCHAR(36) NOT NULL UNIQUE,"
|
||||
+ " deaths BIGINT NOT NULL,"
|
||||
+ " primary key (id));";
|
||||
|
||||
Statement statement = conn.createStatement();
|
||||
statement.execute(sql);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public int requestDeathCountForPlayer(UUID uuid) {
|
||||
//Search our cache first
|
||||
if (getPlayerDeaths().containsKey(uuid)) {
|
||||
return getPlayerDeaths().get(uuid);
|
||||
} else {
|
||||
int deaths = 0;
|
||||
try (var conn = DriverManager.getConnection(this.getDataBaseURL())) {
|
||||
if (conn != null) {
|
||||
String getSQL = "SELECT deaths FROM deaths_counts WHERE uuid = " + "'" + uuid + "'" + ";";
|
||||
|
||||
Statement statement = conn.createStatement();
|
||||
ResultSet resultSet = statement.executeQuery(getSQL);
|
||||
|
||||
if (resultSet.next()) {
|
||||
deaths = resultSet.getInt(1);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
getPlayerDeaths().put(uuid, deaths);
|
||||
|
||||
return deaths;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package me.firephoenix.deathcounter;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author NieGestorben
|
||||
* Copyright© (c) 2025, All Rights Reserved.
|
||||
*/
|
||||
public class DeathPlaceholderExpansion extends PlaceholderExpansion {
|
||||
|
||||
DeathCounter plugin;
|
||||
|
||||
public DeathPlaceholderExpansion(DeathCounter plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> getPlaceholders() {
|
||||
ArrayList<String> placeholders = new ArrayList<>();
|
||||
placeholders.add("%deathcount%");
|
||||
|
||||
return placeholders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||
int deaths = plugin.requestDeathCountForPlayer(player.getUniqueId());
|
||||
|
||||
return String.valueOf(deaths);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onPlaceholderRequest(Player player, @NotNull String params) {
|
||||
int deaths = plugin.requestDeathCountForPlayer(player.getUniqueId());
|
||||
|
||||
return String.valueOf(deaths);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "deathcounter";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getAuthor() {
|
||||
return "NieGestorben";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getVersion() {
|
||||
return "1.0.0";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package me.firephoenix.deathcounter.listener;
|
||||
|
||||
import me.firephoenix.deathcounter.DeathCounter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* @author NieGestorben
|
||||
* Copyright© (c) 2025, All Rights Reserved.
|
||||
*/
|
||||
public class DeathListener implements Listener {
|
||||
|
||||
public DeathCounter plugin;
|
||||
|
||||
public DeathListener(DeathCounter plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||
UUID playerUUID = event.getPlayer().getUniqueId();
|
||||
|
||||
try (var conn = DriverManager.getConnection(plugin.getDataBaseURL())) {
|
||||
if (conn != null) {
|
||||
int deaths = plugin.requestDeathCountForPlayer(playerUUID);
|
||||
|
||||
deaths++;
|
||||
|
||||
//Updated cache
|
||||
plugin.getPlayerDeaths().replace(playerUUID, deaths);
|
||||
|
||||
String updateSQL = "REPLACE INTO deaths_counts (uuid, deaths) VALUES ('" + playerUUID + "', " + deaths + ");";
|
||||
|
||||
Statement updateStatement = conn.createStatement();
|
||||
updateStatement.execute(updateSQL);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
0
src/main/resources/config.yml
Normal file
0
src/main/resources/config.yml
Normal file
6
src/main/resources/plugin.yml
Normal file
6
src/main/resources/plugin.yml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
name: DeathCounter
|
||||
version: '1.0'
|
||||
main: me.firephoenix.deathcounter.DeathCounter
|
||||
api-version: '1.21'
|
||||
description: Counts Deaths of all players via Scoreboard and Tablist
|
||||
depend: ["PlaceholderAPI"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue