Skip to content

Commit

Permalink
GuiFancyWarp#updateButtonStates fixes
Browse files Browse the repository at this point in the history
- Fix faulty visibility setting logic in GuiFancyWarp#updateButtonStates that caused glitched menu states
- Unmute task queue errors in log4j2.xml
- Prevent players from spamming the warp command from pressing the open fancy warp menu hotkey too fast
  • Loading branch information
ILikePlayingGames committed Feb 21, 2024
1 parent 3cc897c commit 9394381
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion log4j2.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<!-- Filter out Hypixel scoreboard and sound errors -->
<RegexFilter regex="Error executing task.*|Unable to play unknown soundEvent.*" onMatch="DENY" onMismatch="NEUTRAL"/>
<RegexFilter regex="Unable to play unknown soundEvent.*" onMatch="DENY" onMismatch="NEUTRAL"/>
<Loggers>
<Logger level="INFO" name="net.minecraft.util.MessageDeserializer" additivity="false">
<AppenderRef ref="SysOut" level="DEBUG" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,19 +442,24 @@ protected void drawButtons(int mouseX, int mouseY) {
@Override
protected void updateButtonStates() {
for (GuiButton button : buttonList) {
// The config button is active on both the custom and default UI.
// Skip the config button as it's active on both the custom and default UI.
if (button instanceof GuiButtonChestMenu && !(button instanceof GuiButtonConfig)) {
GuiButtonChestMenu buttonChestMenu = (GuiButtonChestMenu) button;

buttonChestMenu.setEnabled(customUIInteractionEnabled);
buttonChestMenu.setVisible(renderCustomUI);

if (!renderCustomUI) {
continue;
}

if (button instanceof GuiButtonIsland) {
Island island = ((GuiButtonIsland) button).getIsland();

if (island.getWarpCount() == 1) {
boolean showIsland = WarpVisibilityChecks.shouldShowSingleWarpIsland(island);

buttonChestMenu.setEnabled(showIsland);
buttonChestMenu.setVisible(showIsland);
continue;
}
} else if (button instanceof GuiButtonWarp) {
GuiButtonWarp warpButton = (GuiButtonWarp) button;
Expand All @@ -466,13 +471,8 @@ protected void updateButtonStates() {
warpButton.setDrawWarpLabel(!Settings.shouldHideWarpLabelForIslandsWithOneWarp());
}

warpButton.setEnabled(shouldShowWarp);
warpButton.setVisible(shouldShowWarp);
continue;
}

buttonChestMenu.setEnabled(customUIInteractionEnabled);
buttonChestMenu.setVisible(renderCustomUI);
}
}
}
Expand All @@ -495,6 +495,7 @@ private void onChestItemChange(int triggerCount) {
setCustomUIState(true, true);
}

updateButtonStates();
chestInventory.removeInventoryChangeListener(inventoryListener);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;

/**
* This class allows the setting of a temporary button label that reverts to the original button label
* after a given amount of time.
*/
public class GuiButtonTimedLabel extends GuiButton {
private String originalButtonLabel;
private long timedLabelExpiryTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public class WarpMenuListener implements IResourceManagerReloadListener {
private static final Minecraft mc;
private static final FancyWarpMenu modInstance;
private static final Logger logger;
/** The minimum time in milliseconds after a hotkey press before the player can use the hotkey again*/
private static final int HOTKEY_PRESS_DELAY = 2000;

/**
* Time the user last pressed the fancy warp menu hotkey, used to prevent command spamming from
* spam pressing the hotkey
*/
private long lastWarpMenuHotkeyPress;

static {
mc = Minecraft.getMinecraft();
Expand Down Expand Up @@ -87,7 +95,9 @@ public void onGuiOpen(GuiOpenEvent event) {
@SubscribeEvent
public void keyTyped(InputEvent.KeyInputEvent event) {
if (Settings.isWarpMenuEnabled() && (GameState.isOnSkyBlock() || Settings.shouldSkipSkyBlockCheck()) &&
FancyWarpMenu.getKeyBindingOpenWarpMenu().isPressed()) {
FancyWarpMenu.getKeyBindingOpenWarpMenu().isPressed() &&
Minecraft.getSystemTime() - lastWarpMenuHotkeyPress > HOTKEY_PRESS_DELAY) {
lastWarpMenuHotkeyPress = Minecraft.getSystemTime();
mc.thePlayer.sendChatMessage(SkyBlockConstants.WARP_COMMAND_BASE);
}
}
Expand Down

0 comments on commit 9394381

Please sign in to comment.