Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:AppleDash/SaneEconomy
Browse files Browse the repository at this point in the history
  • Loading branch information
AppleDash committed Jan 17, 2017
2 parents 3695d13 + b81d64c commit 96ee933
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ private boolean checkTableExists(String tableName) {

@Override
public synchronized void reloadDatabase() {
waitUntilFlushed();
createTables();
try (Connection conn = dbConn.openConnection()) {
PreparedStatement ps = conn.prepareStatement(String.format("SELECT * FROM `%s`", dbConn.getTable("saneeconomy_balances")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.appledash.saneeconomy.economy.transaction.TransactionReason;
import org.appledash.saneeconomy.updates.GithubVersionChecker;
import org.appledash.saneeconomy.utils.MessageUtils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -48,6 +49,8 @@ public void onPlayerJoin(PlayerJoinEvent evt) {

@EventHandler
public void onPlayerLogin(AsyncPlayerPreLoginEvent evt) {
plugin.getEconomyManager().getBackend().reloadDatabase(); // TODO: If servers start to lag when lots of people join, this is why.
Bukkit.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, () -> {
plugin.getEconomyManager().getBackend().reloadDatabase(); // TODO: If servers start to lag when lots of people join, this is why.
}, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public void onEnable() {
saveDefaultConfig();

signShopManager.loadSignShops();

getServer().getScheduler().scheduleSyncRepeatingTask(this, limitManager::incrementLimitsHourly, 0, 20 * 60 * 60);

getServer().getPluginManager().registerEvents(new SignChangeListener(this), this);
getServer().getPluginManager().registerEvents(new InteractListener(this), this);
getServer().getPluginManager().registerEvents(new BreakListener(this), this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void onSignChange(SignChangeEvent evt) {
MessageUtils.sendMessage(evt.getPlayer(), "Item: {1} x {2}", signShop.getQuantity(), signShop.getItemStack());

if (signShop.canBuy()) { // The player be buying from the shop, not the other way around.
MessageUtils.sendMessage(evt.getPlayer(), "Will sell to players for {!}.",
MessageUtils.sendMessage(evt.getPlayer(), "Will sell to players for {1}.",
plugin.getSaneEconomy().getEconomyManager().getCurrency().formatAmount(signShop.getBuyPrice())
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,29 @@
* Blackjack is still best pony.
*/
public class DefaultHashMap<K, V> extends HashMap<K, V> {
private final Supplier<V> defaultSupplier;
private final KeyBasedSupplier<K, V> defaultSupplier;

public DefaultHashMap(Supplier<V> defaultSupplier) {
if (defaultSupplier == null) {
throw new NullPointerException("defaultSupplier is null");
}
this((k) -> defaultSupplier.get());
}

this.defaultSupplier = defaultSupplier;
public DefaultHashMap(KeyBasedSupplier<K, V> supplier) {
this.defaultSupplier = supplier;
}

@Override
public V get(Object k) {
V v = super.get(k);

if (v == null) {
v = defaultSupplier.get();
v = defaultSupplier.get((K)k);
this.put((K) k, v);
}

return v;
}

public interface KeyBasedSupplier<K, V> {
V get(K k);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import org.appledash.saneeconomysignshop.signshop.ShopTransaction;
import org.appledash.saneeconomysignshop.signshop.ShopTransaction.TransactionDirection;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;

/**
Expand Down Expand Up @@ -58,4 +61,22 @@ public void incrementLimitsHourly() {
});
}

public void loadLimits(ConfigurationSection config) {
for (Map<?, ?> map : config.getMapList("")) {
String itemName = String.valueOf(map.get("item"));
int sellLimit = Integer.valueOf(String.valueOf(map.get("buyLimit")));
int hourlyGain = Integer.valueOf(String.valueOf(map.get("gain")));

Optional<ItemDatabase.Pair<Integer, Short>> pair = ItemDatabase.getIDAndDamageForName(itemName);

if (!pair.isPresent()) {
continue;
}

ItemInfo itemInfo = new ItemInfo(new ItemStack(pair.get().getLeft(), pair.get().getRight()));

itemLimits.get(TransactionDirection.SELL).put(itemInfo, new ItemLimits(sellLimit, hourlyGain));
}
}

}

0 comments on commit 96ee933

Please sign in to comment.