Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove chest protection inventory check #977

Merged
merged 1 commit into from
Mar 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import tc.oc.pgm.events.PlayerPartyChangeEvent;
import tc.oc.pgm.kits.WalkSpeedKit;
import tc.oc.pgm.spawns.events.ParticipantSpawnEvent;
import tc.oc.pgm.util.TimeUtils;
import tc.oc.pgm.util.attribute.Attribute;
import tc.oc.pgm.util.bukkit.BukkitUtils;
import tc.oc.pgm.util.named.NameStyle;
Expand All @@ -61,12 +60,6 @@
@ListenerScope(MatchScope.LOADED)
public class ViewInventoryMatchModule implements MatchModule, Listener {

/**
* Amount of milliseconds after the match begins where players may not add / remove items from
* chests.
*/
public static final Duration CHEST_PROTECT_TIME = Duration.ofSeconds(2);

public static final Duration TICK = Duration.ofMillis(50);

protected final HashMap<String, InventoryTrackerEntry> monitoredInventories = new HashMap<>();
Expand Down Expand Up @@ -109,26 +102,6 @@ private void checkAllMonitoredInventories() {
}
}

@EventHandler(ignoreCancelled = true)
public void checkInventoryClick(final InventoryClickEvent event) {
if (event.getWhoClicked() instanceof Player) {
MatchPlayer player = this.match.getPlayer((Player) event.getWhoClicked());
if (player == null) {
return;
}
// we only cancel when the view is a chest because the other views tend to crash
if (!allowedInventoryType(event.getInventory().getType())) {
// cancel the click if the player cannot interact with the world or if the match has just
// started
if (!player.canInteract()
|| (player.getMatch().isRunning()
&& TimeUtils.isShorterThan(player.getMatch().getDuration(), CHEST_PROTECT_TIME))) {
event.setCancelled(true);
}
}
}
}

@EventHandler
public void closeMonitoredInventory(final InventoryCloseEvent event) {
this.monitoredInventories.remove(event.getPlayer().getName());
Expand Down Expand Up @@ -293,16 +266,6 @@ public boolean canPreviewInventory(MatchPlayer viewer, MatchPlayer holder) {
return viewer.isObserving() && holder.isAlive();
}

protected static boolean allowedInventoryType(InventoryType type) {
switch (type) {
case CREATIVE:
case PLAYER:
return true;
default:
return false;
}
}

protected void scheduleCheck(Player updater) {
if (this.updateQueue.containsKey(updater.getName())) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
Expand Down Expand Up @@ -333,6 +334,13 @@ public void onPotionSplash(final PotionSplashEvent event) {
// -- Player item/inventory actions --
// -----------------------------------

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onInventoryClick(final InventoryClickEvent event) {
if (!event.getInventory().equals(event.getWhoClicked().getInventory())) {
cancelUnlessInteracting(event, event.getWhoClicked());
}
}

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerDropItem(final PlayerDropItemEvent event) {
if (match.getParticipant(event.getPlayer()) == null) {
Expand Down