mirror of
https://github.com/kiranhart/Auction-House.git
synced 2025-01-25 15:41:20 +01:00
sell menu item drops if killed after item is placed in it
Took 17 minutes
This commit is contained in:
parent
68253d35f3
commit
068e21c100
@ -743,6 +743,11 @@ public class AuctionAPI {
|
|||||||
|
|
||||||
// Actually attempt the insertion now
|
// Actually attempt the insertion now
|
||||||
AuctionHouse.getInstance().getDataManager().insertAuctionAsync(auctionedItem, (error, inserted) -> {
|
AuctionHouse.getInstance().getDataManager().insertAuctionAsync(auctionedItem, (error, inserted) -> {
|
||||||
|
|
||||||
|
AuctionPlayer auctionPlayer = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(seller.getUniqueId());
|
||||||
|
if (auctionPlayer != null)
|
||||||
|
auctionPlayer.setItemBeingListed(null);
|
||||||
|
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
AuctionHouse.getInstance().getLocale().getMessage("general.something_went_wrong_while_listing").sendPrefixedMessage(seller);
|
AuctionHouse.getInstance().getLocale().getMessage("general.something_went_wrong_while_listing").sendPrefixedMessage(seller);
|
||||||
ItemStack originalCopy = original.clone();
|
ItemStack originalCopy = original.clone();
|
||||||
|
@ -10,6 +10,7 @@ import lombok.Getter;
|
|||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -35,8 +36,11 @@ public class AuctionPlayer {
|
|||||||
private boolean showListingInfo;
|
private boolean showListingInfo;
|
||||||
private long lastListedItem;
|
private long lastListedItem;
|
||||||
|
|
||||||
|
private ItemStack itemBeingListed;
|
||||||
|
private int assignedTaskId;
|
||||||
|
|
||||||
public AuctionPlayer(UUID uuid) {
|
public AuctionPlayer(UUID uuid) {
|
||||||
this(uuid, Bukkit.getPlayer(uuid), AuctionSaleType.BOTH, AuctionItemCategory.ALL, AuctionSortType.RECENT, "", true, -1);
|
this(uuid, Bukkit.getPlayer(uuid), AuctionSaleType.BOTH, AuctionItemCategory.ALL, AuctionSortType.RECENT, "", true, -1, null,-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuctionPlayer(Player player) {
|
public AuctionPlayer(Player player) {
|
||||||
|
@ -593,7 +593,9 @@ public class DataManager extends DataManagerAbstract {
|
|||||||
AuctionSortType.valueOf(resultSet.getString("filter_sort_type")),
|
AuctionSortType.valueOf(resultSet.getString("filter_sort_type")),
|
||||||
"",
|
"",
|
||||||
true,
|
true,
|
||||||
resultSet.getLong("last_listed_item")
|
resultSet.getLong("last_listed_item"),
|
||||||
|
null,
|
||||||
|
-1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,9 +17,11 @@ import ca.tweetzy.core.input.PlayerChatInput;
|
|||||||
import ca.tweetzy.core.utils.NumberUtils;
|
import ca.tweetzy.core.utils.NumberUtils;
|
||||||
import ca.tweetzy.core.utils.PlayerUtils;
|
import ca.tweetzy.core.utils.PlayerUtils;
|
||||||
import ca.tweetzy.core.utils.TextUtils;
|
import ca.tweetzy.core.utils.TextUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -46,6 +48,7 @@ public class GUISellItem extends AbstractPlaceholderGui {
|
|||||||
private boolean isAllowingBuyNow;
|
private boolean isAllowingBuyNow;
|
||||||
private int auctionTime;
|
private int auctionTime;
|
||||||
|
|
||||||
|
private BukkitTask task;
|
||||||
|
|
||||||
public GUISellItem(AuctionPlayer auctionPlayer, ItemStack itemToBeListed, double buyNowPrice, double bidStartPrice, double bidIncrementPrice, boolean isBiddingItem, boolean isAllowingBuyNow, int auctionTime) {
|
public GUISellItem(AuctionPlayer auctionPlayer, ItemStack itemToBeListed, double buyNowPrice, double bidStartPrice, double bidIncrementPrice, boolean isBiddingItem, boolean isAllowingBuyNow, int auctionTime) {
|
||||||
super(auctionPlayer);
|
super(auctionPlayer);
|
||||||
@ -84,9 +87,14 @@ public class GUISellItem extends AbstractPlaceholderGui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AuctionHouse.getInstance().getAuctionPlayerManager().addToUsingSellGUI(open.player.getUniqueId());
|
AuctionHouse.getInstance().getAuctionPlayerManager().addToUsingSellGUI(open.player.getUniqueId());
|
||||||
|
|
||||||
|
makeMess();
|
||||||
});
|
});
|
||||||
|
|
||||||
setOnClose(close -> {
|
setOnClose(close -> {
|
||||||
|
|
||||||
|
cleanup();
|
||||||
|
|
||||||
if (!AuctionHouse.getInstance().getAuctionPlayerManager().getUsingSellGUI().contains(close.player.getUniqueId())) {
|
if (!AuctionHouse.getInstance().getAuctionPlayerManager().getUsingSellGUI().contains(close.player.getUniqueId())) {
|
||||||
ItemStack toGiveBack = AuctionHouse.getInstance().getAuctionPlayerManager().getSellHolding().get(close.player.getUniqueId());
|
ItemStack toGiveBack = AuctionHouse.getInstance().getAuctionPlayerManager().getSellHolding().get(close.player.getUniqueId());
|
||||||
PlayerUtils.giveItem(close.player, toGiveBack); // this could give them air
|
PlayerUtils.giveItem(close.player, toGiveBack); // this could give them air
|
||||||
@ -138,6 +146,7 @@ public class GUISellItem extends AbstractPlaceholderGui {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.itemToBeListed = e.clickedItem;
|
this.itemToBeListed = e.clickedItem;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -404,8 +413,6 @@ public class GUISellItem extends AbstractPlaceholderGui {
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
e.player.closeInventory();
|
|
||||||
|
|
||||||
e.player.closeInventory();
|
e.player.closeInventory();
|
||||||
if (Settings.OPEN_MAIN_AUCTION_HOUSE_AFTER_MENU_LIST.getBoolean()) {
|
if (Settings.OPEN_MAIN_AUCTION_HOUSE_AFTER_MENU_LIST.getBoolean()) {
|
||||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||||
@ -463,5 +470,17 @@ public class GUISellItem extends AbstractPlaceholderGui {
|
|||||||
|
|
||||||
private void setTheItemToBeListed() {
|
private void setTheItemToBeListed() {
|
||||||
this.itemToBeListed = getItem(1, 4);
|
this.itemToBeListed = getItem(1, 4);
|
||||||
|
this.auctionPlayer.setItemBeingListed(this.itemToBeListed);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void makeMess() {
|
||||||
|
task = Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(AuctionHouse.getInstance(), this::setTheItemToBeListed, 0L, 10);
|
||||||
|
this.auctionPlayer.setAssignedTaskId(task.getTaskId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cleanup() {
|
||||||
|
if (task != null) {
|
||||||
|
task.cancel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import ca.tweetzy.auctionhouse.AuctionHouse;
|
|||||||
import ca.tweetzy.auctionhouse.api.AuctionAPI;
|
import ca.tweetzy.auctionhouse.api.AuctionAPI;
|
||||||
import ca.tweetzy.auctionhouse.api.UpdateChecker;
|
import ca.tweetzy.auctionhouse.api.UpdateChecker;
|
||||||
import ca.tweetzy.auctionhouse.api.hook.PlaceholderAPIHook;
|
import ca.tweetzy.auctionhouse.api.hook.PlaceholderAPIHook;
|
||||||
|
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
|
||||||
import ca.tweetzy.auctionhouse.guis.GUIAuctionHouse;
|
import ca.tweetzy.auctionhouse.guis.GUIAuctionHouse;
|
||||||
import ca.tweetzy.auctionhouse.helpers.PlayerHelper;
|
import ca.tweetzy.auctionhouse.helpers.PlayerHelper;
|
||||||
import ca.tweetzy.auctionhouse.settings.Settings;
|
import ca.tweetzy.auctionhouse.settings.Settings;
|
||||||
@ -22,6 +23,7 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.event.inventory.PrepareAnvilEvent;
|
import org.bukkit.event.inventory.PrepareAnvilEvent;
|
||||||
import org.bukkit.event.inventory.PrepareItemCraftEvent;
|
import org.bukkit.event.inventory.PrepareItemCraftEvent;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
@ -42,6 +44,22 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class PlayerListeners implements Listener {
|
public class PlayerListeners implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||||
|
final Player player = event.getEntity();
|
||||||
|
|
||||||
|
final AuctionPlayer auctionPlayer = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId());
|
||||||
|
if (auctionPlayer != null) {
|
||||||
|
// task id cancel
|
||||||
|
Bukkit.getServer().getScheduler().cancelTask(auctionPlayer.getAssignedTaskId());
|
||||||
|
|
||||||
|
if (auctionPlayer.getItemBeingListed() != null && player.getLocation().getWorld() != null) {
|
||||||
|
player.getLocation().getWorld().dropItemNaturally(player.getLocation(), auctionPlayer.getItemBeingListed());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||||
Player player = e.getPlayer();
|
Player player = e.getPlayer();
|
||||||
@ -60,9 +78,6 @@ public class PlayerListeners implements Listener {
|
|||||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||||
Player player = e.getPlayer();
|
Player player = e.getPlayer();
|
||||||
|
|
||||||
|
|
||||||
//todo maybe add this back if it messes up stuff
|
|
||||||
// AuctionHouse.getInstance().getAuctionPlayerManager().getCooldowns().remove(player.getUniqueId());
|
|
||||||
AuctionHouse.getInstance().getAuctionPlayerManager().getSellHolding().remove(player.getUniqueId());
|
AuctionHouse.getInstance().getAuctionPlayerManager().getSellHolding().remove(player.getUniqueId());
|
||||||
AuctionHouse.getInstance().getLogger().info("Removing sell holding instance for user: " + player.getName());
|
AuctionHouse.getInstance().getLogger().info("Removing sell holding instance for user: " + player.getName());
|
||||||
}
|
}
|
||||||
|
@ -1,56 +0,0 @@
|
|||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The current file has been created by Kiran Hart
|
|
||||||
* Date Created: July 21 2021
|
|
||||||
* Time Created: 2:51 p.m.
|
|
||||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
|
|
||||||
*/
|
|
||||||
public class Test {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
final List<TestObject> list = new ArrayList<>();
|
|
||||||
|
|
||||||
list.add(new TestObject(1, "Kiran"));
|
|
||||||
list.add(new TestObject(2, "Carl"));
|
|
||||||
list.add(new TestObject(3, "Orlando"));
|
|
||||||
|
|
||||||
System.out.println(list.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Getter
|
|
||||||
static class TestObject {
|
|
||||||
|
|
||||||
private final int id;
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long getSecondsFromString(String time) {
|
|
||||||
time = time.toLowerCase();
|
|
||||||
String[] tokens = time.split("(?<=\\d)(?=\\D)|(?=\\d)(?<=\\D)");
|
|
||||||
char suffix = tokens[1].charAt(0);
|
|
||||||
int amount = Integer.parseInt(tokens[0]);
|
|
||||||
|
|
||||||
switch (suffix) {
|
|
||||||
case 's':
|
|
||||||
return amount;
|
|
||||||
case 'm':
|
|
||||||
return (long) amount * 60;
|
|
||||||
case 'h':
|
|
||||||
return (long) amount * 3600;
|
|
||||||
case 'd':
|
|
||||||
return (long) amount * 3600 * 24;
|
|
||||||
case 'y':
|
|
||||||
return (long) amount * 3600 * 24 * 365;
|
|
||||||
default:
|
|
||||||
return 0L;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user