Skip to content

Commit

Permalink
Fix respawn commands when there isn't a killer
Browse files Browse the repository at this point in the history
  • Loading branch information
srnyx committed Aug 12, 2023
1 parent 2549d0d commit 854bd3b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/main/java/xyz/srnyx/limitedlives/LimitedLives.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class LimitedLives extends AnnoyingPlugin {
/**
* player, lives
*/
@Nullable public Map<UUID, Integer> oldLives = new HashMap<>();
@Nullable public Map<UUID, Integer> oldLivesData = new HashMap<>();
/**
* player, killer
*/
Expand All @@ -53,11 +53,11 @@ public LimitedLives() {
// oldLives
final ConfigurationSection livesSection = oldData.getConfigurationSection("lives");
if (livesSection != null) for (final String key : livesSection.getKeys(false)) try {
oldLives.put(UUID.fromString(key), livesSection.getInt(key));
oldLivesData.put(UUID.fromString(key), livesSection.getInt(key));
} catch (final IllegalArgumentException e) {
log(Level.WARNING, "&cInvalid UUID in &4data.yml&c: &4" + key);
}
if (oldLives.isEmpty()) oldLives = null;
if (oldLivesData.isEmpty()) oldLivesData = null;

// oldDeadPlayers
final ConfigurationSection deadPlayersSection = oldData.getConfigurationSection("dead-players");
Expand All @@ -82,7 +82,7 @@ public LimitedLives() {
if (oldDeadPlayers.isEmpty()) oldDeadPlayers = null;

// No old data loaded
if (oldLives != null || oldDeadPlayers != null) return;
if (oldLivesData != null || oldDeadPlayers != null) return;
oldData.delete();
oldData = null;
}
Expand Down Expand Up @@ -142,7 +142,7 @@ private void revive(@NotNull Player player) {
}

private void kill(@NotNull Player player, @Nullable Player killer) {
new EntityData(this, player).set(DEAD_KEY, killer != null ? killer.getUniqueId().toString() : null);
new EntityData(this, player).set(DEAD_KEY, killer != null ? killer.getUniqueId().toString() : "null");
dispatchCommands(config.commandsPunishmentDeath, player, killer);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xyz.srnyx.limitedlives.listeners;

import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent;
Expand Down Expand Up @@ -76,16 +77,16 @@ public void onPlayerRespawn(@NotNull PlayerRespawnEvent event) {
final String killerString = data.get(LimitedLives.DEAD_KEY);
if (killerString == null) return;
data.remove(LimitedLives.DEAD_KEY);
UUID killerUuid = null;
try {
killerUuid = UUID.fromString(killerString);
OfflinePlayer killer = null;
if (!killerString.equals("null")) try {
killer = Bukkit.getOfflinePlayer(UUID.fromString(killerString));
} catch (final IllegalArgumentException ignored) {
// ignored
}
final UUID finalKillerUuid = killerUuid;
final OfflinePlayer finalKiller = killer;
new BukkitRunnable() {
public void run() {
LimitedLives.dispatchCommands(plugin.config.commandsPunishmentRespawn, player, finalKillerUuid == null ? null : Bukkit.getOfflinePlayer(finalKillerUuid));
LimitedLives.dispatchCommands(plugin.config.commandsPunishmentRespawn, player, finalKiller);
}
}.runTaskLater(plugin, 1);
}
Expand Down Expand Up @@ -121,8 +122,8 @@ public void onPlayerJoin(@NotNull PlayerJoinEvent event) {
boolean save = false;

// oldLives
if (plugin.oldLives != null) {
final Integer lives = plugin.oldLives.remove(uuid);
if (plugin.oldLivesData != null) {
final Integer lives = plugin.oldLivesData.remove(uuid);
if (lives != null) {
data.set(LimitedLives.LIVES_KEY, lives);
plugin.oldData.set("lives." + uuid, null);
Expand Down

0 comments on commit 854bd3b

Please sign in to comment.