diff --git a/pom.xml b/pom.xml index ae18636..d57b438 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 ca.tweetzy auctionhouse - 2.44.0 + 2.45.0 UTF-8 @@ -184,7 +184,7 @@ org.spigotmc spigot - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT provided diff --git a/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java b/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java index 2bff943..259b2de 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java +++ b/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java @@ -207,7 +207,8 @@ public class AuctionHouse extends TweetyPlugin { new CommandStatus(), new CommandAdmin(), new CommandBan(), - new CommandUnban() + new CommandUnban(), + new CommandMarkChest() ); // Placeholder API diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandActive.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandActive.java index f17130e..7a855f7 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandActive.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandActive.java @@ -4,6 +4,7 @@ import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.api.AuctionAPI; import ca.tweetzy.auctionhouse.auction.AuctionPlayer; import ca.tweetzy.auctionhouse.guis.GUIActiveAuctions; +import ca.tweetzy.auctionhouse.settings.Settings; import ca.tweetzy.core.commands.AbstractCommand; import ca.tweetzy.core.utils.TextUtils; import org.bukkit.Bukkit; @@ -29,6 +30,10 @@ public class CommandActive extends AbstractCommand { Player player = (Player) sender; if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE; + if (Settings.USE_AUCTION_CHEST_MODE.getBoolean()) { + AuctionHouse.getInstance().getLocale().getMessage("general.visit auction chest").sendPrefixedMessage(player); + return ReturnType.FAILURE; + } if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) { return ReturnType.FAILURE; diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandAuctionHouse.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandAuctionHouse.java index d604889..4c064f5 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandAuctionHouse.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandAuctionHouse.java @@ -4,6 +4,7 @@ import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.api.AuctionAPI; import ca.tweetzy.auctionhouse.auction.AuctionPlayer; import ca.tweetzy.auctionhouse.guis.GUIAuctionHouse; +import ca.tweetzy.auctionhouse.settings.Settings; import ca.tweetzy.core.commands.AbstractCommand; import ca.tweetzy.core.utils.TextUtils; import org.apache.commons.lang.StringUtils; @@ -31,6 +32,10 @@ public class CommandAuctionHouse extends AbstractCommand { if (sender instanceof Player) { Player player = (Player) sender; if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE; + if (Settings.USE_AUCTION_CHEST_MODE.getBoolean()) { + AuctionHouse.getInstance().getLocale().getMessage("general.visit auction chest").sendPrefixedMessage(player); + return ReturnType.FAILURE; + } if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) { return ReturnType.FAILURE; diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandExpired.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandExpired.java index d654633..5b07cc8 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandExpired.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandExpired.java @@ -4,6 +4,7 @@ import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.api.AuctionAPI; import ca.tweetzy.auctionhouse.auction.AuctionPlayer; import ca.tweetzy.auctionhouse.guis.GUIExpiredItems; +import ca.tweetzy.auctionhouse.settings.Settings; import ca.tweetzy.core.commands.AbstractCommand; import ca.tweetzy.core.utils.TextUtils; import org.bukkit.Bukkit; @@ -29,6 +30,11 @@ public class CommandExpired extends AbstractCommand { Player player = (Player) sender; if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE; + if (Settings.USE_AUCTION_CHEST_MODE.getBoolean()) { + AuctionHouse.getInstance().getLocale().getMessage("general.visit auction chest").sendPrefixedMessage(player); + return ReturnType.FAILURE; + } + if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) { return ReturnType.FAILURE; } diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandMarkChest.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandMarkChest.java new file mode 100644 index 0000000..3670e8a --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandMarkChest.java @@ -0,0 +1,73 @@ +package ca.tweetzy.auctionhouse.commands; + +import ca.tweetzy.auctionhouse.AuctionHouse; +import ca.tweetzy.auctionhouse.api.AuctionAPI; +import ca.tweetzy.core.commands.AbstractCommand; +import ca.tweetzy.core.compatibility.ServerVersion; +import ca.tweetzy.core.compatibility.XMaterial; +import org.bukkit.NamespacedKey; +import org.bukkit.block.Block; +import org.bukkit.block.Chest; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.persistence.PersistentDataType; + +import java.util.List; + +/** + * The current file has been created by Kiran Hart + * Date Created: December 04 2021 + * Time Created: 11:30 p.m. + * Usage of any code found within this class is prohibited unless given explicit permission otherwise + */ +public final class CommandMarkChest extends AbstractCommand { + + public CommandMarkChest() { + super(CommandType.PLAYER_ONLY, "markchest"); + } + + @Override + protected ReturnType runCommand(CommandSender sender, String... args) { + if (AuctionAPI.tellMigrationStatus(sender)) return ReturnType.FAILURE; + if (!ServerVersion.isServerVersionAtLeast(ServerVersion.V1_14)) return ReturnType.FAILURE; + final Player player = (Player) sender; + + final Block targetBlock = player.getTargetBlock(null, 10); + if (targetBlock.getType() != XMaterial.CHEST.parseMaterial()) return ReturnType.FAILURE; + + final Chest chest = (Chest) targetBlock.getState(); + final NamespacedKey key = new NamespacedKey(AuctionHouse.getInstance(), "AuctionHouseMarkedChest"); + + if (chest.getPersistentDataContainer().has(key, PersistentDataType.BYTE)) { + chest.getPersistentDataContainer().remove(key); + chest.update(true); + AuctionHouse.getInstance().getLocale().getMessage("general.unmarked chest").sendPrefixedMessage(player); + } else { + chest.getPersistentDataContainer().set(key, PersistentDataType.BYTE, (byte) 1); + chest.update(true); + AuctionHouse.getInstance().getLocale().getMessage("general.marked chest").sendPrefixedMessage(player); + } + + return ReturnType.SUCCESS; + } + + @Override + protected List onTab(CommandSender sender, String... args) { + return null; + } + + @Override + public String getPermissionNode() { + return "auctionhouse.cmd.markchest"; + } + + @Override + public String getSyntax() { + return AuctionHouse.getInstance().getLocale().getMessage("commands.syntax.markchest").getMessage(); + } + + @Override + public String getDescription() { + return AuctionHouse.getInstance().getLocale().getMessage("commands.description.markchest").getMessage(); + } +} diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSearch.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSearch.java index babf58b..137227f 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSearch.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSearch.java @@ -4,6 +4,7 @@ import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.api.AuctionAPI; import ca.tweetzy.auctionhouse.auction.AuctionPlayer; import ca.tweetzy.auctionhouse.guis.GUIAuctionHouse; +import ca.tweetzy.auctionhouse.settings.Settings; import ca.tweetzy.core.commands.AbstractCommand; import ca.tweetzy.core.utils.TextUtils; import org.bukkit.Bukkit; @@ -30,6 +31,11 @@ public class CommandSearch extends AbstractCommand { Player player = (Player) sender; if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE; + if (Settings.USE_AUCTION_CHEST_MODE.getBoolean()) { + AuctionHouse.getInstance().getLocale().getMessage("general.visit auction chest").sendPrefixedMessage(player); + return ReturnType.FAILURE; + } + if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) { return ReturnType.FAILURE; } diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java index 45d1b4a..856ea8b 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java @@ -41,6 +41,11 @@ public final class CommandSell extends AbstractCommand { Player player = (Player) sender; if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE; + if (Settings.USE_AUCTION_CHEST_MODE.getBoolean()) { + AuctionHouse.getInstance().getLocale().getMessage("general.visit auction chest").sendPrefixedMessage(player); + return ReturnType.FAILURE; + } + if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) { return ReturnType.FAILURE; } diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandTransactions.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandTransactions.java index 667e9a0..f3e8d1b 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandTransactions.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandTransactions.java @@ -3,6 +3,7 @@ package ca.tweetzy.auctionhouse.commands; import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.api.AuctionAPI; import ca.tweetzy.auctionhouse.guis.transaction.GUITransactionType; +import ca.tweetzy.auctionhouse.settings.Settings; import ca.tweetzy.core.commands.AbstractCommand; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -26,6 +27,11 @@ public class CommandTransactions extends AbstractCommand { Player player = (Player) sender; if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE; + if (Settings.USE_AUCTION_CHEST_MODE.getBoolean()) { + AuctionHouse.getInstance().getLocale().getMessage("general.visit auction chest").sendPrefixedMessage(player); + return ReturnType.FAILURE; + } + if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) { return ReturnType.FAILURE; } diff --git a/src/main/java/ca/tweetzy/auctionhouse/listeners/PlayerListeners.java b/src/main/java/ca/tweetzy/auctionhouse/listeners/PlayerListeners.java index 5cdae61..69a93ff 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/listeners/PlayerListeners.java +++ b/src/main/java/ca/tweetzy/auctionhouse/listeners/PlayerListeners.java @@ -4,6 +4,7 @@ import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.api.AuctionAPI; import ca.tweetzy.auctionhouse.api.UpdateChecker; import ca.tweetzy.auctionhouse.auction.AuctionPlayer; +import ca.tweetzy.auctionhouse.guis.GUIAuctionHouse; import ca.tweetzy.auctionhouse.helpers.PlayerHelper; import ca.tweetzy.core.compatibility.ServerVersion; import ca.tweetzy.core.compatibility.XMaterial; @@ -11,7 +12,11 @@ import ca.tweetzy.core.utils.PlayerUtils; import ca.tweetzy.core.utils.TextUtils; import ca.tweetzy.core.utils.nms.NBTEditor; import org.bukkit.Bukkit; +import org.bukkit.NamespacedKey; +import org.bukkit.block.Block; +import org.bukkit.block.Chest; import org.bukkit.entity.Player; +import org.bukkit.event.Event; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; @@ -20,6 +25,7 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.persistence.PersistentDataType; import java.util.ArrayList; import java.util.List; @@ -65,6 +71,27 @@ public class PlayerListeners implements Listener { } } + @EventHandler + public void onAuctionChestClick(PlayerInteractEvent e) { + final Player player = e.getPlayer(); + final Block block = e.getClickedBlock(); + + if (block == null || block.getType() != XMaterial.CHEST.parseMaterial()) return; + final Chest chest = (Chest) block.getState(); + + final NamespacedKey key = new NamespacedKey(AuctionHouse.getInstance(), "AuctionHouseMarkedChest"); + if (chest.getPersistentDataContainer().has(key, PersistentDataType.BYTE)) { + e.setUseInteractedBlock(Event.Result.DENY); + e.setCancelled(true); + + if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) { + return; + } + + AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIAuctionHouse(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()))); + } + } + @EventHandler public void onBundleClick(PlayerInteractEvent e) { Player player = e.getPlayer(); diff --git a/src/main/java/ca/tweetzy/auctionhouse/settings/LocaleSettings.java b/src/main/java/ca/tweetzy/auctionhouse/settings/LocaleSettings.java index fdc6247..f3c05f0 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/settings/LocaleSettings.java +++ b/src/main/java/ca/tweetzy/auctionhouse/settings/LocaleSettings.java @@ -48,6 +48,9 @@ public class LocaleSettings { languageNodes.put("general.please_enter_at_least_one_number", "&cPlease enter at least 1 valid number!"); languageNodes.put("general.mcmmo_ability_active", "&cCannot list item when mcMMO ability is active!"); languageNodes.put("general.cannot list damaged item", "&cCannot list a damaged item!"); + languageNodes.put("general.marked chest", "&aYou marked that chest as an Auction chest"); + languageNodes.put("general.unmarked chest", "&cYou unmarked that chest as an Auction chest"); + languageNodes.put("general.visit auction chest", "&cVisit an Auction chest to use Auction House."); languageNodes.put("pricing.minbaseprice", "&cThe minimum base price must be &a$%price%"); @@ -148,6 +151,7 @@ public class LocaleSettings { languageNodes.put("commands.syntax.ban", "ban [player] [time] [reason]"); languageNodes.put("commands.syntax.unban", "unban "); languageNodes.put("commands.syntax.togglelistinfo", "togglelistinfo"); + languageNodes.put("commands.syntax.markchest", "markchest"); languageNodes.put("commands.description.active", "View all your auction listings"); languageNodes.put("commands.description.auctionhouse", "Main command for the plugin, it opens the auction window."); @@ -163,6 +167,7 @@ public class LocaleSettings { languageNodes.put("commands.description.ban", "Ban a player from the auction house for a set amount of time."); languageNodes.put("commands.description.unban", "Unban a player from the auction house"); languageNodes.put("commands.description.togglelistinfo", "Toggle whether auction house should message you when you list an item"); + languageNodes.put("commands.description.markchest", "Toggles whether a chest is an auction chest"); } public static void setup() { diff --git a/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java b/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java index 25f4dad..7c1d1ac 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java +++ b/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java @@ -128,6 +128,7 @@ public class Settings { public static final ConfigSetting MISC_FILTER_ENABLED = new ConfigSetting(config, "auction setting.enabled filters.misc", true, "Should this filter be enabled?"); public static final ConfigSetting SEARCH_FILTER_ENABLED = new ConfigSetting(config, "auction setting.enabled filters.search", true, "Should this filter be enabled?"); public static final ConfigSetting SELF_FILTER_ENABLED = new ConfigSetting(config, "auction setting.enabled filters.self", true, "Should this filter be enabled?"); + public static final ConfigSetting USE_AUCTION_CHEST_MODE = new ConfigSetting(config, "auction setting.use auction chest mode", false, "Enabling this will make it so players can only access the auction through the auction chest"); public static final ConfigSetting ALLOW_ITEM_BUNDLES = new ConfigSetting(config, "auction setting.bundles.enabled", true, "If true, players can use -b in the sell command to bundle all similar items into a single item."); public static final ConfigSetting ITEM_BUNDLE_ITEM = new ConfigSetting(config, "auction setting.bundles.item", XMaterial.GOLD_BLOCK.name());