Skip to content

Commit

Permalink
Fix pet icon and command history (#1114)
Browse files Browse the repository at this point in the history
* Don't add commands sent by the mod to the command history

* Fix pet icon showing as a bone for skinned pets

* Hide automatic commands

---------

Co-authored-by: Kevinthegreat <[email protected]>
  • Loading branch information
AzureAaron and kevinthegreat1 authored Dec 30, 2024
1 parent add261c commit 19530fa
Show file tree
Hide file tree
Showing 18 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
.text(Text.translatable("text.skyblocker.open"))
.action((screen, opt) -> {
if (Utils.isOnSkyblock()) {
MessageScheduler.INSTANCE.sendMessageAfterCooldown("/widgets");
MessageScheduler.INSTANCE.sendMessageAfterCooldown("/widgets", true);
} else {
MinecraftClient.getInstance().setScreen(new WidgetsConfigurationScreen(Location.HUB, ScreenMaster.ScreenLayer.MAIN_TAB, screen));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public InventoryScreenMixin(PlayerScreenHandler handler, PlayerInventory invento
private void skyblocker$addGardenPlotsWidget(CallbackInfo ci) {
if (Utils.getLocation().equals(Location.GARDEN) && SkyblockerConfigManager.get().farming.garden.gardenPlotsWidget) {
gardenPlotsWidget = new GardenPlotsWidget(x + backgroundWidth + 4, y);
deskButton = ButtonWidget.builder(Text.translatable("skyblocker.gardenPlots.openDesk"), button -> MessageScheduler.INSTANCE.sendMessageAfterCooldown("/desk"))
deskButton = ButtonWidget.builder(Text.translatable("skyblocker.gardenPlots.openDesk"), button -> MessageScheduler.INSTANCE.sendMessageAfterCooldown("/desk", true))
.dimensions(gardenPlotsWidget.getX() + 7, y + 108, 60, 15)
.build();
// make desk button get selected before the widget but render after the widget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void init() {
if (Utils.isOnSkyblock() && screen instanceof ChatScreen && SkyblockerConfigManager.get().chat.confirmationPromptHelper) {
ScreenMouseEvents.beforeMouseClick(screen).register((_screen1, _mouseX, _mouseY, _button) -> {
if (hasCommand()) {
MessageScheduler.INSTANCE.sendMessageAfterCooldown(command);
MessageScheduler.INSTANCE.sendMessageAfterCooldown(command, true);
command = null;
commandFoundAt = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static void init() {
.then(argument("blockPos", ClientBlockPosArgumentType.blockPos())
.then(argument("eggType", EggTypeArgumentType.eggType())
.executes(context -> {
MessageScheduler.INSTANCE.sendMessageAfterCooldown("[Skyblocker] Chocolate " + context.getArgument("eggType", EggType.class) + " Egg found at " + context.getArgument("blockPos", ClientPosArgument.class).toAbsoluteBlockPos(context.getSource()).toShortString() + "!");
MessageScheduler.INSTANCE.sendMessageAfterCooldown("[Skyblocker] Chocolate " + context.getArgument("eggType", EggType.class) + " Egg found at " + context.getArgument("blockPos", ClientPosArgument.class).toAbsoluteBlockPos(context.getSource()).toShortString() + "!", false);
return Command.SINGLE_SUCCESS;
})))))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static void tick() {
score = calculateScore();
if (!sent270 && !sent300 && score >= 270 && score < 300) {
if (SCORE_CONFIG.enableDungeonScore270Message) {
MessageScheduler.INSTANCE.sendMessageAfterCooldown("/pc " + Constants.PREFIX.get().getString() + SCORE_CONFIG.dungeonScore270Message.replaceAll("\\[score]", "270"));
MessageScheduler.INSTANCE.sendMessageAfterCooldown("/pc " + Constants.PREFIX.get().getString() + SCORE_CONFIG.dungeonScore270Message.replaceAll("\\[score]", "270"), false);
}
if (SCORE_CONFIG.enableDungeonScore270Title) {
client.inGameHud.setDefaultTitleFade();
Expand All @@ -110,14 +110,14 @@ public static void tick() {
int crypts = getCrypts();
if (!sentCrypts && score >= SCORE_CONFIG.dungeonCryptsMessageThreshold && crypts < 5) {
if (SCORE_CONFIG.enableDungeonCryptsMessage) {
MessageScheduler.INSTANCE.sendMessageAfterCooldown("/pc " + Constants.PREFIX.get().getString() + SCORE_CONFIG.dungeonCryptsMessage.replaceAll("\\[crypts]", String.valueOf(crypts)));
MessageScheduler.INSTANCE.sendMessageAfterCooldown("/pc " + Constants.PREFIX.get().getString() + SCORE_CONFIG.dungeonCryptsMessage.replaceAll("\\[crypts]", String.valueOf(crypts)), false);
}
sentCrypts = true;
}

if (!sent300 && score >= 300) {
if (SCORE_CONFIG.enableDungeonScore300Message) {
MessageScheduler.INSTANCE.sendMessageAfterCooldown("/pc " + Constants.PREFIX.get().getString() + SCORE_CONFIG.dungeonScore300Message.replaceAll("\\[score]", "300"));
MessageScheduler.INSTANCE.sendMessageAfterCooldown("/pc " + Constants.PREFIX.get().getString() + SCORE_CONFIG.dungeonScore300Message.replaceAll("\\[score]", "300"), false);
}
if (SCORE_CONFIG.enableDungeonScore300Title) {
client.inGameHud.setDefaultTitleFade();
Expand Down Expand Up @@ -215,7 +215,7 @@ public static boolean isEntityMimic(Entity entity) {
public static void handleEntityDeath(Entity entity) {
if (mimicKilled) return;
if (!isEntityMimic(entity)) return;
if (MIMIC_MESSAGE_CONFIG.sendMimicMessage) MessageScheduler.INSTANCE.sendMessageAfterCooldown(MIMIC_MESSAGE_CONFIG.mimicMessage);
if (MIMIC_MESSAGE_CONFIG.sendMimicMessage) MessageScheduler.INSTANCE.sendMessageAfterCooldown(MIMIC_MESSAGE_CONFIG.mimicMessage, false);
mimicKilled = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private static void onLividColorFound(MinecraftClient client, Block color) {
.append(CONFIG.lividColorText.replaceAll("\\[color]", colorString))
.formatted(LividColor.color);
if (CONFIG.enableLividColorText) {
MessageScheduler.INSTANCE.sendMessageAfterCooldown(message.getString());
MessageScheduler.INSTANCE.sendMessageAfterCooldown(message.getString(), false);
}
if (CONFIG.enableLividColorTitle) {
client.inGameHud.setDefaultTitleFade();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ public boolean onMatch(Text message, Matcher matcher) {
}

private void sendCommand(String command, int delay) {
MessageScheduler.INSTANCE.queueMessage(command, false, delay * BASE_DELAY);
MessageScheduler.INSTANCE.queueMessage(command, true, delay * BASE_DELAY);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public static int addWaypointFromCommand(FabricClientCommandSource source, Strin
public static int shareWaypoint(String place) {
if (activeWaypoints.containsKey(place)) {
BlockPos pos = activeWaypoints.get(place).pos;
MessageScheduler.INSTANCE.sendMessageAfterCooldown(Constants.PREFIX.get().getString() + " " + place + ": " + pos.getX() + ", " + pos.getY() + ", " + pos.getZ());
MessageScheduler.INSTANCE.sendMessageAfterCooldown(Constants.PREFIX.get().getString() + " " + place + ": " + pos.getX() + ", " + pos.getY() + ", " + pos.getZ(), false);
} else {
//send fail message
if (CLIENT.player == null || CLIENT.getNetworkHandler() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ public void onClick(double mouseX, double mouseY) {
if (SkyblockerConfigManager.get().farming.garden.closeScreenOnPlotClick && MinecraftClient.getInstance().currentScreen != null)
MinecraftClient.getInstance().currentScreen.close();

if (hoveredSlot == 12) MessageScheduler.INSTANCE.sendMessageAfterCooldown("/warp garden");
else MessageScheduler.INSTANCE.sendMessageAfterCooldown("/plottp " + gardenPlots[hoveredSlot].name);
if (hoveredSlot == 12) MessageScheduler.INSTANCE.sendMessageAfterCooldown("/warp garden", true);
else MessageScheduler.INSTANCE.sendMessageAfterCooldown("/plottp " + gardenPlots[hoveredSlot].name, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static void onMouseClicked(double mouseX, double mouseY, int mouseButton,
// The text starts at `TEXT_START_X + ENTRY_INDENT + ITEM_INDENT`
if (isMouseOverText(mouseX, mouseY, TEXT_START_X + ENTRY_INDENT + ITEM_INDENT, yPosition, textWidth, textRenderer.fontHeight)) {
// Send command to buy the item from the bazaar
MessageScheduler.INSTANCE.sendMessageAfterCooldown("/bz " + itemText);
MessageScheduler.INSTANCE.sendMessageAfterCooldown("/bz " + itemText, true);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public static void itemPriceLookup(ClientPlayerEntity player, @NotNull Slot slot

// Search up the item in the bazaar or auction house
if (TooltipInfoType.BAZAAR.hasOrNullWarning(skyblockApiId)) {
MessageScheduler.INSTANCE.sendMessageAfterCooldown("/bz " + itemName);
MessageScheduler.INSTANCE.sendMessageAfterCooldown("/bz " + itemName, true);
} else if (TooltipInfoType.LOWEST_BINS.hasOrNullWarning(skyblockApiId)) {
MessageScheduler.INSTANCE.sendMessageAfterCooldown("/ahsearch " + itemName);
MessageScheduler.INSTANCE.sendMessageAfterCooldown("/ahsearch " + itemName, true);
}
} else {
player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.helpers.itemPrice.itemPriceLookupFailed")), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public SkyblockInventoryScreen(PlayerEntity player) {
public boolean mouseClicked(double mouseX, double mouseY, int button) {
for (Slot equipmentSlot : equipmentSlots) {
if (isPointWithinBounds(equipmentSlot.x, equipmentSlot.y, 16, 16, mouseX, mouseY)) {
MessageScheduler.INSTANCE.sendMessageAfterCooldown("/equipment");
MessageScheduler.INSTANCE.sendMessageAfterCooldown("/equipment", true);
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void drawTooltip(DrawContext context, int x, int y) {
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (this.hovered != null && this.hovered.getWarpCommand() != null) {
MessageScheduler.INSTANCE.sendMessageAfterCooldown(hovered.getWarpCommand());
MessageScheduler.INSTANCE.sendMessageAfterCooldown(hovered.getWarpCommand(), true);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void onClick(double mouseX, double mouseY) {
if (command == null || command.isEmpty()) {
MinecraftClient.getInstance().player.sendMessage(Constants.PREFIX.get().append(Text.literal("Quick Nav button index " + (index + 1) + " has no command!").formatted(Formatting.RED)), false);
} else {
MessageScheduler.INSTANCE.sendMessageAfterCooldown(command);
MessageScheduler.INSTANCE.sendMessageAfterCooldown(command, true);
}
this.alpha = 0.5f;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ private static void pushCommand() {
} else {
command = "/bz " + search;
}
MessageScheduler.INSTANCE.sendMessageAfterCooldown(command);
MessageScheduler.INSTANCE.sendMessageAfterCooldown(command, true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected void updateContent(List<Text> lines) {
addComponent(new PlainTextComponent(line));
continue;
}
String petName = split[1].trim();
String petName = split[1].replace("✦", "").trim();
if (!petName.equals(prevString)) {
icon = ItemRepository.getItemsStream().filter(stack -> {
String trim = stack.getName().getString().trim();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/hysky/skyblocker/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ private static void tickProfileId() {

@Override
public void run() {
if (requestId == profileIdRequest) MessageScheduler.INSTANCE.sendMessageAfterCooldown("/profileid");
if (requestId == profileIdRequest) MessageScheduler.INSTANCE.sendMessageAfterCooldown("/profileid", true);
}
}, 20 * 8); //8 seconds
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected MessageScheduler() {
* Sends a chat message or command after the minimum cooldown. Prefer this method to send messages or commands to the server.
*
* @param message the message to send
* @param hide whether to hide the message from the chat, default should be true for commands
*/
public void sendMessageAfterCooldown(String message, boolean hide) {
if (lastMessage + MIN_DELAY < System.currentTimeMillis()) {
Expand All @@ -35,10 +36,6 @@ public void sendMessageAfterCooldown(String message, boolean hide) {
}
}

public void sendMessageAfterCooldown(String message) {
sendMessageAfterCooldown(message, false);
}

private void sendMessage(String message, boolean hide) {
MinecraftClient client = MinecraftClient.getInstance();
if (client.player == null) {
Expand All @@ -47,7 +44,7 @@ private void sendMessage(String message, boolean hide) {
}
message = StringHelper.truncateChat(StringUtils.normalizeSpace(message.trim()));

if (!hide) client.inGameHud.getChatHud().addToMessageHistory(message);
if (!hide) client.inGameHud.getChatHud().addToMessageHistory(message);
if (message.startsWith("/")) {
client.player.networkHandler.sendCommand(message.substring(1));
} else {
Expand All @@ -59,6 +56,7 @@ private void sendMessage(String message, boolean hide) {
* Queues a chat message or command to send in {@code delay} ticks. Use this method to send messages or commands a set time in the future. The minimum cooldown is still respected.
*
* @param message the message to send
* @param hide whether to hide the message from the chat, default should be true for commands
* @param delay the delay before sending the message in ticks
*/
public void queueMessage(String message, boolean hide, int delay) {
Expand Down

0 comments on commit 19530fa

Please sign in to comment.