Skip to content

Commit

Permalink
Fix #10 (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
srnyx committed Dec 16, 2023
1 parent 7ed93ec commit f88de47
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/main/java/xyz/srnyx/limitedlives/LimitedConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,24 @@ public class LimitedConfig {
public final int livesMax;
public final int livesMin;
@NotNull public final Set<EntityDamageEvent.DamageCause> deathCauses;
public final boolean stealing;
@Nullable public final Recipe recipe;
public final int recipeAmount;
public final boolean keepInventoryIntegration;
@NotNull public final List<String> commandsPunishmentDeath;
@NotNull public final List<String> commandsPunishmentRespawn;
@NotNull public final List<String> commandsRevive;
public final boolean stealing;
@Nullable public final Recipe recipe;
public final int recipeAmount;

public LimitedConfig(@NotNull LimitedLives plugin) {
final AnnoyingResource config = new AnnoyingResource(plugin, "config.yml");

// livesDefault, livesMax, & livesMin
final ConfigurationSection lives = config.getConfigurationSection("lives");
final boolean hasLives = lives != null;
livesDefault = hasLives ? lives.getInt("default", 5) : 5;
livesMax = hasLives ? lives.getInt("max", 10) : 10;
livesMin = hasLives ? lives.getInt("min", 0) : 0;

// deathCauses
deathCauses = config.getStringList("death-causes").stream()
.map(string -> {
Expand All @@ -47,6 +55,9 @@ public LimitedConfig(@NotNull LimitedLives plugin) {
.filter(Objects::nonNull)
.collect(Collectors.toSet());

// keepInventoryIntegration
keepInventoryIntegration = config.getBoolean("keep-inventory-integration", false);

// commandsPunishmentDeath, commandsPunishmentRespawn, & commandsRevive
final ConfigurationSection commands = config.getConfigurationSection("commands");
final boolean hasCommands = commands != null;
Expand All @@ -56,13 +67,6 @@ public LimitedConfig(@NotNull LimitedLives plugin) {
commandsPunishmentRespawn = hasPunishment ? punishment.getStringList("respawn") : Collections.emptyList();
commandsRevive = hasCommands ? commands.getStringList("revive") : Collections.emptyList();

// livesDefault, livesMax, & livesMin
final ConfigurationSection lives = config.getConfigurationSection("lives");
final boolean hasLives = lives != null;
livesDefault = hasLives ? lives.getInt("default", 5) : 5;
livesMax = hasLives ? lives.getInt("max", 10) : 10;
livesMin = hasLives ? lives.getInt("min", 0) : 0;

// stealing
final ConfigurationSection obtaining = config.getConfigurationSection("obtaining");
final boolean hasObtaining = obtaining != null;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/xyz/srnyx/limitedlives/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public void onPlayerDeath(@NotNull PlayerDeathEvent event) {
if (newLives == null || newLives == plugin.config.livesMin) {
// No more lives
new AnnoyingMessage(plugin, "lives.zero").send(player);
// keepInventoryIntegration
if (plugin.config.keepInventoryIntegration && player.getWorld().getGameRuleValue("keepInventory").equals("true")) event.setKeepInventory(false);
} else if (isPvp) {
// Lose to player
new AnnoyingMessage(plugin, "lives.lose.player")
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ lives:
# Available causes: https://helpch.at/docs/MC_VERSION/org/bukkit/event/entity/EntityDamageEvent.DamageCause.html
death-causes: []

# true:
# keepInventory gamerule = true: players will only lose their inventories when they lose their last life
# keepInventory gamerule = false: players will lose their inventories when they lose any amount of lives (vanilla behavior)
# false:
# keepInventory gamerule = true: players will keep their inventories when they lose any amount of lives (vanilla behavior)
# keepInventory gamerule = false: players will lose their inventories when they lose any amount of lives (vanilla behavior)
# So, in order for this to have any effect, this and keepInventory must be both true
keep-inventory-integration: false

commands:
# The commands that will be executed when a player loses all their lives (executed by the console)
# %player% - The player that lost all their lives
Expand Down

0 comments on commit f88de47

Please sign in to comment.