package im.expensive;
import com.google.common.eventbus.EventBus;
import im.expensive.command.*;
import im.expensive.command.friends.FriendStorage;
import im.expensive.command.impl.*;
import im.expensive.command.impl.feature.*;
import im.expensive.command.staffs.StaffStorage;
import im.expensive.config.ConfigStorage;
import im.expensive.events.EventKey;
import im.expensive.functions.api.Function;
import im.expensive.functions.api.FunctionRegistry;
import im.expensive.scripts.client.ScriptManager;
import im.expensive.ui.ab.factory.*;
import im.expensive.ui.ab.logic.ActivationLogic;
import im.expensive.ui.ab.model.*;
import im.expensive.ui.ab.render.Window;
import im.expensive.ui.autobuy.*;
import im.expensive.ui.dropdown.DropDown;
import im.expensive.ui.mainmenu.*;
import im.expensive.ui.styles.*;
import im.expensive.utils.TPSCalc;
import im.expensive.utils.client.ServerTPS;
import im.expensive.utils.drag.*;
import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import net.minecraft.client.Minecraft;
import net.minecraft.util.text.StringTextComponent;
import via.ViaMCP;
public class Expensive {
public static UserData userData;
public boolean playerOnServer = false;
public static final String CLIENT_NAME = "expensive solutions";
private static Expensive instance;
private FunctionRegistry functionRegistry;
private ConfigStorage configStorage;
private CommandDispatcher commandDispatcher;
private ServerTPS serverTPS;
private MacroManager macroManager;
private StyleManager styleManager;
private final EventBus eventBus = new EventBus();
private final ScriptManager scriptManager = new ScriptManager();
private final File clientDir;
private final File filesDir;
private AltWidget altWidget;
private AltConfig altConfig;
private DropDown dropDown;
private Window autoBuyUI;
private AutoBuyConfig autoBuyConfig;
private AutoBuyHandler autoBuyHandler;
private ViaMCP viaMCP;
private TPSCalc tpsCalc;
private ActivationLogic activationLogic;
private ItemStorage itemStorage;
private final EventKey eventKey;
public Expensive() {
clientDir = new File(Minecraft.getInstance().gameDir + "\\expensive");
filesDir = new File(Minecraft.getInstance().gameDir + "\\expensive\\files");
autoBuyConfig = new AutoBuyConfig();
eventKey = new EventKey(-1);
instance = this;
if (!clientDir.exists()) clientDir.mkdirs();
if (!filesDir.exists()) filesDir.mkdirs();
clientLoad();
FriendStorage.load();
StaffStorage.load();
}
public Dragging createDrag(Function function, String key, float x, float y) {
DragManager.draggables.put(key, new Dragging(function, key, x, y));
return (Dragging) DragManager.draggables.get(key);
}
private void clientLoad() {
viaMCP = new ViaMCP();
serverTPS = new ServerTPS();
functionRegistry = new FunctionRegistry();
macroManager = new MacroManager();
configStorage = new ConfigStorage();
functionRegistry.init();
initCommands();
initStyles();
altWidget = new AltWidget();
altConfig = new AltConfig();
tpsCalc = new TPSCalc();
try {
autoBuyConfig.init();
} catch (Exception e) {
e.printStackTrace();
}
try {
altConfig.init();
} catch (Exception e) {
e.printStackTrace();
}
try {
configStorage.init();
} catch (IOException e) {
System.out.println("Can't load config storage");
}
try {
macroManager.init();
} catch (IOException e) {
System.out.println("Can't load macro manager");
}
DragManager.load();
dropDown = new DropDown(new StringTextComponent(""));
initAutoBuy();
autoBuyUI = new Window(new StringTextComponent(""), itemStorage);
autoBuyHandler = new AutoBuyHandler();
autoBuyConfig = new AutoBuyConfig();
eventBus.register(this);
}
public void onKeyPressed(int keyCode) {
if (!functionRegistry.getSelfDestruct().unhooked) {
eventKey.setKey(keyCode);
eventBus.post(eventKey);
macroManager.onKeyPressed(keyCode);
if (keyCode == 344) {
Minecraft.getInstance().displayGuiScreen(dropDown);
}
if (functionRegistry.getAutoBuyUI().isState()
&& (Integer) functionRegistry.getAutoBuyUI().setting.get() == keyCode) {
Minecraft.getInstance().displayGuiScreen(autoBuyUI);
}
}
}
private void initAutoBuy() {
ItemFactory itemFactory = new ItemFactoryImpl();
CopyOnWriteArrayList<IItem> items = new CopyOnWriteArrayList<>();
itemStorage = new ItemStorage(items, itemFactory);
activationLogic = new ActivationLogic(itemStorage, eventBus);
}
private void initCommands() {
Minecraft mc = Minecraft.getInstance();
Logger logger = new MultiLogger(List.of(new ConsoleLogger(), new MinecraftLogger()));
List<Command> commands = new ArrayList<>();
Prefix prefix = new PrefixImpl();
commands.add(new ListCommand(commands, logger));
commands.add(new FriendCommand(prefix, logger, mc));
commands.add(new BindCommand(prefix, logger));
commands.add(new GPSCommand(prefix, logger));
commands.add(new ConfigCommand(configStorage, prefix, logger));
commands.add(new MacroCommand(macroManager, prefix, logger));
commands.add(new VClipCommand(prefix, logger, mc));
commands.add(new HClipCommand(prefix, logger, mc));
commands.add(new StaffCommand(prefix, logger));
commands.add(new MemoryCommand(logger));
commands.add(new RCTCommand(logger, mc));
AdviceCommandFactory adviceFactory = new AdviceCommandFactoryImpl(logger);
ParametersFactory parametersFactory = new ParametersFactoryImpl();
commandDispatcher = new StandaloneCommandDispatcher(
commands, adviceFactory, prefix, parametersFactory, logger
);
}
private void initStyles() {
StyleFactory styleFactory = new StyleFactoryImpl();
List<Style> styles = new ArrayList<>();
styles.add(styleFactory.createStyle("Default",
new Color(5, 50, 55), new Color(55, 10, 55)));
styles.add(styleFactory.createStyle("Aqua Storm",
new Color(55, 50, 10), new Color(45, 15, 55)));
styles.add(styleFactory.createStyle("Neon Pulse",
new Color(35, 5, 55), new Color(55, 20, 45)));
styles.add(styleFactory.createStyle("Dark Void",
new Color(45, 55, 45), new Color(55, 45, 45)));
styles.add(styleFactory.createStyle("Deep Ocean",
new Color(55, 45, 0), new Color(45, 55, 0)));
styles.add(styleFactory.createStyle("Cyber Storm RGB",
new Color(20, 10, 10), new Color(55, 55, 55)));
styles.add(styleFactory.createStyle("Emerald Wave",
new Color(5, 45, 55), new Color(15, 55, 45)));
styles.add(styleFactory.createStyle("Cosmic Glow",
new Color(55, 5, 20), new Color(45, 45, 45)));
styleManager = new StyleManager(styles, styles.get(0));
}
public static Expensive getInstance() { return instance; }
public boolean isPlayerOnServer() { return playerOnServer; }
public FunctionRegistry getFunctionRegistry() { return functionRegistry; }
public ConfigStorage getConfigStorage() { return configStorage; }
public CommandDispatcher getCommandDispatcher(){ return commandDispatcher; }
public ServerTPS getServerTPS() { return serverTPS; }
public MacroManager getMacroManager() { return macroManager; }
public StyleManager getStyleManager() { return styleManager; }
public EventBus getEventBus() { return eventBus; }
public ScriptManager getScriptManager() { return scriptManager; }
public File getClientDir() { return clientDir; }
public File getFilesDir() { return filesDir; }
public AltWidget getAltWidget() { return altWidget; }
public AltConfig getAltConfig() { return altConfig; }
public DropDown getDropDown() { return dropDown; }
public Window getAutoBuyUI() { return autoBuyUI; }
public AutoBuyConfig getAutoBuyConfig() { return autoBuyConfig; }
public AutoBuyHandler getAutoBuyHandler() { return autoBuyHandler; }
public ViaMCP getViaMCP() { return viaMCP; }
public TPSCalc getTpsCalc() { return tpsCalc; }
public ActivationLogic getActivationLogic() { return activationLogic; }
public ItemStorage getItemStorage() { return itemStorage; }
public EventKey getEventKey() { return eventKey; }
}