Skip to content

Commit

Permalink
1.7.0: OneConfig, Hypixel API Removal, Bug Fixes, + more (#115)
Browse files Browse the repository at this point in the history
Co-authored-by: Detlev1 <[email protected]>
Co-authored-by: Cheezer1656 <[email protected]>
  • Loading branch information
3 people authored Feb 12, 2024
1 parent 02114fb commit 5601081
Show file tree
Hide file tree
Showing 29 changed files with 1,018 additions and 1,252 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: Build JARs

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master", "beta" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Build with Gradle
uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0
with:
arguments: build
- name: Upload JARs
uses: actions/upload-artifact@v4
with:
name: JARs
path: build/libs
65 changes: 55 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import de.undercouch.gradle.tasks.download.Download
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
idea
java
id("gg.essential.loom") version "0.10.0.+"
id("dev.architectury.architectury-pack200") version "0.1.3"
id("de.undercouch.download").version("5.3.0")
id("com.github.johnrengelman.shadow") version "7.1.2"

}

group = "dev.meyi.bazaarnotifier"
version = "1.6.1"
version = "1.7.0"
val mod_id = "bazaarnotifier"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(8))
}

loom {
launchConfigs.named("client") {
arg("--tweakClass", "cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker")
}
log4jConfigs.from(file("log4j2.xml"))
forge {
pack200Provider.set(dev.architectury.pack200.java.Pack200Adapter())
Expand All @@ -26,18 +33,25 @@ sourceSets.main {
output.setResourcesDir(file("$buildDir/classes/java/main"))
}

val shade: Configuration by configurations.creating {
configurations.implementation.get().extendsFrom(this)
}

repositories {
mavenCentral()
maven("https://repo.spongepowered.org/maven/")
maven("https://repo.polyfrost.cc/releases")
}

dependencies {
minecraft("com.mojang:minecraft:1.8.9")
mappings("de.oceanlabs.mcp:mcp_stable:22-1.8.9")
forge("net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9")
modCompileOnly("cc.polyfrost:oneconfig-1.8.9-forge:0.2.2-alpha+")
shade("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta+")
}

// Tasks:


val resourcesFile = "src/main/resources/resources.json"
val resourcesURL = "https://raw.githubusercontent.com/symt/BazaarNotifier/resources/resources.json"
Expand Down Expand Up @@ -82,13 +96,44 @@ task<DefaultTask>("retrieveResources") {
dependsOn("download-task")
}

tasks.withType(JavaCompile::class) {
options.encoding = "UTF-8"
}
tasks{
withType(JavaCompile::class) {
options.encoding = "UTF-8"
}
withType(Jar::class) {
manifest.attributes.run {
this["FMLCorePluginContainsFMLMod"] = "true"
this["ForceLoadAsMod"] = "true"
}
named<ShadowJar>("shadowJar") {
archiveClassifier.set("dev")
configurations = listOf(shade)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

remapJar {
input.set(shadowJar.get().archiveFile)
archiveClassifier.set("")
}

tasks.withType(Jar::class) {
manifest.attributes.run {
this["FMLCorePluginContainsFMLMod"] = "true"
this["ForceLoadAsMod"] = "true"
jar {
manifest {
attributes(
mapOf(
"ModSide" to "CLIENT",
"ForceLoadAsMod" to true,
"TweakOrder" to "0",
"TweakClass" to "cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker"
)
)
}
dependsOn(shadowJar)
archiveClassifier.set("")
enabled = false
}
processResources {
duplicatesStrategy = DuplicatesStrategy.INCLUDE

}
}
}
}
68 changes: 29 additions & 39 deletions src/main/java/dev/meyi/bn/BazaarNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.MalformedJsonException;
import dev.meyi.bn.commands.BazaarNotifierCommand;
import dev.meyi.bn.config.Configuration;
import dev.meyi.bn.handlers.ChestTickHandler;
Expand All @@ -15,8 +14,8 @@
import dev.meyi.bn.handlers.UpdateHandler;
import dev.meyi.bn.json.Order;
import dev.meyi.bn.json.resp.BazaarResponse;
import dev.meyi.bn.modules.Module;
import dev.meyi.bn.modules.ModuleList;
import dev.meyi.bn.modules.calc.BankCalculator;
import dev.meyi.bn.utilities.ReflectionHelper;
import dev.meyi.bn.utilities.ScheduledEvents;
import dev.meyi.bn.utilities.Utils;
Expand All @@ -35,14 +34,15 @@
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLLoadCompleteEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;


@Mod(modid = BazaarNotifier.MODID, version = BazaarNotifier.VERSION)
public class BazaarNotifier {

public static final String MODID = "BazaarNotifier";
public static final String VERSION = "1.6.1";
public static final String VERSION = "1.7.0";
public static final String prefix =
EnumChatFormatting.GOLD + "[" + EnumChatFormatting.YELLOW + "BN" + EnumChatFormatting.GOLD
+ "] " + EnumChatFormatting.RESET;
Expand All @@ -59,13 +59,10 @@ public class BazaarNotifier {
public static boolean activeBazaar = true;
public static boolean inBazaar = false;
public static boolean forceRender = false;
public static boolean validApiKey = false;
public static boolean apiKeyDisabled = true;


public static ArrayList<Order> orders = new ArrayList<>();
public static BazaarResponse bazaarDataRaw;
public static JsonObject playerDataFromAPI = new JsonObject();
public static ModuleList modules;
public static Configuration config;
public static JsonObject resources;
Expand All @@ -75,13 +72,11 @@ public class BazaarNotifier {
public static JsonObject enchantCraftingList;
public static BiMap<String, String> bazaarConv = HashBiMap.create();

public static File configFile;
public static File resourcesFile;

public static void resetMod() {
modules.resetAll();
orders = new ArrayList<>();
config = Configuration.createDefaultConfig();
}

public static void resetScale() {
Expand All @@ -90,33 +85,20 @@ public static void resetScale() {

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
ReflectionHelper.setup();
File bnDir = new File(event.getModConfigurationDirectory(), "BazaarNotifier");
//noinspection ResultOfMethodCallIgnored
bnDir.mkdirs();
configFile = new File(bnDir, "config.json");
resourcesFile = new File(bnDir, "resources.json");
JsonReader configString = null;
Gson gson = new Gson();
try {
if (configFile.isFile()) {
try {
configString = new JsonReader(new StringReader(new String(Files.readAllBytes(Paths.get(configFile.getPath())))));
configString.setLenient(true);
config = gson.fromJson(configString, Configuration.class);
config.version = BazaarNotifier.VERSION;
} catch (JsonSyntaxException | MalformedJsonException e) {
e.printStackTrace();
config = Configuration.createDefaultConfig();
}
}
} catch (IOException e) {
e.printStackTrace();
}

try {
if (resourcesFile.isFile()) {
try {
byte[] bytes = Files.readAllBytes(Paths.get(resourcesFile.getPath()));
if (bytes.length == 0) throw new JsonSyntaxException("Invalid JSON in Resources File");
JsonReader resourcesReader = new JsonReader(new StringReader(new String(
Files.readAllBytes(Paths.get(resourcesFile.getPath())))));
bytes)));
resourcesReader.setLenient(true);
resources = gson.fromJson(resourcesReader, JsonObject.class);
} catch (JsonSyntaxException | ClassCastException e) {
Expand All @@ -136,14 +118,6 @@ public void preInit(FMLPreInitializationEvent event) {
e.printStackTrace();
}

if (configString != null) {
modules = new ModuleList(config);
} else {
config = Configuration.createDefaultConfig();
modules = new ModuleList();
modules.resetAll();
}

try {
Utils.updateResources();
} catch (IOException e) {
Expand All @@ -153,8 +127,6 @@ public void preInit(FMLPreInitializationEvent event) {
enchantCraftingList = resources.getAsJsonObject("enchantCraftingList");
bazaarConv = Utils.jsonToBimap(bazaarConversions);
}

BankCalculator.reset();
}


Expand All @@ -165,16 +137,34 @@ public void init(FMLInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(new MouseHandler());
MinecraftForge.EVENT_BUS.register(new UpdateHandler());
ClientCommandHandler.instance.registerCommand(new BazaarNotifierCommand());
ReflectionHelper.setup();
ScheduledEvents.create();



config = new Configuration();


Runtime.getRuntime()
.addShutdownHook(
new Thread(
() -> {
Configuration.saveConfig(configFile, config);
Utils.saveResources(resourcesFile, resources);
//config.save();
}));

}
@Mod.EventHandler
public void done(FMLLoadCompleteEvent e){
ScheduledEvents.create();
modules = new ModuleList();
if (BazaarNotifier.config.firstLoad){
for(Module m : modules){
m.setActive(true);
m.position.setPosition(20, 20);
m.showInChat = false;
m.showInGuis = false;
}
BazaarNotifier.config.firstLoad = false;
}
}

}
36 changes: 4 additions & 32 deletions src/main/java/dev/meyi/bn/commands/BazaarNotifierCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package dev.meyi.bn.commands;

import cc.polyfrost.oneconfig.gui.OneConfigGui;
import cc.polyfrost.oneconfig.gui.pages.ModConfigPage;
import dev.meyi.bn.BazaarNotifier;
import dev.meyi.bn.config.Configuration;
import dev.meyi.bn.json.resp.BazaarItem;
import dev.meyi.bn.modules.calc.BankCalculator;
import dev.meyi.bn.modules.calc.CraftingCalculator;
Expand Down Expand Up @@ -48,37 +51,7 @@ public String getCommandUsage(ICommandSender sender) {
public void processCommand(ICommandSender ics, String[] args) {
if (ics instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) ics;
if (args.length >= 1 && args[0].equalsIgnoreCase("api")) {
if (args.length == 2) {
BazaarNotifier.config.api = args[1];
try {
if (Utils.validateApiKey()) {
player.addChatMessage(new ChatComponentText(
BazaarNotifier.prefix + EnumChatFormatting.RED
+ "Your api key has been set."));
BazaarNotifier.config.api = args[1];
BazaarNotifier.validApiKey = true;
BazaarNotifier.activeBazaar = true;
} else {
player.addChatMessage(new ChatComponentText(
BazaarNotifier.prefix + EnumChatFormatting.RED
+ "Your api key is invalid. Please run /api new to get a fresh api key & use that in /bn api (key)"));
BazaarNotifier.validApiKey = false;
}
} catch (IOException e) {
player.addChatMessage(new ChatComponentText(
BazaarNotifier.prefix + EnumChatFormatting.RED
+ "An error occurred when trying to set your api key. Please re-run the command to try again."));
BazaarNotifier.validApiKey = false;
e.printStackTrace();
}
} else {
player.addChatMessage(new ChatComponentText(
BazaarNotifier.prefix + EnumChatFormatting.RED
+ "Run /bn api (key) to set your api key. Do /api if you need to get your api key."));
BazaarNotifier.validApiKey = false;
}
} else if (args.length > 0 && args[0].equalsIgnoreCase("reset")) {
if (args.length > 0 && args[0].equalsIgnoreCase("reset")) {
if (args.length == 1 || args[1].equalsIgnoreCase("all")) {
BazaarNotifier.resetMod();
player.addChatMessage(new ChatComponentText(BazaarNotifier.prefix + EnumChatFormatting.RED
Expand Down Expand Up @@ -256,7 +229,6 @@ public List<String> addTabCompletionOptions(ICommandSender sender, String[] args
if (args.length <= 1) {
new ArrayList<String>() {
{
add("api");
add("discord");
add("find");
add("reset");
Expand Down
Loading

0 comments on commit 5601081

Please sign in to comment.