Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

feature/UCA-805-auto-accept-first-aid #808

Merged
merged 4 commits into from
Sep 2, 2023
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 @@ -9,6 +9,7 @@
import com.rettichlp.unicacityaddon.base.registry.annotation.UCNameTag;
import com.rettichlp.unicacityaddon.commands.ABuyCommand;
import com.rettichlp.unicacityaddon.commands.ActivityCommand;
import com.rettichlp.unicacityaddon.commands.AutoFirstAidCommand;
import com.rettichlp.unicacityaddon.commands.BusCommand;
import com.rettichlp.unicacityaddon.commands.CalculateCommand;
import com.rettichlp.unicacityaddon.commands.CancelCountdownCommand;
Expand Down Expand Up @@ -289,6 +290,7 @@ public class Registry {
ASetBlacklistCommand.class,
ATMFillCommand.class,
ActivityCommand.class,
AutoFirstAidCommand.class,
AutoNCCommand.class,
BlackMarketCommand.class,
BlacklistInfoCommand.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.rettichlp.unicacityaddon.commands;

import com.rettichlp.unicacityaddon.UnicacityAddon;
import com.rettichlp.unicacityaddon.base.AddonPlayer;
import com.rettichlp.unicacityaddon.base.builder.TabCompletionBuilder;
import com.rettichlp.unicacityaddon.base.registry.UnicacityCommand;
import com.rettichlp.unicacityaddon.base.registry.annotation.UCCommand;
import com.rettichlp.unicacityaddon.base.text.ColorCode;

import java.util.List;

/**
* @author RettichLP
*/
@UCCommand(prefix = "autofirstaid", usage = "[on|off]")
public class AutoFirstAidCommand extends UnicacityCommand {

public static boolean autoAcceptFirstAid = false;

private final UnicacityAddon unicacityAddon;

public AutoFirstAidCommand(UnicacityAddon unicacityAddon, UCCommand ucCommand) {
super(unicacityAddon, ucCommand);
this.unicacityAddon = unicacityAddon;
}

@Override
public boolean execute(String[] arguments) {
AddonPlayer p = this.unicacityAddon.player();

if (arguments.length < 1 || !arguments[0].matches("on|off")) {
sendUsage();
return true;
}

autoAcceptFirstAid = switch (arguments[0]) {
case "on" -> true;
case "off" -> false;
default -> throw new IllegalStateException("Unexpected value: " + arguments[0]);
};

p.sendInfoMessage("Du hast die Einstellung für die automatische Annahme von Erster Hilfe auf '" + ColorCode.DARK_AQUA.getCode() + arguments[0].toUpperCase() + ColorCode.WHITE.getCode() + "' geändert.");
return true;
}

@Override
public List<String> complete(String[] arguments) {
return TabCompletionBuilder.getBuilder(this.unicacityAddon, arguments)
.addAtIndex(1, "on", "off")
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ public abstract class GuiController {
public abstract void setSelectedHotbarSlot(int slotNumber);

public abstract void updateSetting(boolean expectedValue);

public abstract boolean containsItemContainingString(String name);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.rettichlp.unicacityaddon.listener;

import com.rettichlp.unicacityaddon.UnicacityAddon;
import com.rettichlp.unicacityaddon.base.AddonPlayer;
import com.rettichlp.unicacityaddon.base.enums.api.StatisticType;
import com.rettichlp.unicacityaddon.base.registry.annotation.UCEvent;
import com.rettichlp.unicacityaddon.base.text.ColorCode;
import com.rettichlp.unicacityaddon.base.text.Message;
import com.rettichlp.unicacityaddon.base.text.PatternHandler;
import com.rettichlp.unicacityaddon.commands.ShutdownJailCommand;
import net.labymod.api.client.component.event.ClickEvent;
import net.labymod.api.client.component.event.HoverEvent;
import net.labymod.api.event.Subscribe;
import net.labymod.api.event.client.chat.ChatReceiveEvent;

Expand All @@ -27,6 +32,7 @@ public TimerListener(UnicacityAddon unicacityAddon) {

@Subscribe
public void onChatReceive(ChatReceiveEvent e) {
AddonPlayer p = this.unicacityAddon.player();
String msg = e.chatMessage().getPlainText();

Matcher fbiHackStartedMatcher = PatternHandler.TIMER_FBI_HACK_START_PATTERN.matcher(msg);
Expand All @@ -44,6 +50,16 @@ public void onChatReceive(ChatReceiveEvent e) {
this.unicacityAddon.fileService().data().setTimer(seconds);
}

p.sendMessage(Message.getBuilder()
.info().space()
.of("Das UnicacityAddon nimmt Erste Hilfe automatisch an. Klicke").color(ColorCode.WHITE).advance().space()
.of("hier").color(ColorCode.RED).underline()
.hoverEvent(HoverEvent.Action.SHOW_TEXT, Message.getBuilder().of("Erste Hilfe nicht automatisch annehmen").color(ColorCode.RED).advance().createComponent())
.clickEvent(ClickEvent.Action.RUN_COMMAND, "/autofirstaid off")
.advance().space()
.of("um die Funktion zu deaktivieren.").color(ColorCode.WHITE).advance().space()
.createComponent());

return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import com.rettichlp.unicacityaddon.base.text.ColorCode;
import com.rettichlp.unicacityaddon.base.text.Message;
import com.rettichlp.unicacityaddon.base.text.PatternHandler;
import com.rettichlp.unicacityaddon.commands.AutoFirstAidCommand;
import net.labymod.api.client.component.event.HoverEvent;
import net.labymod.api.event.Subscribe;
import net.labymod.api.event.client.chat.ChatReceiveEvent;
import net.labymod.api.event.client.render.ScreenRenderEvent;

import java.util.Timer;
import java.util.TimerTask;
Expand Down Expand Up @@ -58,4 +60,15 @@ public void run() {
}, TimeUnit.SECONDS.toMillis(90));
}
}

@Subscribe
public void onScreenRender(ScreenRenderEvent e) {
boolean isFirstAidContainer = this.unicacityAddon.guiController().containsItemContainingString("Erste-Hilfe von ");

if (isFirstAidContainer && AutoFirstAidCommand.autoAcceptFirstAid) {
this.unicacityAddon.utilService().debug("Found first aid container");
this.unicacityAddon.guiController().inventoryClick(1);
this.unicacityAddon.logger().info("Accepted first aid automatically");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,18 @@ public void updateSetting(boolean expectedValue) {
}
}
}

@Override
public boolean containsItemContainingString(String name) {
NonNullList<ItemStack> itemStackNonNullList = null;

GuiScreen guiScreen = Minecraft.getMinecraft().currentScreen;
if (guiScreen instanceof GuiChest guiChest) {
itemStackNonNullList = guiChest.inventorySlots.getInventory();
} else if (guiScreen instanceof GuiHopper guiHopper) {
itemStackNonNullList = guiHopper.inventorySlots.getInventory();
}

return itemStackNonNullList != null && itemStackNonNullList.stream().anyMatch(itemStack -> itemStack.getDisplayName().contains(name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,18 @@ public void updateSetting(boolean expectedValue) {
}
}
}

@Override
public boolean containsItemContainingString(String name) {
NonNullList<ItemStack> itemStackNonNullList = null;

Screen screen = Minecraft.getInstance().screen;
if (screen instanceof ContainerScreen containerScreen) {
itemStackNonNullList = containerScreen.getMenu().getItems();
} else if (screen instanceof HopperScreen hopperScreen) {
itemStackNonNullList = hopperScreen.getMenu().getItems();
}

return itemStackNonNullList != null && itemStackNonNullList.stream().anyMatch(itemStack -> itemStack.getDisplayName().getContents().contains(name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,18 @@ public void updateSetting(boolean expectedValue) {
}
}
}

@Override
public boolean containsItemContainingString(String name) {
NonNullList<ItemStack> itemStackNonNullList = null;

Screen screen = Minecraft.getInstance().screen;
if (screen instanceof ContainerScreen containerScreen) {
itemStackNonNullList = containerScreen.getMenu().getItems();
} else if (screen instanceof HopperScreen hopperScreen) {
itemStackNonNullList = hopperScreen.getMenu().getItems();
}

return itemStackNonNullList != null && itemStackNonNullList.stream().anyMatch(itemStack -> itemStack.getDisplayName().getContents().contains(name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,18 @@ public void updateSetting(boolean expectedValue) {
}
}
}

@Override
public boolean containsItemContainingString(String name) {
NonNullList<ItemStack> itemStackNonNullList = null;

Screen screen = Minecraft.getInstance().screen;
if (screen instanceof ContainerScreen containerScreen) {
itemStackNonNullList = containerScreen.getMenu().getItems();
} else if (screen instanceof HopperScreen hopperScreen) {
itemStackNonNullList = hopperScreen.getMenu().getItems();
}

return itemStackNonNullList != null && itemStackNonNullList.stream().anyMatch(itemStack -> itemStack.getDisplayName().getContents().contains(name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,18 @@ public void updateSetting(boolean expectedValue) {
}
}
}

@Override
public boolean containsItemContainingString(String name) {
NonNullList<ItemStack> itemStackNonNullList = null;

Screen screen = Minecraft.getInstance().screen;
if (screen instanceof ContainerScreen containerScreen) {
itemStackNonNullList = containerScreen.getMenu().getItems();
} else if (screen instanceof HopperScreen hopperScreen) {
itemStackNonNullList = hopperScreen.getMenu().getItems();
}

return itemStackNonNullList != null && itemStackNonNullList.stream().anyMatch(itemStack -> itemStack.getDisplayName().getContents().toString().contains(name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,18 @@ public void updateSetting(boolean expectedValue) {
}
}
}

@Override
public boolean containsItemContainingString(String name) {
NonNullList<ItemStack> itemStackNonNullList = null;

Screen screen = Minecraft.getInstance().screen;
if (screen instanceof ContainerScreen containerScreen) {
itemStackNonNullList = containerScreen.getMenu().getItems();
} else if (screen instanceof HopperScreen hopperScreen) {
itemStackNonNullList = hopperScreen.getMenu().getItems();
}

return itemStackNonNullList != null && itemStackNonNullList.stream().anyMatch(itemStack -> itemStack.getDisplayName().getContents().toString().contains(name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,18 @@ public void updateSetting(boolean expectedValue) {
}
}
}

@Override
public boolean containsItemContainingString(String name) {
NonNullList<ItemStack> itemStackNonNullList = null;

Screen screen = Minecraft.getInstance().screen;
if (screen instanceof ContainerScreen containerScreen) {
itemStackNonNullList = containerScreen.getMenu().getItems();
} else if (screen instanceof HopperScreen hopperScreen) {
itemStackNonNullList = hopperScreen.getMenu().getItems();
}

return itemStackNonNullList != null && itemStackNonNullList.stream().anyMatch(itemStack -> itemStack.getDisplayName().getContents().toString().contains(name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,18 @@ public void updateSetting(boolean expectedValue) {
}
}
}

@Override
public boolean containsItemContainingString(String name) {
NonNullList<ItemStack> itemStackNonNullList = null;

Screen screen = Minecraft.getInstance().screen;
if (screen instanceof ContainerScreen containerScreen) {
itemStackNonNullList = containerScreen.getMenu().getItems();
} else if (screen instanceof HopperScreen hopperScreen) {
itemStackNonNullList = hopperScreen.getMenu().getItems();
}

return itemStackNonNullList != null && itemStackNonNullList.stream().anyMatch(itemStack -> itemStack.getDisplayName().getContents().toString().contains(name));
}
}