Initial commit

This commit is contained in:
Scifi9902
2026-10-12 13:57:05 -03:00
commit 4bde3b176a
2576 changed files with 212659 additions and 0 deletions
+77
View File
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ProjectCranked</artifactId>
<groupId>net.crankedpvp</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>Auctionhouse</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.49</version>
</dependency>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>Utils</artifactId>
</dependency>
<dependency>
<artifactId>Core</artifactId>
<groupId>net.crankedpvp</groupId>
</dependency>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>StorageUtilsShaded</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/../StorageUtils/target/StorageUtils-1.0-shaded.jar</systemPath>
</dependency>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>Enchants</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>Trade</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals><goal>shade</goal></goals>
<configuration>
<artifactSet>
<includes>
<include>mysql:mysql-connector-java</include>
</includes>
</artifactSet>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,160 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* net.milkbowl.vault.economy.Economy
* org.bukkit.Bukkit
* org.bukkit.command.CommandExecutor
* org.bukkit.entity.Player
* org.bukkit.event.Listener
* org.bukkit.plugin.Plugin
* org.bukkit.plugin.RegisteredServiceProvider
* org.bukkit.plugin.java.JavaPlugin
* org.bukkit.scheduler.BukkitTask
*/
package me.recolance.auction;
import lombok.SneakyThrows;
import me.recolance.auction.command.CommandHandler;
import me.recolance.auction.controller.ConfirmMenu;
import me.recolance.auction.controller.Controller;
import me.recolance.auction.controller.Events;
import me.recolance.auction.data.DataHandler;
import me.recolance.auction.data.Database;
import me.recolance.auction.data.SafetyToggle;
import me.recolance.auction.menu.BidListener;
import me.recolance.auction.menu.BidManager;
import me.recolance.auction.menu.MenuController;
import me.recolance.auction.tasks.ItemExpireWarnTask;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import java.io.IOException;
public class Auction
extends JavaPlugin {
public static Auction plugin;
public static Economy economy;
public static boolean stoppingServer;
static {
economy = null;
stoppingServer = false;
}
private SafetyToggle toggles;
private BidManager bidManager;
public static Auction getPlugin() {
return plugin;
}
@SneakyThrows
public void onEnable() {
plugin = this;
stoppingServer = false;
this.setupEconomy();
this.saveDefaultConfig();
this.toggles = new SafetyToggle();
if (!Database.openDatabaseConnection()) {
this.getServer().getPluginManager().disablePlugin(this);
return;
}
DataHandler.loadListings();
this.registration();
Controller.expireListings();
Controller.expireOfflineUnclaimedListings();
this.bidManager = new BidManager();
try {
this.bidManager.loadBids(this);
} catch (IOException e) {
e.printStackTrace();
}
this.bidManager.startBidTimer();
}
public void onDisable() {
stoppingServer = true;
if (this.bidManager != null) this.bidManager.setProccessAuctionHouse(false);
for (Player p : Bukkit.getOnlinePlayers()) {
String invName = p.getInventory().getTitle();
if (!invName.equals("Cancelled / Expired Listings") && !invName.equals("Auction House") && !invName.equals("Your Current Listings"))
continue;
p.closeInventory();
}
int attempts = 0;
while (this.getPendingAsyncTasks() > 0 && attempts++ <= 20) {
Bukkit.getLogger().info("(Auction) There are still " + this.getPendingAsyncTasks() + " pending SQL tasks, sleeping 500ms...");
try {
Thread.sleep(500L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (this.toggles != null) this.toggles.saveFile();
if (this.bidManager != null) {
try {
this.bidManager.saveBids(false);
} catch (Exception e) {
e.printStackTrace();
}
}
plugin = null;
Database.closeConnection();
}
private int getPendingAsyncTasks() {
int c = 0;
for (BukkitTask bt : Bukkit.getScheduler().getPendingTasks()) {
if (bt.isSync() || !bt.getOwner().equals((Object) plugin)) continue;
++c;
}
return c;
}
public void registration() {
this.saveDefaultConfig();
this.updateConfig();
this.getServer().getPluginManager().registerEvents((Listener) new BidListener(), (Plugin) this);
this.getServer().getPluginManager().registerEvents((Listener) new MenuController(), (Plugin) this);
this.getServer().getPluginManager().registerEvents((Listener) new Events(), (Plugin) this);
this.getServer().getPluginManager().registerEvents((Listener) new ConfirmMenu(), (Plugin) this);
this.getCommand("ah").setExecutor((CommandExecutor) new CommandHandler());
new ItemExpireWarnTask().runTaskTimer((Plugin) this, 4800L, 4800L);
}
private void updateConfig() {
if (!this.getConfig().contains("auction.preventCreativeSale")) {
this.getConfig().set("auction.preventCreativeSale", (Object) false);
}
this.saveConfig();
}
private boolean setupEconomy() {
RegisteredServiceProvider economyProvider = this.getServer().getServicesManager().getRegistration(Economy.class);
if (economyProvider != null) {
economy = (Economy) economyProvider.getProvider();
}
return economy != null;
}
public boolean hasToggle(Player pl) {
return this.toggles.isToggled(pl);
}
public SafetyToggle getToggles() {
return this.toggles;
}
public BidManager getBidManager() {
return this.bidManager;
}
}
@@ -0,0 +1,202 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* com.cosmicpvp.CosmicSpaceChests.CosmicSpaceChestsAPI
* com.cosmicpvp.CosmicSpaceChests.libs.ItemRarity
* com.cosmicpvp.cosmicutils.me.astropvp.cratekeys.net.astropvp.armorsets.utils.CC
* com.cosmicpvp.cosmicutils.me.astropvp.cratekeys.net.astropvp.armorsets.utils.NumberUtils
* com.rit.sucy.CustomEnchantment
* org.arkhamnetwork.Arkkit.patches.ExpBottles
* org.arkhamnetwork.enchantments.EnchantmentBook
* org.arkhamnetwork.enchantments.util.TieredEnchantments
* org.bukkit.Bukkit
* org.bukkit.ChatColor
* org.bukkit.me.astropvp.cratekeys.inventory.ItemStack
*/
package me.recolance.auction.auction;
import me.recolance.auction.data.AuctionItem;
import me.recolance.auction.util.Item;
import net.crankedpvp.crankedcore.utils.ExpBottleAPI;
import net.crankedpvp.crankedenchants.CrankedEnchantsAPI;
import net.crankedpvp.crankedenchants.struct.enchantstruct.Enchantment;
import net.crankedpvp.crankedenchants.struct.items.BookBuilder;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.NumberUtils;
import net.crankedpvp.crankedutils.utils.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.inventory.ItemStack;
import java.text.DecimalFormat;
import java.util.UUID;
public class Listing
implements Comparable<Listing>,
AuctionItem {
private UUID id;
private long endTime;
private UUID listedBy;
private String listedByName;
private ItemStack item;
private double price;
private DecimalFormat formatter = new DecimalFormat("#,###");
private boolean valid = true;
private boolean checkedBook;
private Integer bookRarity;
private ChatColor bookTierColor;
private String bookTierName;
private Integer expInBottle;
private Double expPerDollar;
private double pricePerItem = 0.0;
public Listing(UUID id, long endTime, UUID listedBy, ItemStack item, double price) {
this.id = id;
this.endTime = endTime;
this.listedBy = listedBy;
this.item = item;
this.price = price;
this.listedByName = Bukkit.getOfflinePlayer((UUID) this.listedBy).getName();
}
public double getPricePerItem() {
if (this.pricePerItem > 0.0) {
return this.pricePerItem;
}
if (this.item.getAmount() > 1) {
this.pricePerItem = (double) this.getPrice() / (double) this.item.getAmount();
return this.pricePerItem;
}
this.pricePerItem = this.getPrice();
return this.pricePerItem;
}
public int getExpInBottle() {
if (this.expInBottle == null) {
this.expInBottle = ExpBottleAPI.isXpBottle((ItemStack) this.item) ? Integer.valueOf(ExpBottleAPI.getXpAmount((ItemStack) this.item)) : Integer.valueOf(0);
}
return this.expInBottle;
}
public double getExpPerDollar() {
if (this.expPerDollar == null) {
int exp = this.getExpInBottle();
this.expPerDollar = exp > 0 ? Double.valueOf((double) this.price / (double) exp) : Double.valueOf(0.0);
}
return this.expPerDollar;
}
public Integer getBookRarity() {
if (!this.checkedBook) {
this.checkedBook = true;
if (!CrankedEnchantsAPI.isEnchantBook((ItemStack) this.item)) {
return null;
}
Enchantment enchant = new BookBuilder(this.item).getBookEnchantment();
if (enchant == null) {
return null;
}
this.bookTierColor = ChatColor.valueOf(enchant.getTier().getColor());
this.bookRarity = enchant.getEnchantTierWeight();
this.bookTierName = enchant.getTier().getFormatedName();
}
return this.bookRarity;
}
public ItemStack getMenuDisplayItem() {
String perData = this.getExpInBottle() > 0 ? CC.Gray + " ($" + NumberUtils.formatMoney((double) this.getExpPerDollar()) + " / xp)" : "";
double perItem = this.getPricePerItem();
if (perItem != (double) this.getPrice() && perItem > 0.0) {
perData = " ($" + NumberUtils.formatMoney((double) perItem) + " / item)";
}
return new Item(new ItemStack(this.getItem())).addLore("", "&7-------------------------", "&e&lClick item to buy!", "", "&6Price: &e$" + this.getPrettyPrice() + perData, "&6Seller: &e" + this.getNameOfWhoListed(), "&7-------------------------").get();
}
public boolean isExpired() {
return this.endTime <= System.currentTimeMillis();
}
public boolean isValid() {
return this.valid;
}
public void setValid(boolean valid) {
this.valid = valid;
}
public UUID getId() {
return this.id;
}
public void setId(UUID id) {
this.id = id;
}
public long getEndTime() {
return this.endTime;
}
public void setEndTime(long endTime) {
this.endTime = endTime;
}
public UUID getWhoListed() {
return this.listedBy;
}
public void setWhoListed(UUID listedBy) {
this.listedBy = listedBy;
}
public String getNameOfWhoListed() {
return this.listedByName;
}
public void setWhoNameOfWhoListed(String name) {
this.listedByName = name;
}
public ItemStack getItem() {
return this.item;
}
public void setItem(ItemStack item) {
this.item = item;
}
public double getPrice() {
return this.price;
}
public void setPrice(int price) {
this.price = price;
}
public String getPrettyPrice() {
return this.formatter.format(this.price);
}
@Override
public int compareTo(Listing o) {
return Long.compare(o.getEndTime(), this.getEndTime());
}
@Override
public ItemStack getDisplay() {
return this.getMenuDisplayItem();
}
public ChatColor getBookTierColor() {
return this.bookTierColor;
}
public String getBookTierName() {
return this.bookTierName;
}
}
@@ -0,0 +1,62 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* org.bukkit.me.astropvp.cratekeys.inventory.ItemStack
*/
package me.recolance.auction.auction;
import org.bukkit.inventory.ItemStack;
import java.util.UUID;
public class UnclaimedListing {
private UUID id;
private UUID listedBy;
private ItemStack item;
private long expireTime;
public UnclaimedListing(UUID id, UUID listedBy, ItemStack item, long expireTime) {
this.id = id;
this.listedBy = listedBy;
this.item = item;
this.expireTime = expireTime;
}
public boolean isExpired() {
return this.expireTime <= System.currentTimeMillis();
}
public UUID getId() {
return this.id;
}
public void setId(UUID id) {
this.id = id;
}
public UUID getListedBy() {
return this.listedBy;
}
public void setListedBy(UUID listedBy) {
this.listedBy = listedBy;
}
public ItemStack getItem() {
return this.item;
}
public void setItem(ItemStack item) {
this.item = item;
}
public long getExpireTime() {
return this.expireTime;
}
public void setExpireTime(long expireTime) {
this.expireTime = expireTime;
}
}
@@ -0,0 +1,23 @@
/*
* Decompiled with CFR 0.150.
*/
package me.recolance.auction.command;
public enum Command {
AUCTION("&6Auction Menu", "&e/auction", "&7Opens the auction house.", "", "&9Aliases:", "&e- /ah", "&e- /auc", "&e- /auctionhouse"),
SELL("&6Sell An Item", "&e/ah sell <price>", "&7List the item you are holding on the auction house.", "", ""),
EXPIRED("&6Open Your Expired Items", "&e/ah expired", "&7View and manage your cancelled and expired items.", "", "&9Aliases:", "&e- /ah ex"),
SELLING("&6Open Your Listed Items", "&e/ah listed", "&7View and manage the items you are selling.", "", "&9Aliases:", "&e- /ah selling"),
HELP("&6Auction Help", "&e/ah help", "&7View this help menu.", "", "&9Aliases:", "&e- /ah commands");
private String[] desc;
private Command(String... desc) {
this.desc = desc;
}
public String[] getDescription() {
return this.desc;
}
}
@@ -0,0 +1,475 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* com.cosmicpvp.cosmicutils.nbt.NBTTagCompoundBuilder
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.CC
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.NBTWrapper
* com.google.common.collect.Lists
* me.vaqxine.NetworkManager.NetworkManager
* net.milkbowl.vault.economy.Economy
* org.arkhamnetwork.Arkkit.Arkkit
* org.arkhamnetwork.Arkkit.net.astropvp.armorsets.commands.CommandArkReboot
* org.arkhamnetwork.Arkkit.patches.AntiCrash
* org.arkhamnetwork.Arkkit.patches.ItemID
* org.arkhamnetwork.Arkkit.plugins.ArkPlugins
* org.arkhamnetwork.Arkkit.net.astropvp.armorsets.utils.TimeUtils
* org.arkhamnetwork.CosmicMoneyNotes.ArkhamMoneyNotesAPI
* org.bukkit.Bukkit
* org.bukkit.ChatColor
* org.bukkit.GameMode
* org.bukkit.Material
* org.bukkit.command.Command
* org.bukkit.command.CommandExecutor
* org.bukkit.command.CommandSender
* org.bukkit.enchantments.Enchantment
* org.bukkit.entity.Player
* org.bukkit.inventory.ItemStack
*/
package me.recolance.auction.command;
import com.google.common.collect.Lists;
import de.tr7zw.nbtapi.NBTCompound;
import de.tr7zw.nbtapi.NBTItem;
import me.recolance.auction.Auction;
import me.recolance.auction.controller.Controller;
import me.recolance.auction.controller.Events;
import me.recolance.auction.data.AuctionBid;
import me.recolance.auction.data.SafetyToggle;
import me.recolance.auction.menu.BidManager;
import me.recolance.auction.menu.MenuRenderer;
import me.recolance.auction.menu.bidmenus.AuctionPackageMenu;
import me.recolance.auction.menu.bidmenus.BidCollectionBinMenu;
import me.recolance.auction.menu.bidmenus.BidMenu;
import me.recolance.auction.util.AuctionUtil;
import me.recolance.auction.util.Util;
import net.crankedpvp.crankedcore.CrankedCore;
import net.crankedpvp.crankedcore.utils.MoneyNotesAPI;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.TimeUtils;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
public class CommandHandler
implements CommandExecutor {
private static Economy economy = Auction.economy;
private static HashSet<Material> noCustomNamedMaterials;
private static HashSet<Short> invisibilityEffectIds;
public CommandHandler() {
noCustomNamedMaterials = new HashSet();
noCustomNamedMaterials.add(Material.CHEST);
noCustomNamedMaterials.add(Material.TRAPPED_CHEST);
noCustomNamedMaterials.add(Material.MONSTER_EGG);
noCustomNamedMaterials.add(Material.PAPER);
noCustomNamedMaterials.add(Material.MOB_SPAWNER);
noCustomNamedMaterials.add(Material.EXP_BOTTLE);
noCustomNamedMaterials.add(Material.BOOK);
noCustomNamedMaterials.add(Material.REDSTONE_TORCH_ON);
noCustomNamedMaterials.add(Material.REDSTONE_TORCH_OFF);
noCustomNamedMaterials.add(Material.EYE_OF_ENDER);
noCustomNamedMaterials.add(Material.EMERALD);
noCustomNamedMaterials.add(Material.EMPTY_MAP);
noCustomNamedMaterials.add(Material.PAPER);
noCustomNamedMaterials.add(Material.INK_SACK);
noCustomNamedMaterials.add(Material.ENCHANTED_BOOK);
noCustomNamedMaterials.add(Material.GLOWSTONE_DUST);
noCustomNamedMaterials.add(Material.SUGAR);
noCustomNamedMaterials.add(Material.SULPHUR);
noCustomNamedMaterials.add(Material.MAGMA_CREAM);
noCustomNamedMaterials.add(Material.BONE);
noCustomNamedMaterials.add(Material.getMaterial((int) 99));
noCustomNamedMaterials.add(Material.getMaterial((int) 100));
invisibilityEffectIds = new HashSet();
invisibilityEffectIds.add((short) 8206);
invisibilityEffectIds.add((short) 8238);
invisibilityEffectIds.add((short) 16398);
invisibilityEffectIds.add((short) 16430);
}
public static boolean canSellItem(ItemStack item) {
double dura;
if (item.getAmount() <= 0) {
return false;
}
Material type = item.getType();
if (type == Material.STAINED_GLASS_PANE) {
return false;
}
if (MoneyNotesAPI.isMoneyNote(item)) {
return false;
}
if (type == Material.POTION && invisibilityEffectIds.contains(item.getDurability())) {
return false;
}
if (noCustomNamedMaterials.contains((Object) type) && item.hasItemMeta() && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName() != null && !item.getItemMeta().getDisplayName().contains("\u00a7")) {
return true;
}
if (CommandHandler.isItemExpired(null, item)) {
return false;
}
if (noCustomNamedMaterials.contains((Object) type) && item.hasItemMeta() && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName() != null && !item.getItemMeta().getDisplayName().contains("\u00a7")) {
return false;
}
return type == Material.AIR;
}
public static boolean handleAuction(Player player) {
MenuRenderer.openAuction(player);
return true;
}
private static boolean isItemExpired(Player player, ItemStack item) {
Long expires;
NBTItem wrapper = new NBTItem(item);
NBTCompound builder = wrapper.getCompound("conaxData");
if (builder != null && builder.hasKey("expiration") && (expires = builder.getLong("expiration")) != null && expires > 0L && expires < System.currentTimeMillis()) {
if (player != null) {
player.sendMessage(CC.RedB + "(!) " + CC.Red + "You cannot sell expired items!");
player.sendMessage(CC.Gray + "This item expired " + CC.GrayU + formatDifference((long) ((System.currentTimeMillis() - expires) / 1000L)) + CC.GrayU + " ago!");
}
return true;
}
return false;
}
public static boolean handleAuctionSell(Player player, String price) {
double dura;
Long expires;
ItemStack item = player.getItemInHand();
if (item == null || item.getType() == Material.AIR) {
Util.message(player, "&c&l(!) &cEquip the item you want to sell in your hand.");
return true;
}
if (item.getType() == Material.STAINED_GLASS_PANE) {
Util.message(player, "&cYou cannot sell this item.");
return true;
}
if (!(item.getType() != Material.TRIPWIRE_HOOK || item.hasItemMeta() && item.getItemMeta().hasLore() && (((String) item.getItemMeta().getLore().get(1)).contains("by right-clicking the warchest") || ((String) item.getItemMeta().getLore().get(0)).contains(CC.Gray + "Consumed upon entering a")))) {
Util.message(player, "&cYou cannot sell this item.");
return true;
}
if (item.getType() == Material.CHEST && item.hasItemMeta() && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().contains("???")) {
Util.message(player, "&cYou cannot sell this item.");
return true;
}
if (MoneyNotesAPI.isMoneyNote((ItemStack) item)) {
Util.message(player, "&cYou cannot sell this item.");
return true;
}
if (item.getType() == Material.POTION && invisibilityEffectIds.contains(item.getDurability())) {
Util.message(player, "&cYou cannot sell this item.");
return true;
}
if (noCustomNamedMaterials.contains((Object) item.getType()) && item.hasItemMeta() && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName() != null && !item.getItemMeta().getDisplayName().contains("\u00a7")) {
Util.message(player, "&cYou cannot sell this item.");
return true;
}
if (CommandHandler.isItemExpired(player, item)) {
return true;
}
NBTItem wrapper = new NBTItem(item);
NBTCompound builder = wrapper.getCompound("conaxData");
if (builder != null && builder.hasKey("expiration") && (expires = builder.getLong("expiration")) != null && expires > 0L && expires < System.currentTimeMillis()) {
player.sendMessage(CC.RedB + "(!) " + CC.Red + "You cannot sell expired items!");
player.sendMessage(CC.Gray + "This item expired " + CC.GrayU + formatDifference((long) ((System.currentTimeMillis() - expires) / 1000L)) + CC.GrayU + " ago!");
return false;
}
if (item.getType() == Material.POTION && Bukkit.getPluginManager().isPluginEnabled("CosmicFactionUtils") && ((dura = (double) item.getDurability()) == 8198.0 || dura == 8230.0 || dura == 8262.0 || dura == 16390.0 || dura == 16422.0 || dura == 16454.0)) {
Util.message(player, "&cYou cannot sell this item.");
return true;
}
if (item.containsEnchantment(Enchantment.DIG_SPEED) && item.getEnchantmentLevel(Enchantment.DIG_SPEED) > 5) {
Util.message(player, "&cYou cannot sell this item.");
return true;
}
if (Auction.plugin.getConfig().getBoolean("auction.preventCreativeSale") && player.getGameMode() == GameMode.CREATIVE) {
Util.message(player, "&cYou cannot sell items while in creative.");
} else if (!AuctionUtil.canSellItemPermission(player)) {
Util.message(player, "&cYou cannot list more than " + AuctionUtil.getCurrentlySellingAmount(player) + " item(s) at once.");
Util.message(player, "&7Purchase ranks with &c/buy&7 to list more items concurrently.");
} else if (AuctionUtil.getItemsToCollectAmount(player) >= 6) {
Util.message(player, "&cYou have too many items in your Collection Bin.");
Util.message(player, "&7Claim those items before they vanish, &c/ah expired");
} else if (!Util.stringIsNumerical(price) && !CommandHandler.isValidAlternatePrice(price)) {
Util.message(player, "&cThat is not a valid price.");
} else if (price.length() > 11) {
Util.message(player, "&cYou can only list something for a max of $99,999,999,999.");
} else {
Controller.attemptSell(player, item, CommandHandler.isValidAlternatePrice(price) ? Util.getMoneyValue(price) : Double.parseDouble(price));
}
return true;
}
private static boolean isValidAlternatePrice(String priceString) {
try {
long money = Util.getMoneyValue(priceString);
return money >= 0L && money <= Double.MAX_VALUE;
} catch (Exception e) {
return false;
}
}
public static boolean handleExpired(Player player) {
MenuRenderer.expired(player);
return true;
}
public static boolean handleSelling(Player player) {
MenuRenderer.selling(player);
return true;
}
public static boolean handleHelp(Player player) {
Controller.help(player);
return true;
}
public static boolean sendNonArg(Player player, Command command) {
if (command == Command.SELL) {
Util.message(player, "&e/ah sell <price>");
Util.message(player, "&7List the item you are holding on the auction house.");
} else {
Util.message(player, "&cUse /ah help for help.");
}
return true;
}
public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd, String commandLabel, String[] argument) {
if (!(sender instanceof Player)) {
return false;
}
Player player = (Player) sender;
if (Auction.stoppingServer || CrankedCore.getInstance().getReboot() != null) {
Util.message(player, "&cYou cannot use the Auction House while the server is rebooting.");
return true;
}
if (Events.isLoading(player)) {
player.sendMessage(CC.RedB + "(!) " + CC.Red + "Please wait while your Auction data loads before using /ah!");
return true;
}
switch (commandLabel.toLowerCase()) {
case "ah": {
int length = argument.length;
if (length < 1) {
return CommandHandler.handleAuction(player);
}
switch (argument[0].toLowerCase()) {
case "sell": {
if (length != 2) {
return CommandHandler.sendNonArg(player, Command.SELL);
}
return CommandHandler.handleAuctionSell(player, argument[1]);
}
case "ex":
case "expired": {
if (length != 1) {
return CommandHandler.sendNonArg(player, Command.EXPIRED);
}
return CommandHandler.handleExpired(player);
}
case "selling":
case "listed": {
if (length != 1) {
return CommandHandler.sendNonArg(player, Command.SELLING);
}
return CommandHandler.handleSelling(player);
}
case "help":
case "commands": {
if (length != 1) {
return CommandHandler.sendNonArg(player, Command.HELP);
}
return CommandHandler.handleHelp(player);
}
case "start": {
return CommandHandler.handleAuction(player);
}
case "togglesafety":
case "toggleconfirm": {
this.handleToggle(player);
return true;
}
case "startbid":
case "hand":
case "auction":
case "auc": {
this.handleStartBid(player, argument);
return true;
}
case "collect": {
new BidCollectionBinMenu(player, Auction.getPlugin().getBidManager().getBidCollectionBin().get(player.getUniqueId())).openGUI(Auction.getPlugin());
return true;
}
case "bids": {
this.handleOpenBids(player);
return true;
}
case "stfu":
case "aucnotify": {
this.handleAuctionMute(player);
return true;
}
case "test": {
if (!player.isOp()) {
return true;
}
for (int i = 0; i < 60; ++i) {
AuctionBid newBid = new AuctionBid(UUID.randomUUID(), player, Lists.newArrayList(new ItemStack(Material.DIRT)), 1000L, 10L, -1L, 60);
Auction.getPlugin().getBidManager().getActiveAuctionBids().put(newBid.getBidID(), newBid);
}
return true;
}
}
Util.message(player, "&cType /ah help to list auction commands.");
}
case "bid":
case "bids":
case "auction":
case "auc": {
String arg;
if (argument.length > 1 && ((arg = argument[0]).equalsIgnoreCase("stfu") || arg.equalsIgnoreCase("aucnotify"))) {
this.handleToggle(player);
return true;
}
this.handleOpenBids(player);
}
}
return false;
}
public void handleAuctionMute(Player player) {
if (Auction.getPlugin().getToggles().isBidMessageToggled(player)) {
Auction.getPlugin().getToggles().getNotifytoggles().remove(player.getUniqueId().toString());
player.sendMessage((Object) ChatColor.GREEN + ChatColor.BOLD.toString() + "(!) " + (Object) ChatColor.GREEN + "You have toggled Auction Bid Notifications: " + (Object) ChatColor.GREEN + ChatColor.BOLD.toString() + "ON");
} else {
Auction.getPlugin().getToggles().getNotifytoggles().add(player.getUniqueId().toString());
player.sendMessage((Object) ChatColor.GREEN + ChatColor.BOLD.toString() + "(!) " + (Object) ChatColor.GREEN + "You have toggled Auction Bid Notifications: " + (Object) ChatColor.RED + ChatColor.BOLD.toString() + "OFF");
}
}
public void handleOpenBids(Player player) {
List<ItemStack> toCollect = Auction.getPlugin().getBidManager().getBidCollectionBin().get(player.getUniqueId());
if (toCollect != null && !toCollect.isEmpty()) {
player.sendMessage((Object) ChatColor.GRAY + "You have items awaiting collection in your " + CC.Green + "/ah collect!");
return;
}
new BidMenu(player).openGUI(Auction.getPlugin());
}
public void handleStartBid(Player player, String[] arguments) {
Long buyoutPrice;
if (arguments.length < 3) {
player.sendMessage(CC.Red + "Invalid usage: /ah startbid <startPrice> <incrementPrice> [buyoutPrice]");
return;
}
List<ItemStack> toCollect = Auction.getPlugin().getBidManager().getBidCollectionBin().get(player.getUniqueId());
if (toCollect != null && !toCollect.isEmpty()) {
player.sendMessage((Object) ChatColor.GRAY + "You have items awaiting collection in your " + CC.Green + "/ah collect!");
return;
}
Set<AuctionBid> currentids = Auction.getPlugin().getBidManager().getCurrentBids().get(player.getUniqueId());
if (currentids != null && currentids.size() >= 3) {
player.sendMessage(CC.RedB + "You can only have 3 Bid Auctions running at a time!");
return;
}
Long startPrice = this.parseLongOrNull(arguments[1]);
Long incrementPrice = this.parseLongOrNull(arguments[2]);
Long l = buyoutPrice = arguments.length > 3 ? this.parseLongOrNull(arguments[3]) : null;
if (startPrice == null || startPrice < 1L) {
player.sendMessage(CC.RedB + "(!) " + CC.Red + "You must enter a valid starting bid price!");
return;
}
if (incrementPrice == null || incrementPrice < 5L) {
player.sendMessage((Object) ChatColor.RED + "You must enter a valid bid increment amount!");
return;
}
if (buyoutPrice == null && arguments.length > 3 || buyoutPrice != null && buyoutPrice <= startPrice) {
player.sendMessage((Object) ChatColor.RED + "You must enter a valid buyout price greater than the starting bid!");
return;
}
if (incrementPrice > 250000L) {
player.sendMessage(CC.RedB + "You cannot have an increment price more than $250,000");
return;
}
BidManager bidManager = Auction.getPlugin().getBidManager();
AuctionPackageMenu packageMenu = new AuctionPackageMenu(player, startPrice, incrementPrice, buyoutPrice == null ? -1L : buyoutPrice, player.getItemInHand(), successItems -> {
AuctionBid bid = new AuctionBid(UUID.randomUUID(), player, (List) successItems.getLeft(), startPrice, incrementPrice, buyoutPrice == null ? -1L : buyoutPrice, (Integer) successItems.getRight());
bidManager.getActiveAuctionBids().put(bid.getBidID(), bid);
bidManager.getCurrentBids().computeIfAbsent(player.getUniqueId(), aucs -> new HashSet()).add(bid);
new BidMenu(player).openGUI(Auction.getPlugin());
player.sendMessage(CC.GreenB + "(AH) " + CC.Gray + "You have started a bid for '" + CC.White + bid.getBidSellDisplayName() + CC.Gray + "' starting at " + CC.GreenB + "$" + CC.Green + Util.formatMoney(startPrice) + "!");
Bukkit.getLogger().info("[AuctionHouse] " + player.getName() + " has started a bid for " + bid.getSellingItems() + " for $" + bid.getStartingBid() + " Inc=" + bid.getBidIncrementAmount() + " buyNow=" + bid.getBuyoutAmount());
});
packageMenu.openGUI(Auction.getPlugin());
}
private Long parseLongOrNull(String val) {
Long originalParse = Util.parseLongOrNull(val);
if (originalParse == null) {
try {
originalParse = Util.getMoneyValue(val);
} catch (Exception exception) {
// empty catch block
}
}
return originalParse;
}
private void handleToggle(Player pl) {
SafetyToggle toggle = Auction.getPlugin().getToggles();
if (toggle.isToggled(pl)) {
toggle.getToggles().remove(pl.getUniqueId().toString());
pl.sendMessage((Object) ChatColor.GREEN + ChatColor.BOLD.toString() + "(!) " + (Object) ChatColor.GREEN + "You have toggled Auction Item Sell Confirmation: " + (Object) ChatColor.GREEN + ChatColor.BOLD.toString() + "ON");
} else {
toggle.getToggles().add(pl.getUniqueId().toString());
pl.sendMessage((Object) ChatColor.RED + ChatColor.BOLD.toString() + "(!) " + (Object) ChatColor.RED + "You have toggled Auction Item Sell Confirmation: " + (Object) ChatColor.RED + ChatColor.BOLD.toString() + "OFF");
}
}
public static String formatDifference(final long time) {
if (time == 0L) {
return "Never";
}
final long day = TimeUnit.SECONDS.toDays(time);
final long hours = TimeUnit.SECONDS.toHours(time) - day * 24L;
final long minutes = TimeUnit.SECONDS.toMinutes(time) - TimeUnit.SECONDS.toHours(time) * 60L;
final long seconds = TimeUnit.SECONDS.toSeconds(time) - TimeUnit.SECONDS.toMinutes(time) * 60L;
final StringBuilder sb = new StringBuilder();
if (day > 0L) {
sb.append(day).append(" ").append((day == 1L) ? "day" : "days").append(" ");
}
if (hours > 0L) {
sb.append(hours).append(" ").append((hours == 1L) ? "hour" : "hours").append(" ");
}
if (minutes > 0L) {
sb.append(minutes).append(" ").append((minutes == 1L) ? "minute" : "minutes").append(" ");
}
if (seconds > 0L && sb.length() <= 0) {
sb.append(seconds).append(" ").append((seconds == 1L) ? "second" : "seconds");
}
final String diff = sb.toString();
return diff.isEmpty() ? "Now" : diff;
}
}
@@ -0,0 +1,171 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.struct.DecimalFormatType
* com.cosmicpvp.cosmicutils.me.astropvp.cratekeys.net.astropvp.armorsets.utils.CC
* com.cosmicpvp.cosmicutils.me.astropvp.cratekeys.net.astropvp.armorsets.utils.NumberUtils
* org.arkhamnetwork.Arkkit.patches.ItemID
* org.arkhamnetwork.Arkkit.plugins.ArkPlugins
* org.bukkit.Bukkit
* org.bukkit.ChatColor
* org.bukkit.Material
* org.bukkit.OfflinePlayer
* org.bukkit.Sound
* org.bukkit.entity.Player
* org.bukkit.event.Event$Result
* org.bukkit.event.EventHandler
* org.bukkit.event.EventPriority
* org.bukkit.event.Listener
* org.bukkit.event.me.astropvp.cratekeys.inventory.InventoryClickEvent
* org.bukkit.event.me.astropvp.cratekeys.inventory.InventoryCloseEvent
* org.bukkit.event.player.PlayerDropItemEvent
* org.bukkit.event.player.PlayerPickupItemEvent
* org.bukkit.me.astropvp.cratekeys.inventory.Inventory
* org.bukkit.me.astropvp.cratekeys.inventory.ItemStack
* org.bukkit.metadata.MetadataValue
* org.bukkit.plugin.Plugin
*/
package me.recolance.auction.controller;
import me.recolance.auction.Auction;
import me.recolance.auction.util.ItemUtils;
import me.recolance.auction.util.Util;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.NumberUtils;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import java.text.DecimalFormat;
public class ConfirmMenu
implements Listener {
private static final DecimalFormat formatter = new DecimalFormat("#,###");
private static final DecimalFormat format = new DecimalFormat("#.##");
public static Inventory getConfirmMenu(ItemStack item, double price, double sellFee, double fee) {
Inventory inv = Bukkit.createInventory(null, (int) 9, (String) "Confirm Auction");
String feeString = CC.RedB + "LISTING FEE: " + CC.RedB + "$" + CC.Red + NumberUtils.formatMoney((double) sellFee) + (CC.Red + " (" + format.format(fee * 100.0) + "%)");
ItemStack confirm = ItemUtils.buildItem(Material.STAINED_GLASS_PANE, (short) 5, (Object) ChatColor.GREEN + ChatColor.BOLD.toString() + "Confirm Auction Price", (Object) ChatColor.GRAY + "Click to " + (Object) ChatColor.GREEN + ChatColor.BOLD.toString() + "accept" + (Object) ChatColor.GRAY + " the auction price for: ", (Object) ChatColor.WHITE + Util.getItemName(item), " ", (Object) ChatColor.YELLOW + ChatColor.BOLD.toString() + "PRICE: $" + (Object) ChatColor.YELLOW + formatter.format(price), feeString);
ItemStack decline = ItemUtils.buildItem(Material.STAINED_GLASS_PANE, (short) 14, (Object) ChatColor.RED + ChatColor.BOLD.toString() + "Decline Auction Price", (Object) ChatColor.GRAY + "Click to " + (Object) ChatColor.RED + ChatColor.BOLD.toString() + "decline" + (Object) ChatColor.GRAY + " the auction.", "", (Object) ChatColor.YELLOW + ChatColor.BOLD.toString() + "PRICE: $" + (Object) ChatColor.YELLOW + formatter.format(price), feeString);
inv.setItem(0, confirm);
inv.setItem(1, confirm);
inv.setItem(2, confirm);
inv.setItem(3, confirm);
inv.setItem(4, item);
inv.setItem(5, decline);
inv.setItem(6, decline);
inv.setItem(7, decline);
inv.setItem(8, decline);
return inv;
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = false)
public void onInventoryClick(InventoryClickEvent e) {
if (e.getInventory().getTitle().equals("Confirm Auction")) {
e.setCancelled(true);
e.setResult(Event.Result.DENY);
if (e.getClickedInventory() == null || e.getWhoClicked().getOpenInventory().getTopInventory() == null || !e.getClickedInventory().equals((Object) e.getWhoClicked().getOpenInventory().getTopInventory())) {
return;
}
Player p = (Player) e.getWhoClicked();
if (!p.hasMetadata("auctionConfirm")) {
this.closePlayerInventoryOnClick(p);
return;
}
int slot = e.getRawSlot();
if (slot < 4) {
ItemStack i = (ItemStack) ((MetadataValue) p.getMetadata("auctionConfirm").get(0)).value();
double price = ((MetadataValue) p.getMetadata("auctionPrice").get(0)).asDouble();
p.removeMetadata("auctionConfirm", (Plugin) Auction.getPlugin());
p.removeMetadata("auctionPrice", (Plugin) Auction.getPlugin());
double fee = Controller.getSellFee(p, price);
if (fee > 0.0 && !Auction.economy.has((OfflinePlayer) p, fee)) {
p.sendMessage(CC.RedB + "(!) " + CC.Red + "You can no longer afford the fee of " + CC.RedB + "$" + CC.Red + NumberUtils.formatMoney((double) fee));
this.closePlayerInventoryOnClick(p);
return;
}
Controller.sell(p, i, price, fee, false);
this.closePlayerInventoryOnClick(p);
} else {
if (slot > 4) {
ItemStack i = (ItemStack) ((MetadataValue) p.getMetadata("auctionConfirm").get(0)).value();
p.removeMetadata("auctionConfirm", (Plugin) Auction.getPlugin());
p.removeMetadata("auctionPrice", (Plugin) Auction.getPlugin());
if (p.getInventory().firstEmpty() != -1) {
p.getInventory().addItem(new ItemStack[]{i});
} else {
p.getWorld().dropItem(p.getLocation(), i);
}
p.sendMessage(ChatColor.RED.toString() + ChatColor.BOLD.toString() + "(!) " + (Object) ChatColor.RED + "You have cancelled your auction.");
p.playSound(p.getLocation(), Sound.BLAZE_DEATH, 1.0f, 1.2f);
this.closePlayerInventoryOnClick(p);
return;
}
}
}
}
@EventHandler
public void onPlayerPickupItem(PlayerPickupItemEvent e) {
if (e.getPlayer().hasMetadata("auctionConfirm")) {
e.setCancelled(true);
}
}
@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent e) {
if (e.getPlayer().hasMetadata("auctionConfirm")) {
e.setCancelled(true);
}
}
@EventHandler
public void onPlayerCloseInventory(InventoryCloseEvent e) {
if (e.getInventory().getTitle().equals("Confirm Auction") && e.getPlayer().hasMetadata("auctionConfirm")) {
final Player p = (Player) e.getPlayer();
ItemStack i = (ItemStack) ((MetadataValue) p.getMetadata("auctionConfirm").get(0)).value();
p.removeMetadata("auctionConfirm", (Plugin) Auction.getPlugin());
p.removeMetadata("auctionPrice", (Plugin) Auction.getPlugin());
if (!p.isDead() && p.getInventory().firstEmpty() != -1) {
p.getInventory().addItem(new ItemStack[]{i});
} else {
p.getWorld().dropItem(p.getLocation(), i);
}
p.sendMessage(ChatColor.RED.toString() + ChatColor.BOLD.toString() + "(!) " + (Object) ChatColor.RED + "You have cancelled your auction.");
p.playSound(p.getLocation(), Sound.BLAZE_DEATH, 1.0f, 1.2f);
Bukkit.getScheduler().runTaskLater((Plugin) Auction.getPlugin(), new Runnable() {
@Override
public void run() {
p.updateInventory();
}
}, 1L);
}
}
private void closePlayerInventoryOnClick(final Player p) {
Bukkit.getScheduler().runTaskLater((Plugin) Auction.getPlugin(), new Runnable() {
@Override
public void run() {
p.closeInventory();
}
}, 1L);
}
}
@@ -0,0 +1,269 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* com.cosmicpvp.cosmicutils.CosmicUtils
* com.cosmicpvp.cosmicutils.customevents.CustomCosmicPlayerEvent
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.struct.DecimalFormatType
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.CC
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.HCFOutpostUtils
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.NumberUtils
* me.vaqxine.NetworkManager.NetworkManager
* net.milkbowl.vault.economy.Economy
* org.arkhamnetwork.Arkkit.Arkkit
* org.arkhamnetwork.Arkkit.net.astropvp.armorsets.commands.CommandArkReboot
* org.arkhamnetwork.Arkkit.patches.AntiCrash
* org.arkhamnetwork.Arkkit.patches.ItemID
* org.arkhamnetwork.Arkkit.plugins.ArkPlugins
* org.bukkit.Bukkit
* org.bukkit.ChatColor
* org.bukkit.OfflinePlayer
* org.bukkit.Sound
* org.bukkit.entity.Player
* org.bukkit.event.Event
* org.bukkit.inventory.ItemStack
* org.bukkit.metadata.FixedMetadataValue
* org.bukkit.metadata.MetadataValue
* org.bukkit.plugin.Plugin
* org.bukkit.scheduler.BukkitRunnable
*/
package me.recolance.auction.controller;
import me.recolance.auction.Auction;
import me.recolance.auction.auction.Listing;
import me.recolance.auction.auction.UnclaimedListing;
import me.recolance.auction.command.Command;
import me.recolance.auction.data.DataHandler;
import me.recolance.auction.data.DataHolder;
import me.recolance.auction.util.AuctionUtil;
import me.recolance.auction.util.Util;
import net.crankedpvp.crankedcore.CrankedCore;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.NumberUtils;
import net.crankedpvp.crankedutils.utils.PlayerUtils;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class Controller {
private static Economy economy = Auction.economy;
public static void purchase(Player player, Listing listing) {
double price = listing.getPrice();
ItemStack item = listing.getItem();
economy.withdrawPlayer(Bukkit.getOfflinePlayer((UUID) player.getUniqueId()), (double) price);
economy.depositPlayer(Bukkit.getOfflinePlayer((UUID) listing.getWhoListed()), (double) price);
PlayerUtils.giveOrDropProtectedItem(player, item, 60);
DataHolder.removeListing(listing);
DataHolder.removePlayerListing(listing.getWhoListed(), listing);
Util.message(player, "&c&l- $" + price);
player.playSound(player.getLocation(), Sound.VILLAGER_HAGGLE, 1.0f, 3.0f);
Player seller = Bukkit.getPlayer((UUID) listing.getWhoListed());
if (seller != null) {
Util.message(seller, "&e&6" + player.getName() + "&e has &6purchased &eyour listing of &6" + Util.getItemName(item) + "&r&e!");
Util.message(seller, "&a&l+ $" + price);
seller.playSound(seller.getLocation(), Sound.CHICKEN_EGG_POP, 1.0f, 0.65f);
}
DataHandler.deleteListing(listing, true);
}
public static void attemptSell(Player player, ItemStack item, double price) {
if (price > Double.MAX_VALUE) {
player.sendMessage((Object) ChatColor.RED + "You cannot list for this amount.");
return;
}
if (price < 0) {
price = 0;
}
if (player.hasMetadata("auctionConfirm") && player.getMetadata("auctionConfirm").size() > 0) {
player.sendMessage(ChatColor.RED.toString() + ChatColor.BOLD.toString() + "(!) " + (Object) ChatColor.RED + "You are creating auctions too quickly!");
return;
}
double fee = Controller.getSellFee(player, price);
if (!Auction.economy.has((OfflinePlayer) player, fee)) {
player.sendMessage(CC.Red + "(!) " + CC.Red + "You cannot afford the sell fee of " + CC.RedB + "$" + CC.Red + NumberUtils.formatMoney((double) fee));
return;
}
if (Auction.getPlugin().hasToggle(player)) {
item = player.getItemInHand().clone();
Controller.sell(player, item, price, fee, true);
} else {
item = player.getItemInHand().clone();
player.setItemInHand(null);
player.setMetadata("auctionConfirm", (MetadataValue) new FixedMetadataValue((Plugin) Auction.getPlugin(), (Object) item));
player.setMetadata("auctionPrice", (MetadataValue) new FixedMetadataValue((Plugin) Auction.getPlugin(), (Object) price));
player.playSound(player.getLocation(), Sound.BAT_TAKEOFF, 0.8f, 0.8f);
player.openInventory(ConfirmMenu.getConfirmMenu(item, price, fee, Controller.getSellFee(player)));
}
}
public static double getSellFee(Player player, double cost) {
if (Auction.getPlugin().getConfig().getBoolean("auction.sellFee", true)) {
return Math.min(1000000.0, cost * Controller.getSellFee(player));
}
return 0.0;
}
public static double getSellFee(Player player) {
if (player.hasPermission("enchantments.max.20")) {
return 0.005;
}
if (player.hasPermission("enchantments.max.12")) {
return 0.0075;
}
if (player.hasPermission("enchantments.max.9")) {
return 0.01;
}
if (player.hasPermission("enchantments.max.6")) {
return 0.0125;
}
return 0.015;
}
public static void sell(Player player, ItemStack item, double price, double fee, boolean removeItem) {
Listing listing = new Listing(UUID.randomUUID(), AuctionUtil.getEndTime(), player.getUniqueId(), item, price);
if (removeItem) {
player.setItemInHand(null);
}
DataHolder.addListing(listing);
DataHolder.addPlayerListing(player.getUniqueId(), listing);
Util.message(player, "&e&l(!) &eYou have &6listed &eyour " + Util.getItemName(item) + "&e on the auction house for &6$" + price + "&e!");
DataHandler.saveListing(listing, true);
if (fee > 0.0) {
Auction.economy.withdrawPlayer((OfflinePlayer) player, fee);
player.sendMessage(CC.RedB + "(AH Fee) - $" + CC.Red + NumberUtils.formatMoney((double) fee));
}
}
public static void cancel(Player player, Listing listing) {
DataHolder.removeListing(listing);
DataHolder.removePlayerListing(listing.getWhoListed(), listing);
UnclaimedListing ucL = new UnclaimedListing(UUID.randomUUID(), listing.getWhoListed(), listing.getItem(), AuctionUtil.getUnclaimedEndTime());
DataHolder.addUnclaimedListing(listing.getWhoListed(), ucL);
DataHandler.deleteListing(listing, true);
DataHandler.saveUnclaimedListing(ucL, true);
Util.message(player, "&e&l(!) &eYou have &6cancelled &ean auction &6listing&e. Return cancelled and expired listings at &6/ah expired&e.");
}
public static void adminCancel(Player player, Listing listing) {
DataHolder.removeListing(listing);
DataHolder.removePlayerListing(listing.getWhoListed(), listing);
UnclaimedListing ucL = new UnclaimedListing(UUID.randomUUID(), listing.getWhoListed(), listing.getItem(), AuctionUtil.getUnclaimedEndTime());
if (Bukkit.getPlayer((UUID) listing.getWhoListed()) != null) {
DataHolder.addUnclaimedListing(listing.getWhoListed(), ucL);
}
DataHandler.deleteListing(listing, true);
DataHandler.saveUnclaimedListing(ucL, true);
Util.message(player, "&c&l(!) &cListing removed.");
}
public static void expire(Listing listing) {
DataHolder.removeListing(listing);
DataHolder.removePlayerListing(listing.getWhoListed(), listing);
UnclaimedListing ucL = new UnclaimedListing(UUID.randomUUID(), listing.getWhoListed(), listing.getItem(), AuctionUtil.getUnclaimedEndTime());
if (Bukkit.getPlayer((UUID) listing.getWhoListed()) != null) {
DataHolder.addUnclaimedListing(listing.getWhoListed(), ucL);
}
DataHandler.deleteListing(listing, true);
DataHandler.saveUnclaimedListing(ucL, true);
}
public static void expireUnclaimed(UnclaimedListing listing) {
DataHolder.removeUnclaimedListing(listing.getListedBy(), listing);
DataHandler.deleteUnclaimedListing(listing, true);
}
public static void claim(Player player, UnclaimedListing listing) {
DataHolder.getUnclaimedListings().get(player.getUniqueId()).remove(listing);
DataHandler.deleteUnclaimedListing(listing, true);
PlayerUtils.giveOrDropProtectedItem(player, listing.getItem(), 60);
}
public static void claimAll(Player player) {
int space = Util.getFreeInventorySpace(player);
int i = 0;
ArrayList<UnclaimedListing> claim = new ArrayList<UnclaimedListing>();
for (UnclaimedListing listing : DataHolder.getUnclaimedListings().get(player.getUniqueId())) {
if (i >= space && !Util.hasInventorySpace(player)) {
Util.message(player, "&c&l(!) &cYou don't have enough inventory space.");
break;
}
PlayerUtils.giveOrDropProtectedItem(player, listing.getItem(), 60);
claim.add(listing);
++i;
}
for (UnclaimedListing listing : claim) {
DataHolder.removeUnclaimedListing(player.getUniqueId(), listing);
DataHandler.deleteUnclaimedListing(listing, true);
}
Util.message(player, "&e&l(!) &eYou have claimed &6" + i + " &e expired listings.");
}
public static void help(Player player) {
Util.message(player, "");
Util.message(player, "&e&l&nAuction House Commands");
for (Command command : Command.values()) {
Util.message(player, command.getDescription()[1]);
Util.message(player, command.getDescription()[2]);
Util.message(player, "");
}
player.sendMessage(CC.Yellow + "/ah startbid <startingBid> <bidIncrement> [buyNowPrice]");
player.sendMessage(CC.Gray + "Create an auction package for others to bid on!");
player.sendMessage("");
player.sendMessage(CC.Yellow + "/ah collect");
player.sendMessage(CC.Gray + "Collect items from previous bid auctions!");
player.sendMessage("");
player.sendMessage(CC.Yellow + "/ah bids");
player.sendMessage(CC.Gray + "View all active bid auctions!");
player.sendMessage("");
player.sendMessage(CC.Yellow + "/ah stfu");
player.sendMessage(CC.Gray + "Turn off alerts when someone outbids you!");
player.sendMessage("");
}
public static void expireListings() {
new BukkitRunnable() {
public void run() {
if (Auction.stoppingServer || CrankedCore.getInstance().getReboot() != null) {
return;
}
List<Listing> listings = DataHolder.getListings();
if (listings.size() > 0 && listings.get(listings.size() - 1).getEndTime() < System.currentTimeMillis()) {
Listing l = listings.get(listings.size() - 1);
Controller.expire(l);
Bukkit.getLogger().info("[Auction] Expiring auction " + l.getId() + " of " + (Object) l.getItem() + " for " + l.getWhoListed() + " for $" + l.getPrice());
}
}
}.runTaskTimer((Plugin) Auction.plugin, 100L, 100L);
}
public static void expireOfflineUnclaimedListings() {
new BukkitRunnable() {
public void run() {
DataHandler.deleteOverExpiredUnclaimedListing(true);
}
}.runTaskTimer((Plugin) Auction.plugin, 0L, 3600L);
}
}
@@ -0,0 +1,68 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* org.bukkit.Bukkit
* org.bukkit.entity.Player
* org.bukkit.event.EventHandler
* org.bukkit.event.EventPriority
* org.bukkit.event.Listener
* org.bukkit.event.player.PlayerJoinEvent
* org.bukkit.event.player.PlayerQuitEvent
* org.bukkit.plugin.Plugin
*/
package me.recolance.auction.controller;
import me.recolance.auction.Auction;
import me.recolance.auction.auction.UnclaimedListing;
import me.recolance.auction.data.DataHandler;
import me.recolance.auction.data.DataHolder;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.Plugin;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
public class Events
implements Listener {
public static Set<UUID> loadingUUIDs = new HashSet<UUID>();
public static boolean isLoading(Player player) {
return loadingUUIDs.contains(player.getUniqueId());
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerJoinEvent(PlayerJoinEvent event) {
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
List<UnclaimedListing> found = DataHolder.getUnclaimedListings().get(uuid);
if (found != null) {
Bukkit.getLogger().info("[AuctionHouse] Skipping loadUnclaimedListings for " + uuid.toString() + " due to already having keys (" + found + ") in unclaimedListings map.");
loadingUUIDs.remove(uuid);
return;
}
if (loadingUUIDs.contains(player.getUniqueId())) {
Bukkit.getLogger().info("[AuctionHouse] Skipping loading of data for " + player.getUniqueId() + " since there is a pending thread already handling it.");
return;
}
loadingUUIDs.add(player.getUniqueId());
Bukkit.getScheduler().runTaskAsynchronously((Plugin) Auction.getPlugin(), () -> {
DataHandler.loadUnclaimedListings(uuid);
loadingUUIDs.remove(player.getUniqueId());
});
}
@EventHandler
public void onLeave(PlayerQuitEvent event) {
DataHolder.removeUnclaimedListingStore(event.getPlayer().getUniqueId());
}
}
@@ -0,0 +1,464 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.gui.CosmicGUI
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.CC
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.JSONMessage
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.TimeUtils
* com.google.common.collect.Lists
* org.apache.commons.lang.builder.HashCodeBuilder
* org.arkhamnetwork.Arkkit.patches.ItemID
* org.arkhamnetwork.Arkkit.plugins.ArkPlugins
* org.bukkit.Bukkit
* org.bukkit.ChatColor
* org.bukkit.Material
* org.bukkit.OfflinePlayer
* org.bukkit.Sound
* org.bukkit.entity.Player
* org.bukkit.inventory.ItemStack
* org.bukkit.inventory.meta.ItemMeta
* org.bukkit.metadata.FixedMetadataValue
* org.bukkit.metadata.MetadataValue
* org.bukkit.plugin.Plugin
* org.bukkit.plugin.java.JavaPlugin
*/
package me.recolance.auction.data;
import com.google.common.collect.Lists;
import me.recolance.auction.Auction;
import me.recolance.auction.menu.BidManager;
import me.recolance.auction.menu.bidmenus.BiddableMenu;
import me.recolance.auction.menu.bidmenus.ConfirmItemMenu;
import me.recolance.auction.menu.bidmenus.PackageViewMenu;
import me.recolance.auction.util.ItemSerialization;
import me.recolance.auction.util.Util;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.JSONMessage;
import net.crankedpvp.crankedutils.utils.TimeUtils;
import net.crankedpvp.crankedutils.utils.cosmicgui.CosmicGUI;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.*;
import java.util.concurrent.TimeUnit;
public class AuctionBid {
private static final long AUCTION_LENGTH_TIME = TimeUnit.SECONDS.toSeconds(60L);
private static final long ANTI_SNIPE_TIME = TimeUnit.SECONDS.toMillis(2L);
private transient List<ItemStack> sellingItems = Lists.newArrayList();
private List<String> serializedStringVersion = Lists.newArrayList();
private UUID bidID;
private UUID sellerUUID;
private double startingBid;
private double buyoutAmount;
private long currentBid;
private long bidIncrementAmount;
private UUID currentHighestBidder;
private String currentBidderName;
private String sellerName;
private long auctionStart;
private long lastBidTime;
private int secondsLeftInAuction = 0;
private Set<UUID> bidders = new HashSet<UUID>();
private boolean expired = false;
public AuctionBid(UUID bidID, Player seller, List<ItemStack> itemsToSell, long startingBid, long bidIncrementAmount, long buyoutAmount, int duration) {
this.bidID = bidID;
this.sellerUUID = seller.getUniqueId();
this.sellerName = seller.getName();
this.sellingItems = itemsToSell;
this.startingBid = startingBid;
this.bidIncrementAmount = bidIncrementAmount;
this.secondsLeftInAuction = duration;
this.auctionStart = System.currentTimeMillis();
this.buyoutAmount = buyoutAmount;
this.serializeItems();
}
public void serializeItems() {
for (ItemStack selling : this.sellingItems) {
this.serializedStringVersion.add(ItemSerialization.itemToStringBase64(selling));
}
}
public void deserialize() {
this.sellingItems = Lists.newArrayList();
if (this.serializedStringVersion != null) {
for (String serialized : this.serializedStringVersion) {
this.sellingItems.add(ItemSerialization.itemFromBase64(serialized));
}
}
}
public boolean isSeller(Player player) {
if (player.getName().equals("iFamasssxD") || player.getName().equals("Merchant")) {
return false;
}
return player.getUniqueId().equals(this.sellerUUID);
}
public boolean isPackageDeal() {
return this.sellingItems.size() > 1;
}
public void placePlayerBid(Player bidder, long bidAmount) {
if (this.expired) {
bidder.sendMessage((Object) ChatColor.RED + "Item Auction no longer valid!");
return;
}
if (this.currentHighestBidder != null) {
OfflinePlayer player = Bukkit.getOfflinePlayer((UUID) this.currentHighestBidder);
Auction.economy.depositPlayer(player, (double) this.currentBid);
if (player instanceof Player && !Auction.getPlugin().getToggles().isBidMessageToggled((Player) player)) {
((Player) player).sendMessage((Object) ChatColor.RED + ChatColor.BOLD.toString() + "(AH) " + CC.Red + bidder.getName() + CC.RedB + " OUTBID " + CC.Red + "you on " + CC.White + "'" + this.getBidSellDisplayName() + CC.White + "'" + CC.Red + " - " + CC.RedB + "$" + Util.formatMoney(bidAmount) + "!");
}
}
bidder.playSound(bidder.getLocation(), Sound.ORB_PICKUP, 0.4f, 1.1f);
bidder.sendMessage(CC.GreenB + "(AH) " + CC.Gray + "You have placed the highest bid for " + CC.GreenB + "$" + CC.Green + Util.formatMoney(bidAmount) + "!");
Auction.economy.withdrawPlayer((OfflinePlayer) bidder, (double) bidAmount);
this.currentBid = bidAmount;
this.currentBidderName = bidder.getName();
this.currentHighestBidder = bidder.getUniqueId();
this.lastBidTime = System.currentTimeMillis();
this.bidders.add(bidder.getUniqueId());
}
public void buyNow(Player buyer) {
if (this.expired) {
return;
}
if (!Auction.economy.has((OfflinePlayer) buyer, this.buyoutAmount)) {
return;
}
this.expired = true;
Auction.getPlugin().getBidManager().removeAuctionBid(this);
if (this.currentHighestBidder != null) {
OfflinePlayer originalBuyer = Bukkit.getOfflinePlayer((UUID) this.currentHighestBidder);
if (originalBuyer != null && originalBuyer instanceof Player) {
((Player) originalBuyer).sendMessage(CC.RedB + "(AH) " + CC.GreenB + this.currentBidderName + CC.Gray + " purchased " + CC.GreenU + this.sellerName + "'s" + CC.Gray + " auction of '" + this.getBidSellDisplayName() + CC.Gray + "' for " + CC.GreenB + "$" + CC.Green + Util.formatMoney(this.buyoutAmount) + CC.Gray + "!");
}
if (originalBuyer != null) {
Bukkit.getLogger().info("Returning $" + this.currentBid + " to " + originalBuyer.getName() + " due to " + buyer.getName() + " buying out item!");
Auction.economy.depositPlayer(originalBuyer, (double) this.currentBid);
}
}
Auction.economy.withdrawPlayer((OfflinePlayer) buyer, this.buyoutAmount);
OfflinePlayer seller = Bukkit.getOfflinePlayer((UUID) this.sellerUUID);
Auction.economy.depositPlayer(seller, this.buyoutAmount);
if (seller instanceof Player) {
Player onlinePlayer = (Player) seller;
onlinePlayer.sendMessage(CC.GreenB + "(AH) " + CC.GreenB + buyer.getName() + CC.Gray + " has purchased your '" + this.getBidSellDisplayName() + CC.Gray + "' for " + CC.GreenB + "$" + CC.Green + Util.formatMoney(this.buyoutAmount) + "!");
}
this.transferItemsToOwner(buyer.getUniqueId());
}
public void expire() {
List sellerBin = Auction.getPlugin().getBidManager().getBidCollectionBin().computeIfAbsent(this.sellerUUID, newBin -> Lists.newArrayList());
for (ItemStack item : this.sellingItems) {
sellerBin.add(item);
}
Auction.getPlugin().getBidManager().removeAuctionBid(this);
}
public ItemStack getAuctionDisplayItem(boolean watchlist) {
boolean canBuyout;
ItemStack toShow = null;
List<String> lore = Lists.newArrayList();
if (this.isPackageDeal()) {
lore.add("");
lore.add((Object) ChatColor.GOLD + "Bundle of " + CC.GoldB + this.getSellingItems().size() + "x " + CC.Gold + "Items:");
for (ItemStack item : this.getSellingItems()) {
lore.add(" " + CC.GoldB + "* " + (item.getAmount() > 1 ? item.getAmount() + "x " : "") + CC.White + Util.getItemName(item));
}
toShow = this.getSellingItems().get(0);
} else {
ItemStack item = this.getSellingItems().get(0);
if (item != null && item.hasItemMeta() && item.getItemMeta().hasLore()) {
lore = item.getItemMeta().getLore();
}
if (item != null) {
toShow = item;
}
}
if (toShow == null) {
toShow = new ItemStack(Material.DIRT);
}
lore.add("");
lore.add((Object) ChatColor.GRAY + "--------------------------");
lore.add("");
lore.add(CC.Gold + "Starting Bid: " + CC.YellowB + "$" + CC.Yellow + Util.formatMoney(this.getStartingBid()));
String color = this.getBidIncrementAmount() >= 100000L ? CC.Red : CC.Yellow;
lore.add(CC.Gold + "Bid Increment: " + color + CC.Bold + "$" + color + Util.formatMoney(this.getBidIncrementAmount()));
lore.add(CC.Gold + "Current Bid: " + CC.YellowB + "$" + CC.Yellow + Util.formatMoney(this.getCurrentBid()));
if (this.getCurrentBidderName() != null) {
lore.add(CC.Gold + "Highest Bidder: " + CC.Yellow + this.getCurrentBidderName());
}
if (canBuyout = this.getBuyoutAmount() > 1.0 && (double) this.getCurrentBid() < this.getBuyoutAmount()) {
lore.add(CC.Gold + "Buy Now for " + CC.YellowB + "$" + Util.formatMoney(this.getBuyoutAmount()));
}
lore.add(CC.Gold + "Seller: " + CC.Yellow + this.getSellerName());
if (watchlist || this.getSecondsLeftInAuction() > 0) {
lore.add(CC.Gold + "Auction Ending in " + CC.GoldB + (this.getSecondsLeftInAuction() <= 0 ? "1s" : TimeUtils.formatSeconds((long) this.getSecondsLeftInAuction())));
}
lore.add("");
lore.add(CC.Yellow + "Left-Click" + CC.Gray + " to bid on this item");
lore.add(CC.Yellow + "Middle-Click " + CC.Gray + "to enter custom bid");
if (canBuyout) {
lore.add(CC.Yellow + "Shift-LClick " + CC.Gray + "to buy it now");
}
if (watchlist) {
lore.add(CC.Yellow + "Shift-RClick " + CC.Gray + "to add to watchlist");
} else {
lore.add(CC.Yellow + "Shift-RClick " + CC.Gray + "to remove from watchlist");
}
if (this.isPackageDeal()) {
lore.add(CC.Yellow + "Right-Click" + CC.Gray + " to view package contents");
}
lore.add((Object) ChatColor.GRAY + "--------------------------");
toShow = toShow.clone();
ItemMeta im = toShow.getItemMeta();
im.setLore(lore);
toShow.setItemMeta(im);
return toShow;
}
public Runnable getRightClickLogic(BiddableMenu parent, Player player) {
return () -> {
if (this.isExpired()) {
player.sendMessage(CC.Red + "That item is no longer available!");
parent.redraw();
return;
}
if (this.isPackageDeal()) {
new PackageViewMenu(player, this, parent).openGUI(Auction.getPlugin());
}
};
}
public Runnable getLeftClickLogic(BiddableMenu parent, Player player) {
return () -> {
if (this.isExpired()) {
player.sendMessage((Object) ChatColor.RED + "That item is no longer available!");
parent.redraw();
return;
}
if (this.isSeller(player)) {
player.sendMessage(CC.RedB + "You cannot bid on your own items!");
return;
}
if (this.getCurrentHighestBidder() != null && this.getCurrentHighestBidder().equals(player.getUniqueId())) {
player.sendMessage(CC.Green + "You are already the highest bidder!");
return;
}
long nextBid = (long) ((this.getCurrentBid() == 0L ? this.getStartingBid() : (double) this.getCurrentBid()) + (double) this.getBidIncrementAmount());
if (!Auction.economy.has((OfflinePlayer) player, (double) nextBid)) {
player.sendMessage(CC.Gray + "You cannot afford a bid of " + CC.GreenB + "$" + CC.Green + Util.formatMoney(nextBid));
return;
}
if (parent.lastBid != 0L && System.currentTimeMillis() - parent.lastBid <= 1000L) {
player.sendMessage(CC.RedB + "(!) " + CC.Red + "Please wait at least 1 second before placing another bid!");
return;
}
parent.lastBid = System.currentTimeMillis();
if (!Auction.getPlugin().getToggles().isToggled(player) && !this.bidders.contains(player.getUniqueId())) {
new ConfirmItemMenu(player, "Confirm First Time Bid", nextBid, this, confirm -> {
this.placePlayerBid(player, nextBid);
parent.forceUpdate = true;
parent.openGUI(Auction.getPlugin());
}, deny -> parent.openGUI(Auction.getPlugin())).openGUI(Auction.getPlugin());
} else {
this.placePlayerBid(player, nextBid);
parent.forceUpdate = true;
parent.redraw();
}
};
}
public Runnable getShiftLeftClickLogic(CosmicGUI parent, Player player) {
return () -> {
if (this.getBuyoutAmount() <= 0.0) {
player.sendMessage(CC.RedB + "You can only bid on this item!");
return;
}
if (this.isSeller(player)) {
player.sendMessage(CC.RedB + "You cannot bid on your own items!");
return;
}
if (this.isExpired()) {
player.sendMessage(CC.RedB + "That item is no longer available!");
parent.redraw();
return;
}
if (!Auction.economy.has((OfflinePlayer) player, this.getBuyoutAmount())) {
player.sendMessage(CC.Gray + "You cannot afford a bid of " + CC.GreenB + "$" + CC.Green + Util.formatMoney(this.getBuyoutAmount()));
return;
}
long buyout = (long) this.getBuyoutAmount();
new ConfirmItemMenu(player, "Buy it Now?", buyout, this, ConfirmItemMenu.getConfirmCallback(this, player, buyout, true), deny -> parent.openGUI((JavaPlugin) Auction.getPlugin())).openGUI(Auction.getPlugin());
};
}
public Runnable getMiddleClickLogic(CosmicGUI menuViewing, Player player) {
return () -> {
if (this.isSeller(player)) {
player.sendMessage(CC.RedB + "You cannot bid on your own items!");
return;
}
if (this.isExpired()) {
player.sendMessage(CC.RedB + "That item is no longer available!");
menuViewing.redraw();
return;
}
player.setMetadata("auctionBidding", (MetadataValue) new FixedMetadataValue((Plugin) Auction.getPlugin(), (Object) this.getBidID().toString()));
player.closeInventory();
player.sendMessage(CC.GreenB + "(!) " + CC.Green + "Please enter a " + CC.GreenU + "custom bid" + CC.Green + " amount" + (this.getBuyoutAmount() > 1.0 && (double) this.getCurrentBid() < this.getBuyoutAmount() ? " " + CC.GreenB + CC.Underline + "OR" + CC.Green + " enter '" + Util.formatMoney(this.getBuyoutAmount()) + "' to Buy Now!" : "!"));
};
}
public void onTick() {
if (this.expired) {
Bukkit.getLogger().info("Called onTick for expired auctionBid: " + this.bidID + " Seller: " + this.sellerName);
return;
}
if (this.secondsLeftInAuction <= 0) {
this.expired = true;
Player seller = Bukkit.getPlayer((UUID) this.sellerUUID);
if (this.currentBid <= 0L || this.currentHighestBidder == null) {
Bukkit.getLogger().info("Expiring bid for " + this.getSellerUUID() + " due to noone placing a bid: " + this.getSellingItems());
if (seller != null) {
seller.sendMessage(CC.RedB + "(AH) " + CC.Red + "Auction Bid expired for '" + this.getBidSellDisplayName() + CC.Red + "'!");
seller.sendMessage(CC.Gray + "You can access your expired bid auction items in " + CC.GrayU + "/ah collect" + CC.Gray + "!");
}
this.expire();
} else if (System.currentTimeMillis() - this.lastBidTime <= ANTI_SNIPE_TIME) {
this.secondsLeftInAuction = 10;
if (seller != null) {
seller.sendMessage(CC.YellowB + "(AH) ANTI SNIPE ACTIVATED - " + CC.Yellow + "Adding 10s to bid...");
}
this.expired = false;
} else {
OfflinePlayer buyer = Bukkit.getOfflinePlayer((UUID) this.currentHighestBidder);
Auction.economy.depositPlayer((OfflinePlayer) (seller == null ? Bukkit.getOfflinePlayer((UUID) this.sellerUUID) : seller), (double) this.currentBid);
String displayName = this.getBidSellDisplayName();
if (seller != null) {
String finishedString = CC.GreenB + "SOLD: \n";
for (ItemStack toSell : this.sellingItems) {
finishedString = finishedString + CC.GoldB + " * " + CC.White + Util.getItemName(toSell) + "\n";
}
JSONMessage message = new JSONMessage(CC.GreenB + "(AH) " + CC.Gray + "Your auction for '", ChatColor.GRAY);
message.addHoverData(displayName, finishedString);
message.addText(null, CC.Gray + "' was purchased by " + CC.GreenU + this.currentBidderName + CC.Gray + " for " + CC.GreenB + "$" + CC.Green + Util.formatMoney(this.currentBid) + CC.Gray + " after " + CC.GreenB + Util.timeToDHMSString(System.currentTimeMillis() - this.auctionStart) + "!", ChatColor.GRAY);
message.sendToPlayer(seller);
}
if (buyer != null && buyer instanceof Player) {
Player pl = (Player) buyer;
pl.sendMessage("");
pl.sendMessage(CC.GreenB + "(AH) " + CC.Gray + "You have purchased '" + displayName + CC.Gray + "' from " + CC.GreenB + this.sellerName + CC.Gray + " for " + CC.GreenB + "$" + CC.Green + Util.formatMoney(this.currentBid) + "!");
pl.sendMessage(CC.Gray + "Collect your winning Auction Item(s) from your " + CC.GrayU + "/ah collect");
}
this.transferItemsToOwner(this.currentHighestBidder);
this.bidders.forEach(playerUUID -> {
if (playerUUID.equals(this.currentHighestBidder)) {
return;
}
Player onlineOrOffline = Bukkit.getPlayer((UUID) playerUUID);
if (onlineOrOffline != null) {
onlineOrOffline.sendMessage(CC.RedB + "(AH) " + CC.GreenB + this.currentBidderName + CC.Gray + " has won " + CC.GreenU + this.sellerName + "'s" + CC.Gray + " auction for '" + displayName + CC.Gray + "' bidding " + CC.GreenB + "$" + CC.Green + Util.formatMoney(this.currentBid) + CC.Gray + " and outbidding " + CC.GreenB + CC.Underline + (this.bidders.size() - 1) + CC.Gray + " bidders!");
}
});
}
} else {
--this.secondsLeftInAuction;
}
}
public void transferItemsToOwner(UUID owner) {
BidManager manager = Auction.getPlugin().getBidManager();
List binItems = manager.getBidCollectionBin().computeIfAbsent(owner, newBin -> Lists.newArrayList());
for (ItemStack sellingItem : this.sellingItems) {
ItemStack won;
ItemStack withoutID = won = sellingItem;
binItems.add(withoutID);
}
Bukkit.getLogger().info("Transfering " + binItems.size() + " items to " + owner + "'s bid bin from " + this.sellerName + "'s Auction: " + this.sellingItems);
}
public String getBidSellDisplayName() {
if (this.sellingItems.size() > 1) {
return CC.GreenB + this.sellingItems.size() + "x Item Package";
}
return Util.getItemName(this.sellingItems.get(0));
}
public boolean equals(Object obj) {
AuctionBid other;
if (obj instanceof AuctionBid && (other = (AuctionBid) obj).getBidID() != null && other.getBidID().equals(this.getBidID()) && this.getSellerUUID() != null && this.getSellerUUID().equals(other.getSellerUUID())) {
return true;
}
return super.equals(obj);
}
public int hashCode() {
return new HashCodeBuilder(17, 37).append((Object) this.bidID).append((Object) this.sellerUUID).toHashCode();
}
public List<ItemStack> getSellingItems() {
return this.sellingItems;
}
public UUID getBidID() {
return this.bidID;
}
public UUID getSellerUUID() {
return this.sellerUUID;
}
public double getStartingBid() {
return this.startingBid;
}
public double getBuyoutAmount() {
return this.buyoutAmount;
}
public long getCurrentBid() {
return this.currentBid;
}
public long getBidIncrementAmount() {
return this.bidIncrementAmount;
}
public UUID getCurrentHighestBidder() {
return this.currentHighestBidder;
}
public String getCurrentBidderName() {
return this.currentBidderName;
}
public String getSellerName() {
return this.sellerName;
}
public int getSecondsLeftInAuction() {
return this.secondsLeftInAuction;
}
public boolean isExpired() {
return this.expired;
}
}
@@ -0,0 +1,14 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* org.bukkit.me.astropvp.cratekeys.inventory.ItemStack
*/
package me.recolance.auction.data;
import org.bukkit.inventory.ItemStack;
public interface AuctionItem {
public ItemStack getDisplay();
}
@@ -0,0 +1,29 @@
/*
* Decompiled with CFR 0.150.
*/
package me.recolance.auction.data;
public class BidInformation {
private String playerName;
private long bidStart;
private long maxBid;
public BidInformation(String playerName, long bidStart, long maxBid) {
this.playerName = playerName;
this.bidStart = bidStart;
this.maxBid = maxBid;
}
public String getPlayerName() {
return this.playerName;
}
public long getBidStart() {
return this.bidStart;
}
public long getMaxBid() {
return this.maxBid;
}
}
@@ -0,0 +1,406 @@
// Decompiled with: FernFlower
// Class Version: 8
package me.recolance.auction.data;
import com.google.common.collect.Lists;
import com.google.common.io.BaseEncoding;
import me.recolance.auction.Auction;
import me.recolance.auction.auction.Listing;
import me.recolance.auction.auction.UnclaimedListing;
import me.recolance.auction.menu.categories.AuctionCategory;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import net.crankedpvp.crankedutils.utils.items.ItemUtils;
import net.minecraft.server.v1_8_R3.NBTCompressedStreamTools;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import org.bukkit.scheduler.BukkitRunnable;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
public class DataHandler {
private static List<AuctionCategory> auctionCategories = Lists.newLinkedList();
private static long nextCategoryCalculation;
private static List<Material> subCategoryItems = null;
public static void generateTables(Connection connection) throws SQLException {
try (PreparedStatement listings = connection.prepareStatement("CREATE TABLE IF NOT EXISTS listings(id VARCHAR(255) NOT NULL,listed_by VARCHAR(255) NOT NULL,item TEXT NOT NULL,price INT NOT NULL,end_time BIGINT NOT NULL,PRIMARY KEY (id))");
PreparedStatement expired = connection.prepareStatement("CREATE TABLE IF NOT EXISTS expired(id VARCHAR(255) NOT NULL,player VARCHAR(255) NOT NULL,item TEXT NOT NULL,expire_time BIGINT NOT NULL,PRIMARY KEY (id))")) {
listings.execute();
expired.execute();
generateIndex(connection);
}
}
private static void generateIndex(Connection connection) throws SQLException {
try (PreparedStatement statement = connection.prepareStatement("CREATE INDEX IDX_EXPIRED ON expired (player)")) {
statement.execute();
} catch (SQLException e) {
if (e.getErrorCode() != 1061) throw e;
}
}
public static void loadListings() throws SQLException {
Connection connection = Database.getConnection();
try (PreparedStatement load = connection.prepareStatement("SELECT * FROM listings");
ResultSet set = load.executeQuery()) {
while(set.next()) {
UUID playerId = UUID.fromString(set.getString("listed_by"));
Listing listing = new Listing(UUID.fromString(set.getString("id")), set.getLong("end_time"), playerId, fromString(set.getString("item")), set.getBigDecimal("price").doubleValue());
DataHolder.addListing(listing);
DataHolder.addPlayerListing(playerId, listing);
}
List<Listing> listings = DataHolder.getListings();
Collections.sort(listings, new Comparator<Listing>() {
public int compare(Listing l1, Listing l2) {
return Long.valueOf(l1.getEndTime()).compareTo(l2.getEndTime());
}
});
Collections.reverse(listings);
}
}
public static List<Material> getSubCategoryItems() {
if (subCategoryItems == null) {
subCategoryItems = Lists.newArrayList(ItemUtils.armor);
subCategoryItems.addAll(Arrays.asList(ItemUtils.weapons));
subCategoryItems.addAll(Arrays.asList(ItemUtils.tools));
subCategoryItems.addAll(Arrays.asList(Material.BOOK, Material.MOB_SPAWNER, Material.TNT, Material.PAPER));
}
return subCategoryItems;
}
private static boolean isSubCategoryItem(MaterialData data, ItemStack item) {
Material type = data.getItemType();
boolean contains = getSubCategoryItems().contains(type);
Material dataType = data.getItemType();
String display = item.getItemMeta().getDisplayName();
return !contains && dataType == Material.EMERALD && item.getItemMeta().hasDisplayName() && display.startsWith(CC.RedB + "Soul Gem [") ? true : contains;
}
public static List<AuctionCategory> getAuctionCategories() {
if (nextCategoryCalculation == 0L || nextCategoryCalculation <= System.currentTimeMillis()) {
auctionCategories.clear();
long start = System.currentTimeMillis();
Map<Material, AuctionCategory> subCategoryCategories = new HashMap();
new HashMap();
Map<Integer, AuctionCategory> bookCategories = new HashMap();
Map<String, AuctionCategory> matchingItemNames = new HashMap();
DataHolder.getListings().forEach((item) -> {
if (item.isValid() && !item.isExpired()) {
ItemStack selling = item.getItem().clone();
String name = ItemUtils.getDisplayName(selling);
if (name == null) {
name = StringUtils.capitaliseAllWords(item.toString().toLowerCase().replace("_", " "));
}
if (selling.getEnchantments().size() > 0) {
selling.getEnchantments().forEach((ench, level) -> {
selling.removeEnchantment(ench);
});
}
selling.setAmount(1);
MaterialData type = selling.getData();
Material mat = type.getItemType();
if (isSubCategoryItem(type, selling)) {
String subCategoryName = CC.White + StringUtils.capitaliseAllWords(mat.name().toLowerCase().replace("_", " "));
if (name.startsWith(CC.RedB + "Soul Gem") && mat == Material.EMERALD) {
subCategoryName = CC.RedB + "Soul Gems";
} else if (item.getBookRarity() != null) {
subCategoryName = CC.White + "Enchant Books";
}
String finalSubCategoryName = subCategoryName;
String finalSubCategoryName1 = subCategoryName;
AuctionCategory category = (AuctionCategory)subCategoryCategories.computeIfAbsent(mat, (e) -> {
return new AuctionCategory(finalSubCategoryName, ChatColor.stripColor(finalSubCategoryName1), (new ItemBuilder(selling)).setName(finalSubCategoryName1).build(), Lists.newArrayList(), (Listing)null, Lists.newLinkedList(), 10);
});
if (item.getBookRarity() != null) {
String bookName = item.getBookTierColor() + item.getBookTierName() + " Enchant Books";
AuctionCategory bookCategory = (AuctionCategory)bookCategories.computeIfAbsent(item.getBookRarity(), (e) -> {
return new AuctionCategory(bookName, ChatColor.stripColor(bookName), (new ItemBuilder(selling)).setName(bookName).build(), Lists.newArrayList(), (Listing)null, Lists.newLinkedList(), item.getBookRarity());
});
bookCategory.getCategoryItems().add(item);
if (!category.getSubCategories().contains(bookCategory)) {
category.getSubCategories().add(bookCategory);
}
return;
}
category.getCategoryItems().add(item);
return;
}
String finalName = name;
String finalName1 = name;
((AuctionCategory)matchingItemNames.computeIfAbsent(name, (e) -> {
return new AuctionCategory(finalName, ChatColor.stripColor(finalName1), selling, Lists.newArrayList(), (Listing)null, Lists.newLinkedList(), 10);
})).getCategoryItems().add(item);
}
});
auctionCategories.addAll(matchingItemNames.values());
auctionCategories.addAll(subCategoryCategories.values());
auctionCategories.forEach(AuctionCategory::sortCategoryItems);
auctionCategories.forEach(AuctionCategory::sortSubCategories);
Collections.sort(auctionCategories, AuctionCategory::compareTo);
Auction.getPlugin().getLogger().info("Took " + (System.currentTimeMillis() - start) + "ms to calculate auction categories " + auctionCategories.size() + " Listings: " + DataHolder.getListings().size());
}
auctionCategories.removeIf((cat) -> {
cat.getCategoryItems().removeIf((item) -> {
return item.isExpired() || !item.isValid();
});
return cat.getCategoryItems().isEmpty() && cat.getSubCategories().isEmpty();
});
return auctionCategories;
}
public static void loadUnclaimedListings(UUID playerId) {
Connection connection = Database.getConnection();
try {
PreparedStatement statement = connection.prepareStatement("SELECT id, item, expire_time FROM expired WHERE player=?");
statement.setString(1, playerId.toString());
ResultSet set = statement.executeQuery();
while(set.next()) {
UnclaimedListing uL = new UnclaimedListing(UUID.fromString(set.getString("id")), playerId, fromString(set.getString("item")), set.getLong("expire_time"));
DataHolder.addUnclaimedListing(playerId, uL);
}
statement.close();
} catch (SQLException var5) {
var5.printStackTrace();
}
}
public static void saveAllListings(boolean async) {
Connection connection = Database.getConnection();
try {
PreparedStatement statement = connection.prepareStatement("REPLACE INTO listings(id, listed_by, item, price, end_time) VALUES (?,?,?,?,?)");
Iterator var3 = DataHolder.getListings().iterator();
while(var3.hasNext()) {
Listing l = (Listing)var3.next();
statement.setString(1, l.getId().toString());
statement.setString(2, l.getWhoListed().toString());
statement.setString(3, toString(l.getItem()));
statement.setBigDecimal(4, new BigDecimal(l.getPrice()));
statement.setLong(5, l.getEndTime());
statement.addBatch();
}
if (async) {
asyncExecuteBatch(statement);
} else {
statement.executeBatch();
statement.close();
}
} catch (SQLException var5) {
var5.printStackTrace();
}
}
public static void saveListing(Listing listing, boolean async) {
Connection connection = Database.getConnection();
try {
PreparedStatement statement = connection.prepareStatement("REPLACE INTO listings(id, listed_by, item, price, end_time) VALUES (?,?,?,?,?)");
statement.setString(1, listing.getId().toString());
statement.setString(2, listing.getWhoListed().toString());
statement.setString(3, toString(listing.getItem()));
statement.setBigDecimal(4, new BigDecimal(listing.getPrice()));
statement.setLong(5, listing.getEndTime());
if (async) {
asyncExecute(statement);
} else {
statement.execute();
statement.close();
}
} catch (SQLException var4) {
var4.printStackTrace();
}
}
public static void saveUnclaimedListing(UnclaimedListing listing, boolean async) {
Connection connection = Database.getConnection();
try {
PreparedStatement statement = connection.prepareStatement("REPLACE INTO expired(id, player, item, expire_time) VALUES (?,?,?,?)");
statement.setString(1, listing.getId().toString());
statement.setString(2, listing.getListedBy().toString());
statement.setString(3, toString(listing.getItem()));
statement.setLong(4, listing.getExpireTime());
if (async) {
asyncExecute(statement);
} else {
statement.execute();
statement.close();
}
} catch (SQLException var4) {
var4.printStackTrace();
}
}
public static void deleteListing(Listing listing, boolean async) {
Connection connection = Database.getConnection();
try {
PreparedStatement statement = connection.prepareStatement("DELETE FROM listings WHERE id=?");
statement.setString(1, listing.getId().toString());
if (async) {
asyncExecute(statement);
} else {
statement.execute();
statement.close();
}
} catch (SQLException var4) {
var4.printStackTrace();
}
}
public static void deleteUnclaimedListing(UnclaimedListing listing, boolean async) {
Connection connection = Database.getConnection();
try {
PreparedStatement statement = connection.prepareStatement("DELETE FROM expired WHERE id=?");
statement.setString(1, listing.getId().toString());
if (async) {
asyncExecute(statement);
} else {
statement.execute();
statement.close();
}
} catch (SQLException var4) {
var4.printStackTrace();
}
}
public static void deleteOverExpiredUnclaimedListing(boolean async) {
Connection connection = Database.getConnection();
try {
PreparedStatement statement = connection.prepareStatement("DELETE FROM expired WHERE expire_time<?");
statement.setLong(1, System.currentTimeMillis());
if (async) {
asyncExecute(statement);
} else {
statement.execute();
statement.close();
}
} catch (SQLException var3) {
var3.printStackTrace();
}
}
private static void asyncExecute(final PreparedStatement statement) {
if (Auction.stoppingServer) {
try {
statement.execute();
statement.close();
} catch (SQLException var2) {
var2.printStackTrace();
}
} else {
(new BukkitRunnable() {
public void run() {
try {
statement.execute();
statement.close();
} catch (SQLException var2) {
var2.printStackTrace();
}
}
}).runTaskAsynchronously(Auction.plugin);
}
}
private static void asyncExecuteBatch(final PreparedStatement statement) {
if (Auction.stoppingServer) {
try {
statement.execute();
} catch (SQLException var2) {
var2.printStackTrace();
}
} else {
(new BukkitRunnable() {
public void run() {
try {
statement.executeBatch();
} catch (SQLException var2) {
var2.printStackTrace();
}
}
}).runTaskAsynchronously(Auction.plugin);
}
}
public static String toString(ItemStack item) {
if (item == null) {
return "null";
} else {
NBTTagCompound tagCompound = new NBTTagCompound();
CraftItemStack.asNMSCopy(item).save(tagCompound);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
NBTCompressedStreamTools.a(tagCompound, outputStream);
} catch (Exception var4) {
var4.printStackTrace();
}
return BaseEncoding.base64().encode(outputStream.toByteArray());
}
}
public static ItemStack fromString(String string) {
if (string.equals("null")) {
return null;
} else {
InputStream is = new ByteArrayInputStream(BaseEncoding.base64().decode(string));
NBTTagCompound nbttagcompound = null;
try {
nbttagcompound = NBTCompressedStreamTools.a(is);
} catch (Exception var4) {
var4.printStackTrace();
}
return CraftItemStack.asBukkitCopy(net.minecraft.server.v1_8_R3.ItemStack.createStack(nbttagcompound));
}
}
}
@@ -0,0 +1,90 @@
/*
* Decompiled with CFR 0.150.
*/
package me.recolance.auction.data;
import me.recolance.auction.auction.Listing;
import me.recolance.auction.auction.UnclaimedListing;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
public class DataHolder {
private static List<Listing> listings = new ArrayList<Listing>();
private static HashMap<UUID, List<Listing>> playerListings = new HashMap();
private static HashMap<UUID, List<UnclaimedListing>> unclaimedListings = new HashMap();
public static List<Listing> getListings() {
return listings;
}
public static void setListings(List<Listing> list) {
listings = list;
}
public static void addListing(Listing listing) {
DataHolder.getListings().add(0, listing);
}
public static void removeListing(Listing listing) {
listing.setValid(false);
listings.remove(listing);
}
public static HashMap<UUID, List<Listing>> getPlayerListings() {
return playerListings;
}
public static void setPlayerListings(HashMap<UUID, List<Listing>> list) {
playerListings = list;
}
public static void addPlayerListing(UUID playerId, Listing listing) {
if (!DataHolder.getPlayerListings().containsKey(playerId)) {
ArrayList<Listing> listings = new ArrayList<Listing>();
listings.add(listing);
DataHolder.getPlayerListings().put(playerId, listings);
} else {
playerListings.get(playerId).add(listing);
}
}
public static void removePlayerListing(UUID playerId, Listing listing) {
if (!DataHolder.getPlayerListings().containsKey(playerId)) {
return;
}
DataHolder.getPlayerListings().get(playerId).remove(listing);
}
public static HashMap<UUID, List<UnclaimedListing>> getUnclaimedListings() {
return unclaimedListings;
}
public static void setUnclaimedListings(HashMap<UUID, List<UnclaimedListing>> uList) {
unclaimedListings = uList;
}
public static void addUnclaimedListing(UUID playerId, UnclaimedListing listing) {
if (!DataHolder.getUnclaimedListings().containsKey(playerId)) {
ArrayList<UnclaimedListing> listings = new ArrayList<UnclaimedListing>();
listings.add(listing);
DataHolder.getUnclaimedListings().put(playerId, listings);
} else {
DataHolder.getUnclaimedListings().get(playerId).add(listing);
}
}
public static void removeUnclaimedListing(UUID playerId, UnclaimedListing listing) {
if (!DataHolder.getUnclaimedListings().containsKey(playerId)) {
return;
}
DataHolder.getUnclaimedListings().get(playerId).remove(listing);
}
public static void removeUnclaimedListingStore(UUID playerId) {
DataHolder.getUnclaimedListings().remove(playerId);
}
}
@@ -0,0 +1,70 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* org.bukkit.configuration.file.FileConfiguration
* org.bukkit.plugin.Plugin
*/
package me.recolance.auction.data;
import me.recolance.auction.Auction;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.Plugin;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
public class Database {
private static Connection connection;
private static Plugin plugin;
private static FileConfiguration config;
static {
plugin = Auction.plugin;
config = plugin.getConfig();
}
public static boolean openDatabaseConnection() {
try {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException ignored) {
Class.forName("com.mysql.jdbc.Driver");
}
connection = DriverManager.getConnection("jdbc:mysql://" + config.getString("sql.host") + ":" + config.getString("sql.port") + "/" + config.getString("sql.database"), config.getString("sql.user"), config.getString("sql.pass"));
DataHandler.generateTables(connection);
return true;
} catch (ClassNotFoundException | SQLException e) {
plugin.getLogger().log(Level.SEVERE, "Could not initialize the auction database", e);
closeConnection();
return false;
}
}
public static void closeConnection() {
if (connection == null) return;
try {
connection.close();
} catch (SQLException e) {
System.out.println("COULD NOT CLOSE CONNECTION!");
e.printStackTrace();
} finally {
connection = null;
}
}
public static Connection getConnection() {
try {
if (connection == null || connection.isClosed()) {
if (!Database.openDatabaseConnection()) {
throw new IllegalStateException("Auction database is unavailable");
}
}
} catch (SQLException e) {
throw new IllegalStateException("Could not check auction database connection", e);
}
return connection;
}
}
@@ -0,0 +1,29 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* net.minecraft.util.com.google.gson.JsonDeserializationContext
* net.minecraft.util.com.google.gson.JsonDeserializer
* net.minecraft.util.com.google.gson.JsonElement
* net.minecraft.util.com.google.gson.JsonObject
* net.minecraft.util.com.google.gson.JsonParseException
* org.bukkit.me.astropvp.cratekeys.inventory.ItemStack
*/
package me.recolance.auction.data;
import com.google.gson.*;
import me.recolance.auction.util.ItemSerialization;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Type;
public class ItemStackDeserializer implements JsonDeserializer<ItemStack> {
public ItemStack deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
JsonObject object;
if (jsonElement instanceof JsonObject && (object = (JsonObject) jsonElement).has("b64")) {
return ItemSerialization.itemFromBase64(object.get("b64").getAsString());
}
return null;
}
}
@@ -0,0 +1,29 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* net.minecraft.util.com.google.gson.JsonElement
* net.minecraft.util.com.google.gson.JsonObject
* net.minecraft.util.com.google.gson.JsonSerializationContext
* net.minecraft.util.com.google.gson.JsonSerializer
* org.bukkit.me.astropvp.cratekeys.inventory.ItemStack
*/
package me.recolance.auction.data;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import me.recolance.auction.util.ItemSerialization;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Type;
public class ItemStackSerializer implements JsonSerializer<ItemStack> {
public JsonElement serialize(ItemStack itemStack, Type type, JsonSerializationContext jsonSerializationContext) {
JsonObject element = new JsonObject();
element.addProperty("b64", ItemSerialization.itemToStringBase64(itemStack));
return element;
}
}
@@ -0,0 +1,63 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* org.bukkit.configuration.file.YamlConfiguration
* org.bukkit.entity.Player
*/
package me.recolance.auction.data;
import me.recolance.auction.Auction;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class SafetyToggle {
private List<String> toggles = new ArrayList<String>();
private List<String> notifytoggles = new ArrayList<String>();
private File file = new File(Auction.getPlugin().getDataFolder(), "toggles.yml");
private YamlConfiguration config;
public SafetyToggle() {
if (!this.file.exists()) {
try {
this.file.createNewFile();
} catch (Exception e) {
e.printStackTrace();
}
}
this.config = YamlConfiguration.loadConfiguration((File) this.file);
this.toggles = this.config.getStringList("toggles");
this.notifytoggles = this.config.getStringList("notify-toggles");
}
public boolean isToggled(Player player) {
return this.toggles.contains(player.getUniqueId().toString());
}
public boolean isBidMessageToggled(Player player) {
return this.notifytoggles.contains(player.getUniqueId().toString());
}
public void saveFile() {
try {
this.config.set("toggles", this.toggles);
this.config.set("notify-toggles", this.notifytoggles);
this.config.save(this.file);
} catch (Exception e) {
e.printStackTrace();
}
}
public List<String> getToggles() {
return this.toggles;
}
public List<String> getNotifytoggles() {
return this.notifytoggles;
}
}
@@ -0,0 +1,145 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* com.cosmicpvp.cosmicutils.me.astropvp.cratekeys.net.astropvp.armorsets.utils.CC
* org.bukkit.Bukkit
* org.bukkit.ChatColor
* org.bukkit.OfflinePlayer
* org.bukkit.entity.Player
* org.bukkit.event.Event$Result
* org.bukkit.event.EventHandler
* org.bukkit.event.EventPriority
* org.bukkit.event.Listener
* org.bukkit.event.me.astropvp.cratekeys.inventory.InventoryClickEvent
* org.bukkit.event.player.AsyncPlayerChatEvent
* org.bukkit.event.player.PlayerInteractEntityEvent
* org.bukkit.event.player.PlayerJoinEvent
* org.bukkit.metadata.MetadataValue
* org.bukkit.plugin.Plugin
*/
package me.recolance.auction.menu;
import me.recolance.auction.Auction;
import me.recolance.auction.data.AuctionBid;
import me.recolance.auction.menu.bidmenus.BidMenu;
import me.recolance.auction.menu.bidmenus.ConfirmItemMenu;
import me.recolance.auction.util.Util;
import net.crankedpvp.crankedutils.utils.CC;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import java.util.UUID;
public class BidListener
implements Listener {
private static String auctionBiddingMetadata = "auctionBidding";
@EventHandler
public void onItemClick(InventoryClickEvent event) {
if (event.getInventory().getName().equals("Active Bids") || event.getInventory().getName().equals("Enter Auction Package Items") || event.getInventory().getName().endsWith("'s Package Items") || event.getInventory().getName().equals("Auction Bid Collection") || event.getInventory().getName().equals("Confirm Purchase Now") || event.getInventory().getName().equals("Confirm Bid Now") || event.getInventory().getName().startsWith("Buy It Now") || event.getInventory().getName().equals("Confirm First Time Bid") || event.getInventory().getName().equals("Bidding Watchlist")) {
event.setCancelled(true);
event.setResult(Event.Result.DENY);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEntityEvent event) {
Player clicked;
if (event.getRightClicked() instanceof Player && (clicked = (Player) event.getRightClicked()).getName().endsWith("Auctioneer") && clicked.hasMetadata("NPC")) {
event.setCancelled(true);
event.getPlayer().chat("/ah");
}
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Auction.getPlugin().getBidManager().setProccessAuctionHouse(true);
}
@EventHandler(priority = EventPriority.LOWEST)
public void onAsyncPLayerChatEvent(AsyncPlayerChatEvent event) {
Player pl = event.getPlayer();
if (pl.hasMetadata(auctionBiddingMetadata)) {
event.setCancelled(true);
Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin) Auction.getPlugin(), () -> {
boolean buyout;
UUID uuid = UUID.fromString(((MetadataValue) pl.getMetadata(auctionBiddingMetadata).get(0)).asString());
if (uuid == null) {
pl.removeMetadata(auctionBiddingMetadata, (Plugin) Auction.getPlugin());
pl.sendMessage(CC.RedB + "Auction no longer valid!");
return;
}
String msg = ChatColor.stripColor((String) event.getMessage());
BidManager bidManager = Auction.getPlugin().getBidManager();
AuctionBid bid = bidManager.getActiveAuctionBids().get(uuid);
if (bid == null || bid.isExpired()) {
pl.sendMessage((Object) ChatColor.RED + "Auction no longer valid!");
pl.removeMetadata(auctionBiddingMetadata, (Plugin) Auction.getPlugin());
return;
}
if (msg.equalsIgnoreCase("cancel")) {
pl.sendMessage((Object) ChatColor.RED + "Auction bid cancelled!");
pl.removeMetadata(auctionBiddingMetadata, (Plugin) Auction.getPlugin());
return;
}
Long bidAmount = Util.parseLongOrNull(msg);
if (bidAmount == null) {
try {
bidAmount = Util.getMoneyValue(msg);
} catch (Exception exception) {
// empty catch block
}
}
if (bidAmount == null || bidAmount <= 0L) {
pl.sendMessage(CC.Red + "You must enter a valid bid!");
return;
}
if (bid.getCurrentBid() >= bidAmount) {
pl.sendMessage((Object) ChatColor.RED + "Your bid must be higher than the current bid!");
pl.sendMessage(CC.RedB + "Current Bid: $" + CC.Red + Util.formatMoney(bid.getCurrentBid()));
pl.sendMessage((Object) ChatColor.GRAY + "Type '" + CC.Red + "cancel" + CC.Gray + "' to cancel this auction bid!");
return;
}
if ((double) bid.getCurrentBid() < bid.getStartingBid() && (double) bidAmount.longValue() < bid.getStartingBid()) {
pl.sendMessage(CC.Red + "You must bid atleast the starting bid amount!");
pl.sendMessage(CC.RedB + "Starting Bid: $" + CC.Red + Util.formatMoney(bid.getStartingBid()));
return;
}
if (!Auction.economy.has((OfflinePlayer) pl, (double) bidAmount.longValue())) {
pl.sendMessage(CC.Red + "You cannot afford that bid!");
pl.sendMessage(CC.Red + "Current Balance: " + CC.RedB + "$" + CC.Red + Util.formatMoney(Auction.economy.getBalance((OfflinePlayer) pl)));
return;
}
long nextBid = bid.getCurrentBid() + bid.getBidIncrementAmount();
if (nextBid > bidAmount) {
pl.sendMessage((Object) ChatColor.RED + "Your bid must be higher than the current bid with the bid increment!");
pl.sendMessage(CC.RedB + "Required Bid: $" + CC.Red + Util.formatMoney(nextBid));
return;
}
boolean bl = buyout = bid.getBuyoutAmount() > 0.0 && (double) bidAmount.longValue() == bid.getBuyoutAmount();
if (buyout && (double) bid.getCurrentBid() >= bid.getBuyoutAmount()) {
pl.sendMessage(CC.RedB + "Buyout no longer available for that item!");
pl.removeMetadata(auctionBiddingMetadata, (Plugin) Auction.getPlugin());
return;
}
pl.removeMetadata(auctionBiddingMetadata, (Plugin) Auction.getPlugin());
long finalBidAmount = bidAmount;
new ConfirmItemMenu(pl, "Confirm " + (buyout ? "Purchase" : "Bid") + " Now", finalBidAmount, bid, ConfirmItemMenu.getConfirmCallback(bid, pl, finalBidAmount, buyout), deny -> new BidMenu(pl).openGUI(Auction.getPlugin())).openGUI(Auction.getPlugin());
});
}
}
}
@@ -0,0 +1,233 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.gui.CosmicGUI
* com.cosmicpvp.cosmicutils.me.astropvp.cratekeys.net.astropvp.armorsets.utils.JSONUtils
* com.google.common.collect.Lists
* net.minecraft.util.com.google.common.reflect.TypeToken
* net.minecraft.util.com.google.gson.Gson
* net.minecraft.util.com.google.gson.GsonBuilder
* net.minecraft.util.com.google.gson.JsonDeserializationContext
* net.minecraft.util.com.google.gson.JsonDeserializer
* net.minecraft.util.com.google.gson.JsonElement
* net.minecraft.util.com.google.gson.JsonParseException
* net.minecraft.util.com.google.gson.JsonPrimitive
* net.minecraft.util.com.google.gson.JsonSerializationContext
* net.minecraft.util.com.google.gson.JsonSerializer
* net.minecraft.util.io.netty.util.internal.ConcurrentSet
* org.bukkit.Bukkit
* org.bukkit.Material
* org.bukkit.me.astropvp.cratekeys.inventory.ItemStack
* org.bukkit.plugin.Plugin
* org.bukkit.plugin.java.JavaPlugin
* org.bukkit.scheduler.BukkitRunnable
* org.bukkit.scheduler.BukkitTask
*/
package me.recolance.auction.menu;
import com.google.common.collect.Lists;
import com.google.common.reflect.TypeToken;
import com.google.gson.*;
import io.netty.util.internal.ConcurrentSet;
import me.recolance.auction.Auction;
import me.recolance.auction.data.AuctionBid;
import me.recolance.auction.data.ItemStackDeserializer;
import me.recolance.auction.data.ItemStackSerializer;
import me.recolance.auction.menu.bidmenus.BiddableMenu;
import me.recolance.auction.util.ItemSerialization;
import net.crankedpvp.crankedutils.utils.JSONUtils;
import net.crankedpvp.crankedutils.utils.cosmicgui.CosmicGUI;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
public class BidManager {
private final Map<UUID, Set<AuctionBid>> currentBids = new HashMap<UUID, Set<AuctionBid>>();
private final HashMap<UUID, List<ItemStack>> bidCollectionBin = new HashMap();
private final Type activeToken = new TypeToken<HashSet<AuctionBid>>() {
}.getType();
private final Type bidBinToken = new TypeToken<HashMap<UUID, List<String>>>() {
}.getType();
private final Type watchlistToken = new TypeToken<ConcurrentHashMap<UUID, ConcurrentSet<UUID>>>() {
}.getType();
private final Type item = new TypeToken<List<ItemStack>>() {
}.getType();
private final Gson gson = new GsonBuilder().registerTypeAdapter(Material.class, new JsonSerializer<Material>() {
public JsonElement serialize(Material material, Type type, JsonSerializationContext jsonSerializationContext) {
return new JsonPrimitive(material.name());
}
}).registerTypeAdapter(Material.class, new JsonDeserializer<Material>() {
public Material deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
if (jsonElement instanceof JsonPrimitive) {
return Material.getMaterial(jsonElement.getAsString());
}
return null;
}
}).registerTypeAdapter(ItemStack.class, new ItemStackSerializer()).registerTypeAdapter(ItemStack.class, new ItemStackDeserializer()).enableComplexMapKeySerialization().create();
private ConcurrentHashMap<UUID, AuctionBid> activeAuctionBids = new ConcurrentHashMap();
private Map<UUID, ConcurrentSet<UUID>> watchlists = new ConcurrentHashMap<UUID, ConcurrentSet<UUID>>();
private File activeAuctionFile;
private File bidCollectionBinFile;
private File watchlistFile;
private BukkitTask task;
private boolean proccessAuctionHouse = false;
private List<ItemStack> loaded;
public void loadBids(JavaPlugin plugin) throws IOException {
this.activeAuctionFile = JSONUtils.getOrCreateFile(plugin.getDataFolder(), "activeAuctions.json");
this.bidCollectionBinFile = JSONUtils.getOrCreateFile(plugin.getDataFolder(), "bidCollectionBids.json");
this.watchlistFile = JSONUtils.getOrCreateFile(plugin.getDataFolder(), "watchlistFile.json");
HashMap<UUID, List<String>> serializedList = (HashMap) JSONUtils.fromJson(this.bidCollectionBinFile, this.bidBinToken, this.gson);
Set<AuctionBid> auctions = (Set<AuctionBid>) JSONUtils.fromJson(this.activeAuctionFile, this.activeToken, this.gson);
if (auctions != null) {
auctions.forEach(auc -> {
if (auc == null || auc.isExpired()) {
return;
}
auc.deserialize();
this.activeAuctionBids.put(auc.getBidID(), (AuctionBid) auc);
});
}
if (this.activeAuctionBids == null) {
this.activeAuctionBids = new ConcurrentHashMap();
}
if (serializedList != null) {
serializedList.forEach((id, list) -> this.bidCollectionBin.put(id, list.stream().map(ItemSerialization::itemFromBase64).collect(Collectors.toList())));
}
this.watchlists = (Map) JSONUtils.fromJson(this.watchlistFile, this.watchlistToken);
if (this.watchlists == null) {
this.watchlists = new ConcurrentHashMap<UUID, ConcurrentSet<UUID>>();
}
this.watchlists.forEach((owner, ids) -> ids.stream().filter(aucID -> !this.activeAuctionBids.containsKey(aucID)).forEach(((ConcurrentSet) ids)::remove));
this.activeAuctionBids.forEach((auctionId, bid) -> {
Set bids = this.currentBids.computeIfAbsent(bid.getSellerUUID(), e -> new HashSet());
bids.add(bid);
});
Bukkit.getScheduler().scheduleSyncDelayedTask(Auction.getPlugin(), () -> {
this.proccessAuctionHouse = true;
}, 1200L);
Bukkit.getScheduler().scheduleSyncRepeatingTask(Auction.getPlugin(), () -> {
try {
this.saveBids(true);
} catch (IOException e) {
e.printStackTrace();
}
}, 1200L, 6000L);
if (Bukkit.getOnlinePlayers().size() > 0) {
this.proccessAuctionHouse = true;
}
}
public void startBidTimer() {
if (this.task != null) {
this.task.cancel();
}
this.task = new BukkitRunnable() {
public void run() {
if (!BidManager.this.proccessAuctionHouse) {
return;
}
for (Map.Entry bidEntry : BidManager.this.activeAuctionBids.entrySet()) {
try {
AuctionBid bid = (AuctionBid) bidEntry.getValue();
boolean expired = bid.isExpired();
bid.onTick();
if (!bid.isExpired() || expired) continue;
BidManager.this.removeAuctionBid(bid);
Bukkit.getLogger().info("Removing expired auction bid " + bid.getSellerName() + " for " + bid.getBidSellDisplayName());
} catch (Exception e) {
Bukkit.getLogger().info("ERROR onTick inside bid: " + ((AuctionBid) bidEntry.getValue()).getSellerName() + " ( " + ((AuctionBid) bidEntry.getValue()).getBidID() + ") Selling: " + ((AuctionBid) bidEntry.getValue()).getBidSellDisplayName() + " Items: " + ((AuctionBid) bidEntry.getValue()).getSellingItems());
if (((AuctionBid) bidEntry.getValue()).isExpired()) {
BidManager.this.activeAuctionBids.remove(bidEntry.getKey());
}
e.printStackTrace();
}
}
CosmicGUI.activeGUIs.forEach((uuid, gui) -> {
BiddableMenu bidMenu;
if (gui instanceof BiddableMenu && (bidMenu = (BiddableMenu) gui).getPlayer() != null && bidMenu.getPlayer().getOpenInventory() != null && bidMenu.getPlayer().getOpenInventory().getTopInventory() != null && bidMenu.getPlayer().getOpenInventory().getTopInventory().getName().equals(((BiddableMenu) gui).getTitle())) {
gui.redraw();
}
});
}
}.runTaskTimer(Auction.getPlugin(), 20L, 20L);
}
public void removeAuctionBid(AuctionBid bid) {
this.activeAuctionBids.remove(bid.getBidID());
Set<AuctionBid> bids = this.currentBids.get(bid.getSellerUUID());
if (bids != null) {
bids.remove(bid);
}
Bukkit.getLogger().info("Removing bid " + bid.getBidID() + " from " + bid.getSellerName());
}
public void saveBids(boolean async) throws IOException {
if (async && Bukkit.isPrimaryThread()) {
ConcurrentHashMap<UUID, AuctionBid> copy = new ConcurrentHashMap<UUID, AuctionBid>(this.activeAuctionBids);
HashMap<UUID, List<ItemStack>> binCopy = new HashMap<UUID, List<ItemStack>>(this.bidCollectionBin);
CompletableFuture.runAsync(() -> {
try {
this.saveBids(copy, binCopy);
} catch (IOException e) {
e.printStackTrace();
}
});
return;
}
this.saveBids(this.activeAuctionBids, this.bidCollectionBin);
}
public void saveBids(ConcurrentHashMap<UUID, AuctionBid> bids, HashMap<UUID, List<ItemStack>> collectionBins) throws IOException {
ArrayList bis = Lists.newArrayList(bids.values());
HashMap serializedCollectionBins = new HashMap();
collectionBins.forEach((id, itemList) -> serializedCollectionBins.put(id, itemList.stream().map(ItemSerialization::itemToStringBase64).collect(Collectors.toList())));
JSONUtils.saveJSONToFile(this.bidCollectionBinFile, serializedCollectionBins, this.bidBinToken, this.gson);
JSONUtils.saveJSONToFile(this.activeAuctionFile, bis, this.activeToken, this.gson);
JSONUtils.saveJSONToFile(this.watchlistFile, this.watchlists, this.watchlistToken, this.gson);
}
public Map<UUID, Set<AuctionBid>> getCurrentBids() {
return this.currentBids;
}
public ConcurrentHashMap<UUID, AuctionBid> getActiveAuctionBids() {
return this.activeAuctionBids;
}
public HashMap<UUID, List<ItemStack>> getBidCollectionBin() {
return this.bidCollectionBin;
}
public Map<UUID, ConcurrentSet<UUID>> getWatchlists() {
return this.watchlists;
}
public boolean isProccessAuctionHouse() {
return this.proccessAuctionHouse;
}
public void setProccessAuctionHouse(boolean proccessAuctionHouse) {
this.proccessAuctionHouse = proccessAuctionHouse;
}
}
@@ -0,0 +1,167 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* net.minecraft.server.v1_8_R3.ItemStack
* net.minecraft.server.v1_8_R3.NBTTagCompound
* org.bukkit.Bukkit
* org.bukkit.ChatColor
* org.bukkit.Material
* org.bukkit.craftbukkit.v1_8_R3.me.astropvp.cratekeys.inventory.CraftItemStack
* org.bukkit.enchantments.Enchantment
* org.bukkit.me.astropvp.cratekeys.inventory.ItemStack
* org.bukkit.me.astropvp.cratekeys.inventory.meta.ItemMeta
* org.bukkit.me.astropvp.cratekeys.inventory.meta.SkullMeta
*/
package me.recolance.auction.menu;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class MenuButton {
private static List<Integer> attributeItems;
static {
int[] idWithAttribute;
attributeItems = new ArrayList<Integer>();
for (int item : idWithAttribute = new int[]{256, 257, 258, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 283, 284, 285, 286, 373, 387, 403, 2256, 2257, 2258, 2259, 2260, 2261, 2262, 2263, 2264, 2265, 2266, 2267}) {
attributeItems.add(item);
}
}
private ItemStack item;
public MenuButton() {
this.item = new ItemStack(Material.AIR, 1);
}
public MenuButton(ItemStack item) {
this.item = item;
}
private static boolean typeHasAttribute(int id) {
return attributeItems.contains(id);
}
public MenuButton name(String name) {
ItemMeta meta = this.item.getItemMeta();
meta.setDisplayName(ChatColor.translateAlternateColorCodes((char) '&', (String) name));
this.item.setItemMeta(meta);
return this;
}
public MenuButton lore(String... lore) {
ItemMeta meta = this.item.getItemMeta();
ArrayList<String> loreList = new ArrayList<String>();
if (meta.hasLore()) {
loreList.addAll(meta.getLore());
}
for (String line : lore) {
loreList.add(ChatColor.translateAlternateColorCodes((char) '&', (String) line));
}
meta.setLore(loreList);
this.item.setItemMeta(meta);
return this;
}
public MenuButton lore(List<String> lore) {
ItemMeta meta = this.item.getItemMeta();
ArrayList<String> loreList = new ArrayList<String>();
if (meta.hasLore()) {
loreList.addAll(meta.getLore());
}
for (String line : lore) {
loreList.add(ChatColor.translateAlternateColorCodes((char) '&', (String) line));
}
meta.setLore(loreList);
this.item.setItemMeta(meta);
return this;
}
public MenuButton lore(String loreLine) {
ItemMeta meta = this.item.getItemMeta();
ArrayList<String> loreList = new ArrayList<String>();
if (meta.hasLore()) {
loreList.addAll(meta.getLore());
}
loreList.add(ChatColor.translateAlternateColorCodes((char) '&', (String) loreLine));
meta.setLore(loreList);
this.item.setItemMeta(meta);
return this;
}
public MenuButton skull(UUID uuid) {
return this.skull(Bukkit.getOfflinePlayer((UUID) uuid).getName());
}
public MenuButton skull(String name) {
SkullMeta meta = (SkullMeta) this.item.getItemMeta();
meta.setOwner(name);
this.item.setItemMeta((ItemMeta) meta);
return this;
}
public MenuButton amount(int amount) {
this.item.setAmount(amount);
return this;
}
public MenuButton type(Material material) {
return this.type(material.getId());
}
public MenuButton type(int typeId) {
this.item.setTypeId(typeId);
return this;
}
public MenuButton durability(int durability) {
this.item.setDurability((short) durability);
return this;
}
public ItemStack get() {
if (MenuButton.typeHasAttribute(this.item.getTypeId())) {
net.minecraft.server.v1_8_R3.ItemStack stack = CraftItemStack.asNMSCopy((ItemStack) this.item);
NBTTagCompound compound = stack.getTag();
if (compound == null) {
compound = new NBTTagCompound();
stack.setTag(compound);
compound = stack.getTag();
}
compound.setInt("HideFlags", 63);
stack.setTag(compound);
this.item = CraftItemStack.asCraftMirror((net.minecraft.server.v1_8_R3.ItemStack) stack);
}
return this.item;
}
public MenuButton addGlow() {
this.item.addUnsafeEnchantment(Enchantment.DURABILITY, -1);
net.minecraft.server.v1_8_R3.ItemStack stack = CraftItemStack.asNMSCopy((ItemStack) this.item);
NBTTagCompound compound = stack.getTag();
if (compound == null) {
compound = new NBTTagCompound();
stack.setTag(compound);
compound = stack.getTag();
}
if (!compound.hasKey("HideFlags")) {
compound.setInt("HideFlags", 1);
}
stack.setTag(compound);
this.item = CraftItemStack.asCraftMirror((net.minecraft.server.v1_8_R3.ItemStack) stack);
return this;
}
}
@@ -0,0 +1,343 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.CC
* net.milkbowl.vault.economy.Economy
* org.bukkit.Bukkit
* org.bukkit.Material
* org.bukkit.entity.Player
* org.bukkit.event.Event$Result
* org.bukkit.event.EventHandler
* org.bukkit.event.EventPriority
* org.bukkit.event.Listener
* org.bukkit.event.inventory.ClickType
* org.bukkit.event.inventory.InventoryClickEvent
* org.bukkit.event.inventory.InventoryCloseEvent
* org.bukkit.event.inventory.InventoryDragEvent
* org.bukkit.inventory.Inventory
* org.bukkit.inventory.ItemStack
* org.bukkit.plugin.Plugin
* org.bukkit.scheduler.BukkitRunnable
*/
package me.recolance.auction.menu;
import me.recolance.auction.Auction;
import me.recolance.auction.auction.Listing;
import me.recolance.auction.auction.UnclaimedListing;
import me.recolance.auction.controller.Controller;
import me.recolance.auction.data.DataHolder;
import me.recolance.auction.menu.bidmenus.BidMenu;
import me.recolance.auction.menu.categories.CategoryMainMenu;
import me.recolance.auction.util.Util;
import net.crankedpvp.crankedutils.utils.CC;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
public class MenuController
implements Listener {
private static HashMap<UUID, Inventory> closeSecurity = new HashMap();
private static HashMap<UUID, Long> timer = new HashMap();
private static Economy economy = Auction.economy;
@EventHandler(priority = EventPriority.LOWEST)
public void onClick(InventoryClickEvent event) {
ItemStack item;
Player player = (Player) event.getWhoClicked();
Inventory inventory = event.getInventory();
if (closeSecurity.containsKey(player.getUniqueId()) && closeSecurity.get(player.getUniqueId()) == inventory) {
event.setCancelled(true);
return;
}
if (!MenuHelper.isViewing(player)) {
return;
}
if (!timer.containsKey(player.getUniqueId())) {
timer.put(player.getUniqueId(), System.currentTimeMillis());
} else if (System.currentTimeMillis() - timer.get(player.getUniqueId()) < 350L) {
event.setCancelled(true);
return;
}
timer.put(player.getUniqueId(), System.currentTimeMillis());
if (event.getCurrentItem() != null && !event.getClickedInventory().equals((Object) player.getOpenInventory().getTopInventory())) {
event.setCancelled(true);
event.setResult(Event.Result.DENY);
Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin) Auction.getPlugin(), ((Player) player)::closeInventory, 1L);
Util.message(player, "&e&l(!) &eTo list an item for sale on the &6/ah&e use &6/ah sell <price>&e, to list an item up for auction use &6/ah startbid&e.");
return;
}
int slot = event.getRawSlot();
if (MenuUtil.isCancellableClick(inventory, slot, event.getClick())) {
event.setCancelled(true);
event.setResult(Event.Result.DENY);
player.updateInventory();
}
if ((item = event.getCurrentItem()) == null || item.getType() == Material.AIR) {
return;
}
switch (MenuHelper.getViewing(player)) {
case AUCTION: {
if (slot < 45 && slot >= 0) {
List<Listing> vL = MenuHelper.getViewingListings(player);
if (vL == null) {
Bukkit.getLogger().info("[AuctionHouse] Player " + player.getName() + " has a null vL object, closing inventory.");
player.closeInventory();
return;
}
Listing l = vL.get(slot);
if (event.getClick() == ClickType.SHIFT_RIGHT && player.hasPermission("auction.admin.expire")) {
Controller.adminCancel(player, l);
MenuRenderer.renderAuctionPage(MenuHelper.getViewingPage(player), inventory, player);
break;
}
if (!DataHolder.getListings().contains(l)) {
MenuUtil.displayMenuInvalidity(slot, inventory, item, "This item is no longer available.");
break;
}
if (l.getWhoListed().equals(player.getUniqueId())) {
MenuUtil.displayMenuInvalidity(slot, inventory, item, "To cancel your auction, click the diamond.");
break;
}
if (!Util.hasInventorySpace(player)) {
MenuUtil.displayMenuInvalidity(slot, inventory, item, "You do not have enough inventory space!");
break;
}
if (!economy.has(Bukkit.getOfflinePlayer((UUID) player.getUniqueId()), (double) l.getPrice())) {
MenuUtil.displayMenuInvalidity(slot, inventory, item, "You cannot afford this item.");
break;
}
player.closeInventory();
Bukkit.getScheduler().runTaskLater((Plugin) Auction.getPlugin(), () -> MenuRenderer.purchaseConfirmation(player, l), 1L);
break;
}
if (slot == 45) {
player.closeInventory();
MenuRenderer.selling(player);
break;
}
if (slot == 46) {
player.closeInventory();
MenuRenderer.expired(player);
break;
}
if (slot == 47) {
if (item.getType() == Material.ENDER_CHEST) {
Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin) Auction.getPlugin(), () -> {
player.closeInventory();
player.performCommand("ah collect");
}, 1L);
break;
}
if (item.getType() != Material.BOOK_AND_QUILL) break;
Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin) Auction.getPlugin(), () -> {
player.closeInventory();
Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin) Auction.getPlugin(), () -> new BidMenu(player).openGUI(Auction.getPlugin()), 1L);
}, 1L);
break;
}
if (slot == 48 && MenuHelper.getViewingListings(player).size() != 0) {
MenuRenderer.renderAuctionPage(MenuHelper.getViewingPage(player) - 1, inventory, player);
break;
}
if (slot == 49) {
int page = MenuHelper.getViewingPage(player);
if (page == -1) break;
MenuRenderer.renderAuctionPage(page, inventory, player);
MenuUtil.displayMenuInfo(slot, inventory, item, "All auctions have been refreshed.");
break;
}
if (slot == 50) {
MenuRenderer.renderAuctionPage(MenuHelper.getViewingPage(player) + 1, inventory, player);
break;
}
if (slot != 51) break;
Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin) Auction.getPlugin(), () -> {
player.closeInventory();
Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin) Auction.getPlugin(), () -> new CategoryMainMenu(player).openGUI(Auction.getPlugin()), 1L);
}, 1L);
break;
}
case PURCHASE_CONFIRMATION: {
boolean viewingCategories = player.hasMetadata("category_view");
if (slot < 4) {
Listing l = MenuHelper.getPurchasing(player);
if (!DataHolder.getListings().contains(l)) {
if (viewingCategories) {
player.closeInventory();
player.sendMessage(CC.RedB + "(!) " + CC.Red + "Item is no longer available!");
Bukkit.getScheduler().runTaskLater((Plugin) Auction.getPlugin(), () -> new CategoryMainMenu(player).openGUI(Auction.getPlugin()), 1L);
return;
}
MenuUtil.displayMenuInvalidity(slot, inventory, item, "This item is no longer available.");
break;
}
if (l.getWhoListed().equals(player.getUniqueId())) {
MenuUtil.displayMenuInvalidity(slot, inventory, item, "To cancel your auction, click the diamond.");
break;
}
if (!Util.hasInventorySpace(player)) {
if (viewingCategories) {
player.closeInventory();
player.sendMessage(CC.RedB + "(!) " + CC.Red + "You dont have enough inventory space to purchase that item!");
Bukkit.getScheduler().runTaskLater((Plugin) Auction.getPlugin(), () -> new CategoryMainMenu(player).openGUI(Auction.getPlugin()), 1L);
return;
}
MenuUtil.displayMenuInvalidity(slot, inventory, item, "You do not have enough inventory space!");
break;
}
if (!economy.has(Bukkit.getOfflinePlayer((UUID) player.getUniqueId()), (double) l.getPrice())) {
if (viewingCategories) {
player.closeInventory();
player.sendMessage(CC.RedB + "(!) " + CC.Red + "You cannot afford this item.");
Bukkit.getScheduler().runTaskLater((Plugin) Auction.getPlugin(), () -> new CategoryMainMenu(player).openGUI(Auction.getPlugin()), 1L);
return;
}
MenuUtil.displayMenuInvalidity(slot, inventory, item, "You cannot afford this item.");
break;
}
Controller.purchase(player, l);
player.closeInventory();
MenuRenderer.openAuction(player);
break;
}
if (slot <= 4 || slot >= 9) break;
player.closeInventory();
if (viewingCategories) {
Bukkit.getScheduler().runTaskLater((Plugin) Auction.getPlugin(), () -> new CategoryMainMenu(player).openGUI(Auction.getPlugin()), 1L);
return;
}
MenuRenderer.openAuction(player);
break;
}
case SELLING: {
if (slot < 45) {
List<Listing> listings = MenuHelper.getViewingListings(player);
Listing listing = listings.get(slot);
if (!DataHolder.getListings().contains(listing)) {
MenuUtil.displayMenuInvalidity(slot, inventory, item, "This item is no longer available.");
break;
}
Controller.cancel(player, listing);
MenuRenderer.renderSelling(player, inventory);
break;
}
if (slot != 45) break;
player.closeInventory();
MenuRenderer.openAuction(player);
break;
}
case EXPIRED: {
if (slot < 45) {
List<UnclaimedListing> listings = MenuHelper.getUnclaimedViewing(player);
UnclaimedListing listing = listings.get(slot);
if (!DataHolder.getUnclaimedListings().containsKey(player.getUniqueId()) || !DataHolder.getUnclaimedListings().get(player.getUniqueId()).contains(listing)) {
MenuUtil.displayMenuInvalidity(slot, inventory, item, "This Item No Longer Exists");
break;
}
if (!Util.hasInventorySpace(player)) {
MenuUtil.displayMenuInvalidity(slot, inventory, item, "You do not have enough inventory space!");
break;
}
Controller.claim(player, listing);
MenuRenderer.renderExpired(1, inventory, player);
break;
}
if (slot == 45) {
player.closeInventory();
MenuRenderer.openAuction(player);
break;
}
if (slot == 48) {
MenuRenderer.renderExpired(MenuHelper.getViewingPage(player) - 1, inventory, player);
break;
}
if (slot == 49) {
if (!DataHolder.getUnclaimedListings().containsKey(player.getUniqueId())) {
MenuUtil.displayMenuInvalidity(slot, inventory, item, "Your Collection Bin is empty!");
break;
}
if (!Util.hasInventorySpace(player)) {
MenuUtil.displayMenuInvalidity(slot, inventory, item, "You do not have enough inventory space!");
break;
}
Controller.claimAll(player);
MenuRenderer.renderExpired(1, inventory, player);
break;
}
if (slot != 50) break;
MenuRenderer.renderExpired(MenuHelper.getViewingPage(player) + 1, inventory, player);
}
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onClose(InventoryCloseEvent event) {
final Player player = (Player) event.getPlayer();
if (!MenuHelper.isViewing(player)) {
return;
}
switch (MenuHelper.getViewing(player)) {
case AUCTION: {
MenuHelper.removeViewingListings(player);
MenuHelper.removeViewingPage(player);
break;
}
case PURCHASE_CONFIRMATION: {
MenuHelper.removePurchasing(player);
break;
}
case SELLING: {
MenuHelper.removeViewingListings(player);
break;
}
case EXPIRED: {
MenuHelper.removeViewingPage(player);
MenuHelper.removeViewingUnclaimed(player);
}
}
MenuHelper.removeViewing(player);
closeSecurity.put(player.getUniqueId(), event.getInventory());
new BukkitRunnable() {
public void run() {
closeSecurity.remove(player.getUniqueId());
}
}.runTaskLater((Plugin) Auction.plugin, 2L);
}
@EventHandler(priority = EventPriority.LOWEST)
public void onDrag(InventoryDragEvent event) {
Player player = (Player) event.getWhoClicked();
if (!MenuHelper.isViewing(player)) {
return;
}
Inventory inventory = event.getInventory();
Iterator iterator = event.getRawSlots().iterator();
while (iterator.hasNext()) {
int slot = (Integer) iterator.next();
if (slot >= inventory.getSize()) continue;
event.setCancelled(true);
break;
}
}
}
@@ -0,0 +1,96 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* org.bukkit.entity.Player
* org.bukkit.plugin.Plugin
*/
package me.recolance.auction.menu;
import me.recolance.auction.Auction;
import me.recolance.auction.auction.Listing;
import me.recolance.auction.auction.UnclaimedListing;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
public class MenuHelper {
public static HashMap<Player, Integer> viewingPage = new HashMap();
public static HashMap<Player, List<Listing>> viewingListings = new HashMap();
public static HashMap<Player, Listing> purchasing = new HashMap();
public static HashMap<Player, List<UnclaimedListing>> viewingUnclaimed = new HashMap();
private static final HashMap<UUID, MenuType> currentlyViewing = new HashMap();
public static boolean isViewing(Player player) {
return currentlyViewing.containsKey(player.getUniqueId());
}
public static MenuType getViewing(Player player) {
return currentlyViewing.get(player.getUniqueId());
}
public static void setViewing(Player player, MenuType menuType) {
currentlyViewing.put(player.getUniqueId(), menuType);
}
public static void removeViewing(Player player) {
currentlyViewing.remove(player.getUniqueId());
}
public static int getViewingPage(Player player) {
if (!viewingPage.containsKey(player)) {
player.closeInventory();
return -1;
}
return viewingPage.get(player);
}
public static void setViewingPage(Player player, int page) {
viewingPage.put(player, page);
}
public static void removeViewingPage(Player player) {
viewingPage.remove(player);
}
public static List<Listing> getViewingListings(Player player) {
return viewingListings.get(player);
}
public static void setViewingListings(Player player, List<Listing> list) {
viewingListings.put(player, list);
}
public static void removeViewingListings(Player player) {
viewingListings.remove(player);
}
public static Listing getPurchasing(Player player) {
return purchasing.get(player);
}
public static void setPurchasing(Player player, Listing list) {
purchasing.put(player, list);
}
public static void removePurchasing(Player player) {
purchasing.remove(player);
player.removeMetadata("category_view", Auction.getPlugin());
}
public static List<UnclaimedListing> getUnclaimedViewing(Player player) {
return viewingUnclaimed.get(player);
}
public static void setViewingUnclaimed(Player player, List<UnclaimedListing> list) {
viewingUnclaimed.put(player, list);
}
public static void removeViewingUnclaimed(Player player) {
viewingUnclaimed.remove(player);
}
}
@@ -0,0 +1,308 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.CC
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.ItemBuilder
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.NumberUtils
* com.google.common.collect.Lists
* org.bukkit.Bukkit
* org.bukkit.ChatColor
* org.bukkit.Material
* org.bukkit.Sound
* org.bukkit.entity.Player
* org.bukkit.inventory.Inventory
* org.bukkit.inventory.ItemStack
* org.bukkit.metadata.FixedMetadataValue
* org.bukkit.metadata.MetadataValue
* org.bukkit.plugin.Plugin
*/
package me.recolance.auction.menu;
import com.google.common.collect.Lists;
import me.recolance.auction.Auction;
import me.recolance.auction.auction.Listing;
import me.recolance.auction.auction.UnclaimedListing;
import me.recolance.auction.controller.Controller;
import me.recolance.auction.data.DataHolder;
import me.recolance.auction.util.AuctionUtil;
import me.recolance.auction.util.Item;
import me.recolance.auction.util.Util;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.NumberUtils;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import java.util.*;
public class MenuRenderer {
private static Plugin plugin = Auction.plugin;
private static MenuButton pP;
private static MenuButton rP;
private static MenuButton nP;
private static MenuButton hTS;
private static MenuButton wITP;
private static String auctionInventoryName;
private static String itemsSellingName;
private static String expiredItemName;
private static List<String> itemsSellingLore;
private static List<String> expirationLore;
public static void loadMenuItems() {
auctionInventoryName = ChatColor.translateAlternateColorCodes((char) '&', (String) plugin.getConfig().getString("menuText.menuName"));
itemsSellingName = plugin.getConfig().getString("menuText.itemsYoureSelling.name");
itemsSellingLore = plugin.getConfig().getStringList("menuText.itemsYoureSelling.lore");
expiredItemName = plugin.getConfig().getString("menuText.collectExpired.name");
expirationLore = plugin.getConfig().getStringList("menuText.collectExpired.lore");
String pPN = plugin.getConfig().getString("menuText.previous.name");
List<String> pPL = plugin.getConfig().getStringList("menuText.previous.lore");
pP = new MenuButton().type(Material.PAPER).name(pPN);
for (String lore : pPL) {
pP.lore(lore);
}
String rPN = plugin.getConfig().getString("menuText.refresh.name");
List<String> rPL = plugin.getConfig().getStringList("menuText.refresh.lore");
rP = new MenuButton().type(Material.CHEST).name(rPN);
for (String lore : rPL) {
rP.lore(lore);
}
String nPN = plugin.getConfig().getString("menuText.next.name");
List<String> nPL = plugin.getConfig().getStringList("menuText.next.lore");
nP = new MenuButton().type(Material.PAPER).name(nPN);
for (String lore : nPL) {
nP.lore(lore);
}
String hTSN = plugin.getConfig().getString("menuText.howToSell.name");
List<String> hTSL = plugin.getConfig().getStringList("menuText.howToSell.lore");
hTS = new MenuButton().type(Material.GOLD_INGOT).name(hTSN);
for (String lore : hTSL) {
hTS.lore(lore);
}
hTS.lore("", CC.Gray + "To list an item in a Bid Auction use", CC.Yellow + "/ah startbid <startPrice> <bidIncrement>", "", CC.Gray + "To toggle alerts when you are outbid", CC.Gray + "use " + CC.Yellow + "/ah aucnotify");
String wITPN = plugin.getConfig().getString("menuText.bookButton.name");
ArrayList<String> wITPL = Lists.newArrayList("&7This is the auction house, here you can", "&7list items for sale and purchase items", "&7that others have listed for sale.", "", "&7The auction is also a great way to make", "&7money by selling farmable items other", "&7players may be interested in buying.", "", "&7All sell listings last for a max of &e15 minutes", "&7unsold items are sent to your collection bin.", "", "&7You can also list items up for auction", "&7where players can outbid each other to", "&7be the highest bidder using &e/bids&7.", "", "&7For more help, use &e/ah help!");
wITP = new MenuButton().type(Material.BOOK).name(wITPN);
for (String lore : wITPL) {
wITP.lore(lore.replace("15 minute", "60 minute"));
}
}
public static void openAuction(Player player) {
if (pP == null) {
MenuRenderer.loadMenuItems();
}
Inventory inventory = Bukkit.createInventory(null, (int) 54, (String) auctionInventoryName);
MenuRenderer.renderAuctionPage(1, inventory, player);
MenuButton iYS = new MenuButton().type(Material.DIAMOND).name(itemsSellingName);
for (String string : itemsSellingLore) {
iYS.lore(string.replace("%selling%", String.valueOf(AuctionUtil.getCurrentlySellingAmount(player))));
}
MenuButton cEI = new MenuButton().type(Material.ENDER_CHEST).name(expiredItemName);
for (String lore : expirationLore) {
cEI.lore(lore.replace("%expired%", String.valueOf(AuctionUtil.getItemsToCollectAmount(player))));
}
inventory.setItem(45, iYS.get());
inventory.setItem(46, cEI.get());
BidManager bidManager = Auction.getPlugin().getBidManager();
List<ItemStack> claimMenu = bidManager.getBidCollectionBin().get(player.getUniqueId());
if (claimMenu != null && !claimMenu.isEmpty()) {
inventory.setItem(47, new ItemBuilder(Material.ENDER_CHEST).setName(CC.YellowB + "Bid Collection Bin").addLore(CC.Gray + "Click to view all items won from bid auctions", CC.Gray + "or expired bids you attempted to sell.", "", CC.YellowB + claimMenu.size() + " Item(s)").build());
} else {
inventory.setItem(47, new ItemBuilder(Material.BOOK_AND_QUILL).setName(CC.YellowB + "Auction Bids").addLore(CC.Gray + "Click here to view all current Auction Biddings!", "", CC.YellowB + bidManager.getActiveAuctionBids().size() + " Auction(s)").build());
}
inventory.setItem(48, pP.get());
inventory.setItem(49, rP.get());
inventory.setItem(50, nP.get());
inventory.setItem(51, new ItemBuilder(Material.STORAGE_MINECART, CC.YellowB + "Category View", CC.Gray + "Click to view all current", CC.Gray + "auction item categories!").build());
inventory.setItem(52, hTS.get());
inventory.setItem(53, wITP.get());
player.openInventory(inventory);
player.playSound(player.getLocation(), Sound.BAT_TAKEOFF, 1.0f, 2.4f);
MenuHelper.setViewing(player, MenuType.AUCTION);
}
public static void renderAuctionPage(int page, Inventory inventory, Player player) {
int sI;
int eI;
int displaying;
int lS;
List<Listing> listings = DataHolder.getListings();
if (page < 1) {
lS = listings.size();
page = lS / 45;
if (lS % 45 > 0) {
++page;
}
}
if ((displaying = (eI = (sI = (page - 1) * 45) + 44 >= (lS = listings.size()) ? lS - 1 : page * 45 - 1) - sI + 1) < 1 && page != 1) {
MenuRenderer.renderAuctionPage(1, inventory, player);
return;
}
int slot = 0;
for (int i = 0; i < 45; ++i) {
inventory.setItem(i, null);
}
ArrayList<Listing> vL = new ArrayList<Listing>();
for (int i = sI; i <= eI; ++i) {
Listing listing = listings.get(i);
inventory.setItem(slot, listing.getMenuDisplayItem());
++slot;
vL.add(listing);
}
MenuHelper.setViewingPage(player, page);
MenuHelper.setViewingListings(player, vL);
}
public static void purchaseConfirmation(Player player, Listing listing) {
MenuRenderer.purchaseConfirmation(player, listing, false);
}
public static void purchaseConfirmation(Player player, Listing listing, boolean categoryViewing) {
Inventory inventory = Bukkit.createInventory(null, (int) 9, (String) "Purchase Item: Are You Sure?");
ItemStack yes = new MenuButton().type(Material.STAINED_GLASS_PANE).durability(5).name("&a&lConfirm Purchase").lore("&7Click to confirm purchase.").get();
for (int i = 0; i < 4; ++i) {
inventory.setItem(i, yes);
}
ItemStack no = new MenuButton().type(Material.STAINED_GLASS_PANE).durability(14).name("&c&lCancel Purchase").lore("&7Click to cancel purchase.").get();
for (int i = 5; i < 9; ++i) {
inventory.setItem(i, no);
}
ItemStack item = new Item(new ItemStack(listing.getItem())).addLore("", "&6Price: &e$" + listing.getPrettyPrice(), "&6Seller: &e" + Bukkit.getOfflinePlayer((UUID) listing.getWhoListed()).getName()).get();
inventory.setItem(4, item);
player.openInventory(inventory);
MenuHelper.setPurchasing(player, listing);
MenuHelper.setViewing(player, MenuType.PURCHASE_CONFIRMATION);
if (categoryViewing) {
player.setMetadata("category_view", (MetadataValue) new FixedMetadataValue((Plugin) Auction.getPlugin(), (Object) ""));
}
}
public static void selling(Player player) {
Inventory inventory = Bukkit.createInventory(null, (int) 54, (String) "Your Current Listings");
MenuRenderer.renderSelling(player, inventory);
MenuButton back = new MenuButton().type(Material.CHEST).name("&e&lReturn to Auction House").lore("&7Click here to return to the", "&7auction house main menu.");
MenuButton wITP = new MenuButton().type(Material.BOOK).name("&e&lTutorial").lore("&7These are your current listings, all of", "&7the items you currently have listed on", "&7the auction house are displayed here.", "", "&7You can cancel and view your listing's", "&7expire time here.");
inventory.setItem(45, back.get());
inventory.setItem(53, wITP.get());
player.openInventory(inventory);
MenuHelper.setViewing(player, MenuType.SELLING);
}
public static void renderSelling(Player player, Inventory inventory) {
for (int i = 0; i < 45; ++i) {
inventory.setItem(i, null);
}
List<Listing> playerListings = DataHolder.getPlayerListings().get(player.getUniqueId());
if (playerListings == null || playerListings.isEmpty()) {
return;
}
if (playerListings.size() > 1) {
Collections.sort(playerListings, new Comparator<Listing>() {
@Override
public int compare(Listing l1, Listing l2) {
return Long.valueOf(l1.getEndTime()).compareTo(l2.getEndTime());
}
});
}
ArrayList<Listing> vL = new ArrayList<Listing>();
int slot = 0;
for (Listing listing : playerListings) {
String perData = listing.getExpInBottle() > 0 ? CC.Gray + " ($" + NumberUtils.formatMoney((double) listing.getExpPerDollar()) + " / xp)" : "";
double perItem = listing.getPricePerItem();
if (perItem != (double) listing.getPrice() && perItem > 0.0) {
perData = " ($" + NumberUtils.formatMoney((double) perItem) + " / item)";
}
ItemStack item = new Item(new ItemStack(listing.getItem())).addLore("&7-------------------------", "&c&lClick item to cancel auction.", "", "&6Price: &e$" + listing.getPrettyPrice() + perData, "&6Expire: &e" + Util.getRemainingTimeString(System.currentTimeMillis(), listing.getEndTime() - System.currentTimeMillis()), "&7-------------------------").get();
vL.add(listing);
inventory.setItem(slot, item);
++slot;
}
MenuHelper.setViewingListings(player, vL);
}
public static void expired(Player player) {
Inventory inventory = Bukkit.createInventory(null, (int) 54, (String) "Cancelled / Expired Listings");
MenuRenderer.renderExpired(1, inventory, player);
MenuButton back = new MenuButton().type(Material.CHEST).name("&e&lReturn to Auction House").lore("&7Click here to return to the", "&7auction house main menu.");
MenuButton previous = new MenuButton().type(Material.PAPER).name("&e&l<- Previous Page");
MenuButton all = new MenuButton().type(Material.ENDER_CHEST).name("&e&lClaim All").lore("&7Click here to claim all", "&7your Collection Bin items.");
MenuButton next = new MenuButton().type(Material.PAPER).name("&e&lNext Page ->");
MenuButton wITP = new MenuButton().type(Material.BOOK).name("&e&lTutorial").lore("&7This page houses all of your cancelled and", "&7expired items, when a listings is cancelled", "&7or expires you will be able to return that", "&7item back to you from this menu.", "", "&7Just click on the item and if you have enough", "&7inventory space you will recieve the item.");
inventory.setItem(45, back.get());
inventory.setItem(48, previous.get());
inventory.setItem(49, all.get());
inventory.setItem(50, next.get());
inventory.setItem(53, wITP.get());
player.openInventory(inventory);
MenuHelper.setViewing(player, MenuType.EXPIRED);
}
public static void renderExpired(int page, Inventory inventory, Player player) {
int sI;
int eI;
int displaying;
int lS;
List<UnclaimedListing> listings = DataHolder.getUnclaimedListings().get(player.getUniqueId());
if (listings == null) {
listings = new ArrayList<UnclaimedListing>();
}
for (int i = 0; i < 45; ++i) {
inventory.setItem(i, null);
}
if (page < 1) {
lS = listings.size();
page = lS / 45;
if (lS % 45 > 0) {
++page;
}
}
MenuHelper.setViewingPage(player, page);
if (listings.isEmpty()) {
return;
}
if (listings.size() > 1) {
Collections.sort(listings, new Comparator<UnclaimedListing>() {
@Override
public int compare(UnclaimedListing l1, UnclaimedListing l2) {
return Long.valueOf(l1.getExpireTime()).compareTo(l2.getExpireTime());
}
});
Collections.reverse(listings);
}
if ((displaying = (eI = (sI = (page - 1) * 45) + 44 >= (lS = listings.size()) ? lS - 1 : page * 45 - 1) - sI + 1) < 1 && page != 1) {
MenuRenderer.renderExpired(1, inventory, player);
return;
}
ArrayList<UnclaimedListing> vL = new ArrayList<UnclaimedListing>();
ArrayList<UnclaimedListing> rL = new ArrayList<UnclaimedListing>();
int slot = 0;
for (int i = sI; i <= eI; ++i) {
UnclaimedListing listing = listings.get(i);
if (listing.getExpireTime() < System.currentTimeMillis()) {
rL.add(listing);
continue;
}
ItemStack item = new Item(new ItemStack(listing.getItem())).addLore("&7-------------------------", "&e&lClick here to claim item.", "", "&6Item Deletion: &e" + Util.getRemainingTimeString(System.currentTimeMillis(), listing.getExpireTime() - System.currentTimeMillis()), "&7-------------------------").get();
inventory.setItem(slot, item);
++slot;
vL.add(listing);
}
for (UnclaimedListing l : rL) {
Controller.expireUnclaimed(l);
}
MenuHelper.setViewingUnclaimed(player, vL);
}
}
@@ -0,0 +1,13 @@
/*
* Decompiled with CFR 0.150.
*/
package me.recolance.auction.menu;
public enum MenuType {
AUCTION,
PURCHASE_CONFIRMATION,
SELLING,
EXPIRED;
}
@@ -0,0 +1,65 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* org.bukkit.Material
* org.bukkit.event.me.astropvp.cratekeys.inventory.ClickType
* org.bukkit.me.astropvp.cratekeys.inventory.Inventory
* org.bukkit.me.astropvp.cratekeys.inventory.ItemStack
* org.bukkit.plugin.Plugin
* org.bukkit.scheduler.BukkitRunnable
*/
package me.recolance.auction.menu;
import me.recolance.auction.Auction;
import me.recolance.auction.util.Util;
import org.bukkit.Material;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
public class MenuUtil {
public static boolean isCancellableClick(Inventory inventory, int slot, ClickType click) {
if (slot < inventory.getSize()) {
return true;
}
return click != ClickType.LEFT && click != ClickType.RIGHT;
}
public static void displayMenuInvalidity(final int slot, final Inventory inventory, final ItemStack originalItem, String message) {
message = Util.setStringColors(message);
if (originalItem.getType() == Material.STAINED_GLASS_PANE) {
return;
}
inventory.setItem(slot, new MenuButton().type(Material.STAINED_GLASS_PANE).durability(14).name("&c" + message).get());
new BukkitRunnable() {
public void run() {
ItemStack item = inventory.getItem(slot);
if (item != null && inventory.getItem(slot).getType() == Material.STAINED_GLASS_PANE) {
inventory.setItem(slot, originalItem);
}
}
}.runTaskLater((Plugin) Auction.plugin, 20L);
}
public static void displayMenuInfo(final int slot, final Inventory inventory, final ItemStack originalItem, String message) {
message = Util.setStringColors(message);
if (originalItem.getType() == Material.STAINED_GLASS_PANE) {
return;
}
inventory.setItem(slot, new MenuButton().type(Material.STAINED_GLASS_PANE).durability(4).name("&e" + message).get());
new BukkitRunnable() {
public void run() {
ItemStack item = inventory.getItem(slot);
if (item != null && inventory.getItem(slot).getType() == Material.STAINED_GLASS_PANE) {
inventory.setItem(slot, originalItem);
}
}
}.runTaskLater((Plugin) Auction.plugin, 20L);
}
}
@@ -0,0 +1,36 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.gui.CosmicGUI
* com.cosmicpvp.cosmicutils.me.astropvp.cratekeys.net.astropvp.armorsets.utils.CC
* org.bukkit.entity.Player
*/
package me.recolance.auction.menu.bidmenus;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.cosmicgui.CosmicGUI;
import org.bukkit.entity.Player;
public abstract class AuctionGUI
extends CosmicGUI {
private long lastClicked;
public AuctionGUI(Player player, String title, int size) {
super(player, title, size);
}
public boolean canClick() {
if (this.lastClicked <= System.currentTimeMillis()) {
return true;
}
this.player.sendMessage(CC.RedB + "(!) " + CC.Red + "Please wait before clicking again!");
return false;
}
public void click() {
this.lastClicked = System.currentTimeMillis() + 500L;
}
}
@@ -0,0 +1,232 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* com.cosmicpvp.cosmicutils.compat.ASound
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.gui.InventoryItem
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.CC
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.ItemBuilder
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.PlayerUtil
* com.google.common.collect.Lists
* net.minecraft.util.org.apache.commons.lang3.tuple.ImmutablePair
* net.minecraft.util.org.apache.commons.lang3.tuple.Pair
* org.bukkit.Bukkit
* org.bukkit.ChatColor
* org.bukkit.DyeColor
* org.bukkit.Material
* org.bukkit.Sound
* org.bukkit.entity.Player
* org.bukkit.event.inventory.ClickType
* org.bukkit.event.inventory.InventoryClickEvent
* org.bukkit.inventory.ItemStack
*/
package me.recolance.auction.menu.bidmenus;
import com.google.common.collect.Lists;
import me.recolance.auction.command.CommandHandler;
import me.recolance.auction.util.ItemUtils;
import me.recolance.auction.util.Util;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.PlayerUtils;
import net.crankedpvp.crankedutils.utils.SoundUtils;
import net.crankedpvp.crankedutils.utils.cosmicgui.InventoryItem;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
public class AuctionPackageMenu
extends AuctionGUI {
public long bidLength5 = TimeUnit.MINUTES.toSeconds(5L);
public long bidLength10 = TimeUnit.MINUTES.toSeconds(10L);
public long bidLength15 = TimeUnit.MINUTES.toSeconds(15L);
public long bidLength30 = TimeUnit.MINUTES.toSeconds(30L);
public int bidLength = (int) TimeUnit.MINUTES.toSeconds(15L);
private List<ItemStack> toReturn = Lists.newArrayList();
private long startingBid;
private long maxBid;
private long buyoutPrice;
private Consumer<Pair<List<ItemStack>, Integer>> callback;
private boolean confirmed = false;
public AuctionPackageMenu(Player player, long startingBid, long incrementAmount, long buyoutPrice, ItemStack selling, Consumer<Pair<List<ItemStack>, Integer>> successCallback) {
super(player, "Enter Auction Package Items", 54);
this.startingBid = startingBid;
this.maxBid = incrementAmount;
this.buyoutPrice = buyoutPrice;
this.callback = successCallback;
if (selling != null && selling.getType() != Material.AIR && CommandHandler.canSellItem(selling)) {
player.getInventory().removeItem(new ItemStack[]{selling});
this.toReturn.add(selling);
}
}
public void onInventoryClose() {
super.onInventoryClose();
if (!this.confirmed) {
this.player.sendMessage(CC.Red + "Auction bid " + CC.RedB + "CANCELLED");
if (this.toReturn.isEmpty()) {
this.confirmed = true;
return;
}
this.player.sendMessage(CC.Gray + "Your items have been returned to you.");
this.confirmed = true;
for (ItemStack retr : this.toReturn) {
PlayerUtils.giveOrDropProtectedItem((Player) this.player, (ItemStack) retr, (int) 60);
}
this.toReturn.clear();
}
}
public void redraw() {
this.inventory.clear();
this.getInventoryItems().clear();
int slot = 0;
for (ItemStack itemStack : this.toReturn) {
ItemStack clone = itemStack.clone();
this.setItem(slot++, new InventoryItem(new ItemBuilder(clone).build()).click(() -> {
if (!this.toReturn.remove((Object) itemStack)) {
this.redraw();
Bukkit.getLogger().info("Didnt find item in toReturn: " + (Object) itemStack + " for " + this.player.getName());
return;
}
PlayerUtils.giveOrDropProtectedItem((Player) this.player, (ItemStack) itemStack, (int) 60);
this.player.playSound(this.player.getLocation(), Sound.LAVA_POP, 1.0f, 1.4f);
this.redraw();
}));
}
ArrayList lore = Lists.newArrayList( new String[]{"", CC.Gray + "Confirm to auction " + CC.GrayB + this.toReturn.size() + "x" + CC.Gray + " Items:"});
for (ItemStack item3 : this.toReturn) {
lore.add(CC.GoldB + "* " + CC.White + Util.getItemName(item3));
}
lore.add("");
lore.add(CC.Gold + "Starting Bid: " + CC.GreenB + "$" + CC.Green + Util.formatMoney(this.startingBid));
lore.add(CC.Gold + "Bid Increments: " + CC.GreenB + "$" + CC.Green + Util.formatMoney(this.maxBid));
if (this.buyoutPrice > 1L) {
lore.add(CC.Gold + "Buy Now Price: " + CC.GreenB + "$" + CC.Green + Util.formatMoney(this.buyoutPrice));
}
lore.add("");
lore.add(CC.RedB + "NOTE: " + CC.Red + "You cannot cancel this");
lore.add(CC.Red + "auction once it has started!");
InventoryItem inventoryItem = new InventoryItem(new ItemBuilder(Material.STAINED_GLASS_PANE).setDurability((short) DyeColor.LIME.getWoolData()).setName(CC.GreenB + "Confirm Auction").addLore((List) lore).build()).click(() -> {
if (this.toReturn.isEmpty()) {
this.player.sendMessage(CC.RedB + "(!) " + CC.Red + "You must provide at least 1 item to auction!");
return;
}
if (this.confirmed) {
this.player.sendMessage(CC.RedB + "(!) " + CC.Red + "Package already confirmed!");
return;
}
if (!this.canClick()) {
return;
}
this.click();
this.confirmed = true;
this.callback.accept((Pair<List<ItemStack>, Integer>) new ImmutablePair(this.toReturn, (Object) this.bidLength));
});
for (int index = this.size - 9; index < this.size; ++index) {
if (index < this.size - 5) {
this.setItem(index, inventoryItem);
continue;
}
this.setItem(index, new InventoryItem(new ItemBuilder(Material.STAINED_GLASS_PANE).setDurability((short) DyeColor.RED.getWoolData()).setName(CC.RedB + "Cancel Auction").addLore("", CC.Gray + "Click to cancel this auction.").build()).click(() -> {
if (this.confirmed) {
return;
}
Util.closePlayerInventoryOnClick(this.player);
}));
}
if (!this.toReturn.isEmpty()) {
ItemStack sellingItem = this.toReturn.get(0);
this.setItem(this.size - 5, new InventoryItem(sellingItem));
}
for (int i = this.size - 18; i < this.size - 9; ++i) {
this.setItem(i, new InventoryItem(new ItemBuilder(Material.STAINED_GLASS_PANE).setDurability((short) DyeColor.GRAY.getWoolData()).setName(" ").build()));
}
boolean min = (long) this.bidLength == this.bidLength5;
boolean min2 = (long) this.bidLength == this.bidLength10;
boolean min5 = (long) this.bidLength == this.bidLength15;
boolean min30 = (long) this.bidLength == this.bidLength30;
boolean maxRank = this.player.hasPermission("enchantments.max.20");
int slots = this.size - (maxRank ? 16 : 15);
this.setItem(slots, new InventoryItem(ItemUtils.setFakeEnchantment(new ItemBuilder(Material.WATCH).setName(CC.GreenB + "5 Minute Duration").addLore("", CC.Gray + "Click to set auction bid duration!").build(), min)).click(() -> {
if (!this.canClick()) {
return;
}
this.bidLength = (int) this.bidLength5;
this.click();
this.redraw();
}));
this.setItem(++slots, new InventoryItem(ItemUtils.setFakeEnchantment(new ItemBuilder(Material.WATCH).setName(CC.GreenB + "10 Minute Duration").addLore("", CC.Gray + "Click to set auction bid duration!").build(), min2)).click(() -> {
if (!this.canClick()) {
return;
}
this.bidLength = (int) this.bidLength10;
this.click();
this.redraw();
}));
if (maxRank) {
++slots;
}
this.setItem(++slots, new InventoryItem(ItemUtils.setFakeEnchantment(new ItemBuilder(Material.WATCH).setName(CC.GreenB + "15 Minute Duration").addLore("", CC.Gray + "Click to set auction bid duration!").build(), min5)).click(() -> {
if (!this.canClick()) {
return;
}
this.bidLength = (int) this.bidLength15;
this.click();
this.redraw();
}));
if (maxRank) {
this.setItem(++slots, new InventoryItem(ItemUtils.setFakeEnchantment(new ItemBuilder(Material.WATCH).setName(CC.GreenB + "30 Minute Duration").addLore("", CC.Gray + "Click to set auction bid duration!").build(), min30)).click(() -> {
if (!this.canClick()) {
return;
}
this.bidLength = (int) this.bidLength30;
this.click();
this.redraw();
}));
}
}
public void onUnknownItemClick(InventoryClickEvent event) {
event.setCancelled(true);
if (event.getClick() != ClickType.LEFT && event.getClick() != ClickType.RIGHT) {
return;
}
if (!this.canClick()) {
return;
}
this.click();
if (event.getRawSlot() >= event.getInventory().getSize()) {
ItemStack item = event.getCurrentItem();
if (item == null || event.getCurrentItem().getType() == Material.AIR) {
return;
}
if (!CommandHandler.canSellItem(item)) {
this.player.sendMessage(CC.Red + "You cannot sell this item.");
return;
}
if (this.toReturn.size() >= 5) {
this.player.sendMessage((Object) ChatColor.RED + "You can only sell up to 5 items in a single Auction Package!");
return;
}
event.getClickedInventory().setItem(event.getSlot(), null);
this.toReturn.add(item);
this.player.sendMessage(CC.GreenB + "(!) " + CC.Green + "Item added into Auction Package!");
this.player.playSound(this.player.getLocation(), Sound.ORB_PICKUP, 1.4f, 1.4f);
this.redraw();
}
}
}
@@ -0,0 +1,83 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.gui.CosmicGUI
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.gui.InventoryItem
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.CC
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.InventoryUtils
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.ItemBuilder
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.PlayerUtil
* org.arkhamnetwork.Arkkit.patches.ItemID
* org.arkhamnetwork.Arkkit.plugins.ArkPlugins
* org.bukkit.Bukkit
* org.bukkit.ChatColor
* org.bukkit.Material
* org.bukkit.entity.Player
* org.bukkit.inventory.ItemStack
*/
package me.recolance.auction.menu.bidmenus;
import me.recolance.auction.Auction;
import me.recolance.auction.menu.BidManager;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.InventoryUtils;
import net.crankedpvp.crankedutils.utils.PlayerUtils;
import net.crankedpvp.crankedutils.utils.cosmicgui.CosmicGUI;
import net.crankedpvp.crankedutils.utils.cosmicgui.InventoryItem;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.List;
public class BidCollectionBinMenu
extends CosmicGUI {
public BidCollectionBinMenu(Player player, List<ItemStack> bin) {
super(player, "Auction Bid Collection", InventoryUtils.fitSize((int) (bin != null ? bin.size() + 1 : 9)));
}
public void redraw() {
BidManager bidManager = Auction.getPlugin().getBidManager();
List<ItemStack> binItems = bidManager.getBidCollectionBin().get(this.player.getUniqueId());
this.inventory.clear();
this.getInventoryItems().clear();
if (binItems != null && !binItems.isEmpty()) {
int slot = 0;
for (ItemStack toClaim : binItems) {
if (slot >= this.size) break;
this.setItem(slot++, new InventoryItem(toClaim).click(() -> {
if (!binItems.contains((Object) toClaim)) {
this.redraw();
return;
}
if (this.player.getInventory().firstEmpty() == -1) {
this.player.sendMessage((Object) ChatColor.RED + "You do not have the inventory space for this item!");
return;
}
binItems.remove((Object) toClaim);
if (binItems.isEmpty()) {
bidManager.getBidCollectionBin().remove(this.player.getUniqueId());
}
PlayerUtils.giveOrDropProtectedItem((Player) this.player, (ItemStack) toClaim, (int) -1);
if (binItems.isEmpty()) {
new BidMenu(this.player).openGUI(Auction.getPlugin());
return;
}
this.redraw();
}));
}
}
this.setItem(this.size - 1, new InventoryItem(new ItemBuilder(Material.ARROW).setName(CC.GreenB + "Return to Auction Page").addLore(new String[]{CC.Gray + "Click here to return to the", CC.Gray + "auction house main menu."}).build()).click(() -> {
this.player.closeInventory();
this.player.performCommand("ah");
}));
}
}
@@ -0,0 +1,153 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.gui.InventoryItem
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.CC
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.ItemBuilder
* com.google.common.collect.Lists
* net.minecraft.util.io.netty.util.internal.ConcurrentSet
* org.bukkit.Bukkit
* org.bukkit.ChatColor
* org.bukkit.Material
* org.bukkit.OfflinePlayer
* org.bukkit.Sound
* org.bukkit.entity.Player
* org.bukkit.event.inventory.ClickType
* org.bukkit.plugin.Plugin
*/
package me.recolance.auction.menu.bidmenus;
import com.google.common.collect.Lists;
import io.netty.util.internal.ConcurrentSet;
import me.recolance.auction.Auction;
import me.recolance.auction.data.AuctionBid;
import me.recolance.auction.menu.BidManager;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.cosmicgui.InventoryItem;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
public class BidMenu
extends BiddableMenu {
int page = 1;
private long lastUpdate = 0L;
private boolean forceUpdate = false;
public BidMenu(Player player) {
super(player, "Active Bids", 54);
}
@Override
public String getTitle() {
return this.title;
}
@Override
public Player getPlayer() {
return this.player;
}
public void redraw() {
int startIndex;
if (System.currentTimeMillis() - this.lastUpdate <= 500L && !this.forceUpdate) {
return;
}
this.forceUpdate = false;
BidManager bidManager = Auction.getPlugin().getBidManager();
ArrayList<Map.Entry<UUID, AuctionBid>> bidEntries = Lists.newArrayList(bidManager.getActiveAuctionBids().entrySet()); // HELP
bidEntries.sort((o1, o2) -> {
int secondsLeft2;
int secondsLeft1 = o1.getValue().getSecondsLeftInAuction();
if (secondsLeft1 > (secondsLeft2 = o2.getValue().getSecondsLeftInAuction())) {
return -1;
}
if (secondsLeft2 == secondsLeft1) {
return 0;
}
return 1;
});
double perPage = 45.0;
int maxPages = Math.max(1, (int) Math.ceil((double) bidEntries.size() / perPage));
if (this.page < 1) {
this.page = 1;
}
if (this.page > maxPages) {
this.page = maxPages;
}
this.inventory.clear();
this.getInventoryItems().clear();
this.lastUpdate = System.currentTimeMillis();
AtomicInteger slot = new AtomicInteger(0);
for (int i = startIndex = (int) ((double) this.page * perPage - perPage); (double) i < (double) startIndex + perPage && i < bidEntries.size(); ++i) {
Map.Entry entry = bidEntries.get(i);
AuctionBid auctionBid = (AuctionBid) entry.getValue();
if (slot.get() >= this.size) break;
if (auctionBid.isExpired()) continue;
this.setItem(slot.getAndIncrement(), new InventoryItem(new ItemBuilder(auctionBid.getAuctionDisplayItem(true)).build()).click(ClickType.LEFT, auctionBid.getLeftClickLogic(this, this.player)).click(ClickType.RIGHT, auctionBid.getRightClickLogic(this, this.player)).click(ClickType.MIDDLE, auctionBid.getMiddleClickLogic(this, this.player)).click(ClickType.SHIFT_LEFT, auctionBid.getShiftLeftClickLogic(this, this.player)).click(ClickType.SHIFT_RIGHT, () -> {
Set watching = Auction.getPlugin().getBidManager().getWatchlists().computeIfAbsent(this.player.getUniqueId(), list -> new ConcurrentSet());
if (watching.contains(auctionBid.getBidID())) {
watching.remove(auctionBid.getBidID());
this.player.sendMessage(CC.RedB + "(!) " + CC.Red + "Item removed from watchlist!");
if (watching.isEmpty()) {
Auction.getPlugin().getBidManager().getWatchlists().remove(this.player.getUniqueId());
}
return;
}
if (watching.size() >= 40) {
this.player.sendMessage(CC.RedB + "Your watch list is currently full!");
this.player.sendMessage(CC.Gray + "Visit the watchlist tab to remove expired bids!");
return;
}
this.player.sendMessage(CC.GreenB + "(!) " + CC.Green + "Item added to your bidding watchlist!");
watching.add(auctionBid.getBidID());
this.player.playSound(this.player.getLocation(), Sound.LEVEL_UP, 1.0f, 1.4f);
}).click(ClickType.NUMBER_KEY, () -> this.forceExpireAuction(auctionBid, this.player)));
}
this.setItem(this.size - 9, new InventoryItem(new ItemBuilder(Material.CHEST, CC.YellowB + "Return to Auction", CC.Gray + "Click here to return to the", CC.Gray + "auction house main menu.").build()).click(() -> {
this.player.closeInventory();
this.player.performCommand("ah");
}));
this.setItem(this.size - 8, new InventoryItem(new ItemBuilder(Material.DIAMOND, CC.AquaB + "View Watchlist").addLore(CC.Gray + "Click here to view all active", CC.Gray + "bids on your watchlist!").build()).click(() -> Bukkit.getScheduler().scheduleSyncDelayedTask(Auction.getPlugin(), () -> new WatchlistMenu(this.player).openGUI(Auction.getPlugin()))));
this.setItem(this.size - 6, new InventoryItem(new ItemBuilder(Material.PAPER, CC.YellowB + "<- Previous Page", CC.Gray + "View previous page of auction biddings.").build()).click(() -> {
--this.page;
this.forceUpdate = true;
this.redraw();
}));
this.setItem(this.size - 4, new InventoryItem(new ItemBuilder(Material.PAPER, CC.YellowB + "Next Page ->", CC.Gray + "View next page of auction biddings.").build()).click(() -> {
++this.page;
this.forceUpdate = true;
this.redraw();
}));
}
public void forceExpireAuction(AuctionBid auctionBid, Player player) {
if (!player.isOp()) {
return;
}
if (auctionBid.isExpired()) {
player.sendMessage(ChatColor.RED + "Bid already expired!");
return;
}
auctionBid.expire();
if (auctionBid.getCurrentHighestBidder() != null) {
OfflinePlayer offlineBuyer = Bukkit.getOfflinePlayer(auctionBid.getCurrentHighestBidder());
if (offlineBuyer != null) {
Auction.economy.depositPlayer(offlineBuyer, (double) auctionBid.getCurrentBid());
}
player.sendMessage(CC.Red + "Returned " + auctionBid.getCurrentBidderName() + " $" + auctionBid.getCurrentBid());
}
player.sendMessage(CC.RedB + "Auction Bid force expired and items have been returned to seller!");
this.redraw();
}
}
@@ -0,0 +1,35 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.gui.CosmicGUI
* org.bukkit.entity.Player
*/
package me.recolance.auction.menu.bidmenus;
import net.crankedpvp.crankedutils.utils.cosmicgui.CosmicGUI;
import org.bukkit.entity.Player;
import java.util.UUID;
public abstract class BiddableMenu
extends CosmicGUI {
public boolean forceUpdate = false;
public long lastLeftClick;
public long lastRightClick;
public long lastBid;
private UUID lastSlotClicked;
public BiddableMenu(Player player, String title, int size) {
super(player, title, size);
}
public Player getPlayer() {
return this.player;
}
public String getTitle() {
return this.title;
}
}
@@ -0,0 +1,98 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.gui.CosmicGUI
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.gui.InventoryItem
* com.cosmicpvp.cosmicutils.me.astropvp.cratekeys.net.astropvp.armorsets.utils.CC
* com.cosmicpvp.cosmicutils.me.astropvp.cratekeys.net.astropvp.armorsets.utils.ItemBuilder
* org.bukkit.Bukkit
* org.bukkit.ChatColor
* org.bukkit.DyeColor
* org.bukkit.Material
* org.bukkit.OfflinePlayer
* org.bukkit.entity.Player
* org.bukkit.plugin.Plugin
*/
package me.recolance.auction.menu.bidmenus;
import com.google.common.collect.Lists;
import io.netty.util.internal.ConcurrentSet;
import me.recolance.auction.Auction;
import me.recolance.auction.data.AuctionBid;
import me.recolance.auction.menu.BidManager;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.cosmicgui.CosmicGUI;
import net.crankedpvp.crankedutils.utils.cosmicgui.InventoryItem;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import me.recolance.auction.Auction;
import me.recolance.auction.data.AuctionBid;
import me.recolance.auction.util.Util;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import java.util.function.Consumer;
public class ConfirmItemMenu
extends CosmicGUI {
Consumer<Void> confirmCallback;
Consumer<Void> denyCallback;
private AuctionBid bid;
private long bidding;
public ConfirmItemMenu(Player player, String title, long bidding, AuctionBid bid, Consumer<Void> confirm, Consumer<Void> deny) {
super(player, title, 9);
this.confirmCallback = confirm;
this.denyCallback = deny;
this.bid = bid;
this.bidding = bidding;
if (Auction.getPlugin().getToggles().isToggled(player)) {
Bukkit.getLogger().info("Automatically accepting confirm menu due to safetey toggles turned off: " + player.getName());
confirm.accept(null);
}
}
public static Consumer<Void> getConfirmCallback(AuctionBid bid, Player pl, long finalBidAmount, boolean buyout) {
return confirm -> {
if (bid.isExpired()) {
pl.sendMessage(CC.RedB + "Item no longer available!");
return;
}
if (bid.getCurrentBid() >= finalBidAmount) {
pl.sendMessage((Object) ChatColor.RED + "Your bid must be higher than the current bid!");
pl.sendMessage(CC.RedB + "Current Bid: $" + CC.Red + Util.formatMoney(bid.getCurrentBid()));
return;
}
if (!Auction.economy.has((OfflinePlayer) pl, (double) finalBidAmount)) {
pl.sendMessage(CC.Red + "You do not have the funds to do that!");
return;
}
if (buyout) {
bid.buyNow(pl);
} else {
bid.placePlayerBid(pl, finalBidAmount);
}
pl.closeInventory();
Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin) Auction.getPlugin(), () -> new BidMenu(pl).openGUI(Auction.getPlugin()), 1L);
};
}
public void redraw() {
int i;
boolean buyout = this.bid.getBuyoutAmount() > 0.0 && this.bid.getBuyoutAmount() == (double) this.bidding;
InventoryItem item = new InventoryItem(new ItemBuilder(Material.STAINED_GLASS_PANE, CC.GreenB + "Confirm " + (buyout ? "Buy" : "Bid") + " Now", new String[]{(Object) ChatColor.GRAY + "Click to confirm " + (buyout ? "purchase of" : "bid on"), CC.Gray + "'" + CC.White + this.bid.getBidSellDisplayName() + CC.Gray + "' for " + CC.GreenB + "$" + CC.Green + Util.formatMoney(this.bidding)}).setDurability((short) DyeColor.LIME.getWoolData()).build()).click(() -> this.confirmCallback.accept(null));
InventoryItem deny = new InventoryItem(new ItemBuilder(Material.STAINED_GLASS_PANE, CC.RedB + "Cancel", new String[]{(Object) ChatColor.GRAY + "Click to cancel this bid!"}).setDurability((short) DyeColor.RED.getWoolData()).build()).click(() -> this.denyCallback.accept(null));
for (i = 0; i < 4; ++i) {
this.setItem(i, item);
}
for (i = 4; i < this.size; ++i) {
this.setItem(i, deny);
}
this.setItem(4, new InventoryItem(this.bid.getSellingItems().get(0).clone()));
}
}
@@ -0,0 +1,63 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.gui.CosmicGUI
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.gui.InventoryItem
* com.cosmicpvp.cosmicutils.me.astropvp.cratekeys.net.astropvp.armorsets.utils.CC
* com.cosmicpvp.cosmicutils.me.astropvp.cratekeys.net.astropvp.armorsets.utils.InventoryUtils
* com.cosmicpvp.cosmicutils.me.astropvp.cratekeys.net.astropvp.armorsets.utils.ItemBuilder
* org.bukkit.Bukkit
* org.bukkit.Material
* org.bukkit.entity.Player
* org.bukkit.me.astropvp.cratekeys.inventory.ItemStack
* org.bukkit.plugin.Plugin
*/
package me.recolance.auction.menu.bidmenus;
import com.google.common.collect.Lists;
import io.netty.util.internal.ConcurrentSet;
import me.recolance.auction.Auction;
import me.recolance.auction.data.AuctionBid;
import me.recolance.auction.menu.BidManager;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.InventoryUtils;
import net.crankedpvp.crankedutils.utils.cosmicgui.CosmicGUI;
import net.crankedpvp.crankedutils.utils.cosmicgui.InventoryItem;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import me.recolance.auction.Auction;
import me.recolance.auction.data.AuctionBid;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
public class PackageViewMenu
extends CosmicGUI {
private AuctionBid toView;
private BiddableMenu menu;
public PackageViewMenu(Player player, AuctionBid toView, BiddableMenu parent) {
super(player, toView.getSellerName() + "'s Package Items", InventoryUtils.fitSize((int) (toView.getSellingItems().size() + 1)));
this.toView = toView;
this.menu = parent;
}
public void redraw() {
if (this.toView.isExpired()) {
this.player.closeInventory();
this.player.sendMessage(CC.Red + "That Auction item is no longer available!");
return;
}
int slot = 0;
for (ItemStack item : this.toView.getSellingItems()) {
this.setItem(slot++, item, null);
}
this.setItem(this.size - 1, new InventoryItem(new ItemBuilder(Material.ARROW).setName(CC.GreenB + "Return to Auctions").addLore(new String[]{"", CC.Gray + "Click to return to auction bids!"}).build()).click(() -> Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin) Auction.getPlugin(), () -> this.menu.openGUI(Auction.getPlugin()), 1L)));
}
}
@@ -0,0 +1,133 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.gui.InventoryItem
* com.cosmicpvp.cosmicutils.me.astropvp.cratekeys.net.astropvp.armorsets.utils.CC
* com.cosmicpvp.cosmicutils.me.astropvp.cratekeys.net.astropvp.armorsets.utils.ItemBuilder
* net.minecraft.util.io.netty.util.internal.ConcurrentSet
* org.bukkit.Bukkit
* org.bukkit.Material
* org.bukkit.entity.Player
* org.bukkit.event.me.astropvp.cratekeys.inventory.ClickType
* org.bukkit.plugin.Plugin
*/
package me.recolance.auction.menu.bidmenus;
import com.google.common.collect.Lists;
import io.netty.util.internal.ConcurrentSet;
import me.recolance.auction.Auction;
import me.recolance.auction.data.AuctionBid;
import me.recolance.auction.menu.BidManager;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.InventoryUtils;
import net.crankedpvp.crankedutils.utils.cosmicgui.CosmicGUI;
import net.crankedpvp.crankedutils.utils.cosmicgui.InventoryItem;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import me.recolance.auction.Auction;
import me.recolance.auction.data.AuctionBid;
import io.netty.util.internal.ConcurrentSet;
import me.recolance.auction.Auction;
import me.recolance.auction.data.AuctionBid;
import me.recolance.auction.menu.BidManager;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.plugin.Plugin;
import java.util.LinkedList;
import java.util.Set;
import java.util.UUID;
public class WatchlistMenu
extends BiddableMenu {
private LinkedList<AuctionBid> bidsWatching = new LinkedList();
public WatchlistMenu(Player player) {
super(player, "Bidding Watchlist", 54);
BidManager bidManager = Auction.getPlugin().getBidManager();
ConcurrentSet<UUID> bids = bidManager.getWatchlists().get(player.getUniqueId());
if (bids != null) {
bids.forEach(bidId -> {
AuctionBid bid = bidManager.getActiveAuctionBids().get(bidId);
if (bid == null || bid.isExpired()) {
bids.remove(bidId);
return;
}
if (!this.bidsWatching.contains(bid)) {
this.bidsWatching.add(bid);
}
});
if (bids.isEmpty()) {
bidManager.getWatchlists().remove(player.getUniqueId());
}
}
if (this.bidsWatching != null) {
this.bidsWatching.sort((o1, o2) -> {
int secondsLeft2;
int secondsLeft1 = o1.getSecondsLeftInAuction();
if (secondsLeft1 > (secondsLeft2 = o2.getSecondsLeftInAuction())) {
return -1;
}
if (secondsLeft2 == secondsLeft1) {
return 0;
}
return 1;
});
}
}
public void redraw() {
int slot = 0;
for (AuctionBid bid : this.bidsWatching) {
ItemBuilder builder = new ItemBuilder(bid.getAuctionDisplayItem(false));
if (bid.isExpired()) {
builder.addLore("", CC.RedB + "EXPIRED", bid.getCurrentHighestBidder() != null ? CC.GreenB + "BUYER: " + CC.Green + bid.getCurrentBidderName() : "");
}
this.setItem(slot++, new InventoryItem(builder.build()).click(ClickType.LEFT, () -> {
if (bid.isExpired()) {
this.player.sendMessage(CC.RedB + "That auction has expired!");
this.player.sendMessage(CC.Gray + "Shift-RClick to remove this from your watchlist!");
return;
}
bid.getLeftClickLogic(this, this.player).run();
}).click(ClickType.RIGHT, () -> {
if (bid.isExpired()) {
this.player.sendMessage(CC.RedB + "That auction has expired!");
this.player.sendMessage(CC.Gray + "Shift-RClick to remove this from your watchlist!");
return;
}
bid.getRightClickLogic(this, this.player).run();
}).click(ClickType.MIDDLE, () -> {
if (bid.isExpired()) {
this.player.sendMessage(CC.RedB + "That auction has expired!");
this.player.sendMessage(CC.Gray + "Shift-RClick to remove this from your watchlist!");
return;
}
bid.getMiddleClickLogic(this, this.player).run();
}).click(ClickType.SHIFT_LEFT, () -> {
if (bid.isExpired()) {
this.player.sendMessage(CC.RedB + "That auction has expired!");
this.player.sendMessage(CC.Gray + "Shift-RClick to remove this from your watchlist!");
return;
}
bid.getShiftLeftClickLogic(this, this.player).run();
}).click(ClickType.SHIFT_RIGHT, () -> {
Set watching = (Set) Auction.getPlugin().getBidManager().getWatchlists().computeIfAbsent(this.player.getUniqueId(), list -> new ConcurrentSet());
this.player.sendMessage(CC.RedB + "(!) " + CC.Red + "Item removed from watchlist!");
watching.remove(bid.getBidID());
this.bidsWatching.remove(bid);
if (watching.isEmpty()) {
Auction.getPlugin().getBidManager().getWatchlists().remove(this.player.getUniqueId());
}
this.redraw();
}));
}
this.setItem(this.size - 9, new InventoryItem(new ItemBuilder(Material.CHEST, CC.YellowB + "Return to Bids", CC.Gray + "Click here to return to the", CC.Gray + "bid auction main page.").build()).click(() -> Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin) Auction.getPlugin(), () -> new BidMenu(this.player).openGUI(Auction.getPlugin()))));
}
}
@@ -0,0 +1,100 @@
// Decompiled with: FernFlower
// Class Version: 8
package me.recolance.auction.menu.categories;
import com.google.common.collect.Lists;
import me.recolance.auction.auction.Listing;
import me.recolance.auction.data.AuctionItem;
import net.crankedpvp.crankedcore.utils.ExpBottleAPI;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.util.Comparator;
import java.util.List;
public class AuctionCategory implements Comparable<AuctionCategory>, AuctionItem {
private String displayName;
private String strippedName;
private ItemStack displayItem;
private List<Listing> categoryItems = Lists.newLinkedList();
private Listing lowestPricedItem;
private List<AuctionCategory> subCategories;
private Integer rarityTier = 0;
public double getLowestPricedItem() {
if (this.lowestPricedItem == null || this.lowestPricedItem.isExpired() || !this.lowestPricedItem.isValid()) {
this.lowestPricedItem = null;
this.lowestPricedItem = (Listing)this.categoryItems.stream().min(Comparator.comparing(Listing::getPrice)).orElse(null);
}
return this.lowestPricedItem != null ? this.lowestPricedItem.getPrice() : 0.0D;
}
public List<Listing> getCategoryItems() {
this.categoryItems.removeIf((item) -> {
return !item.isValid() || item.isExpired();
});
return this.categoryItems;
}
public void addSubCategoryItem(AuctionCategory subCategory) {
this.subCategories.add(subCategory);
}
public void sortSubCategories() {
this.subCategories.sort(Comparator.comparingInt(AuctionCategory::getRarityTier));
}
public void sortCategoryItems() {
if (this.displayItem != null && this.displayItem.getType() == Material.EXP_BOTTLE && ExpBottleAPI.isXpBottle(this.displayItem)) {
int exp = ExpBottleAPI.getXpAmount(this.displayItem);
if (exp > 0) {
this.getCategoryItems().sort(Comparator.comparingDouble(Listing::getExpPerDollar));
}
} else {
this.getCategoryItems().sort((item1, item2) -> {
return item1.getPricePerItem() == item2.getPricePerItem() ? item1.compareTo(item2) : Double.compare(item1.getPricePerItem(), item2.getPricePerItem());
});
}
}
public int compareTo(AuctionCategory o) {
return this.getDisplayItem().getType().compareTo(o.getDisplayItem().getType());
}
public ItemStack getDisplay() {
return this.getDisplayItem();
}
public AuctionCategory(String displayName, String strippedName, ItemStack displayItem, List<Listing> categoryItems, Listing lowestPricedItem, List<AuctionCategory> subCategories, Integer rarityTier) {
this.displayName = displayName;
this.strippedName = strippedName;
this.displayItem = displayItem;
this.categoryItems = categoryItems;
this.lowestPricedItem = lowestPricedItem;
this.subCategories = subCategories;
this.rarityTier = rarityTier;
}
public String getDisplayName() {
return this.displayName;
}
public String getStrippedName() {
return this.strippedName;
}
public ItemStack getDisplayItem() {
return this.displayItem;
}
public List<AuctionCategory> getSubCategories() {
return this.subCategories;
}
public Integer getRarityTier() {
return this.rarityTier;
}
}
@@ -0,0 +1,107 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.gui.CosmicGUI
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.gui.InventoryItem
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.CC
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.ItemBuilder
* org.bukkit.Material
* org.bukkit.entity.Player
* org.bukkit.event.inventory.ClickType
*/
package me.recolance.auction.menu.categories;
import com.google.common.collect.Lists;
import io.netty.util.internal.ConcurrentSet;
import me.recolance.auction.Auction;
import me.recolance.auction.data.AuctionBid;
import me.recolance.auction.menu.BidManager;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.InventoryUtils;
import net.crankedpvp.crankedutils.utils.cosmicgui.CosmicGUI;
import net.crankedpvp.crankedutils.utils.cosmicgui.InventoryItem;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import me.recolance.auction.Auction;
import me.recolance.auction.data.AuctionBid;
import me.recolance.auction.auction.Listing;
import me.recolance.auction.auction.UnclaimedListing;
import me.recolance.auction.controller.Controller;
import me.recolance.auction.data.DataHolder;
import me.recolance.auction.menu.MenuRenderer;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import java.util.List;
public abstract class AuctionMenu
extends CosmicGUI {
public long nextClickExpiration = System.currentTimeMillis() + 1000L;
public AuctionMenu(Player player, String title, int size) {
super(player, title, size);
}
public void clearItems() {
this.inventory.clear();
this.getInventoryItems().clear();
}
public InventoryItem getAuctionItem(Listing item) {
Runnable leftClick = () -> {
if (!this.canClick()) {
return;
}
if (!item.isValid() || item.isExpired()) {
this.player.sendMessage(CC.Red + "Item no longer available!");
this.redraw();
return;
}
if (item.getWhoListed().equals(this.player.getUniqueId())) {
this.player.sendMessage(CC.RedB + "(!) " + CC.Red + "You cannot purchase your own item!");
this.player.sendMessage(CC.Gray + "Shift Right-Click to stop selling this item!");
return;
}
this.nextClickExpiration = System.currentTimeMillis() + 100L;
this.closeWithDelay(pl -> MenuRenderer.purchaseConfirmation(this.player, item, true));
};
return new InventoryItem(new ItemBuilder(item.getMenuDisplayItem()).build()).click(ClickType.LEFT, leftClick).click(ClickType.SHIFT_RIGHT, () -> {
if (!this.canClick()) {
return;
}
if (!item.isValid() || item.isExpired()) {
this.player.sendMessage(CC.Red + "Item no longer valid!");
this.redraw();
return;
}
if (item.getWhoListed().equals(this.player.getUniqueId())) {
this.nextClickExpiration = System.currentTimeMillis() + 100L;
if (item.isValid() && !item.isExpired()) {
Controller.cancel(this.player, item);
this.redraw();
}
} else {
leftClick.run();
}
});
}
public InventoryItem getCollectionBinItem() {
List<UnclaimedListing> itemsSelling = DataHolder.getUnclaimedListings().get(this.player.getUniqueId());
int emptyItems = itemsSelling != null ? (int) itemsSelling.stream().filter(item -> !item.isExpired()).count() : 0;
return new InventoryItem(new ItemBuilder(Material.ENDER_CHEST, CC.YellowB + "Collection Bin", new String[]{CC.Gray + "Click to view and collect", CC.Gray + "all of your active, cancelled", CC.Gray + "or expired Auction items.", "", CC.YellowB + emptyItems + " Item" + (emptyItems != 1 ? "s" : "")}).build()).click(() -> this.closeWithDelay(pl -> MenuRenderer.expired(this.player)));
}
public boolean canClick() {
if (this.nextClickExpiration > System.currentTimeMillis() && !this.player.hasPermission("cosmicsky.auction.vip")) {
this.player.sendMessage(CC.RedB + "(!) " + CC.Red + "Please slow down in between clicks!");
return false;
}
return true;
}
}
@@ -0,0 +1,92 @@
// Decompiled with: CFR 0.151
// Class Version: 8
package me.recolance.auction.menu.categories;
import com.google.common.collect.Lists;
import io.netty.util.internal.ConcurrentSet;
import me.recolance.auction.Auction;
import me.recolance.auction.data.AuctionBid;
import me.recolance.auction.menu.BidManager;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.InventoryUtils;
import net.crankedpvp.crankedutils.utils.cosmicgui.CosmicGUI;
import net.crankedpvp.crankedutils.utils.cosmicgui.InventoryItem;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import me.recolance.auction.Auction;
import me.recolance.auction.data.AuctionBid;
import me.recolance.auction.Auction;
import me.recolance.auction.auction.Listing;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.List;
public class CategoryItemViewMenu
extends AuctionMenu {
private AuctionCategory category;
private int page = 1;
public CategoryItemViewMenu(Player player, AuctionCategory category) {
super(player, "Category Items", 54);
this.category = category;
}
@Override
public void redraw() {
this.clearItems();
int PREVIOUS_PAGE_SLOT = this.inventory.getSize() - 6;
int NEXT_PAGE_SLOT = this.inventory.getSize() - 4;
int MAIN_CATEGORY_SLOT = this.inventory.getSize() - 1;
int COLLECTION_BIN_SLOT = this.inventory.getSize() - 9;
List<Listing> items = this.category.getCategoryItems();
this.setItem(MAIN_CATEGORY_SLOT, new InventoryItem(new ItemBuilder(Material.PAPER, CC.RedB + "Main Category Menu", new String[]{CC.Gray + "Click to view all current", CC.Gray + "auction item categories."}).build()).click(() -> {
if (this.getParentGUI() != null) {
this.getParentGUI().openGUI(Auction.getPlugin());
this.getParentGUI().redraw();
}
}));
this.setItem(COLLECTION_BIN_SLOT, this.getCollectionBinItem());
if (items.size() > 0) {
int perPage = 45;
int maxPages = (int)Math.ceil((double)items.size() / 45.0);
if (this.page > maxPages) {
this.page = maxPages;
}
if (this.page < 1) {
this.page = 1;
}
if (this.page > 1) {
int previousPage = Math.max(1, this.page - 1);
this.setItem(PREVIOUS_PAGE_SLOT, new InventoryItem(new ItemBuilder(Material.ARROW, CC.RedB + "Previous Page (" + CC.Gray + previousPage + CC.Red + "/" + CC.Gray + maxPages + CC.RedB + ")", new String[]{CC.Gray + "Click to view previous page."}).build()).click(() -> {
if (!this.canClick()) {
return;
}
--this.page;
this.nextClickExpiration = System.currentTimeMillis() + 100L;
this.redraw();
}));
}
if (maxPages > 1 && this.page < maxPages) {
int nextPage = Math.min(maxPages, this.page + 1);
this.setItem(NEXT_PAGE_SLOT, new InventoryItem(new ItemBuilder(Material.ARROW, CC.GreenB + "Next Page (" + CC.Gray + nextPage + CC.Green + "/" + CC.Gray + maxPages + CC.GreenB + ")", new String[]{CC.Gray + "Click to view next page."}).build()).click(() -> {
if (!this.canClick()) {
return;
}
++this.page;
this.nextClickExpiration = System.currentTimeMillis() + 100L;
this.redraw();
}));
}
int startIndex = this.page * 45 - 45;
int endIndex = startIndex + 45;
int index = 0;
for (int i = startIndex; i < endIndex && i < items.size(); ++i) {
Listing item = items.get(i);
this.setItem(index++, this.getAuctionItem(item));
}
}
}
}
@@ -0,0 +1,166 @@
// Decompiled with: CFR 0.151
// Class Version: 8
package me.recolance.auction.menu.categories;
import com.google.common.collect.Lists;
import io.netty.util.internal.ConcurrentSet;
import me.recolance.auction.Auction;
import me.recolance.auction.data.AuctionBid;
import me.recolance.auction.menu.BidManager;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.InventoryUtils;
import net.crankedpvp.crankedutils.utils.NumberUtils;
import net.crankedpvp.crankedutils.utils.cosmicgui.CosmicGUI;
import net.crankedpvp.crankedutils.utils.cosmicgui.InventoryItem;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import me.recolance.auction.Auction;
import me.recolance.auction.data.AuctionBid;
import com.google.common.collect.Lists;
import me.recolance.auction.Auction;
import me.recolance.auction.auction.Listing;
import me.recolance.auction.data.AuctionItem;
import me.recolance.auction.data.DataHandler;
import me.recolance.auction.menu.MenuRenderer;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
public class CategoryMainMenu
extends AuctionMenu {
private List<AuctionItem> categories;
private int page = 1;
private boolean mainPage = true;
public CategoryMainMenu(Player player) {
super(player, "Auction Categories", 54);
}
public void setCategories(List<AuctionItem> categories, boolean main) {
this.categories = categories;
this.mainPage = main;
}
private List<AuctionItem> getCategories() {
if (this.categories == null || this.categories.isEmpty()) {
this.categories = Lists.newLinkedList(DataHandler.getAuctionCategories());
this.mainPage = true;
}
return this.categories;
}
@Override
public void redraw() {
this.clearItems();
int PREVIOUS_PAGE_SLOT = this.inventory.getSize() - 6;
int NEXT_PAGE_SLOT = this.inventory.getSize() - 4;
int MAIN_AUCTION_SLOT = this.inventory.getSize() - 1;
int BIN_SLOT = this.inventory.getSize() - 9;
int REFRESH_SLOT = this.inventory.getSize() - 5;
int MAIN_CATEGORIES = this.inventory.getSize() - 7;
List<AuctionItem> categories = this.getCategories();
int perPage = 45;
int maxPages = (int)Math.ceil((double)categories.size() / 45.0);
if (this.page > maxPages) {
this.page = maxPages;
}
if (this.page < 1) {
this.page = 1;
}
if (this.page > 1) {
int previousPage = Math.max(1, this.page - 1);
this.setItem(PREVIOUS_PAGE_SLOT, new ItemBuilder(Material.ARROW, CC.RedB + "Previous Page (" + CC.Gray + previousPage + CC.Red + "/" + CC.Gray + maxPages + CC.RedB + ")", new String[]{CC.Gray + "Click to view previous category page."}).build(), () -> {
if (!this.canClick()) {
return;
}
--this.page;
this.nextClickExpiration = System.currentTimeMillis() + 100L;
this.redraw();
});
}
if (maxPages > 1 && this.page < maxPages) {
int nextPage = Math.min(maxPages, this.page + 1);
this.setItem(NEXT_PAGE_SLOT, new ItemBuilder(Material.ARROW, CC.GreenB + "Next Page (" + CC.Gray + nextPage + CC.Green + "/" + CC.Gray + maxPages + CC.GreenB + ")", new String[]{CC.Gray + "Click to view next category page."}).build(), () -> {
if (!this.canClick()) {
return;
}
++this.page;
this.nextClickExpiration = System.currentTimeMillis() + 100L;
this.redraw();
});
}
this.setItem(MAIN_AUCTION_SLOT, new ItemBuilder(Material.PAPER, CC.YellowB + "Main Auction Menu", new String[]{CC.Gray + "Click to view the main auction menu."}).build(), () -> this.closeWithDelay(pl -> MenuRenderer.openAuction(this.player)));
this.setItem(BIN_SLOT, this.getCollectionBinItem());
this.setItem(REFRESH_SLOT, new ItemBuilder(Material.WATCH, CC.GreenB + "Refresh", new String[]{CC.Gray + "Click to refresh the auction page!"}).build(), () -> {
if (!this.canClick()) {
return;
}
this.nextClickExpiration = System.currentTimeMillis() + 100L;
this.redraw();
});
if (!this.mainPage) {
this.setItem(MAIN_CATEGORIES, new ItemBuilder(Material.CHEST, CC.RedB + "Main Categories", new String[]{CC.Gray + "Click to view main category page."}).build(), () -> {
if (!this.canClick()) {
return;
}
this.page = 1;
this.nextClickExpiration = System.currentTimeMillis() + 100L;
this.categories = Lists.newLinkedList(DataHandler.getAuctionCategories());
this.mainPage = true;
this.redraw();
});
}
int startIndex = this.page * 45 - 45;
int endIndex = startIndex + 45;
int index = 0;
for (int i = startIndex; i < endIndex && i < categories.size(); ++i) {
AuctionItem item = categories.get(i);
ItemStack display = item.getDisplay();
ItemMeta im = display.getItemMeta();
if (item instanceof AuctionCategory) {
AuctionCategory category = (AuctionCategory)item;
if (category.getCategoryItems().size() == 1 && category.getSubCategories().isEmpty()) {
this.setItem(index++, this.getAuctionItem(category.getCategoryItems().get(0)));
continue;
}
ArrayList<String> lore = Lists.newArrayList();
lore.add("");
if (category.getSubCategories() != null && !category.getSubCategories().isEmpty()) {
lore.add(CC.Gold + "Sub Categories: " + CC.Yellow + category.getSubCategories().size());
}
lore.add(CC.GoldB + "Listings: " + CC.Yellow + category.getCategoryItems().size());
lore.add(CC.Gold + " Lowest Price: " + CC.YellowB + "$" + CC.Yellow + NumberUtils.formatMoney(category.getLowestPricedItem()));
if (category.getSubCategories() != null && !category.getSubCategories().isEmpty()) {
lore.add(CC.Gray + "Click to view sub categories!");
}
im.setLore(lore);
display.setItemMeta(im);
this.setItem(index++, new InventoryItem(display).click(() -> {
if (category.getSubCategories() != null && category.getSubCategories().size() > 0) {
this.categories = Lists.newLinkedList(category.getSubCategories());
if (category.getCategoryItems() != null && !category.getCategoryItems().isEmpty()) {
this.categories.addAll(category.getCategoryItems());
}
this.mainPage = false;
this.redraw();
return;
}
new CategoryItemViewMenu(this.player, category).setParentGUI(this).openGUI(Auction.getPlugin());
}));
continue;
}
if (!(item instanceof Listing)) continue;
this.setItem(index++, this.getAuctionItem((Listing)item));
}
}
public void setCategories(List<AuctionItem> categories) {
this.categories = categories;
}
}
@@ -0,0 +1,41 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* org.bukkit.Bukkit
* org.bukkit.ChatColor
* org.bukkit.Sound
* org.bukkit.entity.Player
* org.bukkit.scheduler.BukkitRunnable
*/
package me.recolance.auction.tasks;
import me.recolance.auction.auction.UnclaimedListing;
import me.recolance.auction.data.DataHolder;
import me.recolance.auction.util.Util;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.List;
public class ItemExpireWarnTask
extends BukkitRunnable {
public void run() {
block0:
for (Player p : Bukkit.getOnlinePlayers()) {
List<UnclaimedListing> listings = DataHolder.getUnclaimedListings().get(p.getUniqueId());
if (listings == null || listings.size() <= 0) continue;
for (UnclaimedListing ul : listings) {
long l = ul.getExpireTime() - System.currentTimeMillis();
if (l <= 0L || l > 900000L) continue;
p.sendMessage((Object) ChatColor.RED + "" + (Object) ChatColor.BOLD + "(!) " + (Object) ChatColor.RED + "You have item(s) in your " + (Object) ChatColor.UNDERLINE + "/ah expired" + (Object) ChatColor.RED + " that are going to be deleted in " + (Object) ChatColor.BOLD + Util.timeToDHMSString(l));
p.playSound(p.getLocation(), Sound.CHICKEN_EGG_POP, 1.2f, 1.25f);
continue block0;
}
}
}
}
@@ -0,0 +1,67 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* org.bukkit.entity.Player
*/
package me.recolance.auction.util;
import me.recolance.auction.Auction;
import me.recolance.auction.data.DataHolder;
import org.bukkit.entity.Player;
public class AuctionUtil {
public static int getCurrentlySellingAmount(Player player) {
if (!DataHolder.getPlayerListings().containsKey(player.getUniqueId())) {
return 0;
}
return DataHolder.getPlayerListings().get(player.getUniqueId()).size();
}
public static int getItemsToCollectAmount(Player player) {
if (!DataHolder.getUnclaimedListings().containsKey(player.getUniqueId())) {
return 0;
}
return DataHolder.getUnclaimedListings().get(player.getUniqueId()).size();
}
public static long getEndTime() {
return System.currentTimeMillis() + 864000000; //10 days
}
public static long getUnclaimedEndTime() {
return System.currentTimeMillis() + (long) (Auction.plugin.getConfig().getInt("auction.unclaimedHours") * 3600000);
}
public static boolean canSellItemPermission(Player player) {
int currentlySelling = AuctionUtil.getCurrentlySellingAmount(player);
if (player.isOp()) {
return true;
}
int limit = AuctionUtil.getSellItemLimit(player);
return currentlySelling + 1 <= limit;
}
private static int getSellItemLimit(Player p) {
if (p.hasPermission("auction.limit.8")) {
return 8;
}
if (p.hasPermission("auction.limit.6")) {
return 6;
}
if (p.hasPermission("auction.limit.5")) {
return 5;
}
if (p.hasPermission("auction.limit.4")) {
return 4;
}
if (p.hasPermission("auction.limit.3")) {
return 3;
}
if (p.hasPermission("auction.limit.2")) {
return 2;
}
return 1;
}
}
@@ -0,0 +1,214 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* net.minecraft.server.v1_8_R3.ItemStack
* net.minecraft.server.v1_8_R3.NBTTagCompound
* org.bukkit.Bukkit
* org.bukkit.ChatColor
* org.bukkit.Material
* org.bukkit.craftbukkit.v1_8_R3.me.astropvp.cratekeys.inventory.CraftItemStack
* org.bukkit.enchantments.Enchantment
* org.bukkit.me.astropvp.cratekeys.inventory.ItemStack
* org.bukkit.me.astropvp.cratekeys.inventory.meta.ItemMeta
* org.bukkit.me.astropvp.cratekeys.inventory.meta.SkullMeta
*/
package me.recolance.auction.util;
import me.recolance.globalutils.attribute.Attributes;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import java.util.ArrayList;
import java.util.UUID;
public class Item {
private ItemStack item;
public Item() {
this.item = new ItemStack(Material.AIR, 1);
}
public Item(ItemStack item) {
this.item = item;
}
public Item(Item item) {
item = this;
}
public Item setAmount(int amount) {
this.item.setAmount(amount);
return this;
}
public Item setType(Material mat) {
this.item.setType(mat);
return this;
}
public Item setType(int id) {
this.item.setTypeId(id);
return this;
}
public Item setDurability(short d) {
this.item.setDurability(d);
return this;
}
public Item setDurability(int d) {
this.item.setDurability((short) d);
return this;
}
public Item setName(String name) {
name = ChatColor.translateAlternateColorCodes((char) '&', (String) name);
ItemMeta meta = this.item.getItemMeta();
meta.setDisplayName(name);
this.item.setItemMeta(meta);
return this;
}
public Item addLore(String... lore) {
ItemMeta meta = this.item.getItemMeta();
ArrayList<String> loreList = new ArrayList<String>();
if (meta.hasLore()) {
loreList.addAll(meta.getLore());
}
for (String line : lore) {
loreList.add(ChatColor.translateAlternateColorCodes((char) '&', (String) line));
}
meta.setLore(loreList);
this.item.setItemMeta(meta);
return this;
}
public boolean isEnchanted() {
return this.item.hasItemMeta() && this.item.getItemMeta().hasEnchants();
}
public Item addEnchant(int eId, int level) {
return this.addEnchant(Enchantment.getById((int) eId), level);
}
public Item addEnchant(Enchantment enchant, int level) {
this.item.addUnsafeEnchantment(enchant, level);
return this;
}
public Item incrementEnchant(int eId, int amount) {
return this.incrementEnchant(Enchantment.getById((int) eId), amount);
}
public Item incrementEnchant(Enchantment enchant, int amount) {
if (!this.item.containsEnchantment(enchant)) {
this.item.addUnsafeEnchantment(enchant, amount);
} else {
int cEL = this.item.getEnchantmentLevel(enchant);
this.item.removeEnchantment(enchant);
this.item.addUnsafeEnchantment(enchant, cEL + amount);
}
return this;
}
public Item incrementSafeEnchant(int eId, int amount) {
return this.incrementSafeEnchant(Enchantment.getById((int) eId), amount);
}
public Item incrementSafeEnchant(Enchantment enchant, int amount) {
int mEL = enchant.getMaxLevel();
if (!this.item.containsEnchantment(enchant)) {
int inc = amount > mEL ? mEL : amount;
this.item.addEnchantment(enchant, inc);
} else {
int cEL = this.item.getEnchantmentLevel(enchant);
int inc = cEL + amount > mEL ? mEL : cEL + amount;
this.item.removeEnchantment(enchant);
this.item.addEnchantment(enchant, inc);
}
return this;
}
public Item skull(UUID uuid) {
return this.skull(Bukkit.getOfflinePlayer((UUID) uuid).getName());
}
public Item skull(String name) {
SkullMeta meta = (SkullMeta) this.item.getItemMeta();
meta.setOwner(name);
this.item.setItemMeta((ItemMeta) meta);
return this;
}
public Item hideFlag(FlagType flagType) {
int type = (Integer) flagType.getFlag();
net.minecraft.server.v1_8_R3.ItemStack stack = CraftItemStack.asNMSCopy((ItemStack) this.item);
NBTTagCompound compound = stack.getTag();
if (compound == null) {
compound = new NBTTagCompound();
stack.setTag(compound);
compound = stack.getTag();
}
compound.setInt("HideFlags", type);
stack.setTag(compound);
this.item = CraftItemStack.asCraftMirror((net.minecraft.server.v1_8_R3.ItemStack) stack);
return this;
}
public Item setUnbreakable(boolean isUnbreakable) {
int type = isUnbreakable ? (Integer) FlagType.UNBREAKABLE_TRUE.getFlag() : (Integer) FlagType.UNBREAKABLE_FALSE.getFlag();
net.minecraft.server.v1_8_R3.ItemStack stack = CraftItemStack.asNMSCopy((ItemStack) this.item);
NBTTagCompound compound = stack.getTag();
if (compound == null) {
compound = new NBTTagCompound();
stack.setTag(compound);
compound = stack.getTag();
}
compound.setInt("Unbreakable", type);
stack.setTag(compound);
this.item = CraftItemStack.asCraftMirror((net.minecraft.server.v1_8_R3.ItemStack) stack);
return this;
}
public Item addAttribute(String name, Attributes.AttributeType type, double amount) {
Attributes a = new Attributes(this.item);
a.add(Attributes.Attribute.newBuilder().name(name).type(type).amount(amount).build());
this.item = a.getStack();
return this;
}
public ItemStack get() {
return this.item;
}
public static enum FlagType {
ENCHANTMENTS(1),
ATTRIBUTES(2),
UNBREAKABLE(4),
CAN_DESTROY(8),
CAN_PLACE_ON(16),
OTHERS(32),
ALL(64),
UNBREAKABLE_TRUE(1),
UNBREAKABLE_FALSE(0);
private Object flag;
private FlagType(Object flag) {
this.flag = flag;
}
public Object getFlag() {
return this.flag;
}
}
}
@@ -0,0 +1,291 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* com.cosmicpvp.cosmicutils.net.astropvp.armorsets.utils.ItemBuilder
* net.minecraft.server.v1_8_R3.ItemStack
* net.minecraft.server.v1_8_R3.NBTBase
* net.minecraft.server.v1_8_R3.NBTCompressedStreamTools
* net.minecraft.server.v1_8_R3.NBTReadLimiter
* net.minecraft.server.v1_8_R3.NBTTagCompound
* net.minecraft.server.v1_8_R3.NBTTagList
* org.bukkit.Material
* org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryCustom
* org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack
* org.bukkit.inventory.Inventory
* org.bukkit.inventory.ItemStack
* org.bukkit.inventory.PlayerInventory
* org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder
*/
package me.recolance.auction.util;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import net.minecraft.server.v1_8_R3.*;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryCustom;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
import java.io.*;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ItemSerialization {
private static final int VERSION = 1;
private static final String INVENTORY_CUSTOM = "custom";
private static final String INVENTORY_PLAYER = "player";
private static final int NBT_TYPE_COMPOUND = 10;
private static final String NBT_TYPE = "type";
private static final String NBT_ITEM = "item";
private static final String NBT_ITEMS = "items";
private static final String NBT_VERSION = "version";
private static final String NBT_PLAYER_HELD_INDEX = "player_held_index";
private static final String NBT_PLAYER_NAME = "player_name";
private static Method WRITE_NBT;
private static Method READ_NBT;
public static String inventoryToString(Inventory inv) {
return ItemSerialization.toBase64(inv);
}
public static Inventory getInventoryFromString(String s, String name, int size) {
return ItemSerialization.fromBase64(s, name, size);
}
public static String itemListToBase64(List<ItemStack> items) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DataOutputStream dataOutput = new DataOutputStream(outputStream);
NBTTagCompound root = new NBTTagCompound();
NBTTagList itemList = new NBTTagList();
for (ItemStack is : items) {
NBTTagCompound outputObject = new NBTTagCompound();
CraftItemStack craft = ItemSerialization.getCraftVersion(is);
net.minecraft.server.v1_8_R3.ItemStack nmsCopy = CraftItemStack.asNMSCopy((ItemStack) craft);
if (nmsCopy != null) {
nmsCopy.save(outputObject);
}
itemList.add((NBTBase) outputObject);
}
root.setInt(NBT_VERSION, 1);
root.set(NBT_ITEMS, (NBTBase) itemList);
ItemSerialization.writeNbt((NBTBase) root, dataOutput);
return Base64Coder.encodeLines((byte[]) outputStream.toByteArray());
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
* Enabled aggressive exception aggregation
*/
public static String itemToStringBase64(ItemStack item) {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
String string;
block11:
{
DataOutputStream dataOutput = new DataOutputStream(outputStream);
try {
NBTTagCompound root = new NBTTagCompound();
CraftItemStack craft = ItemSerialization.getCraftVersion(item);
net.minecraft.server.v1_8_R3.ItemStack nmsCopy = CraftItemStack.asNMSCopy((ItemStack) craft);
NBTTagCompound outputObject = new NBTTagCompound();
if (nmsCopy != null) {
nmsCopy.save(outputObject);
}
root.setInt(NBT_VERSION, 1);
root.set(NBT_ITEM, (NBTBase) outputObject);
ItemSerialization.writeNbt((NBTBase) root, dataOutput);
String retr = Base64Coder.encodeLines((byte[]) outputStream.toByteArray());
dataOutput.close();
outputStream.close();
string = retr;
if (Collections.singletonList(dataOutput).get(0) == null) break block11;
} catch (Throwable throwable) {
if (Collections.singletonList(dataOutput).get(0) != null) {
dataOutput.close();
}
throw throwable;
}
dataOutput.close();
}
return string;
} finally {
if (Collections.singletonList(outputStream).get(0) != null) {
outputStream.close();
}
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static ItemStack itemFromBase64(String data) {
if (data == null) {
return new ItemBuilder(Material.DIRT, "Invalid NBT Data!").build();
}
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines((String) data));
NBTTagCompound root = (NBTTagCompound) ItemSerialization.readNbt(new DataInputStream(inputStream), 0);
if (root.getInt(NBT_VERSION) != 1) {
throw new IllegalArgumentException("Incompatible version: " + root.getInt(NBT_VERSION));
}
NBTTagCompound compound = root.getCompound(NBT_ITEM);
if (!compound.isEmpty()) {
return CraftItemStack.asCraftMirror((net.minecraft.server.v1_8_R3.ItemStack) net.minecraft.server.v1_8_R3.ItemStack.createStack((NBTTagCompound) compound));
}
return null;
}
public static List<ItemStack> itemListFromBase64(String data) {
ArrayList<ItemStack> items = new ArrayList<ItemStack>();
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines((String) data));
NBTTagCompound root = (NBTTagCompound) ItemSerialization.readNbt(new DataInputStream(inputStream), 0);
if (root.getInt(NBT_VERSION) != 1) {
throw new IllegalArgumentException("Incompatible version: " + root.getInt(NBT_VERSION));
}
NBTTagList itemList = root.getList(NBT_ITEMS, 10);
for (int i = 0; i < itemList.size(); ++i) {
NBTTagCompound inputObject = itemList.get(i);
if (inputObject.isEmpty()) continue;
items.add((ItemStack) CraftItemStack.asCraftMirror((net.minecraft.server.v1_8_R3.ItemStack) net.minecraft.server.v1_8_R3.ItemStack.createStack((NBTTagCompound) inputObject)));
}
return items;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
* Enabled aggressive exception aggregation
*/
public static String toBase64(Inventory inventory) {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
String string;
block13:
{
DataOutputStream dataOutput = new DataOutputStream(outputStream);
try {
NBTTagCompound root = new NBTTagCompound();
NBTTagList itemList = new NBTTagList();
String type = INVENTORY_CUSTOM;
int size = inventory.getSize();
if (inventory instanceof PlayerInventory) {
PlayerInventory playerInventory = (PlayerInventory) inventory;
root.setInt(NBT_PLAYER_HELD_INDEX, playerInventory.getHeldItemSlot());
root.setString(NBT_PLAYER_NAME, playerInventory.getHolder().getName());
type = INVENTORY_PLAYER;
size += 4;
}
for (int i = 0; i < size; ++i) {
NBTTagCompound outputObject = new NBTTagCompound();
CraftItemStack craft = ItemSerialization.getCraftVersion(inventory.getItem(i));
net.minecraft.server.v1_8_R3.ItemStack nmsCopy = CraftItemStack.asNMSCopy((ItemStack) craft);
if (nmsCopy != null) {
nmsCopy.save(outputObject);
}
itemList.add((NBTBase) outputObject);
}
root.setString(NBT_TYPE, type);
root.setInt(NBT_VERSION, 1);
root.set(NBT_ITEMS, (NBTBase) itemList);
ItemSerialization.writeNbt((NBTBase) root, dataOutput);
string = Base64Coder.encodeLines((byte[]) outputStream.toByteArray());
if (Collections.singletonList(dataOutput).get(0) == null) break block13;
} catch (Throwable throwable) {
if (Collections.singletonList(dataOutput).get(0) != null) {
dataOutput.close();
}
throw throwable;
}
dataOutput.close();
}
return string;
} finally {
if (Collections.singletonList(outputStream).get(0) != null) {
outputStream.close();
}
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static Inventory fromBase64(String data, String name, int size) {
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines((String) data));
NBTTagCompound root = (NBTTagCompound) ItemSerialization.readNbt(new DataInputStream(inputStream), 0);
if (root.getInt(NBT_VERSION) != 1) {
throw new IllegalArgumentException("Incompatible version: " + root.getInt(NBT_VERSION));
}
NBTTagList itemList = root.getList(NBT_ITEMS, 10);
String type = root.getString(NBT_TYPE);
return ItemSerialization.parseInventory(root, size, itemList, type, name);
}
private static Inventory parseInventory(NBTTagCompound root, int size, NBTTagList itemList, String type, String name) {
CraftInventoryCustom inventory = new CraftInventoryCustom(null, size, name);
for (int i = 0; i < itemList.size(); ++i) {
NBTTagCompound inputObject = itemList.get(i);
if (inputObject.isEmpty()) continue;
inventory.setItem(i, (ItemStack) CraftItemStack.asCraftMirror((net.minecraft.server.v1_8_R3.ItemStack) net.minecraft.server.v1_8_R3.ItemStack.createStack((NBTTagCompound) inputObject)));
}
return inventory;
}
private static void writeNbt(NBTBase base, DataOutput output) {
if (WRITE_NBT == null) {
try {
WRITE_NBT = NBTCompressedStreamTools.class.getDeclaredMethod("a", NBTBase.class, DataOutput.class);
WRITE_NBT.setAccessible(true);
} catch (Exception e) {
throw new IllegalStateException("Unable to find private write method.", e);
}
}
try {
WRITE_NBT.invoke(null, new Object[]{base, output});
} catch (Exception e) {
throw new IllegalArgumentException("Unable to write " + (Object) base + " to " + output, e);
}
}
private static NBTBase readNbt(DataInput input, int level) {
if (READ_NBT == null) {
try {
READ_NBT = NBTCompressedStreamTools.class.getDeclaredMethod("a", DataInput.class, Integer.TYPE, NBTReadLimiter.class);
READ_NBT.setAccessible(true);
} catch (Exception e) {
throw new IllegalStateException("Unable to find private read method.", e);
}
}
try {
return (NBTBase) READ_NBT.invoke(null, new Object[]{input, level, NBTReadLimiter.a});
} catch (Exception e) {
throw new IllegalArgumentException("Unable to read from " + input, e);
}
}
public static Inventory getInventoryFromArray(ItemStack[] items) {
CraftInventoryCustom custom = new CraftInventoryCustom(null, items.length);
for (int i = 0; i < items.length; ++i) {
if (items[i] == null) continue;
custom.setItem(i, items[i]);
}
return custom;
}
private static CraftItemStack getCraftVersion(ItemStack stack) {
if (stack instanceof CraftItemStack) {
return (CraftItemStack) stack;
}
if (stack != null) {
return CraftItemStack.asCraftCopy((ItemStack) stack);
}
return null;
}
}
@@ -0,0 +1,75 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* net.minecraft.server.v1_8_R3.ItemStack
* net.minecraft.server.v1_8_R3.NBTBase
* net.minecraft.server.v1_8_R3.NBTTagCompound
* org.bukkit.Material
* org.bukkit.craftbukkit.v1_8_R3.me.astropvp.cratekeys.inventory.CraftItemStack
* org.bukkit.me.astropvp.cratekeys.inventory.ItemStack
* org.bukkit.me.astropvp.cratekeys.inventory.meta.ItemMeta
*/
package me.recolance.auction.util;
import net.minecraft.server.v1_8_R3.ItemStack;
import net.minecraft.server.v1_8_R3.NBTBase;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.Arrays;
public class ItemUtils {
public static org.bukkit.inventory.ItemStack buildItem(Material m, short metaData, String name, String... description) {
org.bukkit.inventory.ItemStack is = new org.bukkit.inventory.ItemStack(m, 1, metaData);
ItemMeta im = is.getItemMeta();
if (name != null) {
im.setDisplayName(name);
}
if (description != null) {
im.setLore(Arrays.asList(description));
}
is.setItemMeta(im);
return is;
}
public static org.bukkit.inventory.ItemStack setNBTString(org.bukkit.inventory.ItemStack item, String key, String data) {
ItemStack nmsItem = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) item);
NBTTagCompound compound = nmsItem.getTag();
if (compound == null) {
compound = new NBTTagCompound();
}
compound.setString(key, data);
nmsItem.setTag(compound);
return CraftItemStack.asCraftMirror((ItemStack) nmsItem);
}
public static org.bukkit.inventory.ItemStack setFakeEnchantment(org.bukkit.inventory.ItemStack item, boolean enchant) {
if (!enchant) {
return item;
}
ItemStack nmsItem = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) item);
NBTTagCompound compound = nmsItem.getTag();
if (compound == null) {
compound = new NBTTagCompound();
}
compound.set("ench", (NBTBase) new NBTTagCompound());
nmsItem.setTag(compound);
return CraftItemStack.asCraftMirror((ItemStack) nmsItem);
}
public static String getNBTString(org.bukkit.inventory.ItemStack item, String key) {
ItemStack nmsItem = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) item);
NBTTagCompound compound = nmsItem.getTag();
if (compound == null) {
return null;
}
if (!compound.hasKey(key)) {
return null;
}
return compound.getString(key);
}
}
@@ -0,0 +1,158 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* org.bukkit.Bukkit
* org.bukkit.ChatColor
* org.bukkit.Material
* org.bukkit.entity.Player
* org.bukkit.me.astropvp.cratekeys.inventory.ItemStack
* org.bukkit.plugin.Plugin
*/
package me.recolance.auction.util;
import me.recolance.auction.Auction;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import java.text.DecimalFormat;
import java.util.regex.Pattern;
public class Util {
private static DecimalFormat format = new DecimalFormat("#,###");
public static String setStringColors(String message) {
return ChatColor.translateAlternateColorCodes((char) '&', (String) message);
}
public static void message(Player player, String message) {
player.sendMessage(ChatColor.translateAlternateColorCodes((char) '&', (String) message));
}
public static String formatMoney(long value) {
return format.format(value);
}
public static String formatMoney(double value) {
return format.format(value);
}
public static void closePlayerInventoryOnClick(Player p) {
Bukkit.getScheduler().runTaskLater((Plugin) Auction.getPlugin(), ((Player) p)::closeInventory, 1L);
}
public static Long parseLongOrNull(String strg) {
try {
return Long.parseLong(strg);
} catch (Exception exception) {
return null;
}
}
public static long getMoneyValue(String formatted_value) {
String numb_val = ChatColor.stripColor((String) formatted_value.replaceAll(",", "").replace("$", "")).toLowerCase();
numb_val = numb_val.replace("k", "000");
numb_val = numb_val.replace("million", "000000");
numb_val = numb_val.replace("billion", "000000000");
numb_val = numb_val.replace("trillion", "000000000000");
numb_val = numb_val.replace("mil", "000000");
numb_val = numb_val.replace("bil", "000000000");
numb_val = numb_val.replace("tril", "000000000000");
numb_val = numb_val.replace("m", "000000");
numb_val = numb_val.replace("b", "000000000");
numb_val = numb_val.replace("t", "000000000000");
return Long.parseLong(numb_val);
}
public static boolean hasInventorySpace(Player player) {
for (ItemStack item : player.getInventory().getContents()) {
if (item != null && item.getType() != Material.AIR) continue;
return true;
}
return false;
}
public static int getFreeInventorySpace(Player player) {
int i = 0;
for (ItemStack item : player.getInventory().getContents()) {
if (item != null && item.getType() != Material.AIR) continue;
++i;
}
return i;
}
public static boolean itemLoreContains(ItemStack i, String s) {
if (i == null || !i.hasItemMeta() || !i.getItemMeta().hasLore()) {
return false;
}
for (String lore : i.getItemMeta().getLore()) {
if (!lore.equals(s)) continue;
return true;
}
return false;
}
public static String getItemName(ItemStack item) {
if (item.hasItemMeta() && item.getItemMeta().hasDisplayName()) {
return item.getItemMeta().getDisplayName();
}
String name = item.getType().name();
name = name.replace('_', ' ');
StringBuilder sb = new StringBuilder(name = name.toLowerCase());
if (sb.length() > 0) {
sb.setCharAt(0, Character.toUpperCase(name.charAt(0)));
}
int i = 0;
for (char character : name.toCharArray()) {
if (character == ' ') {
sb.setCharAt(i + 1, Character.toUpperCase(sb.charAt(i + 1)));
}
++i;
}
return sb.toString();
}
public static boolean stringIsNumerical(String string) {
Pattern pattern = Pattern.compile("[^0-9]");
return !pattern.matcher(string).find();
}
public static String getRemainingTimeString(long startTime, long lengthOfTime) {
return Util.timeToDHMSString(startTime - System.currentTimeMillis() + lengthOfTime);
}
public static String timeToDHMSString(long time) {
int second = 1000;
int minute = second * 60;
int hour = minute * 60;
int day = hour * 24;
long playTimeManipulator = time;
StringBuilder timeString = new StringBuilder();
if (playTimeManipulator >= (long) day) {
long finalDay = playTimeManipulator / (long) day;
playTimeManipulator -= finalDay * (long) day;
timeString.append(finalDay + (finalDay > 1L ? "d " : "d "));
}
if (playTimeManipulator >= (long) hour) {
long finalHour = playTimeManipulator / (long) hour;
playTimeManipulator -= finalHour * (long) hour;
timeString.append(finalHour + (finalHour > 1L ? "h " : "h "));
}
if (playTimeManipulator >= (long) minute) {
long finalMinute = playTimeManipulator / (long) minute;
playTimeManipulator -= finalMinute * (long) minute;
timeString.append(finalMinute + (finalMinute > 1L ? "m " : "m "));
}
if (playTimeManipulator >= (long) second) {
long finalSecond = playTimeManipulator / (long) second;
playTimeManipulator -= finalSecond * (long) second;
timeString.append(finalSecond + (finalSecond > 1L ? "s" : "s"));
}
return timeString.toString();
}
}
@@ -0,0 +1,311 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* com.google.common.base.Function
* com.google.common.base.Objects
* com.google.common.base.Preconditions
* com.google.common.collect.Iterators
* com.google.common.collect.Maps
* javax.annotation.Nonnull
* javax.annotation.Nullable
* org.bukkit.me.astropvp.cratekeys.inventory.ItemStack
*/
package me.recolance.globalutils.attribute;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterators;
import com.google.common.collect.Maps;
import org.bukkit.inventory.ItemStack;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Iterator;
import java.util.UUID;
import java.util.concurrent.ConcurrentMap;
public class Attributes {
public ItemStack stack;
private NbtFactory.NbtList attributes;
public Attributes(ItemStack stack) {
this.stack = NbtFactory.getCraftItemStack(stack);
NbtFactory.NbtCompound nbt = NbtFactory.fromItemTag(this.stack);
this.attributes = nbt.getList("AttributeModifiers", true);
}
public ItemStack getStack() {
return this.stack;
}
public int size() {
return this.attributes.size();
}
public void add(Attribute attribute) {
Preconditions.checkNotNull((Object) attribute.getName(), (Object) "must specify an attribute name.");
this.attributes.add(attribute.data);
}
public boolean remove(Attribute attribute) {
UUID uuid = attribute.getUUID();
Iterator<Attribute> it = this.values().iterator();
while (it.hasNext()) {
if (!Objects.equal((Object) it.next().getUUID(), (Object) uuid)) continue;
it.remove();
return true;
}
return false;
}
public void clear() {
this.attributes.clear();
}
public Attribute get(int index) {
return new Attribute((NbtFactory.NbtCompound) this.attributes.get(index));
}
public Iterable<Attribute> values() {
return new Iterable<Attribute>() {
@Override
public Iterator<Attribute> iterator() {
return Iterators.transform(Attributes.this.attributes.iterator(), (Function) new Function<Object, Attribute>() {
public Attribute apply(@Nullable Object element) {
return new Attribute((NbtFactory.NbtCompound) element);
}
});
}
};
}
public static enum Operation {
ADD_NUMBER(0),
MULTIPLY_PERCENTAGE(1),
ADD_PERCENTAGE(2);
private int id;
private Operation(int id) {
this.id = id;
}
public static Operation fromId(int id) {
for (Operation op : Operation.values()) {
if (op.getId() != id) continue;
return op;
}
throw new IllegalArgumentException("Corrupt operation ID " + id + " detected.");
}
public int getId() {
return this.id;
}
}
public static class Attribute {
private NbtFactory.NbtCompound data;
private Attribute(Builder builder) {
this.data = NbtFactory.createCompound();
this.setAmount(builder.amount);
this.setOperation(builder.operation);
this.setAttributeType(builder.type);
this.setName(builder.name);
this.setUUID(builder.uuid);
}
private Attribute(NbtFactory.NbtCompound data) {
this.data = data;
}
public static Builder newBuilder() {
return new Builder().uuid(UUID.randomUUID()).operation(Operation.ADD_NUMBER);
}
private static /* synthetic */ void $$$reportNull$$$0(int n) {
Object[] arrobject;
Object[] arrobject2;
Object[] arrobject3 = new Object[3];
switch (n) {
default: {
arrobject2 = arrobject3;
arrobject3[0] = "operation";
break;
}
case 1: {
arrobject2 = arrobject3;
arrobject3[0] = "type";
break;
}
case 2: {
arrobject2 = arrobject3;
arrobject3[0] = "name";
break;
}
case 3: {
arrobject2 = arrobject3;
arrobject3[0] = "id";
break;
}
}
arrobject2[1] = "me/recolance/globalutils/attribute/Attributes$Attribute";
switch (n) {
default: {
arrobject = arrobject2;
arrobject2[2] = "setOperation";
break;
}
case 1: {
arrobject = arrobject2;
arrobject2[2] = "setAttributeType";
break;
}
case 2: {
arrobject = arrobject2;
arrobject2[2] = "setName";
break;
}
case 3: {
arrobject = arrobject2;
arrobject2[2] = "setUUID";
break;
}
}
throw new IllegalArgumentException(String.format("Argument for @Nonnull parameter '%s' of %s.%s must not be null", arrobject));
}
public double getAmount() {
return this.data.getDouble("Amount", 0.0);
}
public void setAmount(double amount) {
this.data.put("Amount", (Object) amount);
}
public Operation getOperation() {
return Operation.fromId(this.data.getInteger("Operation", 0));
}
public void setOperation(@Nonnull Operation operation) {
if (operation == null) {
Attribute.$$$reportNull$$$0(0);
}
Preconditions.checkNotNull((Object) ((Object) operation), (Object) "operation cannot be NULL.");
this.data.put("Operation", (Object) operation.getId());
}
public AttributeType getAttributeType() {
return AttributeType.fromId(this.data.getString("AttributeName", null));
}
public void setAttributeType(@Nonnull AttributeType type) {
if (type == null) {
Attribute.$$$reportNull$$$0(1);
}
Preconditions.checkNotNull((Object) type, (Object) "type cannot be NULL.");
this.data.put("AttributeName", (Object) type.getMinecraftId());
}
public String getName() {
return this.data.getString("Name", null);
}
public void setName(@Nonnull String name) {
if (name == null) {
Attribute.$$$reportNull$$$0(2);
}
Preconditions.checkNotNull((Object) name, (Object) "name cannot be NULL.");
this.data.put("Name", (Object) name);
}
public UUID getUUID() {
return new UUID(this.data.getLong("UUIDMost", null), this.data.getLong("UUIDLeast", null));
}
public void setUUID(@Nonnull UUID id) {
if (id == null) {
Attribute.$$$reportNull$$$0(3);
}
Preconditions.checkNotNull((Object) "id", (Object) "id cannot be NULL.");
this.data.put("UUIDLeast", (Object) id.getLeastSignificantBits());
this.data.put("UUIDMost", (Object) id.getMostSignificantBits());
}
public static class Builder {
private double amount;
private Operation operation = Operation.ADD_NUMBER;
private AttributeType type;
private String name;
private UUID uuid;
private Builder() {
}
public Builder amount(double amount) {
this.amount = amount;
return this;
}
public Builder operation(Operation operation) {
this.operation = operation;
return this;
}
public Builder type(AttributeType type) {
this.type = type;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder uuid(UUID uuid) {
this.uuid = uuid;
return this;
}
public Attribute build() {
return new Attribute(this);
}
}
}
public static class AttributeType {
private static ConcurrentMap<String, AttributeType> LOOKUP = Maps.newConcurrentMap();
public static final AttributeType GENERIC_MAX_HEALTH = new AttributeType("generic.maxHealth").register();
public static final AttributeType GENERIC_FOLLOW_RANGE = new AttributeType("generic.followRange").register();
public static final AttributeType GENERIC_ATTACK_DAMAGE = new AttributeType("generic.attackDamage").register();
public static final AttributeType GENERIC_MOVEMENT_SPEED = new AttributeType("generic.movementSpeed").register();
public static final AttributeType GENERIC_KNOCKBACK_RESISTANCE = new AttributeType("generic.knockbackResistance").register();
private final String minecraftId;
public AttributeType(String minecraftId) {
this.minecraftId = minecraftId;
}
public static AttributeType fromId(String minecraftId) {
return (AttributeType) LOOKUP.get(minecraftId);
}
public static Iterable<AttributeType> values() {
return LOOKUP.values();
}
public String getMinecraftId() {
return this.minecraftId;
}
public AttributeType register() {
AttributeType old = LOOKUP.putIfAbsent(this.minecraftId, this);
return old != null ? old : this;
}
}
}
@@ -0,0 +1,750 @@
/*
* Decompiled with CFR 0.150.
*
* Could not load the following classes:
* com.google.common.base.Splitter
* com.google.common.collect.BiMap
* com.google.common.collect.HashBiMap
* com.google.common.collect.Lists
* com.google.common.collect.MapMaker
* com.google.common.io.Closeables
* com.google.common.io.InputSupplier
* com.google.common.io.OutputSupplier
* com.google.common.primitives.Primitives
* org.bukkit.Bukkit
* org.bukkit.Material
* org.bukkit.Server
* org.bukkit.inventory.ItemStack
*/
package me.recolance.globalutils.attribute;
import com.google.common.base.Splitter;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Lists;
import com.google.common.collect.MapMaker;
import com.google.common.io.Closeables;
import com.google.common.io.InputSupplier;
import com.google.common.io.OutputSupplier;
import com.google.common.primitives.Primitives;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.ConcurrentMap;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
public class NbtFactory {
private static final BiMap<Integer, Class<?>> NBT_CLASS = HashBiMap.create();
private static final BiMap<Integer, NbtType> NBT_ENUM = HashBiMap.create();
private static NbtFactory INSTANCE;
private final Field[] DATA_FIELD = new Field[12];
private Class<?> BASE_CLASS;
private Class<?> COMPOUND_CLASS;
private Class<?> STREAM_TOOLS;
private Class<?> READ_LIMITER_CLASS;
private Method NBT_CREATE_TAG;
private Method NBT_GET_TYPE;
private Field NBT_LIST_TYPE;
private Class<?> CRAFT_STACK;
private Field CRAFT_HANDLE;
private Field STACK_TAG;
private LoadCompoundMethod LOAD_COMPOUND;
private Method SAVE_COMPOUND;
private NbtFactory() {
if (this.BASE_CLASS == null) {
try {
ClassLoader loader = NbtFactory.class.getClassLoader();
String packageName = this.getPackageName();
Class<?> offlinePlayer = loader.loadClass(packageName + ".CraftOfflinePlayer");
this.COMPOUND_CLASS = NbtFactory.getMethod(0, 8, offlinePlayer, "getData", new Class[0]).getReturnType();
this.BASE_CLASS = this.COMPOUND_CLASS.getSuperclass();
this.NBT_GET_TYPE = NbtFactory.getMethod(0, 8, this.BASE_CLASS, "getTypeId", new Class[0]);
this.NBT_CREATE_TAG = NbtFactory.getMethod(8, 0, this.BASE_CLASS, "createTag", Byte.TYPE);
this.CRAFT_STACK = loader.loadClass(packageName + ".inventory.CraftItemStack");
this.CRAFT_HANDLE = NbtFactory.getField(null, this.CRAFT_STACK, "handle");
this.STACK_TAG = NbtFactory.getField(null, this.CRAFT_HANDLE.getType(), "tag");
String nmsPackage = this.BASE_CLASS.getPackage().getName();
this.initializeNMS(loader, nmsPackage);
this.LOAD_COMPOUND = this.READ_LIMITER_CLASS != null ? new LoadMethodSkinUpdate(this.STREAM_TOOLS, this.READ_LIMITER_CLASS) : new LoadMethodWorldUpdate(this.STREAM_TOOLS);
this.SAVE_COMPOUND = NbtFactory.getMethod(8, 0, this.STREAM_TOOLS, null, this.BASE_CLASS, DataOutput.class);
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Unable to find offline player.", e);
}
}
}
private static NbtFactory get() {
if (INSTANCE == null) {
INSTANCE = new NbtFactory();
}
return INSTANCE;
}
public static NbtList createList(Object... content) {
return NbtFactory.createList(Arrays.asList(content));
}
public static NbtList createList(Iterable<? extends Object> iterable) {
NbtFactory nbtFactory = NbtFactory.get();
nbtFactory.getClass();
NbtList list = nbtFactory.new NbtList(INSTANCE.createNbtTag(NbtType.TAG_LIST, null));
for (Object object : iterable) {
list.add(object);
}
return list;
}
public static NbtCompound createCompound() {
NbtFactory nbtFactory = NbtFactory.get();
nbtFactory.getClass();
return nbtFactory.new NbtCompound(INSTANCE.createNbtTag(NbtType.TAG_COMPOUND, null));
}
public static NbtList fromList(Object nmsList) {
NbtFactory nbtFactory = NbtFactory.get();
nbtFactory.getClass();
return nbtFactory.new NbtList(nmsList);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public static NbtCompound fromStream(InputSupplier<? extends InputStream> stream, StreamOptions option) throws IOException {
NbtCompound nbtCompound;
block7:
{
boolean suppress;
InputStream input;
block6:
{
input = null;
DataInputStream data = null;
suppress = true;
try {
input = (InputStream) stream.getInput();
data = new DataInputStream(new BufferedInputStream(option == StreamOptions.GZIP_COMPRESSION ? new GZIPInputStream(input) : input));
NbtCompound result = NbtFactory.fromCompound(NbtFactory.get().LOAD_COMPOUND.loadNbt(data));
suppress = false;
nbtCompound = result;
if (data == null) break block6;
} catch (Throwable throwable) {
if (data != null) {
Closeables.close(data, (boolean) suppress);
} else if (input != null) {
Closeables.close((Closeable) input, (boolean) suppress);
}
throw throwable;
}
Closeables.close((Closeable) data, (boolean) suppress);
break block7;
}
if (input != null) {
Closeables.close((Closeable) input, (boolean) suppress);
}
}
return nbtCompound;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public static void saveStream(NbtCompound source, OutputSupplier<? extends OutputStream> stream, StreamOptions option) throws IOException {
block7:
{
boolean suppress;
OutputStream output;
block6:
{
output = null;
DataOutputStream data = null;
suppress = true;
try {
output = (OutputStream) stream.getOutput();
data = new DataOutputStream(option == StreamOptions.GZIP_COMPRESSION ? new GZIPOutputStream(output) : output);
NbtFactory.invokeMethod(NbtFactory.get().SAVE_COMPOUND, null, source.getHandle(), data);
suppress = false;
if (data == null) break block6;
} catch (Throwable throwable) {
if (data != null) {
Closeables.close(data, (boolean) suppress);
} else if (output != null) {
Closeables.close((Closeable) output, (boolean) suppress);
}
throw throwable;
}
Closeables.close((Closeable) data, (boolean) suppress);
break block7;
}
if (output != null) {
Closeables.close((Closeable) output, (boolean) suppress);
}
}
}
public static NbtCompound fromCompound(Object nmsCompound) {
NbtFactory nbtFactory = NbtFactory.get();
nbtFactory.getClass();
return nbtFactory.new NbtCompound(nmsCompound);
}
public static void setItemTag(ItemStack stack, NbtCompound compound) {
NbtFactory.checkItemStack(stack);
Object nms = NbtFactory.getFieldValue(NbtFactory.get().CRAFT_HANDLE, (Object) stack);
NbtFactory.setFieldValue(NbtFactory.get().STACK_TAG, nms, compound.getHandle());
}
public static NbtCompound fromItemTag(ItemStack stack) {
NbtFactory.checkItemStack(stack);
Object nms = NbtFactory.getFieldValue(NbtFactory.get().CRAFT_HANDLE, (Object) stack);
Object tag = NbtFactory.getFieldValue(NbtFactory.get().STACK_TAG, nms);
if (tag == null) {
NbtCompound compound = NbtFactory.createCompound();
NbtFactory.setItemTag(stack, compound);
return compound;
}
return NbtFactory.fromCompound(tag);
}
public static ItemStack getCraftItemStack(ItemStack stack) {
if (stack == null || NbtFactory.get().CRAFT_STACK.isAssignableFrom(stack.getClass())) {
return stack;
}
try {
Constructor<?> caller = NbtFactory.INSTANCE.CRAFT_STACK.getDeclaredConstructor(ItemStack.class);
caller.setAccessible(true);
return (ItemStack) caller.newInstance(new Object[]{stack});
} catch (Exception e) {
throw new IllegalStateException("Unable to convert " + (Object) stack + " + to a CraftItemStack.");
}
}
private static void checkItemStack(ItemStack stack) {
if (stack == null) {
throw new IllegalArgumentException("Stack cannot be NULL.");
}
if (!NbtFactory.get().CRAFT_STACK.isAssignableFrom(stack.getClass())) {
throw new IllegalArgumentException("Stack must be a CraftItemStack.");
}
if (stack.getType() == Material.AIR) {
throw new IllegalArgumentException("ItemStacks representing air cannot store NMS information.");
}
}
private static Object invokeMethod(Method method, Object target, Object... params) {
try {
return method.invoke(target, params);
} catch (Exception e) {
throw new RuntimeException("Unable to invoke method " + method + " for " + target, e);
}
}
private static void setFieldValue(Field field, Object target, Object value) {
try {
field.set(target, value);
} catch (Exception e) {
throw new RuntimeException("Unable to set " + field + " for " + target, e);
}
}
private static Object getFieldValue(Field field, Object target) {
try {
return field.get(target);
} catch (Exception e) {
throw new RuntimeException("Unable to retrieve " + field + " for " + target, e);
}
}
private static Method getMethod(int requireMod, int bannedMod, Class<?> clazz, String methodName, Class<?>... params) {
for (Method method : clazz.getDeclaredMethods()) {
if ((method.getModifiers() & requireMod) != requireMod || (method.getModifiers() & bannedMod) != 0 || methodName != null && !method.getName().equals(methodName) || !Arrays.equals(method.getParameterTypes(), params))
continue;
method.setAccessible(true);
return method;
}
if (clazz.getSuperclass() != null) {
return NbtFactory.getMethod(requireMod, bannedMod, clazz.getSuperclass(), methodName, params);
}
throw new IllegalStateException(String.format("Unable to find method %s (%s).", methodName, Arrays.asList(params)));
}
private static Field getField(Object instance, Class<?> clazz, String fieldName) {
if (clazz == null) {
clazz = instance.getClass();
}
for (Field field : clazz.getDeclaredFields()) {
if (!field.getName().equals(fieldName)) continue;
field.setAccessible(true);
return field;
}
if (clazz.getSuperclass() != null) {
return NbtFactory.getField(instance, clazz.getSuperclass(), fieldName);
}
throw new IllegalStateException("Unable to find field " + fieldName + " in " + instance);
}
private void initializeNMS(ClassLoader loader, String nmsPackage) {
try {
this.STREAM_TOOLS = loader.loadClass(nmsPackage + ".NBTCompressedStreamTools");
this.READ_LIMITER_CLASS = loader.loadClass(nmsPackage + ".NBTReadLimiter");
} catch (ClassNotFoundException classNotFoundException) {
// empty catch block
}
}
private String getPackageName() {
String name;
Server server = Bukkit.getServer();
String string = name = server != null ? server.getClass().getPackage().getName() : null;
if (name != null && name.contains("craftbukkit")) {
return name;
}
return "org.bukkit.craftbukkit.v1_7_R3";
}
private Map<String, Object> getDataMap(Object handle) {
return (Map) NbtFactory.getFieldValue(this.getDataField(NbtType.TAG_COMPOUND, handle), handle);
}
private List<Object> getDataList(Object handle) {
return (List) NbtFactory.getFieldValue(this.getDataField(NbtType.TAG_LIST, handle), handle);
}
private Object unwrapValue(Object value) {
if (value == null) {
return null;
}
if (value instanceof Wrapper) {
return ((Wrapper) value).getHandle();
}
if (value instanceof List) {
throw new IllegalArgumentException("Can only insert a WrappedList.");
}
if (value instanceof Map) {
throw new IllegalArgumentException("Can only insert a WrappedCompound.");
}
return this.createNbtTag(this.getPrimitiveType(value), value);
}
private Object wrapNative(Object nms) {
if (nms == null) {
return null;
}
if (this.BASE_CLASS.isAssignableFrom(nms.getClass())) {
NbtType type = this.getNbtType(nms);
switch (type) {
case TAG_COMPOUND: {
return new NbtCompound(nms);
}
case TAG_LIST: {
return new NbtList(nms);
}
}
return NbtFactory.getFieldValue(this.getDataField(type, nms), nms);
}
throw new IllegalArgumentException("Unexpected type: " + nms);
}
private Object createNbtTag(NbtType type, Object value) {
Object tag = NbtFactory.invokeMethod(this.NBT_CREATE_TAG, null, (byte) type.id);
if (value != null) {
NbtFactory.setFieldValue(this.getDataField(type, tag), tag, value);
}
return tag;
}
private Field getDataField(NbtType type, Object nms) {
if (this.DATA_FIELD[type.id] == null) {
this.DATA_FIELD[type.id] = NbtFactory.getField(nms, null, type.getFieldName());
}
return this.DATA_FIELD[type.id];
}
private NbtType getNbtType(Object nms) {
byte type = (Byte) NbtFactory.invokeMethod(this.NBT_GET_TYPE, nms, new Object[0]);
return (NbtType) ((Object) NBT_ENUM.get((Object) type));
}
private NbtType getPrimitiveType(Object primitive) {
NbtType type = (NbtType) ((Object) NBT_ENUM.get(NBT_CLASS.inverse().get((Object) Primitives.unwrap(primitive.getClass()))));
if (type == null) {
throw new IllegalArgumentException(String.format("Illegal type: %s (%s)", primitive.getClass(), primitive));
}
return type;
}
private static enum NbtType {
TAG_END(0, Void.class),
TAG_BYTE(1, Byte.TYPE),
TAG_SHORT(2, Short.TYPE),
TAG_INT(3, Integer.TYPE),
TAG_LONG(4, Long.TYPE),
TAG_FLOAT(5, Float.TYPE),
TAG_DOUBLE(6, Double.TYPE),
TAG_BYTE_ARRAY(7, byte[].class),
TAG_INT_ARRAY(11, int[].class),
TAG_STRING(8, String.class),
TAG_LIST(9, List.class),
TAG_COMPOUND(10, Map.class);
public final int id;
private NbtType(int id, Class<?> type) {
this.id = id;
NBT_CLASS.put(id, type);
NBT_ENUM.put(id, this);
}
private String getFieldName() {
if (this == TAG_COMPOUND) {
return "map";
}
if (this == TAG_LIST) {
return "list";
}
return "data";
}
}
public static enum StreamOptions {
NO_COMPRESSION,
GZIP_COMPRESSION;
}
public static interface Wrapper {
public Object getHandle();
}
private static class LoadMethodSkinUpdate
extends LoadCompoundMethod {
private Object readLimiter;
public LoadMethodSkinUpdate(Class<?> streamClass, Class<?> readLimiterClass) {
this.setMethod(NbtFactory.getMethod(8, 0, streamClass, null, new Class[]{DataInput.class, readLimiterClass}));
for (Field field : readLimiterClass.getDeclaredFields()) {
if (!readLimiterClass.isAssignableFrom(field.getType())) continue;
try {
this.readLimiter = field.get(null);
} catch (Exception e) {
throw new RuntimeException("Cannot retrieve read limiter.", e);
}
}
}
@Override
public Object loadNbt(DataInput input) {
return NbtFactory.invokeMethod(this.staticMethod, null, new Object[]{input, this.readLimiter});
}
}
private static class LoadMethodWorldUpdate
extends LoadCompoundMethod {
public LoadMethodWorldUpdate(Class<?> streamClass) {
this.setMethod(NbtFactory.getMethod(8, 0, streamClass, null, new Class[]{DataInput.class}));
}
@Override
public Object loadNbt(DataInput input) {
return NbtFactory.invokeMethod(this.staticMethod, null, new Object[]{input});
}
}
private static abstract class LoadCompoundMethod {
protected Method staticMethod;
private LoadCompoundMethod() {
}
protected void setMethod(Method method) {
this.staticMethod = method;
this.staticMethod.setAccessible(true);
}
public abstract Object loadNbt(DataInput var1);
}
private class ConvertedList
extends AbstractList<Object>
implements Wrapper {
private final Object handle;
private final List<Object> original;
private final CachedNativeWrapper cache;
public ConvertedList(Object handle, List<Object> original) {
this.cache = new CachedNativeWrapper();
if (NbtFactory.this.NBT_LIST_TYPE == null) {
NbtFactory.this.NBT_LIST_TYPE = NbtFactory.getField(handle, null, "type");
}
this.handle = handle;
this.original = original;
}
protected Object wrapOutgoing(Object value) {
return this.cache.wrap(value);
}
protected Object unwrapIncoming(Object wrapped) {
return NbtFactory.this.unwrapValue(wrapped);
}
@Override
public Object get(int index) {
return this.wrapOutgoing(this.original.get(index));
}
@Override
public int size() {
return this.original.size();
}
@Override
public Object set(int index, Object element) {
return this.wrapOutgoing(this.original.set(index, this.unwrapIncoming(element)));
}
@Override
public void add(int index, Object element) {
Object nbt = this.unwrapIncoming(element);
if (this.size() == 0) {
NbtFactory.setFieldValue(NbtFactory.this.NBT_LIST_TYPE, this.handle, (byte) ((NbtFactory) NbtFactory.this).getNbtType((Object) nbt).id);
}
this.original.add(index, nbt);
}
@Override
public Object remove(int index) {
return this.wrapOutgoing(this.original.remove(index));
}
@Override
public boolean remove(Object o) {
return this.original.remove(this.unwrapIncoming(o));
}
@Override
public Object getHandle() {
return this.handle;
}
}
private class ConvertedMap
extends AbstractMap<String, Object>
implements Wrapper {
private final Object handle;
private final Map<String, Object> original;
private final CachedNativeWrapper cache;
public ConvertedMap(Object handle, Map<String, Object> original) {
this.cache = new CachedNativeWrapper();
this.handle = handle;
this.original = original;
}
protected Object wrapOutgoing(Object value) {
return this.cache.wrap(value);
}
protected Object unwrapIncoming(Object wrapped) {
return NbtFactory.this.unwrapValue(wrapped);
}
@Override
public Object put(String key, Object value) {
return this.wrapOutgoing(this.original.put(key, this.unwrapIncoming(value)));
}
@Override
public Object get(Object key) {
return this.wrapOutgoing(this.original.get(key));
}
@Override
public Object remove(Object key) {
return this.wrapOutgoing(this.original.remove(key));
}
@Override
public boolean containsKey(Object key) {
return this.original.containsKey(key);
}
@Override
public Set<Entry<String, Object>> entrySet() {
return new AbstractSet<Entry<String, Object>>() {
@Override
public boolean add(Entry<String, Object> e) {
String key = e.getKey();
Object value = e.getValue();
ConvertedMap.this.original.put(key, ConvertedMap.this.unwrapIncoming(value));
return true;
}
@Override
public int size() {
return ConvertedMap.this.original.size();
}
@Override
public Iterator<Entry<String, Object>> iterator() {
return ConvertedMap.this.iterator();
}
};
}
private Iterator<Entry<String, Object>> iterator() {
final Iterator<Entry<String, Object>> proxy = this.original.entrySet().iterator();
return new Iterator<Entry<String, Object>>() {
@Override
public boolean hasNext() {
return proxy.hasNext();
}
@Override
public Entry<String, Object> next() {
Entry entry = (Entry) proxy.next();
return new SimpleEntry<String, Object>((String) entry.getKey(), ConvertedMap.this.wrapOutgoing(entry.getValue()));
}
@Override
public void remove() {
proxy.remove();
}
};
}
@Override
public Object getHandle() {
return this.handle;
}
}
private final class CachedNativeWrapper {
private final ConcurrentMap<Object, Object> cache = new MapMaker().weakKeys().makeMap();
private CachedNativeWrapper() {
}
public Object wrap(Object value) {
Object current = this.cache.get(value);
if (current == null && ((current = NbtFactory.this.wrapNative(value)) instanceof ConvertedMap || current instanceof ConvertedList)) {
this.cache.put(value, current);
}
return current;
}
}
public final class NbtList
extends ConvertedList {
private NbtList(Object handle) {
super(handle, NbtFactory.this.getDataList(handle));
}
}
public final class NbtCompound
extends ConvertedMap {
private NbtCompound(Object handle) {
super(handle, NbtFactory.this.getDataMap(handle));
}
public Byte getByte(String key, Byte defaultValue) {
return this.containsKey(key) ? (Byte) this.get(key) : defaultValue;
}
public Short getShort(String key, Short defaultValue) {
return this.containsKey(key) ? (Short) this.get(key) : defaultValue;
}
public Integer getInteger(String key, Integer defaultValue) {
return this.containsKey(key) ? (Integer) this.get(key) : defaultValue;
}
public Long getLong(String key, Long defaultValue) {
return this.containsKey(key) ? (Long) this.get(key) : defaultValue;
}
public Float getFloat(String key, Float defaultValue) {
return this.containsKey(key) ? (Float) this.get(key) : defaultValue;
}
public Double getDouble(String key, Double defaultValue) {
return this.containsKey(key) ? (Double) this.get(key) : defaultValue;
}
public String getString(String key, String defaultValue) {
return this.containsKey(key) ? (String) this.get(key) : defaultValue;
}
public byte[] getByteArray(String key, byte[] defaultValue) {
return this.containsKey(key) ? (byte[]) this.get(key) : defaultValue;
}
public int[] getIntegerArray(String key, int[] defaultValue) {
return this.containsKey(key) ? (int[]) this.get(key) : defaultValue;
}
public NbtList getList(String key, boolean createNew) {
NbtList list = (NbtList) this.get(key);
if (list == null && createNew) {
list = NbtFactory.createList(new Object[0]);
this.put(key, (Object) list);
}
return list;
}
public NbtCompound getMap(String key, boolean createNew) {
return this.getMap(Arrays.asList(key), createNew);
}
public NbtCompound putPath(String path, Object value) {
List<String> entries = this.getPathElements(path);
NbtCompound map = this.getMap(entries.subList(0, entries.size() - 1), true);
map.put(entries.get(entries.size() - 1), value);
return this;
}
public <T> T getPath(String path) {
List<String> entries = this.getPathElements(path);
NbtCompound map = this.getMap(entries.subList(0, entries.size() - 1), false);
if (map != null) {
return (T) map.get(entries.get(entries.size() - 1));
}
return null;
}
public void saveTo(OutputSupplier<? extends OutputStream> stream, StreamOptions option) throws IOException {
NbtFactory.saveStream(this, stream, option);
}
private NbtCompound getMap(Iterable<String> path, boolean createNew) {
NbtCompound current = this;
for (String entry : path) {
NbtCompound child = (NbtCompound) current.get(entry);
if (child == null) {
if (!createNew) {
return null;
}
child = NbtFactory.createCompound();
current.put(entry, (Object) child);
}
current = child;
}
return current;
}
private List<String> getPathElements(String path) {
return Lists.newArrayList((Iterable) Splitter.on((String) ".").omitEmptyStrings().split((CharSequence) path));
}
}
}
@@ -0,0 +1,69 @@
############################################
# Your database information should go here.#
############################################
sql:
host: '127.0.0.1'
port: '3306'
database: 'database'
user: 'user'
pass: 'password'
auction:
#Listing price is the price it costs to list one item on the auction house.
listingPrice: 1000
#Listing hours is the amount of hours a listing is active before being automatically cancelled and expired.
listingMinutes: 15
#Unclaimed hours is the amount of hours a cancelled or expired listing can remain unretrieved for before being removed from the database.
unclaimedHours: 24
#Disallow users in creative mode from listing me.astropvp.cratekeys.items.
preventCreativeSale: true
menuText:
menuName: 'Auction House'
itemsYoureSelling:
name: '&e&lYour Auctions'
lore:
- '&7Click here to view all of the items you'
- '&7are currently selling on the auction.'
- ''
- '&e&l%selling% Item(s)'
collectExpired:
name: '&e&lCollection Bin'
lore:
- '&7Click here to view and collect all of the'
- '&7items you have cancelled or have expired.'
- ''
- '&e&l%expired% Item(s)'
previous:
name: '&e&l<- Previous Page'
lore:
- '&7View the previous page of auctions.'
refresh:
name: '&6&lRefresh Auctions'
lore:
- '&7Click to refresh the currently'
- '&7available auction listings.'
next:
name: '&e&lNext Page ->'
lore:
- '&7View the next page of auctions.'
howToSell:
name: '&e&lHow to Sell'
lore:
- '&7To list an item on the auction house, just hold'
- '&7the item in your hand and type &e/ah sell <price>&7.'
bookButton:
name: '&e&lGuide'
lore:
- '&7This is the auction house, here you can'
- '&7list items for sale, and purchase items'
- '&7that others have listed for sale.'
- ''
- '&7The auction is also a great way to make'
- '&7money by selling farmable items other'
- '&7players may be interested in buying.'
- ''
- '&7All listings last for a max of &e15 minutes'
- '&7unsold items are sent to your collection bin.'
- ''
- '&7For more help, use &e/ah help!'
@@ -0,0 +1,10 @@
name: CrankedAuction
main: me.recolance.auction.Auction
version: 1.1
depend: [Vault, CrankedUtils]
commands:
ah:
aliases: [auction, auctionhouse, auc, bid, bids]
permissions:
auction.admin.expire:
default: op