Skip to content

Commit

Permalink
Fixed GUI lag exploit
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Oct 26, 2023
1 parent 9e625c0 commit 29d69d7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
Expand Down Expand Up @@ -77,12 +78,12 @@ public final boolean isCaptiveFromEmpty() {
}

@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
Expand Down
13 changes: 13 additions & 0 deletions eco-api/src/main/java/com/willfp/eco/core/gui/slot/Slot.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand Down Expand Up @@ -96,8 +97,20 @@ default boolean isCaptiveFromEmpty() {
* 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 29d69d7

Please sign in to comment.