Registers the block break listener and adds some small improvements
This commit is contained in:
@@ -8,6 +8,7 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -20,11 +21,15 @@ import java.util.logging.Level;
|
||||
/**
|
||||
* A manager for keeping track of plugin-signs created by players
|
||||
*/
|
||||
public class TrackedSignManager {
|
||||
public final class TrackedSignManager {
|
||||
|
||||
private static Map<Location, TrackedSign> trackedSigns = new HashMap<>();
|
||||
private static final File signsFile = new File(PaidSigns.getInstance().getDataFolder(), "data.yml");
|
||||
|
||||
private TrackedSignManager() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a tracked sign to the manager
|
||||
*
|
||||
@@ -47,15 +52,18 @@ public class TrackedSignManager {
|
||||
if (!trackedSigns.containsKey(signLocation)) {
|
||||
return;
|
||||
}
|
||||
TrackedSign trackedSign = trackedSigns.get(signLocation);
|
||||
trackedSigns.remove(signLocation);
|
||||
saveTrackedSigns();
|
||||
if (!PaidSigns.getInstance().areRefundsEnabled()) {
|
||||
return;
|
||||
}
|
||||
TrackedSign trackedSign = trackedSigns.get(signLocation);
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(trackedSign.getPlayerId());
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(trackedSign.getPlayerId());
|
||||
double refundSum = trackedSign.getCost() / 100 * PaidSigns.getInstance().getRefundPercentage();
|
||||
EconomyManager.withdraw(player, refundSum);
|
||||
EconomyManager.withdraw(offlinePlayer, -refundSum);
|
||||
if (offlinePlayer instanceof Player player) {
|
||||
player.sendMessage("You were refunded " + refundSum + " for your broken sign");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,7 +75,7 @@ public class TrackedSignManager {
|
||||
trackedSigns = new HashMap<>();
|
||||
|
||||
if (signSection == null) {
|
||||
PaidSigns.getInstance().getLogger().log(Level.WARNING, "Signs section not found in data.yml");
|
||||
PaidSigns.getInstance().getLogger().log(Level.WARNING, "Tracked signs section not found in data.yml");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -120,7 +128,7 @@ public class TrackedSignManager {
|
||||
String locationString = Objects.requireNonNull(signLocation.getWorld()).getUID() + "," +
|
||||
signLocation.getBlockX() + "," + signLocation.getBlockY() + "," + signLocation.getBlockZ();
|
||||
signSection.set(locationString + ".cost", sign.getCost());
|
||||
signSection.set(locationString + ".playerId", sign.getPlayerId());
|
||||
signSection.set(locationString + ".playerId", sign.getPlayerId().toString());
|
||||
}
|
||||
configuration.save(signsFile);
|
||||
}
|
||||
|
Reference in New Issue
Block a user