mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2024-09-27 14:12:58 +02:00
Clean up code
This commit is contained in:
parent
3cfdd0185a
commit
0f23767336
@ -18,11 +18,6 @@
|
||||
<artifactId>SaneEconomyCore</artifactId>
|
||||
<version>0.10.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.appledash</groupId>
|
||||
<artifactId>SaneEconomyCore</artifactId>
|
||||
<version>0.10.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -11,7 +11,7 @@ import org.bukkit.event.block.BlockBreakEvent;
|
||||
* Blackjack is best pony.
|
||||
*/
|
||||
public class BreakListener implements Listener {
|
||||
private SaneEconomySignShop plugin;
|
||||
private final SaneEconomySignShop plugin;
|
||||
|
||||
public BreakListener(SaneEconomySignShop plugin) {
|
||||
this.plugin = plugin;
|
||||
|
@ -6,6 +6,7 @@ import org.appledash.saneeconomy.economy.transaction.TransactionResult;
|
||||
import org.appledash.saneeconomy.utils.MessageUtils;
|
||||
import org.appledash.saneeconomysignshop.SaneEconomySignShop;
|
||||
import org.appledash.saneeconomysignshop.signshop.ShopTransaction;
|
||||
import org.appledash.saneeconomysignshop.signshop.ShopTransaction.TransactionDirection;
|
||||
import org.appledash.saneeconomysignshop.signshop.SignShop;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -84,7 +85,7 @@ public class InteractListener implements Listener {
|
||||
EconomyManager ecoMan = plugin.getSaneEconomy().getEconomyManager();
|
||||
int quantity = player.isSneaking() ? 1 : shop.getQuantity();
|
||||
|
||||
ShopTransaction shopTransaction = shop.makeTransaction(player, ShopTransaction.TransactionDirection.BUY, quantity);
|
||||
ShopTransaction shopTransaction = shop.makeTransaction(player, TransactionDirection.BUY, quantity);
|
||||
|
||||
/* No buy limits for now!
|
||||
if (!plugin.getLimitManager().shouldAllowTransaction(shopTransaction)) {
|
||||
@ -121,14 +122,14 @@ public class InteractListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
ShopTransaction shopTransaction = shop.makeTransaction(player, ShopTransaction.TransactionDirection.SELL, quantity);
|
||||
ShopTransaction shopTransaction = shop.makeTransaction(player, TransactionDirection.SELL, quantity);
|
||||
|
||||
if (!plugin.getLimitManager().shouldAllowTransaction(shopTransaction)) {
|
||||
MessageUtils.sendMessage(player, "You have reached your selling limit for the time being. Try back in an hour or so.");
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getLimitManager().setRemainingLimit(player, ShopTransaction.TransactionDirection.SELL, shop.getItem(), plugin.getLimitManager().getRemainingLimit(player, ShopTransaction.TransactionDirection.SELL, shop.getItem()) - quantity);
|
||||
plugin.getLimitManager().setRemainingLimit(player, TransactionDirection.SELL, shop.getItem(), plugin.getLimitManager().getRemainingLimit(player, TransactionDirection.SELL, shop.getItem()) - quantity);
|
||||
|
||||
|
||||
ItemStack stack = shop.getItemStack().clone();
|
||||
|
@ -6,6 +6,7 @@ import org.appledash.saneeconomy.utils.MessageUtils;
|
||||
import org.appledash.saneeconomysignshop.SaneEconomySignShop;
|
||||
import org.appledash.saneeconomysignshop.signshop.SignShop;
|
||||
import org.appledash.saneeconomysignshop.util.ItemDatabase;
|
||||
import org.appledash.saneeconomysignshop.util.ItemDatabase.InvalidItemException;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -21,7 +22,7 @@ import java.util.regex.Pattern;
|
||||
* Blackjack is still best pony.
|
||||
*/
|
||||
public class SignChangeListener implements Listener {
|
||||
private SaneEconomySignShop plugin;
|
||||
private final SaneEconomySignShop plugin;
|
||||
|
||||
public SignChangeListener(SaneEconomySignShop plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -91,7 +92,7 @@ public class SignChangeListener implements Listener {
|
||||
ItemStack itemStack;
|
||||
try {
|
||||
itemStack = ItemDatabase.parseGive(itemName);
|
||||
} catch (ItemDatabase.InvalidItemException e) {
|
||||
} catch (InvalidItemException e) {
|
||||
return new ParsedSignShop("Invalid item name or ID specified.");
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ public class SignShop implements Serializable {
|
||||
private final double sellPrice;
|
||||
|
||||
public SignShop(UUID ownerUuid, Location location, ItemStack item, int quantity, double buyPrice, double sellPrice) {
|
||||
if (ownerUuid == null || location == null || item == null) {
|
||||
if ((ownerUuid == null) || (location == null) || (item == null)) {
|
||||
throw new IllegalArgumentException("ownerUuid, location, and item must not be null.");
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import java.util.Optional;
|
||||
* Blackjack is still best pony.
|
||||
*/
|
||||
public class SignShopManager {
|
||||
private SignShopStorage storage;
|
||||
private final SignShopStorage storage;
|
||||
|
||||
public SignShopManager(SignShopStorage storage) {
|
||||
this.storage = storage;
|
||||
|
@ -20,7 +20,7 @@ import java.util.Map;
|
||||
public class SignShopStorageJSON implements SignShopStorage {
|
||||
private final Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create();
|
||||
private final File storageFile;
|
||||
private Map<Location, SignShop> cachedSignShops = new HashMap<>();
|
||||
private final Map<Location, SignShop> cachedSignShops = new HashMap<>();
|
||||
|
||||
public SignShopStorageJSON(File storageFile) {
|
||||
this.storageFile = storageFile;
|
||||
|
@ -19,15 +19,16 @@ public class DefaultHashMap<K, V> extends HashMap<K, V> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(Object k) {
|
||||
V v = super.get(k);
|
||||
@SuppressWarnings("unchecked")
|
||||
public V get(Object key) {
|
||||
V value = super.get(key);
|
||||
|
||||
if (v == null) {
|
||||
v = defaultSupplier.get((K)k);
|
||||
this.put((K) k, v);
|
||||
if (value == null) {
|
||||
value = defaultSupplier.get((K)key);
|
||||
this.put((K) key, value);
|
||||
}
|
||||
|
||||
return v;
|
||||
return value;
|
||||
}
|
||||
|
||||
public interface KeyBasedSupplier<K, V> {
|
||||
|
@ -109,19 +109,20 @@ public class ItemDatabase {
|
||||
}
|
||||
|
||||
public static class Pair<K, V> {
|
||||
private K k;
|
||||
private V v;
|
||||
public Pair(K k, V v) {
|
||||
this.k = k;
|
||||
this.v = v;
|
||||
private final K left;
|
||||
private final V right;
|
||||
|
||||
public Pair(K left, V right) {
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
public K getLeft() {
|
||||
return k;
|
||||
return left;
|
||||
}
|
||||
|
||||
public V getRight() {
|
||||
return v;
|
||||
return right;
|
||||
}
|
||||
|
||||
public static <K, V> Pair of(K k, V v) {
|
||||
|
@ -2,6 +2,7 @@ package org.appledash.saneeconomysignshop.util;
|
||||
|
||||
import org.appledash.saneeconomysignshop.signshop.ShopTransaction;
|
||||
import org.appledash.saneeconomysignshop.signshop.ShopTransaction.TransactionDirection;
|
||||
import org.appledash.saneeconomysignshop.util.ItemDatabase.InvalidItemException;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -66,9 +67,8 @@ public class LimitManager {
|
||||
sellPlayerLimits.forEach((playerUuid, itemToLimit) -> {
|
||||
Map<ItemInfo, Integer> newLimits = new HashMap<>();
|
||||
|
||||
itemToLimit.forEach((itemInfo, currentLimit) -> {
|
||||
newLimits.put(itemInfo, currentLimit + (sellItemLimits.get(itemInfo).getHourlyGain()));
|
||||
});
|
||||
itemToLimit.forEach((itemInfo, currentLimit) ->
|
||||
newLimits.put(itemInfo, currentLimit + (sellItemLimits.get(itemInfo).getHourlyGain())));
|
||||
|
||||
itemToLimit.putAll(newLimits);
|
||||
});
|
||||
@ -83,7 +83,7 @@ public class LimitManager {
|
||||
|
||||
try {
|
||||
stack = ItemDatabase.parseGive(itemName);
|
||||
} catch (ItemDatabase.InvalidItemException e) {
|
||||
} catch (InvalidItemException e) {
|
||||
LOGGER.warning(String.format("You tried to load the item '%s' in limits.yml, but I have no idea what that is.", map.get("item")));
|
||||
continue;
|
||||
}
|
||||
|
@ -11,9 +11,12 @@ import java.util.UUID;
|
||||
* Blackjack is best pony.
|
||||
*/
|
||||
public class SerializableLocation implements Serializable {
|
||||
private double x, y, z;
|
||||
private float yaw, pitch;
|
||||
private UUID worldUuid;
|
||||
private final double x;
|
||||
private final double y;
|
||||
private final double z;
|
||||
private final float yaw;
|
||||
private final float pitch;
|
||||
private final UUID worldUuid;
|
||||
|
||||
public SerializableLocation(Location location) {
|
||||
this.x = location.getX();
|
||||
|
Loading…
Reference in New Issue
Block a user