mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2024-11-10 12:31:07 +01:00
Sign shop: Random stuff!
This commit is contained in:
parent
2ccd25cce4
commit
8627f07163
@ -40,6 +40,9 @@ public class SaneEconomySignShop extends JavaPlugin {
|
|||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
|
|
||||||
signShopManager.loadSignShops();
|
signShopManager.loadSignShops();
|
||||||
|
|
||||||
|
getServer().getScheduler().scheduleSyncRepeatingTask(this, limitManager::incrementLimitsHourly, 0, 20 * 60 * 60);
|
||||||
|
|
||||||
getServer().getPluginManager().registerEvents(new SignChangeListener(this), this);
|
getServer().getPluginManager().registerEvents(new SignChangeListener(this), this);
|
||||||
getServer().getPluginManager().registerEvents(new InteractListener(this), this);
|
getServer().getPluginManager().registerEvents(new InteractListener(this), this);
|
||||||
getServer().getPluginManager().registerEvents(new BreakListener(this), this);
|
getServer().getPluginManager().registerEvents(new BreakListener(this), this);
|
||||||
|
@ -53,7 +53,7 @@ public class SignChangeListener implements Listener {
|
|||||||
MessageUtils.sendMessage(evt.getPlayer(), "Item: {1} x {2}", signShop.getQuantity(), signShop.getItemStack());
|
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.
|
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())
|
plugin.getSaneEconomy().getEconomyManager().getCurrency().formatAmount(signShop.getBuyPrice())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,14 @@ import java.util.function.Supplier;
|
|||||||
* Blackjack is still best pony.
|
* Blackjack is still best pony.
|
||||||
*/
|
*/
|
||||||
public class DefaultHashMap<K, V> extends HashMap<K, V> {
|
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) {
|
public DefaultHashMap(Supplier<V> defaultSupplier) {
|
||||||
if (defaultSupplier == null) {
|
this((k) -> defaultSupplier.get());
|
||||||
throw new NullPointerException("defaultSupplier is null");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.defaultSupplier = defaultSupplier;
|
public DefaultHashMap(KeyBasedSupplier<K, V> supplier) {
|
||||||
|
this.defaultSupplier = supplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -23,10 +23,14 @@ public class DefaultHashMap<K, V> extends HashMap<K, V> {
|
|||||||
V v = super.get(k);
|
V v = super.get(k);
|
||||||
|
|
||||||
if (v == null) {
|
if (v == null) {
|
||||||
v = defaultSupplier.get();
|
v = defaultSupplier.get((K)k);
|
||||||
this.put((K) k, v);
|
this.put((K) k, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface KeyBasedSupplier<K, V> {
|
||||||
|
V get(K k);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,13 @@ package org.appledash.saneeconomysignshop.util;
|
|||||||
|
|
||||||
import org.appledash.saneeconomysignshop.signshop.ShopTransaction;
|
import org.appledash.saneeconomysignshop.signshop.ShopTransaction;
|
||||||
import org.appledash.saneeconomysignshop.signshop.ShopTransaction.TransactionDirection;
|
import org.appledash.saneeconomysignshop.signshop.ShopTransaction.TransactionDirection;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,4 +61,22 @@ public class LimitManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user