Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented the unused MONEY_EARNED_OFFLINE lang #216

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/main/java/com/bgsoftware/wildchests/WildChestsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.bukkit.World;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.Inventory;
import org.bukkit.plugin.java.JavaPlugin;

Expand Down Expand Up @@ -138,6 +139,8 @@ public void onDisable() {
Executor.stop();
log("Terminating database...");
SQLHelper.close();
log("Terminating events...");
HandlerList.unregisterAll(this);
}

private void loadAPI() {
Expand Down Expand Up @@ -188,8 +191,8 @@ private boolean loadNMSAdapter() {

if (version != null) {
try {
nmsAdapter = (NMSAdapter) Class.forName(String.format("com.bgsoftware.wildchests.nms.%s.NMSAdapter", version)).newInstance();
nmsInventory = (NMSInventory) Class.forName(String.format("com.bgsoftware.wildchests.nms.%s.NMSInventory", version)).newInstance();
nmsAdapter = (NMSAdapter) Class.forName(String.format("com.bgsoftware.wildchests.nms.%s.NMSAdapter", version)).getDeclaredConstructor().newInstance();
nmsInventory = (NMSInventory) Class.forName(String.format("com.bgsoftware.wildchests.nms.%s.NMSInventory", version)).getDeclaredConstructor().newInstance();

return true;
} catch (Exception error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

@SuppressWarnings("ResultOfMethodCallIgnored")
public final class DataHandler {
Expand All @@ -56,13 +54,13 @@ public void saveDatabase(Chunk chunk, boolean async) {

List<Chest> regularModifiedChests = chestList.stream()
.filter(chest -> chest.getChestType() == ChestType.CHEST)
.collect(Collectors.toList());
.toList();
List<Chest> storageModifiedChests = chestList.stream()
.filter(chest -> chest.getChestType() == ChestType.STORAGE_UNIT)
.collect(Collectors.toList());
.toList();
List<Chest> linkedChestsModifiedChests = chestList.stream()
.filter(chest -> chest.getChestType() == ChestType.LINKED_CHEST)
.collect(Collectors.toList());
.toList();

if (!regularModifiedChests.isEmpty()) {
StatementHolder chestsUpdateHolder = Query.REGULAR_CHEST_UPDATE_INVENTORIES.getStatementHolder(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private void registerPricesProvider(WildChestsPlugin plugin) {
.flatMap(shopsProvider -> shopsProvider.createInstance(plugin).map(shopsBridge ->
new PricesProvider_ShopsBridgeWrapper(shopsProvider, shopsBridge)));

if (!pricesProvider.isPresent()) {
if (pricesProvider.isEmpty()) {
WildChestsPlugin.log("- Couldn't find any prices providers, using default one");
return;
}
Expand Down Expand Up @@ -277,7 +277,7 @@ private <T> Optional<T> createInstance(String className) {
return Optional.of((T) constructor.newInstance(plugin));
} catch (Exception error) {
// noinspection unchecked
return Optional.of((T) clazz.newInstance());
return Optional.of((T) clazz.getDeclaredConstructor().newInstance());
}
} catch (ClassNotFoundException ignored) {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public final class SettingsHandler {
public final boolean invalidWorldDelete;
public final boolean wildStackerHook;
public final int maximumPickupDelay;
public final int offlineMoneyMessageDelay;

public SettingsHandler(WildChestsPlugin plugin) {
WildChestsPlugin.log("Loading configuration started...");
Expand Down Expand Up @@ -67,6 +68,7 @@ public SettingsHandler(WildChestsPlugin plugin) {
invalidWorldDelete = cfg.getBoolean("database.invalid-world-delete", false);
wildStackerHook = cfg.getBoolean("hooks.wildstacker", true);
maximumPickupDelay = cfg.getInt("maximum-pickup-delay", 32767);
offlineMoneyMessageDelay = cfg.getInt("offline-money-message-delay",10);

Map<String, Double> prices = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.bgsoftware.wildchests.listeners;

import com.bgsoftware.wildchests.Locale;
import com.bgsoftware.wildchests.WildChestsPlugin;
import com.bgsoftware.wildchests.utils.ChestUtils;
import com.bgsoftware.wildchests.utils.Executor;
import com.bgsoftware.wildchests.utils.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;

import java.math.BigDecimal;

@SuppressWarnings("unused")
public final class PlayerListener implements Listener {

Expand All @@ -33,6 +39,14 @@ public void onPlayerJoin(PlayerJoinEvent e){
e.getPlayer().sendMessage(ChatColor.DARK_PURPLE + "" + ChatColor.BOLD + "WildChests" +
ChatColor.GRAY + " A new version is available (v" + plugin.getUpdater().getLatestVersion() + ")!"), 20L);
}
Bukkit.getScheduler().runTaskLater(plugin,()->{
if (ChestUtils.offlineDeposit.containsKey(e.getPlayer().getUniqueId())) {
BigDecimal bigdecimal = BigDecimal.valueOf(ChestUtils.offlineDeposit.get(e.getPlayer().getUniqueId()));
Locale.MONEY_EARNED_OFFLINE.send(e.getPlayer(), plugin.getSettings().sellFormat ?
StringUtils.fancyFormat(bigdecimal) : StringUtils.format(bigdecimal));
ChestUtils.offlineDeposit.remove(e.getPlayer().getUniqueId());
}
}, plugin.getSettings().offlineMoneyMessageDelay);
}

}
10 changes: 4 additions & 6 deletions src/main/java/com/bgsoftware/wildchests/utils/ChestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.function.BiPredicate;

public final class ChestUtils {
Expand All @@ -30,6 +25,7 @@ public final class ChestUtils {

private static final WildChestsPlugin plugin = WildChestsPlugin.getPlugin();
public static final short DEFAULT_COOLDOWN = 20;
public static final HashMap<UUID, Double> offlineDeposit = new HashMap<>();

public static final BiPredicate<Item, ChestData> SUCTION_PREDICATE = (item, chestData) -> {
Key itemKey = item.getItemStack() == null ? Key.of("AIR:0") : Key.of(item.getItemStack());
Expand Down Expand Up @@ -183,6 +179,8 @@ public static boolean trySellItem(OfflinePlayer player, Chest chest, ItemStack t

if (successDeposit)
NotifierTask.addTransaction(player.getUniqueId(), toSell, toSell.getAmount(), finalPrice);
if(!player.isOnline())
offlineDeposit.put(player.getUniqueId(),offlineDeposit.getOrDefault(player.getUniqueId(),0.0)+finalPrice);

return successDeposit;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ hooks:
# The maximum pickup delay items can have for the suction chests to pick them up.
maximum-pickup-delay: 32767

# How long the received money while being offline message should be delayed (in ticks)
offline-money-message-delay: 10

# The plugin brings tons of new custom and unique chests to your server. All the chests are configurable, and
# you can create and mix between them. You can create chests that stores infinite amount of items, chests that
# are connected to player vaults or factions, linked chests and many more!
Expand Down