diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 44fbaea..946ac0d 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -9,8 +9,5 @@
-
-
-
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index 062f6b7..2d43911 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -11,21 +11,26 @@
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
index eecc2ad..9f23a86 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -5,6 +5,7 @@
+
-
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index a90fd61..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/README.md b/README.md
index 8b13789..9270c7a 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,46 @@
+# AugmentedHardcore
+AugmentedHardcore is a [Spigot](https://www.spigotmc.org/) plugin that enhances Minecraft's hardcore mode with lives, death bans, revives, and progression mechanics.
+
+## Build
+
+This project uses Maven and requires Java 8 or newer. To build the plugin run:
+
+```bash
+mvn package
+```
+
+The shaded jar will be created in `target/`. Copy the jar to your server's `plugins` directory and restart the server.
+
+## Usage
+
+On first run the plugin will generate its configuration files. Adjust `config.yml` and `messages.yml` to customize behaviour.
+
+Handy commands include:
+
+- `/augmentedhardcore` – show help and plugin information
+- `/lives` – view your remaining lives
+- `/revive ` – revive a death‑banned player
+
+See the in‑game help for the complete command list and permissions.
+
+## Contributing
+
+Contributions are welcome! If you would like to help:
+
+1. Fork the repository and create a feature branch.
+2. Make your changes following the existing style.
+3. Run `mvn test` to make sure the project builds.
+4. Open a pull request with a clear description of your work.
+
+Please open an issue to discuss major changes before starting.
+
+This repository contains the AugmentedHardcore plugin. Unit tests are located in `src/test/java` and can be executed with Maven.
+
+## Running Tests
+
+```bash
+mvn test
+```
+
+The tests cover core components such as the `Database` and `PlayerData` classes. They rely on Mockito to mock Bukkit APIs where necessary.
diff --git a/pom.xml b/pom.xml
index 1c2c4bc..8d89e83 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,10 +4,10 @@
4.0.0
com.backtobedrock
AugmentedHardcore
- 3.4.0
+ 3.4.2
jar
- 8
+ 17
UTF-8
@@ -25,9 +25,19 @@
sirblobman-public
- https://nexus.sirblobman.xyz/repository/public/
+ https://nexus.sirblobman.xyz/public/
+
+
+ maven-central
+ https://oss.sonatype.org/content/groups/public
+
+
+ maven-central
+ https://repo1.maven.org/maven2/
+
+
src
clean package
@@ -51,8 +61,16 @@
${java.version}
${java.version}
+
+ test/**
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 3.1.2
+
org.apache.maven.plugins
maven-shade-plugin
@@ -71,40 +89,28 @@
-
+
org.spigotmc
spigot-api
- 1.20.1-R0.1-SNAPSHOT
+ 1.21.8-R0.1-SNAPSHOT
provided
me.clip
placeholderapi
- 2.11.1
+ 2.11.6
provided
net.wesjd
anvilgui
- 1.9.0-SNAPSHOT
-
-
- com.zaxxer
- HikariCP
- 5.0.1
- provided
-
-
- org.javatuples
- javatuples
- 1.2
- provided
+ 1.10.2-SNAPSHOT
- com.SirBlobman.combatlogx
- CombatLogX-API
- 10.0.0.0-SNAPSHOT
+ com.github.sirblobman.combatlogx
+ api
+ 11.4-SNAPSHOT
provided
@@ -112,5 +118,17 @@
ConfigUpdater
2.1-SNAPSHOT
-
-
\ No newline at end of file
+
+ com.zaxxer
+ HikariCP
+ 7.0.2
+ provided
+
+
+ org.junit.jupiter
+ junit-jupiter
+ 5.10.2
+ test
+
+
+
\ No newline at end of file
diff --git a/src/com/backtobedrock/augmentedhardcore/AugmentedHardcore.java b/src/com/backtobedrock/augmentedhardcore/AugmentedHardcore.java
index c91270f..94f1969 100644
--- a/src/com/backtobedrock/augmentedhardcore/AugmentedHardcore.java
+++ b/src/com/backtobedrock/augmentedhardcore/AugmentedHardcore.java
@@ -32,6 +32,11 @@
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.*;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.stream.Collectors;
@@ -54,6 +59,21 @@ public class AugmentedHardcore extends JavaPlugin implements Listener {
//runnables
private UpdateChecker updateChecker;
+ //async executor
+ private ExecutorService executor;
+ private final ThreadFactory asyncThreadFactory = new ThreadFactory() {
+ private final AtomicInteger count = new AtomicInteger(1);
+ private final ThreadFactory backingFactory = Executors.defaultThreadFactory();
+
+ @Override
+ public Thread newThread(@NotNull Runnable r) {
+ Thread thread = backingFactory.newThread(r);
+ thread.setName(String.format("AugHC-Async-%d", count.getAndIncrement()));
+ thread.setDaemon(true);
+ return thread;
+ }
+ };
+
@Override
public void onEnable() {
this.initialize();
@@ -64,8 +84,8 @@ public void onEnable() {
//bstats metrics
Metrics metrics = new Metrics(this, 10843);
- metrics.addCustomChart(new Metrics.SingleLineChart("currently_ongoing_death_bans", () -> this.serverRepository.getServerDataSync().getTotalOngoingBans()));
- metrics.addCustomChart(new Metrics.SingleLineChart("total_death_bans", () -> this.serverRepository.getServerDataSync().getTotalDeathBans()));
+ metrics.addCustomChart(new Metrics.SingleLineChart("currently_ongoing_death_bans", () -> (Integer) this.serverRepository.getServerDataSync().getTotalOngoingBans()));
+ metrics.addCustomChart(new Metrics.SingleLineChart("total_death_bans", () -> (Integer) this.serverRepository.getServerDataSync().getTotalDeathBans()));
//PAPI
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
@@ -82,10 +102,29 @@ public void onDisable() {
if (this.getServerRepository() != null) {
ServerData serverData = this.getServerRepository().getServerDataSync();
if (serverData != null) {
- this.getServerRepository().updateServerData(serverData);
+ this.getServerRepository().updateServerData(serverData).join();
}
}
+ if (this.updateChecker != null) {
+ this.updateChecker.stop();
+ }
+
+ if (this.executor != null) {
+ this.executor.shutdown();
+ try {
+ if (!this.executor.awaitTermination(10, TimeUnit.SECONDS)) {
+ this.getLogger().log(Level.WARNING, "Executor did not terminate in the allotted time.");
+ }
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ }
+
+ if (this.getConfigurations() != null && this.getConfigurations().getDataConfiguration().getDatabase() != null) {
+ this.getConfigurations().getDataConfiguration().getDatabase().close();
+ }
+
super.onDisable();
}
@@ -95,34 +134,41 @@ public boolean onCommand(@NotNull CommandSender cs, @NotNull Command cmnd, @NotN
}
public void initialize() {
- //initialize old config directory
+ if (this.executor == null || this.executor.isShutdown()) {
+ this.executor = Executors.newFixedThreadPool(Math.max(2, Runtime.getRuntime().availableProcessors()), this.asyncThreadFactory);
+ }
+
+ this.prepareConfigFiles();
+ this.loadConfigurations();
+ this.setupDatabase();
+ this.initRepositories();
+ this.registerListeners();
+ }
+
+ private void prepareConfigFiles() {
File dir = new File(this.getDataFolder() + "/old");
- List configs = new ArrayList() {{
- add(new File(getDataFolder(), "config.old.yml"));
- add(new File(getDataFolder(), "messages.old.yml"));
- }};
+ List configs = List.of(
+ new File(getDataFolder(), "config.old.yml"),
+ new File(getDataFolder(), "messages.old.yml")
+ );
//noinspection ResultOfMethodCallIgnored
dir.mkdir();
//noinspection ResultOfMethodCallIgnored
configs.stream().filter(File::exists).forEach(File::delete);
- //get config.yml and make if none existent
File configFile = new File(this.getDataFolder(), "config.yml");
if (!configFile.exists()) {
this.getLogger().log(Level.INFO, "Creating {0}.", configFile.getAbsolutePath());
this.saveResource("config.yml", false);
}
- //get messages.yml and make if none existent
File messagesFile = new File(this.getDataFolder(), "messages.yml");
if (!messagesFile.exists()) {
this.getLogger().log(Level.INFO, "Creating {0}.", messagesFile.getAbsolutePath());
this.saveResource("messages.yml", false);
}
- //update configurations
try {
- //config.yml
File copy = new File(this.getDataFolder() + "/old/", "config.old.yml");
if (copy.exists()) {
//noinspection ResultOfMethodCallIgnored
@@ -130,46 +176,32 @@ public void initialize() {
}
Files.copy(configFile.toPath(), copy.toPath());
ConfigUpdater.update(this, "config.yml", configFile, Arrays.asList("LifePartsPerKill", "MaxHealthIncreasePerKill"));
- configFile = new File(this.getDataFolder(), "config.yml");
+ } catch (IOException e) {
+ getLogger().log(Level.SEVERE, "Failed to update config.yml", e);
+ }
- //messages.yml
- copy = new File(this.getDataFolder() + "/old/", "messages.old.yml");
+ try {
+ File copy = new File(this.getDataFolder() + "/old/", "messages.old.yml");
if (copy.exists()) {
//noinspection ResultOfMethodCallIgnored
copy.delete();
}
Files.copy(messagesFile.toPath(), copy.toPath());
ConfigUpdater.update(this, "messages.yml", messagesFile, Collections.emptyList());
- messagesFile = new File(this.getDataFolder(), "messages.yml");
} catch (IOException e) {
- //ignore
+ getLogger().log(Level.SEVERE, "Failed to update messages.yml", e);
}
+ }
- //initialize config and messages
+ private void loadConfigurations() {
+ File configFile = new File(this.getDataFolder(), "config.yml");
+ File messagesFile = new File(this.getDataFolder(), "messages.yml");
this.configurations = new Configurations(configFile);
this.messages = new Messages(messagesFile);
-
- //initialize commands
this.commands = new Commands();
-
- //initialize database if needed
- this.initDB();
-
- //initialize repositories
- if (this.playerRepository == null) {
- this.playerRepository = new PlayerRepository();
- } else {
- this.playerRepository.onReload();
- }
- if (this.serverRepository == null) {
- this.serverRepository = new ServerRepository();
- }
-
- //register event listeners
- this.registerListeners();
}
- private void initDB() {
+ private void setupDatabase() {
if (this.getConfigurations().getDataConfiguration().getStorageType() != StorageType.MYSQL) {
return;
}
@@ -179,19 +211,19 @@ private void initDB() {
setup = new BufferedReader(new InputStreamReader(in)).lines().collect(Collectors.joining());
} catch (IOException | NullPointerException e) {
getLogger().log(Level.SEVERE, "Could not read db setup file.", e);
- e.printStackTrace();
}
String[] queries = setup.split(";");
for (String query : queries) {
+ query = query.trim();
if (query.isEmpty()) {
- return;
+ continue;
}
- try (Connection conn = this.getConfigurations().getDataConfiguration().getDatabase().getDataSource().getConnection();
+ try (Connection conn = this.getConfigurations().getDataConfiguration().getDatabase().getConnection();
PreparedStatement stmt = conn.prepareStatement(query)) {
stmt.execute();
} catch (SQLException e) {
- e.printStackTrace();
+ getLogger().log(Level.SEVERE, "Error executing db setup query.", e);
}
}
@@ -203,6 +235,19 @@ private void initDB() {
getLogger().info("Setup complete.");
}
+ private void initRepositories() {
+ if (this.playerRepository == null) {
+ this.playerRepository = new PlayerRepository(this);
+ } else {
+ this.playerRepository.onReload();
+ }
+ if (this.serverRepository == null) {
+ this.serverRepository = new ServerRepository(this);
+ } else {
+ this.serverRepository.onReload();
+ }
+ }
+
private void registerListeners() {
Arrays.asList(
//dependencies
@@ -273,4 +318,8 @@ public void removeFromGuis(Player player) {
public UpdateChecker getUpdateChecker() {
return updateChecker;
}
+
+ public ExecutorService getExecutor() {
+ return executor;
+ }
}
diff --git a/src/com/backtobedrock/augmentedhardcore/commands/AbstractCommand.java b/src/com/backtobedrock/augmentedhardcore/commands/AbstractCommand.java
index 1499e15..9b50b86 100644
--- a/src/com/backtobedrock/augmentedhardcore/commands/AbstractCommand.java
+++ b/src/com/backtobedrock/augmentedhardcore/commands/AbstractCommand.java
@@ -76,7 +76,7 @@ protected CompletableFuture hasPlayedBefore(String playerName) {
}
this.target = player;
return true;
- });
+ }, this.plugin.getExecutor());
}
public void sendUsageMessage(Command command) {
diff --git a/src/com/backtobedrock/augmentedhardcore/commands/CommandAugmentedHardcore.java b/src/com/backtobedrock/augmentedhardcore/commands/CommandAugmentedHardcore.java
index e8cd71e..e0218bd 100644
--- a/src/com/backtobedrock/augmentedhardcore/commands/CommandAugmentedHardcore.java
+++ b/src/com/backtobedrock/augmentedhardcore/commands/CommandAugmentedHardcore.java
@@ -6,10 +6,12 @@
import com.backtobedrock.augmentedhardcore.utilities.PlayerUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
+import java.util.logging.Level;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.OptionalInt;
public class CommandAugmentedHardcore extends AbstractCommand {
public CommandAugmentedHardcore(CommandSender cs, String[] args) {
@@ -37,12 +39,16 @@ public void run() {
if (!this.hasCorrectAmountOfArguments(command))
return;
+ OptionalInt amountOptional;
+ int amount;
+
switch (command) {
case ADDLIVES:
- int amount = CommandUtils.getPositiveNumberFromString(this.cs, this.args[2]);
- if (amount == -1) {
+ amountOptional = CommandUtils.getPositiveNumberFromString(this.cs, this.args[2]);
+ if (amountOptional.isEmpty()) {
return;
}
+ amount = amountOptional.getAsInt();
this.hasPlayedBefore(this.args[1]).thenAcceptAsync(bool -> {
if (!bool) {
@@ -63,20 +69,21 @@ public void run() {
);
this.plugin.getPlayerRepository().updatePlayerData(playerData);
- }).exceptionally(ex -> {
- ex.printStackTrace();
+ }, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing AugmentedHardcore command.", ex);
return null;
});
- }).exceptionally(ex -> {
- ex.printStackTrace();
+ }, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing AugmentedHardcore command.", ex);
return null;
});
break;
case ADDLIFEPARTS:
- amount = CommandUtils.getPositiveNumberFromString(this.cs, this.args[2]);
- if (amount == -1) {
+ amountOptional = CommandUtils.getPositiveNumberFromString(this.cs, this.args[2]);
+ if (amountOptional.isEmpty()) {
return;
}
+ amount = amountOptional.getAsInt();
this.hasPlayedBefore(this.args[1]).thenAcceptAsync(bool -> {
if (!bool) {
@@ -97,20 +104,21 @@ public void run() {
);
this.plugin.getPlayerRepository().updatePlayerData(playerData);
- }).exceptionally(ex -> {
- ex.printStackTrace();
+ }, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing AugmentedHardcore command.", ex);
return null;
});
- }).exceptionally(ex -> {
- ex.printStackTrace();
+ }, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing AugmentedHardcore command.", ex);
return null;
});
break;
case SETLIVES:
- amount = CommandUtils.getPositiveNumberFromString(this.cs, this.args[2]);
- if (amount == -1) {
+ amountOptional = CommandUtils.getPositiveNumberFromString(this.cs, this.args[2]);
+ if (amountOptional.isEmpty()) {
return;
}
+ amount = amountOptional.getAsInt();
this.hasPlayedBefore(this.args[1]).thenAcceptAsync(bool -> {
if (!bool) {
@@ -131,20 +139,21 @@ public void run() {
);
this.plugin.getPlayerRepository().updatePlayerData(playerData);
- }).exceptionally(ex -> {
- ex.printStackTrace();
+ }, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing AugmentedHardcore command.", ex);
return null;
});
- }).exceptionally(ex -> {
- ex.printStackTrace();
+ }, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing AugmentedHardcore command.", ex);
return null;
});
break;
case SETLIFEPARTS:
- amount = CommandUtils.getPositiveNumberFromString(this.cs, this.args[2]);
- if (amount == -1) {
+ amountOptional = CommandUtils.getPositiveNumberFromString(this.cs, this.args[2]);
+ if (amountOptional.isEmpty()) {
return;
}
+ amount = amountOptional.getAsInt();
this.hasPlayedBefore(this.args[1]).thenAcceptAsync(bool -> {
if (!bool) {
@@ -165,20 +174,21 @@ public void run() {
);
this.plugin.getPlayerRepository().updatePlayerData(playerData);
- }).exceptionally(ex -> {
- ex.printStackTrace();
+ }, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing AugmentedHardcore command.", ex);
return null;
});
- }).exceptionally(ex -> {
- ex.printStackTrace();
+ }, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing AugmentedHardcore command.", ex);
return null;
});
break;
case ADDMAXHEALTH:
- amount = CommandUtils.getPositiveNumberFromString(this.cs, this.args[2]);
- if (amount == -1) {
+ amountOptional = CommandUtils.getPositiveNumberFromString(this.cs, this.args[2]);
+ if (amountOptional.isEmpty()) {
return;
}
+ amount = amountOptional.getAsInt();
this.hasPlayedBefore(this.args[1]).thenAcceptAsync(bool -> {
if (!bool) {
@@ -201,16 +211,17 @@ public void run() {
this.plugin.getMessages().getCommandAddMaxHealth(maxHealth, maxHealthRaw, maxHealthTotal, maxHealthTotalRaw),
this.plugin.getMessages().getCommandAddMaxHealthSuccess(this.target.getName(), maxHealth, maxHealthRaw, maxHealthTotal, maxHealthTotalRaw)
);
- }).exceptionally(ex -> {
- ex.printStackTrace();
+ }, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing AugmentedHardcore command.", ex);
return null;
});
break;
case SETMAXHEALTH:
- amount = CommandUtils.getPositiveNumberFromString(this.cs, this.args[2]);
- if (amount == -1) {
+ amountOptional = CommandUtils.getPositiveNumberFromString(this.cs, this.args[2]);
+ if (amountOptional.isEmpty()) {
return;
}
+ amount = amountOptional.getAsInt();
this.hasPlayedBefore(this.args[1]).thenAcceptAsync(bool -> {
if (!bool) {
@@ -231,8 +242,8 @@ public void run() {
this.plugin.getMessages().getCommandSetMaxHealth(maxHealth, maxHealthRaw),
this.plugin.getMessages().getCommandSetMaxHealthSuccess(this.target.getName(), maxHealth, maxHealthRaw)
);
- }).exceptionally(ex -> {
- ex.printStackTrace();
+ }, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing AugmentedHardcore command.", ex);
return null;
});
break;
@@ -246,8 +257,8 @@ public void run() {
playerData.reset();
this.cs.sendMessage(this.plugin.getMessages().getCommandResetSuccess(this.target.getName()));
- });
- });
+ }, this.plugin.getExecutor());
+ }, this.plugin.getExecutor());
break;
case RELOAD:
this.plugin.initialize();
diff --git a/src/com/backtobedrock/augmentedhardcore/commands/CommandDeathBans.java b/src/com/backtobedrock/augmentedhardcore/commands/CommandDeathBans.java
index 08f560e..2c90e9e 100644
--- a/src/com/backtobedrock/augmentedhardcore/commands/CommandDeathBans.java
+++ b/src/com/backtobedrock/augmentedhardcore/commands/CommandDeathBans.java
@@ -6,6 +6,7 @@
import com.backtobedrock.augmentedhardcore.utilities.PlayerUtils;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
+import java.util.logging.Level;
public class CommandDeathBans extends AbstractCommand {
public CommandDeathBans(CommandSender cs, String[] args) {
@@ -39,16 +40,16 @@ public void run() {
}
this.runCommand(this.target);
- }).exceptionally(ex -> {
- ex.printStackTrace();
+ }, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing death bans command.", ex);
return null;
});
}
}
private void runCommand(OfflinePlayer player) {
- this.plugin.getPlayerRepository().getByPlayer(player).thenAcceptAsync(playerData -> PlayerUtils.openInventory(this.sender, new GuiPlayerDeathBans(playerData))).exceptionally(ex -> {
- ex.printStackTrace();
+ this.plugin.getPlayerRepository().getByPlayer(player).thenAcceptAsync(playerData -> PlayerUtils.openInventory(this.sender, new GuiPlayerDeathBans(this.plugin, playerData)), this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing death bans command.", ex);
return null;
});
}
diff --git a/src/com/backtobedrock/augmentedhardcore/commands/CommandLifeParts.java b/src/com/backtobedrock/augmentedhardcore/commands/CommandLifeParts.java
index 75af65a..cfe0500 100644
--- a/src/com/backtobedrock/augmentedhardcore/commands/CommandLifeParts.java
+++ b/src/com/backtobedrock/augmentedhardcore/commands/CommandLifeParts.java
@@ -5,6 +5,7 @@
import com.backtobedrock.augmentedhardcore.domain.enums.Permission;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
+import java.util.logging.Level;
public class CommandLifeParts extends AbstractCommand {
public CommandLifeParts(CommandSender cs, String[] args) {
@@ -38,16 +39,16 @@ public void run() {
}
this.runCommand(this.target);
- }).exceptionally(ex -> {
- ex.printStackTrace();
+ }, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing life parts command.", ex);
return null;
});
}
}
private void runCommand(OfflinePlayer player) {
- this.plugin.getPlayerRepository().getByPlayer(player).thenAcceptAsync(this::sendSuccessMessage).exceptionally(ex -> {
- ex.printStackTrace();
+ this.plugin.getPlayerRepository().getByPlayer(player).thenAcceptAsync(this::sendSuccessMessage, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing life parts command.", ex);
return null;
});
}
diff --git a/src/com/backtobedrock/augmentedhardcore/commands/CommandLives.java b/src/com/backtobedrock/augmentedhardcore/commands/CommandLives.java
index 17b773d..4d29b97 100644
--- a/src/com/backtobedrock/augmentedhardcore/commands/CommandLives.java
+++ b/src/com/backtobedrock/augmentedhardcore/commands/CommandLives.java
@@ -5,6 +5,7 @@
import com.backtobedrock.augmentedhardcore.domain.enums.Permission;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
+import java.util.logging.Level;
public class CommandLives extends AbstractCommand {
public CommandLives(CommandSender cs, String[] args) {
@@ -38,16 +39,16 @@ public void run() {
}
this.runCommand(this.target);
- }).exceptionally(ex -> {
- ex.printStackTrace();
+ }, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing lives command.", ex);
return null;
});
}
}
private void runCommand(OfflinePlayer player) {
- this.plugin.getPlayerRepository().getByPlayer(player).thenAcceptAsync(this::sendSuccessMessage).exceptionally(ex -> {
- ex.printStackTrace();
+ this.plugin.getPlayerRepository().getByPlayer(player).thenAcceptAsync(this::sendSuccessMessage, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing lives command.", ex);
return null;
});
}
@@ -56,8 +57,8 @@ private void sendSuccessMessage(PlayerData playerData) {
this.cs.sendMessage(
this.plugin.getMessages().getCommandLivesLeft(
playerData.getPlayer().getName(),
- playerData.getLives() + (playerData.getLives() == 1 ? " life" : " lives"),
- Integer.toString(playerData.getLives())
+ playerData.getLifeManager().getLives() + (playerData.getLifeManager().getLives() == 1 ? " life" : " lives"),
+ Integer.toString(playerData.getLifeManager().getLives())
));
}
}
diff --git a/src/com/backtobedrock/augmentedhardcore/commands/CommandMyStats.java b/src/com/backtobedrock/augmentedhardcore/commands/CommandMyStats.java
index 23c25be..1baf72f 100644
--- a/src/com/backtobedrock/augmentedhardcore/commands/CommandMyStats.java
+++ b/src/com/backtobedrock/augmentedhardcore/commands/CommandMyStats.java
@@ -6,6 +6,7 @@
import com.backtobedrock.augmentedhardcore.utilities.PlayerUtils;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
+import java.util.logging.Level;
public class CommandMyStats extends AbstractCommand {
public CommandMyStats(CommandSender cs, String[] args) {
@@ -39,16 +40,16 @@ public void run() {
}
this.runCommand(this.target);
- }).exceptionally(ex -> {
- ex.printStackTrace();
+ }, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing my stats command.", ex);
return null;
});
}
}
private void runCommand(OfflinePlayer player) {
- this.plugin.getPlayerRepository().getByPlayer(player).thenAcceptAsync(playerData -> PlayerUtils.openInventory(this.sender, new GuiMyStats(this.sender, playerData))).exceptionally(ex -> {
- ex.printStackTrace();
+ this.plugin.getPlayerRepository().getByPlayer(player).thenAcceptAsync(playerData -> PlayerUtils.openInventory(this.sender, new GuiMyStats(this.plugin, this.sender, playerData)), this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing my stats command.", ex);
return null;
});
}
diff --git a/src/com/backtobedrock/augmentedhardcore/commands/CommandNextLifePart.java b/src/com/backtobedrock/augmentedhardcore/commands/CommandNextLifePart.java
index 248e87e..bbf424f 100644
--- a/src/com/backtobedrock/augmentedhardcore/commands/CommandNextLifePart.java
+++ b/src/com/backtobedrock/augmentedhardcore/commands/CommandNextLifePart.java
@@ -8,6 +8,7 @@
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
+import java.util.logging.Level;
public class CommandNextLifePart extends AbstractCommand {
public CommandNextLifePart(CommandSender cs, String[] args) {
@@ -41,22 +42,22 @@ public void run() {
}
this.runCommand(this.target);
- }).exceptionally(ex -> {
- ex.printStackTrace();
+ }, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing next life part command.", ex);
return null;
});
}
}
private void runCommand(OfflinePlayer player) {
- this.plugin.getPlayerRepository().getByPlayer(player).thenAcceptAsync(this::sendSuccessMessage).exceptionally(ex -> {
- ex.printStackTrace();
+ this.plugin.getPlayerRepository().getByPlayer(player).thenAcceptAsync(this::sendSuccessMessage, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing next life part command.", ex);
return null;
});
}
private void sendSuccessMessage(PlayerData playerData) {
- long nextLifePart = playerData.getTimeTillNextLifePart();
+ long nextLifePart = playerData.getPlaytimeTracker().getTimeTillNextLifePart();
this.cs.sendMessage(this.plugin.getMessages().getCommandNextLifePart(this.cs instanceof Player && ((Player) this.cs).getUniqueId().toString().equals(playerData.getPlayer().getUniqueId().toString())
? "You"
: playerData.getPlayer().getName(), MessageUtils.getTimeFromTicks(nextLifePart, TimePattern.LONG)));
diff --git a/src/com/backtobedrock/augmentedhardcore/commands/CommandNextMaxHealth.java b/src/com/backtobedrock/augmentedhardcore/commands/CommandNextMaxHealth.java
index bfe0177..048141e 100644
--- a/src/com/backtobedrock/augmentedhardcore/commands/CommandNextMaxHealth.java
+++ b/src/com/backtobedrock/augmentedhardcore/commands/CommandNextMaxHealth.java
@@ -8,6 +8,7 @@
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
+import java.util.logging.Level;
public class CommandNextMaxHealth extends AbstractCommand {
public CommandNextMaxHealth(CommandSender cs, String[] args) {
@@ -41,22 +42,22 @@ public void run() {
}
this.runCommand(this.target);
- }).exceptionally(ex -> {
- ex.printStackTrace();
+ }, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing next max health command.", ex);
return null;
});
}
}
private void runCommand(OfflinePlayer player) {
- this.plugin.getPlayerRepository().getByPlayer(player).thenAcceptAsync(this::sendSuccessMessage).exceptionally(ex -> {
- ex.printStackTrace();
+ this.plugin.getPlayerRepository().getByPlayer(player).thenAcceptAsync(this::sendSuccessMessage, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing next max health command.", ex);
return null;
});
}
private void sendSuccessMessage(PlayerData playerData) {
- long nextMaxHealth = playerData.getTimeTillNextMaxHealth();
+ long nextMaxHealth = playerData.getPlaytimeTracker().getTimeTillNextMaxHealth();
this.cs.sendMessage(this.plugin.getMessages().getCommandNextMaxHealth(this.cs instanceof Player && ((Player) this.cs).getUniqueId().toString().equals(playerData.getPlayer().getUniqueId().toString())
? "You"
: playerData.getPlayer().getName(), MessageUtils.getTimeFromTicks(nextMaxHealth, TimePattern.LONG)));
diff --git a/src/com/backtobedrock/augmentedhardcore/commands/CommandNextRevive.java b/src/com/backtobedrock/augmentedhardcore/commands/CommandNextRevive.java
index 2214387..983a363 100644
--- a/src/com/backtobedrock/augmentedhardcore/commands/CommandNextRevive.java
+++ b/src/com/backtobedrock/augmentedhardcore/commands/CommandNextRevive.java
@@ -8,6 +8,7 @@
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
+import java.util.logging.Level;
public class CommandNextRevive extends AbstractCommand {
public CommandNextRevive(CommandSender cs, String[] args) {
@@ -41,22 +42,22 @@ public void run() {
}
this.runCommand(this.target);
- }).exceptionally(ex -> {
- ex.printStackTrace();
+ }, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing next revive command.", ex);
return null;
});
}
}
private void runCommand(OfflinePlayer player) {
- this.plugin.getPlayerRepository().getByPlayer(player).thenAcceptAsync(this::sendSuccessMessage).exceptionally(ex -> {
- ex.printStackTrace();
+ this.plugin.getPlayerRepository().getByPlayer(player).thenAcceptAsync(this::sendSuccessMessage, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing next revive command.", ex);
return null;
});
}
private void sendSuccessMessage(PlayerData playerData) {
- long reviveCooldown = playerData.getTimeTillNextRevive();
+ long reviveCooldown = playerData.getPlaytimeTracker().getTimeTillNextRevive();
this.cs.sendMessage(this.plugin.getMessages().getCommandNextRevive(this.cs instanceof Player && ((Player) this.cs).getUniqueId().toString().equals(playerData.getPlayer().getUniqueId().toString())
? "You"
: playerData.getPlayer().getName(), MessageUtils.getTimeFromTicks(reviveCooldown, TimePattern.LONG)));
diff --git a/src/com/backtobedrock/augmentedhardcore/commands/CommandRevive.java b/src/com/backtobedrock/augmentedhardcore/commands/CommandRevive.java
index 79fbb76..5c8db56 100644
--- a/src/com/backtobedrock/augmentedhardcore/commands/CommandRevive.java
+++ b/src/com/backtobedrock/augmentedhardcore/commands/CommandRevive.java
@@ -5,6 +5,7 @@
import com.backtobedrock.augmentedhardcore.guis.GuiRevive;
import com.backtobedrock.augmentedhardcore.utilities.PlayerUtils;
import org.bukkit.command.CommandSender;
+import java.util.logging.Level;
public class CommandRevive extends AbstractCommand {
public CommandRevive(CommandSender cs, String[] args) {
@@ -37,14 +38,14 @@ public void run() {
return;
}
- AbstractGui gui = new GuiRevive(playerData, this.target);
+ AbstractGui gui = new GuiRevive(this.plugin, playerData, this.target);
PlayerUtils.openInventory(this.sender, gui);
- }).exceptionally(ex -> {
- ex.printStackTrace();
+ }, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing revive command.", ex);
return null;
});
- }).exceptionally(ex -> {
- ex.printStackTrace();
+ }, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing revive command.", ex);
return null;
});
}
diff --git a/src/com/backtobedrock/augmentedhardcore/commands/CommandServerDeathBans.java b/src/com/backtobedrock/augmentedhardcore/commands/CommandServerDeathBans.java
index 569208a..ddbae46 100644
--- a/src/com/backtobedrock/augmentedhardcore/commands/CommandServerDeathBans.java
+++ b/src/com/backtobedrock/augmentedhardcore/commands/CommandServerDeathBans.java
@@ -4,6 +4,7 @@
import com.backtobedrock.augmentedhardcore.guis.GuiServerDeathBans;
import com.backtobedrock.augmentedhardcore.utilities.PlayerUtils;
import org.bukkit.command.CommandSender;
+import java.util.logging.Level;
public class CommandServerDeathBans extends AbstractCommand {
public CommandServerDeathBans(CommandSender cs, String[] args) {
@@ -27,8 +28,8 @@ public void run() {
}
- this.plugin.getServerRepository().getServerData(this.plugin.getServer()).thenAcceptAsync(serverData -> PlayerUtils.openInventory(this.sender, new GuiServerDeathBans(this.sender, serverData))).exceptionally(ex -> {
- ex.printStackTrace();
+ this.plugin.getServerRepository().getServerData(this.plugin.getServer()).thenAcceptAsync(serverData -> PlayerUtils.openInventory(this.sender, new GuiServerDeathBans(this.plugin, this.sender, serverData)), this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing server death bans command.", ex);
return null;
});
}
diff --git a/src/com/backtobedrock/augmentedhardcore/commands/CommandUnDeathBan.java b/src/com/backtobedrock/augmentedhardcore/commands/CommandUnDeathBan.java
index 265311c..4344ce8 100644
--- a/src/com/backtobedrock/augmentedhardcore/commands/CommandUnDeathBan.java
+++ b/src/com/backtobedrock/augmentedhardcore/commands/CommandUnDeathBan.java
@@ -4,6 +4,7 @@
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
+import java.util.logging.Level;
public class CommandUnDeathBan extends AbstractCommand {
public CommandUnDeathBan(CommandSender cs, String[] args) {
@@ -39,8 +40,8 @@ public void run() {
}
this.unDeathBan();
- }).exceptionally(ex -> {
- ex.printStackTrace();
+ }, this.plugin.getExecutor()).exceptionally(ex -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing un-death-ban command.", ex);
return null;
});
}
@@ -52,8 +53,8 @@ private void unDeathBan() {
} else {
this.cs.sendMessage(this.plugin.getMessages().getTargetNotBannedByPluginError(this.target.getName(), this.plugin.getDescription().getName()));
}
- }).exceptionally(e -> {
- e.printStackTrace();
+ }, this.plugin.getExecutor()).exceptionally(e -> {
+ this.plugin.getLogger().log(Level.SEVERE, "Error executing un-death-ban command.", e);
return null;
});
}
diff --git a/src/com/backtobedrock/augmentedhardcore/commands/Commands.java b/src/com/backtobedrock/augmentedhardcore/commands/Commands.java
index abacbcc..5107733 100644
--- a/src/com/backtobedrock/augmentedhardcore/commands/Commands.java
+++ b/src/com/backtobedrock/augmentedhardcore/commands/Commands.java
@@ -67,6 +67,8 @@ public boolean onCommand(CommandSender cs, Command cmnd, String alias, String[]
case "serverdeathbans":
new CommandServerDeathBans(cs, args).run();
break;
+ default:
+ return false;
}
return true;
}
diff --git a/src/com/backtobedrock/augmentedhardcore/configs/Messages.java b/src/com/backtobedrock/augmentedhardcore/configs/Messages.java
index 4effe16..847928d 100644
--- a/src/com/backtobedrock/augmentedhardcore/configs/Messages.java
+++ b/src/com/backtobedrock/augmentedhardcore/configs/Messages.java
@@ -103,24 +103,20 @@ public String getRequireOnlinePlayerError() {
}
public String getTargetNotOnlineError(String player) {
- Map placeholders = new HashMap() {{
- put("player", player);
- }};
+ Map placeholders = Map.of("player", player);
return MessageUtils.replacePlaceholders(this.messages.getString("TargetNotOnlineError", "&c%player% is currently not online."), placeholders);
}
public String getTargetNotPlayedBeforeError(String player) {
- Map placeholders = new HashMap() {{
- put("player", player);
- }};
+ Map placeholders = Map.of("player", player);
return MessageUtils.replacePlaceholders(this.messages.getString("TargetNotPlayedBeforeError", "&c%player% has not played on the server before."), placeholders);
}
public String getTargetNotBannedByPluginError(String player, String plugin) {
- Map placeholders = new HashMap() {{
- put("player", player);
- put("plugin", plugin);
- }};
+ Map placeholders = Map.of(
+ "player", player,
+ "plugin", plugin
+ );
return MessageUtils.replacePlaceholders(this.messages.getString("TargetNotBannedByPluginError", "&c%player% is not death banned by %plugin%."), placeholders);
}
@@ -141,187 +137,181 @@ public String getCommandHelpFooter() {
}
public String getCommandAddLives(String lives, String livesRaw, String livesTotal, String livesTotalRaw) {
- Map placeholders = new HashMap() {{
- put("lives", lives);
- put("livesraw", livesRaw);
- put("livestotal", livesTotal);
- put("livestotalraw", livesTotalRaw);
- }};
+ Map placeholders = Map.of(
+ "lives", lives,
+ "livesraw", livesRaw,
+ "livestotal", livesTotal,
+ "livestotalraw", livesTotalRaw
+ );
return MessageUtils.replacePlaceholders(this.messages.getString("CommandAddLives", "&aYou've been given &e%lives%&a, you now have &e%livestotal%&a."), placeholders);
}
public String getCommandAddLivesSuccess(String player, String lives, String livesRaw, String livesTotal, String livesTotalRaw) {
- Map placeholders = new HashMap() {{
- put("player", player);
- put("lives", lives);
- put("livesraw", livesRaw);
- put("livestotal", livesTotal);
- put("livestotalraw", livesTotalRaw);
- }};
+ Map placeholders = Map.of(
+ "player", player,
+ "lives", lives,
+ "livesraw", livesRaw,
+ "livestotal", livesTotal,
+ "livestotalraw", livesTotalRaw
+ );
return MessageUtils.replacePlaceholders(this.messages.getString("CommandAddLivesSuccess", "&aYou successfully gave &e%lives%&a, &e%player% &anow has §e%livestotal%§a."), placeholders);
}
public String getCommandAddLifeParts(String lifeparts, String lifepartsRaw, String lifepartsTotal, String lifepartsTotalRaw) {
- Map placeholders = new HashMap() {{
- put("lifeparts", lifeparts);
- put("lifepartsraw", lifepartsRaw);
- put("lifepartstotal", lifepartsTotal);
- put("lifepartstotalraw", lifepartsTotalRaw);
- }};
+ Map placeholders = Map.of(
+ "lifeparts", lifeparts,
+ "lifepartsraw", lifepartsRaw,
+ "lifepartstotal", lifepartsTotal,
+ "lifepartstotalraw", lifepartsTotalRaw
+ );
return MessageUtils.replacePlaceholders(this.messages.getString("CommandAddLifeParts", "&aYou've been given &e%lifeparts%&a, you now have &e%lifepartstotal%&a."), placeholders);
}
public String getCommandAddLifePartsSuccess(String player, String lifeparts, String lifepartsRaw, String lifepartsTotal, String lifepartsTotalRaw) {
- Map placeholders = new HashMap() {{
- put("player", player);
- put("lifeparts", lifeparts);
- put("lifepartsraw", lifepartsRaw);
- put("lifepartstotal", lifepartsTotal);
- put("lifepartstotalraw", lifepartsTotalRaw);
- }};
+ Map placeholders = Map.of(
+ "player", player,
+ "lifeparts", lifeparts,
+ "lifepartsraw", lifepartsRaw,
+ "lifepartstotal", lifepartsTotal,
+ "lifepartstotalraw", lifepartsTotalRaw
+ );
return MessageUtils.replacePlaceholders(this.messages.getString("CommandAddLifePartsSuccess", "&aYou successfully gave &e%lives%&a, &e%player% &anow has §e%livesTotal%§a."), placeholders);
}
public String getCommandSetLives(String lives, String livesRaw, String livesTotal, String livesTotalRaw) {
- Map placeholders = new HashMap() {{
- put("lives", lives);
- put("livesraw", livesRaw);
- put("livestotal", livesTotal);
- put("livestotalraw", livesTotalRaw);
- }};
+ Map placeholders = Map.of(
+ "lives", lives,
+ "livesraw", livesRaw,
+ "livestotal", livesTotal,
+ "livestotalraw", livesTotalRaw
+ );
return MessageUtils.replacePlaceholders(this.messages.getString("CommandSetLives", "&aYour &elives &ahave been set to &e%livestotal%&a."), placeholders);
}
public String getCommandSetLivesSuccess(String player, String lives, String livesRaw, String livesTotal, String livesTotalRaw) {
- Map placeholders = new HashMap() {{
- put("player", player);
- put("lives", lives);
- put("livesraw", livesRaw);
- put("livestotal", livesTotal);
- put("livestotalraw", livesTotalRaw);
- }};
+ Map placeholders = Map.of(
+ "player", player,
+ "lives", lives,
+ "livesraw", livesRaw,
+ "livestotal", livesTotal,
+ "livestotalraw", livesTotalRaw
+ );
return MessageUtils.replacePlaceholders(this.messages.getString("CommandSetLivesSuccess", "&aYou successfully set the &elives &aof &e%player% &ato &e%livestotal%&a."), placeholders);
}
public String getCommandSetLifeParts(String lifeparts, String lifepartsRaw, String lifepartsTotal, String lifepartsTotalRaw) {
- Map placeholders = new HashMap() {{
- put("lifeparts", lifeparts);
- put("lifepartsraw", lifepartsRaw);
- put("lifepartstotal", lifepartsTotal);
- put("lifepartstotalraw", lifepartsTotalRaw);
- }};
+ Map placeholders = Map.of(
+ "lifeparts", lifeparts,
+ "lifepartsraw", lifepartsRaw,
+ "lifepartstotal", lifepartsTotal,
+ "lifepartstotalraw", lifepartsTotalRaw
+ );
return MessageUtils.replacePlaceholders(this.messages.getString("CommandSetLifeParts", "&aYour &elife parts &ahave been set to &e%lifeparts%&a, giving you &e%livestotal% &aand &e%lifepartstotal%&a."), placeholders);
}
public String getCommandSetLifePartsSuccess(String player, String lifeParts, String lifePartsRaw, String lifePartsTotal, String lifePartsTotalRaw) {
- Map placeholders = new HashMap() {{
- put("player", player);
- put("lifeparts", lifeParts);
- put("lifepartsraw", lifePartsRaw);
- put("lifepartstotal", lifePartsTotal);
- put("lifepartstotalraw", lifePartsTotalRaw);
- }};
+ Map placeholders = Map.of(
+ "player", player,
+ "lifeparts", lifeParts,
+ "lifepartsraw", lifePartsRaw,
+ "lifepartstotal", lifePartsTotal,
+ "lifepartstotalraw", lifePartsTotalRaw
+ );
return MessageUtils.replacePlaceholders(this.messages.getString("CommandSetLifePartsSuccess", "&aYou successfully set the &elife parts &aof &e%player% &ato &e%lifeparts%&a, &e%player% &anow has &e%livestotal% &aand &e%lifepartstotal%&a."), placeholders);
}
public String getCommandAddMaxHealth(String maxHealth, String maxHealthRaw, String maxHealthTotal, String maxHealthTotalRaw) {
- Map placeholders = new HashMap() {{
- put("maxhealth", maxHealth);
- put("maxhealthraw", maxHealthRaw);
- put("maxhealthtotal", maxHealthTotal);
- put("maxhealthtotalraw", maxHealthTotalRaw);
- }};
+ Map placeholders = Map.of(
+ "maxhealth", maxHealth,
+ "maxhealthraw", maxHealthRaw,
+ "maxhealthtotal", maxHealthTotal,
+ "maxhealthtotalraw", maxHealthTotalRaw
+ );
return MessageUtils.replacePlaceholders(this.messages.getString("CommandAddMaxHealth", "&aYou've been given &e%maxhealth%&a, you now have &e%maxhealthtotal%&a."), placeholders);
}
public String getCommandAddMaxHealthSuccess(String player, String maxHealth, String maxHealthRaw, String maxHealthTotal, String maxHealthTotalRaw) {
- Map placeholders = new HashMap() {{
- put("player", player);
- put("maxhealth", maxHealth);
- put("maxhealthraw", maxHealthRaw);
- put("maxhealthtotal", maxHealthTotal);
- put("maxhealthtotalraw", maxHealthTotalRaw);
- }};
+ Map placeholders = Map.of(
+ "player", player,
+ "maxhealth", maxHealth,
+ "maxhealthraw", maxHealthRaw,
+ "maxhealthtotal", maxHealthTotal,
+ "maxhealthtotalraw", maxHealthTotalRaw
+ );
return MessageUtils.replacePlaceholders(this.messages.getString("CommandAddMaxHealthSuccess", "&aYou successfully gave &e%maxhealth%&a, &e%player% &anow has &e%maxhealthtotal%&a."), placeholders);
}
public String getCommandSetMaxHealth(String maxHealth, String maxHealthRaw) {
- Map placeholders = new HashMap() {{
- put("maxhealth", maxHealth);
- put("maxhealthraw", maxHealthRaw);
- }};
+ Map placeholders = Map.of(
+ "maxhealth", maxHealth,
+ "maxhealthraw", maxHealthRaw
+ );
return MessageUtils.replacePlaceholders(this.messages.getString("CommandSetMaxHealth", "&aYour &emax health &ahas been set to &e%maxhealthraw%&a."), placeholders);
}
public String getCommandSetMaxHealthSuccess(String player, String maxHealth, String maxHealthRaw) {
- Map placeholders = new HashMap() {{
- put("player", player);
- put("maxhealth", maxHealth);
- put("maxhealthraw", maxHealthRaw);
- }};
+ Map placeholders = Map.of(
+ "player", player,
+ "maxhealth", maxHealth,
+ "maxhealthraw", maxHealthRaw
+ );
return MessageUtils.replacePlaceholders(this.messages.getString("CommandSetMaxHealthSuccess", "&aYou successfully set the &emax health &aof &e%player%&a to &e%maxhealthraw%&a."), placeholders);
}
public String getCommandResetSuccess(String player) {
- Map placeholders = new HashMap() {{
- put("player", player);
- }};
+ Map placeholders = Map.of("player", player);
return MessageUtils.replacePlaceholders(this.messages.getString("CommandResetSuccess", "&aYou have successfully reset &e%player%&a."), placeholders);
}
public String getCommandReloadSuccess(String plugin) {
- Map placeholders = new HashMap() {{
- put("plugin", plugin);
- }};
+ Map placeholders = Map.of("plugin", plugin);
return MessageUtils.replacePlaceholders(this.messages.getString("CommandReloadSuccess", "&a%plugin% has successfully been reloaded."), placeholders);
}
public String getCommandLifePartsLeft(String player, String lifeParts, String lifePartsRaw) {
- Map placeholders = new HashMap() {{
- put("player", player);
- put("lifeparts", lifeParts);
- put("lifepartsraw", lifePartsRaw);
- }};
+ Map placeholders = Map.of(
+ "player", player,
+ "lifeparts", lifeParts,
+ "lifepartsraw", lifePartsRaw
+ );
return MessageUtils.replacePlaceholders(this.messages.getString("CommandLifePartsLeft", "&a%player% currently has &6%lifeparts%&a."), placeholders);
}
public String getCommandLivesLeft(String player, String lives, String livesRaw) {
- Map placeholders = new HashMap() {{
- put("player", player);
- put("lives", lives);
- put("livesraw", livesRaw);
- }};
+ Map placeholders = Map.of(
+ "player", player,
+ "lives", lives,
+ "livesraw", livesRaw
+ );
return MessageUtils.replacePlaceholders(this.messages.getString("CommandLivesLeft", "&a%player% currently has &6%lives%&a."), placeholders);
}
public String getCommandNextLifePart(String player, String timeLeft) {
- Map placeholders = new HashMap() {{
- put("player", player);
- put("timeleft", timeLeft);
- }};
+ Map placeholders = Map.of(
+ "player", player,
+ "timeleft", timeLeft
+ );
return MessageUtils.replacePlaceholders(this.messages.getString("CommandNextLifePart", "&a%player% will receive a new &elife part in %timeleft%&a."), placeholders);
}
public String getCommandNextMaxHealth(String player, String timeLeft) {
- Map placeholders = new HashMap() {{
- put("player", player);
- put("timeleft", timeLeft);
- }};
+ Map placeholders = Map.of(
+ "player", player,
+ "timeleft", timeLeft
+ );
return MessageUtils.replacePlaceholders(this.messages.getString("CommandNextMaxHealth", "&a%player% will receive extra &emax health in %timeleft%&a."), placeholders);
}
public String getCommandNextRevive(String player, String timeLeft) {
- Map placeholders = new HashMap() {{
- put("player", player);
- put("timeleft", timeLeft);
- }};
+ Map placeholders = Map.of(
+ "player", player,
+ "timeleft", timeLeft
+ );
return MessageUtils.replacePlaceholders(this.messages.getString("CommandNextRevive", "&a%player% will be able to &erevive in %timeleft%&a."), placeholders);
}
public String getCommandUndeathBan(String player) {
- Map placeholders = new HashMap() {{
- put("player", player);
- }};
+ Map placeholders = Map.of("player", player);
return MessageUtils.replacePlaceholders(this.messages.getString("CommandUndeathBan", "&a%player% has successfully been unbanned from a death ban."), placeholders);
}
//
diff --git a/src/com/backtobedrock/augmentedhardcore/domain/BanEntry.java b/src/com/backtobedrock/augmentedhardcore/domain/BanEntry.java
new file mode 100644
index 0000000..129d034
--- /dev/null
+++ b/src/com/backtobedrock/augmentedhardcore/domain/BanEntry.java
@@ -0,0 +1,7 @@
+package com.backtobedrock.augmentedhardcore.domain;
+
+/**
+ * Simple record representing a ban entry consisting of the ban's id and the {@link Ban} itself.
+ */
+public record BanEntry(int id, Ban ban) {
+}
diff --git a/src/com/backtobedrock/augmentedhardcore/domain/Database.java b/src/com/backtobedrock/augmentedhardcore/domain/Database.java
index e67f066..6b60ff8 100644
--- a/src/com/backtobedrock/augmentedhardcore/domain/Database.java
+++ b/src/com/backtobedrock/augmentedhardcore/domain/Database.java
@@ -1,10 +1,13 @@
package com.backtobedrock.augmentedhardcore.domain;
import com.backtobedrock.augmentedhardcore.AugmentedHardcore;
-import com.zaxxer.hikari.HikariDataSource;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.plugin.java.JavaPlugin;
+import com.zaxxer.hikari.HikariDataSource;
+
+import java.sql.Connection;
+import java.sql.SQLException;
import java.util.logging.Level;
public class Database {
@@ -75,7 +78,7 @@ public String getPassword() {
return password;
}
- public HikariDataSource getDataSource() {
+ private HikariDataSource getDataSource() {
if (this.dataSource == null) {
this.dataSource = new HikariDataSource();
this.dataSource.setJdbcUrl(String.format("jdbc:mysql://%s:%s/%s", this.getHostname(), this.getPort(), this.getDatabaseName()));
@@ -90,4 +93,14 @@ public HikariDataSource getDataSource() {
}
return this.dataSource;
}
+
+ public Connection getConnection() throws SQLException {
+ return this.getDataSource().getConnection();
+ }
+
+ public void close() {
+ if (this.dataSource != null) {
+ this.dataSource.close();
+ }
+ }
}
diff --git a/src/com/backtobedrock/augmentedhardcore/domain/Killer.java b/src/com/backtobedrock/augmentedhardcore/domain/Killer.java
index 57986c5..d188d38 100644
--- a/src/com/backtobedrock/augmentedhardcore/domain/Killer.java
+++ b/src/com/backtobedrock/augmentedhardcore/domain/Killer.java
@@ -6,6 +6,7 @@
import java.util.HashMap;
import java.util.Map;
+import java.util.Objects;
public class Killer {
private final String name;
@@ -72,4 +73,9 @@ public boolean equals(Object o) {
Killer killer = (Killer) o;
return getName().equals(killer.getName()) && getType().equals(killer.getType());
}
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(this.name, this.type);
+ }
}
diff --git a/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/ConfigurationCombatTag.java b/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/ConfigurationCombatTag.java
index 8a544bb..39edc73 100644
--- a/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/ConfigurationCombatTag.java
+++ b/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/ConfigurationCombatTag.java
@@ -4,6 +4,7 @@
import org.bukkit.configuration.ConfigurationSection;
import java.util.List;
+import java.util.OptionalInt;
public class ConfigurationCombatTag {
private final boolean combatTagSelf;
@@ -33,11 +34,11 @@ public static ConfigurationCombatTag deserialize(ConfigurationSection section) {
boolean cPlayerCombatTag = section.getBoolean("PlayerCombatTag", true);
boolean cMonsterCombatTag = section.getBoolean("MonsterCombatTag", true);
boolean cCombatTagSelf = section.getBoolean("CombatTagSelf", true);
- int cCombatTagTime = ConfigUtils.checkMinMax("CombatTagTime", section.getInt("CombatTagTime", 15), 1, Integer.MAX_VALUE);
+ OptionalInt cCombatTagTime = ConfigUtils.checkMinMax("CombatTagTime", section.getInt("CombatTagTime", 15), 1, Integer.MAX_VALUE);
boolean cCombatTagPlayerKickDeath = section.getBoolean("CombatTagPlayerKickDeath", true);
List cDisableCombatTagInWorlds = section.getStringList("DisableCombatTagInWorlds");
- if (cCombatTagTime == -10) {
+ if (cCombatTagTime.isEmpty()) {
return null;
}
@@ -45,7 +46,7 @@ public static ConfigurationCombatTag deserialize(ConfigurationSection section) {
cPlayerCombatTag,
cMonsterCombatTag,
cCombatTagSelf,
- cCombatTagTime,
+ cCombatTagTime.getAsInt(),
cCombatTagPlayerKickDeath,
cDisableCombatTagInWorlds
);
diff --git a/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/ConfigurationLivesAndLifeParts.java b/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/ConfigurationLivesAndLifeParts.java
index 36ad407..a2999e0 100644
--- a/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/ConfigurationLivesAndLifeParts.java
+++ b/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/ConfigurationLivesAndLifeParts.java
@@ -8,6 +8,7 @@
import java.util.EnumMap;
import java.util.List;
+import java.util.OptionalInt;
import java.util.logging.Level;
public class ConfigurationLivesAndLifeParts {
@@ -83,24 +84,24 @@ public ConfigurationLivesAndLifeParts(
public static ConfigurationLivesAndLifeParts deserialize(ConfigurationSection section) {
//lives
boolean cUseLives = section.getBoolean("UseLives", true);
- int cMaxLives = ConfigUtils.checkMinMax("MaxLives", section.getInt("MaxLives", 5), 1, Integer.MAX_VALUE);
- int cLivesAtStart = ConfigUtils.checkMinMax("LivesAtStart", section.getInt("LivesAtStart", 1), 1, Integer.MAX_VALUE);
- int cLivesAfterBan = ConfigUtils.checkMinMax("LivesAfterBan", section.getInt("LivesAfterBan", 1), 1, Integer.MAX_VALUE);
- int cLivesLostPerDeath = ConfigUtils.checkMinMax("LivesLostPerDeath", section.getInt("LivesLostPerDeath", 1), 1, Integer.MAX_VALUE);
+ OptionalInt cMaxLives = ConfigUtils.checkMinMax("MaxLives", section.getInt("MaxLives", 5), 1, Integer.MAX_VALUE);
+ OptionalInt cLivesAtStart = ConfigUtils.checkMinMax("LivesAtStart", section.getInt("LivesAtStart", 1), 1, Integer.MAX_VALUE);
+ OptionalInt cLivesAfterBan = ConfigUtils.checkMinMax("LivesAfterBan", section.getInt("LivesAfterBan", 1), 1, Integer.MAX_VALUE);
+ OptionalInt cLivesLostPerDeath = ConfigUtils.checkMinMax("LivesLostPerDeath", section.getInt("LivesLostPerDeath", 1), 1, Integer.MAX_VALUE);
List cDisableLosingLivesInWorlds = section.getStringList("DisableLosingLivesInWorlds").stream().map(String::toLowerCase).toList();
//life parts
boolean cUseLifeParts = section.getBoolean("UseLifeParts", true);
- int cMaxLifeParts = ConfigUtils.checkMinMax("MaxLifeParts", section.getInt("MaxLifeParts", 6), -1, Integer.MAX_VALUE);
- int cLifePartsPerLife = ConfigUtils.checkMinMax("LifePartsPerLife", section.getInt("LifePartsPerLife"), 1, Integer.MAX_VALUE);
- int cLifePartsAtStart = ConfigUtils.checkMinMax("LifePartsAtStart", section.getInt("LifePartsAtStart"), 0, Integer.MAX_VALUE);
- int cLifePartsAfterBan = ConfigUtils.checkMinMax("LifePartsAfterBan", section.getInt("LifePartsAfterBan"), -1, Integer.MAX_VALUE);
- int cLifePartsLostPerDeath = ConfigUtils.checkMinMax("LifePartsLostPerDeath", section.getInt("LifePartsLostPerDeath", 1), -1, Integer.MAX_VALUE);
- int cLifePartsLostPerDeathBan = ConfigUtils.checkMinMax("LifePartsLostPerDeathBan", section.getInt("LifePartsLostPerDeathBan", -1), -1, Integer.MAX_VALUE);
+ OptionalInt cMaxLifeParts = ConfigUtils.checkMinMax("MaxLifeParts", section.getInt("MaxLifeParts", 6), -1, Integer.MAX_VALUE);
+ OptionalInt cLifePartsPerLife = ConfigUtils.checkMinMax("LifePartsPerLife", section.getInt("LifePartsPerLife"), 1, Integer.MAX_VALUE);
+ OptionalInt cLifePartsAtStart = ConfigUtils.checkMinMax("LifePartsAtStart", section.getInt("LifePartsAtStart"), 0, Integer.MAX_VALUE);
+ OptionalInt cLifePartsAfterBan = ConfigUtils.checkMinMax("LifePartsAfterBan", section.getInt("LifePartsAfterBan"), -1, Integer.MAX_VALUE);
+ OptionalInt cLifePartsLostPerDeath = ConfigUtils.checkMinMax("LifePartsLostPerDeath", section.getInt("LifePartsLostPerDeath", 1), -1, Integer.MAX_VALUE);
+ OptionalInt cLifePartsLostPerDeathBan = ConfigUtils.checkMinMax("LifePartsLostPerDeathBan", section.getInt("LifePartsLostPerDeathBan", -1), -1, Integer.MAX_VALUE);
boolean cLifePartsOnKill = section.getBoolean("LifePartsOnKill");
EnumMap cLifePartsPerKill = new EnumMap<>(EntityType.class);
boolean cGetLifePartsByPlaytime = section.getBoolean("GetLifePartByPlaytime", false);
- int cPlaytimePerLifePart = ConfigUtils.checkMinMax("PlaytimePerLifePart", section.getInt("PlaytimePerLifePart", 30), 1, Integer.MAX_VALUE);
+ OptionalInt cPlaytimePerLifePart = ConfigUtils.checkMinMax("PlaytimePerLifePart", section.getInt("PlaytimePerLifePart", 30), 1, Integer.MAX_VALUE);
List cDisableGainingLifePartsInWorlds = section.getStringList("DisableGainingLifePartsInWorlds").stream().map(String::toLowerCase).toList();
List cDisableLosingLifePartsInWorlds = section.getStringList("DisableLosingLifePartsInWorlds").stream().map(String::toLowerCase).toList();
@@ -109,14 +110,14 @@ public static ConfigurationLivesAndLifeParts deserialize(ConfigurationSection se
}
//if cLifePartsLostPerDeath or cLifePartsLostPerDeathBan == -1 then set to max Integer.
- if (cLifePartsLostPerDeath == -1) {
- cLifePartsLostPerDeath = Integer.MAX_VALUE;
+ if (cLifePartsLostPerDeath.isPresent() && cLifePartsLostPerDeath.getAsInt() == -1) {
+ cLifePartsLostPerDeath = OptionalInt.of(Integer.MAX_VALUE);
}
- if (cLifePartsLostPerDeathBan == -1) {
- cLifePartsLostPerDeathBan = Integer.MAX_VALUE;
+ if (cLifePartsLostPerDeathBan.isPresent() && cLifePartsLostPerDeathBan.getAsInt() == -1) {
+ cLifePartsLostPerDeathBan = OptionalInt.of(Integer.MAX_VALUE);
}
- if (cMaxLifeParts == -1) {
- cMaxLifeParts = Integer.MAX_VALUE;
+ if (cMaxLifeParts.isPresent() && cMaxLifeParts.getAsInt() == -1) {
+ cMaxLifeParts = OptionalInt.of(Integer.MAX_VALUE);
}
ConfigurationSection lifePartsPerKillSection = section.getConfigurationSection("LifePartsPerKill");
@@ -124,37 +125,48 @@ public static ConfigurationLivesAndLifeParts deserialize(ConfigurationSection se
lifePartsPerKillSection.getKeys(false).forEach(e -> {
EntityType type = ConfigUtils.getLivingEntityType("LifePartsPerKill", e);
if (type != null) {
- int amount = ConfigUtils.checkMin("LifePartsPerKill." + e, lifePartsPerKillSection.getInt(e, 0), 0);
- if (amount != -10)
- cLifePartsPerKill.put(type, amount);
+ OptionalInt amount = ConfigUtils.checkMin("LifePartsPerKill." + e, lifePartsPerKillSection.getInt(e, 0), 0);
+ amount.ifPresent(a -> cLifePartsPerKill.put(type, a));
}
});
}
- if (cMaxLives == -10 || cLivesAtStart == -10 || cLivesAfterBan == -10 || cLivesLostPerDeath == -10 || cMaxLifeParts == -10 || cLifePartsPerLife == -10 || cLifePartsAtStart == -10 || cLifePartsAfterBan == -10 || cLifePartsLostPerDeath == -10 || cLifePartsLostPerDeathBan == -10 || cPlaytimePerLifePart == -10) {
+ if (cMaxLives.isEmpty() || cLivesAtStart.isEmpty() || cLivesAfterBan.isEmpty() || cLivesLostPerDeath.isEmpty() || cMaxLifeParts.isEmpty() || cLifePartsPerLife.isEmpty() || cLifePartsAtStart.isEmpty() || cLifePartsAfterBan.isEmpty() || cLifePartsLostPerDeath.isEmpty() || cLifePartsLostPerDeathBan.isEmpty() || cPlaytimePerLifePart.isEmpty()) {
return null;
}
+ int vMaxLives = cMaxLives.getAsInt();
+ int vLivesAtStart = cLivesAtStart.getAsInt();
+ int vLivesAfterBan = cLivesAfterBan.getAsInt();
+ int vLivesLostPerDeath = cLivesLostPerDeath.getAsInt();
+ int vMaxLifeParts = cMaxLifeParts.getAsInt();
+ int vLifePartsPerLife = cLifePartsPerLife.getAsInt();
+ int vLifePartsAtStart = cLifePartsAtStart.getAsInt();
+ int vLifePartsAfterBan = cLifePartsAfterBan.getAsInt();
+ int vLifePartsLostPerDeath = cLifePartsLostPerDeath.getAsInt();
+ int vLifePartsLostPerDeathBan = cLifePartsLostPerDeathBan.getAsInt();
+ int vPlaytimePerLifePart = cPlaytimePerLifePart.getAsInt();
+
return new ConfigurationLivesAndLifeParts(
//lives
cUseLives,
- cMaxLives,
- cLivesAtStart,
- cLivesAfterBan,
- cLivesLostPerDeath,
+ vMaxLives,
+ vLivesAtStart,
+ vLivesAfterBan,
+ vLivesLostPerDeath,
cDisableLosingLivesInWorlds,
//life parts
cUseLifeParts,
- cMaxLifeParts,
- cLifePartsPerLife,
- cLifePartsAtStart,
- cLifePartsAfterBan,
- cLifePartsLostPerDeath,
- cLifePartsLostPerDeathBan,
+ vMaxLifeParts,
+ vLifePartsPerLife,
+ vLifePartsAtStart,
+ vLifePartsAfterBan,
+ vLifePartsLostPerDeath,
+ vLifePartsLostPerDeathBan,
cLifePartsOnKill,
cLifePartsPerKill,
cGetLifePartsByPlaytime,
- cPlaytimePerLifePart * 1200,
+ vPlaytimePerLifePart * 1200,
cDisableGainingLifePartsInWorlds,
cDisableLosingLifePartsInWorlds
);
diff --git a/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/ConfigurationMaxHealth.java b/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/ConfigurationMaxHealth.java
index 6b3a6d3..8ae1e85 100644
--- a/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/ConfigurationMaxHealth.java
+++ b/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/ConfigurationMaxHealth.java
@@ -6,6 +6,8 @@
import java.util.EnumMap;
import java.util.List;
+import java.util.OptionalDouble;
+import java.util.OptionalInt;
public class ConfigurationMaxHealth {
private final boolean useMaxHealth;
@@ -36,14 +38,14 @@ public ConfigurationMaxHealth(boolean useMaxHealth, double maxHealth, double min
public static ConfigurationMaxHealth deserialize(ConfigurationSection section) {
boolean cUseMaxHealth = section.getBoolean("UseMaxHealth", true);
- double cMaxHealth = ConfigUtils.checkMinMax("MaxHealth", section.getDouble("MaxHealth", 20), 1, Double.MAX_VALUE);
- double cMinHealth = ConfigUtils.checkMinMax("MinHealth", section.getDouble("MinHealth", 6), 1, Double.MAX_VALUE);
- double cMaxHealthAfterBan = section.getDouble("MaxHealthAfterBan", 20) == -1 ? -1 : ConfigUtils.checkMinMax("MaxHealthAfterBan", section.getDouble("MaxHealthAfterBan", 20), -1, Double.MAX_VALUE);
- double cMaxHealthDecreasePerDeath = ConfigUtils.checkMinMax("MaxHealthDecreasePerDeath", section.getDouble("MaxHealthDecreasePerDeath", 2), 1, Double.MAX_VALUE);
+ OptionalDouble cMaxHealth = ConfigUtils.checkMinMax("MaxHealth", section.getDouble("MaxHealth", 20), 1, Double.MAX_VALUE);
+ OptionalDouble cMinHealth = ConfigUtils.checkMinMax("MinHealth", section.getDouble("MinHealth", 6), 1, Double.MAX_VALUE);
+ OptionalDouble cMaxHealthAfterBan = section.getDouble("MaxHealthAfterBan", 20) == -1 ? OptionalDouble.of(-1) : ConfigUtils.checkMinMax("MaxHealthAfterBan", section.getDouble("MaxHealthAfterBan", 20), -1, Double.MAX_VALUE);
+ OptionalDouble cMaxHealthDecreasePerDeath = ConfigUtils.checkMinMax("MaxHealthDecreasePerDeath", section.getDouble("MaxHealthDecreasePerDeath", 2), 1, Double.MAX_VALUE);
boolean cMaxHealthIncreaseOnKill = section.getBoolean("MaxHealthIncreaseOnKill", true);
EnumMap cMaxHealthIncreasePerKill = new EnumMap<>(EntityType.class);
boolean cGetMaxHealthByPlaytime = section.getBoolean("GetMaxHealthByPlaytime", false);
- int cPlaytimePerHalfHeart = ConfigUtils.checkMinMax("PlaytimePerHalfHeart", section.getInt("PlaytimePerHalfHeart", 30), 1, Integer.MAX_VALUE);
+ OptionalInt cPlaytimePerHalfHeart = ConfigUtils.checkMinMax("PlaytimePerHalfHeart", section.getInt("PlaytimePerHalfHeart", 30), 1, Integer.MAX_VALUE);
List cDisableLosingMaxHealthInWorlds = section.getStringList("DisableLosingMaxHealthInWorlds").stream().map(String::toLowerCase).toList();
List cDisableGainingMaxHealthInWorlds = section.getStringList("DisableGainingMaxHealthInWorlds").stream().map(String::toLowerCase).toList();
@@ -53,27 +55,32 @@ public static ConfigurationMaxHealth deserialize(ConfigurationSection section) {
maxHealthIncreasePerKillSection.getKeys(false).forEach(e -> {
EntityType type = ConfigUtils.getLivingEntityType("MaxHealthIncreasePerKill", e);
if (type != null) {
- double amount = ConfigUtils.checkMinMax("MaxHealthIncreasePerKill." + e, maxHealthIncreasePerKillSection.getDouble(e, 0), 0, Integer.MAX_VALUE);
- if (amount != -10)
- cMaxHealthIncreasePerKill.put(type, amount);
+ OptionalDouble amount = ConfigUtils.checkMinMax("MaxHealthIncreasePerKill." + e, maxHealthIncreasePerKillSection.getDouble(e, 0), 0, Integer.MAX_VALUE);
+ amount.ifPresent(a -> cMaxHealthIncreasePerKill.put(type, a));
}
});
}
- if (cMaxHealth == -10 || cMinHealth == -10 || cMaxHealthAfterBan == -10 || cMaxHealthDecreasePerDeath == -10 || cPlaytimePerHalfHeart == -10) {
+ if (cMaxHealth.isEmpty() || cMinHealth.isEmpty() || cMaxHealthAfterBan.isEmpty() || cMaxHealthDecreasePerDeath.isEmpty() || cPlaytimePerHalfHeart.isEmpty()) {
return null;
}
+ double vMaxHealth = cMaxHealth.getAsDouble();
+ double vMinHealth = cMinHealth.getAsDouble();
+ double vMaxHealthAfterBan = cMaxHealthAfterBan.getAsDouble();
+ double vMaxHealthDecreasePerDeath = cMaxHealthDecreasePerDeath.getAsDouble();
+ int vPlaytimePerHalfHeart = cPlaytimePerHalfHeart.getAsInt();
+
return new ConfigurationMaxHealth(
cUseMaxHealth,
- cMaxHealth,
- cMinHealth,
- cMaxHealthAfterBan,
- cMaxHealthDecreasePerDeath,
+ vMaxHealth,
+ vMinHealth,
+ vMaxHealthAfterBan,
+ vMaxHealthDecreasePerDeath,
cMaxHealthIncreaseOnKill,
cMaxHealthIncreasePerKill,
cGetMaxHealthByPlaytime,
- cPlaytimePerHalfHeart * 1200,
+ vPlaytimePerHalfHeart * 1200,
cDisableLosingMaxHealthInWorlds,
cDisableGainingMaxHealthInWorlds
);
diff --git a/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/ConfigurationRevive.java b/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/ConfigurationRevive.java
index f1bfd33..7fd104c 100644
--- a/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/ConfigurationRevive.java
+++ b/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/ConfigurationRevive.java
@@ -4,6 +4,7 @@
import org.bukkit.configuration.ConfigurationSection;
import java.util.List;
+import java.util.OptionalInt;
public class ConfigurationRevive {
private final boolean useRevive;
@@ -24,21 +25,21 @@ public ConfigurationRevive(boolean useRevive, int livesLostOnReviving, int lives
public static ConfigurationRevive deserialize(ConfigurationSection section) {
boolean cUseRevive = section.getBoolean("UseRevive", true);
- int cLivesLostOnReviving = ConfigUtils.checkMinMax("LivesLostOnReviving", section.getInt("LivesLostOnReviving", 1), 1, Integer.MAX_VALUE);
- int cLivesGainedOnRevive = ConfigUtils.checkMinMax("LivesGainedOnRevive", section.getInt("LivesGainedOnRevive", 1), 1, Integer.MAX_VALUE);
- int cTimeBetweenRevives = ConfigUtils.checkMinMax("TimeBetweenRevives", section.getInt("TimeBetweenRevives", 1440), 0, Integer.MAX_VALUE);
+ OptionalInt cLivesLostOnReviving = ConfigUtils.checkMinMax("LivesLostOnReviving", section.getInt("LivesLostOnReviving", 1), 1, Integer.MAX_VALUE);
+ OptionalInt cLivesGainedOnRevive = ConfigUtils.checkMinMax("LivesGainedOnRevive", section.getInt("LivesGainedOnRevive", 1), 1, Integer.MAX_VALUE);
+ OptionalInt cTimeBetweenRevives = ConfigUtils.checkMinMax("TimeBetweenRevives", section.getInt("TimeBetweenRevives", 1440), 0, Integer.MAX_VALUE);
boolean cReviveOnFirstJoin = section.getBoolean("ReviveOnFirstJoin", false);
List cDisableReviveInWorlds = section.getStringList("DisableReviveInWorlds").stream().map(String::toLowerCase).toList();
- if (cTimeBetweenRevives == -10 || cLivesLostOnReviving == -10 || cLivesGainedOnRevive == -10) {
+ if (cTimeBetweenRevives.isEmpty() || cLivesLostOnReviving.isEmpty() || cLivesGainedOnRevive.isEmpty()) {
return null;
}
return new ConfigurationRevive(
cUseRevive,
- cLivesLostOnReviving,
- cLivesGainedOnRevive,
- cTimeBetweenRevives * 1200,
+ cLivesLostOnReviving.getAsInt(),
+ cLivesGainedOnRevive.getAsInt(),
+ cTimeBetweenRevives.getAsInt() * 1200,
cReviveOnFirstJoin,
cDisableReviveInWorlds
);
diff --git a/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/configurationHelperClasses/BanConfiguration.java b/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/configurationHelperClasses/BanConfiguration.java
index e77b076..f684885 100644
--- a/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/configurationHelperClasses/BanConfiguration.java
+++ b/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/configurationHelperClasses/BanConfiguration.java
@@ -7,6 +7,7 @@
import org.bukkit.plugin.java.JavaPlugin;
import java.util.List;
+import java.util.OptionalInt;
import java.util.logging.Level;
public class BanConfiguration {
@@ -21,7 +22,7 @@ public BanConfiguration(int banTime, List displayMessages) {
public static BanConfiguration deserialize(DamageCause cause, ConfigurationSection section) {
AugmentedHardcore plugin = JavaPlugin.getPlugin(AugmentedHardcore.class);
- int cBanTime = ConfigUtils.checkMinMaxNoNotification(section.getInt("BanTime", cause.getDefaultBantime()), -1, Integer.MAX_VALUE);
+ OptionalInt cBanTime = ConfigUtils.checkMinMaxNoNotification(section.getInt("BanTime", cause.getDefaultBantime()), -1, Integer.MAX_VALUE);
List cDisplayMessages = section.contains("DisplayMessages") ? section.getStringList("DisplayMessages") : null;
if (cDisplayMessages == null) {
@@ -29,12 +30,12 @@ public static BanConfiguration deserialize(DamageCause cause, ConfigurationSecti
plugin.getLogger().log(Level.SEVERE, String.format("DeathCauseConfigurations: %s didn't have correct DisplayMessages configured and default value will be used: %s.", cause.name(), cause.getDefaultDisplayMessages().toString()));
}
- if (cBanTime == -10) {
- cBanTime = cause.getDefaultBantime();
+ int banTime = cBanTime.orElse(cause.getDefaultBantime());
+ if (cBanTime.isEmpty()) {
plugin.getLogger().log(Level.SEVERE, String.format("DeathCauseConfigurations: %s didn't have a correct BanTime configured and default value will be used: %d.", cause.name(), cause.getDefaultBantime()));
}
- return new BanConfiguration(cBanTime, cDisplayMessages);
+ return new BanConfiguration(banTime, cDisplayMessages);
}
public int getBanTime() {
diff --git a/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/configurationHelperClasses/Display.java b/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/configurationHelperClasses/Display.java
index 5f0df21..0209e31 100644
--- a/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/configurationHelperClasses/Display.java
+++ b/src/com/backtobedrock/augmentedhardcore/domain/configurationDomain/configurationHelperClasses/Display.java
@@ -11,6 +11,7 @@
import java.util.HashMap;
import java.util.List;
+import java.util.OptionalInt;
import java.util.logging.Level;
public class Display {
@@ -32,18 +33,18 @@ public static Display deserialize(String id, ConfigurationSection section) {
Material cMaterial = ConfigUtils.getMaterial(id + ".Material", section.getString("Material"));
String cName = section.getString("Name");
List cLore = section.getStringList("Lore");
- int cAmount = ConfigUtils.checkMinMax(id + ".Amount", section.getInt("Amount", 1), 1, Integer.MAX_VALUE);
+ OptionalInt cAmount = ConfigUtils.checkMinMax(id + ".Amount", section.getInt("Amount", 1), 1, Integer.MAX_VALUE);
if (cName == null) {
plugin.getLogger().log(Level.SEVERE, id + ".Name: %s is not a valid name.");
return null;
}
- if (cAmount == -10 || cMaterial == null) {
+ if (cAmount.isEmpty() || cMaterial == null) {
return null;
}
- return new Display(cMaterial, cName, cLore, cAmount);
+ return new Display(cMaterial, cName, cLore, cAmount.getAsInt());
}
public ItemStack getItem() {
diff --git a/src/com/backtobedrock/augmentedhardcore/domain/data/BanManager.java b/src/com/backtobedrock/augmentedhardcore/domain/data/BanManager.java
new file mode 100644
index 0000000..37206ef
--- /dev/null
+++ b/src/com/backtobedrock/augmentedhardcore/domain/data/BanManager.java
@@ -0,0 +1,48 @@
+package com.backtobedrock.augmentedhardcore.domain.data;
+
+import com.backtobedrock.augmentedhardcore.domain.Ban;
+import com.backtobedrock.augmentedhardcore.domain.BanEntry;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.NavigableMap;
+import java.util.TreeMap;
+
+/**
+ * Simple container around the player's death bans.
+ */
+public class BanManager {
+ private final NavigableMap bans = new TreeMap<>();
+
+ public BanManager() {
+ }
+
+ public BanManager(NavigableMap existing) {
+ if (existing != null) {
+ this.bans.putAll(existing);
+ }
+ }
+
+ public NavigableMap getBans() {
+ return Collections.unmodifiableNavigableMap(this.bans);
+ }
+
+ public int getBanCount() {
+ return bans.size();
+ }
+
+ public BanEntry addBan(Ban ban) {
+ int key = (bans.isEmpty() ? 0 : bans.lastKey()) + 1;
+ bans.put(key, ban);
+ return new BanEntry(key, ban);
+ }
+
+ public void clearBans() {
+ this.bans.clear();
+ }
+
+ public Ban getLastDeathBan() {
+ Map.Entry entry = bans.lastEntry();
+ return entry == null ? null : entry.getValue();
+ }
+}
diff --git a/src/com/backtobedrock/augmentedhardcore/domain/data/LifeManager.java b/src/com/backtobedrock/augmentedhardcore/domain/data/LifeManager.java
new file mode 100644
index 0000000..89c545d
--- /dev/null
+++ b/src/com/backtobedrock/augmentedhardcore/domain/data/LifeManager.java
@@ -0,0 +1,58 @@
+package com.backtobedrock.augmentedhardcore.domain.data;
+
+import com.backtobedrock.augmentedhardcore.AugmentedHardcore;
+
+/**
+ * Handles life and life-part bookkeeping for a player.
+ */
+public class LifeManager {
+ private final AugmentedHardcore plugin;
+ private int lives;
+ private int lifeParts;
+
+ public LifeManager(AugmentedHardcore plugin, int lives, int lifeParts) {
+ this.plugin = plugin;
+ this.setLives(lives);
+ this.setLifeParts(lifeParts);
+ }
+
+ public int getLives() {
+ return lives;
+ }
+
+ public void setLives(int lives) {
+ int maxLives = plugin.getConfigurations().getLivesAndLifePartsConfiguration().getMaxLives();
+ this.lives = Math.max(0, Math.min(lives, maxLives));
+ }
+
+ public void increaseLives(int amount) {
+ setLives(this.lives + amount);
+ }
+
+ public void decreaseLives(int amount) {
+ setLives(this.lives - amount);
+ }
+
+ public int getLifeParts() {
+ return lifeParts;
+ }
+
+ public void setLifeParts(int lifeParts) {
+ int lifePartsPerLife = plugin.getConfigurations().getLivesAndLifePartsConfiguration().getLifePartsPerLife();
+ int livesToAdd = Math.min(lifeParts / lifePartsPerLife,
+ plugin.getConfigurations().getLivesAndLifePartsConfiguration().getMaxLives() - this.getLives());
+ if (livesToAdd > 0) {
+ increaseLives(livesToAdd);
+ }
+ int maxLifeParts = plugin.getConfigurations().getLivesAndLifePartsConfiguration().getMaxLifeParts();
+ this.lifeParts = Math.min(maxLifeParts, Math.max(0, lifeParts - livesToAdd * lifePartsPerLife));
+ }
+
+ public void increaseLifeParts(int amount) {
+ setLifeParts(this.lifeParts + amount);
+ }
+
+ public void decreaseLifeParts(int amount) {
+ setLifeParts(this.lifeParts - amount);
+ }
+}
diff --git a/src/com/backtobedrock/augmentedhardcore/domain/data/PlayerData.java b/src/com/backtobedrock/augmentedhardcore/domain/data/PlayerData.java
index 07d68dd..ca89c4c 100644
--- a/src/com/backtobedrock/augmentedhardcore/domain/data/PlayerData.java
+++ b/src/com/backtobedrock/augmentedhardcore/domain/data/PlayerData.java
@@ -2,6 +2,7 @@
import com.backtobedrock.augmentedhardcore.AugmentedHardcore;
import com.backtobedrock.augmentedhardcore.domain.Ban;
+import com.backtobedrock.augmentedhardcore.domain.BanEntry;
import com.backtobedrock.augmentedhardcore.domain.Killer;
import com.backtobedrock.augmentedhardcore.domain.enums.DamageCause;
import com.backtobedrock.augmentedhardcore.domain.enums.Permission;
@@ -23,67 +24,60 @@
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
-import org.bukkit.plugin.java.JavaPlugin;
-import org.javatuples.Pair;
import java.time.LocalDateTime;
import java.util.*;
+import java.util.logging.Level;
public class PlayerData {
- private final AugmentedHardcore plugin = JavaPlugin.getPlugin(AugmentedHardcore.class);
+ private final AugmentedHardcore plugin;
private final OfflinePlayer player;
private final List playtime = new ArrayList<>();
private final Map, IObserver>> observers;
private final String lastKnownIp;
- private final NavigableMap bans;
+ private final BanManager banManager;
+ private final LifeManager lifeManager;
+ private final PlaytimeTracker playtimeTracker;
private List combatTag = new ArrayList<>();
private boolean kicked = false;
private boolean combatLogged = false;
private Killer combatTagger;
private Killer reviving;
- private int lives;
- private int lifeParts;
- private long timeTillNextRevive;
- private long timeTillNextLifePart;
- private long timeTillNextMaxHealth;
private boolean spectatorBanned;
private LocalDateTime lastDeath;
- public PlayerData(OfflinePlayer player) {
+ public PlayerData(AugmentedHardcore plugin, OfflinePlayer player) {
this(
+ plugin,
player,
null,
LocalDateTime.now(),
- JavaPlugin.getPlugin(AugmentedHardcore.class).getConfigurations().getLivesAndLifePartsConfiguration().getLivesAtStart(),
- JavaPlugin.getPlugin(AugmentedHardcore.class).getConfigurations().getLivesAndLifePartsConfiguration().getLifePartsAtStart(),
+ plugin.getConfigurations().getLivesAndLifePartsConfiguration().getLivesAtStart(),
+ plugin.getConfigurations().getLivesAndLifePartsConfiguration().getLifePartsAtStart(),
false,
- JavaPlugin.getPlugin(AugmentedHardcore.class).getConfigurations().getReviveConfiguration().isReviveOnFirstJoin() ? 0L : JavaPlugin.getPlugin(AugmentedHardcore.class).getConfigurations().getReviveConfiguration().getTimeBetweenRevives(),
- JavaPlugin.getPlugin(AugmentedHardcore.class).getConfigurations().getLivesAndLifePartsConfiguration().getPlaytimePerLifePart(),
- JavaPlugin.getPlugin(AugmentedHardcore.class).getConfigurations().getMaxHealthConfiguration().getPlaytimePerHalfHeart(),
+ plugin.getConfigurations().getReviveConfiguration().isReviveOnFirstJoin() ? 0L : plugin.getConfigurations().getReviveConfiguration().getTimeBetweenRevives(),
+ plugin.getConfigurations().getLivesAndLifePartsConfiguration().getPlaytimePerLifePart(),
+ plugin.getConfigurations().getMaxHealthConfiguration().getPlaytimePerHalfHeart(),
new TreeMap<>()
);
}
- public PlayerData(OfflinePlayer player, String lastKnownIp, LocalDateTime lastDeath, int lives, int lifeParts, boolean spectatorBanned, long timeTillNextRevive, long timeTillNextLifePart, long timeTillNextMaxHealth, NavigableMap bans) {
+ public PlayerData(AugmentedHardcore plugin, OfflinePlayer player, String lastKnownIp, LocalDateTime lastDeath, int lives, int lifeParts, boolean spectatorBanned, long timeTillNextRevive, long timeTillNextLifePart, long timeTillNextMaxHealth, NavigableMap bans) {
+ this.plugin = plugin;
this.player = player;
this.lastDeath = lastDeath;
- this.bans = bans;
this.observers = new HashMap<>();
this.spectatorBanned = spectatorBanned;
- this.setTimeTillNextLifePart(timeTillNextLifePart);
- this.setTimeTillNextMaxHealth(timeTillNextMaxHealth);
- this.setTimeTillNextRevive(timeTillNextRevive);
- this.setLives(lives);
- this.setLifeParts(lifeParts);
+ this.lifeManager = new LifeManager(plugin, lives, lifeParts);
+ this.playtimeTracker = new PlaytimeTracker(plugin, this, timeTillNextRevive, timeTillNextLifePart, timeTillNextMaxHealth);
+ this.banManager = new BanManager(bans);
if (player.getPlayer() != null) {
lastKnownIp = PlayerUtils.getPlayerIP(player.getPlayer());
}
this.lastKnownIp = lastKnownIp;
}
- public static PlayerData deserialize(ConfigurationSection section, OfflinePlayer player) {
- AugmentedHardcore plugin = JavaPlugin.getPlugin(AugmentedHardcore.class);
-
+ public static PlayerData deserialize(AugmentedHardcore plugin, ConfigurationSection section, OfflinePlayer player) {
NavigableMap cBans = new TreeMap<>();
String cLastKnownIp = section.getString("LastKnownIp", null);
LocalDateTime cLastDeath = LocalDateTime.parse(section.getString("LastDeath", LocalDateTime.now().toString()));
@@ -105,15 +99,19 @@ public static PlayerData deserialize(ConfigurationSection section, OfflinePlayer
}
}
- return new PlayerData(player, cLastKnownIp, cLastDeath, cLives, cLifeParts, cSpectatorBanned, cTimeTillNextRevive, cTimeTillNextLifePart, cTimeTillNextMaxHealth, cBans);
+ return new PlayerData(plugin, player, cLastKnownIp, cLastDeath, cLives, cLifeParts, cSpectatorBanned, cTimeTillNextRevive, cTimeTillNextLifePart, cTimeTillNextMaxHealth, cBans);
+ }
+
+ public PlaytimeTracker getPlaytimeTracker() {
+ return this.playtimeTracker;
}
public long getTimeTillNextRevive() {
- return timeTillNextRevive;
+ return this.playtimeTracker.getTimeTillNextRevive();
}
private void setTimeTillNextRevive(long timeTillNextRevive) {
- this.timeTillNextRevive = Math.max(0, Math.min(timeTillNextRevive, this.plugin.getConfigurations().getReviveConfiguration().getTimeBetweenRevives()));
+ this.playtimeTracker.setTimeTillNextRevive(timeTillNextRevive);
this.observers.forEach((key, value) -> value.get(MyStatsTimeTillNextReviveObserver.class).update());
}
@@ -121,12 +119,20 @@ public String getLastKnownIp() {
return this.lastKnownIp;
}
+ public LifeManager getLifeManager() {
+ return this.lifeManager;
+ }
+
+ public BanManager getBanManager() {
+ return this.banManager;
+ }
+
public int getLives() {
- return lives;
+ return this.lifeManager.getLives();
}
public void setLives(int lives) {
- this.lives = Math.max(0, Math.min(lives, this.plugin.getConfigurations().getLivesAndLifePartsConfiguration().getMaxLives()));
+ this.lifeManager.setLives(lives);
this.observers.forEach((key, value) -> value.get(MyStatsLivesObserver.class).update());
}
@@ -135,41 +141,40 @@ public OfflinePlayer getPlayer() {
}
public int getLifeParts() {
- return lifeParts;
+ return this.lifeManager.getLifeParts();
}
public void setLifeParts(int lifeParts) {
- int lifePartsPerLife = this.plugin.getConfigurations().getLivesAndLifePartsConfiguration().getLifePartsPerLife();
- int lives = Math.min(lifeParts / lifePartsPerLife, this.plugin.getConfigurations().getLivesAndLifePartsConfiguration().getMaxLives() - this.getLives());
- if (lives > 0) {
- this.increaseLives(lives);
- }
- this.lifeParts = Math.min(this.plugin.getConfigurations().getLivesAndLifePartsConfiguration().getMaxLifeParts(), Math.max(0, lifeParts - (lives * lifePartsPerLife)));
+ this.lifeManager.setLifeParts(lifeParts);
this.observers.forEach((key, value) -> value.get(MyStatsLifePartsObserver.class).update());
}
public NavigableMap getBans() {
- return bans;
+ return this.banManager.getBans();
}
public int getBanCount() {
- return this.bans.size();
+ return this.banManager.getBanCount();
}
private void decreaseLives(int amount) {
- this.setLives(this.getLives() - amount);
+ this.lifeManager.decreaseLives(amount);
+ this.observers.forEach((key, value) -> value.get(MyStatsLivesObserver.class).update());
}
public void increaseLives(int amount) {
- this.setLives(this.getLives() + amount);
+ this.lifeManager.increaseLives(amount);
+ this.observers.forEach((key, value) -> value.get(MyStatsLivesObserver.class).update());
}
private void decreaseLifeParts(int amount) {
- this.setLifeParts(this.getLifeParts() - amount);
+ this.lifeManager.decreaseLifeParts(amount);
+ this.observers.forEach((key, value) -> value.get(MyStatsLifePartsObserver.class).update());
}
public void increaseLifeParts(int amount) {
- this.setLifeParts(this.getLifeParts() + amount);
+ this.lifeManager.increaseLifeParts(amount);
+ this.observers.forEach((key, value) -> value.get(MyStatsLifePartsObserver.class).update());
}
public void onDeath(PlayerDeathEvent event, Player player) {
@@ -190,7 +195,7 @@ public void onDeath(PlayerDeathEvent event, Player player) {
this.loseMaxHealth(this.plugin.getConfigurations().getMaxHealthConfiguration().getMaxHealthDecreasePerDeath(), player);
if (this.plugin.getConfigurations().getLivesAndLifePartsConfiguration().isUseLives()) {
- if (this.lives == 0) {
+ if (this.getLives() == 0) {
this.loseLifeParts(this.plugin.getConfigurations().getLivesAndLifePartsConfiguration().getLifePartsLostPerDeathBan(), player);
this.ban(event, player);
} else {
@@ -332,16 +337,15 @@ private void ban(PlayerDeathEvent event, Player player) {
}
this.plugin.getServerRepository().getServerData(this.plugin.getServer()).thenAcceptAsync(serverData -> serverData.addBan(this, player, this.addBan(ban))).exceptionally(e -> {
- e.printStackTrace();
+ this.plugin.getLogger().log(Level.SEVERE, "Error processing death ban.", e);
return null;
});
}
- private Pair addBan(Ban ban) {
- int key = (this.bans.isEmpty() ? 0 : this.bans.lastKey()) + 1;
- this.bans.put(key, ban);
+ private BanEntry addBan(Ban ban) {
+ BanEntry entry = this.banManager.addBan(ban);
this.observers.forEach((k, value) -> value.get(MyStatsDeathBansObserver.class).update());
- return new Pair<>(key, ban);
+ return entry;
}
public void onRespawn(Player player) {
@@ -350,7 +354,7 @@ public void onRespawn(Player player) {
}
if (this.plugin.getConfigurations().getLivesAndLifePartsConfiguration().isUseLives()) {
- if (this.lives != 0) {
+ if (this.getLives() != 0) {
return;
}
@@ -419,7 +423,7 @@ private void onMaxHealthEntityKill(EntityType type, Player player) {
this.gainMaxHealth(this.plugin.getConfigurations().getMaxHealthConfiguration().getMaxHealthIncreasePerKill().getOrDefault(type, 0D), player);
}
- private void gainLifeParts(int amount, Player player) {
+ void gainLifeParts(int amount, Player player) {
//check if in disabled world
if (this.plugin.getConfigurations().getLivesAndLifePartsConfiguration().getDisableGainingLifePartsInWorlds().contains(player.getWorld().getName().toLowerCase())) {
return;
@@ -428,7 +432,7 @@ private void gainLifeParts(int amount, Player player) {
this.increaseLifeParts(amount);
}
- private void gainMaxHealth(double amount, Player player) {
+ void gainMaxHealth(double amount, Player player) {
//check if in disabled world
if (this.plugin.getConfigurations().getMaxHealthConfiguration().getDisableGainingMaxHealthInWorlds().contains(player.getWorld().getName().toLowerCase())) {
return;
@@ -438,33 +442,59 @@ private void gainMaxHealth(double amount, Player player) {
}
public void onCombatTag(Killer tagger, Player player) {
- if (this.isSpectatorBanned()) {
- return;
- }
-
- if (!this.plugin.getConfigurations().getCombatTagConfiguration().isUseCombatTag()) {
- return;
- }
-
- if (tagger == null) {
- return;
- }
-
- //check if combat tag self enabled and if self harming
- if (!this.plugin.getConfigurations().getCombatTagConfiguration().isCombatTagSelf() && tagger.getName().equals(this.player.getName())) {
- return;
- }
-
- //check if in disabled worlds
- if (this.plugin.getConfigurations().getCombatTagConfiguration().getDisableCombatTagInWorlds().contains(player.getWorld().getName().toLowerCase())) {
- return;
+ // 1) Spectator or disabled → do nothing
+ if (isSpectatorBanned()) return;
+ if (!plugin.getConfigurations().getCombatTagConfiguration().isUseCombatTag()) return;
+
+ // 2) Null or self-tagging disabled → do nothing
+ if (tagger == null) return;
+ if (!plugin.getConfigurations().getCombatTagConfiguration().isCombatTagSelf()
+ && tagger.getName().equals(player.getName())) return;
+
+ // 3) Disabled world → do nothing
+ String worldName = player.getWorld().getName().toLowerCase();
+ if (plugin.getConfigurations().getCombatTagConfiguration()
+ .getDisableCombatTagInWorlds()
+ .contains(worldName)) {
+ return;
+ }
+
+ // 4) Make sure our list exists
+ if (combatTag == null) {
+ combatTag = new ArrayList<>();
+ }
+
+ // 5) If we already have tags, restart them—filtering out and logging any nulls
+ if (!combatTag.isEmpty()) {
+ Iterator it = combatTag.iterator();
+ while (it.hasNext()) {
+ AbstractCombatTag tag = it.next();
+ if (tag != null) {
+ tag.restart(tagger);
+ } else {
+ plugin.getLogger().warning(
+ "[CombatTag] Found and removed null entry for player " + player.getName()
+ );
+ it.remove();
+ }
+ }
}
-
- if (!this.combatTag.isEmpty()) {
- this.combatTag.forEach(e -> e.restart(tagger));
- } else {
- this.combatTag = this.plugin.getMessages().getCombatTagNotificationsConfiguration(player, this, tagger);
- this.combatTag.forEach(AbstractCombatTag::start);
+ // 6) Otherwise, create and start new tags
+ else {
+ combatTag = plugin.getMessages()
+ .getCombatTagNotificationsConfiguration(player, this, tagger);
+ Iterator it = combatTag.iterator();
+ while (it.hasNext()) {
+ AbstractCombatTag tag = it.next();
+ if (tag != null) {
+ tag.start();
+ } else {
+ plugin.getLogger().warning(
+ "[CombatTag] Dropped null new‐tag for player " + player.getName()
+ );
+ it.remove();
+ }
+ }
}
}
@@ -539,96 +569,26 @@ public void resetSpectatorDeathBan(Player player) {
}
public void decreaseTimeTillNextLifePart(int amount, Player player) {
- if (this.isSpectatorBanned()) {
- return;
- }
-
- if (!this.plugin.getConfigurations().getLivesAndLifePartsConfiguration().isUseLifeParts()) {
- return;
- }
-
- if (!this.plugin.getConfigurations().getLivesAndLifePartsConfiguration().isGetLifePartsByPlaytime()) {
- return;
- }
-
- if (player.hasPermission(Permission.BYPASS_GAINLIFEPARTS_PLAYTIME.getPermissionString())) {
- return;
- }
-
- if (this.plugin.getConfigurations().getLivesAndLifePartsConfiguration().getDisableGainingLifePartsInWorlds().contains(player.getWorld().getName().toLowerCase())) {
- return;
- }
-
- if (this.lifeParts >= this.plugin.getConfigurations().getLivesAndLifePartsConfiguration().getMaxLifeParts()) {
- return;
- }
-
- long decreased = this.getTimeTillNextLifePart() - amount;
- if (decreased <= 0) {
- this.gainLifeParts(1, player);
- this.setTimeTillNextLifePart(this.plugin.getConfigurations().getLivesAndLifePartsConfiguration().getPlaytimePerLifePart() - Math.abs(decreased));
- } else {
- this.setTimeTillNextLifePart(decreased);
- }
+ this.playtimeTracker.decreaseTimeTillNextLifePart(amount, player);
+ this.observers.forEach((key, value) -> value.get(MyStatsTimeTillNextLifePartObserver.class).update());
}
public void decreaseTimeTillNextMaxHealth(int amount, Player player) {
- if (this.isSpectatorBanned()) {
- return;
- }
-
- if (!this.plugin.getConfigurations().getMaxHealthConfiguration().isUseMaxHealth()) {
- return;
- }
-
- if (!this.plugin.getConfigurations().getMaxHealthConfiguration().isGetMaxHealthByPlaytime()) {
- return;
- }
-
- if (player.hasPermission(Permission.BYPASS_GAINMAXHEALTH_PLAYTIME.getPermissionString())) {
- return;
- }
-
- if (this.plugin.getConfigurations().getMaxHealthConfiguration().getDisableGainingMaxHealthInWorlds().contains(player.getWorld().getName().toLowerCase())) {
- return;
- }
-
- double value = PlayerUtils.getMaxHealth(player);
- if (value >= this.plugin.getConfigurations().getMaxHealthConfiguration().getMaxHealth()) {
- return;
- }
-
- long decreased = this.getTimeTillNextMaxHealth() - amount;
- if (decreased <= 0) {
- this.gainMaxHealth(1D, player);
- this.setTimeTillNextMaxHealth(this.plugin.getConfigurations().getMaxHealthConfiguration().getPlaytimePerHalfHeart() - Math.abs(decreased));
- } else {
- this.setTimeTillNextMaxHealth(decreased);
- }
+ this.playtimeTracker.decreaseTimeTillNextMaxHealth(amount, player);
+ this.observers.forEach((key, value) -> value.get(MyStatsTimeTillNextMaxHealthObserver.class).update());
}
public void decreaseTimeTillNextRevive(int amount) {
- if (this.isSpectatorBanned()) {
- return;
- }
-
- if (!this.plugin.getConfigurations().getReviveConfiguration().isUseRevive()) {
- return;
- }
-
- if (this.timeTillNextRevive == 0) {
- return;
- }
-
- this.setTimeTillNextRevive(this.getTimeTillNextRevive() - amount);
+ this.playtimeTracker.decreaseTimeTillNextRevive(amount);
+ this.observers.forEach((key, value) -> value.get(MyStatsTimeTillNextReviveObserver.class).update());
}
public long getTimeTillNextMaxHealth() {
- return this.timeTillNextMaxHealth;
+ return this.playtimeTracker.getTimeTillNextMaxHealth();
}
private void setTimeTillNextMaxHealth(long timeTillNextMaxHealth) {
- this.timeTillNextMaxHealth = Math.max(0, Math.min(timeTillNextMaxHealth, this.plugin.getConfigurations().getMaxHealthConfiguration().getPlaytimePerHalfHeart()));
+ this.playtimeTracker.setTimeTillNextMaxHealth(timeTillNextMaxHealth);
this.observers.forEach((key, value) -> value.get(MyStatsTimeTillNextMaxHealthObserver.class).update());
}
@@ -745,7 +705,7 @@ public boolean checkRevivePermissionsReviver(OfflinePlayer reviving, Player play
}
//check if revive on cooldown
- if (this.timeTillNextRevive > 0 && !player.hasPermission(Permission.BYPASS_REVIVECOOLDOWN.getPermissionString())) {
+ if (this.getTimeTillNextRevive() > 0 && !player.hasPermission(Permission.BYPASS_REVIVECOOLDOWN.getPermissionString())) {
player.sendMessage(String.format("§cYou cannot revive %s for another %s.", reviving.getName(), MessageUtils.getTimeFromTicks(this.getTimeTillNextRevive(), TimePattern.LONG)));
return false;
}
@@ -768,11 +728,11 @@ public void onRevive(Player reviver) {
}
public long getTimeTillNextLifePart() {
- return timeTillNextLifePart;
+ return this.playtimeTracker.getTimeTillNextLifePart();
}
private void setTimeTillNextLifePart(long timeTillNextLifePart) {
- this.timeTillNextLifePart = Math.max(0, Math.min(timeTillNextLifePart, this.plugin.getConfigurations().getLivesAndLifePartsConfiguration().getPlaytimePerLifePart()));
+ this.playtimeTracker.setTimeTillNextLifePart(timeTillNextLifePart);
this.observers.forEach((key, value) -> value.get(MyStatsTimeTillNextLifePartObserver.class).update());
}
@@ -784,15 +744,15 @@ public Map serialize() {
Map map = new HashMap<>();
Map