Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Feb 15, 2024
0 parents commit 3a0bfd2
Show file tree
Hide file tree
Showing 8 changed files with 577 additions and 0 deletions.
113 changes: 113 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
71 changes: 71 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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>de.tubyoub</groupId>
<artifactId>CombatLogger</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>CombatLogging</name>

<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</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.2.4</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>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.13-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
27 changes: 27 additions & 0 deletions src/main/java/de/tubyoub/combatlogger/CombatLoggerPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package de.tubyoub.combatlogger;

import de.tubyoub.combatlogger.Commands.CombatLoggerCommand;
import de.tubyoub.combatlogger.Listeners.CombatListener;
import org.bukkit.plugin.java.JavaPlugin;

public class CombatLoggerPlugin extends JavaPlugin {

private CombatManager combatManager;

@Override
public void onEnable() {
getConfig().options().copyDefaults(true);
saveConfig();

int combatTimeoutInSeconds = getConfig().getInt("combatTimeoutInSeconds");

CombatManager combatManager = new CombatManager(this, combatTimeoutInSeconds);

getServer().getPluginManager().registerEvents(new CombatListener(this, combatTimeoutInSeconds), this);

getCommand("combatlogger").setExecutor(new CombatLoggerCommand(combatManager,this));
}
@Override
public void onDisable() {
}
}
161 changes: 161 additions & 0 deletions src/main/java/de/tubyoub/combatlogger/CombatManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package de.tubyoub.combatlogger;

import org.bukkit.Bukkit;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public class CombatManager {

private Map<UUID, Long> combatTimers = new HashMap<>();
private Map<UUID, Long> lastHitTimes = new HashMap<>();
private Map<UUID, Integer> combatStatus = new HashMap<>();
private Map<UUID, BossBar> bossBars = new HashMap<>();

private int combatTimeoutInSeconds;
private CombatLoggerPlugin plugin;

public CombatManager(CombatLoggerPlugin plugin, int combatTimeoutInSeconds) {
this.plugin = plugin;
this.combatTimeoutInSeconds = combatTimeoutInSeconds;

new BukkitRunnable() {
@Override
public void run() {
checkTimers();
}
}.runTaskTimer(plugin, 20, 20);
}

public void handlePlayerQuit(Player player) {
UUID playerId = player.getUniqueId();

if (combatTimers.containsKey(playerId)) {
long logoutTime = System.currentTimeMillis();
long lastCombatTime = combatTimers.get(playerId);
if (combatTimers.get(playerId) != null) {
player.sendMessage("You are no longer in combat.");
removeBossBar(player);
}
if (logoutTime - lastCombatTime <= combatTimeoutInSeconds * 1000) {
long remainingTime = (lastCombatTime + combatTimeoutInSeconds * 1000) - logoutTime;
if (remainingTime > 0) {
Bukkit.getScheduler().runTaskLater(plugin, () -> {
Player target = Bukkit.getPlayer(playerId);
if (target != null && target.isOnline()) {
target.setHealth(0);
target.sendMessage("You died because you logged out during combat.");
}
}, remainingTime / 50);
}
}

combatTimers.remove(playerId);
combatStatus.remove(playerId);
removeBossBar(player);
}
}



public void handlePlayerDeath(Player player) {
combatTimers.remove(player.getUniqueId());

combatStatus.remove(player.getUniqueId());
}

public void startCombatTimer(Player player) {
UUID playerId = player.getUniqueId();
combatTimers.put(playerId, System.currentTimeMillis());
createBossBar(player);
}

public void stopCombatTimer(Player player) {
UUID playerId = player.getUniqueId();
combatTimers.remove(playerId);
removeBossBar(player);
}
public void resetCombatTimer(Player player) {
combatTimers.put(player.getUniqueId(), System.currentTimeMillis());
}

public void handlePlayerHit(Player player) {
UUID playerId = player.getUniqueId();

if (!combatTimers.containsKey(playerId)) {
startCombatTimer(player);
player.sendMessage("You entered combat!");
} else {
resetCombatTimer(player);
}
}

public List<String> getPlayersInCombat() {
List<String> playersInCombat = new ArrayList<>();
for (UUID playerId : combatStatus.keySet()) {
Player player = Bukkit.getPlayer(playerId);
if (player != null && combatStatus.get(playerId) == 1) {
playersInCombat.add(player.getName());
}
}
return playersInCombat;
}

private void checkTimers() {
long currentTime = System.currentTimeMillis();
for (UUID playerId : combatTimers.keySet()) {
long lastCombatTime = combatTimers.get(playerId);
if (combatTimers.get(playerId) != null){
Player player = plugin.getServer().getPlayer(playerId);
player.sendMessage("You are no longer in combat.");
removeBossBar(player);
}
if (currentTime - lastCombatTime >= combatTimeoutInSeconds * 1000) {
combatTimers.remove(playerId);
combatStatus.remove(playerId);
Player player = plugin.getServer().getPlayer(playerId);
if (player != null) {
player.sendMessage("You are no longer in combat.");
removeBossBar(player);
}
} else {
Player player = plugin.getServer().getPlayer(playerId);
if (player != null) {
BossBar bossBar = bossBars.get(playerId);
if (bossBar != null) {
long timeLeft = lastCombatTime + (combatTimeoutInSeconds * 1000) - currentTime;
double progress = (double) timeLeft / (combatTimeoutInSeconds * 1000);
bossBar.setProgress(progress);
}
}
}
}
}


private void createBossBar(Player player) {
UUID playerId = player.getUniqueId();
BossBar bossBar = Bukkit.createBossBar("Combat Timer", BarColor.RED, BarStyle.SOLID);
bossBar.setProgress(1.0);
bossBar.addPlayer(player);
bossBars.put(playerId, bossBar);
}

private void removeBossBar(Player player) {
UUID playerId = player.getUniqueId();
BossBar bossBar = bossBars.get(playerId);
if (bossBar != null) {
bossBar.removeAll();
bossBars.remove(playerId);
}
}

}
Loading

0 comments on commit 3a0bfd2

Please sign in to comment.