From 8aa840ef0dade831f2cb6de2cac996711f3cc8b0 Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Mon, 13 Mar 2023 18:51:34 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=A0=20move=20meteor=20client=20checks?= =?UTF-8?q?=20into=20own=20listener=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Took 13 minutes --- .../listeners/MeteorClientListeners.java | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/main/java/ca/tweetzy/auctionhouse/listeners/MeteorClientListeners.java diff --git a/src/main/java/ca/tweetzy/auctionhouse/listeners/MeteorClientListeners.java b/src/main/java/ca/tweetzy/auctionhouse/listeners/MeteorClientListeners.java new file mode 100644 index 0000000..beba629 --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/listeners/MeteorClientListeners.java @@ -0,0 +1,94 @@ +/* + * Auction House + * Copyright 2023 Kiran Hart + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package ca.tweetzy.auctionhouse.listeners; + +import ca.tweetzy.auctionhouse.AuctionHouse; +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.*; + +public final class MeteorClientListeners implements Listener { + + @EventHandler + public void onPlayerPlaceItemIntoFrame(final PlayerInteractEntityEvent event) { + final Player player = event.getPlayer(); + + if (AuctionHouse.getInstance().getAuctionPlayerManager().isInSellProcess(player)) { + event.setCancelled(true); + } + } + + @EventHandler + public void onItemDropDuringSell(final PlayerDropItemEvent event) { + final Player player = event.getPlayer(); + + if (AuctionHouse.getInstance().getAuctionPlayerManager().isInSellProcess(player)) + event.setCancelled(true); + } + + @EventHandler + public void onHotbarSwapDuringSell(final PlayerItemHeldEvent event) { + final Player player = event.getPlayer(); + + if (AuctionHouse.getInstance().getAuctionPlayerManager().isInSellProcess(player)) + event.setCancelled(true); + } + + @EventHandler + public void onOffhandSwap(final PlayerSwapHandItemsEvent event) { + final Player player = event.getPlayer(); + + if (AuctionHouse.getInstance().getAuctionPlayerManager().isInSellProcess(player)) { + event.setCancelled(true); + } + } + + @EventHandler + public void onItemRemove(final InventoryClickEvent event) { + final HumanEntity clicker = event.getWhoClicked(); + if (!(clicker instanceof Player)) return; + + final Player player = (Player) clicker; + if (AuctionHouse.getInstance().getAuctionPlayerManager().isInSellProcess(player)) { + event.setCancelled(true); + } + } + + @EventHandler + public void onCommandDuringSell(final PlayerCommandPreprocessEvent event) { + final Player player = event.getPlayer(); + + if (AuctionHouse.getInstance().getAuctionPlayerManager().isInSellProcess(player)) + event.setCancelled(true); + } + + @EventHandler + public void onBuildDuringSell(final BlockPlaceEvent event) { + final Player player = event.getPlayer(); + + if (AuctionHouse.getInstance().getAuctionPlayerManager().isInSellProcess(player)) { + event.setBuild(false); + event.setCancelled(true); + } + } +}