Files
com
config.yml
Code
7 3,036
com/minedhype/ishop/Shop.java
package com.minedhype.ishop;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.minedhype.ishop.inventories.InvAdminShop;
import com.minedhype.ishop.inventories.InvStock;
import java.sql.Blob;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import javax.sql.rowset.serial.SerialBlob;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.chat.ClickEvent.Action;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.Particle;
import org.bukkit.World;
import org.bukkit.block.ShulkerBox;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BlockStateMeta;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.plugin.Plugin;
public class Shop {
public static boolean deletePlayerShop;
public static boolean particleEffects;
public static boolean saveEmptyShops;
public static boolean shopOutStock;
public static boolean shopEnabled;
public static boolean showOwnedShops;
public static boolean shopNotifications;
public static boolean stockMessages;
public static boolean stockMessagesSaveAll;
public static List<String> exemptExpiringList;
public static Particle shopParticles;
public static int maxDays;
public static final ConcurrentHashMap<Integer, UUID> shopList;
public static final ConcurrentHashMap<UUID, ArrayList<String>> shopMessages;
private static boolean exemptListInactive;
private static final List<Shop> shops;
private static final Plugin plugin;
private static final long millisecondsPerDay = 86400000L;
private final ItemStack airItem;
private final Map<Player, Long> cdTime;
private final UUID owner;
private final Location location;
private final RowStore[] rows;
private final boolean admin;
private int idTienda;
private Shop(int idTienda, UUID owner, Location loc, boolean admin) {
this.airItem = new ItemStack(Material.AIR, 0);
this.cdTime = new HashMap();
this.idTienda = idTienda;
this.owner = owner;
this.location = loc;
this.rows = new RowStore[5];
this.admin = admin;
if (idTienda == -1) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
PreparedStatement stmt = null;
try {
stmt = iShop.getConnection().prepareStatement("INSERT INTO zooMercaTiendas (location, owner, admin) VALUES (?,?,?);", 1);
int var10000 = loc.getBlockX();
String locationRaw = var10000 + ";" + loc.getBlockY() + ";" + loc.getBlockZ() + ";" + loc.getWorld().getName();
stmt.setString(1, locationRaw);
stmt.setString(2, owner.toString());
stmt.setBoolean(3, admin);
stmt.executeUpdate();
ResultSet res = stmt.getGeneratedKeys();
if (res.next()) {
this.idTienda = res.getInt(1);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (stmt != null) {
stmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
public static Optional<Shop> getShopByLocation(Location location) {
return shops.parallelStream().filter((shop) -> shop.location.equals(location)).findFirst();
}
public static Optional<Shop> getShopById(int id) {
return shops.parallelStream().filter((shop) -> shop.idTienda == id).findFirst();
}
public static boolean checkShopDistanceFromStockBlock(Location stockLocation, UUID shopOwner) {
return shops.parallelStream().filter((s) -> !s.admin && s.isOwner(shopOwner)).anyMatch((s) -> s.getLocation().getWorld().equals(stockLocation.getWorld()) && s.location.distanceSquared(stockLocation) <= (double)(EventShop.stockRangeLimit * EventShop.stockRangeLimit));
}
public static int getNumShops(UUID owner) {
return (int)shops.parallelStream().filter((t) -> !t.admin && t.owner.equals(owner)).count();
}
public static boolean strictStockShopCheck(ItemStack item, UUID uuid) {
AtomicBoolean restricted = new AtomicBoolean(true);
shops.parallelStream().filter((s) -> !s.admin && s.isOwner(uuid)).forEach((s) -> {
if (restricted.get()) {
for(int i = 0; i < 5; ++i) {
if (restricted.get()) {
Optional<RowStore> row = s.getRow(i);
if (row.isPresent() && (((RowStore)row.get()).getItemOut().isSimilar(item) || ((RowStore)row.get()).getItemOut2().isSimilar(item))) {
restricted.set(false);
}
}
}
}
});
return restricted.get();
}
public static void getPlayersShopList() {
if (iShop.config.getBoolean("adminShopPublic")) {
shops.parallelStream().forEach((s) -> shopList.putIfAbsent(s.idTienda, s.owner));
} else {
shops.parallelStream().filter((s) -> !s.admin).forEach((s) -> shopList.putIfAbsent(s.idTienda, s.owner));
}
}
public static void findItem(Player player, ItemStack item, String itemName) {
player.sendMessage(Messages.SHOP_FIND.toString().replaceAll("%item", itemName.toLowerCase()));
AtomicBoolean foundItem = new AtomicBoolean(false);
shops.parallelStream().forEach((s) -> {
AtomicBoolean foundItemInShop = new AtomicBoolean(false);
for(int i = 0; i < 5; ++i) {
Optional<RowStore> row = s.getRow(i);
if (row.isPresent() && !foundItemInShop.get()) {
boolean itemMatch = ((RowStore)row.get()).getItemOut().isSimilar(item);
boolean itemMatch2 = ((RowStore)row.get()).getItemOut2().isSimilar(item);
if (itemMatch && itemMatch2 && Utils.hasDoubleItemStock(s, ((RowStore)row.get()).getItemOut(), ((RowStore)row.get()).getItemOut2()) || itemMatch && !itemMatch2 && Utils.hasStock(s, ((RowStore)row.get()).getItemOut()) || !itemMatch && itemMatch2 && Utils.hasStock(s, ((RowStore)row.get()).getItemOut2())) {
foundItem.set(true);
foundItemInShop.set(true);
player.sendMessage(Messages.SHOP_LOCATION.toString().replaceAll("%id", String.valueOf(s.idTienda)).replaceAll("%x", String.valueOf(s.location.getBlockX())).replaceAll("%y", String.valueOf(s.location.getBlockY())).replaceAll("%z", String.valueOf(s.location.getBlockZ())).replaceAll("%world", s.location.getWorld().getName()));
break;
}
if (((RowStore)row.get()).getItemOut().getType().toString().contains("SHULKER_BOX") && ((RowStore)row.get()).getItemOut().getItemMeta() instanceof BlockStateMeta && Utils.hasStock(s, ((RowStore)row.get()).getItemOut())) {
BlockStateMeta itemMeta = (BlockStateMeta)((RowStore)row.get()).getItemOut().getItemMeta();
ShulkerBox shulkerBox = (ShulkerBox)itemMeta.getBlockState();
if (shulkerBox.getInventory().contains(item.getType())) {
for(ItemStack itemSearch : shulkerBox.getInventory().getContents()) {
if (itemSearch.isSimilar(item)) {
foundItem.set(true);
foundItemInShop.set(true);
player.sendMessage(Messages.SHOP_LOCATION.toString().replaceAll("%id", String.valueOf(s.idTienda)).replaceAll("%x", String.valueOf(s.location.getBlockX())).replaceAll("%y", String.valueOf(s.location.getBlockY())).replaceAll("%z", String.valueOf(s.location.getBlockZ())).replaceAll("%world", s.location.getWorld().getName()));
break;
}
}
}
}
if (((RowStore)row.get()).getItemOut2().getType().toString().contains("SHULKER_BOX") && ((RowStore)row.get()).getItemOut2().getItemMeta() instanceof BlockStateMeta && Utils.hasStock(s, ((RowStore)row.get()).getItemOut2())) {
BlockStateMeta itemMeta = (BlockStateMeta)((RowStore)row.get()).getItemOut2().getItemMeta();
ShulkerBox shulkerBox = (ShulkerBox)itemMeta.getBlockState();
if (shulkerBox.getInventory().contains(item.getType())) {
for(ItemStack itemSearch : shulkerBox.getInventory().getContents()) {
if (itemSearch.isSimilar(item)) {
foundItem.set(true);
foundItemInShop.set(true);
player.sendMessage(Messages.SHOP_LOCATION.toString().replaceAll("%id", String.valueOf(s.idTienda)).replaceAll("%x", String.valueOf(s.location.getBlockX())).replaceAll("%y", String.valueOf(s.location.getBlockY())).replaceAll("%z", String.valueOf(s.location.getBlockZ())).replaceAll("%world", s.location.getWorld().getName()));
break;
}
}