From 84d782c18bde0ca964c48f13ee449dc8cb190160 Mon Sep 17 00:00:00 2001 From: Jess Date: Sat, 26 Aug 2023 15:19:12 +0100 Subject: [PATCH] Initial commit --- .gitignore | 3 + .idea/.gitignore | 3 + .idea/.name | 1 + .idea/compiler.xml | 16 ++ .idea/discord.xml | 7 + .idea/gradle.xml | 21 ++ .idea/jarRepositories.xml | 50 ++++ .idea/misc.xml | 13 + .idea/modules.xml | 11 + .idea/modules/Client/BaseBand.Client.main.iml | 24 ++ .idea/modules/Client/BaseBand.Client.test.iml | 19 ++ .idea/modules/Loader/BaseBand.Loader.main.iml | 26 ++ .idea/modules/Loader/BaseBand.Loader.test.iml | 21 ++ .idea/uiDesigner.xml | 124 ++++++++++ .idea/vcs.xml | 6 + Client/.gitignore | 42 ++++ Client/build.gradle | 107 ++++++++ Client/gradle.properties | 7 + .../main/java/com/baseband/client/Main.java | 40 +++ .../main/java/com/baseband/client/Utils.java | 17 ++ .../com/baseband/client/command/Command.java | 21 ++ .../client/command/CommandManager.java | 62 +++++ .../command/commands/CreditsCommand.java | 16 ++ .../client/command/commands/HelpCommand.java | 14 ++ .../command/commands/ToggleCommand.java | 24 ++ .../java/com/baseband/client/event/Event.java | 13 + .../baseband/client/event/EventManager.java | 75 ++++++ .../client/event/events/SafeTickEvent.java | 9 + .../java/com/baseband/client/gui/Button.java | 46 ++++ .../com/baseband/client/gui/ButtonList.java | 32 +++ .../com/baseband/client/gui/ClickGui.java | 54 ++++ .../baseband/client/mixins/MixinForgeBus.java | 13 + .../client/mixins/MixinMinecraft.java | 19 ++ .../com/baseband/client/module/Module.java | 48 ++++ .../client/module/ModuleRegistry.java | 64 +++++ .../client/module/modules/ClickGUI.java | 19 ++ .../baseband/client/module/modules/HUD.java | 21 ++ .../baseband/client/module/modules/Test.java | 24 ++ Client/src/main/resources/client_at.cfg | 0 Client/src/main/resources/mcmod.info | 15 ++ .../src/main/resources/mixins.baseband.json | 10 + Installer/.gitignore | 42 ++++ Installer/build.gradle | 58 +++++ .../java/com/thnkscj/installer/Installer.java | 19 ++ .../util/library/LibraryInstaller.java | 41 +++ .../util/minecraft/MinecraftFiles.java | 42 ++++ .../util/version/VersionInstaller.java | 78 ++++++ Loader/.gitignore | 42 ++++ Loader/build.gradle | 120 +++++++++ Loader/gradle.properties | 7 + .../java/org/baseband/launcher/Tweaker.java | 63 +++++ .../org/baseband/launcher/launch/Loader.java | 127 ++++++++++ .../tweaker/CfgAccessTransformer.java | 11 + .../org/baseband/launcher/tweaker/Core.java | 26 ++ .../launcher/util/CustomClassloader.java | 100 ++++++++ .../java/org/baseband/launcher/util/HWID.java | 23 ++ README.md | 49 ++++ Server/.gitignore | 42 ++++ Server/build.gradle | 18 ++ .../main/java/dev/baseband/server/Main.java | 11 + .../baseband/server/socket/ClientHandler.java | 59 +++++ .../dev/baseband/server/socket/Socket.java | 47 ++++ .../baseband/server/socket/UserManager.java | 75 ++++++ .../dev/baseband/server/socket/UserMap.java | 63 +++++ build.gradle | 14 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 60756 bytes gradle/wrapper/gradle-wrapper.properties | 5 + gradlew | 234 ++++++++++++++++++ gradlew.bat | 89 +++++++ settings.gradle | 6 + 70 files changed, 2668 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/.name create mode 100644 .idea/compiler.xml create mode 100644 .idea/discord.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/modules/Client/BaseBand.Client.main.iml create mode 100644 .idea/modules/Client/BaseBand.Client.test.iml create mode 100644 .idea/modules/Loader/BaseBand.Loader.main.iml create mode 100644 .idea/modules/Loader/BaseBand.Loader.test.iml create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml create mode 100644 Client/.gitignore create mode 100644 Client/build.gradle create mode 100644 Client/gradle.properties create mode 100644 Client/src/main/java/com/baseband/client/Main.java create mode 100644 Client/src/main/java/com/baseband/client/Utils.java create mode 100644 Client/src/main/java/com/baseband/client/command/Command.java create mode 100644 Client/src/main/java/com/baseband/client/command/CommandManager.java create mode 100644 Client/src/main/java/com/baseband/client/command/commands/CreditsCommand.java create mode 100644 Client/src/main/java/com/baseband/client/command/commands/HelpCommand.java create mode 100644 Client/src/main/java/com/baseband/client/command/commands/ToggleCommand.java create mode 100644 Client/src/main/java/com/baseband/client/event/Event.java create mode 100644 Client/src/main/java/com/baseband/client/event/EventManager.java create mode 100644 Client/src/main/java/com/baseband/client/event/events/SafeTickEvent.java create mode 100644 Client/src/main/java/com/baseband/client/gui/Button.java create mode 100644 Client/src/main/java/com/baseband/client/gui/ButtonList.java create mode 100644 Client/src/main/java/com/baseband/client/gui/ClickGui.java create mode 100644 Client/src/main/java/com/baseband/client/mixins/MixinForgeBus.java create mode 100644 Client/src/main/java/com/baseband/client/mixins/MixinMinecraft.java create mode 100644 Client/src/main/java/com/baseband/client/module/Module.java create mode 100644 Client/src/main/java/com/baseband/client/module/ModuleRegistry.java create mode 100644 Client/src/main/java/com/baseband/client/module/modules/ClickGUI.java create mode 100644 Client/src/main/java/com/baseband/client/module/modules/HUD.java create mode 100644 Client/src/main/java/com/baseband/client/module/modules/Test.java create mode 100644 Client/src/main/resources/client_at.cfg create mode 100644 Client/src/main/resources/mcmod.info create mode 100644 Client/src/main/resources/mixins.baseband.json create mode 100644 Installer/.gitignore create mode 100644 Installer/build.gradle create mode 100644 Installer/src/main/java/com/thnkscj/installer/Installer.java create mode 100644 Installer/src/main/java/com/thnkscj/installer/util/library/LibraryInstaller.java create mode 100644 Installer/src/main/java/com/thnkscj/installer/util/minecraft/MinecraftFiles.java create mode 100644 Installer/src/main/java/com/thnkscj/installer/util/version/VersionInstaller.java create mode 100644 Loader/.gitignore create mode 100644 Loader/build.gradle create mode 100644 Loader/gradle.properties create mode 100644 Loader/src/main/java/org/baseband/launcher/Tweaker.java create mode 100644 Loader/src/main/java/org/baseband/launcher/launch/Loader.java create mode 100644 Loader/src/main/java/org/baseband/launcher/tweaker/CfgAccessTransformer.java create mode 100644 Loader/src/main/java/org/baseband/launcher/tweaker/Core.java create mode 100644 Loader/src/main/java/org/baseband/launcher/util/CustomClassloader.java create mode 100644 Loader/src/main/java/org/baseband/launcher/util/HWID.java create mode 100644 README.md create mode 100644 Server/.gitignore create mode 100644 Server/build.gradle create mode 100644 Server/src/main/java/dev/baseband/server/Main.java create mode 100644 Server/src/main/java/dev/baseband/server/socket/ClientHandler.java create mode 100644 Server/src/main/java/dev/baseband/server/socket/Socket.java create mode 100644 Server/src/main/java/dev/baseband/server/socket/UserManager.java create mode 100644 Server/src/main/java/dev/baseband/server/socket/UserMap.java create mode 100644 build.gradle create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b740e72 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# Project exclude paths +/.gradle/ +/build/ \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..35b96d3 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +BaseBand \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..beb2915 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/discord.xml b/.idea/discord.xml new file mode 100644 index 0000000..d8e9561 --- /dev/null +++ b/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..b576a7a --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,21 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..5aba590 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..508965a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..d6e9b12 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/Client/BaseBand.Client.main.iml b/.idea/modules/Client/BaseBand.Client.main.iml new file mode 100644 index 0000000..081693b --- /dev/null +++ b/.idea/modules/Client/BaseBand.Client.main.iml @@ -0,0 +1,24 @@ + + + + + + + + + + + + MIXIN + + + + + + + \ No newline at end of file diff --git a/.idea/modules/Client/BaseBand.Client.test.iml b/.idea/modules/Client/BaseBand.Client.test.iml new file mode 100644 index 0000000..68324d7 --- /dev/null +++ b/.idea/modules/Client/BaseBand.Client.test.iml @@ -0,0 +1,19 @@ + + + + + + + MIXIN + + + + + + + \ No newline at end of file diff --git a/.idea/modules/Loader/BaseBand.Loader.main.iml b/.idea/modules/Loader/BaseBand.Loader.main.iml new file mode 100644 index 0000000..c896813 --- /dev/null +++ b/.idea/modules/Loader/BaseBand.Loader.main.iml @@ -0,0 +1,26 @@ + + + + + + + + + + + + FORGE + MIXIN + MCP + + + + + + + \ No newline at end of file diff --git a/.idea/modules/Loader/BaseBand.Loader.test.iml b/.idea/modules/Loader/BaseBand.Loader.test.iml new file mode 100644 index 0000000..0aca131 --- /dev/null +++ b/.idea/modules/Loader/BaseBand.Loader.test.iml @@ -0,0 +1,21 @@ + + + + + + + FORGE + MIXIN + MCP + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Client/.gitignore b/Client/.gitignore new file mode 100644 index 0000000..b63da45 --- /dev/null +++ b/Client/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Client/build.gradle b/Client/build.gradle new file mode 100644 index 0000000..990447e --- /dev/null +++ b/Client/build.gradle @@ -0,0 +1,107 @@ +buildscript { + repositories { + maven { url = 'https://maven.minecraftforge.net' } + maven { url = 'https://repo.spongepowered.org/repository/maven-public' } + mavenCentral() + } + dependencies { + classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.1', changing: true + classpath "org.spongepowered:mixingradle:0.7.+" + } +} + +apply plugin: 'net.minecraftforge.gradle' +apply plugin: 'org.spongepowered.mixin' +apply plugin: 'eclipse' +apply plugin: 'idea' +apply plugin: 'java' + +group = project.modGroup +version = project.modVersion + +sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' + +tasks.withType(JavaCompile) { + configure(options) { + options.compilerArgs.add("-XDignore.symbol.file=true") + options.encoding = 'utf-8' + } +} + +minecraft { + mappings channel: 'stable', version: '39-1.12' + accessTransformer = file('src/main/resources/client_at.cfg') + + runs { + client { + workingDirectory project.file('run') + + property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' + property 'forge.logging.console.level', 'debug' + } + } +} + +repositories { + maven { + name = 'spongepowered-repo' + url = 'https://repo.spongepowered.org/maven' + } + + maven { + name = "jitpack.io" + url = "https://jitpack.io" + } + + mavenCentral() +} + +dependencies { + + + minecraft 'net.minecraftforge:forge:1.12.2-14.23.5.2860' + + implementation('org.spongepowered:mixin:0.7.11-SNAPSHOT') { + exclude module: 'launchwrapper' + exclude module: 'guava' + exclude module: 'gson' + exclude module: 'commons-io' + exclude module: 'log4j-core' + } + + annotationProcessor('org.spongepowered:mixin:0.8.5:processor') { + exclude module: 'gson' + } +} + +compileJava { + def targetFile = file("src/main/java/com/baseband/client/Main.java") + def content = targetFile.text + def updatedContent = content.replaceFirst("buildNumber = (\\d+)", { _, value -> "buildNumber = ${value.toInteger() + 1}" }) + targetFile.text = updatedContent +} + +processResources { + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + + inputs.property 'version', project.version + inputs.property 'mcversion', '1.12.2' + + from(sourceSets.main.resources.srcDirs) { + include 'mcmod.info' + expand 'version': project.version, 'mcversion': '1.12.2' + } + + from(sourceSets.main.resources.srcDirs) { exclude 'mcmod.info' } + + rename '(.+_at.cfg)', 'META-INF/$1' +} + +mixin { + defaultObfuscationEnv 'searge' + add sourceSets.main, 'mixins.baseband.refmap.json' +} + +jar { + duplicatesStrategy = DuplicatesStrategy.EXCLUDE +} \ No newline at end of file diff --git a/Client/gradle.properties b/Client/gradle.properties new file mode 100644 index 0000000..973e3a8 --- /dev/null +++ b/Client/gradle.properties @@ -0,0 +1,7 @@ +org.gradle.jvmargs=-Xmx4G +org.gradle.daemon=false + +modGroup=dev.baseband +modVersion=1.0.0 +mcpVersion=snapshot_20180814 +forgeVersion=1.12.2-14.23.5.2847 diff --git a/Client/src/main/java/com/baseband/client/Main.java b/Client/src/main/java/com/baseband/client/Main.java new file mode 100644 index 0000000..8a5397d --- /dev/null +++ b/Client/src/main/java/com/baseband/client/Main.java @@ -0,0 +1,40 @@ +package com.baseband.client; + + +import com.baseband.client.command.CommandManager; +import com.baseband.client.event.EventManager; +import com.baseband.client.event.events.SafeTickEvent; +import com.baseband.client.module.ModuleRegistry; +import net.minecraft.client.Minecraft; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class Main { + public static int buildNumber = 11; + public static EventManager EVENT_MANAGER; + public static final String name = "BaseBand"; + public static ModuleRegistry moduleRegistry; + public static CommandManager commandRegistry; + public static final Logger log = LogManager.getLogger("BaseBand"); + + public static void onInit() { + EVENT_MANAGER = new EventManager(); + moduleRegistry = new ModuleRegistry(); + commandRegistry = new CommandManager(); + + log.info("BaseBand Instantiated."); + } + + @SubscribeEvent + public void tick(TickEvent.ClientTickEvent e) { + if(isIngame()) { + EVENT_MANAGER.publish(new SafeTickEvent()); + } + } + + public static boolean isIngame() { + return Minecraft.getMinecraft().world != null && Minecraft.getMinecraft().player != null; + } +} diff --git a/Client/src/main/java/com/baseband/client/Utils.java b/Client/src/main/java/com/baseband/client/Utils.java new file mode 100644 index 0000000..c69847f --- /dev/null +++ b/Client/src/main/java/com/baseband/client/Utils.java @@ -0,0 +1,17 @@ +package com.baseband.client; + +import net.minecraft.client.Minecraft; +import net.minecraft.util.text.TextComponentString; + +public class Utils { + public static void sendChatMessage(String e) { + if (Main.isIngame()) { + try { + Minecraft.getMinecraft().player.sendMessage(new TextComponentString("[" + "§a" + Main.name + "§r" + "]" + " " + e)); + } catch (Exception ee) { + ee.printStackTrace(); + } + } + } + +} diff --git a/Client/src/main/java/com/baseband/client/command/Command.java b/Client/src/main/java/com/baseband/client/command/Command.java new file mode 100644 index 0000000..51ac7c0 --- /dev/null +++ b/Client/src/main/java/com/baseband/client/command/Command.java @@ -0,0 +1,21 @@ +package com.baseband.client.command; + +import net.minecraft.client.Minecraft; + +public abstract class Command { + protected static Minecraft mc = Minecraft.getMinecraft(); + String commandName; + + + public Command(String name) { + super(); + commandName = name; + + } + + public String getName() { + return commandName; + } + + public abstract String run(String[] args); +} diff --git a/Client/src/main/java/com/baseband/client/command/CommandManager.java b/Client/src/main/java/com/baseband/client/command/CommandManager.java new file mode 100644 index 0000000..76a881f --- /dev/null +++ b/Client/src/main/java/com/baseband/client/command/CommandManager.java @@ -0,0 +1,62 @@ +package com.baseband.client.command; + +import com.baseband.client.Utils; +import com.baseband.client.command.commands.CreditsCommand; +import com.baseband.client.command.commands.HelpCommand; +import com.baseband.client.command.commands.ToggleCommand; +import net.minecraftforge.client.event.ClientChatEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +import java.util.ArrayList; +import java.util.Arrays; + +public class CommandManager { + + + public String commandPrefix = "="; + + + public ArrayList commands = new ArrayList<>(); + + public CommandManager() { + registerCommands(); + MinecraftForge.EVENT_BUS.register(this); + } + + public void registerCommands() { + commands.add(new CreditsCommand()); + commands.add(new HelpCommand()); + commands.add(new ToggleCommand()); + } + + @SubscribeEvent + public void onChat(ClientChatEvent event) { + String message = event.getOriginalMessage(); + if (message.startsWith(commandPrefix)) { + event.setCanceled(true); + + + String[] split = message.split(" "); + + String name = split[0].replace(commandPrefix, ""); + String[] args = Arrays.copyOfRange(split, 1, split.length); + + Command cmd = null; + + for (Command command : commands) { + if (command.getName().equalsIgnoreCase(name)) { + cmd = command; + break; + } + } + + if (cmd != null) { + Utils.sendChatMessage(cmd.run(args)); + } else { + Utils.sendChatMessage("Incorrect command."); + } + } + } + +} diff --git a/Client/src/main/java/com/baseband/client/command/commands/CreditsCommand.java b/Client/src/main/java/com/baseband/client/command/commands/CreditsCommand.java new file mode 100644 index 0000000..d31fc2f --- /dev/null +++ b/Client/src/main/java/com/baseband/client/command/commands/CreditsCommand.java @@ -0,0 +1,16 @@ +package com.baseband.client.command.commands; + +import com.baseband.client.Utils; +import com.baseband.client.command.Command; + +public class CreditsCommand extends Command { + public CreditsCommand() { + super("credits"); + } + + @Override + public String run(String[] args) { + Utils.sendChatMessage("Base and most of the loader written by JessSystemV, John200410 helped with the loader."); + return null; + } +} diff --git a/Client/src/main/java/com/baseband/client/command/commands/HelpCommand.java b/Client/src/main/java/com/baseband/client/command/commands/HelpCommand.java new file mode 100644 index 0000000..0b54854 --- /dev/null +++ b/Client/src/main/java/com/baseband/client/command/commands/HelpCommand.java @@ -0,0 +1,14 @@ +package com.baseband.client.command.commands; + +import com.baseband.client.command.Command; + +public class HelpCommand extends Command { + public HelpCommand() { + super("help"); + } + + @Override + public String run(String[] args) { + return "BaseBand Rewrite Copyright (2023) JessSystemV"; + } +} diff --git a/Client/src/main/java/com/baseband/client/command/commands/ToggleCommand.java b/Client/src/main/java/com/baseband/client/command/commands/ToggleCommand.java new file mode 100644 index 0000000..e795d57 --- /dev/null +++ b/Client/src/main/java/com/baseband/client/command/commands/ToggleCommand.java @@ -0,0 +1,24 @@ +package com.baseband.client.command.commands; + +import com.baseband.client.Main; +import com.baseband.client.command.Command; +import com.baseband.client.module.Module; + +public class ToggleCommand extends Command { + public ToggleCommand() { + super("toggle"); + } + + @Override + public String run(String[] args) { + if (args.length != 1) { + return "Please specify a module name."; + } + Module module = Main.moduleRegistry.getModule(args[0]); + if (module == null) { + return "Cannot find module."; + } + module.setEnabled(!module.isEnabled()); + return module.getName() + " toggled. (" + module.isEnabled() + ")"; + } +} diff --git a/Client/src/main/java/com/baseband/client/event/Event.java b/Client/src/main/java/com/baseband/client/event/Event.java new file mode 100644 index 0000000..854e423 --- /dev/null +++ b/Client/src/main/java/com/baseband/client/event/Event.java @@ -0,0 +1,13 @@ +package com.baseband.client.event; + +public class Event { + boolean isCancelled = false; + + public void setCancelled(boolean cancelled) { + isCancelled = cancelled; + } + + public boolean isCancelled() { + return isCancelled; + } +} diff --git a/Client/src/main/java/com/baseband/client/event/EventManager.java b/Client/src/main/java/com/baseband/client/event/EventManager.java new file mode 100644 index 0000000..5aa6dd2 --- /dev/null +++ b/Client/src/main/java/com/baseband/client/event/EventManager.java @@ -0,0 +1,75 @@ +package com.baseband.client.event; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class EventManager { + private final Map, List> subscribers; + private final Object lock; + + public EventManager() { + subscribers = new HashMap<>(); + lock = new Object(); + } + + public void subscribe(Object subscriber) { + Class subscriberClass = subscriber.getClass(); + Method[] methods = subscriberClass.getDeclaredMethods(); + + for (Method method : methods) { + Class[] parameterTypes = method.getParameterTypes(); + if (parameterTypes.length == 1 && Event.class.isAssignableFrom(parameterTypes[0])) { + @SuppressWarnings("unchecked") + Class eventType = (Class) parameterTypes[0]; + SubscriberMethod subscriberMethod = new SubscriberMethod(subscriber, method); + + synchronized (lock) { + List eventSubscribers = subscribers.getOrDefault(eventType, new ArrayList<>()); + eventSubscribers.add(subscriberMethod); + subscribers.put(eventType, eventSubscribers); + } + } + } + } + + public void unsubscribe(Object subscriber) { + synchronized (lock) { + for (List eventSubscribers : subscribers.values()) { + eventSubscribers.removeIf(subscriberMethod -> subscriberMethod.subscriber == subscriber); + } + } + } + + public void publish(Event event) { + Class eventType = event.getClass(); + List eventSubscribers; + synchronized (lock) { + eventSubscribers = new ArrayList<>(subscribers.getOrDefault(eventType, new ArrayList<>())); + } + for (SubscriberMethod subscriberMethod : eventSubscribers) { + subscriberMethod.invoke(event); + } + } + + private static class SubscriberMethod { + private final Object subscriber; + private final Method method; + + private SubscriberMethod(Object subscriber, Method method) { + this.subscriber = subscriber; + this.method = method; + this.method.setAccessible(true); + } + + private void invoke(Event event) { + try { + method.invoke(subscriber, event); + } catch (Exception e) { + e.printStackTrace(); + } + } + } +} diff --git a/Client/src/main/java/com/baseband/client/event/events/SafeTickEvent.java b/Client/src/main/java/com/baseband/client/event/events/SafeTickEvent.java new file mode 100644 index 0000000..f25353e --- /dev/null +++ b/Client/src/main/java/com/baseband/client/event/events/SafeTickEvent.java @@ -0,0 +1,9 @@ +package com.baseband.client.event.events; + +import com.baseband.client.event.Event; + + + +public class SafeTickEvent extends Event { +//Stub +} diff --git a/Client/src/main/java/com/baseband/client/gui/Button.java b/Client/src/main/java/com/baseband/client/gui/Button.java new file mode 100644 index 0000000..8f56c70 --- /dev/null +++ b/Client/src/main/java/com/baseband/client/gui/Button.java @@ -0,0 +1,46 @@ +package com.baseband.client.gui; + +public abstract class Button { + + private int x, y, width, height; + private boolean hovered; + + public Button(int x, int y, int width, int height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + + public abstract void drawButton(int mouseX, int mouseY, float partialTicks); + + public void onClick(int mouseX, int mouseY) {} + + public boolean isMouseOver(int mouseX, int mouseY) { + return mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height; + } + + public void setHovered(boolean hovered) { + this.hovered = hovered; + } + + public boolean isHovered() { + return hovered; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public int getWidth() { + return width; + } + + public int getHeight() { + return height; + } +} diff --git a/Client/src/main/java/com/baseband/client/gui/ButtonList.java b/Client/src/main/java/com/baseband/client/gui/ButtonList.java new file mode 100644 index 0000000..05e00c8 --- /dev/null +++ b/Client/src/main/java/com/baseband/client/gui/ButtonList.java @@ -0,0 +1,32 @@ +package com.baseband.client.gui; + +import java.util.ArrayList; +import java.util.List; + +public class ButtonList { + + private List