Fixed GUI lag exploit

This commit is contained in:
Auxilor
2023-10-26 18:24:32 +01:00
parent 9e625c004e
commit 29d69d77b4
4 changed files with 18 additions and 4 deletions

View File

@@ -2,6 +2,7 @@ package com.willfp.eco.core.gui.slot;
import com.willfp.eco.core.gui.menu.Menu;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -77,12 +78,12 @@ public abstract class CustomSlot implements Slot {
}
@Override
public boolean shouldRenderOnClick() {
public boolean shouldRenderOnClick(@NotNull final ClickType clickType) {
if (delegate == null) {
throw new IllegalStateException("Custom Slot was not initialized!");
}
return delegate.shouldRenderOnClick();
return delegate.shouldRenderOnClick(clickType);
}
@Override

View File

@@ -7,6 +7,7 @@ import com.willfp.eco.core.gui.slot.functional.SlotProvider;
import com.willfp.eco.core.items.TestableItem;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -96,8 +97,20 @@ public interface Slot extends GUIComponent {
* If the slot should re-render the menu if clicked.
*
* @return If the slot should re-render.
* @deprecated Use {@link Slot#shouldRenderOnClick(ClickType)} instead.
*/
@Deprecated(since = "6.66.0", forRemoval = true)
default boolean shouldRenderOnClick() {
return shouldRenderOnClick(ClickType.LEFT);
}
/**
* If the slot should re-render the menu if clicked.
*
* @param clickType The click type.
* @return If the slot should re-render.
*/
default boolean shouldRenderOnClick(@NotNull final ClickType clickType) {
return true;
}

View File

@@ -35,5 +35,5 @@ open class EcoSlot(
override fun getActionableSlot(player: Player, menu: Menu): EcoSlot = this
override fun shouldRenderOnClick() = handlers.values.any { it.isNotEmpty() }
override fun shouldRenderOnClick(clickType: ClickType) = !handlers[clickType].isNullOrEmpty()
}

View File

@@ -46,7 +46,7 @@ class GUIListener(private val plugin: EcoPlugin) : Listener {
if (delegate is EcoSlot) {
delegate.handleInventoryClick(event, menu)
if (delegate.shouldRenderOnClick()) {
if (delegate.shouldRenderOnClick(event.click)) {
player.renderActiveMenu()
}
} else if (delegate === this) {