Performs some minor changes
Changes some warning messages to info Displays sign creation cost when unable to create a paid sign Changes spigot dependency to 1.19 Refunds the player during reload/startup when a tracked sign's physical sign has been destroyed
This commit is contained in:
parent
b1aefdd9d9
commit
35e0666a1d
2
pom.xml
2
pom.xml
@ -73,7 +73,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.18.1-R0.1-SNAPSHOT</version>
|
||||
<version>1.19-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -87,7 +87,7 @@ public final class Translator {
|
||||
}
|
||||
|
||||
try {
|
||||
PaidSigns.getInstance().getLogger().log(Level.WARNING, "Loading custom strings...");
|
||||
PaidSigns.getInstance().getLogger().log(Level.INFO, "Loading custom strings...");
|
||||
return loadTranslatableMessages(language, new BufferedReader(new InputStreamReader(new FileInputStream(strings))));
|
||||
} catch (FileNotFoundException e) {
|
||||
PaidSigns.getInstance().getLogger().log(Level.WARNING, "Unable to load custom messages");
|
||||
|
@ -71,14 +71,13 @@ public class SignListener implements Listener {
|
||||
double cost = paidSign.getCost();
|
||||
boolean canAfford = EconomyManager.canAfford(player, cost);
|
||||
if (!canAfford) {
|
||||
player.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.ERROR_CANNOT_AFFORD));
|
||||
player.sendMessage(replaceCost(cost, StringFormatter.getTranslatedErrorMessage(
|
||||
TranslatableMessage.ERROR_CANNOT_AFFORD)));
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
String unit = EconomyManager.getCurrency(cost != 1);
|
||||
EconomyManager.withdraw(player, cost);
|
||||
player.sendMessage(String.format(StringFormatter.replacePlaceholders(
|
||||
StringFormatter.getTranslatedInfoMessage(TranslatableMessage.SUCCESS_PAID_FOR_SIGN),
|
||||
new String[]{"{cost}", "{unit}"}, new String[]{"%.2f", "%s"}), cost, unit));
|
||||
player.sendMessage(replaceCost(cost, StringFormatter.getTranslatedInfoMessage(
|
||||
TranslatableMessage.SUCCESS_PAID_FOR_SIGN)));
|
||||
try {
|
||||
TrackedSignManager.addTrackedSign(event.getBlock().getLocation(), player.getUniqueId(), cost);
|
||||
} catch (IOException ignored) {
|
||||
@ -86,4 +85,17 @@ public class SignListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces cost and unit placeholders in the given message
|
||||
*
|
||||
* @param cost <p>The cost to insert</p>
|
||||
* @param message <p>The original message to replace the cost placeholder for</p>
|
||||
* @return <p>The message with the cost instead of the cost placeholder</p>
|
||||
*/
|
||||
private String replaceCost(double cost, String message) {
|
||||
String unit = EconomyManager.getCurrency(cost != 1);
|
||||
return String.format(StringFormatter.replacePlaceholders(message, new String[]{"{cost}", "{unit}"},
|
||||
new String[]{"%.2f", "%s"}), cost, unit);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ public final class PaidSignManager {
|
||||
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(signsFile);
|
||||
ConfigurationSection signSection = configuration.getConfigurationSection("paidSigns");
|
||||
if (signSection == null) {
|
||||
PaidSigns.getInstance().getLogger().log(Level.WARNING, "Signs section not found in data.yml");
|
||||
PaidSigns.getInstance().getLogger().log(Level.INFO, "Signs section not found in data.yml");
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@ import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -59,18 +58,7 @@ public final class TrackedSignManager {
|
||||
TrackedSign trackedSign = trackedSigns.get(signLocation);
|
||||
trackedSigns.remove(signLocation);
|
||||
saveTrackedSigns();
|
||||
if (!PaidSigns.getInstance().areRefundsEnabled() || !refund) {
|
||||
return;
|
||||
}
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(trackedSign.getPlayerId());
|
||||
double refundSum = trackedSign.getCost() / 100 * PaidSigns.getInstance().getRefundPercentage();
|
||||
EconomyManager.deposit(offlinePlayer, refundSum);
|
||||
if (offlinePlayer instanceof Player player) {
|
||||
player.sendMessage(String.format(StringFormatter.replacePlaceholders(
|
||||
StringFormatter.getTranslatedInfoMessage(TranslatableMessage.SUCCESS_REFUNDED),
|
||||
new String[]{"{cost}", "{unit}"}, new String[]{"%.2f", "%s"}), refundSum,
|
||||
EconomyManager.getCurrency(refundSum != 1)));
|
||||
}
|
||||
refund(trackedSign, refund);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,17 +70,12 @@ public final class TrackedSignManager {
|
||||
trackedSigns = new HashMap<>();
|
||||
|
||||
if (signSection == null) {
|
||||
PaidSigns.getInstance().getLogger().log(Level.WARNING, "Tracked signs section not found in data.yml");
|
||||
PaidSigns.getInstance().getLogger().log(Level.INFO, "Tracked signs section not found in data.yml");
|
||||
return;
|
||||
}
|
||||
|
||||
for (String key : signSection.getKeys(false)) {
|
||||
try {
|
||||
loadSign(signSection, key);
|
||||
} catch (InvalidConfigurationException e) {
|
||||
PaidSigns.getInstance().getLogger().log(Level.SEVERE, "Unable to load sign " + key + ": " +
|
||||
e.getMessage());
|
||||
}
|
||||
loadSign(signSection, key);
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,9 +84,8 @@ public final class TrackedSignManager {
|
||||
*
|
||||
* @param signSection <p>The configuration section containing signs</p>
|
||||
* @param key <p>The sign key which is also the sign's location</p>
|
||||
* @throws InvalidConfigurationException <p>If unable to load the sign</p>
|
||||
*/
|
||||
private static void loadSign(ConfigurationSection signSection, String key) throws InvalidConfigurationException {
|
||||
private static void loadSign(ConfigurationSection signSection, String key) {
|
||||
String[] locationParts = key.split(",");
|
||||
Location signLocation;
|
||||
try {
|
||||
@ -111,20 +93,23 @@ public final class TrackedSignManager {
|
||||
Double.parseDouble(locationParts[1]), Double.parseDouble(locationParts[2]),
|
||||
Double.parseDouble(locationParts[3]));
|
||||
} catch (NumberFormatException exception) {
|
||||
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.");
|
||||
PaidSigns.getInstance().getLogger().log(Level.SEVERE, "Unable to load tracked sign " + key + ": " +
|
||||
exception.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
double cost = signSection.getDouble(key + ".cost");
|
||||
UUID playerId = UUID.fromString(Objects.requireNonNull(signSection.getString(key + ".playerId")));
|
||||
|
||||
TrackedSign trackedSign = new TrackedSign(playerId, cost);
|
||||
|
||||
//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. Refunding the player.");
|
||||
refund(trackedSign, true);
|
||||
return;
|
||||
}
|
||||
|
||||
trackedSigns.put(signLocation, trackedSign);
|
||||
}
|
||||
|
||||
@ -147,4 +132,25 @@ public final class TrackedSignManager {
|
||||
configuration.save(signsFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refunds the player for the sign if refunds are enabled and refund is set to true
|
||||
*
|
||||
* @param trackedSign <p>The tracked sign to refund for</p>
|
||||
* @param refund <p>Whether to actually refund</p>
|
||||
*/
|
||||
private static void refund(TrackedSign trackedSign, boolean refund) {
|
||||
if (!PaidSigns.getInstance().areRefundsEnabled() || !refund) {
|
||||
return;
|
||||
}
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(trackedSign.getPlayerId());
|
||||
double refundSum = trackedSign.getCost() / 100 * PaidSigns.getInstance().getRefundPercentage();
|
||||
EconomyManager.deposit(offlinePlayer, refundSum);
|
||||
if (offlinePlayer instanceof Player player) {
|
||||
player.sendMessage(String.format(StringFormatter.replacePlaceholders(
|
||||
StringFormatter.getTranslatedInfoMessage(TranslatableMessage.SUCCESS_REFUNDED),
|
||||
new String[]{"{cost}", "{unit}"}, new String[]{"%.2f", "%s"}), refundSum,
|
||||
EconomyManager.getCurrency(refundSum != 1)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,6 @@ en:
|
||||
ERROR_INVALID_INPUT: "&bInvalid input: {input}"
|
||||
ERROR_PAID_SIGN_NOT_FOUND: "&bNo such paid sign exists"
|
||||
ERROR_NO_SUCH_CONDITION: "&bThe paid sign you specified has no condition for line {line}"
|
||||
ERROR_CANNOT_AFFORD: "&bYou cannot afford to create this sign"
|
||||
ERROR_CANNOT_AFFORD: "&bYou cannot afford to create this sign. The cost is {cost} {unit}"
|
||||
ERROR_INVALID_REGULAR_EXPRESSION: "&bThe provided regular expression is invalid"
|
||||
ERROR_PROPERTY_NOT_RECOGNIZED: "&bThe property you tried to change was not recognized"
|
Loading…
Reference in New Issue
Block a user