-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.2.2: Find & Better Function Profit (#9)
Showing
13 changed files
with
204 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package dev.meyi.bn.handlers; | ||
|
||
import dev.meyi.bn.BazaarNotifier; | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.concurrent.ScheduledThreadPoolExecutor; | ||
import java.util.concurrent.TimeUnit; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.event.ClickEvent; | ||
import net.minecraft.event.ClickEvent.Action; | ||
import net.minecraft.util.ChatComponentText; | ||
import net.minecraft.util.EnumChatFormatting; | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||
import net.minecraftforge.fml.common.network.FMLNetworkEvent; | ||
import org.apache.commons.io.IOUtils; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.json.JSONObject; | ||
|
||
public class UpdateHandler { | ||
|
||
boolean firstJoin = true; | ||
|
||
@SubscribeEvent | ||
public void onPlayerJoinEvent(FMLNetworkEvent.ClientConnectedToServerEvent event) { | ||
if (firstJoin) { | ||
firstJoin = false; | ||
new ScheduledThreadPoolExecutor(1).schedule(() -> { | ||
try { | ||
JSONObject json = new JSONObject(IOUtils.toString(new BufferedReader | ||
(new InputStreamReader( | ||
HttpClientBuilder.create().build().execute(new HttpGet( | ||
"https://api.github.com/repos/symt/BazaarNotifier/releases/latest")) | ||
.getEntity().getContent())))); | ||
String[] latestTag = json.getString("tag_name").split("\\."); | ||
String[] currentTag = BazaarNotifier.VERSION.split("\\."); | ||
|
||
if (latestTag.length == 3 && currentTag.length == 3) { | ||
for (int i = 0; i < latestTag.length; i++) { | ||
if (latestTag[i].compareTo(currentTag[i]) != 0) { | ||
if (latestTag[i].compareTo(currentTag[i]) <= -1) { | ||
Minecraft.getMinecraft().thePlayer.addChatMessage( | ||
new ChatComponentText(BazaarNotifier.prefix + EnumChatFormatting.RED | ||
+ "This version hasn't been released yet. Please report any bugs that you come across.")); | ||
} else if (latestTag[i].compareTo(currentTag[i]) >= 1) { | ||
ChatComponentText updateLink = new ChatComponentText( | ||
EnumChatFormatting.DARK_RED + "" + EnumChatFormatting.BOLD | ||
+ "[UPDATE LINK]"); | ||
updateLink | ||
.setChatStyle(updateLink.getChatStyle().setChatClickEvent(new ClickEvent( | ||
Action.OPEN_URL, | ||
"https://github.com/symt/BazaarNotifier/releases/latest"))); | ||
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( | ||
BazaarNotifier.prefix + EnumChatFormatting.RED | ||
+ "The mod version that you're on is outdated. Please update for the best profits: ") | ||
.appendSibling(updateLink)); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
}, 3, TimeUnit.SECONDS); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dev.meyi.bn.utilities; | ||
|
||
import org.json.JSONObject; | ||
|
||
public class Defaults { | ||
public static final int DEFAULT_SUGGESTION_MODULE_X = 5; | ||
public static final int DEFAULT_SUGGESTION_MODULE_Y = 10; | ||
public static final JSONObject DEFAULT_ORDERS_LAYOUT = new JSONObject(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters