Makes sure signs are no longer tracked if they no longer exist

This commit is contained in:
Kristian Knarvik 2022-02-28 15:35:58 +01:00
parent 797020aa7f
commit 483ffaec2b

View File

@ -5,6 +5,7 @@ import net.knarcraft.paidsigns.container.TrackedSign;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.block.Sign;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -107,6 +108,13 @@ public final class TrackedSignManager {
throw new InvalidConfigurationException("Invalid sign coordinates"); throw new InvalidConfigurationException("Invalid sign coordinates");
} }
//Prevent destroyed signs from being tracked indefinitely
if (!(signLocation.getBlock().getState() instanceof Sign)) {
PaidSigns.getInstance().getLogger().log(Level.WARNING, "The sign at " + signLocation + " no longer " +
"exists. Removing from sign tracker.");
return;
}
double cost = signSection.getDouble(key + ".cost"); double cost = signSection.getDouble(key + ".cost");
UUID playerId = UUID.fromString(Objects.requireNonNull(signSection.getString(key + ".playerId"))); UUID playerId = UUID.fromString(Objects.requireNonNull(signSection.getString(key + ".playerId")));