[TUTORIAL] Send message to player when joining world if mod is out-of-date

Started by RedWirePlatinum on

Topic category: User side tutorials

Last seen on 03:48, 15. Apr 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[TUTORIAL] Send message to player when joining world if mod is out-of-date
Sun, 09/03/2023 - 23:07 (edited)

(copied and pasted from the discord thread i made, forgive me if its janky https://discord.com/channels/1146663795545100298/1148006473897611314)
File manager plugin, if you don't already have it: https://mcreator.net/plugin/64638/file-creator


Step 1: Create a file on a website that you will be using to check/update your version on
for example: On github, I have modver.json under my mod repository. I don't think the file has to have the json extension, just as long as it is in a json format https://github.com/RedWirePlatinumTwo/RedWiresMinecraftMod/blob/main/modver.json
current version (as im writing this) is v5.0.1, so i separated each version number in a separate variable (ver1,ver2,ver3)

Step 2: Create a procedure with event "Player joins the world" (or whatever at least uses the target entity dependency)

Step 3: Create 5 (or 6) local variables:

3 number variables (same thing as modver.json)

a file variable

 a jsonobject variable

and a url string variable (optional, but makes the process easier)

if you're using github (like me), get the raw page of the website file youre using and set url to that, example: https://raw.githubusercontent.com/RedWirePlatinumTwo/RedWiresMinecraftMod/main/modver.json

Step 4: Create a custom code snippet and paste the code inside (since, as of writing, copy path [url] to [file] doesn't work)

try { org.apache.commons.io.FileUtils.copyURLToFile(new URL(url), testfile, 1000, 1000); } catch (IOException e) {    e.printStackTrace(); }


if you didn't create a url local variable, you can simply replace url in new URL(url) to the link. replace testfile with the name of your local file variable

Step 5: The actual checking part
use read JSON file [file] as [json] and get values otherwise this part won't work.
Check if any of the numbers from the website file are greater than the number variables, then simply send a chat to the player (if including the latest version in the message, use the round block so numbers like5.0 turn to 5.

to test it out, try decreasing one of the 3 number local variables (for example: i changed v3 to 0) if it works, you'll get the message to notify the player!

Edited by RedWirePlatinum on Sun, 09/03/2023 - 23:07
Last seen on 03:48, 15. Apr 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Update: Made the version…
Mon, 09/04/2023 - 20:21

Update: Made the version number-checking thing *actually* accurate because you could get a message saying v4.9.0 is the latest version of v5.0.0 because when comparing the 2nd numbers, 9 is greater than 0.
https://cdn.discordapp.com/attachments/1148006473897611314/1148351916062027866/modchecker.ptpl

Last seen on 03:48, 15. Apr 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
(The update in question)
Mon, 09/04/2023 - 20:23

(The update in question)

Last seen on 03:48, 15. Apr 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Update: Changed the…
Tue, 11/07/2023 - 19:43

Update: Changed the procedure to have the 3 number variables automatically update to your mod version instead of manually having to change the numbers + added 2 comments to some of the code blocks
https://cdn.discordapp.com/attachments/1148006473897611314/117153450409…;